Advertisement
Guest User

DeskBar.cpp

a guest
Dec 2nd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.91 KB | None | 0 0
  1. #include "App.h"
  2. #include "Deskbar.h"
  3.  
  4. #include <AppFileInfo.h>
  5. #include <Bitmap.h>
  6. #include <Entry.h>
  7. #include <File.h>
  8. #include <MenuItem.h>
  9. #include <Region.h>
  10. #include <PopUpMenu.h>
  11. #include <Roster.h>
  12. #include <View.h>
  13. #include <Window.h>
  14.  
  15. #include <stdio.h>
  16.  
  17.  
  18. const uint32 M_Pause = 'puse';
  19. const uint32 M_Resume = 'rsme';
  20. const uint32 M_Next = 'next';
  21. const uint32 M_Previous = 'prvs';
  22. const uint32 M_Settings = 'sttg';
  23. const uint32 M_About = 'abut';
  24. const uint32 M_Quit = 'quit';
  25.  
  26.  
  27. BView *instantiate_deskbar_item()
  28. {
  29.     return new Deskbar();
  30. }
  31.  
  32. Deskbar::Deskbar()
  33.     :   BView(BRect(0, 0, 15, 15), "RollerDeskbarView",
  34.         B_FOLLOW_ALL, B_WILL_DRAW)
  35. {
  36.     Init();
  37. }
  38.  
  39. Deskbar::Deskbar(BMessage *message)
  40.     :   BView(message)
  41. {
  42.     Init();
  43. }
  44.  
  45. Deskbar::~Deskbar()
  46. {
  47.     delete fIcon;
  48. }
  49.  
  50. void Deskbar::Init()
  51. {
  52.     entry_ref ref;
  53.     be_roster->FindApp(M_Roller_Signature, &ref);
  54.    
  55.     BFile           file(&ref, B_READ_ONLY);
  56.     BAppFileInfo    appFileInfo(&file);
  57.     fIcon = new BBitmap(BRect(0,0,15,15), B_CMAP8);
  58.     appFileInfo.GetIcon(fIcon, B_MINI_ICON);
  59. }
  60.  
  61. Deskbar *Deskbar::Instantiate(BMessage *message)
  62. {
  63.     if (validate_instantiation(message, "RollerDeskbarView"))
  64.     return new Deskbar(message);
  65.  
  66.     return NULL;
  67.    
  68. }
  69.  
  70.    
  71. status_t Deskbar::Archive(BMessage *message, bool deep) const
  72. {
  73.     BView::Archive(message, deep);
  74.     message->AddString("add_on",M_Roller_Signature);
  75.     message->AddString("class","RollerDeskbarView");
  76.  
  77.     return B_OK;
  78. }
  79.  
  80.  
  81. void Deskbar::AttachedToWindow()
  82. {
  83.     BView::AttachedToWindow();
  84.  
  85.     SetViewColor(Parent()->ViewColor());
  86.  
  87. }
  88.  
  89.  
  90. void Deskbar::Draw(BRect rect)
  91. {
  92.     SetDrawingMode( B_OP_ALPHA );
  93.     DrawBitmap(fIcon, BPoint(0.0, 0.0));
  94. }
  95.  
  96.  
  97. void Deskbar::MouseDown(BPoint where)
  98. {
  99.     BPoint location;
  100.     uint32 buttons;
  101.  
  102.     GetMouse(&location, &buttons);
  103.    
  104.  
  105.     if (buttons & B_PRIMARY_MOUSE_BUTTON) {
  106.         LeftClick(where);
  107.  
  108.     } else if (buttons & B_SECONDARY_MOUSE_BUTTON) {
  109.                 RightClick(where);
  110.        
  111.     }
  112. }
  113.  
  114.  
  115. void Deskbar::LeftClick(BPoint where)
  116. {
  117.         BPopUpMenu *popup = new BPopUpMenu("popup", false, false);
  118.         popup->AddItem(new BMenuItem("Pause",
  119.         new BMessage(M_Pause)));
  120.         popup->AddItem(new BMenuItem("Resume",
  121.         new BMessage(M_Resume)));
  122.  
  123.         popup->AddSeparatorItem();
  124.  
  125.         popup->AddItem(new BMenuItem("Previous",
  126.         new BMessage(M_Previous)));
  127.         popup->AddItem(new BMenuItem("Next",
  128.         new BMessage(M_Next)));
  129.         popup->SetTargetForItems(this);
  130.  
  131.         ConvertToScreen(&where);
  132.         popup->Go(where, true, true, true);
  133.  
  134. }
  135.  
  136.  
  137. void Deskbar::RightClick(BPoint where)
  138. {
  139.         BPopUpMenu *popup = new BPopUpMenu("popup", false, false);
  140.         popup->AddItem(new BMenuItem("Settins",
  141.         new BMessage(M_Settings)));
  142.         popup->AddItem(new BMenuItem("About",
  143.         new BMessage(M_About)));
  144.  
  145.         popup->AddSeparatorItem();
  146.  
  147.         popup->AddItem(new BMenuItem("Quit",
  148.         new BMessage(M_Quit)));
  149.         popup->SetTargetForItems(this);
  150.  
  151.         ConvertToScreen(&where);
  152.         popup->Go(where, true, true, true);
  153.  
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement