void ServerSettingsView::_GetAuthEncrMenu(entry_ref protocol, BMenuField*& authField, BMenuField*& sslField) { BMailAccountSettings dummySettings; BView *view = new BStringView("", "Not here!");//CreateConfigView(protocol, dummySettings.InboundSettings(), // dummySettings, fImageId); authField = (BMenuField*)view->FindView("auth_method"); sslField = (BMenuField*)view->FindView("flavor"); view->RemoveChild(authField); view->RemoveChild(sslField); delete view; }
static filter_result TextViewFilter(BMessage* message, BHandler**, BMessageFilter* filter) { uchar key; if (message->FindInt8("byte", (int8*)&key) != B_OK) return B_DISPATCH_MESSAGE; ThrowOnAssert(filter != NULL); BContainerWindow* window = dynamic_cast<BContainerWindow*>( filter->Looper()); ThrowOnAssert(window != NULL); BPoseView* poseView = window->PoseView(); ThrowOnAssert(poseView != NULL); if (key == B_RETURN || key == B_ESCAPE) { poseView->CommitActivePose(key == B_RETURN); return B_SKIP_MESSAGE; } if (key == B_TAB) { if (poseView->ActivePose()) { if (message->FindInt32("modifiers") & B_SHIFT_KEY) poseView->ActivePose()->EditPreviousWidget(poseView); else poseView->ActivePose()->EditNextWidget(poseView); } return B_SKIP_MESSAGE; } // the BTextView doesn't respect window borders when resizing itself; // we try to work-around this "bug" here. // find the text editing view BView* scrollView = poseView->FindView("BorderView"); if (scrollView != NULL) { BTextView* textView = dynamic_cast<BTextView*>( scrollView->FindView("WidgetTextView")); if (textView != NULL) { BRect rect = scrollView->Frame(); if (rect.right + 3 > poseView->Bounds().right || rect.left - 3 < 0) textView->MakeResizable(true, NULL); } } return B_DISPATCH_MESSAGE; }
void BTextWidget::StopEdit(bool saveChanges, BPoint poseLoc, BPoseView* view, BPose* pose, int32 poseIndex) { // find the text editing view BView* scrollView = view->FindView("BorderView"); ASSERT(scrollView != NULL); if (scrollView == NULL) return; BTextView* textView = dynamic_cast<BTextView*>( scrollView->FindView("WidgetTextView")); ASSERT(textView != NULL); if (textView == NULL) return; BColumn* column = view->ColumnFor(fAttrHash); ASSERT(column != NULL); if (column == NULL) return; if (saveChanges && fText->CommitEditedText(textView)) { // we have an actual change, re-sort view->CheckPoseSortOrder(pose, poseIndex); } // make text widget visible again SetVisible(true); view->Invalidate(ColumnRect(poseLoc, column, view)); // force immediate redraw so TEView disappears scrollView->RemoveSelf(); delete scrollView; ASSERT(view->Window() != NULL); view->Window()->UpdateIfNeeded(); view->MakeFocus(); SetActive(false); }
void PBox::GetData(BMessage* data){ BView * panel = fPrefView; BMessage cur; for (int i = 0; fTemplate.FindMessage("setting", i, &cur) == B_OK; i++) { const char *name = cur.FindString("name"); int32 type = -1; cur.FindInt32("type", &type); if ( dynamic_cast<BTextControl*>(panel->FindView(name))) { // Free text BTextControl * ctrl = (BTextControl*)panel->FindView(name); switch (type) { case B_STRING_TYPE: { data->AddString(name, ctrl->Text() ); } break; case B_INT32_TYPE: { data->AddInt32(name, atoi(ctrl->Text()) ); } break; default: { return; }; }; } else if (dynamic_cast<BMenuField*>(panel->FindView(name))) { // Provided option BMenuField * ctrl = (BMenuField*)panel->FindView(name); BMenuItem * item = ctrl->Menu()->FindMarked(); if (!item) return; switch (type) { case B_STRING_TYPE: { data->AddString(name, item->Label() ); BString index(name); index << "_index"; data->AddInt32(index.String(), ctrl->Menu()->IndexOf(item)); //index } break; case B_INT32_TYPE: { data->AddInt32(name, atoi(item->Label()) ); BString index(name); index << "_index"; data->AddInt32(index.String(), ctrl->Menu()->IndexOf(item)); //index } break; default: { return; }; } } else if (dynamic_cast<BCheckBox*>(panel->FindView(name))) { // Boolean setting BCheckBox * box = (BCheckBox*)panel->FindView(name); if ( box->Value() == B_CONTROL_ON ) { data->AddBool(name,true); } else { data->AddBool(name,false); } } else if (dynamic_cast<BTextView *>(panel->FindView(name))) { BTextView *view = (BTextView *)panel->FindView(name); data->AddString(name, view->Text()); }; }; }
void ImageFilePanel::Show() { if (fImageView == NULL) { Window()->Lock(); BView* background = Window()->ChildAt(0); uint32 poseViewResizingMode = background->FindView("PoseView")->ResizingMode(); uint32 countVwResizingMode = background->FindView("CountVw")->ResizingMode(); uint32 vScrollBarResizingMode = background->FindView("VScrollBar")->ResizingMode(); uint32 hScrollBarResizingMode = background->FindView("HScrollBar")->ResizingMode(); background->FindView("PoseView") ->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP); background->FindView("CountVw") ->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP); background->FindView("VScrollBar") ->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP); background->FindView("HScrollBar") ->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP); Window()->ResizeBy(0, 70); background->FindView("PoseView")->SetResizingMode(poseViewResizingMode); background->FindView("CountVw")->SetResizingMode(countVwResizingMode); background->FindView("VScrollBar") ->SetResizingMode(vScrollBarResizingMode); background->FindView("HScrollBar") ->SetResizingMode(hScrollBarResizingMode); BRect rect(background->Bounds().left + 15, background->Bounds().bottom - 94, background->Bounds().left + 122, background->Bounds().bottom - 15); fImageView = new BView(rect, "ImageView", B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_SUBPIXEL_PRECISE); fImageView->SetViewColor(background->ViewColor()); background->AddChild(fImageView); rect = BRect(background->Bounds().left + 132, background->Bounds().bottom - 85, background->Bounds().right, background->Bounds().bottom - 65); fResolutionView = new BStringView(rect, "ResolutionView", NULL, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); background->AddChild(fResolutionView); rect.OffsetBy(0, -16); fImageTypeView = new BStringView(rect, "ImageTypeView", NULL, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); background->AddChild(fImageTypeView); Window()->Unlock(); } BFilePanel::Show(); }
int32 LibraryWindow::ScanThread(void *data) { LibraryWindow *win = (LibraryWindow *)data; float maxwidth; BRect r(5,5,105,20); BView *systemheader = win->AddHeader(r.LeftTop(),TR("System Libraries:")); win->Lock(); r = systemheader->Frame(); win->Unlock(); maxwidth = r.right; r.OffsetBy(0,r.Height() + 10); DPath sysPath = GetSystemPath(B_USER_DEVELOP_DIRECTORY); sysPath << "lib/x86"; BRect out = win->ScanFolder(r.LeftTop(),sysPath.GetFullPath(),&maxwidth); if (out != BRect(0,0,-1,-1)) { r = out; r.OffsetBy(0,10); } if (gPlatform == PLATFORM_HAIKU || gPlatform == PLATFORM_HAIKU_GCC4) { BView *commonheader = win->AddHeader(r.LeftTop(),TR("Common Libraries:")); win->Lock(); r = commonheader->Frame(); win->Unlock(); maxwidth = MAX(r.right,maxwidth); r.OffsetBy(0,r.Height() + 10); out = win->ScanFolder(r.LeftTop(),GetSystemPath(B_USER_LIB_DIRECTORY).GetFullPath(), &maxwidth); if (out != BRect(0,0,-1,-1)) { r = out; r.OffsetBy(0,10); } } BView *userheader = win->AddHeader(r.LeftTop(),TR("User Libraries:")); win->Lock(); r = userheader->Frame(); win->Unlock(); maxwidth = MAX(r.right,maxwidth); r.OffsetBy(0,r.Height() + 10); out = win->ScanFolder(r.LeftTop(),GetSystemPath(B_USER_LIB_DIRECTORY).GetFullPath(), &maxwidth); if (out.IsValid()) { r = out; r.OffsetBy(0,10); } win->Lock(); BView *top = win->GetBackgroundView(); BScrollView *scrollView = (BScrollView*)top->FindView("scrollView"); BScrollBar *vbar = scrollView->ScrollBar(B_VERTICAL); vbar->SetRange(0, r.bottom - scrollView->Bounds().Height()); vbar->SetSteps(r.Height() * 2.0,r.Height() * 8.0); gSettings.Lock(); BRect savedframe; if (gSettings.FindRect("libwin_frame",&savedframe) == B_OK) win->ResizeTo(savedframe.Width(),savedframe.Height()); gSettings.Unlock(); BStringView *label = (BStringView*)top->FindView("label"); label->SetText(TR("Choose the system libraries for your project.")); float minw = label->Frame().right + 10; win->SetSizeLimits(minw,30000,200,30000); if (win->Bounds().Width() < minw) win->ResizeTo(minw,win->Bounds().Height()); win->fScanThread = -1; win->Unlock(); return 0; }
// SavePanel class SavePanel::SavePanel(const char* name, BMessenger* target, entry_ref* startDirectory, uint32 nodeFlavors, bool allowMultipleSelection, BMessage* message, BRefFilter* filter, bool modal, bool hideWhenDone) : BFilePanel(B_SAVE_PANEL, target, startDirectory, nodeFlavors, allowMultipleSelection, message, filter, modal, hideWhenDone), BHandler(name), fConfigWindow(NULL), fFormatM(NULL), fExportMode(EXPORT_MODE_ICON_RDEF) { BWindow* window = Window(); if (!window || !window->Lock()) return; window->SetTitle(B_TRANSLATE("Save image")); // add this instance as BHandler to the window's looper window->AddHandler(this); // find a couple of important views and mess with their layout BView* background = Window()->ChildAt(0); BButton* cancel = dynamic_cast<BButton*>(background->FindView("cancel button")); BView* textview = background->FindView("text view"); BScrollBar* hscrollbar = dynamic_cast<BScrollBar*>(background->FindView("HScrollBar")); if (!background || !cancel || !textview || !hscrollbar) { printf("SavePanel::SavePanel() - couldn't find necessary controls.\n"); return; } _BuildMenu(); BRect rect = textview->Frame(); rect.top = cancel->Frame().top; font_height fh; be_plain_font->GetHeight(&fh); rect.bottom = rect.top + fh.ascent + fh.descent + 5.0; fFormatMF = new BMenuField(rect, "format popup", B_TRANSLATE("Format"), fFormatM, true, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW | B_NAVIGABLE); fFormatMF->SetDivider(be_plain_font->StringWidth( B_TRANSLATE("Format")) + 7); fFormatMF->MenuBar()->ResizeToPreferred(); fFormatMF->ResizeToPreferred(); float height = fFormatMF->Bounds().Height() + 8.0; // find all the views that are in the way and // move up them up the height of the menu field BView *poseview = background->FindView("PoseView"); if (poseview) poseview->ResizeBy(0, -height); BButton *insert = (BButton *)background->FindView("default button"); if (hscrollbar) hscrollbar->MoveBy(0, -height); BScrollBar *vscrollbar = (BScrollBar *)background->FindView("VScrollBar"); if (vscrollbar) vscrollbar->ResizeBy(0, -height); BView *countvw = (BView *)background->FindView("CountVw"); if (countvw) countvw->MoveBy(0, -height); textview->MoveBy(0, -height); #if HAIKU_TARGET_PLATFORM_DANO fFormatMF->MoveTo(textview->Frame().left, fFormatMF->Frame().top + 2); #else fFormatMF->MoveTo(textview->Frame().left, fFormatMF->Frame().top); #endif background->AddChild(fFormatMF); // Build the "Settings" button relative to the format menu rect = cancel->Frame(); rect.OffsetTo(fFormatMF->Frame().right + 5.0, rect.top); fSettingsB = new BButton(rect, "settings", B_TRANSLATE("Settings"B_UTF8_ELLIPSIS), new BMessage(MSG_SETTINGS), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW | B_NAVIGABLE); fSettingsB->ResizeToPreferred(); background->AddChild(fSettingsB); fSettingsB->SetTarget(this); textview->ResizeTo(fSettingsB->Frame().right - fFormatMF->Frame().left, textview->Frame().Height()); // Make sure the smallest window won't draw the "Settings" button over anything else float minWindowWidth = textview->Bounds().Width() + cancel->Bounds().Width() + (insert ? insert->Bounds().Width() : 0.0) + 90; Window()->SetSizeLimits(minWindowWidth, 10000, 250, 10000); if (Window()->Bounds().IntegerWidth() + 1 < minWindowWidth) Window()->ResizeTo(minWindowWidth, Window()->Bounds().Height()); window->Unlock(); }
void PrefsWindow::MessageReceived(BMessage *msg) { switch (msg->what) { case MSG_OK: { // "Start" button clicked read_volumes_prefs(); read_memory_prefs(); read_graphics_prefs(); SavePrefs(); send_quit_on_close = false; PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(ok_message); break; } case MSG_CANCEL: // "Quit" button clicked send_quit_on_close = false; PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED); break; case B_ABOUT_REQUESTED: { // "About" menu item selected ShowAboutWindow(); break; } case MSG_ZAP_PRAM: // "Zap PRAM File" menu item selected ZapPRAM(); break; case MSG_VOLUME_INVOKED: { // Double-clicked on volume name, toggle read-only flag int selected = volume_list->CurrentSelection(); if (selected >= 0) { const char *str = PrefsFindString("disk", selected); BStringItem *item = (BStringItem *)volume_list->RemoveItem(selected); delete item; char newstr[256]; if (str[0] == '*') strcpy(newstr, str+1); else { strcpy(newstr, "*"); strcat(newstr, str); } PrefsReplaceString("disk", newstr, selected); volume_list->AddItem(new BStringItem(newstr), selected); volume_list->Select(selected); } break; } case MSG_ADD_VOLUME: add_volume_panel->Show(); break; case MSG_CREATE_VOLUME: create_volume_panel->Show(); break; case MSG_ADD_VOLUME_PANEL: { entry_ref ref; if (msg->FindRef("refs", &ref) == B_NO_ERROR) { BEntry entry(&ref, true); BPath path; entry.GetPath(&path); if (entry.IsFile()) { PrefsAddString("disk", path.Path()); volume_list->AddItem(new BStringItem(path.Path())); } else if (entry.IsDirectory()) { BVolume volume; if (path.Path()[0] == '/' && strchr(path.Path()+1, '/') == NULL && entry.GetVolume(&volume) == B_NO_ERROR) { int32 i = 0; dev_t d; fs_info info; while ((d = next_dev(&i)) >= 0) { fs_stat_dev(d, &info); if (volume.Device() == info.dev) { PrefsAddString("disk", info.device_name); volume_list->AddItem(new BStringItem(info.device_name)); } } } } } break; } case MSG_CREATE_VOLUME_PANEL: { entry_ref dir; if (msg->FindRef("directory", &dir) == B_NO_ERROR) { BEntry entry(&dir, true); BPath path; entry.GetPath(&path); path.Append(msg->FindString("name")); create_volume_panel->Window()->Lock(); BView *background = create_volume_panel->Window()->ChildAt(0); NumberControl *v = (NumberControl *)background->FindView("hardfile_size"); int size = v->Value(); char cmd[1024]; sprintf(cmd, "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", path.Path(), size); int ret = system(cmd); if (ret == 0) { PrefsAddString("disk", path.Path()); volume_list->AddItem(new BStringItem(path.Path())); } else { sprintf(cmd, GetString(STR_CREATE_VOLUME_WARN), strerror(ret)); WarningAlert(cmd); } } break; } case MSG_REMOVE_VOLUME: { int selected = volume_list->CurrentSelection(); if (selected >= 0) { PrefsRemoveItem("disk", selected); BStringItem *item = (BStringItem *)volume_list->RemoveItem(selected); delete item; volume_list->Select(selected); } break; } case MSG_BOOT_ANY: PrefsReplaceInt32("bootdriver", 0); break; case MSG_BOOT_CDROM: PrefsReplaceInt32("bootdriver", CDROMRefNum); break; case MSG_NOCDROM: PrefsReplaceBool("nocdrom", nocdrom_checkbox->Value() == B_CONTROL_ON); break; case MSG_VIDEO_WINDOW: display_type = DISPLAY_WINDOW; hide_show_graphics_ctrls(); break; case MSG_VIDEO_SCREEN: display_type = DISPLAY_SCREEN; hide_show_graphics_ctrls(); break; case MSG_REF_5HZ: PrefsReplaceInt32("frameskip", 12); break; case MSG_REF_7_5HZ: PrefsReplaceInt32("frameskip", 8); break; case MSG_REF_10HZ: PrefsReplaceInt32("frameskip", 6); break; case MSG_REF_15HZ: PrefsReplaceInt32("frameskip", 4); break; case MSG_REF_30HZ: PrefsReplaceInt32("frameskip", 2); break; case MSG_NOSOUND: PrefsReplaceBool("nosound", nosound_checkbox->Value() == B_CONTROL_ON); break; case MSG_SER_A: { BMenuItem *source = NULL; msg->FindPointer("source", (void **)&source); if (source) PrefsReplaceString("seriala", source->Label()); break; } case MSG_SER_B: { BMenuItem *source = NULL; msg->FindPointer("source", (void **)&source); if (source) PrefsReplaceString("serialb", source->Label()); break; } case MSG_ETHER: if (ether_checkbox->Value() == B_CONTROL_ON) PrefsReplaceString("ether", "yes"); else PrefsRemoveItem("ether"); break; case MSG_UDPTUNNEL: PrefsReplaceBool("udptunnel", udptunnel_checkbox->Value() == B_CONTROL_ON); hide_show_serial_ctrls(); break; case MSG_RAMSIZE: PrefsReplaceInt32("ramsize", ramsize_slider->Value() * 1024 * 1024); break; case MSG_MODELID_5: PrefsReplaceInt32("modelid", 5); break; case MSG_MODELID_14: PrefsReplaceInt32("modelid", 14); break; case MSG_CPU_68020: PrefsReplaceInt32("cpu", 2); PrefsReplaceBool("fpu", false); break; case MSG_CPU_68020_FPU: PrefsReplaceInt32("cpu", 2); PrefsReplaceBool("fpu", true); break; case MSG_CPU_68030: PrefsReplaceInt32("cpu", 3); PrefsReplaceBool("fpu", false); break; case MSG_CPU_68030_FPU: PrefsReplaceInt32("cpu", 3); PrefsReplaceBool("fpu", true); break; case MSG_CPU_68040: PrefsReplaceInt32("cpu", 4); PrefsReplaceBool("fpu", true); break; default: { // Screen mode messages if ((msg->what & 0xffff0000) == MSG_SCREEN_MODE) { int m = msg->what & 0xffff; uint32 mask = scr_mode[m].mode_mask; for (int i=0; i<32; i++) if (mask & (1 << i)) scr_mode_bit = i; } else BWindow::MessageReceived(msg); } } }
PrefsWindow::PrefsWindow(uint32 msg) : BWindow(BRect(0, 0, 400, 289), GetString(STR_PREFS_TITLE), B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS), this_messenger(this) { int i; ok_message = msg; send_quit_on_close = true; get_system_info(&sys_info); // Move window to right position Lock(); MoveTo(80, 80); // Set up menus BMenuBar *bar = new BMenuBar(Bounds(), "menu"); BMenu *menu = new BMenu(GetString(STR_PREFS_MENU)); menu->AddItem(new BMenuItem(GetString(STR_PREFS_ITEM_ABOUT), new BMessage(B_ABOUT_REQUESTED))); menu->AddItem(new BSeparatorItem); menu->AddItem(new BMenuItem(GetString(STR_PREFS_ITEM_START), new BMessage(MSG_OK))); menu->AddItem(new BMenuItem(GetString(STR_PREFS_ITEM_ZAP_PRAM), new BMessage(MSG_ZAP_PRAM))); menu->AddItem(new BSeparatorItem); menu->AddItem(new BMenuItem(GetString(STR_PREFS_ITEM_QUIT), new BMessage(MSG_CANCEL), 'Q')); bar->AddItem(menu); AddChild(bar); SetKeyMenuBar(bar); int mbar_height = int(bar->Bounds().bottom) + 1; // Resize window to fit menu bar ResizeBy(0, mbar_height); // Light gray background BRect b = Bounds(); top = new BView(BRect(0, mbar_height, b.right, b.bottom), "top", B_FOLLOW_NONE, B_WILL_DRAW); AddChild(top); top->SetViewColor(fill_color); top_frame = top->Bounds(); // Create panes panes[0] = create_volumes_pane(); panes[1] = create_graphics_pane(); panes[2] = create_serial_pane(); panes[3] = create_memory_pane(); // Prefs item tab view pane_tabs = new BTabView(BRect(10, 10, top_frame.right-10, top_frame.bottom-50), "items", B_WIDTH_FROM_LABEL); for (i=0; i<NUM_PANES; i++) pane_tabs->AddTab(panes[i]); top->AddChild(pane_tabs); volume_list->Select(0); // Create volume file panels add_volume_panel = new BFilePanel(B_OPEN_PANEL, &this_messenger, NULL, B_FILE_NODE | B_DIRECTORY_NODE, false, new BMessage(MSG_ADD_VOLUME_PANEL)); add_volume_panel->SetButtonLabel(B_DEFAULT_BUTTON, GetString(STR_ADD_VOLUME_PANEL_BUTTON)); add_volume_panel->Window()->SetTitle(GetString(STR_ADD_VOLUME_TITLE)); create_volume_panel = new BFilePanel(B_SAVE_PANEL, &this_messenger, NULL, B_FILE_NODE | B_DIRECTORY_NODE, false, new BMessage(MSG_CREATE_VOLUME_PANEL)); create_volume_panel->SetButtonLabel(B_DEFAULT_BUTTON, GetString(STR_CREATE_VOLUME_PANEL_BUTTON)); create_volume_panel->Window()->SetTitle(GetString(STR_CREATE_VOLUME_TITLE)); create_volume_panel->Window()->Lock(); BView *background = create_volume_panel->Window()->ChildAt(0); background->FindView("PoseView")->ResizeBy(0, -30); background->FindView("VScrollBar")->ResizeBy(0, -30); background->FindView("CountVw")->MoveBy(0, -30); BView *v = background->FindView("HScrollBar"); if (v) v->MoveBy(0, -30); else { i = 0; while ((v = background->ChildAt(i++)) != NULL) { if (v->Name() == NULL || v->Name()[0] == 0) { v->MoveBy(0, -30); // unnamed horizontal scroll bar break; } } } BView *filename = background->FindView("text view"); BRect fnr(filename->Frame()); fnr.OffsetBy(0, -30); NumberControl *nc = new NumberControl(fnr, 80, "hardfile_size", GetString(STR_HARDFILE_SIZE_CTRL), 40, NULL); background->AddChild(nc); create_volume_panel->Window()->Unlock(); // "Start" button BButton *button = new BButton(BRect(20, top_frame.bottom-35, 90, top_frame.bottom-10), "start", GetString(STR_START_BUTTON), new BMessage(MSG_OK)); top->AddChild(button); SetDefaultButton(button); // "Quit" button top->AddChild(new BButton(BRect(top_frame.right-90, top_frame.bottom-35, top_frame.right-20, top_frame.bottom-10), "cancel", GetString(STR_QUIT_BUTTON), new BMessage(MSG_CANCEL))); Unlock(); Show(); }