void NetPulseView::MouseDown(BPoint where) { int32 buttons; int32 clicks; if (Window()->CurrentMessage()->FindInt32("buttons", &buttons) != B_OK || Window()->CurrentMessage()->FindInt32("clicks", &clicks) != B_OK) { return; } if (buttons == B_SECONDARY_MOUSE_BUTTON) { BPopUpMenu* popUpMenu = new BPopUpMenu("NetPulseMenu"); popUpMenu->AddItem(new BMenuItem("Connect", new BMessage(kMsgConnect))); popUpMenu->AddItem(new BMenuItem("Disconnect", new BMessage(kMsgDisconnect))); popUpMenu->AddSeparatorItem(); popUpMenu->AddItem(new BMenuItem("Statistics...", new BMessage(kMsgStatistics))); popUpMenu->AddSeparatorItem(); uint32 cookie = 0; BNetworkInterface interface; BNetworkRoster& roster = BNetworkRoster::Default(); while (roster.GetNextInterface(&cookie, interface) == B_OK) { const char* name = interface.Name(); if (strncmp(name, "loop", 4) != 0) { BMenuItem* menuItem = new BMenuItem(name, new BMessage(kMsgChangeInterface + cookie)); menuItem->SetMarked(cookie == fCookie); popUpMenu->AddItem(menuItem); } } popUpMenu->AddSeparatorItem(); popUpMenu->AddItem(new BMenuItem("Quit", new BMessage(kMsgQuit))); popUpMenu->SetTargetForItems(this); popUpMenu->FindItem(kMsgConnect)->SetEnabled(!fEnable && fCookie != 0); popUpMenu->FindItem(kMsgDisconnect)->SetEnabled(fEnable && fCookie != 0); popUpMenu->FindItem(kMsgStatistics)->SetEnabled(fEnable && fCookie != 0); popUpMenu->Go(ConvertToScreen(BPoint(0, 0)), true, false, false); delete popUpMenu; } else if (buttons == B_PRIMARY_MOUSE_BUTTON && clicks == 2) be_roster->Launch("application/x-vnd.Haiku-Network"); }
/*static*/ BPopUpMenu* AppearancePrefView::_MakeMenu(uint32 msg, const char** items, const char* defaultItemName) { BPopUpMenu* menu = new BPopUpMenu(""); int32 i = 0; while (*items) { if (!strcmp((*items), "")) menu->AddSeparatorItem(); else { BMessage* message = new BMessage(msg); menu->AddItem(new BMenuItem((*items), message)); } items++; i++; } BMenuItem* defaultItem = menu->FindItem(defaultItemName); if (defaultItem) defaultItem->SetMarked(true); return menu; }
MagWindow::MagWindow (BRect frame, const char *name, CanvasView *_myView) : BWindow (frame, name, B_DOCUMENT_WINDOW, 0, 0) { BRect viewFrame, hFrame, vFrame, menubarFrame; menubarFrame.Set (0, 0, 0, 0); menubar = new BMenuBar (menubarFrame, "Magnify Menubar"); BPopUpMenu *zoomMenu = new BPopUpMenu (""); zoomMenu->AddItem (new BMenuItem ("1:2", new BMessage ('zm2'))); zoomMenu->AddItem (new BMenuItem ("1:4", new BMessage ('zm4'))); zoomMenu->AddItem (new BMenuItem ("1:8", new BMessage ('zm8'))); zoomMenu->AddItem (new BMenuItem ("1:16", new BMessage ('zm16'))); zoomMenu->FindItem('zm8')->SetMarked (true); menubar->AddItem (zoomMenu); BPopUpMenu *gridMenu = new BPopUpMenu (""); gridMenu->AddItem (new BMenuItem (lstring (410, "Grid off"), new BMessage ('grd0'))); gridMenu->AddItem (new BMenuItem (lstring (411, "Grid B"), new BMessage ('grdB'))); gridMenu->AddItem (new BMenuItem (lstring (412, "Grid W"), new BMessage ('grdW'))); gridMenu->FindItem('grdB')->SetMarked (true); menubar->AddItem (gridMenu); editMenu = new BMenu (lstring (60, "")); editMenu->AddItem (new BMenuItem (lstring (61, "Undo"), new BMessage (B_UNDO), 'Z')); editMenu->AddItem (new BMenuItem (lstring (62, "Redo"), new BMessage ('redo'), 'Z', B_SHIFT_KEY)); menubar->AddItem (editMenu); AddChild (menubar); menubar->ResizeToPreferred(); menubarFrame = menubar->Frame(); menubarheight = menubarFrame.Height(); viewFrame.Set (0, menubarheight + 1, frame.Width() - B_V_SCROLL_BAR_WIDTH, frame.Height() - B_H_SCROLL_BAR_HEIGHT); magView = new MagView (viewFrame, "Magnify View", _myView); hFrame.Set (0, frame.Height() - B_H_SCROLL_BAR_HEIGHT + 1, frame.Width() - B_V_SCROLL_BAR_WIDTH + 1, frame.Height() + 1); h = new BScrollBar (hFrame, NULL, magView, 0, 0, B_HORIZONTAL); vFrame.Set (frame.Width() - B_V_SCROLL_BAR_WIDTH + 1, menubarFrame.Height(), frame.Width() + 1, frame.Height() - B_H_SCROLL_BAR_HEIGHT + 1); v = new BScrollBar (vFrame, NULL, magView, 0, 0, B_VERTICAL); AddChild (h); AddChild (v); magView->setScrollBars (h, v); AddChild (magView); myWindow = _myView->Window(); SetPulseRate (50000); }
BView *PrefsWindow::create_volumes_pane(void) { BView *pane = new BView(BRect(0, 0, top_frame.right-20, top_frame.bottom-80), GetString(STR_VOLUMES_PANE_TITLE), B_FOLLOW_NONE, B_WILL_DRAW); pane->SetViewColor(fill_color); float right = pane->Bounds().right-10; const char *str; int32 index = 0; volume_list = new VolumeListView(BRect(15, 10, pane->Bounds().right-30, 113), "volumes"); while ((str = PrefsFindString("disk", index++)) != NULL) volume_list->AddItem(new BStringItem(str)); volume_list->SetSelectionMessage(new BMessage(MSG_VOLUME_SELECTED)); volume_list->SetInvocationMessage(new BMessage(MSG_VOLUME_INVOKED)); pane->AddChild(new BScrollView("volumes_border", volume_list, B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true)); pane->AddChild(new BButton(BRect(10, 118, pane->Bounds().right/3, 138), "add_volume", GetString(STR_ADD_VOLUME_BUTTON), new BMessage(MSG_ADD_VOLUME))); pane->AddChild(new BButton(BRect(pane->Bounds().right/3, 118, pane->Bounds().right*2/3, 138), "create_volume", GetString(STR_CREATE_VOLUME_BUTTON), new BMessage(MSG_CREATE_VOLUME))); pane->AddChild(new BButton(BRect(pane->Bounds().right*2/3, 118, pane->Bounds().right-11, 138), "remove_volume", GetString(STR_REMOVE_VOLUME_BUTTON), new BMessage(MSG_REMOVE_VOLUME))); extfs_control = new PathControl(true, BRect(10, 145, right, 160), "extfs", GetString(STR_EXTFS_CTRL), PrefsFindString("extfs"), NULL); extfs_control->SetDivider(90); pane->AddChild(extfs_control); BMenuField *menu_field; BPopUpMenu *menu = new BPopUpMenu(""); menu_field = new BMenuField(BRect(10, 165, right, 180), "bootdriver", GetString(STR_BOOTDRIVER_CTRL), menu); menu_field->SetDivider(90); menu->AddItem(new BMenuItem(GetString(STR_BOOT_ANY_LAB), new BMessage(MSG_BOOT_ANY))); menu->AddItem(new BMenuItem(GetString(STR_BOOT_CDROM_LAB), new BMessage(MSG_BOOT_CDROM))); pane->AddChild(menu_field); int32 i32 = PrefsFindInt32("bootdriver"); BMenuItem *item; if (i32 == 0) { if ((item = menu->FindItem(GetString(STR_BOOT_ANY_LAB))) != NULL) item->SetMarked(true); } else if (i32 == CDROMRefNum) { if ((item = menu->FindItem(GetString(STR_BOOT_CDROM_LAB))) != NULL) item->SetMarked(true); } nocdrom_checkbox = new BCheckBox(BRect(10, 185, right, 200), "nocdrom", GetString(STR_NOCDROM_CTRL), new BMessage(MSG_NOCDROM)); pane->AddChild(nocdrom_checkbox); nocdrom_checkbox->SetValue(PrefsFindBool("nocdrom") ? B_CONTROL_ON : B_CONTROL_OFF); return pane; }
BPopUpMenu* AutoConfigView::_SetupProtocolMenu() { BPopUpMenu* menu = new BPopUpMenu(B_TRANSLATE("Choose Protocol")); // TODO: use path finder! for (int i = 0; i < 2; i++) { BPath path; status_t status = find_directory((i == 0) ? B_USER_ADDONS_DIRECTORY : B_BEOS_ADDONS_DIRECTORY, &path); if (status != B_OK) return menu; path.Append("mail_daemon"); path.Append("inbound_protocols"); BDirectory dir(path.Path()); entry_ref protocolRef; while (dir.GetNextRef(&protocolRef) == B_OK) { BEntry entry(&protocolRef); BMessage* msg = new BMessage(kProtokollChangedMsg); BMenuItem* item = new BMenuItem(entry.Name(), msg); menu->AddItem(item); msg->AddRef("protocol", &protocolRef); item->SetMarked(true); } } // make imap default protocol if existing BMenuItem* imapItem = menu->FindItem("IMAP"); if (imapItem) imapItem->SetMarked(true); return menu; }
//This is used to make the toolbar reflect the current state of //the document (enable, disable, set font values etc bool EV_BeOSToolbar::refreshToolbar(AV_View * pView, AV_ChangeMask mask) { const EV_Toolbar_ActionSet * pToolbarActionSet; pToolbarActionSet = m_pBeOSApp->getToolbarActionSet(); UT_ASSERT(pToolbarActionSet); int oldstate, perform_update = 0; UT_uint32 nrLabelItemsInLayout = m_pToolbarLayout->getLayoutItemCount(); for (UT_uint32 k=0; (k < nrLabelItemsInLayout); k++) { EV_Toolbar_LayoutItem * pLayoutItem = m_pToolbarLayout->getLayoutItem(k); UT_ASSERT(pLayoutItem); XAP_Toolbar_Id id = pLayoutItem->getToolbarId(); EV_Toolbar_Action * pAction = pToolbarActionSet->getAction(id); UT_ASSERT(pAction); AV_ChangeMask maskOfInterest = pAction->getChangeMaskOfInterest(); if ((maskOfInterest & mask) == 0) //If this item doesn't care about continue; // changes of this type, skip it... switch (pLayoutItem->getToolbarLayoutFlags()) { case EV_TLF_Normal: { const char * szState = 0; EV_Toolbar_ItemState tis = pAction->getToolbarItemState(pView,&szState); switch (pAction->getItemType()) { case EV_TBIT_ColorFore: case EV_TBIT_ColorBack: case EV_TBIT_PushButton: { bool bGrayed = EV_TIS_ShouldBeGray(tis); // UT_DEBUGMSG(("refreshToolbar: PushButton [%s] is %s\n", // m_pToolbarLabelSet->getLabel(id)->getToolbarLabel(), // ((bGrayed) ? "disabled" : "enabled"))); tb_item_t * item = m_pTBView->FindItemByID(id); if (item) { oldstate = item->state; item->state = (bGrayed) ? 0 : ENABLED_MASK; perform_update |= (oldstate == item->state) ? 0 : 1; if(perform_update) { m_pTBView->LockLooper(); m_pTBView->Invalidate(item->rect); m_pTBView->UnlockLooper(); } } } break; case EV_TBIT_GroupButton: // DPRINTF(printf("Ref Group->Toggle Button \n")); case EV_TBIT_ToggleButton: { bool bGrayed = EV_TIS_ShouldBeGray(tis); bool bToggled = EV_TIS_ShouldBeToggled(tis); // UT_DEBUGMSG(("refreshToolbar: ToggleBut [%s] is %s and %s\n", // m_pToolbarLabelSet->getLabel(id)->getToolbarLabel(), // ((bGrayed) ? "disabled" : "enabled"), // ((bToggled) ? "pressed" : "not pressed"))); tb_item_t * item = m_pTBView->FindItemByID(id); if (item) { oldstate = item->state; item->state = ((bGrayed) ? 0 : ENABLED_MASK) | ((bToggled) ? PRESSED_MASK : 0); perform_update |= (oldstate == item->state) ? 0 : 1; if(perform_update) { m_pTBView->LockLooper(); m_pTBView->Invalidate(item->rect); m_pTBView->UnlockLooper(); } } } break; case EV_TBIT_ComboBox: { // bool bGrayed = EV_TIS_ShouldBeGray(tis); bool bString = EV_TIS_ShouldUseString(tis); // UT_DEBUGMSG(("refreshToolbar: ComboBox [%s] is %s \n", // m_pToolbarLabelSet->getLabel(id)->getToolbarLabel(), // ((bString) ? szState : "no state"))); tb_item_t * item = m_pTBView->FindItemByID(id); if (item && bString) { BPopUpMenu *popup; UT_ASSERT(item->menu); popup = (BPopUpMenu*)item->menu->Menu(); UT_ASSERT(popup); BMenuItem *mnuitem = popup->FindItem(szState); if (mnuitem) { // printf("Can't find menu item %s \n", szState); // if (!(mnuitem = popup->FindItem("Dutch801 Rm BT"))) // break; //Send a message to fix that /* char *buffer = "Dutch801 Rm BT"; toolbarEvent(id, (UT_UCSChar *)buffer, strlen(buffer)); */ mnuitem->SetMarked(true); } } } break; case EV_TBIT_EditText: case EV_TBIT_DropDown: case EV_TBIT_StaticLabel: case EV_TBIT_Spacer: DPRINTF(printf("refreshToolbar: Update Text, DropDown, Label, Spacer \n")); break; case EV_TBIT_BOGUS: default: //KNORR!! //UT_ASSERT(0); break; } } break; case EV_TLF_Spacer: break; default: //KNORR!! //UT_ASSERT(0); break; } } #if 1 //TF I can't remember why I put this in, but it doesn't //seem to be needed now and is contributing in a big way //to the slowdown of the drag updates. //TF Note ... without this we don't get updated properly //when a button state changes. Instead put in hooks //that only update us as required. #endif return true; }
BView *PrefsWindow::create_graphics_pane(void) { BView *pane = new BView(BRect(0, 0, top_frame.right-20, top_frame.bottom-80), GetString(STR_GRAPHICS_SOUND_PANE_TITLE), B_FOLLOW_NONE, B_WILL_DRAW); pane->SetViewColor(fill_color); float right = pane->Bounds().right-10; const char *mode_str = PrefsFindString("screen"); int width = 512, height = 384; scr_mode_bit = 0; display_type = DISPLAY_WINDOW; if (mode_str) { if (sscanf(mode_str, "win/%d/%d", &width, &height) == 2) display_type = DISPLAY_WINDOW; else if (sscanf(mode_str, "scr/%d", &scr_mode_bit) == 1) display_type = DISPLAY_SCREEN; } BMenuField *menu_field; BMenuItem *item; BPopUpMenu *menu; menu = new BPopUpMenu(""); menu_field = new BMenuField(BRect(10, 5, right, 20), "videotype", GetString(STR_VIDEO_TYPE_CTRL), menu); menu_field->SetDivider(120); menu->AddItem(item = new BMenuItem(GetString(STR_WINDOW_LAB), new BMessage(MSG_VIDEO_WINDOW))); if (display_type == DISPLAY_WINDOW) item->SetMarked(true); menu->AddItem(item = new BMenuItem(GetString(STR_FULLSCREEN_LAB), new BMessage(MSG_VIDEO_SCREEN))); if (display_type == DISPLAY_SCREEN) item->SetMarked(true); pane->AddChild(menu_field); menu = new BPopUpMenu(""); frameskip_menu = new BMenuField(BRect(10, 26, right, 41), "frameskip", GetString(STR_FRAMESKIP_CTRL), menu); frameskip_menu->SetDivider(120); menu->AddItem(new BMenuItem(GetString(STR_REF_5HZ_LAB), new BMessage(MSG_REF_5HZ))); menu->AddItem(new BMenuItem(GetString(STR_REF_7_5HZ_LAB), new BMessage(MSG_REF_7_5HZ))); menu->AddItem(new BMenuItem(GetString(STR_REF_10HZ_LAB), new BMessage(MSG_REF_10HZ))); menu->AddItem(new BMenuItem(GetString(STR_REF_15HZ_LAB), new BMessage(MSG_REF_15HZ))); menu->AddItem(new BMenuItem(GetString(STR_REF_30HZ_LAB), new BMessage(MSG_REF_30HZ))); pane->AddChild(frameskip_menu); int32 i32 = PrefsFindInt32("frameskip"); if (i32 == 12) { if ((item = menu->FindItem(GetString(STR_REF_5HZ_LAB))) != NULL) item->SetMarked(true); } else if (i32 == 8) { if ((item = menu->FindItem(GetString(STR_REF_7_5HZ_LAB))) != NULL) item->SetMarked(true); } else if (i32 == 6) { if ((item = menu->FindItem(GetString(STR_REF_10HZ_LAB))) != NULL) item->SetMarked(true); } else if (i32 == 4) { if ((item = menu->FindItem(GetString(STR_REF_15HZ_LAB))) != NULL) item->SetMarked(true); } else if (i32 == 2) { if ((item = menu->FindItem(GetString(STR_REF_30HZ_LAB))) != NULL) item->SetMarked(true); } display_x_ctrl = new NumberControl(BRect(10, 48, right / 2, 66), 118, "width", GetString(STR_DISPLAY_X_CTRL), width, NULL); pane->AddChild(display_x_ctrl); display_y_ctrl = new NumberControl(BRect(10, 69, right / 2, 87), 118, "height", GetString(STR_DISPLAY_Y_CTRL), height, NULL); pane->AddChild(display_y_ctrl); menu = new BPopUpMenu(""); scr_mode_menu = new BMenuField(BRect(10, 26, right, 41), "screenmode", GetString(STR_SCREEN_MODE_CTRL), menu); scr_mode_menu->SetDivider(120); for (int i=0; scr_mode[i].mode_mask; i++) { menu->AddItem(item = new BMenuItem(GetString(scr_mode[i].str), new BMessage(MSG_SCREEN_MODE + i))); if (scr_mode[i].mode_mask & (1 << scr_mode_bit)) item->SetMarked(true); } pane->AddChild(scr_mode_menu); nosound_checkbox = new BCheckBox(BRect(10, 90, right, 105), "nosound", GetString(STR_NOSOUND_CTRL), new BMessage(MSG_NOSOUND)); pane->AddChild(nosound_checkbox); nosound_checkbox->SetValue(PrefsFindBool("nosound") ? B_CONTROL_ON : B_CONTROL_OFF); hide_show_graphics_ctrls(); return pane; }
/*********************************************************** * MouseDown ***********************************************************/ void HListView::MouseDown(BPoint pos) { int32 buttons = 0; ResourceUtils utils; BPoint point = pos; MenuUtils menu_utils; Window()->CurrentMessage()->FindInt32("buttons", &buttons); this->MakeFocus(true); // Handling of right click if (buttons == B_SECONDARY_MOUSE_BUTTON) { int32 sel = IndexOf(pos); if (sel >= 0) Select(sel); else DeselectAll(); sel = CurrentSelection(); HListItem* item = NULL; if (sel >= 0) item = cast_as(ItemAt(sel), HListItem); BPopUpMenu* theMenu = new BPopUpMenu("RIGHT_CLICK", false, false); BFont font(be_plain_font); font.SetSize(10); theMenu->SetFont(&font); menu_utils.AddMenuItem(theMenu , _("Add New Download") , M_ADD_URL , NULL, NULL , 'A', 0, utils.GetBitmapResource('BBMP', "BMP:ADDURL")); theMenu->AddSeparatorItem(); menu_utils.AddMenuItem(theMenu , _("Suspend") , M_SUSPEND, NULL, NULL , 0, 0, utils.GetBitmapResource('BBMP', "BMP:SUSPEND")); if (item) { theMenu->FindItem(M_SUSPEND)->SetEnabled(item->IsSuspendable()); } else { theMenu->FindItem(M_SUSPEND)->SetEnabled(false); } menu_utils.AddMenuItem(theMenu , _("Resume") , M_RESUME, NULL, NULL , 0, 0, utils.GetBitmapResource('BBMP', "BMP:RESUME")); if (item) { theMenu->FindItem(M_RESUME)->SetEnabled(item->IsResumable()); } else { theMenu->FindItem(M_RESUME)->SetEnabled(false); } theMenu->AddSeparatorItem(); menu_utils.AddMenuItem(theMenu , _("Stop") , M_STOP, NULL, NULL , 0, 0, utils.GetBitmapResource('BBMP', "BMP:STOP")); if (item) theMenu->FindItem(M_STOP)->SetEnabled(item->IsStarted()); else theMenu->FindItem(M_STOP)->SetEnabled(false); menu_utils.AddMenuItem(theMenu , _("Start") , M_START, NULL, NULL , 0, 0, utils.GetBitmapResource('BBMP', "BMP:CONNECTING")); if (sel >= 0) theMenu->FindItem(M_START)->SetEnabled(!item->IsStarted()); else theMenu->FindItem(M_START)->SetEnabled(false); theMenu->AddSeparatorItem(); menu_utils.AddMenuItem(theMenu , _("Delete") , M_DELETE, NULL, NULL , 'T', 0, utils.GetBitmapResource('BBMP', "BMP:TRASH")); theMenu->FindItem(M_DELETE)->SetEnabled((sel >= 0) ? true : false); BRect r; ConvertToScreen(&pos); r.top = pos.y - 5; r.bottom = pos.y + 5; r.left = pos.x - 5; r.right = pos.x + 5; BMenuItem* theItem = theMenu->Go(pos, false, true, r); if (theItem) { BMessage* aMessage = theItem->Message(); if (aMessage) this->Window()->PostMessage(aMessage); } delete theMenu; } else ColumnListView::MouseDown(point); }