root/BF_GUI_OperRoster.cpp

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

DEFINITIONS

This source file includes following definitions.
  1. BF_GUI_OperRoster_Draw_Progress
  2. State
  3. Ask_Message
  4. Ask_Error
  5. Ask_Copy_FileExist
  6. DePause
  7. Canceled
  8. Cancel
  9. Pause
  10. Run
  11. Finished
  12. SetProgress
  13. BF_GUI_OperTask_Thread
  14. RunThread
  15. DrawProg
  16. Draw
  17. MouseDown
  18. Draw
  19. Task_Pause
  20. Task_Cancel
  21. Minimaze
  22. MessageReceived
  23. PrepareKeysMenu
  24. Enable
  25. StoreCurrentFocus
  26. Check_ScreenWaiting
  27. SetFocusToOld
  28. MessageReceived
  29. UpdateLenta
  30. UpdateDialog
  31. CalcTotalProg
  32. AddTask
  33. CanMinimase
  34. SetViewMode
  35. TaskAt
  36. Close
  37. fHeightInWinMain
  38. BF_GUI_OperRoster_Init
  39. BF_GUI_OperRoster_AddTask

   1 #include <stdio.h>
   2 #include <Autolock.h>
   3 #include "BF_Dict.h"  
   4 #include "BF_GUI_WinMain.h"  
   5 #include "BF_GUI_Func.h"  
   6 #include "BF_GUI_KeysMenu.h"  
   7 #include "BF_GUI_OperRoster.h"  
   8 #include "BF_GUI_CmdLine.h"  
   9 
  10 
  11 BF_GUI_OperRoster *poOperRoster = NULL;
  12 
  13 void                                                    
  14 BF_GUI_OperRoster_Draw_Progress(BView *po_Render,const BRect & o_Rect,uint64 i_Index,uint64 i_Count,const char *pc_Text)    /* [previous][next][first][last][top][bottom][index][help] */
  15 {
  16         ASSERT(po_Render);
  17         BRect   oRect;  
  18         float   fDelta = i_Count<=0?i_Count:(o_Rect.Width()-10.0) / (float)i_Count ;
  19         ///
  20         oRect = o_Rect;
  21         oRect.right = oRect.left +(float)i_Index * fDelta;
  22         po_Render->SetHighColor(SYS_COLOR(BF_COLOR_DIALOG_PROGRESS_FILLED));
  23         po_Render->FillRect(oRect/*,B_MIXED_COLORS*/);
  24         //
  25         oRect.left = oRect.right+1;
  26         oRect.right = o_Rect.right;
  27         po_Render->SetHighColor(SYS_COLOR(BF_COLOR_DIALOG_PROGRESS_EMPTY));
  28         po_Render->FillRect(oRect);
  29         //
  30         /* draw text */ 
  31         BL_String s,s1;
  32         s<< pc_Text;
  33         s<<" ";
  34         //
  35         s1=i_Index;
  36         s1.SetDigits();
  37         s<<s1;
  38         s<<BF_DictAt(BF_DICT_ROSTER_OFF);
  39         //
  40         s1=i_Count;
  41         s1.SetDigits();
  42         s<<s1;
  43         //oRect = o_Rect;
  44         float fWidth = poSysSetup->oFontToolView.oFont.StringWidth(s.String());
  45         BPoint oPoint(o_Rect.Width()/2-fWidth/2,o_Rect.top + poSysSetup->oFontToolView.fAscent);
  46         po_Render->SetHighColor(SYS_COLOR(BF_COLOR_DIALOG_BUTTON_TEXT));
  47         po_Render->SetLowColor(SYS_COLOR(BF_COLOR_DIALOG_BACK));
  48         po_Render->SetDrawingMode(B_OP_INVERT);
  49         po_Render->DrawString(s.String(),oPoint);               
  50         po_Render->SetDrawingMode(B_OP_COPY);
  51 }
  52 ///////////////////////////////////////////////////////////////////////////
  53 BF_GUI_OperTask::BF_GUI_OperTask(const char *pc_Name,int32 i_Styles)
  54 {
  55         ASSERT(poWin && pc_Name);
  56         sName = pc_Name;
  57         iStyles = i_Styles;
  58         iState = BF_GUI_OPERTASK_STATE_PRESTART;
  59         idThread = 0;   
  60         iLastProgressTime = 0;
  61         
  62         iTotalCount = 0;
  63         iTotalIndex = 0;
  64         
  65         bReqCancel = false;     
  66         bWaitingScreen = false;
  67         
  68         iLastCopyAnswer = BF_GUI_OPERTASK_COPY_DEFAULT;
  69 }
  70 
  71 BF_GUI_OperTask::~BF_GUI_OperTask()
  72 {
  73 }
  74 
  75 int32                                                   
  76 BF_GUI_OperTask::State()    /* [previous][next][first][last][top][bottom][index][help] */
  77 {
  78         return iState;
  79 }
  80 
  81 int32
  82 BF_GUI_OperTask::Ask_Message(const char *pc_Message,BL_List *plo_MenuItem,const char *pc_ExtMessage)    /* [previous][next][first][last][top][bottom][index][help] */
  83 {
  84         ASSERT(pc_Message);
  85         
  86         // wait free screen     
  87         bWaitingScreen = true;
  88         
  89         { //  roster,please, free screen
  90                 oMessage.MakeEmpty();
  91                 oMessage.what = BF_MSG_TO_OPERROSTER_TASK_WAITING_SCREEN;
  92                 oMessage.AddPointer("bf_poTask",this);
  93                 BMessenger oMessenger(poOperRoster);
  94                 oMessenger.SendMessage(&oMessage);              
  95         }
  96         
  97         while(bWaitingScreen){                  
  98                 snooze(20000);
  99                 //bWaitingScreen = false;
 100         }
 101                 
 102         int32 iResult = BF_Dialog_Alert(BF_DictAt(BF_DICT_ROSTER_INFO),pc_Message,plo_MenuItem,pc_ExtMessage);
 103         
 104         // free screen
 105         {
 106                 oMessage.MakeEmpty();
 107                 oMessage.what = BF_MSG_TO_OPERROSTER_TASK_FREE_SCREEN;
 108                 oMessage.AddPointer("bf_poTask",this);
 109                 BMessenger oMessenger(poOperRoster);
 110                 oMessenger.SendMessage(&oMessage);      
 111         }               
 112         
 113         return iResult;
 114 }
 115 
 116 BF_GUI_OperTask_Error_Answer            
 117 BF_GUI_OperTask::Ask_Error(const char *pc_Message,bool b_AskAdditional, const char *pc_ExtMessage)    /* [previous][next][first][last][top][bottom][index][help] */
 118 {
 119         ASSERT(pc_Message);
 120         
 121         BL_List *ploMenu = new BL_List();
 122         ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_OK),""));
 123         if(b_AskAdditional){
 124                 ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_CANCELALL),""));
 125         }
 126         
 127         int32 iResult = Ask_Message(pc_Message,ploMenu,pc_ExtMessage);
 128                         
 129         // return result
 130         if(iResult==0)  return BF_GUI_OPERTASK_ERROR_OK;
 131         if(iResult==1)  return BF_GUI_OPERTASK_ERROR_CANCEL_ALL;
 132         return BF_GUI_OPERTASK_ERROR_OK;
 133 }
 134 
 135 BF_GUI_OperTask_Copy_Answer             
 136 BF_GUI_OperTask::Ask_Copy_FileExist(const char *pc_NodeName,bool b_AskAboutAppend)    /* [previous][next][first][last][top][bottom][index][help] */
 137 {
 138         ASSERT(pc_NodeName);    
 139         
 140         // check for all 
 141         if(iLastCopyAnswer!=BF_GUI_OPERTASK_COPY_DEFAULT) return iLastCopyAnswer;
 142         
 143         // wait free screen     
 144         bWaitingScreen = true;
 145         
 146         { //  roster,please, free screen
 147                 oMessage.MakeEmpty();
 148                 oMessage.what = BF_MSG_TO_OPERROSTER_TASK_WAITING_SCREEN;
 149                 oMessage.AddPointer("bf_poTask",this);
 150                 BMessenger oMessenger(poOperRoster);
 151                 oMessenger.SendMessage(&oMessage);              
 152         }
 153         
 154         while(bWaitingScreen){                  
 155                 snooze(20000);
 156                 //bWaitingScreen = false;
 157         }
 158         
 159         BL_String s(BF_DictAt(BF_DICT_ROSTER_FILE));
 160         s<<pc_NodeName;
 161         s<<BF_DictAt(BF_DICT_ROSTER_EXISTS);
 162         
 163         BL_List *ploMenu = new BL_List();
 164         ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_OWERWRITE),"overwrite"));
 165         ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_SKIP),"skip"));
 166         ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_OWERWRITEALL),"overwrite_all"));
 167         ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_SKIPALLERRORS),"skip_all"));
 168         ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_CANCEL),"cancel"));
 169         if(b_AskAboutAppend) ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_APPEND),"appens"));
 170         
 171         int32 iResult = BF_Dialog_Alert(BF_DictAt(BF_DICT_ROSTER_COPYASK),s.String(),ploMenu);
 172         
 173         // free screen
 174         {
 175                 oMessage.MakeEmpty();
 176                 oMessage.what = BF_MSG_TO_OPERROSTER_TASK_FREE_SCREEN;
 177                 oMessage.AddPointer("bf_poTask",this);
 178                 BMessenger oMessenger(poOperRoster);
 179                 oMessenger.SendMessage(&oMessage);      
 180         }               
 181                         
 182         // return result //
 183         BF_GUI_OperTask_Copy_Answer iAnswer = BF_GUI_OPERTASK_COPY_DEFAULT;
 184         switch(iResult){
 185         case 0:
 186                 iAnswer =  BF_GUI_OPERTASK_COPY_OVERWRITE;
 187                 break;  
 188         case 1:
 189                 iAnswer =  BF_GUI_OPERTASK_COPY_SKIP;
 190                 break;
 191         case 2:
 192                 iAnswer =  BF_GUI_OPERTASK_COPY_OVERWRITE;
 193                 iLastCopyAnswer = iAnswer;
 194                 break;
 195         case 3:
 196                 iAnswer =  BF_GUI_OPERTASK_COPY_SKIP;
 197                 iLastCopyAnswer = iAnswer;
 198                 break;          
 199         case 4:
 200                 iAnswer =  BF_GUI_OPERTASK_COPY_CANCEL;
 201                 break;
 202         case 5:
 203                 ASSERT(b_AskAboutAppend);
 204                 iAnswer =  BF_GUI_OPERTASK_COPY_APPEND;
 205                 break;          
 206         default:
 207                 iAnswer = BF_GUI_OPERTASK_COPY_SKIP;
 208         };
 209                 
 210         return iAnswer;
 211 }
 212 
 213 bool                                                    
 214 BF_GUI_OperTask::DePause()    /* [previous][next][first][last][top][bottom][index][help] */
 215 {
 216         if(BF_GUI_OPERTASK_STATE_PAUSE!=iState) return false;   
 217         if(B_OK!=resume_thread(idThread)) return false;
 218         
 219         iState = BF_GUI_OPERTASK_STATE_RUN;
 220         
 221         oMessage.MakeEmpty();
 222         oMessage.what = BF_MSG_TO_OPERROSTER_SETPROGRESS;
 223         oMessage.AddPointer("bf_poTask",this);
 224         BMessenger oMessenger(poOperRoster);
 225         oMessenger.SendMessage(&oMessage);
 226         
 227         return true;
 228 }
 229 
 230 bool                                                    
 231 BF_GUI_OperTask::Canceled()    /* [previous][next][first][last][top][bottom][index][help] */
 232 {
 233         return bReqCancel;
 234 }
 235 
 236 bool
 237 BF_GUI_OperTask::Cancel()    /* [previous][next][first][last][top][bottom][index][help] */
 238 {
 239         switch(State()){
 240         case BF_GUI_OPERTASK_STATE_PAUSE:
 241                 DePause();      
 242                 break;
 243         }               
 244         bReqCancel = true;              
 245         return true;
 246 }
 247 
 248 bool
 249 BF_GUI_OperTask::Pause()    /* [previous][next][first][last][top][bottom][index][help] */
 250 {
 251 
 252         if(BF_GUI_OPERTASK_STATE_RUN!=iState) return false;     
 253         if(B_OK!=suspend_thread(idThread)) return false;
 254         
 255         iState = BF_GUI_OPERTASK_STATE_PAUSE;
 256         
 257         oMessage.MakeEmpty();
 258         oMessage.what = BF_MSG_TO_OPERROSTER_TASK_PAUSED;
 259         oMessage.AddPointer("bf_poTask",this);
 260         BMessenger oMessenger(poOperRoster);
 261         oMessenger.SendMessage(&oMessage);
 262         
 263         
 264         return true;
 265 }
 266 
 267 void                                                    
 268 BF_GUI_OperTask::Run()    /* [previous][next][first][last][top][bottom][index][help] */
 269 {                       
 270 }
 271 
 272 void
 273 BF_GUI_OperTask::Finished()    /* [previous][next][first][last][top][bottom][index][help] */
 274 {
 275         oMessage.MakeEmpty();
 276         oMessage.what = BF_MSG_TO_OPERROSTER_TASK_FINISHED;
 277         oMessage.AddPointer("bf_poTask",this);
 278         BMessenger oMessenger(poOperRoster);
 279         oMessenger.SendMessage(&oMessage);              
 280 }
 281 
 282 void                                                    
 283 BF_GUI_OperTask::SetProgress(uint64 i_TotalIndex,uint64 i_TotalCount)    /* [previous][next][first][last][top][bottom][index][help] */
 284 {
 285         iTotalCount = i_TotalCount;
 286         iTotalIndex = i_TotalIndex;
 287         
 288         if(iTotalCount<iTotalIndex){
 289                 int32 i=0;
 290                 i++;    
 291         }
 292         
 293         if((iLastProgressTime>0) && (real_time_clock_usecs() - iLastProgressTime)<500000) return;
 294         iLastProgressTime = real_time_clock_usecs();
 295         //printf("iLastProgressTime = %i\n",iLastProgressTime);
 296 
 297         oMessage.MakeEmpty();
 298         oMessage.what = BF_MSG_TO_OPERROSTER_SETPROGRESS;
 299         oMessage.AddPointer("bf_poTask",this);
 300         //oMessage.AddString("bf_pcText",s.String());
 301         BMessenger oMessenger(poOperRoster);
 302         oMessenger.SendMessage(&oMessage);              
 303         
 304         return;
 305 }
 306 
 307 
 308 int32 
 309 BF_GUI_OperTask_Thread(void *data)    /* [previous][next][first][last][top][bottom][index][help] */
 310 {
 311 
 312         BF_GUI_OperTask *poTask = (BF_GUI_OperTask*)data;
 313         ASSERT(poTask);
 314         poTask->iState = BF_GUI_OPERTASK_STATE_RUN;
 315         poTask->Run();
 316         poTask->Finished();             
 317         
 318         return 0;
 319 }
 320 
 321 void                                                    
 322 BF_GUI_OperTask::RunThread()    /* [previous][next][first][last][top][bottom][index][help] */
 323 {                       
 324         idThread = spawn_thread(BF_GUI_OperTask_Thread,"opertask_thread",B_THREAD_SUSPENDED,(void*)this);       
 325         ASSERT(idThread>0,"can`t start opertask_thread\n");     
 326         ASSERT(B_OK==resume_thread(idThread));          
 327         set_thread_priority(idThread,1);        
 328 }
 329 
 330 ///////////////////////////////////////////////////////////////////////////
 331 
 332 BF_GUI_OperRoster_Lenta::BF_GUI_OperRoster_Lenta()
 333 :BView(BRect(-1,-1,-1,-1),"operroster_lenta",B_FOLLOW_LEFT_RIGHT|B_FOLLOW_BOTTOM,B_WILL_DRAW)
 334 {
 335         iLastProgressTime = 0;
 336         iProgCount = 0;
 337         iProgIndex = 0;
 338         //
 339         SetFont(&poSysSetup->oFontToolView.oFont);
 340         SetViewColor(B_TRANSPARENT_COLOR);              
 341         //
 342         fSizeY = (int32)poSysSetup->oFontToolView.fHeight+2;
 343         //
 344         BMessenger oMessenger(poWinView);
 345         BMessage   oMessage(BF_MSG_TO_WIN_OPERLENTA_SHOWED);
 346         oMessage.AddInt32("bf_iSizeY",fSizeY+1);
 347         oMessenger.SendMessage(&oMessage);
 348         //
 349         BRect oRect;
 350         if(poCmdLine){
 351                 oRect = poCmdLine->Frame();
 352         }else
 353         if(poSysKeysMenu){
 354                 oRect = poSysKeysMenu->Frame();
 355         }else
 356                 ASSERT(false);
 357         //oRect.bottom = poSysSetup->oFontCMDLine.fHeight + poSysSetup->oFontNode.fHeight -2;
 358         oRect.bottom = oRect.top-1;
 359         oRect.top = oRect.bottom - fSizeY;
 360         
 361         MoveTo(oRect.left,oRect.top);
 362         ResizeTo(oRect.Width(),oRect.Height()); 
 363         //              
 364 }
 365 BF_GUI_OperRoster_Lenta::~BF_GUI_OperRoster_Lenta()
 366 {
 367         BMessenger oMessenger(poWinView);
 368         BMessage   oMessage(BF_MSG_TO_WIN_OPERLENTA_SHOWED);
 369         oMessage.AddInt32("bf_iSizeY",(int32)(-1-fSizeY));
 370         oMessenger.SendMessage(&oMessage);      
 371 }
 372 
 373 void                                                    
 374 BF_GUI_OperRoster_Lenta::DrawProg(uint64 i_Index,uint64 i_Count,bool b_MustDraw)    /* [previous][next][first][last][top][bottom][index][help] */
 375 {
 376         iProgCount = i_Count;
 377         iProgIndex = i_Index;
 378         if(!b_MustDraw && (iLastProgressTime>0) && (real_time_clock_usecs() - iLastProgressTime)<500000) return;
 379         iLastProgressTime = real_time_clock_usecs();    
 380         Draw(Bounds());
 381 }
 382 
 383 void
 384 BF_GUI_OperRoster_Lenta::Draw(BRect o_Rect)    /* [previous][next][first][last][top][bottom][index][help] */
 385 {
 386         BRect oRect(Bounds());
 387         SetHighColor(SYS_COLOR(BF_COLOR_BACK));
 388         FillRect(oRect);                
 389         
 390         oRect.left++;
 391         oRect.right--;
 392         oRect.top++;
 393         oRect.bottom--;         
 394         BF_GUI_OperRoster_Draw_Progress(this,oRect,iProgIndex,iProgCount,BF_DictAt(BF_DICT_ROSTER_OPERPROGRESS));
 395                 
 396         /*
 397         SetHighColor(SYS_COLOR(BF_COLOR_NODE));
 398         SetLowColor(SYS_COLOR(BF_COLOR_BACK));
 399         BL_String s;
 400         s<<"a zdes tipa kompaktniy variant progress-barov :) click me  ";
 401         s<<sText;       
 402         DrawString(s.String(),BPoint(0,poSysSetup->oFontToolView.fAscent));*/
 403 }
 404 
 405 void                                                    
 406 BF_GUI_OperRoster_Lenta::MouseDown(BPoint point)    /* [previous][next][first][last][top][bottom][index][help] */
 407 {
 408         BMessage oMessage(BF_MSG_TO_OPERROSTER_CLOSELENTA);
 409         BMessenger oMessenger(poOperRoster);
 410         oMessenger.SendMessage(&oMessage);              
 411 }
 412 
 413 ///////////////////////////////////////////////////////////////////////////
 414 BF_GUI_OperRoster_Dialog_Item::BF_GUI_OperRoster_Dialog_Item(
 415         const char *pc_StatText,
 416         int i_TaskState)
 417 :BF_GUI_ViewMenu_Item(" ","")
 418 {
 419         sStatText = pc_StatText;
 420         iProgCount = 0;
 421         iProgIndex = 0; 
 422         iTaskState = i_TaskState;
 423 }
 424 void                                                    
 425 BF_GUI_OperRoster_Dialog_Item::Draw(BF_GUI_DlgView_Menu *po_Parent,BView *po_Render,float f_PosY)    /* [previous][next][first][last][top][bottom][index][help] */
 426 {
 427         po_Parent->SetColor_Text(po_Render,po_Parent->IsFocus());
 428         
 429         BPoint oPoint(10,f_PosY);
 430         oPoint.y += poSysSetup->oFontToolView.fAscent;
 431         po_Render->DrawString(sStatText.String(),oPoint);       
 432         
 433         BRect oRect;
 434         oRect.Set(10,f_PosY+poSysSetup->oFontToolView.fHeight,
 435                 po_Render->Bounds().Width()-10,f_PosY + poSysSetup->oFontToolView.fHeight*2);
 436                 
 437         switch(iTaskState){
 438         case BF_GUI_OPERTASK_STATE_PRESTART:            
 439                 oPoint.y += poSysSetup->oFontToolView.fHeight+1;
 440                 po_Render->DrawString(BF_DictAt(BF_DICT_ROSTER_PREPARING),oPoint);
 441                 break;
 442         case BF_GUI_OPERTASK_STATE_PAUSE:               
 443                 BF_GUI_OperRoster_Draw_Progress(po_Render,oRect,iProgIndex,iProgCount,BF_DictAt(BF_DICT_ROSTER_PAUSED));
 444                 /*oPoint.y += poSysSetup->oFontToolView.fHeight+1;
 445                 po_Render->DrawString(" paused ",oPoint);       */
 446                 break;
 447         case BF_GUI_OPERTASK_STATE_RUN:
 448                 BF_GUI_OperRoster_Draw_Progress(po_Render,oRect,iProgIndex,iProgCount,BF_DictAt(BF_DICT_ROSTER_TOTAL));
 449                 break;
 450         };
 451 }
 452 ///////////////////////////////////////////////////////////////////////////
 453 
 454 BF_GUI_OperRoster_Dialog::BF_GUI_OperRoster_Dialog(const BRect & o_Rect)
 455  :BF_GUI_Dialog(o_Rect,BF_DictAt(BF_DICT_ROSTER_TITLE),"operroster_dialog",BMessage(),BG_GUI_DIALOG_WINRESIZE_RESIZE_ALL)
 456 {
 457 }
 458 
 459 void
 460 BF_GUI_OperRoster_Dialog::Task_Pause(int i_TaskIndex)    /* [previous][next][first][last][top][bottom][index][help] */
 461 {       
 462         BF_GUI_OperTask* poTask = poOperRoster->TaskAt(i_TaskIndex);    
 463         if(!poTask) return;
 464 
 465         switch(poTask->State()){
 466         case BF_GUI_OPERTASK_STATE_RUN:
 467                 poTask->Pause();        
 468                 break;
 469         case BF_GUI_OPERTASK_STATE_PAUSE:
 470                 poTask->DePause();      
 471                 break;
 472         }       
 473         
 474 }
 475 
 476 void
 477 BF_GUI_OperRoster_Dialog::Task_Cancel(int i_TaskIndex)    /* [previous][next][first][last][top][bottom][index][help] */
 478 {       
 479         BF_GUI_OperTask* poTask = poOperRoster->TaskAt(i_TaskIndex);    
 480         if(!poTask) return;
 481         
 482         poTask->Cancel();
 483 }
 484 
 485 void
 486 BF_GUI_OperRoster_Dialog::Minimaze()    /* [previous][next][first][last][top][bottom][index][help] */
 487 {
 488         if(!poOperRoster->CanMinimase()) return;
 489         //
 490         BMessage oMessage(BF_MSG_TO_OPERROSTER_CLOSEDIALOG);
 491         BMessenger oMessenger(poOperRoster);
 492         oMessenger.SendMessage(&oMessage);              
 493         //
 494         RemoveSelf();
 495         delete this;    
 496 }
 497 
 498 void
 499 BF_GUI_OperRoster_Dialog::MessageReceived(BMessage* po_Message)    /* [previous][next][first][last][top][bottom][index][help] */
 500 {
 501         switch(po_Message->what){
 502         case BF_MSG_DIALOG_PRESSED_CANCEL:{
 503                 Minimaze();
 504                 break;}
 505         case BF_MSG_DIALOG_PRESSED_OK:{
 506                 BF_GUI_DialogView *poView;
 507                 ASSERT(B_OK==po_Message->FindPointer("bf_DlgView_Focus",(void**)&poView) && poView);
 508                 if(strcmp( poView->Name(),"menu")==0){
 509                         BF_GUI_DlgView_Menu *poMenu = (BF_GUI_DlgView_Menu*)poView;
 510                         
 511                         switch(poMenu->iNavCursorIndex){
 512                         case 0:{ // pause                                                               
 513                                 if(!poTasksMenu) return;
 514                                 Task_Pause(poTasksMenu->iNavCursorIndex);
 515                                 break;}
 516                         case 1:{ // cancel
 517                                 if(!poTasksMenu) return;
 518                                 Task_Cancel(poTasksMenu->iNavCursorIndex);
 519                                 break;}
 520                         case 2:{ // minimase
 521                                 Minimaze();
 522                                 break;}
 523                         }
 524                 }
 525                 break;}
 526         default:
 527                 BF_GUI_Dialog::MessageReceived(po_Message);
 528         };
 529 }
 530 
 531 void
 532 BF_GUI_OperRoster_Dialog::PrepareKeysMenu(bool b_Init)    /* [previous][next][first][last][top][bottom][index][help] */
 533 {
 534         /*
 535         if(b_Init){
 536                 poSysKeysMenu->Clear(this);
 537                         
 538                 poSysKeysMenu->SetText(3,"Pause");
 539                 poSysKeysMenu->SetMessage(3,new BMessage(BF_MSG_TO_OPERROSTERDIALOG_TASK_PAUSED),this);                 
 540         }               
 541         */
 542 }
 543 
 544 ///////////////////////////////////////////////////////////////////////////
 545 
 546 BF_GUI_OperRoster::BF_GUI_OperRoster()
 547 {
 548         iViewMode = BF_GUI_OPERROSTER_VIEW_HIDED;
 549         sOldFocusViewName = "";
 550         iDisableCount = 0;
 551         //
 552         {
 553                 ASSERT(poWin); 
 554                 LOCK_WIN();
 555                 poWin->AddHandler(this);
 556         }
 557         //
 558         poOperRoster = this;
 559 }
 560 
 561 BF_GUI_OperRoster::~BF_GUI_OperRoster()
 562 {
 563         LOCK_WIN();
 564         poWin->RemoveHandler(this);     
 565 }
 566 
 567 void                                                    
 568 BF_GUI_OperRoster::Enable(bool b_Enable)    /* [previous][next][first][last][top][bottom][index][help] */
 569 {
 570         iDisableCount += !b_Enable?+1:-1;       
 571         
 572         if(iDisableCount==0){
 573                 // enable lenta
 574                 UpdateLenta(true);
 575                 // 
 576                 Check_ScreenWaiting();          
 577                 // enable dialog
 578                 BF_GUI_OperRoster_Dialog* poOperDialog = (BF_GUI_OperRoster_Dialog*)poWin->FindView("operroster_dialog");
 579                 if(poOperDialog) poOperDialog->EnableDialog(true);
 580         }else
 581         if(iDisableCount==1){
 582                 // disable dialog
 583                 BF_GUI_OperRoster_Dialog* poOperDialog = (BF_GUI_OperRoster_Dialog*)poWin->FindView("operroster_dialog");
 584                 if(poOperDialog) poOperDialog->EnableDialog(false);
 585         }
 586 }
 587 
 588 void
 589 BF_GUI_OperRoster::StoreCurrentFocus()    /* [previous][next][first][last][top][bottom][index][help] */
 590 {
 591         sOldFocusViewName = "";
 592         BView *poView =poWin->CurrentFocus();
 593         if(!poView) return;
 594         sOldFocusViewName = poView->Name();
 595 }
 596 
 597 void
 598 BF_GUI_OperRoster::Check_ScreenWaiting()    /* [previous][next][first][last][top][bottom][index][help] */
 599 {
 600         if(iDisableCount!=0) return;
 601         
 602         BF_GUI_OperTask *poTask;
 603         for(int i=0;i<loTask.CountItems();i++){
 604                 poTask = TaskAt(i);
 605                 if(!poTask->bWaitingScreen) continue;
 606                 
 607                 Enable(false);
 608                 if(BF_GUI_OPERROSTER_VIEW_LENTA==iViewMode){            
 609                         StoreCurrentFocus();
 610                         BF_GUI_Func_PanelsEnable( false,false );                        
 611                 }
 612                 poTask->bWaitingScreen = false;
 613         }
 614 }
 615 
 616 void
 617 BF_GUI_OperRoster::SetFocusToOld()    /* [previous][next][first][last][top][bottom][index][help] */
 618 {
 619         ASSERT(sOldFocusViewName!="","BF_GUI_OperRoster::SetFocusToOld():sOldFocusViewName=''");
 620 
 621         BAutolock oLocker(poWin);
 622         
 623         BView *poView = poWin->FindView(sOldFocusViewName.String());
 624         ASSERT(poView,"BF_GUI_OperRoster::SetFocusToOld():OldFocusView not found");
 625         
 626         BF_GUI_MakeFocusTo(poView);
 627         sOldFocusViewName = ""; 
 628 }
 629 
 630 void
 631 BF_GUI_OperRoster::MessageReceived(BMessage* po_Message)    /* [previous][next][first][last][top][bottom][index][help] */
 632 {
 633         switch(po_Message->what){
 634         //
 635         case BF_MSG_SETUP_UPDATED:
 636                 break;
 637         //
 638         case BF_MSG_TO_OPERROSTER_TASK_WAITING_SCREEN:{
 639                 Check_ScreenWaiting();          
 640                 break;}
 641         case BF_MSG_TO_OPERROSTER_TASK_FREE_SCREEN:{
 642                 Enable(true);
 643                 if(BF_GUI_OPERROSTER_VIEW_LENTA==iViewMode){
 644                         BF_GUI_Func_PanelsEnable( true,false ); 
 645                         SetFocusToOld();
 646                 }
 647                 break;}
 648         ///////
 649         case BF_MSG_TO_OPERROSTER_TASK_FINISHED:{
 650                 BF_GUI_OperTask *poTask=NULL;
 651                 ASSERT(B_OK==po_Message->FindPointer("bf_poTask",(void**)&poTask) && poTask);
 652                 int iIndex = loTask.IndexOf(poTask);
 653                 ASSERT(iIndex>=0,"BF_MSG_TO_OPERROSTER_TASK_FINISHED");
 654                 
 655                 // remove from dialog
 656                 BF_GUI_OperRoster_Dialog* poOperDialog = (BF_GUI_OperRoster_Dialog*)poWin->FindView("operroster_dialog");
 657                 
 658                 if(poOperDialog && loTask.CountItems()>1){
 659                         poOperDialog->poTasksMenu->DeleteItemAt(iIndex);
 660                 }
 661                                                 
 662                 // delete task
 663                 loTask.RemoveItem(poTask);              
 664                 DELETE(poTask);         
 665                 
 666                 // check existing unfinished tasks
 667                 if(loTask.CountItems()==0){
 668                         Close();
 669                 }
 670                 
 671                 break;}
 672         case BF_MSG_TO_OPERROSTER_CLOSELENTA:
 673                 if(0==iDisableCount)    SetViewMode(BF_GUI_OPERROSTER_VIEW_DIALOG);
 674                 break;
 675         case BF_MSG_TO_OPERROSTER_CLOSEDIALOG:{         
 676                 SetViewMode(BF_GUI_OPERROSTER_VIEW_LENTA);              
 677                 break;}
 678         case BF_MSG_TO_OPERROSTER_TASK_PAUSED:{         
 679                                         
 680                 BF_GUI_OperTask *poTask=NULL;
 681                 ASSERT(B_OK==po_Message->FindPointer("bf_poTask",(void**)&poTask) && poTask);
 682                 int32 iIndex = loTask.IndexOf(poTask);
 683                 if(iIndex<0) return;
 684                 
 685                 switch(iViewMode){
 686                 case BF_GUI_OPERROSTER_VIEW_DIALOG:{
 687                         BF_GUI_OperRoster_Dialog* poOperDialog = (BF_GUI_OperRoster_Dialog*)poWin->FindView("operroster_dialog");
 688                         if(!poOperDialog) return;
 689                         BF_GUI_OperRoster_Dialog_Item *poItem = (BF_GUI_OperRoster_Dialog_Item*)poOperDialog->poTasksMenu->ItemAt(iIndex);
 690                         
 691                         poItem->iTaskState = BF_GUI_OPERTASK_STATE_PAUSE;
 692                         if(iDisableCount==0)  poOperDialog->poTasksMenu->DrawItemExt(poOperDialog->poTasksMenu,iIndex,true);
 693                 
 694                         break;}
 695 /*              case BF_GUI_OPERROSTER_VIEW_LENTA:{
 696                         UpdateLenta();
 697                         break;}*/
 698                 };                      
 699                 break;}
 700         case BF_MSG_TO_OPERROSTER_SETPROGRESS:{
 701                                 
 702                 if(iDisableCount!=0) return;
 703                                         
 704                 BF_GUI_OperTask *poTask=NULL;
 705                 ASSERT(B_OK==po_Message->FindPointer("bf_poTask",(void**)&poTask) && poTask);
 706                 int32 iIndex = loTask.IndexOf(poTask);
 707                 if(iIndex<0) return;
 708                 
 709                 switch(iViewMode){
 710                 case BF_GUI_OPERROSTER_VIEW_DIALOG:{
 711                         BF_GUI_OperRoster_Dialog* poOperDialog = (BF_GUI_OperRoster_Dialog*)poWin->FindView("operroster_dialog");
 712                         if(!poOperDialog) return;
 713                         BF_GUI_OperRoster_Dialog_Item *poItem = (BF_GUI_OperRoster_Dialog_Item*)poOperDialog->poTasksMenu->ItemAt(iIndex);
 714                         poItem->iProgCount = poTask->iTotalCount;
 715                         poItem->iProgIndex = poTask->iTotalIndex;                       
 716                         poItem->iTaskState = BF_GUI_OPERTASK_STATE_RUN;
 717                         poOperDialog->poTasksMenu->DrawItemExt(poOperDialog->poTasksMenu,iIndex,true);
 718                         break;}
 719                 case BF_GUI_OPERROSTER_VIEW_LENTA:{
 720                         UpdateLenta();
 721                         break;}
 722                 };              
 723                 break;}
 724         case BF_MSG_TO_OPERROSTER_ADDTASK:{
 725                 BF_GUI_OperTask *poTask=NULL;
 726                 ASSERT(B_OK==po_Message->FindPointer("bf_poTask",(void**)&poTask) && poTask);
 727                 AddTask(poTask);
 728                 break;}
 729         default:
 730                 BHandler::MessageReceived(po_Message);
 731         }
 732 }
 733 
 734 void
 735 BF_GUI_OperRoster::UpdateLenta(bool b_Must)    /* [previous][next][first][last][top][bottom][index][help] */
 736 {
 737         if(iDisableCount!=0) return;
 738 
 739         if(iViewMode!=BF_GUI_OPERROSTER_VIEW_LENTA) return;
 740         BF_GUI_OperRoster_Lenta *poLenta = (BF_GUI_OperRoster_Lenta*)poWin->FindView("operroster_lenta");
 741         if(!poLenta) return;
 742         uint64 iCount,iIndex;
 743         CalcTotalProg(iCount,iIndex);
 744         poLenta->DrawProg(iIndex,iCount,b_Must);
 745 }
 746 
 747 void
 748 BF_GUI_OperRoster::UpdateDialog()    /* [previous][next][first][last][top][bottom][index][help] */
 749 {
 750         BF_GUI_OperRoster_Dialog* poOperDialog = (BF_GUI_OperRoster_Dialog*)poWin->FindView("operroster_dialog");
 751         if(!poOperDialog) return;
 752         
 753         BF_GUI_OperTask *poTask=NULL;
 754         
 755         for(int i=0;i<poOperDialog->poTasksMenu->ploMenu->CountItems();i++){
 756                 BF_GUI_OperRoster_Dialog_Item *poItem = (BF_GUI_OperRoster_Dialog_Item*)poOperDialog->poTasksMenu->ItemAt(i);
 757                 poTask = TaskAt(i);
 758                 if(!poTask) continue;
 759                 poItem->iProgCount = poTask->iTotalCount;
 760                 poItem->iProgIndex = poTask->iTotalIndex;                       
 761                 poOperDialog->poTasksMenu->DrawItemExt(poOperDialog->poTasksMenu,i,true);       
 762         }       
 763 }
 764 
 765 void
 766 BF_GUI_OperRoster::CalcTotalProg(uint64 & iCount,uint64 & iIndex)    /* [previous][next][first][last][top][bottom][index][help] */
 767 {
 768         BF_GUI_OperTask *poTask;
 769         float f=0,f0=0;
 770         iCount=100;
 771         iIndex=0;
 772         
 773         for(int i=0;i<loTask.CountItems();i++){
 774                 poTask = TaskAt(i);
 775                 f = (float)poTask->iTotalIndex/(float)poTask->iTotalCount*100.0;
 776                 if(i>0) f0 = (f+f0)/2; else f0=f;
 777         }
 778         iIndex = (uint64)f0;
 779 }
 780 
 781 status_t                                                
 782 BF_GUI_OperRoster::AddTask(BF_GUI_OperTask *po_Task)    /* [previous][next][first][last][top][bottom][index][help] */
 783 {
 784         ASSERT(po_Task);
 785         loTask.AddItem(po_Task);        
 786         //
 787         if(poSysSetup->MainStyle() & BF_SETUP_OPERROSTER_DEFDIALOG)
 788                 SetViewMode(BF_GUI_OPERROSTER_VIEW_DIALOG);
 789         else
 790                 SetViewMode(BF_GUI_OPERROSTER_VIEW_LENTA);
 791         
 792         po_Task->RunThread();
 793         
 794         return B_OK;
 795 }
 796 
 797 bool 
 798 BF_GUI_OperRoster::CanMinimase()    /* [previous][next][first][last][top][bottom][index][help] */
 799 {
 800         bool bCanMinimase = true;
 801         for(int i=0;i<loTask.CountItems();i++){
 802                 bCanMinimase = TaskAt(i)->iStyles & BF_GUI_OPERTASK_STYLE_CANMINIMASE;
 803                 if(!bCanMinimase) break;
 804         }
 805         return bCanMinimase;
 806 }
 807 
 808 void
 809 BF_GUI_OperRoster::SetViewMode(int32 i_NewViewMode)    /* [previous][next][first][last][top][bottom][index][help] */
 810 {
 811         BAutolock oLocker(poWin);
 812                 
 813         // check for existing mode 
 814         if(i_NewViewMode == iViewMode) return   ;
 815         
 816         // handle closing old view_mode
 817         
 818         if(BF_GUI_OPERROSTER_VIEW_LENTA==iViewMode){
 819                 BF_GUI_OperRoster_Lenta *poLenta = (BF_GUI_OperRoster_Lenta*)poWin->FindView("operroster_lenta");
 820                 poLenta->RemoveSelf();
 821                 DELETE(poLenta);                                
 822         }else
 823         if(BF_GUI_OPERROSTER_VIEW_DIALOG==iViewMode){
 824         
 825                 // check can_minimase dialog //
 826                 if(!CanMinimase()) return;
 827         
 828         
 829                 BF_GUI_Func_PanelsEnable( true ,false);
 830                 BF_GUI_OperRoster_Dialog* poOperDialog = (BF_GUI_OperRoster_Dialog*)poWin->FindView("operroster_dialog");
 831                 if(poOperDialog){
 832                         poOperDialog->RemoveSelf();
 833                         DELETE(poOperDialog);
 834                 }
 835         }
 836                 
 837         
 838         // switch to new mode
 839         if(BF_GUI_OPERROSTER_VIEW_HIDED == i_NewViewMode){
 840                 if(BF_GUI_OPERROSTER_VIEW_DIALOG==iViewMode){
 841                         SetFocusToOld();
 842                 }
 843                 iViewMode = BF_GUI_OPERROSTER_VIEW_HIDED;                               
 844         }else
 845         if(BF_GUI_OPERROSTER_VIEW_LENTA==i_NewViewMode){                                
 846                 iViewMode = BF_GUI_OPERROSTER_VIEW_LENTA;               
 847                 BF_GUI_Func_AddChildToMainView( new BF_GUI_OperRoster_Lenta() );                
 848                 SetFocusToOld();
 849         }else
 850         if(i_NewViewMode==BF_GUI_OPERROSTER_VIEW_DIALOG){
 851                 
 852                 StoreCurrentFocus(); 
 853                 
 854                 // disable panels
 855                 BF_GUI_Func_PanelsEnable( false,false );
 856                 BF_GUI_OperRoster_Dialog* poDialog = new BF_GUI_OperRoster_Dialog(BRect(0,0,400,300));
 857         
 858                 // make tasks_menu
 859                 BRect oRect;    
 860                 {
 861                         BL_List                         *ploItem = new BL_List();
 862                         BF_GUI_OperTask         *poTask=NULL;
 863                         for(int i=0;i<loTask.CountItems();i++){
 864                                 poTask = TaskAt(i);
 865                                 ploItem->AddItem( new BF_GUI_OperRoster_Dialog_Item(poTask->sName.String(),poTask->iState));
 866                         }
 867                         poDialog->LocalBounds(oRect);
 868                         oRect.bottom -= poSysSetup->oFontToolView.fHeight*2-2;
 869                         poDialog->poTasksMenu = new BF_GUI_DlgView_VMenu(oRect,"tasks",B_FOLLOW_ALL,ploItem,
 870                                 BF_GUI_DLGVIEW_VMENU_NAV_PARENTINFORM,(float)(int)poSysSetup->oFontToolView.fHeight*3);
 871                         poDialog->AddChild( poDialog->poTasksMenu );
 872                 }
 873                 
 874                 // make divider_line
 875                 oRect.bottom++;
 876             oRect.top=oRect.bottom;
 877             poDialog->AddChild(new BF_GUI_ViewFrame(oRect,B_FOLLOW_BOTTOM|B_FOLLOW_LEFT_RIGHT));
 878                 
 879                 // make bottom menu 
 880                 BRect oRect1;
 881                 poDialog->LocalBounds(oRect1);
 882                 oRect.left = oRect1.left;
 883                 oRect.right = oRect1.right;     
 884                 oRect.top = oRect.bottom+10;
 885                 oRect.bottom = oRect.top + poSysSetup->oFontToolView.fHeight;
 886                 BL_List *ploMenu = new BL_List();
 887                 ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_ROSTER_PAUSERUN),"pause"));
 888                 ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_CANCEL),"cancel"));
 889                 ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_ROSTER_MINIMISE),"minimase"));
 890                 poDialog->AddMenu(oRect,ploMenu,true);          
 891                 
 892                 // finish               
 893                 poDialog->MoveToCenter( poWinView );                                    
 894                 BF_GUI_Func_AddChildToMainView ( poDialog );                    
 895                 //
 896                 iViewMode = BF_GUI_OPERROSTER_VIEW_DIALOG;
 897                 //
 898                 UpdateDialog();
 899         }
 900 }
 901 
 902 BF_GUI_OperTask*
 903 BF_GUI_OperRoster::TaskAt(int32 i_Index)    /* [previous][next][first][last][top][bottom][index][help] */
 904 {
 905         return (BF_GUI_OperTask*)loTask.ItemAt(i_Index);
 906 }
 907 
 908 void                                                    
 909 BF_GUI_OperRoster::Close()    /* [previous][next][first][last][top][bottom][index][help] */
 910 {
 911         SetViewMode(BF_GUI_OPERROSTER_VIEW_HIDED);
 912 }
 913 
 914 float                                                   
 915 BF_GUI_OperRoster::fHeightInWinMain()    /* [previous][next][first][last][top][bottom][index][help] */
 916 {
 917         switch(iViewMode){
 918         case BF_GUI_OPERROSTER_VIEW_LENTA:{
 919                 BF_GUI_OperRoster_Lenta *poLenta = (BF_GUI_OperRoster_Lenta*)poWin->FindView("operroster_lenta");
 920                 if(!poLenta) return 0;
 921                 return poLenta->Frame().Height();}
 922         }
 923         return 0;
 924 }
 925 
 926 ///////////////////////////////////////////////////////////////////////////
 927 
 928 void
 929 BF_GUI_OperRoster_Init()    /* [previous][next][first][last][top][bottom][index][help] */
 930 {
 931         new BF_GUI_OperRoster();
 932 }
 933 
 934 void
 935 BF_GUI_OperRoster_AddTask(BF_GUI_OperTask *po_Task)    /* [previous][next][first][last][top][bottom][index][help] */
 936 {
 937         ASSERT(poOperRoster && po_Task);
 938         BMessenger      oMessenger(poOperRoster);
 939         BMessage        oMessage(BF_MSG_TO_OPERROSTER_ADDTASK);
 940         oMessage.AddPointer("bf_poTask",po_Task);
 941         oMessenger.SendMessage(&oMessage);
 942 }
 943 

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