menubar.cpp

00001 /***************************************************************************
00002                           menubar.cpp  -  description
00003                              -------------------
00004     begin                : Mon Mar 29 2004
00005     copyright            : (C) 2004 by Dynacube Team
00006     email                :
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018  #include "gui/components/menubar.h"
00019  #include "gui/components/window.h"
00020  #include "gui/components/menu.h"
00021 
00022         typedef struct
00023         {
00024                 char lbl[MN_MAX_CHAR];
00025                 DB cmdCode; //To be sent to the client
00026         } _MENUITEM;
00027 
00028         typedef struct
00029         {
00030                 DB no_item;
00031                 _MENUITEM mnuitem[MN_MAX_ITEM];
00032         } _MENU;
00033 
00034         typedef struct
00035         {
00036                 DB no_menu;
00037                 
00038                 struct
00039                 {
00040                         char label[MB_MAX_CHAR];
00041                         _MENU menu_ptr;
00042                 }mnu[MB_MAX_MENU];
00043                 
00044         } _MENUBAR;
00045         
00046  void menubar::menubar_init(void *_cnt_ptr,DW _x,DW _y,DW _width,DW _height, DD _user_menu_addr, DW _pid)
00047  {
00048           DB i,j;
00049 
00050           MENUITEM *mnuitem;
00051           char info[100];
00052 
00053           cnt_ptr = _cnt_ptr;
00054           x = _x;
00055           y = _y;
00056           width = _width;
00057           height = _height;
00058           user_menu_addr = _user_menu_addr;
00059          
00060                 _MENUBAR *mybar = (_MENUBAR *)_user_menu_addr;
00061 
00062           //Get the real Values from user's Menu
00063     no_menu = (mybar->no_menu > MB_MAX_MENU) ? MB_MAX_MENU : mybar->no_menu;
00064     cur_menu = -1; //No Selected Menu
00065 
00066     menu mymenu[MB_MAX_MENU];
00067 
00068     for(i = 0 ; i < no_menu ; i++)
00069     {
00070                         mnu[i].menu_ptr = (menu*)kmalloc(sizeof(menu));
00071                         strcpy(mnu[i].label,mybar->mnu[i].label);
00072                         mnuitem = (MENUITEM*)kmalloc(mybar->mnu[i].menu_ptr.no_item * sizeof(MENUITEM));
00073                         
00074                         for(j = 0 ; j < mybar->mnu[i].menu_ptr.no_item ; j++)
00075                         {
00076                                 strcpy(mnuitem[j].lbl,mybar->mnu[i].menu_ptr.mnuitem[j].lbl);
00077                                 mnuitem[j].cmdCode = mybar->mnu[i].menu_ptr.mnuitem[j].cmdCode;
00078                         }
00079                         
00080                         mnu[i].menu_ptr->menu_init(_cnt_ptr,mybar->mnu[i].menu_ptr.no_item,mnuitem,_pid);
00081 
00082                         if(mnuitem != NULL)
00083                                 free(mnuitem);
00084         }
00085  }
00086 
00087  void menubar::paint()
00088   {
00089     DW _x,_y,_width,_height;
00090     DW x1,y1,x2,y2;
00091     DB i;
00092                 window *win_ptr = (window*)cnt_ptr;
00093                 DW offset = 0, summa_x_off = 10, summa_y_off = 5;
00094 
00095           if(win_ptr->style & W_MAXIMIZE)
00096           {
00097                 _x = BORDER_WIDTH;
00098             _y = TITLE_HEIGHT + BORDER_HEIGHT ;
00099             _width  = SCREEN_WIDTH;
00100             _height = SCREEN_HEIGHT;
00101           }
00102           else
00103           {
00104                 _x = win_ptr->x + BORDER_WIDTH;
00105                   _y = win_ptr->y + TITLE_HEIGHT + BORDER_HEIGHT ;
00106                   _width = win_ptr->width;
00107                   _height = win_ptr->height;
00108           }
00109 
00110         fillrect(_x+x,_y+y,_width-2*BORDER_WIDTH,height,MENUBAR_COLOR);
00111 
00112                         x1 = _x;
00113       y1 = _y+height;
00114       x2 = _x+_width-2*BORDER_WIDTH;
00115       y2 = _y+height;
00116 
00117                         for(i = 0 ; i < no_menu ; i++)
00118                         {
00119         cprint(x1+offset+(i+1)*summa_x_off,y1-height+summa_y_off,mnu[i].label,0x0);
00120         offset  += strlen(mnu[i].label) * 10;
00121                         }
00122       line(x1,y1,x2,y2,0x0);
00123 
00124                   if(cur_menu != -1)
00125                   {
00126                                 //Generic Menu Painting
00127                                 x1 = mnu[cur_menu].menu_ptr->x;
00128                                 y1 = mnu[cur_menu].menu_ptr->y - MENUBAR_HEIGHT + 3;
00129                                 x2 = strlen(mnu[cur_menu].label)*10; //Not really x2 but width :-)
00130                                 y2 = MENUBAR_HEIGHT-2*3;
00131                     emboss3D(x1,y1,x2,y2,LEFT|TOP|RIGHT,_true,1);
00132                                 mnu[cur_menu].menu_ptr->paint();
00133                         }
00134   }
00135 
00136 
00137    SDB menubar::process(DW x,DW y) //Absolute x, y
00138    {
00139                 DW _x,_y, _width, _height;
00140     DW x1,y1,x2,y2;
00141                 DW offset = 0, summa_x_off = 10, summa_y_off = 5;
00142                 window *win_ptr = (window*)cnt_ptr;
00143                 DB i, j;
00144                 SDB ret;
00145 
00146           if(win_ptr->style & W_MAXIMIZE)
00147           {
00148                 _x = BORDER_WIDTH;
00149             _y = TITLE_HEIGHT + BORDER_HEIGHT;
00150             _width  = SCREEN_WIDTH;
00151             _height = SCREEN_HEIGHT;
00152           }
00153           else
00154           {
00155                 _x = win_ptr->x + BORDER_WIDTH;
00156                   _y = win_ptr->y + TITLE_HEIGHT + BORDER_HEIGHT;
00157                   _width = win_ptr->width;
00158                   _height = win_ptr->height;
00159           }
00160 
00161                         x1 = _x;
00162       y1 = _y+height;
00163       x2 = _x+_width-2*BORDER_WIDTH;
00164       y2 = _y+height;
00165 
00166           if(iswithin(x,y,_x,_y,_width,MENUBAR_HEIGHT))
00167           {
00168                         restoreImage(mcurx,mcury);
00169 
00170                         if(cur_menu != -1)
00171                         {
00172                                 mnu[cur_menu].menu_ptr->menu_restore();
00173                         }
00174 
00175                         for(i = 0 ; i < no_menu ; i++)
00176                         {
00177         if(iswithin(x,y,x1+offset+(i+1)*summa_x_off,y1-height+summa_y_off,strlen(mnu[i].label)*10,height))
00178         {
00179                                         cur_menu = i;
00180                                 mnu[cur_menu].menu_ptr->x = x1+offset+(i+1)*summa_x_off-3;
00181                       mnu[cur_menu].menu_ptr->y = y1;
00182                                         break;
00183                                 }
00184         offset  += strlen(mnu[i].label) * 10;
00185                         }
00186 
00187                         if(i == no_menu)
00188                         {
00189                                 cur_menu = -1;
00190                         }
00191 
00192                         this->paint();
00193 
00194                         mouse_restore();
00195 
00196                         mvBuf2Svga();
00197 
00198                         return 0;
00199           }
00200           else if(cur_menu != -1)
00201           {
00202                         mnu[cur_menu].menu_ptr->menu_restore();
00203 
00204                         if(mnu[cur_menu].menu_ptr->process(x,y) == 0) //Something Useful
00205                                 ret = 0;
00206                         else
00207                                 ret = -1;
00208 
00209                 cur_menu = -1;
00210 
00211                 win_ptr->paint_win();
00212             mouse_restore();
00213 
00214             if(ret == 0)
00215                     mvBuf2Svga();
00216 
00217                   return ret;
00218                 }
00219 
00220    }
00221 
00222         void menubar::keyPress(DW state,DW ch)
00223         {
00224         }
00225 
00226          void menubar::freeAll()
00227          {
00228                  DB i;
00229 
00230                  for(i = 0 ; i < no_menu ; i++)
00231                  {
00232                          if(mnu[i].menu_ptr != NULL)
00233                                  free(mnu[i].menu_ptr);
00234                  }
00235    }

Generated on Thu Jul 27 23:52:27 2006 for Dynacube by  doxygen 1.4.7