// -------------------------------------------------------------- NetworkSetupWindow::NetworkSetupWindow(const char *title) : BWindow(BRect(100, 100, 300, 300), title, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS), fAddonCount(0) { // ---- Profiles section BMenu *profilesPopup = new BPopUpMenu("<none>"); _BuildProfilesMenu(profilesPopup, kMsgProfileSelected); BMenuField *profilesMenuField = new BMenuField("profiles_menu", B_TRANSLATE("Profile:"), profilesPopup); profilesMenuField->SetFont(be_bold_font); profilesMenuField->SetEnabled(false); // ---- Settings section fPanel = new BTabView("showview_box"); fApplyButton = new BButton("apply", B_TRANSLATE("Apply"), new BMessage(kMsgApply)); SetDefaultButton(fApplyButton); fRevertButton = new BButton("revert", B_TRANSLATE("Revert"), new BMessage(kMsgRevert)); // fRevertButton->SetEnabled(false); // Enable boxes resizing modes //fPanel->SetResizingMode(B_FOLLOW_ALL); // Build the layout SetLayout(new BGroupLayout(B_VERTICAL)); AddChild(BGroupLayoutBuilder(B_VERTICAL, B_USE_SMALL_SPACING) .AddGroup(B_HORIZONTAL, B_USE_SMALL_SPACING) .Add(profilesMenuField) .AddGlue() .End() .Add(fPanel) .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING) .Add(fRevertButton) .AddGlue() .Add(fApplyButton) .End() .SetInsets(B_USE_SMALL_SPACING, B_USE_SMALL_SPACING, B_USE_SMALL_SPACING, B_USE_SMALL_SPACING) ); _BuildShowTabView(kMsgAddonShow); fPanel->SetExplicitMinSize(BSize(fMinAddonViewRect.Width(), fMinAddonViewRect.Height())); fAddonView = NULL; CenterOnScreen(); }
NetworkWindow::NetworkWindow() : BWindow(BRect(100, 100, 400, 400), B_TRANSLATE("Network"), B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS), fServicesItem(NULL), fDialUpItem(NULL), fOtherItem(NULL) { // Profiles section #if ENABLE_PROFILES BPopUpMenu* profilesPopup = new BPopUpMenu("<none>"); _BuildProfilesMenu(profilesPopup, kMsgProfileSelected); BMenuField* profilesMenuField = new BMenuField("profiles_menu", B_TRANSLATE("Profile:"), profilesPopup); profilesMenuField->SetFont(be_bold_font); profilesMenuField->SetEnabled(false); #endif // Settings section fRevertButton = new BButton("revert", B_TRANSLATE("Revert"), new BMessage(kMsgRevert)); BMessage* message = new BMessage(kMsgToggleReplicant); BCheckBox* showReplicantCheckBox = new BCheckBox("showReplicantCheckBox", B_TRANSLATE("Show network status in Deskbar"), message); showReplicantCheckBox->SetExplicitMaxSize( BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); showReplicantCheckBox->SetValue(_IsReplicantInstalled()); fListView = new BOutlineListView("list", B_SINGLE_SELECTION_LIST, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS | B_NAVIGABLE); fListView->SetSelectionMessage(new BMessage(kMsgItemSelected)); BScrollView* scrollView = new BScrollView("ScrollView", fListView, 0, false, true); scrollView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); fAddOnShellView = new BView("add-on shell", 0, new BGroupLayout(B_VERTICAL)); fAddOnShellView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fInterfaceView = new InterfaceView(); // Build the layout BLayoutBuilder::Group<>(this, B_VERTICAL) .SetInsets(B_USE_DEFAULT_SPACING) #if ENABLE_PROFILES .AddGroup(B_HORIZONTAL, B_USE_SMALL_SPACING) .Add(profilesMenuField) .AddGlue() .End() #endif .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING) .Add(scrollView) .Add(fAddOnShellView) .End() .Add(showReplicantCheckBox) .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING) .Add(fRevertButton) .AddGlue() .End(); gNetworkWindow = this; _ScanInterfaces(); _ScanAddOns(); _UpdateRevertButton(); fListView->Select(0); _SelectItem(fListView->ItemAt(0)); // Call this manually, so that CenterOnScreen() below already // knows the final window size. // Set size of the list view from its contents float width; float height; fListView->GetPreferredSize(&width, &height); width += 2 * be_control_look->DefaultItemSpacing(); fListView->SetExplicitSize(BSize(width, B_SIZE_UNSET)); fListView->SetExplicitMinSize(BSize(width, std::min(height, 400.f))); CenterOnScreen(); fSettings.StartMonitoring(this); start_watching_network(B_WATCH_NETWORK_INTERFACE_CHANGES | B_WATCH_NETWORK_LINK_CHANGES | B_WATCH_NETWORK_WLAN_CHANGES, this); }
// -------------------------------------------------------------- NetworkSetupWindow::NetworkSetupWindow(const char *title) : BWindow(BRect(100, 100, 600, 600), title, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS) { BMenu *show_menu; BMenu *profiles_menu; BMenuField *menu_field; BBox *top_box, *bottom_box, *line; // *group BButton *button; BCheckBox *check; BRect r; float x, w, h; float size, min_size = 360; // TODO: cleanup this mess! show_menu = new BPopUpMenu("<please select me!>"); _BuildShowMenu(show_menu, SHOW_MSG); #define H_MARGIN 10 #define V_MARGIN 10 #define SMALL_MARGIN 3 // Resize the window to minimal width ResizeTo(fMinAddonViewRect.Width() + 2 * H_MARGIN, Bounds().Height()); top_box = new BBox(Bounds(), NULL, B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); AddChild(top_box); r = top_box->Bounds(); r.InsetBy(H_MARGIN, V_MARGIN); // ---- Profiles section profiles_menu = new BPopUpMenu("<none>"); menu_field = new BMenuField(r, "profiles_menu", PROFILE_LABEL, profiles_menu); menu_field->SetFont(be_bold_font); menu_field->SetDivider(be_bold_font->StringWidth(PROFILE_LABEL "#")); top_box->AddChild(menu_field); menu_field->ResizeToPreferred(); menu_field->GetPreferredSize(&w, &h); size = w; button = new BButton(r, "manage_profiles", MANAGE_PROFILES_LABEL, new BMessage(MANAGE_PROFILES_MSG), B_FOLLOW_TOP | B_FOLLOW_RIGHT); button->GetPreferredSize(&w, &h); button->ResizeToPreferred(); button->MoveTo(r.right - w, r.top); top_box->AddChild(button); size += SMALL_MARGIN + w; min_size = max_c(min_size, (H_MARGIN + size + H_MARGIN)); r.top += h + V_MARGIN; // ---- Separator line between Profiles section and Settings section line = new BBox(BRect(r.left, r.top, r.right, r.top + 1), NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP ); top_box->AddChild(line); _BuildProfilesMenu(profiles_menu, SELECT_PROFILE_MSG); r.top += 2 + V_MARGIN; // ---- Settings section // Make the show popup field half the whole width and centered menu_field = new BMenuField(r, "show_menu", SHOW_LABEL, show_menu); menu_field->SetFont(be_bold_font); menu_field->SetDivider(be_bold_font->StringWidth(SHOW_LABEL "#")); top_box->AddChild(menu_field); menu_field->ResizeToPreferred(); menu_field->GetPreferredSize(&w, &h); r.top += h+1 + V_MARGIN; min_size = max_c(min_size, (H_MARGIN + w + H_MARGIN)); r = fMinAddonViewRect.OffsetByCopy(H_MARGIN, r.top); fPanel = new BBox(r, "showview_box", B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); top_box->AddChild(fPanel); top_box->ResizeTo(Bounds().Width(), r.bottom + 1 + V_MARGIN); // ---- Bottom globals buttons section r = Bounds(); r.top = top_box->Frame().bottom + 1; bottom_box = new BBox(r, NULL, B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); AddChild(bottom_box); r.OffsetTo(0, 0); r.InsetBy(H_MARGIN, V_MARGIN); check = new BCheckBox(r, "dont_touch", DONT_TOUCH_LABEL, new BMessage(DONT_TOUCH_MSG), B_FOLLOW_TOP | B_FOLLOW_LEFT); check->GetPreferredSize(&w, &h); check->ResizeToPreferred(); check->SetValue(B_CONTROL_ON); check->MoveTo(H_MARGIN, r.top); bottom_box->AddChild(check); size = w; button = new BButton(r, "apply_now", APPLY_NOW_LABEL, new BMessage(APPLY_NOW_MSG), B_FOLLOW_TOP | B_FOLLOW_RIGHT); button->GetPreferredSize(&w, &h); button->ResizeToPreferred(); x = r.right - w; button->MoveTo(x, r.top); bottom_box->AddChild(button); fApplyNowButton = button; size += SMALL_MARGIN + w; button = new BButton(r, "revert", REVERT_LABEL, new BMessage(REVERT_MSG), B_FOLLOW_TOP | B_FOLLOW_RIGHT); button->GetPreferredSize(&w, &h); button->ResizeToPreferred(); button->MoveTo(x - w - SMALL_MARGIN, r.top); bottom_box->AddChild(button); fRevertButton = button; fRevertButton->SetEnabled(false); size += SMALL_MARGIN + w; min_size = max_c(min_size, (H_MARGIN + size + H_MARGIN)); r.bottom = r.top + h; r.InsetBy(-H_MARGIN, -V_MARGIN); bottom_box->ResizeTo(Bounds().Width(), r.Height()); // Resize window to enclose top and bottom boxes ResizeTo(Bounds().Width(), bottom_box->Frame().bottom); // Enable boxes resizing modes top_box->SetResizingMode(B_FOLLOW_ALL); fPanel->SetResizingMode(B_FOLLOW_ALL); bottom_box->SetResizingMode(B_FOLLOW_BOTTOM | B_FOLLOW_LEFT_RIGHT); // Set default/minimal window size ResizeTo(min_size, Bounds().Height()); SetSizeLimits(min_size, 20000, Bounds().Height(), 20000); fAddonView = NULL; }