void PadView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) { MainWindow* window = dynamic_cast<MainWindow*>(Window()); if (window == NULL) return; if (fDragging) { window->MoveTo(ConvertToScreen(where) - fDragOffset); } else if (window->AutoRaise()) { where = ConvertToScreen(where); BScreen screen(window); BRect frame = screen.Frame(); BRect windowFrame = window->Frame(); if (where.x == frame.left || where.x == frame.right || where.y == frame.top || where.y == frame.bottom) { BPoint position = window->ScreenPosition(); bool raise = false; if (fabs(0.5 - position.x) > fabs(0.5 - position.y)) { // left or right border if (where.y >= windowFrame.top && where.y <= windowFrame.bottom) { if (position.x < 0.5 && where.x == frame.left) raise = true; else if (position.x > 0.5 && where.x == frame.right) raise = true; } } else { // top or bottom border if (where.x >= windowFrame.left && where.x <= windowFrame.right) { if (position.y < 0.5 && where.y == frame.top) raise = true; else if (position.y > 0.5 && where.y == frame.bottom) raise = true; } } if (raise) window->Activate(); } } }
void PadView::DisplayMenu(BPoint where, LaunchButton* button) const { MainWindow* window = dynamic_cast<MainWindow*>(Window()); if (window == NULL) return; LaunchButton* nearestButton = button; if (!nearestButton) { // find the nearest button for (int32 i = 0; (nearestButton = ButtonAt(i)); i++) { if (nearestButton->Frame().top > where.y) break; } } BPopUpMenu* menu = new BPopUpMenu(B_TRANSLATE("launch popup"), false, false); // add button BMessage* message = new BMessage(MSG_ADD_SLOT); message->AddPointer("be:source", (void*)nearestButton); BMenuItem* item = new BMenuItem(B_TRANSLATE("Add button here"), message); item->SetTarget(window); menu->AddItem(item); // button options if (button) { // clear button message = new BMessage(MSG_CLEAR_SLOT); message->AddPointer("be:source", (void*)button); item = new BMenuItem(B_TRANSLATE("Clear button"), message); item->SetTarget(window); menu->AddItem(item); // remove button message = new BMessage(MSG_REMOVE_SLOT); message->AddPointer("be:source", (void*)button); item = new BMenuItem(B_TRANSLATE("Remove button"), message); item->SetTarget(window); menu->AddItem(item); // Open containing folder button if (button->Ref() != NULL) { message = new BMessage(MSG_OPEN_CONTAINING_FOLDER); message->AddPointer("be:source", (void*)button); item = new BMenuItem(B_TRANSLATE("Open containing folder"), message); item->SetTarget(window); menu->AddItem(item); } // set button description if (button->Ref()) { message = new BMessage(MSG_SET_DESCRIPTION); message->AddPointer("be:source", (void*)button); item = new BMenuItem(B_TRANSLATE("Set description"B_UTF8_ELLIPSIS), message); item->SetTarget(window); menu->AddItem(item); } } menu->AddSeparatorItem(); // window settings BMenu* settingsM = new BMenu(B_TRANSLATE("Settings")); settingsM->SetFont(be_plain_font); const char* toggleLayoutLabel; if (fButtonLayout->Orientation() == B_HORIZONTAL) toggleLayoutLabel = B_TRANSLATE("Vertical layout"); else toggleLayoutLabel = B_TRANSLATE("Horizontal layout"); item = new BMenuItem(toggleLayoutLabel, new BMessage(MSG_TOGGLE_LAYOUT)); item->SetTarget(this); settingsM->AddItem(item); BMenu* iconSizeM = new BMenu(B_TRANSLATE("Icon size")); for (uint32 i = 0; i < sizeof(kIconSizes) / sizeof(uint32); i++) { uint32 iconSize = kIconSizes[i]; message = new BMessage(MSG_SET_ICON_SIZE); message->AddInt32("size", iconSize); BString label; label << iconSize << " x " << iconSize; item = new BMenuItem(label.String(), message); item->SetTarget(this); item->SetMarked(IconSize() == iconSize); iconSizeM->AddItem(item); } settingsM->AddItem(iconSizeM); item = new BMenuItem(B_TRANSLATE("Ignore double-click"), new BMessage(MSG_SET_IGNORE_DOUBLECLICK)); item->SetTarget(this); item->SetMarked(IgnoreDoubleClick()); settingsM->AddItem(item); uint32 what = window->Look() == B_BORDERED_WINDOW_LOOK ? MSG_SHOW_BORDER : MSG_HIDE_BORDER; item = new BMenuItem(B_TRANSLATE("Show window border"), new BMessage(what)); item->SetTarget(window); item->SetMarked(what == MSG_HIDE_BORDER); settingsM->AddItem(item); item = new BMenuItem(B_TRANSLATE("Auto-raise"), new BMessage(MSG_TOGGLE_AUTORAISE)); item->SetTarget(window); item->SetMarked(window->AutoRaise()); settingsM->AddItem(item); item = new BMenuItem(B_TRANSLATE("Show on all workspaces"), new BMessage(MSG_SHOW_ON_ALL_WORKSPACES)); item->SetTarget(window); item->SetMarked(window->ShowOnAllWorkspaces()); settingsM->AddItem(item); menu->AddItem(settingsM); menu->AddSeparatorItem(); // pad commands BMenu* padM = new BMenu(B_TRANSLATE("Pad")); padM->SetFont(be_plain_font); // new pad item = new BMenuItem(B_TRANSLATE("New"), new BMessage(MSG_ADD_WINDOW)); item->SetTarget(be_app); padM->AddItem(item); // new pad item = new BMenuItem(B_TRANSLATE("Clone"), new BMessage(MSG_ADD_WINDOW)); item->SetTarget(window); padM->AddItem(item); padM->AddSeparatorItem(); // close item = new BMenuItem(B_TRANSLATE("Close"), new BMessage(B_QUIT_REQUESTED)); item->SetTarget(window); padM->AddItem(item); menu->AddItem(padM); // app commands BMenu* appM = new BMenu(B_TRANSLATE_SYSTEM_NAME("LaunchBox")); appM->SetFont(be_plain_font); // quit item = new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED)); item->SetTarget(be_app); appM->AddItem(item); menu->AddItem(appM); // finish popup menu->SetAsyncAutoDestruct(true); menu->SetFont(be_plain_font); where = ConvertToScreen(where); BRect mouseRect(where, where); mouseRect.InsetBy(-4.0, -4.0); menu->Go(where, true, false, mouseRect, true); }