root/BF_GUI_DlgViews_Menu.cpp

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

DEFINITIONS

This source file includes following definitions.
  1. Set
  2. Draw
  3. MakeFocus
  4. CalcWidth
  5. BF_GUI_ViewMenu_CalcMaxWidth
  6. BF_GUI_ViewMenu_CalcTotalWidth
  7. ItemByTitle
  8. ItemAt
  9. FocusItem
  10. Height
  11. BF_GUI_DlgView_Menu_Sort_0
  12. SortList
  13. SetList
  14. DeleteItemAt
  15. KeyDown
  16. NavChangeCursor
  17. NavEscape
  18. NavEnter
  19. AddItem
  20. SaveToMessage
  21. Draw
  22. DrawItems
  23. Draw_FocusItemPointer
  24. MakeFocus
  25. AttachedToWindow
  26. DrawItem
  27. SetColor_Text
  28. SetColor_Back
  29. AddItem
  30. CreateVScroll
  31. AttachedToWindow
  32. FrameResized
  33. Height
  34. SetList
  35. SaveToMessage
  36. KeyDown
  37. NavSelect
  38. DrawItems
  39. DrawItemExt
  40. DrawItem
  41. MouseDown
  42. NavChangeCursor
  43. DrawItem
  44. CalcItemXPos
  45. DrawItem
  46. MouseDown

   1 #include <stdio.h>
   2 
   3 #include "BF_Msg.h" 
   4 #include "BF_GUI_Func.h" 
   5 #include "BF_GUI_DlgViews.h"  
   6 #include "BF_GUI_WinMain.h"  
   7 
   8 
   9 /*================================================================*/
  10 BF_GUI_ViewMenu_Item::BF_GUI_ViewMenu_Item(
  11         const char *pc_Title,
  12         const char *pc_Code,
  13         BBitmap *po_SIcon)
  14 {
  15         sCode = pc_Code;        
  16         sTitle = pc_Title;      
  17         fWidth  = 0;    
  18         poSIcon = po_SIcon;
  19         bSelected = false;
  20 }
  21 
  22 BF_GUI_ViewMenu_Item::BF_GUI_ViewMenu_Item(BF_GUI_ViewMenu_Item *po_Src)
  23 {
  24         Set(po_Src);    
  25 }
  26 
  27 void                                    
  28 BF_GUI_ViewMenu_Item::Set(BF_GUI_ViewMenu_Item *po_Src)    /* [previous][next][first][last][top][bottom][index][help] */
  29 {
  30         ASSERT(po_Src);
  31         sCode = po_Src->sCode;
  32         sTitle = po_Src->sTitle;
  33         fWidth = po_Src->fWidth;
  34         if(po_Src->poSIcon) poSIcon = new BBitmap(poSIcon); else poSIcon = NULL;
  35         bSelected = po_Src->bSelected;
  36 }
  37 
  38 BF_GUI_ViewMenu_Item::~BF_GUI_ViewMenu_Item()
  39 {
  40         if(poSIcon) DELETE(poSIcon);
  41 }
  42 
  43 void
  44 BF_GUI_ViewMenu_Item::Draw(BF_GUI_DlgView_Menu *po_Parent,BView *po_Render,float f_PosY)    /* [previous][next][first][last][top][bottom][index][help] */
  45 {
  46 }
  47 
  48 void                                    
  49 BF_GUI_ViewMenu_Item::MakeFocus(BF_GUI_DlgView_Menu *po_Parent)    /* [previous][next][first][last][top][bottom][index][help] */
  50 {       
  51 }
  52 
  53 float
  54 BF_GUI_ViewMenu_Item::CalcWidth(BF_GUI_Setup_Font * po_Font)    /* [previous][next][first][last][top][bottom][index][help] */
  55 {
  56         ASSERT(po_Font);
  57         fWidth =  po_Font->oFont.StringWidth(sTitle.String());
  58         fWidth += 10; // for focus_pointer
  59         return fWidth;
  60 }
  61 
  62 float
  63 BF_GUI_ViewMenu_CalcMaxWidth(BL_List *plo_Menu,BF_GUI_Setup_Font * po_Font,bool b_ShowIcons)    /* [previous][next][first][last][top][bottom][index][help] */
  64 {
  65         ASSERT(po_Font && plo_Menu);
  66         /* calc max_item  width */
  67         float fMaxWidth=0;
  68         {
  69                 BF_GUI_ViewMenu_Item *po;
  70                 for(int i=0;i<plo_Menu->CountItems();i++){
  71                         po = (BF_GUI_ViewMenu_Item*)plo_Menu->ItemAt(i);                        
  72                         ASSERT(po);
  73                         po->CalcWidth(po_Font);
  74                         if(po->fWidth>fMaxWidth) fMaxWidth = po->fWidth;
  75                 }
  76                 if(b_ShowIcons) fMaxWidth+=19;
  77         }               
  78         return fMaxWidth;
  79 }
  80 
  81 float
  82 BF_GUI_ViewMenu_CalcTotalWidth(BL_List *plo_Menu,BF_GUI_Setup_Font * po_Font,bool b_ShowIcons)    /* [previous][next][first][last][top][bottom][index][help] */
  83 {
  84         ASSERT(po_Font && plo_Menu);
  85         /* calc max_item  width */
  86         float fTotalWidth=0;
  87         {
  88                 BF_GUI_ViewMenu_Item *po;
  89                 for(int i=0;i<plo_Menu->CountItems();i++){
  90                         po = (BF_GUI_ViewMenu_Item*)plo_Menu->ItemAt(i);                        
  91                         ASSERT(po);
  92                         po->CalcWidth(po_Font);
  93                         fTotalWidth += po->fWidth+10;                   
  94                 }
  95         }       
  96         return fTotalWidth;
  97 }
  98 /*================================================================*/
  99 // plo_Menu will deleted with all items after close
 100 BF_GUI_DlgView_Menu::BF_GUI_DlgView_Menu(
 101                 const BRect     &o_Rect,
 102                 const char      *pc_Name,
 103                 uint32  i_FollowType,
 104                 BL_List *plo_Menu
 105                 )
 106 :BF_GUI_DialogView(o_Rect,pc_Name,i_FollowType,B_WILL_DRAW|B_NAVIGABLE)
 107 {
 108         ASSERT(plo_Menu);
 109         ploMenu = plo_Menu;
 110         iNavCursorIndex = -1;   
 111         bDestroyMenu = true;
 112         bHideCursorOnDefocus = true;
 113         //
 114         SetViewColor(B_TRANSPARENT_COLOR);
 115         //      
 116 }
 117 
 118 BF_GUI_ViewMenu_Item*   
 119 BF_GUI_DlgView_Menu::ItemByTitle(const char *pc_Title)    /* [previous][next][first][last][top][bottom][index][help] */
 120 {
 121         ASSERT(pc_Title);
 122         BF_GUI_ViewMenu_Item* po;
 123         for(int i=0;i<ploMenu->CountItems();i++){
 124                 po = ItemAt(i);
 125                 if(po->sTitle==pc_Title) return po;
 126         }
 127         return NULL;
 128 }
 129 
 130 BF_GUI_ViewMenu_Item*   
 131 BF_GUI_DlgView_Menu::ItemAt(int32 i_Index)    /* [previous][next][first][last][top][bottom][index][help] */
 132 {
 133         if(i_Index>=ploMenu->CountItems()) return NULL;
 134         return (BF_GUI_ViewMenu_Item*)ploMenu->ItemAt(i_Index);
 135 }
 136 
 137 BF_GUI_ViewMenu_Item*   
 138 BF_GUI_DlgView_Menu::FocusItem()    /* [previous][next][first][last][top][bottom][index][help] */
 139 {
 140         if(iNavCursorIndex<0 || ploMenu->CountItems()==0) return NULL;
 141         return (BF_GUI_ViewMenu_Item*)ploMenu->ItemAt(iNavCursorIndex);
 142 }
 143 
 144 float
 145 BF_GUI_DlgView_Menu::Height()    /* [previous][next][first][last][top][bottom][index][help] */
 146 {
 147         return poFont->fHeight;
 148 }
 149 
 150 
 151 BF_GUI_DlgView_Menu::~BF_GUI_DlgView_Menu()
 152 {
 153         printf("BF_GUI_DlgView_Menu::~BF_GUI_DlgView_Menu()\n");        
 154         /*---------*/
 155         if(bDestroyMenu) DELETE(ploMenu);
 156         printf("BF_GUI_DlgView_Menu::~BF_GUI_DlgView_Menu()\n");
 157 }
 158 
 159 
 160 int BF_GUI_DlgView_Menu_Sort_0(const void * p_1, const void *p_2)    /* [previous][next][first][last][top][bottom][index][help] */
 161 {
 162         BF_GUI_ViewMenu_Item *po1 = *((BF_GUI_ViewMenu_Item**)p_1);
 163         BF_GUI_ViewMenu_Item *po2 = *((BF_GUI_ViewMenu_Item**)p_2);
 164         
 165         return po1->sTitle.Compare(po2->sTitle);
 166 }
 167 
 168 void                                    
 169 BF_GUI_DlgView_Menu::SortList(BL_List *plo_List)    /* [previous][next][first][last][top][bottom][index][help] */
 170 {
 171         ASSERT(plo_List);
 172         plo_List->SortItems(BF_GUI_DlgView_Menu_Sort_0);
 173 }
 174 
 175 void                                    
 176 BF_GUI_DlgView_Menu::SetList(BL_List *plo_NewMenu)    /* [previous][next][first][last][top][bottom][index][help] */
 177 {
 178         if(bDestroyMenu) DELETE(ploMenu) else ploMenu = NULL;
 179         ASSERT(plo_NewMenu);
 180         ploMenu = plo_NewMenu;
 181         iNavCursorIndex = ploMenu->CountItems()>0?0:-1; 
 182 }
 183 
 184 void                                    
 185 BF_GUI_DlgView_Menu::DeleteItemAt(int i_Index)    /* [previous][next][first][last][top][bottom][index][help] */
 186 {
 187         BF_GUI_ViewMenu_Item *poItem = ItemAt(i_Index);
 188         if(!poItem) return;
 189         ploMenu->RemoveItem(i_Index);
 190         DELETE(poItem);
 191         if(iNavCursorIndex>=ploMenu->CountItems()) iNavCursorIndex--;
 192         Draw(Bounds());
 193 }
 194 
 195 void
 196 BF_GUI_DlgView_Menu::KeyDown(const char *bytes, int32 numBytes)    /* [previous][next][first][last][top][bottom][index][help] */
 197 {
 198         /* is list empty */
 199         if(iNavCursorIndex<0){
 200                 BView::KeyDown(bytes,numBytes);
 201                 return;
 202         }
 203         /* handle keys */
 204         if(numBytes==1 && (bytes[0]==B_DOWN_ARROW || bytes[0]==B_RIGHT_ARROW)){         
 205                 NavChangeCursor(iNavCursorIndex+1,BF_GUI_TOOLMENU_MOVE_DOWN);
 206         }else
 207         if(numBytes==1 && (bytes[0]==B_UP_ARROW  || bytes[0]==B_LEFT_ARROW)){           
 208                 NavChangeCursor(iNavCursorIndex-1,BF_GUI_TOOLMENU_MOVE_UP);
 209         }else
 210         if(numBytes==1 && (bytes[0]==B_HOME || bytes[0]==B_PAGE_UP)){           
 211                 NavChangeCursor(0,BF_GUI_TOOLMENU_MOVE_POS);
 212         }else
 213         if(numBytes==1 && (bytes[0]==B_END  || bytes[0]==B_PAGE_DOWN)){ 
 214                 NavChangeCursor(ploMenu->CountItems()-1,BF_GUI_TOOLMENU_MOVE_END);
 215         }else   
 216         if(numBytes==1 && bytes[0]==B_ENTER){           
 217                 NavEnter();
 218         }else
 219         if(numBytes==1 && bytes[0]==B_ESCAPE){          
 220                 NavEscape();
 221         }else{  
 222                 
 223                 if(BF_GUI_DialogView::KeyDownExt(bytes,numBytes)) return;else
 224                 BView::KeyDown(bytes,numBytes);
 225         }       
 226 };
 227 
 228 void                                    
 229 BF_GUI_DlgView_Menu::NavChangeCursor(int32 i_NewCursor,int i_DirectMove,bool b_Redraw)    /* [previous][next][first][last][top][bottom][index][help] */
 230 {
 231         if(i_NewCursor<0){
 232                 if(i_DirectMove!=BF_GUI_TOOLMENU_MOVE_UP)
 233                         i_NewCursor = 0;
 234                 else
 235                         i_NewCursor = ploMenu->CountItems()-1;
 236         }
 237         if(i_NewCursor>=ploMenu->CountItems()){
 238                 if(i_DirectMove!=BF_GUI_TOOLMENU_MOVE_DOWN)
 239                         i_NewCursor = ploMenu->CountItems()-1;
 240                 else
 241                         i_NewCursor = 0;
 242         }
 243         //
 244         if(i_NewCursor==iNavCursorIndex) return;
 245         ///
 246         if(i_NewCursor<0) return;
 247         // find next non-empty line //
 248         BF_GUI_ViewMenu_Item *po;
 249         while(TRUE){
 250                 po = (BF_GUI_ViewMenu_Item*)ploMenu->ItemAt(i_NewCursor);
 251                 if(po->sTitle!="") break;else
 252                 switch(i_DirectMove){
 253                 case BF_GUI_TOOLMENU_MOVE_END:                  
 254                         if(i_NewCursor-->=0) continue;else return;
 255                         break;
 256                 case BF_GUI_TOOLMENU_MOVE_DOWN:
 257                 case BF_GUI_TOOLMENU_MOVE_PG_DOWN:              
 258                         i_NewCursor++;                  break;
 259                 case BF_GUI_TOOLMENU_MOVE_PG_UP:                                        
 260                 case BF_GUI_TOOLMENU_MOVE_UP:
 261                         i_NewCursor--;                  break;
 262                 }
 263                 if(i_NewCursor==ploMenu->CountItems()) return;
 264                 if(i_NewCursor<0) return;
 265                 break;
 266         }
 267         // draw items
 268         int32 iOldCursor = iNavCursorIndex;
 269         iNavCursorIndex = i_NewCursor;
 270         
 271         if(b_Redraw){
 272                 if( iNavCursorIndex>=0 )        DrawItem(this,iOldCursor,true);                 
 273                 if(b_Redraw) DrawItem(this,iNavCursorIndex,true);
 274         }
 275                 
 276         po->MakeFocus(this);
 277 }
 278 
 279 void
 280 BF_GUI_DlgView_Menu::NavEscape()    /* [previous][next][first][last][top][bottom][index][help] */
 281 {
 282         BMessage oMessage(BF_MSG_DIALOG_PRESSED_CANCEL);
 283         oMessage.AddPointer("bf_DlgView_Focus",this);
 284         BMessenger oMessenger(Parent());                
 285         oMessenger.SendMessage(&oMessage);                      
 286 }
 287 
 288 void                                    
 289 BF_GUI_DlgView_Menu::NavEnter()    /* [previous][next][first][last][top][bottom][index][help] */
 290 {
 291         BF_GUI_ViewMenu_Item *po = (BF_GUI_ViewMenu_Item*)ploMenu->ItemAt(iNavCursorIndex);     
 292         if(po->Invoke(this)) return;
 293         BMessage oMessage(BF_MSG_DIALOG_PRESSED_OK);
 294         oMessage.AddPointer("bf_DlgView_Focus",this);
 295         BMessenger oMessenger(Parent());                
 296         oMessenger.SendMessage(&oMessage);              
 297 }
 298 
 299 void                                    
 300 BF_GUI_DlgView_Menu::AddItem(BF_GUI_ViewMenu_Item* po_Item,bool b_SetCursorOnItem)    /* [previous][next][first][last][top][bottom][index][help] */
 301 {       
 302         ASSERT(po_Item);
 303         ploMenu->AddItem(po_Item);
 304         
 305         DrawItem(this,ploMenu->CountItems()-1,true);
 306         
 307         if(iNavCursorIndex<0) NavChangeCursor(0,BF_GUI_TOOLMENU_MOVE_POS);else
 308         if(b_SetCursorOnItem) NavChangeCursor(ploMenu->CountItems()-1,BF_GUI_TOOLMENU_MOVE_POS);                
 309 }
 310 
 311 void                                    
 312 BF_GUI_DlgView_Menu::SaveToMessage(BMessage *po_Message)    /* [previous][next][first][last][top][bottom][index][help] */
 313 {       
 314         po_Message->AddInt32(Name(),iNavCursorIndex);   
 315         //
 316         BF_GUI_ViewMenu_Item *po = (BF_GUI_ViewMenu_Item*)ploMenu->ItemAt(iNavCursorIndex);     
 317         if(po){
 318                 BString s;      
 319                 s<<Name();      
 320                 s<<"_code";
 321                 po_Message->AddString(s.String(),po->sCode.String());   
 322         }
 323 }
 324 
 325 void                                    
 326 BF_GUI_DlgView_Menu::Draw(BRect o_Rect)    /* [previous][next][first][last][top][bottom][index][help] */
 327 {               
 328         /* create render */
 329         BRect   oRect(Bounds());
 330         BBitmap oB(oRect,B_RGBA32,TRUE);
 331         BView   *pv;
 332         oB.AddChild(pv = new BView(oRect,"",B_FOLLOW_ALL,B_WILL_DRAW)); 
 333         oB.Lock();      
 334         /* init render */
 335         pv->SetFont(&poFont->oFont);
 336         pv->SetViewColor(B_TRANSPARENT_COLOR);  
 337         
 338         /* draw background */                   
 339         pv->SetHighColor(SYS_COLOR(BF_COLOR_DIALOG_BACK));
 340         pv->FillRect(Bounds());         
 341                         
 342         DrawItems(pv);
 343         
 344         /* close render */      
 345         pv->Sync();
 346         oB.Unlock();
 347         DrawBitmap(&oB,oRect);
 348 }
 349 
 350 void    
 351 BF_GUI_DlgView_Menu::DrawItems(BView *po_Render)    /* [previous][next][first][last][top][bottom][index][help] */
 352 {
 353         /* draw items */        
 354         for(int i=0;i<ploMenu->CountItems();i++){
 355                 DrawItem(po_Render,i,false);
 356         }
 357 }
 358 
 359 void    
 360 BF_GUI_DlgView_Menu::Draw_FocusItemPointer(BPoint & o_PointStart,BView *po_Render)    /* [previous][next][first][last][top][bottom][index][help] */
 361 {
 362         BPoint o1(o_PointStart),o2(o1),o3;              
 363         o1.y += poFont->fHeight/2-2;                            
 364         o2.y += poFont->fHeight/2;
 365         o2.x += 3;              
 366         o3 = o1;
 367         o3.y+=4;
 368         po_Render->FillTriangle(o1,o2,o3);
 369 }
 370 
 371 void    
 372 BF_GUI_DlgView_Menu::MakeFocus(bool     b_Focused)    /* [previous][next][first][last][top][bottom][index][help] */
 373 {
 374         BView::MakeFocus(b_Focused);
 375         if(iNavCursorIndex<0 && ploMenu && ploMenu->CountItems()>0) iNavCursorIndex = 0;
 376         if(iNavCursorIndex>=0) DrawItem(this,iNavCursorIndex,true);
 377 }
 378 
 379 void            
 380 BF_GUI_DlgView_Menu::AttachedToWindow(void)    /* [previous][next][first][last][top][bottom][index][help] */
 381 {       
 382         BF_GUI_DialogView::AttachedToWindow();
 383         NavChangeCursor(iNavCursorIndex<0?0:iNavCursorIndex,BF_GUI_TOOLMENU_MOVE_POS,false);    
 384 }
 385 
 386 
 387 void                                    
 388 BF_GUI_DlgView_Menu::DrawItem(BView *po,int32 i_Index,bool b_ReqDrawBack)    /* [previous][next][first][last][top][bottom][index][help] */
 389 {
 390 }
 391 
 392 
 393 void                                    
 394 BF_GUI_DlgView_Menu::SetColor_Text(BView * po_Render,bool b_IsFocused,BF_GUI_ViewMenu_Item *po_Item)    /* [previous][next][first][last][top][bottom][index][help] */
 395 {
 396         po_Render->SetHighColor((po_Item && po_Item->bSelected)?SYS_COLOR(BF_COLOR_DIALOG_MENU_ITEMSELECTED):SYS_COLOR(BF_COLOR_DIALOG_TEXT));  
 397         if((po_Item && po_Item->bSelected)){                            
 398                 po_Render->SetLowColor(SYS_COLOR(BF_COLOR_DIALOG_BUTTON_FOCUS));        
 399         }else{  
 400                 po_Render->SetLowColor(SYS_COLOR(BF_COLOR_DIALOG_BACK));        
 401         }
 402 }
 403 
 404 void                                    
 405 BF_GUI_DlgView_Menu::SetColor_Back(BView *po_Render,bool b_IsFocused)    /* [previous][next][first][last][top][bottom][index][help] */
 406 {
 407         if(b_IsFocused){
 408                 po_Render->SetHighColor(SYS_COLOR(BF_COLOR_DIALOG_BUTTON_FOCUS));       
 409         }else{
 410                 po_Render->SetHighColor(SYS_COLOR(BF_COLOR_DIALOG_BACK));       
 411         }       
 412 }
 413 /*================================================================*/
 414 BF_GUI_DlgView_VMenu::BF_GUI_DlgView_VMenu(
 415         const BRect     &o_Rect,
 416         const char      *pc_Name,
 417         uint32  i_FollowType,
 418         BL_List *plo_Menu,
 419         uint32  i_Style,
 420         float   f_NewItemHeight)
 421 :BF_GUI_DlgView_Menu(o_Rect,pc_Name,i_FollowType,plo_Menu)
 422 {
 423         iStyle = i_Style | BF_GUI_DLGVIEW_VMENU_SET_VSCROLLBAR;
 424         iFirstIndex = 0;
 425         fNewItemHeight = f_NewItemHeight;
 426         
 427         iPageSize = (int32)( Bounds().Height() / Height() );
 428         poVScroll = NULL;
 429         
 430         if(iStyle & BF_GUI_DLGVIEW_VMENU_SET_VSCROLLBAR) CreateVScroll();
 431 }
 432 
 433 void                                    
 434 BF_GUI_DlgView_VMenu::AddItem(BF_GUI_ViewMenu_Item* po_Item,bool b_SetCursorOnItem)    /* [previous][next][first][last][top][bottom][index][help] */
 435 {
 436         BF_GUI_DlgView_Menu::AddItem(po_Item,b_SetCursorOnItem);
 437         CreateVScroll();
 438 }
 439 
 440 void                                    
 441 BF_GUI_DlgView_VMenu::CreateVScroll()    /* [previous][next][first][last][top][bottom][index][help] */
 442 {               
 443         if(!poVScroll){ 
 444                 if(iPageSize<ploMenu->CountItems()){
 445                         
 446                         ResizeTo(Bounds().Width()-14,Bounds().Height());
 447                                                                         
 448                         BRect oRect(Frame());
 449                         oRect.left = oRect.right+6; 
 450                         oRect.right = oRect.left+8;
 451                         poVScroll = new BF_GUI_VScrollBar(oRect,"scroll",B_FOLLOW_TOP_BOTTOM|B_FOLLOW_RIGHT);           
 452                         
 453                         if(Window()) Parent()->AddChild(poVScroll);
 454                 }
 455         }
 456         
 457         if(poVScroll) poVScroll->SetLimits(ploMenu->CountItems(),iPageSize);
 458 }
 459 
 460 
 461 void                                    
 462 BF_GUI_DlgView_VMenu::AttachedToWindow(void)    /* [previous][next][first][last][top][bottom][index][help] */
 463 {
 464         if(poVScroll){
 465                 Parent()->AddChild(poVScroll);          
 466         }
 467         BF_GUI_DlgView_Menu::AttachedToWindow();
 468 }
 469 
 470 void                                    
 471 BF_GUI_DlgView_VMenu::FrameResized(float width, float height)    /* [previous][next][first][last][top][bottom][index][help] */
 472 {
 473         BF_GUI_DlgView_Menu::FrameResized(width,height);
 474         iPageSize = (int32)( Bounds().Height() / Height() );
 475 }
 476 
 477 float
 478 BF_GUI_DlgView_VMenu::Height()    /* [previous][next][first][last][top][bottom][index][help] */
 479 {
 480         if(fNewItemHeight>0) return fNewItemHeight;
 481         float f = poFont->fHeight;
 482         if((iStyle & BF_GUI_DLGVIEW_VMENU_SICON) && f<18) f=18;
 483         
 484         return f;
 485 }
 486 void                                    
 487 BF_GUI_DlgView_VMenu::SetList(BL_List *plo_NewMenu)    /* [previous][next][first][last][top][bottom][index][help] */
 488 {
 489         BF_GUI_DlgView_Menu::SetList(plo_NewMenu);
 490         iFirstIndex = 0;
 491         CreateVScroll();
 492 }
 493 
 494 void                                    
 495 BF_GUI_DlgView_VMenu::SaveToMessage(BMessage *po_Message)    /* [previous][next][first][last][top][bottom][index][help] */
 496 {
 497         if((iStyle & BF_GUI_DLGVIEW_VMENU_CAN_SELECTING) && ploMenu){
 498                 BF_GUI_ViewMenu_Item *po;
 499                 BL_String       s;
 500                 
 501                 for(int i=0;i<ploMenu->CountItems();i++){                       
 502                         po = ItemAt(i);
 503                         if(po->bSelected){
 504                                 s=Name();
 505                                 s+="_sel";
 506                                 po_Message->AddString(s.String(),po->sCode.String());                   
 507                         }
 508                 }
 509         }
 510         BF_GUI_DlgView_Menu::SaveToMessage(po_Message);
 511 }
 512 
 513 void
 514 BF_GUI_DlgView_VMenu::KeyDown(const char *bytes, int32 numBytes)    /* [previous][next][first][last][top][bottom][index][help] */
 515 {
 516         /* is list empty */
 517         if(iNavCursorIndex<0){
 518                 BView::KeyDown(bytes,numBytes);
 519                 return;
 520         }
 521         /* handle keys */
 522         if((iStyle & BF_GUI_DLGVIEW_VMENU_CAN_SELECTING) && numBytes==1 && bytes[0]==B_INSERT){
 523                 NavSelect();
 524         }else
 525         if(numBytes==1 && bytes[0]==B_PAGE_UP){         
 526                 NavChangeCursor(iNavCursorIndex - iPageSize,BF_GUI_TOOLMENU_MOVE_PG_UP);
 527         }else
 528         if(numBytes==1 && bytes[0]==B_PAGE_DOWN){       
 529                 NavChangeCursor(iNavCursorIndex + iPageSize,BF_GUI_TOOLMENU_MOVE_PG_DOWN);
 530         }else   
 531                 BF_GUI_DlgView_Menu::KeyDown(bytes,numBytes);
 532 }
 533 
 534 void
 535 BF_GUI_DlgView_VMenu::NavSelect()    /* [previous][next][first][last][top][bottom][index][help] */
 536 {
 537         BF_GUI_ViewMenu_Item*   poItem = FocusItem();   
 538         if(!poItem) return;
 539         
 540         poItem->bSelected = !poItem->bSelected;
 541         DrawItem(this,iNavCursorIndex,true);
 542         NavChangeCursor(iNavCursorIndex+1,BF_GUI_TOOLMENU_MOVE_DOWN,true);
 543 }
 544 
 545 void    
 546 BF_GUI_DlgView_VMenu::DrawItems(BView *po_Render)    /* [previous][next][first][last][top][bottom][index][help] */
 547 {
 548         /* draw items */        
 549         for(int i=iFirstIndex;i<iFirstIndex+iPageSize;i++){
 550                 if(i>=ploMenu->CountItems()) break;
 551                 DrawItem(po_Render,i,false);
 552         }
 553 }
 554 
 555 void
 556 BF_GUI_DlgView_VMenu::DrawItemExt(BView *po_Render,int32 i_Index,bool b_ReqDrawBack)    /* [previous][next][first][last][top][bottom][index][help] */
 557 {
 558         DrawItem(po_Render,i_Index,b_ReqDrawBack);
 559 }
 560 
 561 void                                    
 562 BF_GUI_DlgView_VMenu::DrawItem(BView *po_Render,int32 i_Index,bool b_ReqDrawBack)    /* [previous][next][first][last][top][bottom][index][help] */
 563 {       
 564         ASSERT(po_Render);
 565         if((i_Index - iFirstIndex) > iPageSize) return;
 566 
 567         BPoint oPointStart(0,0),oPoint;         
 568         oPointStart.y += ((float)(i_Index-iFirstIndex)) * Height();
 569         oPoint = oPointStart;
 570         //
 571         bool    bListFocused = IsFocus();
 572         bool    bItemFocused = i_Index==iNavCursorIndex;
 573         // draw background 
 574         if(bListFocused || b_ReqDrawBack)
 575         {
 576                 SetColor_Back(po_Render,bListFocused && bItemFocused);
 577                 BRect oRect =po_Render->Bounds();
 578                 oRect.top = oPoint.y;
 579                 oRect.bottom = oRect.top+Height();
 580                 po_Render->FillRect(oRect);
 581         }
 582         
 583         // check for empty index
 584         if(i_Index<0) return;
 585         
 586                                 
 587         BF_GUI_ViewMenu_Item *po;
 588         po = (BF_GUI_ViewMenu_Item*)ploMenu->ItemAt(i_Index);
 589         ASSERT(po);     //      
 590         SetColor_Text(po_Render,bItemFocused,po);
 591         
 592         if(po->sTitle!=""){
 593                 oPoint.x = 10.0;
 594                 if(iStyle & BF_GUI_DLGVIEW_VMENU_SICON){
 595                         if(po->poSIcon){
 596                                 po_Render->SetDrawingMode(B_OP_ALPHA);                          
 597                                 po_Render->DrawBitmap(po->poSIcon,oPoint);
 598                                 po_Render->SetDrawingMode(B_OP_COPY);
 599                         }
 600                         oPoint.x+=20;
 601                 }
 602                 oPoint.y += poFont->fAscent;
 603                 po_Render->DrawString(po->sTitle.String(),oPoint);
 604         }else{
 605                 oPoint.x = 10.0;
 606                 oPoint.y+=Height()/2;
 607                 BRect oRect(po_Render->Bounds());
 608                 BPoint oPointEnd(oRect.right-4.0,oPoint.y);
 609                 po_Render->StrokeLine(oPoint,oPointEnd);
 610         }
 611         //
 612         if(bItemFocused) Draw_FocusItemPointer(oPointStart,po_Render);  
 613         //
 614         po->Draw(this,po_Render,oPointStart.y);
 615 }
 616 
 617 //
 618 void                                    
 619 BF_GUI_DlgView_VMenu::MouseDown(BPoint point)    /* [previous][next][first][last][top][bottom][index][help] */
 620 {       
 621         if(!(Flags() & B_NAVIGABLE)) return;
 622         /*  */
 623         int32 iNewCursor;
 624         /* */
 625         BPoint oPoint = point;
 626         iNewCursor = (int32)(oPoint.y/Height()) + iFirstIndex;
 627         if(iNewCursor!=iNavCursorIndex){
 628                 NavChangeCursor(iNewCursor,BF_GUI_TOOLMENU_MOVE_POS);
 629                 NavEnter();
 630         }else{
 631                 NavEnter();
 632         }
 633 }
 634 
 635 void                                    
 636 BF_GUI_DlgView_VMenu::NavChangeCursor(int32 i_NewCursor,int i_DirectMove,bool b_Redraw)    /* [previous][next][first][last][top][bottom][index][help] */
 637 {
 638         int32 iOldCursor = iNavCursorIndex;
 639         BF_GUI_DlgView_Menu::NavChangeCursor(i_NewCursor,i_DirectMove,false);
 640         
 641         BRect oRect(Bounds());
 642         
 643         int iCount = (int)(oRect.Height()/Height());    
 644         int i1=iNavCursorIndex-iFirstIndex;
 645         
 646         if(i1>=iCount){
 647                 iFirstIndex = iNavCursorIndex - iCount+1;                                               
 648                 Draw(Bounds());                                 
 649         }else
 650         if(i1<0){
 651                 iFirstIndex = iNavCursorIndex;
 652                 Draw(Bounds());         
 653         }else{
 654                 if(iOldCursor>=0) DrawItem(this,iOldCursor,true);
 655                 DrawItem(this,iNavCursorIndex,true);            
 656         }
 657         if(iStyle & BF_GUI_DLGVIEW_VMENU_NAV_PARENTINFORM){
 658                 BMessenger oMessenger(Parent());
 659                 BMessage   oMessage(BF_MSG_DIALOG_VMENU_NAV);
 660                 oMessage.AddString("bf_name",Name());
 661                 oMessage.AddInt32("bf_index",iNavCursorIndex);
 662                 oMessage.AddInt32("bf_oldindex",iOldCursor);
 663                 oMessenger.SendMessage(&oMessage);
 664         }
 665         
 666         if(poVScroll) poVScroll->SetCursor(iNavCursorIndex);
 667 }
 668 /*================================================================*/
 669 BF_GUI_DlgView_VCMenu_Column::BF_GUI_DlgView_VCMenu_Column(const char *pc_ColName,float f_Width)
 670 {
 671         ASSERT(pc_ColName);
 672         sName = pc_ColName;
 673         fWidth = f_Width;
 674 }
 675 
 676 BF_GUI_DlgView_VCMenu::BF_GUI_DlgView_VCMenu(
 677         const BRect     &o_Rect,
 678         const char      *pc_Name,
 679         uint32  i_FollowType,
 680         BL_List *plo_Menu,
 681         uint32  i_Style,
 682         BL_List  *plo_Col)
 683 :BF_GUI_DlgView_VMenu(o_Rect,pc_Name,i_FollowType,plo_Menu,i_Style)
 684 {
 685         ASSERT(plo_Col);
 686         ploCol = plo_Col;
 687 }
 688 
 689 BF_GUI_DlgView_VCMenu::~BF_GUI_DlgView_VCMenu()
 690 {
 691         DELETE(ploCol);
 692 }
 693 
 694 
 695 void                                    
 696 BF_GUI_DlgView_VCMenu::DrawItem(BView *po_Render,int32 i_Index,bool b_ReqDrawBack)    /* [previous][next][first][last][top][bottom][index][help] */
 697 {
 698         if(!po_Render) po_Render = this;        
 699         //
 700         bool    bListFocused = IsFocus();
 701         bool    bItemFocused = i_Index==iNavCursorIndex;
 702         BPoint  oPoint(0,0);            
 703         oPoint.y += ((float)(i_Index-iFirstIndex)) * Height();
 704         //
 705         if(bListFocused || b_ReqDrawBack){
 706                 SetColor_Back(po_Render,bListFocused && bItemFocused);
 707                 BRect oRect =po_Render->Bounds();
 708                 oRect.top = oPoint.y;
 709                 oRect.bottom = oRect.top+poFont->fHeight;
 710                 po_Render->FillRect(oRect);
 711         }                       
 712         
 713         // check for empty index
 714         if(i_Index<0) return;
 715         
 716         // get item 
 717         BF_GUI_ViewMenu_Item *po;
 718         po = (BF_GUI_ViewMenu_Item*)ploMenu->ItemAt(i_Index);
 719         if(!po) return;
 720         
 721         SetColor_Text(po_Render,bItemFocused,po);
 722         if(po->sTitle!=""){
 723                 if(iStyle & BF_GUI_DLGVIEW_VMENU_SICON){
 724                         if(po->poSIcon){
 725                                 po_Render->SetDrawingMode(B_OP_ALPHA);                          
 726                                 po_Render->DrawBitmap(po->poSIcon,oPoint);
 727                                 po_Render->SetDrawingMode(B_OP_COPY);
 728                         }
 729                         oPoint.x+=20;
 730                 }               
 731                 //
 732                 BF_GUI_ViewMenu_Item *poColData;
 733                 BF_GUI_DlgView_VCMenu_Column    *poColInfo;
 734                 BPoint  o1,o2;
 735                 o1.y=oPoint.y;
 736                 o2.y=oPoint.y+Height();
 737                 oPoint.y += poFont->fAscent;
 738                 for(int32 i=-1;i<po->loColItem.CountItems();i++){               
 739                         poColInfo = (BF_GUI_DlgView_VCMenu_Column*)ploCol->ItemAt(i+1);
 740                         ASSERT(poColInfo);
 741                         //
 742                         if(i>=0){
 743                                 o1.x = oPoint.x;
 744                                 o2.x = oPoint.x;
 745                                 po_Render->StrokeLine(o1,o2);
 746                         }
 747                         oPoint.x+=3;
 748                         //
 749                         if(i<0) poColData = po;else poColData = (BF_GUI_ViewMenu_Item*)po->loColItem.ItemAt(i);
 750                         if(poColData){
 751                                 int iLength = BF_GUI_GetTextLength(poColData->sTitle,poColInfo->fWidth-6,poFont->oFont);
 752                                 po_Render->DrawString(poColData->sTitle.String(),iLength,oPoint);
 753                         }
 754                         oPoint.x+=poColInfo->fWidth-3;                  
 755                 }
 756         }else{
 757                 oPoint.x = 4.0;
 758                 oPoint.y+=Height()/2;
 759                 BRect oRect(po_Render->Bounds());
 760                 BPoint oPointEnd(oRect.right-4.0,oPoint.y);
 761                 po_Render->StrokeLine(oPoint,oPointEnd);
 762         }
 763         //
 764 }
 765 
 766 /*================================================================*/
 767 BF_GUI_DlgView_HMenu::BF_GUI_DlgView_HMenu(
 768         const BRect     &o_Rect,
 769         const char      *pc_Name,
 770         uint32  i_FollowType,
 771         BL_List *plo_Menu)
 772 :BF_GUI_DlgView_Menu(o_Rect,pc_Name,i_FollowType,plo_Menu)
 773 {
 774         bItemsInCenter = true;
 775         // calc width for every item //
 776         BF_GUI_ViewMenu_Item *po;
 777         fItemsWidth=0;
 778         for(int i=0;i<ploMenu->CountItems();i++){
 779                 po = (BF_GUI_ViewMenu_Item*)ploMenu->ItemAt(i);
 780                 po->CalcWidth(poFont);
 781                 fItemsWidth+=po->fWidth+10;
 782                 if(i>0) fItemsWidth+=10;
 783         }               
 784 }
 785 //
 786 float
 787 BF_GUI_DlgView_HMenu::CalcItemXPos(int32 i_Index)    /* [previous][next][first][last][top][bottom][index][help] */
 788 {
 789         float fx=0;
 790         if(bItemsInCenter) fx += Bounds().Width()/2-fItemsWidth/2;
 791         //
 792         {// calc width of all prev.items
 793                 BF_GUI_ViewMenu_Item *po;
 794                 for(int i=0;i<i_Index;i++){
 795                         po = (BF_GUI_ViewMenu_Item*)ploMenu->ItemAt(i);
 796                         fx += po->fWidth+10;
 797                 }
 798         }       
 799         return fx;
 800 }
 801 
 802 void                                    
 803 BF_GUI_DlgView_HMenu::DrawItem(BView *po_Render,int32 i_Index,bool b_ReqDrawBack)    /* [previous][next][first][last][top][bottom][index][help] */
 804 {
 805         BPoint  oPoint(CalcItemXPos(i_Index),0);                                        
 806         bool    bListFocused = IsFocus();
 807         bool    bItemFocused = i_Index==iNavCursorIndex;
 808         //
 809         BF_GUI_ViewMenu_Item *po;
 810         po = (BF_GUI_ViewMenu_Item*)ploMenu->ItemAt(i_Index);
 811         if(!po) return;
 812         //
 813         if(bListFocused || b_ReqDrawBack){
 814                 SetColor_Back(po_Render,bListFocused && bItemFocused);
 815                 BRect oRect = po_Render->Bounds();
 816                 oRect.left = oPoint.x;
 817                 oRect.right = oRect.left+po->fWidth+10;
 818                 po_Render->FillRect(oRect);                             
 819         }
 820         //      
 821         SetColor_Text(po_Render,bItemFocused);  
 822         if(bItemFocused) Draw_FocusItemPointer(oPoint,po_Render);               
 823         
 824         oPoint.y += poFont->fAscent;
 825         oPoint.x += 10;
 826         po_Render->DrawString(po->sTitle.String(),oPoint);
 827         //      
 828 }
 829 
 830 void                                    
 831 BF_GUI_DlgView_HMenu::MouseDown(BPoint point)    /* [previous][next][first][last][top][bottom][index][help] */
 832 {       
 833         if(!(Flags() & B_NAVIGABLE)) return;
 834         
 835         BRect   oRect(Bounds());
 836         BPoint  oPointStart(bItemsInCenter?(oRect.Width()/2-fItemsWidth/2):0,0);                        
 837 
 838         {// calc width of all prev.items
 839                 BF_GUI_ViewMenu_Item *po;
 840                 for(int i=0;i<ploMenu->CountItems();i++){
 841                         po = (BF_GUI_ViewMenu_Item*)ploMenu->ItemAt(i);
 842                         oPointStart.x += po->fWidth+10;
 843                         if(oPointStart.x>=point.x){
 844                                 if(i!=iNavCursorIndex){
 845                                         NavChangeCursor(i,BF_GUI_TOOLMENU_MOVE_POS);
 846                                         NavEnter();
 847                                 }else{
 848                                         NavEnter();
 849                                 }
 850                                 break;
 851                         }
 852                 }
 853         }
 854 }
 855 

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