void
DateTimeView::_InitView()
{
	fCalendarView = new BCalendarView("calendar");
	fCalendarView->SetWeekNumberHeaderVisible(false);
	fCalendarView->SetSelectionMessage(new BMessage(kDayChanged));
	fCalendarView->SetInvocationMessage(new BMessage(kDayChanged));

	fDateEdit = new TDateEdit("dateEdit", 3);
	fTimeEdit = new TTimeEdit("timeEdit", 4);
	fClock = new TAnalogClock("analogClock");

	BTime time(BTime::CurrentTime(B_LOCAL_TIME));
	fClock->SetTime(time.Hour(), time.Minute(), time.Second());

	BBox* divider = new BBox(BRect(0, 0, 1, 1),
		B_EMPTY_STRING, B_FOLLOW_ALL_SIDES,
		B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER);
	divider->SetExplicitMaxSize(BSize(1, B_SIZE_UNLIMITED));

	const float kInset = be_control_look->DefaultItemSpacing();
	BLayoutBuilder::Group<>(this)
		.AddGroup(B_VERTICAL, kInset / 2)
			.Add(fDateEdit)
			.Add(fCalendarView)
		.End()
		.Add(divider)
		.AddGroup(B_VERTICAL, 0)
			.Add(fTimeEdit)
			.Add(fClock)
		.End()
		.SetInsets(kInset, kInset, kInset, kInset);
}
LookAndFeelSettingsView::LookAndFeelSettingsView(const char* name)
	:
	BView(name, 0),
	fDecorInfoButton(NULL),
	fDecorMenuField(NULL),
	fDecorMenu(NULL)
{
	// Decorator menu
	_BuildDecorMenu();
	fDecorMenuField = new BMenuField("decorator",
		B_TRANSLATE("Decorator:"), fDecorMenu);

	fDecorInfoButton = new BButton(B_TRANSLATE("About"),
		new BMessage(kMsgDecorInfo));

	// scroll bar arrow style
	BBox* arrowStyleBox = new BBox("arrow style");
	arrowStyleBox->SetLabel(B_TRANSLATE("Arrow style"));

	fSavedDoubleArrowsValue = _DoubleScrollBarArrows();

	fArrowStyleSingle = new FakeScrollBar(true, false,
		new BMessage(kMsgArrowStyleSingle));
	fArrowStyleDouble = new FakeScrollBar(true, true,
		new BMessage(kMsgArrowStyleDouble));

	BView* arrowStyleView;
	arrowStyleView = BLayoutBuilder::Group<>()
		.AddGroup(B_VERTICAL, 1)
			.Add(new BStringView("single", B_TRANSLATE("Single:")))
			.Add(fArrowStyleSingle)
			.AddStrut(B_USE_DEFAULT_SPACING)
			.Add(new BStringView("double", B_TRANSLATE("Double:")))
			.Add(fArrowStyleDouble)
			.SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING,
				B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
			.End()
		.View();
	arrowStyleBox->AddChild(arrowStyleView);
	arrowStyleBox->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
		B_ALIGN_VERTICAL_CENTER));
	arrowStyleBox->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));

	BStringView* scrollBarLabel
		= new BStringView("scroll bar", B_TRANSLATE("Scroll bar:"));
	scrollBarLabel->SetExplicitAlignment(
		BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP));

	// control layout
	BLayoutBuilder::Grid<>(this, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
		.Add(fDecorMenuField->CreateLabelLayoutItem(), 0, 0)
		.Add(fDecorMenuField->CreateMenuBarLayoutItem(), 1, 0)
		.Add(fDecorInfoButton, 2, 0)
		.Add(scrollBarLabel, 0, 1)
		.Add(arrowStyleBox, 1, 1)
		.AddGlue(0, 2)
		.SetInsets(B_USE_WINDOW_SPACING);

	// TODO : Decorator Preview Image?
}
void
MidiPlayerWindow::CreateViews()
{
	// Set up needed views
	scopeView = new ScopeView;

	showScope = new BCheckBox("showScope", B_TRANSLATE("Scope"),
		new BMessage(MSG_SHOW_SCOPE));
	showScope->SetValue(B_CONTROL_ON);

	CreateInputMenu();
	CreateReverbMenu();

	volumeSlider = new BSlider("volumeSlider", NULL, NULL, 0, 100,
		B_HORIZONTAL);
	rgb_color col = { 152, 152, 255 };
	volumeSlider->UseFillColor(true, &col);
	volumeSlider->SetModificationMessage(new BMessage(MSG_VOLUME));

	playButton = new BButton("playButton", B_TRANSLATE("Play"),
		new BMessage(MSG_PLAY_STOP));
	playButton->SetEnabled(false);

	BBox* divider = new BBox(B_EMPTY_STRING, B_WILL_DRAW | B_FRAME_EVENTS,
		B_FANCY_BORDER);
	divider->SetExplicitMaxSize(
		BSize(B_SIZE_UNLIMITED, 1));

	BStringView* volumeLabel = new BStringView(NULL, B_TRANSLATE("Volume:"));
	volumeLabel->SetAlignment(B_ALIGN_LEFT);
	volumeLabel->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));

	// Build the layout
	SetLayout(new BGroupLayout(B_HORIZONTAL));

	AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
		.Add(scopeView)
		.Add(BGridLayoutBuilder(10, 10)
			.Add(BSpaceLayoutItem::CreateGlue(), 0, 0)
			.Add(showScope, 1, 0)

			.Add(reverbMenu->CreateLabelLayoutItem(), 0, 1)
			.Add(reverbMenu->CreateMenuBarLayoutItem(), 1, 1)

			.Add(inputMenu->CreateLabelLayoutItem(), 0, 2)
			.Add(inputMenu->CreateMenuBarLayoutItem(), 1, 2)

			.Add(volumeLabel, 0, 3)
			.Add(volumeSlider, 1, 3)
		)
		.AddGlue()
		.Add(divider)
		.AddGlue()
		.Add(playButton)
		.AddGlue()
		.SetInsets(5, 5, 5, 5)
	);
}
SettingsView::SettingsView(MouseSettings& settings)
	: BBox("main_view"),
	fSettings(settings)
{
	// Add the "Mouse Type" pop up menu
	fTypeMenu = new BPopUpMenu("unknown");
	fTypeMenu->AddItem(new BMenuItem(B_TRANSLATE("1-Button"),
		new BMessage(kMsgMouseType)));
	fTypeMenu->AddItem(new BMenuItem(B_TRANSLATE("2-Button"),
		new BMessage(kMsgMouseType)));
	fTypeMenu->AddItem(new BMenuItem(B_TRANSLATE("3-Button"),
		new BMessage(kMsgMouseType)));

	BMenuField* typeField = new BMenuField(B_TRANSLATE("Mouse type:"),
		fTypeMenu);
	typeField->SetAlignment(B_ALIGN_RIGHT);

	// Create the "Double-click speed slider...
	fClickSpeedSlider = new BSlider("double_click_speed",
		B_TRANSLATE("Double-click speed"), new BMessage(kMsgDoubleClickSpeed),
		0, 1000, B_HORIZONTAL);
	fClickSpeedSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
	fClickSpeedSlider->SetHashMarkCount(5);
	fClickSpeedSlider->SetLimitLabels(B_TRANSLATE("Slow"),
		B_TRANSLATE("Fast"));

	// Create the "Mouse Speed" slider...
	fMouseSpeedSlider = new BSlider("mouse_speed", B_TRANSLATE("Mouse speed"),
		new BMessage(kMsgMouseSpeed), 0, 1000, B_HORIZONTAL);
	fMouseSpeedSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
	fMouseSpeedSlider->SetHashMarkCount(7);
	fMouseSpeedSlider->SetLimitLabels(B_TRANSLATE("Slow"),
		B_TRANSLATE("Fast"));

	// Create the "Mouse Acceleration" slider...
	fAccelerationSlider = new BSlider("mouse_acceleration",
		B_TRANSLATE("Mouse acceleration"),
		new BMessage(kMsgAccelerationFactor), 0, 1000, B_HORIZONTAL);
	fAccelerationSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
	fAccelerationSlider->SetHashMarkCount(5);
	fAccelerationSlider->SetLimitLabels(B_TRANSLATE("Slow"),
		B_TRANSLATE("Fast"));

	// Mouse image...
	fMouseView = new MouseView(fSettings);

	// Create the "Double-click test area" text box...
	BTextControl* doubleClickTextControl = new BTextControl(NULL,
		B_TRANSLATE("Double-click test area"), NULL);
	doubleClickTextControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_CENTER);

	// Add the "Mouse focus mode" pop up menu
	fFocusMenu = new BPopUpMenu(B_TRANSLATE("Click to focus and raise"));

	const char *focusLabels[] = {B_TRANSLATE_MARK("Click to focus and raise"),
		B_TRANSLATE_MARK("Click to focus"),
		B_TRANSLATE_MARK("Focus follows mouse")};
	const mode_mouse focusModes[] = {B_NORMAL_MOUSE, B_CLICK_TO_FOCUS_MOUSE,
										B_FOCUS_FOLLOWS_MOUSE};

	for (int i = 0; i < 3; i++) {
		BMessage* message = new BMessage(kMsgMouseFocusMode);
		message->AddInt32("mode", focusModes[i]);

		fFocusMenu->AddItem(new BMenuItem(B_TRANSLATE_NOCOLLECT(focusLabels[i]),
			message));
	}

	BMenuField* focusField = new BMenuField(B_TRANSLATE("Focus mode:"),
		fFocusMenu);
	focusField->SetAlignment(B_ALIGN_RIGHT);

	// Add the "Focus follows mouse mode" pop up menu
	fFocusFollowsMouseMenu = new BPopUpMenu(B_TRANSLATE("Normal"));

	const char *focusFollowsMouseLabels[] = {B_TRANSLATE_MARK("Normal"),
		B_TRANSLATE_MARK("Warp"), B_TRANSLATE_MARK("Instant warp")};
	const mode_focus_follows_mouse focusFollowsMouseModes[] =
		{B_NORMAL_FOCUS_FOLLOWS_MOUSE, B_WARP_FOCUS_FOLLOWS_MOUSE,
			B_INSTANT_WARP_FOCUS_FOLLOWS_MOUSE};

	for (int i = 0; i < 3; i++) {
		BMessage* message = new BMessage(kMsgFollowsMouseMode);
		message->AddInt32("mode_focus_follows_mouse",
			focusFollowsMouseModes[i]);

		fFocusFollowsMouseMenu->AddItem(new BMenuItem(
			B_TRANSLATE_NOCOLLECT(focusFollowsMouseLabels[i]), message));
	}

	BMenuField* focusFollowsMouseField = new BMenuField(
		"Focus follows mouse mode:", fFocusFollowsMouseMenu);
	focusFollowsMouseField->SetAlignment(B_ALIGN_RIGHT);

	// Add the "Click-through" check box
	fAcceptFirstClickBox = new BCheckBox(B_TRANSLATE("Accept first click"),
		new BMessage(kMsgAcceptFirstClick));

	// dividers
	BBox* hdivider = new BBox(
		BRect(0, 0, 1, 1), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES,
			B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER);
	hdivider->SetExplicitMaxSize(BSize(1, B_SIZE_UNLIMITED));

	BBox* vdivider = new BBox(
		BRect(0, 0, 1, 1), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES,
			B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER);
	vdivider->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));

	// Build the layout
	SetLayout(new BGroupLayout(B_HORIZONTAL));

	AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
		.AddGroup(B_HORIZONTAL, 10)
			.AddGroup(B_VERTICAL, 10, 1)
				.AddGroup(B_HORIZONTAL, 10)
					.AddGlue()
					.Add(typeField)
					.AddGlue()
				.End()
				.AddGlue()
				.Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
					.AddGlue()
					.Add(fMouseView)
					.AddGlue()
				)
				.AddGlue()
				.Add(doubleClickTextControl)
			.End()
			.Add(hdivider)
			.AddGroup(B_VERTICAL, 5, 3)
				.Add(BGroupLayoutBuilder(B_HORIZONTAL, 0)
					.Add(fClickSpeedSlider)
				)
				.Add(BGroupLayoutBuilder(B_HORIZONTAL, 0)
					.Add(fMouseSpeedSlider)
				)
				.Add(BGroupLayoutBuilder(B_HORIZONTAL, 0)
					.Add(fAccelerationSlider)
				)
			.End()
		.End()
		.Add(vdivider)
		.AddGroup(B_HORIZONTAL, 10)
			.Add(focusField)
			.AddGlue()
			.AddGroup(B_VERTICAL, 0)
				.Add(fAcceptFirstClickBox)
			.End()
		.End()
		.SetInsets(5, 5, 5, 5)
	);
}
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();
}
Exemple #6
0
FindWindow::FindWindow(BMessenger messenger, const BString& str,
	bool findSelection, bool matchWord, bool matchCase, bool forwardSearch)
	:
	BWindow(kWindowFrame, B_TRANSLATE("Find"), B_FLOATING_WINDOW,
		B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_CLOSE_ON_ESCAPE
		| B_AUTO_UPDATE_SIZE_LIMITS),
	fFindDlgMessenger(messenger)
{
	SetLayout(new BGroupLayout(B_VERTICAL));

	BBox* separator = new BBox("separator");
	separator->SetExplicitMinSize(BSize(250.0, B_SIZE_UNSET));
	separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1.0));

	BRadioButton* useSelection = NULL;
	const float spacing = be_control_look->DefaultItemSpacing();
	AddChild(BGroupLayoutBuilder(B_VERTICAL, B_USE_SMALL_SPACING)
		.SetInsets(spacing, spacing, spacing, spacing)
		.Add(BGridLayoutBuilder(B_USE_SMALL_SPACING, B_USE_SMALL_SPACING)
			.Add(fTextRadio = new BRadioButton(B_TRANSLATE("Use text:"),
				new BMessage(TOGGLE_FIND_CONTROL)), 0, 0)
			.Add(fFindLabel = new BTextControl(NULL, NULL, NULL), 1, 0)
			.Add(useSelection = new BRadioButton(B_TRANSLATE("Use selection"),
				new BMessage(TOGGLE_FIND_CONTROL)), 0, 1))
		.Add(BSpaceLayoutItem::CreateVerticalStrut(spacing / 4))
		.Add(separator)
		.Add(BSpaceLayoutItem::CreateVerticalStrut(spacing / 4))
		.Add(fForwardSearchBox = new BCheckBox(B_TRANSLATE("Search forward")))
		.Add(fMatchCaseBox = new BCheckBox(B_TRANSLATE("Match case")))
		.Add(fMatchWordBox = new BCheckBox(B_TRANSLATE("Match word")))
		.AddGroup(B_HORIZONTAL)
			.AddGlue()
			.Add(fFindButton = new BButton(B_TRANSLATE("Find"),
				new BMessage(MSG_FIND)))
			.End()
		.TopView());

	fFindLabel->SetDivider(0.0);

	if (!findSelection) {
		fFindLabel->SetText(str.String());
		fFindLabel->MakeFocus(true);
	} else {
		fFindLabel->SetEnabled(false);
	}

	if (findSelection)
		useSelection->SetValue(B_CONTROL_ON);
	else
		fTextRadio->SetValue(B_CONTROL_ON);

	if (forwardSearch)
		fForwardSearchBox->SetValue(B_CONTROL_ON);

	if (matchCase)
		fMatchCaseBox->SetValue(B_CONTROL_ON);

	if (matchWord)
		fMatchWordBox->SetValue(B_CONTROL_ON);

	fFindButton->MakeDefault(true);

	AddShortcut((uint32)'W', B_COMMAND_KEY, new BMessage(MSG_FIND_HIDE));
}
Exemple #7
0
void
PrintOptionsWindow::Setup()
{
    BString value;
    enum PrintOptions::Option op = fCurrentOptions.Option();
    BRadioButton* rbFit;
    BRadioButton* rbZoom;
    BRadioButton* rbDpi;
    BRadioButton* rbResize;
    BBox* line;
    BButton* button;

    rbFit = AddRadioButton("fit_to_page", B_TRANSLATE("Fit image to page"),
                           kMsgFitToPageSelected, op == PrintOptions::kFitToPage);

    rbZoom = AddRadioButton("zoom_factor", B_TRANSLATE("Zoom factor in %:"),
                            kMsgZoomFactorSelected, op == PrintOptions::kZoomFactor);

    fZoomFactor = AddTextControl("zoom_factor_text", "",
                                 fCurrentOptions.ZoomFactor() * 100, kMsgZoomFactorChanged);

    rbDpi = AddRadioButton("dpi", B_TRANSLATE("DPI:"), kMsgDPISelected,
                           op == PrintOptions::kDPI);

    fDPI = AddTextControl("dpi_text", "", fCurrentOptions.DPI(),
                          kMsgDPIChanged);

    rbResize = AddRadioButton("width_and_height",
                              B_TRANSLATE("Resize to (in 1/72 inches):"), kMsgWidthAndHeightSelected,
                              op == PrintOptions::kWidth || op == PrintOptions::kHeight);

    fWidth = AddTextControl("width", B_TRANSLATE("Width:"),
                            fCurrentOptions.Width(), kMsgWidthChanged);

    fHeight = AddTextControl("height", B_TRANSLATE("Height: "),
                             fCurrentOptions.Height(), kMsgHeightChanged);

    line = new BBox(B_EMPTY_STRING, B_WILL_DRAW | B_FRAME_EVENTS,
                    B_FANCY_BORDER);
    line->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));

    button = new BButton("job setup", B_TRANSLATE("Job setup"),
                         new BMessage(kMsgJobSetup));
    SetDefaultButton(button);

    const float spacing = be_control_look->DefaultItemSpacing();

    SetLayout(new BGroupLayout(B_HORIZONTAL));
    AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
             .Add(BGridLayoutBuilder()
                  .Add(rbFit, 0, 0)
                  .Add(rbZoom, 0, 1)
                  .Add(fZoomFactor, 1, 1)
                  .Add(rbDpi, 0, 2)
                  .Add(fDPI, 1, 2)
                  .Add(rbResize, 0, 3)
                 )
             .AddGroup(B_HORIZONTAL, spacing)
             .Add(fWidth)
             .Add(fHeight)
             .AddGlue()
             .SetInsets(22, 0, 0, 0)
             .End()
             .Add(line)
             .AddGroup(B_HORIZONTAL, 0)
             .Add(button)
             .End()
             .SetInsets(spacing, spacing, spacing, spacing)
            );
}
PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
    : BlockingWindow(BRect(0, 0, 100, 100), "Page setup",
                     B_TITLED_WINDOW_LOOK,
                     B_MODAL_APP_WINDOW_FEEL,
                     B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE
                     | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE),
      fSetupMsg(msg),
      fPrinterDirName(printerName)
{
    if (printerName)
        SetTitle(BString(printerName).Append(" Page setup").String());

    // load orientation
    if (fSetupMsg->FindInt32("orientation", &fCurrentOrientation) != B_OK)
        fCurrentOrientation = PrinterDriver::PORTRAIT_ORIENTATION;

    // load page rect
    BRect page;
    float width = letter_width;
    float height = letter_height;
    if (fSetupMsg->FindRect("preview:paper_rect", &page) == B_OK) {
        width = page.Width();
        height = page.Height();
    } else {
        page.Set(0, 0, width, height);
    }

    BString label;
    if (fSetupMsg->FindString("preview:paper_size", &label) != B_OK)
        label = "Letter";

    // Load units
    int32 units;
    if (fSetupMsg->FindInt32("units", &units) != B_OK)
        units = kUnitInch;

    // re-calculate the margin from the printable rect in points
    BRect margin = page;
    if (fSetupMsg->FindRect("preview:printable_rect", &margin) == B_OK) {
        margin.top -= page.top;
        margin.left -= page.left;
        margin.right = page.right - margin.right;
        margin.bottom = page.bottom - margin.bottom;
    } else {
        margin.Set(28.34, 28.34, 28.34, 28.34);		// 28.34 dots = 1cm
    }


    fMarginView = new MarginView(int32(width), int32(height), margin,
                                 MarginUnit(units));

    BPopUpMenu* pageSizePopUpMenu = new BPopUpMenu("Page size");
    pageSizePopUpMenu->SetRadioMode(true);

    fPageSizeMenu = new BMenuField("page_size", "Page size:", pageSizePopUpMenu);
    fPageSizeMenu->Menu()->SetLabelFromMarked(true);

    for (int32 i = 0; pageFormat[i].label != NULL; i++) {
        BMessage* message = new BMessage(PAGE_SIZE_CHANGED);
        message->AddFloat("width", pageFormat[i].width);
        message->AddFloat("height", pageFormat[i].height);
        BMenuItem* item = new BMenuItem(pageFormat[i].label, message);
        pageSizePopUpMenu->AddItem(item);

        if (label.Compare(pageFormat[i].label) == 0)
            item->SetMarked(true);
    }

    BPopUpMenu* orientationPopUpMenu = new BPopUpMenu("Orientation");
    orientationPopUpMenu->SetRadioMode(true);

    fOrientationMenu = new BMenuField("orientation", "Orientation:",
                                      orientationPopUpMenu);
    fOrientationMenu->Menu()->SetLabelFromMarked(true);

    for (int32 i = 0; orientation[i].label != NULL; i++) {
        BMessage* message = new BMessage(ORIENTATION_CHANGED);
        message->AddInt32("orientation", orientation[i].orientation);
        BMenuItem* item = new BMenuItem(orientation[i].label, message);
        orientationPopUpMenu->AddItem(item);

        if (fCurrentOrientation == orientation[i].orientation)
            item->SetMarked(true);
    }

    float scale0;
    BString scale;
    if (fSetupMsg->FindFloat("scale", &scale0) == B_OK)
        scale << (int)scale0;
    else
        scale = "100";

    fScaleControl = new BTextControl("scale", "Scale [%]:",
                                     scale.String(), NULL);

    for (uint32 i = 0; i < '0'; i++)
        fScaleControl->TextView()->DisallowChar(i);

    for (uint32 i = '9' + 1; i < 255; i++)
        fScaleControl->TextView()->DisallowChar(i);

    fScaleControl->TextView()->SetMaxBytes(3);

    BBox *separator = new BBox("separator");
    separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));

    BButton *cancel = new BButton("cancel", "Cancel", new BMessage(CANCEL_MSG));

    BButton *ok = new BButton("ok", "OK", new BMessage(OK_MSG));
    ok->MakeDefault(true);

    BGridView* settings = new BGridView();
    BGridLayout* settingsLayout = settings->GridLayout();
    settingsLayout->AddItem(fPageSizeMenu->CreateLabelLayoutItem(), 0, 0);
    settingsLayout->AddItem(fPageSizeMenu->CreateMenuBarLayoutItem(), 1, 0);
    settingsLayout->AddItem(fOrientationMenu->CreateLabelLayoutItem(), 0, 1);
    settingsLayout->AddItem(fOrientationMenu->CreateMenuBarLayoutItem(), 1, 1);
    settingsLayout->AddItem(fScaleControl->CreateLabelLayoutItem(), 0, 2);
    settingsLayout->AddItem(fScaleControl->CreateTextViewLayoutItem(), 1, 2);
    settingsLayout->SetSpacing(0, 0);

    SetLayout(new BGroupLayout(B_VERTICAL));
    AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
             .AddGroup(B_HORIZONTAL, 5, 1)
             .AddGroup(B_VERTICAL, 0, 1.0f)
             .Add(fMarginView)
             .AddGlue()
             .End()
             .AddGroup(B_VERTICAL, 0, 1.0f)
             .Add(settings)
             .AddGlue()
             .End()
             .End()
             .Add(separator)
             .AddGroup(B_HORIZONTAL, 10, 1.0f)
             .AddGlue()
             .Add(cancel)
             .Add(ok)
             .End()
             .SetInsets(10, 10, 10, 10)
            );

    BRect winFrame(Frame());
    BRect screenFrame(BScreen().Frame());
    MoveTo((screenFrame.right - winFrame.right) / 2,
           (screenFrame.bottom - winFrame.bottom) / 2);
}
void
BJobSetupPanel::_SetupInterface()
{
    BGroupView* groupView = new BGroupView(B_VERTICAL, 10.0);

    // printers
    fPrinterPopUp = new BPopUpMenu("");
    fPrinterPopUp->SetRadioMode(true);
    fPrinterMenuField = new BMenuField("", fPrinterPopUp);
    fPrinterMenuField->Menu()->SetLabelFromMarked(true);

    BPrinter printer;
    while (fPrinterRoster->GetNextPrinter(&printer) == B_OK) {
        BMenuItem* item = new BMenuItem(printer.Name().String(), NULL);
        fPrinterPopUp->AddItem(item);
        if (printer == *fPrinter)
            item->SetMarked(true);
    }

    if (fPrinterRoster->CountPrinters() > 0)
        fPrinterPopUp->AddItem(new BSeparatorItem);

    BMenuItem* pdf = new BMenuItem("Save as PDF file" , NULL);
    fPrinterPopUp->AddItem(pdf);
    if (fPrinterPopUp->FindMarked() == NULL)
        pdf->SetMarked(true);

    fProperties = new BButton("Properties" B_UTF8_ELLIPSIS , new BMessage('prop'));
    fPrinterInfo = new BStringView("label", "");
    fPrinterInfo->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
    BBox* divider = new BBox(B_FANCY_BORDER, NULL);
    divider->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));
    fPrintToFile = new BCheckBox("Print to file");

    BView* view = BGroupLayoutBuilder(B_VERTICAL, 5.0)
                  .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10.0)
                       .Add(fPrinterMenuField->CreateMenuBarLayoutItem())
                       .Add(fProperties))
                  .Add(BGroupLayoutBuilder(B_HORIZONTAL,5.0)
                       .Add(new BStringView("label", "Printer info:"))
                       .Add(fPrinterInfo))
                  .Add(divider)
                  .Add(fPrintToFile)
                  .SetInsets(10.0, 5.0, 10.0, 5.0);

    BBox *box = new BBox(B_FANCY_BORDER, view);
    box->SetLabel(BGroupLayoutBuilder()
                  .Add(new BStringView("", "Printer"))
                  .SetInsets(2.0, 0.0, 2.0, 0.0));
    groupView->AddChild(box);

    // page range
    fPrintAll = new BRadioButton("Print all", new BMessage('prrg'));
    fPrintAll->SetValue(B_CONTROL_ON);
    fPagesFrom = new BRadioButton("Pages from:", new BMessage('prrg'));
    fFirstPage = new BTextControl("", "", NULL);
    _DisallowChar(fFirstPage->TextView());
    fLastPage = new BTextControl("to:", "", NULL);
    _DisallowChar(fLastPage->TextView());
    fSelection = new BRadioButton("Print selection", new BMessage('prrg'));

    fFirstPage->CreateLabelLayoutItem();
    view = BGroupLayoutBuilder(B_VERTICAL, 5.0)
           .Add(fPrintAll)
           .Add(BGroupLayoutBuilder(B_HORIZONTAL, 5.0)
                .Add(fPagesFrom)
                .Add(fFirstPage->CreateTextViewLayoutItem())
                .Add(fLastPage->CreateLabelLayoutItem())
                .Add(fLastPage->CreateTextViewLayoutItem()))
           .Add(fSelection)
           .SetInsets(10.0, 5.0, 10.0, 5.0);

    box = new BBox(B_FANCY_BORDER, view);
    box->SetLabel(BGroupLayoutBuilder()
                  .Add(new BStringView("", "Page range"))
                  .SetInsets(2.0, 0.0, 2.0, 0.0));

    // copies
    fNumberOfCopies = new BTextControl("Number of copies:", "1", NULL);
    _DisallowChar(fNumberOfCopies->TextView());
    fCollate = new BCheckBox("Collate");
    fReverse = new BCheckBox("Reverse");

    BView* view2 = BGroupLayoutBuilder(B_VERTICAL, 5.0)
                   .Add(BGroupLayoutBuilder(B_HORIZONTAL, 5.0)
                        .Add(fNumberOfCopies->CreateLabelLayoutItem())
                        .Add(fNumberOfCopies->CreateTextViewLayoutItem()))
                   .Add(fCollate)
                   .Add(fReverse)
                   .SetInsets(10.0, 5.0, 10.0, 5.0);

    BBox* box2 = new BBox(B_FANCY_BORDER, view2);
    box2->SetLabel(BGroupLayoutBuilder()
                   .Add(new BStringView("", "Copies"))
                   .SetInsets(2.0, 0.0, 2.0, 0.0));

    groupView->AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 10.0)
                        .Add(box)
                        .Add(box2));

    // other
    fColor = new BCheckBox("Print in color");
    fDuplex = new BCheckBox("Double side printing");

    view = BGroupLayoutBuilder(B_VERTICAL, 5.0)
           .Add(fColor)
           .Add(fDuplex)
           .SetInsets(10.0, 5.0, 10.0, 5.0);

    box = new BBox(B_FANCY_BORDER, view);
    box->SetLabel(BGroupLayoutBuilder()
                  .Add(new BStringView("", "Other"))
                  .SetInsets(2.0, 0.0, 2.0, 0.0));
    groupView->AddChild(box);

    AddPanel(groupView);
    SetOptionFlags(fJobPanelFlags);
}
Exemple #10
0
void 
JobSetupView::AttachedToWindow()
{
	// quality
	BBox* qualityBox = new BBox("quality");
	qualityBox->SetLabel("Quality");

	// color
	fColorType = new BPopUpMenu("color");
	fColorType->SetRadioMode(true);
	FillCapabilityMenu(fColorType, kMsgQuality, PrinterCap::kColor,
		fJobData->GetColor());
	BMenuField* colorMenuField = new BMenuField("color", "Color:", fColorType);
	fColorType->SetTargetForItems(this);
	
	if (IsHalftoneConfigurationNeeded())
		CreateHalftoneConfigurationUI();

	// page range

	BBox* pageRangeBox = new BBox("pageRange");
	pageRangeBox->SetLabel("Page Range");

	fAll = new BRadioButton("all", "Print all Pages", new BMessage(kMsgRangeAll));

	BRadioButton *range = new BRadioButton("selection", "Print selected Pages:",
		new BMessage(kMsgRangeSelection));

	fFromPage = new BTextControl("from", "From:", "", NULL);
	fFromPage->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
	AllowOnlyDigits(fFromPage->TextView(), 6);

	fToPage = new BTextControl("to", "To:", "", NULL);
	fToPage->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
	AllowOnlyDigits(fToPage->TextView(), 6);

	int first_page = fJobData->GetFirstPage();
	int last_page  = fJobData->GetLastPage();

	if (first_page <= 1 && last_page <= 0) {
		fAll->SetValue(B_CONTROL_ON);
	} else {
		range->SetValue(B_CONTROL_ON);
		if (first_page < 1)
			first_page = 1;
		if (first_page > last_page)
			last_page = -1;

		BString oss1;
		oss1 << first_page;
		fFromPage->SetText(oss1.String());

		BString oss2;
		oss2 << last_page;
		fToPage->SetText(oss2.String());
	}

	fAll->SetTarget(this);
	range->SetTarget(this);

	// paper source
	fPaperFeed = new BPopUpMenu("");
	fPaperFeed->SetRadioMode(true);
	FillCapabilityMenu(fPaperFeed, kMsgNone, PrinterCap::kPaperSource,
		fJobData->GetPaperSource());
	BMenuField* paperSourceMenufield = new BMenuField("paperSource",
		"Paper Source:", fPaperFeed);

	// Pages per sheet
	fNup = new BPopUpMenu("");
	fNup->SetRadioMode(true);
	FillCapabilityMenu(fNup, kMsgNone, gNups,
		sizeof(gNups) / sizeof(gNups[0]), (int)fJobData->GetNup());
	BMenuField* pagesPerSheet = new BMenuField("pagesPerSheet",
		"Pages Per Sheet:", fNup);

	// duplex
	if (fPrinterCap->Supports(PrinterCap::kPrintStyle)) {
		fDuplex = new BCheckBox("duplex", "Duplex",
			new BMessage(kMsgDuplexChanged));
		if (fJobData->GetPrintStyle() != JobData::kSimplex) {
			fDuplex->SetValue(B_CONTROL_ON);
		}
		fDuplex->SetTarget(this);
	} else {
		fDuplex = NULL;
	}

	// copies
	fCopies = new BTextControl("copies", "Number of Copies:", "", NULL);
	AllowOnlyDigits(fCopies->TextView(), 3);

	BString copies;
	copies << fJobData->GetCopies();
	fCopies->SetText(copies.String());

	// collate
	fCollate = new BCheckBox("collate", "Collate",
		new BMessage(kMsgCollateChanged));
	if (fJobData->GetCollate()) {
		fCollate->SetValue(B_CONTROL_ON);
	}
	fCollate->SetTarget(this);

	// reverse
	fReverse = new BCheckBox("reverse", "Reverse Order",
		new BMessage(kMsgReverseChanged));
	if (fJobData->GetReverse()) {
		fReverse->SetValue(B_CONTROL_ON);
	}
	fReverse->SetTarget(this);

	// pages view
	// TODO make layout API compatible
	fPages = new PagesView(BRect(0, 0, 150, 40), "pages", B_FOLLOW_ALL,
		B_WILL_DRAW);
	fPages->SetCollate(fJobData->GetCollate());
	fPages->SetReverse(fJobData->GetReverse());
	fPages->SetExplicitMinSize(BSize(150, 40));
	fPages->SetExplicitMaxSize(BSize(150, 40));
	
	// page selection
	BBox* pageSelectionBox = new BBox("pageSelection");
	pageSelectionBox->SetLabel("Page Selection");
	
	fAllPages = CreatePageSelectionItem("allPages", "All Pages",
		JobData::kAllPages);
	fOddNumberedPages = CreatePageSelectionItem("oddPages",
		"Odd-Numbered Pages", JobData::kOddNumberedPages);
	fEvenNumberedPages = CreatePageSelectionItem("evenPages",
		"Even-Numbered Pages", JobData::kEvenNumberedPages);

	fPreview = new BCheckBox("preview", "Show preview before printing", NULL);
	if (fJobData->GetShowPreview())
		fPreview->SetValue(B_CONTROL_ON);

	// separator line
	BBox *separator = new BBox("separator");
	separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));

	// buttons
	BButton* cancel = new BButton("cancel", "Cancel",
		new BMessage(kMsgCancel));
	BButton* ok = new BButton("ok", "OK", new BMessage(kMsgOK));
	ok->MakeDefault(true);
	
	if (IsHalftoneConfigurationNeeded()) {
		BGroupView* halftoneGroup = new BGroupView(B_VERTICAL, 0);
		BGroupLayout* halftoneLayout = halftoneGroup->GroupLayout();
		halftoneLayout->AddView(fHalftone);
		fHalftoneBox->AddChild(halftoneGroup);
	}

	BGridView* qualityGrid = new BGridView();
	BGridLayout* qualityGridLayout = qualityGrid->GridLayout();
	qualityGridLayout->AddItem(colorMenuField->CreateLabelLayoutItem(), 0, 0);
	qualityGridLayout->AddItem(colorMenuField->CreateMenuBarLayoutItem(), 1, 0);
	if (IsHalftoneConfigurationNeeded()) {
		qualityGridLayout->AddItem(fDitherMenuField->CreateLabelLayoutItem(),
			0, 1);
		qualityGridLayout->AddItem(fDitherMenuField->CreateMenuBarLayoutItem(),
			1, 1);
		qualityGridLayout->AddView(fGamma, 0, 2, 2);
		qualityGridLayout->AddView(fInkDensity, 0, 3, 2);
		qualityGridLayout->AddView(fHalftoneBox, 0, 4, 2);
	} else {
		AddDriverSpecificSettings(qualityGridLayout, 1);
	}
	qualityGridLayout->SetSpacing(0, 0);
	qualityGridLayout->SetInsets(5, 5, 5, 5);
	qualityBox->AddChild(qualityGrid);
	// TODO put qualityGrid in a scroll view
	// the layout of the box surrounding the scroll view using the following
	// code is not correct; the box still has the size of the qualityGird;
	// and the scroll view is vertically centered inside the box!
	//BScrollView* qualityScroller = new BScrollView("qualityScroller",
	//	qualityGrid, 0, false, true);
	//qualityScroller->SetExplicitMaxSize(BSize(500, 500));
	//qualityBox->AddChild(qualityScroller);

	BGridView* pageRangeGrid = new BGridView();
	BGridLayout* pageRangeLayout = pageRangeGrid->GridLayout();
	pageRangeLayout->AddItem(fFromPage->CreateLabelLayoutItem(), 0, 0);
	pageRangeLayout->AddItem(fFromPage->CreateTextViewLayoutItem(), 1, 0);
	pageRangeLayout->AddItem(fToPage->CreateLabelLayoutItem(), 0, 1);
	pageRangeLayout->AddItem(fToPage->CreateTextViewLayoutItem(), 1, 1);
	pageRangeLayout->SetInsets(0, 0, 0, 0);
	pageRangeLayout->SetSpacing(0, 0);

	BGroupView* pageRangeGroup = new BGroupView(B_VERTICAL, 0);
	BGroupLayout* pageRangeGroupLayout = pageRangeGroup->GroupLayout();
	pageRangeGroupLayout->AddView(fAll);
	pageRangeGroupLayout->AddView(range);
	pageRangeGroupLayout->AddView(pageRangeGrid);
	pageRangeGroupLayout->SetInsets(5, 5, 5, 5);
	pageRangeBox->AddChild(pageRangeGroup);

	BGridView* settings = new BGridView();
	BGridLayout* settingsLayout = settings->GridLayout();
	settingsLayout->AddItem(paperSourceMenufield->CreateLabelLayoutItem(), 0,
		0);
	settingsLayout->AddItem(paperSourceMenufield->CreateMenuBarLayoutItem(), 1,
		0);
	settingsLayout->AddItem(pagesPerSheet->CreateLabelLayoutItem(), 0, 1);
	settingsLayout->AddItem(pagesPerSheet->CreateMenuBarLayoutItem(), 1, 1);
	int row = 2;
	if (fDuplex != NULL) {
		settingsLayout->AddView(fDuplex, 0, row, 2);
		row ++;
	}
	settingsLayout->AddItem(fCopies->CreateLabelLayoutItem(), 0, row);
	settingsLayout->AddItem(fCopies->CreateTextViewLayoutItem(), 1, row);
	settingsLayout->SetSpacing(0, 0);


	BGroupView* pageSelectionGroup = new BGroupView(B_VERTICAL, 0);
	BGroupLayout* groupLayout = pageSelectionGroup->GroupLayout();
	groupLayout->AddView(fAllPages);
	groupLayout->AddView(fOddNumberedPages);
	groupLayout->AddView(fEvenNumberedPages);
	groupLayout->SetInsets(5, 5, 5, 5);
	pageSelectionBox->AddChild(pageSelectionGroup);

	SetLayout(new BGroupLayout(B_VERTICAL));
	AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
		.AddGroup(B_HORIZONTAL, 10, 1.0f)
			.AddGroup(B_VERTICAL, 10, 1.0f)
				.Add(qualityBox)
				.Add(pageRangeBox)
				.AddGlue()
			.End()
			.AddGroup(B_VERTICAL, 0, 1.0f)
				.Add(settings)
				.AddStrut(5)
				.Add(fCollate)
				.Add(fReverse)
				.Add(fPages)
				.AddStrut(5)
				.Add(pageSelectionBox)
				.AddGlue()
			.End()
		.End()
		.Add(fPreview)
		.AddGlue()
		.Add(separator)
		.AddGroup(B_HORIZONTAL, 10, 1.0f)
			.AddGlue()
			.Add(cancel)
			.Add(ok)
		.End()
		.SetInsets(0, 0, 0, 0)
	);

	UpdateHalftonePreview();

	UpdateButtonEnabledState();
}
Exemple #11
0
PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
	: HWindow(BRect(0, 0, 200, 100), "Page setup", B_TITLED_WINDOW_LOOK,
 		B_MODAL_APP_WINDOW_FEEL,
 		B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE
			| B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE),
	 fResult(B_ERROR),
	 fSetupMsg(msg),
	 fAdvancedSettings(*msg),
	 fPrinterDirName(printerName)
{
	fExitSem = create_sem(0, "PageSetup");

	if (printerName)
		SetTitle(BString(printerName).Append(" page setup").String());

	if (fSetupMsg->FindInt32("orientation", &fCurrentOrientation) != B_OK)
		fCurrentOrientation = PrinterDriver::PORTRAIT_ORIENTATION;

	BRect page;
	float width = letter_width;
	float height = letter_height;
	if (fSetupMsg->FindRect("paper_rect", &page) == B_OK) {
		width = page.Width();
		height = page.Height();
	} else {
		page.Set(0, 0, width, height);
	}

	BString label;
	if (fSetupMsg->FindString("pdf_paper_size", &label) != B_OK)
		label = "Letter";

	int32 compression;
	fSetupMsg->FindInt32("pdf_compression", &compression);

	int32 units;
	if (fSetupMsg->FindInt32("units", &units) != B_OK)
		units = kUnitInch;

	// re-calculate the margin from the printable rect in points
	BRect margin = page;
	if (fSetupMsg->FindRect("printable_rect", &margin) == B_OK) {
		margin.top -= page.top;
		margin.left -= page.left;
		margin.right = page.right - margin.right;
		margin.bottom = page.bottom - margin.bottom;
	} else {
		margin.Set(28.34, 28.34, 28.34, 28.34);		// 28.34 dots = 1cm
	}

	BString setting_value;
	if (fSetupMsg->FindString("pdf_compatibility", &setting_value) != B_OK)
		setting_value = "1.3";

	// Load font settings
	fFonts = new Fonts();
	fFonts->CollectFonts();
	BMessage fonts;
	if (fSetupMsg->FindMessage("fonts", &fonts) == B_OK)
		fFonts->SetTo(&fonts);

	fMarginView = new MarginView(int32(width), int32(height), margin,
		MarginUnit(units));

	BPopUpMenu* pageSize = new BPopUpMenu("Page size");
	pageSize->SetRadioMode(true);

	fPageSizeMenu = new BMenuField("page_size", "Page size:", pageSize);
	fPageSizeMenu->Menu()->SetLabelFromMarked(true);

	for (int32 i = 0; pageFormat[i].label != NULL; i++) {
		BMessage* message = new BMessage(PAGE_SIZE_CHANGED);
		message->AddFloat("width", pageFormat[i].width);
		message->AddFloat("height", pageFormat[i].height);
		BMenuItem* item = new BMenuItem(pageFormat[i].label, message);
		pageSize->AddItem(item);

		if (label.Compare(pageFormat[i].label) == 0)
			item->SetMarked(true);
	}

	BPopUpMenu* orientationPopUpMenu = new BPopUpMenu("Orientation");
	orientationPopUpMenu->SetRadioMode(true);

	fOrientationMenu = new BMenuField("orientation", "Orientation:",
		orientationPopUpMenu);
	fOrientationMenu->Menu()->SetLabelFromMarked(true);

	for (int32 i = 0; orientation[i].label != NULL; i++) {
	 	BMessage* message = new BMessage(ORIENTATION_CHANGED);
		message->AddInt32("orientation", orientation[i].orientation);
		BMenuItem* item = new BMenuItem(orientation[i].label, message);
		orientationPopUpMenu->AddItem(item);

		if (fCurrentOrientation == orientation[i].orientation)
			item->SetMarked(true);
	}

	BPopUpMenu* compatibility = new BPopUpMenu("PDF compatibility");
	compatibility->SetRadioMode(true);

	fPDFCompatibilityMenu = new BMenuField("pdf_compatibility",
		"PDF compatibility:", compatibility);
	fPDFCompatibilityMenu->Menu()->SetLabelFromMarked(true);

	for (int32 i = 0; pdf_compatibility[i] != NULL; i++) {
		BMenuItem* item = new BMenuItem(pdf_compatibility[i], NULL);
		compatibility->AddItem(item);
		if (setting_value == pdf_compatibility[i])
			item->SetMarked(true);
	}

	fPDFCompressionSlider = new BSlider("pdf_compression",
		"Compression:", NULL, 0, 9, B_HORIZONTAL);
	fPDFCompressionSlider->SetLimitLabels("None", "Best");
	fPDFCompressionSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
	fPDFCompressionSlider->SetValue(compression);

	BBox *separator = new BBox("separator");
	separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));

	BButton *cancel = new BButton("cancel", "Cancel", new BMessage(CANCEL_MSG));

	BButton *ok = new BButton("ok", "OK", new BMessage(OK_MSG));
	ok->MakeDefault(true);

	BButton *fontsButton = new BButton("fonts", "Fonts" B_UTF8_ELLIPSIS,
		new BMessage(FONTS_MSG));

	BButton* advancedButton = new BButton("advanced",
		"Advanced" B_UTF8_ELLIPSIS,
		new BMessage(ADVANCED_MSG));

	BGridView* settings = new BGridView();
	BGridLayout* settingsLayout = settings->GridLayout();
	settingsLayout->AddItem(fPageSizeMenu->CreateLabelLayoutItem(), 0, 0);
	settingsLayout->AddItem(fPageSizeMenu->CreateMenuBarLayoutItem(), 1, 0);
	settingsLayout->AddItem(fOrientationMenu->CreateLabelLayoutItem(), 0, 1);
	settingsLayout->AddItem(fOrientationMenu->CreateMenuBarLayoutItem(), 1, 1);
	settingsLayout->AddItem(fPDFCompatibilityMenu->CreateLabelLayoutItem(), 0, 2);
	settingsLayout->AddItem(fPDFCompatibilityMenu->CreateMenuBarLayoutItem(), 1, 2);
	settingsLayout->AddView(fPDFCompressionSlider, 0, 3, 2);
	settingsLayout->SetSpacing(0, 0);

	SetLayout(new BGroupLayout(B_VERTICAL));
	AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
		.AddGroup(B_HORIZONTAL, 5, 1)
			.AddGroup(B_VERTICAL, 0, 1.0f)
				.Add(fMarginView)
				.AddGlue()
			.End()
			.AddGroup(B_VERTICAL, 0, 1.0f)
				.Add(settings)
				.AddGlue()
			.End()
		.End()
		.Add(separator)
		.AddGroup(B_HORIZONTAL, 10, 1.0f)
			.Add(fontsButton)
			.Add(advancedButton)
			.AddGlue()
			.Add(cancel)
			.Add(ok)
		.End()
		.SetInsets(10, 10, 10, 10)
	);

	BRect winFrame(Frame());
	BRect screenFrame(BScreen().Frame());
	MoveTo((screenFrame.right - winFrame.right) / 2,
		(screenFrame.bottom - winFrame.bottom) / 2);
}
Exemple #12
0
// --------------------------------------------------
JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName)
	:	HWindow(BRect(0, 0, 100, 100), "Job Setup",
			B_TITLED_WINDOW_LOOK,
			B_MODAL_APP_WINDOW_FEEL,
			B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE
				| B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE)
{
	fSetupMsg = msg;
	fExitSem = create_sem(0, "JobSetup");
	fResult	= B_ERROR;
	
	if (printerName) {
		BString	title;
		title << printerName << " Job Setup";
		SetTitle(title.String());
		fPrinterName = printerName;
	}
	
	// PrinterDriver ensures that property exists
	int32 firstPage;
	fSetupMsg->FindInt32("first_page", &firstPage);
	int32 lastPage;
	fSetupMsg->FindInt32("last_page",  &lastPage);

	BMessage doc_info;
	if (fSetupMsg->FindMessage("doc_info", &doc_info) != B_OK) {
		// default fields
		doc_info.AddString("Author", "");
		doc_info.AddString("Subject", "");
		doc_info.AddString("Keywords", "");
		fSetupMsg->AddMessage("doc_info", &doc_info);
	}
	AddFields(&fDocInfo, fSetupMsg, NULL, includeKeys);
	
	bool allPages = firstPage == 1 && lastPage == MAX_INT32;

	fAll = new BRadioButton("allPages", "Print all pages",
		new BMessage(ALL_PAGES_MGS));
	fAll->SetValue(allPages);

	fRange = new BRadioButton("pagesRange", "Print pages:",
		new BMessage(RANGE_SELECTION_MSG));
	fRange->SetValue(!allPages);

	fFrom = new BTextControl("from", "From:", "SomeSpaceHere", NULL);
	fFrom->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
	fFrom->SetEnabled(!allPages);

	fTo = new BTextControl("to", "To:", "", NULL);
	fTo->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
	fTo->SetEnabled(!allPages);

	BString buffer;
	buffer << firstPage;
	fFrom->SetText(buffer.String());

	buffer = "";
	buffer << lastPage;
	fTo->SetText(buffer.String());

	for (uint32 i = 0; i < '0'; i++) {
		fTo->TextView()->DisallowChar(i);
		fFrom->TextView()->DisallowChar(i);
	}

	for (uint32 i = '9' + 1; i < 255; i++) {
		fTo->TextView()->DisallowChar(i);
		fFrom->TextView()->DisallowChar(i);
	}

	BBox *separator = new BBox("separator");
	separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));

	BButton *documentInfo = new BButton("documentInfo",
		"Document"  B_UTF8_ELLIPSIS,
		new BMessage(DOC_INFO_MSG));

	BButton *cancel = new BButton("cancel", "Cancel", new BMessage(CANCEL_MSG));

	BButton *ok = new BButton("ok", "OK", new BMessage(OK_MSG));
	ok->MakeDefault(true);

	BGridView* settings = new BGridView();
	BGridLayout* settingsLayout = settings->GridLayout();
	settingsLayout->AddItem(fFrom->CreateLabelLayoutItem(), 0, 0);
	settingsLayout->AddItem(fFrom->CreateTextViewLayoutItem(), 1, 0);
	settingsLayout->AddItem(fTo->CreateLabelLayoutItem(), 0, 1);
	settingsLayout->AddItem(fTo->CreateTextViewLayoutItem(), 1, 1);
	settingsLayout->SetSpacing(0, 0);

	SetLayout(new BGroupLayout(B_VERTICAL));
	AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
		.Add(fAll)
		.Add(fRange)
		.Add(settings)
		.AddGlue()
		.Add(separator)
		.AddGroup(B_HORIZONTAL, 10, 1.0f)
			.Add(documentInfo)
			.AddGlue()
			.Add(cancel)
			.Add(ok)
		.End()
		.SetInsets(10, 10, 10, 10)
	);
}
Exemple #13
0
void
AddPrinterView::AttachedToWindow()
{
	// protocol class box
	BBox* protocolClassBox = new BBox("protocolClass");
	protocolClassBox->SetLabel("Protocol classes:");

	// protocol class
	fProtocolClassList = new BListView("protocolClassList");
	fProtocolClassList->SetExplicitMinSize(BSize(500, 200));
	BScrollView* protocolClassScroller = new BScrollView(
		"protocolClassListScroller",
		fProtocolClassList,
		0,
		false,
		true,
		B_NO_BORDER);
	fProtocolClassList->SetSelectionMessage(
		new BMessage(kMsgProtocolClassChanged));
	fProtocolClassList->SetTarget(this);

	protocolClassBox->AddChild(protocolClassScroller);

	int count = fPrinterCap->CountCap(PrinterCap::kProtocolClass);
	ProtocolClassCap **protocolClasses =
		(ProtocolClassCap **)fPrinterCap->GetCaps(PrinterCap::kProtocolClass);
	while (count--) {
		const ProtocolClassCap *protocolClass = *protocolClasses;

		BStringItem* item = new ProtocolClassItem(protocolClass);
		fProtocolClassList->AddItem(item);
		if (protocolClass->fIsDefault) {
			int index = fProtocolClassList->IndexOf(item);
			fProtocolClassList->Select(index);
		}
		protocolClasses ++;
	}

	// description of protocol class box
	BBox* descriptionBox = new BBox("descriptionBox");
	descriptionBox->SetLabel("Description:");

	// description of protocol class
	fDescription = new BTextView("description");
	fDescription->SetExplicitMinSize(BSize(200, 200));
	fDescription->SetViewColor(descriptionBox->ViewColor());
	BScrollView* descriptionScroller = new BScrollView("descriptionScroller",
			fDescription,
			0,
			false,
			true,
			B_NO_BORDER);
	fDescription->MakeEditable(false);

	descriptionBox->AddChild(descriptionScroller);

	// separator line
	BBox *separator = new BBox("separator");
	separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));

	// buttons
	BButton* cancel = new BButton("cancel", "Cancel",
		new BMessage(kMsgCancel));
	BButton* ok = new BButton("ok", "OK", new BMessage(kMsgOK));
	ok->MakeDefault(true);

	SetLayout(new BGroupLayout(B_VERTICAL));
	AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
		.Add(protocolClassBox)
		.Add(descriptionBox)
		.AddGlue()
		.Add(separator)
		.AddGroup(B_HORIZONTAL, 10, 1.0f)
			.AddGlue()
			.Add(cancel)
			.Add(ok)
		.End()
		.SetInsets(0, 0, 0, 0)
	);


	// update description
	BMessage updateDescription(kMsgProtocolClassChanged);
	MessageReceived(&updateDescription);
}