Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "App.h"
- #include "Deskbar.h"
- #include <AppFileInfo.h>
- #include <Bitmap.h>
- #include <Entry.h>
- #include <File.h>
- #include <MenuItem.h>
- #include <Region.h>
- #include <PopUpMenu.h>
- #include <Roster.h>
- #include <View.h>
- #include <Window.h>
- #include <stdio.h>
- const uint32 M_Pause = 'puse';
- const uint32 M_Resume = 'rsme';
- const uint32 M_Next = 'next';
- const uint32 M_Previous = 'prvs';
- const uint32 M_Settings = 'sttg';
- const uint32 M_About = 'abut';
- const uint32 M_Quit = 'quit';
- BView *instantiate_deskbar_item()
- {
- return new Deskbar();
- }
- Deskbar::Deskbar()
- : BView(BRect(0, 0, 15, 15), "RollerDeskbarView",
- B_FOLLOW_ALL, B_WILL_DRAW)
- {
- Init();
- }
- Deskbar::Deskbar(BMessage *message)
- : BView(message)
- {
- Init();
- }
- Deskbar::~Deskbar()
- {
- delete fIcon;
- }
- void Deskbar::Init()
- {
- entry_ref ref;
- be_roster->FindApp(M_Roller_Signature, &ref);
- BFile file(&ref, B_READ_ONLY);
- BAppFileInfo appFileInfo(&file);
- fIcon = new BBitmap(BRect(0,0,15,15), B_CMAP8);
- appFileInfo.GetIcon(fIcon, B_MINI_ICON);
- }
- Deskbar *Deskbar::Instantiate(BMessage *message)
- {
- if (validate_instantiation(message, "RollerDeskbarView"))
- return new Deskbar(message);
- return NULL;
- }
- status_t Deskbar::Archive(BMessage *message, bool deep) const
- {
- BView::Archive(message, deep);
- message->AddString("add_on",M_Roller_Signature);
- message->AddString("class","RollerDeskbarView");
- return B_OK;
- }
- void Deskbar::AttachedToWindow()
- {
- BView::AttachedToWindow();
- SetViewColor(Parent()->ViewColor());
- }
- void Deskbar::Draw(BRect rect)
- {
- SetDrawingMode( B_OP_ALPHA );
- DrawBitmap(fIcon, BPoint(0.0, 0.0));
- }
- void Deskbar::MouseDown(BPoint where)
- {
- BPoint location;
- uint32 buttons;
- GetMouse(&location, &buttons);
- if (buttons & B_PRIMARY_MOUSE_BUTTON) {
- LeftClick(where);
- } else if (buttons & B_SECONDARY_MOUSE_BUTTON) {
- RightClick(where);
- }
- }
- void Deskbar::LeftClick(BPoint where)
- {
- BPopUpMenu *popup = new BPopUpMenu("popup", false, false);
- popup->AddItem(new BMenuItem("Pause",
- new BMessage(M_Pause)));
- popup->AddItem(new BMenuItem("Resume",
- new BMessage(M_Resume)));
- popup->AddSeparatorItem();
- popup->AddItem(new BMenuItem("Previous",
- new BMessage(M_Previous)));
- popup->AddItem(new BMenuItem("Next",
- new BMessage(M_Next)));
- popup->SetTargetForItems(this);
- ConvertToScreen(&where);
- popup->Go(where, true, true, true);
- }
- void Deskbar::RightClick(BPoint where)
- {
- BPopUpMenu *popup = new BPopUpMenu("popup", false, false);
- popup->AddItem(new BMenuItem("Settins",
- new BMessage(M_Settings)));
- popup->AddItem(new BMenuItem("About",
- new BMessage(M_About)));
- popup->AddSeparatorItem();
- popup->AddItem(new BMenuItem("Quit",
- new BMessage(M_Quit)));
- popup->SetTargetForItems(this);
- ConvertToScreen(&where);
- popup->Go(where, true, true, true);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement