BButton* _MakeButton(const char* label) { BButton* button = new BButton(label, new BMessage('BOOM')); button->SetExplicitMinSize(BSize(10, 50)); button->SetExplicitMaxSize(BSize(500, 500)); button->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT)); return button; }
TypeListWindow::TypeListWindow(const char* currentType, uint32 what, BWindow* target) : BWindow(BRect(100, 100, 360, 440), B_TRANSLATE("Choose type"), B_MODAL_WINDOW, B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), fTarget(target), fWhat(what) { float padding = be_control_look->DefaultItemSpacing(); fSelectButton = new BButton("select", B_TRANSLATE("Done"), new BMessage(kMsgSelected)); fSelectButton->SetEnabled(false); BButton* button = new BButton("cancel", B_TRANSLATE("Cancel"), new BMessage(B_CANCEL)); fSelectButton->MakeDefault(true); fListView = new MimeTypeListView("typeview", NULL, true, false); fListView->SetSelectionMessage(new BMessage(kMsgTypeSelected)); fListView->SetInvocationMessage(new BMessage(kMsgSelected)); BScrollView* scrollView = new BScrollView("scrollview", fListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true); SetLayout(new BGroupLayout(B_VERTICAL)); AddChild(BGroupLayoutBuilder(B_VERTICAL, padding) .Add(scrollView) .Add(BGroupLayoutBuilder(B_HORIZONTAL, padding) .Add(button) .Add(fSelectButton) ) .SetInsets(padding, padding, padding, padding) ); BAlignment buttonAlignment = BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_VERTICAL_CENTER); button->SetExplicitAlignment(buttonAlignment); fSelectButton->SetExplicitAlignment(buttonAlignment); MoveTo(target->Frame().LeftTop() + BPoint(15.0f, 15.0f)); }
ScreenshotWindow::ScreenshotWindow(const Utility& utility, bool silent, bool clipboard) : BWindow(BRect(0, 0, 200.0, 100.0), B_TRANSLATE_SYSTEM_NAME("Screenshot"), B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AVOID_FRONT | B_QUIT_ON_WINDOW_CLOSE | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE), fUtility(utility), fDelayControl(NULL), fScreenshot(NULL), fOutputPathPanel(NULL), fLastSelectedPath(NULL), fSettingsWindow(NULL), fDelay(0), fIncludeBorder(false), fIncludeCursor(false), fGrabActiveWindow(false), fOutputFilename(NULL), fExtension(""), fImageFileType(B_PNG_FORMAT) { // _ReadSettings() needs a valid fOutputPathMenu fOutputPathMenu = new BMenu(B_TRANSLATE("Please select")); _ReadSettings(); // _NewScreenshot() needs a valid fNameControl BString name(B_TRANSLATE_NOCOLLECT(fUtility.sDefaultFileNameBase)); name << 1; name = _FindValidFileName(name.String()); fNameControl = new BTextControl("", B_TRANSLATE("Name:"), name, NULL); // Check if fUtility contains valid data if (fUtility.wholeScreen == NULL) { _NewScreenshot(silent, clipboard, true); return; } fScreenshot = fUtility.MakeScreenshot(fIncludeCursor, fGrabActiveWindow, fIncludeBorder); fActiveWindow = new BCheckBox(B_TRANSLATE("Capture active window"), new BMessage(kActiveWindow)); if (fGrabActiveWindow) fActiveWindow->SetValue(B_CONTROL_ON); fWindowBorder = new BCheckBox(B_TRANSLATE("Include window border"), new BMessage(kIncludeBorder)); if (fIncludeBorder) fWindowBorder->SetValue(B_CONTROL_ON); if (!fGrabActiveWindow) fWindowBorder->SetEnabled(false); fShowCursor = new BCheckBox(B_TRANSLATE("Include mouse pointer"), new BMessage(kIncludeCursor)); if (fIncludeCursor) fShowCursor->SetValue(B_CONTROL_ON); BString delay; delay << fDelay / 1000000; fDelayControl = new BTextControl("", B_TRANSLATE("Delay:"), delay.String(), NULL); _DisallowChar(fDelayControl->TextView()); fDelayControl->TextView()->SetAlignment(B_ALIGN_RIGHT); BStringView* seconds = new BStringView("", B_TRANSLATE("seconds")); seconds->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); BMenuField* menuLocation = new BMenuField(B_TRANSLATE("Save in:"), fOutputPathMenu); menuLocation->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); fTranslatorMenu = new BMenu(B_TRANSLATE("Please select")); _SetupTranslatorMenu(); BMenuField* menuFormat = new BMenuField(B_TRANSLATE("Save as:"), fTranslatorMenu); menuFormat->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); BButton* showSettings = new BButton("", B_TRANSLATE("Settings" B_UTF8_ELLIPSIS), new BMessage(kSettings)); showSettings->SetExplicitAlignment( BAlignment(B_ALIGN_RIGHT, B_ALIGN_BOTTOM)); BBox* divider = new BBox(B_FANCY_BORDER, NULL); divider->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); BButton* saveScreenshot = new BButton("", B_TRANSLATE("Save"), new BMessage(kSaveScreenshot)); const float kSpacing = be_control_look->DefaultItemSpacing(); const float kLabelSpacing = be_control_look->DefaultLabelSpacing(); fPreview = new BView("preview", B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE); BBox* previewBox = new BBox(B_FANCY_BORDER, fPreview); BLayoutBuilder::Group<>(this, B_VERTICAL, 0) .AddGroup(B_HORIZONTAL) .SetInsets(B_USE_WINDOW_SPACING, B_USE_WINDOW_SPACING, B_USE_WINDOW_SPACING, B_USE_DEFAULT_SPACING) .Add(previewBox) .AddGroup(B_VERTICAL, 0) .Add(fActiveWindow) .Add(fWindowBorder) .Add(fShowCursor) .AddStrut(kSpacing) .AddGrid(0.0, kSpacing / 2) .Add(fDelayControl->CreateLabelLayoutItem(), 0, 0) .Add(fDelayControl->CreateTextViewLayoutItem(), 1, 0) .Add(BSpaceLayoutItem::CreateHorizontalStrut(kLabelSpacing), 2, 0) .Add(seconds, 3, 0) .Add(fNameControl->CreateLabelLayoutItem(), 0, 1) .Add(fNameControl->CreateTextViewLayoutItem(), 1, 1, 3, 1) .Add(menuLocation->CreateLabelLayoutItem(), 0, 2) .Add(menuLocation->CreateMenuBarLayoutItem(), 1, 2, 3, 1) .Add(menuFormat->CreateLabelLayoutItem(), 0, 3) .Add(menuFormat->CreateMenuBarLayoutItem(), 1, 3, 3, 1) .End() .AddStrut(kSpacing / 2) .Add(showSettings) .AddGlue() .End() .End() .Add(new BSeparatorView(B_HORIZONTAL)) .AddGroup(B_HORIZONTAL) .SetInsets(B_USE_WINDOW_SPACING, B_USE_DEFAULT_SPACING, B_USE_WINDOW_SPACING, B_USE_WINDOW_SPACING) .Add(new BButton("", B_TRANSLATE("Copy to clipboard"), new BMessage(B_COPY))) .Add(new BButton("", B_TRANSLATE("New screenshot"), new BMessage(kNewScreenshot))) .AddGlue() .Add(saveScreenshot); saveScreenshot->MakeDefault(true); _UpdatePreviewPanel(); _UpdateFilenameSelection(); CenterOnScreen(); Show(); }