root/BF_GUI_KeysMenu.cpp

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. BF_GUI_KeysMenu_Item
  2. BF_GUI_KeysMenu_Item
  3. Invoke
  4. MouseDown
  5. SetText
  6. Draw
  7. SetMessage
  8. FrameResized
  9. SetText
  10. Clear
  11. SetMessage
  12. OnKeyDown
  13. MessageReceived

   1 #include <string.h>
   2 #include <stdio.h>
   3 #include <String.h>
   4 #include "BL_Tools.h"
   5 #include "BF_Msg.h"
   6 #include "BF_GUI_KeysMenu.h"
   7 
   8 BF_GUI_KeysMenu                 *poSysKeysMenu = NULL;
   9 
  10 BF_GUI_KeysMenu_Item::
  11 BF_GUI_KeysMenu_Item(BRect o_frame, const char *pc_ButtonNum,const char *pc_ButtonText, BMessage *po_Message, BHandler *po_Handler)    /* [previous][next][first][last][top][bottom][index][help] */
  12  : BView(o_frame,"buttons_item",B_FOLLOW_TOP,B_WILL_DRAW)
  13 {
  14         ASSERT(pc_ButtonText && pc_ButtonNum);
  15         /* init self vars */
  16         poMessage = NULL;
  17         poHandler = NULL;       
  18         //SetViewColor(SYS_COLOR(BF_COLOR_CURSOR_BACK));
  19         SetViewColor(B_TRANSPARENT_COLOR);
  20         sNum = pc_ButtonNum;
  21         sText = pc_ButtonText;
  22 };
  23 
  24 BF_GUI_KeysMenu_Item::
  25 ~BF_GUI_KeysMenu_Item()    /* [previous][next][first][last][top][bottom][index][help] */
  26 {
  27         SetMessage();
  28 };
  29 
  30 bool
  31 BF_GUI_KeysMenu_Item::Invoke()    /* [previous][next][first][last][top][bottom][index][help] */
  32 {
  33         if (poMessage != NULL && poHandler != NULL){
  34                 BMessenger oMessenger(poHandler);
  35                 oMessenger.SendMessage(new BMessage(*poMessage)); 
  36                 return true;
  37         }else
  38                 return false;
  39 }
  40 
  41 void                                    
  42 BF_GUI_KeysMenu_Item::MouseDown(BPoint point)    /* [previous][next][first][last][top][bottom][index][help] */
  43 {
  44         Invoke();
  45 }
  46                                                                                 
  47 void                                    
  48 BF_GUI_KeysMenu_Item::SetText(const char *pc_Text)    /* [previous][next][first][last][top][bottom][index][help] */
  49 {
  50         sText= pc_Text;
  51         if(sText.Length()>10) sText.Remove(10,sText.Length()-9);        
  52 }
  53 
  54  
  55 void 
  56 BF_GUI_KeysMenu_Item::Draw(BRect o_Rect)    /* [previous][next][first][last][top][bottom][index][help] */
  57 {
  58         BRect oRect = Bounds();
  59 
  60         /* draw background for number*/         
  61         oRect.right = oRect.left + StringWidth("99");
  62         SetHighColor(0,0,0);
  63         FillRect(oRect);
  64 
  65         /* draw background for text */
  66         BRect oRect1 = Bounds();        
  67         oRect1.left = oRect.right+1;
  68         SetHighColor(SYS_COLOR(BF_COLOR_CURSOR_BACK));
  69         FillRect(oRect1);
  70         
  71         /* draw number */
  72         SetHighColor(209,209,209);
  73         SetLowColor(0,0,0);     
  74         BPoint oPoint(oRect.left + (oRect.Width() - StringWidth(sNum.String()))/2,
  75                 oRect.bottom - 1);
  76         DrawString(sNum.String(),oPoint);                               
  77         
  78         /* draw text */
  79         SetHighColor(0,0,0);
  80         SetLowColor(SYS_COLOR(BF_COLOR_CURSOR_BACK));
  81         oPoint.x = oRect1.left + 3;
  82         DrawString(sText.String(),oPoint);      
  83         //
  84 };
  85 
  86 void
  87 BF_GUI_KeysMenu_Item::SetMessage(BMessage *po_Message, BHandler *po_Handler)    /* [previous][next][first][last][top][bottom][index][help] */
  88 {
  89         if (poMessage)          delete(poMessage);
  90         /* old code 
  91         if (poMessage != NULL)          delete(poMessage);
  92         */
  93         poMessage               = po_Message;
  94         poHandler               = po_Handler;
  95 }
  96 
  97 /*===========================================================================
  98                                     BF_GUI_KeysMenu
  99 ===========================================================================*/
 100 BF_GUI_KeysMenu::BF_GUI_KeysMenu(BRect o_frame) 
 101 : BView(o_frame,"buttons_view",B_FOLLOW_BOTTOM|B_FOLLOW_LEFT_RIGHT,
 102         B_WILL_DRAW|B_FRAME_EVENTS)
 103 {
 104         poSysKeysMenu = this;
 105 
 106         //SetViewColor(SYS_COLOR(BF_COLOR_CURSOR_BACK));
 107         SetViewColor(B_TRANSPARENT_COLOR);
 108         
 109         int iCounter;
 110         float fStep = o_frame.Width() / 10;
 111         
 112         BRect oRect = Bounds();
 113         oRect.right = fStep;
 114         for(iCounter = 0; iCounter < 10; iCounter++, oRect.left += fStep, oRect.right += fStep)
 115         {
 116                 switch(iCounter)
 117                 {
 118                         case 0:
 119                                 poButtonList[iCounter] = new BF_GUI_KeysMenu_Item(oRect,"1","");
 120                                 break;
 121                         case 1:
 122                                 poButtonList[iCounter] = new BF_GUI_KeysMenu_Item(oRect,"2","");
 123                                 break;
 124                         case 2:
 125                                 poButtonList[iCounter] = new BF_GUI_KeysMenu_Item(oRect,"3","");
 126                                 break;
 127                         case 3:
 128                                 poButtonList[iCounter] = new BF_GUI_KeysMenu_Item(oRect,"4","");
 129                                 break;
 130                         case 4:
 131                                 poButtonList[iCounter] = new BF_GUI_KeysMenu_Item(oRect,"5","");
 132                                 break;
 133                         case 5:
 134                                 poButtonList[iCounter] = new BF_GUI_KeysMenu_Item(oRect,"6","");
 135                                 break;
 136                         case 6:
 137                                 poButtonList[iCounter] = new BF_GUI_KeysMenu_Item(oRect,"7","");
 138                                 break;
 139                         case 7:
 140                                 poButtonList[iCounter] = new BF_GUI_KeysMenu_Item(oRect,"8","");
 141                                 break;
 142                         case 8:
 143                                 poButtonList[iCounter] = new BF_GUI_KeysMenu_Item(oRect,"9","");
 144                                 break;
 145                         case 9:
 146                                 poButtonList[iCounter] = new BF_GUI_KeysMenu_Item(oRect,"10","");
 147                                 break;
 148                 };
 149                 AddChild(poButtonList[iCounter]);
 150         };
 151 }
 152 
 153 void
 154 BF_GUI_KeysMenu::FrameResized(float f_width, float f_height)    /* [previous][next][first][last][top][bottom][index][help] */
 155 {
 156         BView::FrameResized(f_width,f_height);
 157 
 158         int iCounter;   
 159         BRect oRect = Bounds();
 160         float fStep = oRect.Width() / 10;
 161         oRect.right = fStep;
 162         
 163         for(iCounter = 0; iCounter < 10; iCounter++, oRect.left += fStep, oRect.right += fStep)
 164         {
 165                 poButtonList[iCounter]->ResizeTo(oRect.Width(),oRect.Height());
 166                 poButtonList[iCounter]->MoveTo(oRect.left,oRect.top);
 167         }
 168 } 
 169 
 170 void                                    
 171 BF_GUI_KeysMenu::SetText(uint8 i_Index,const char *pc_Text)    /* [previous][next][first][last][top][bottom][index][help] */
 172 {       
 173         i_Index--;
 174         ASSERT(i_Index<10,"BF_GUI_KeysMenu::SetText() : i_Index>9 !!1");
 175         poButtonList[i_Index]->SetText(pc_Text);                
 176         poButtonList[i_Index]->Invalidate();
 177 }
 178 
 179 void                                    
 180 BF_GUI_KeysMenu::Clear()    /* [previous][next][first][last][top][bottom][index][help] */
 181 {
 182         for(int i=0;i<10;i++){
 183                 SetText(i+1,"");
 184                 SetMessage(i+1,NULL,NULL);
 185         }
 186 }
 187   
 188 void
 189 BF_GUI_KeysMenu::SetMessage(uint8 i_Index, BMessage *po_Message , BHandler *po_Handler )    /* [previous][next][first][last][top][bottom][index][help] */
 190 {
 191         i_Index--;
 192         ASSERT(i_Index<10,"BF_GUI_KeysMenu::SetMessage() : i_Index>9 !!1");
 193         poButtonList[i_Index]->SetMessage(po_Message,po_Handler);
 194         poButtonList[i_Index]->Invalidate();
 195 }
 196 
 197 bool                                    
 198 BF_GUI_KeysMenu::OnKeyDown(const char *bytes, int32 numBytes)    /* [previous][next][first][last][top][bottom][index][help] */
 199 {               
 200         if(bytes[0] == B_FUNCTION_KEY){
 201                 int32 iKey;
 202                 BMessage *poMsg = Window()->CurrentMessage();
 203                 if(!poMsg) return false;
 204                 poMsg->FindInt32("key", &iKey);
 205                 
 206                 if(iKey>=B_F1_KEY && iKey<=B_F10_KEY){          
 207                         BF_GUI_KeysMenu_Item* poItem = (BF_GUI_KeysMenu_Item*)poButtonList[(int)(iKey - B_F1_KEY)];
 208                         if(poItem->Invoke()) return true;
 209                 }
 210                 
 211         }
 212         return false;
 213 }
 214 void                                    
 215 BF_GUI_KeysMenu::MessageReceived(BMessage* po_Message)    /* [previous][next][first][last][top][bottom][index][help] */
 216 {
 217         switch(po_Message->what) {
 218         case BF_MSG_SETUP_UPDATED:{             
 219                 for(int i=0;i<10;i++){
 220                         if(!poButtonList[i]) continue;
 221                         poButtonList[i]->Draw(poButtonList[i]->Bounds());
 222                 }
 223                 break;}
 224         default:
 225                 BView::MessageReceived(po_Message);
 226         }

/* [previous][next][first][last][top][bottom][index][help] */