Exemplo n.º 1
0
	KeyRequestView()
		:
		BView("KeyRequestView", B_WILL_DRAW),
		fPassword(NULL)
	{
		SetViewUIColor(B_PANEL_BACKGROUND_COLOR);

		BGroupLayout* rootLayout = new(std::nothrow) BGroupLayout(B_VERTICAL);
		if (rootLayout == NULL)
			return;

		SetLayout(rootLayout);

		BGridView* controls = new(std::nothrow) BGridView();
		if (controls == NULL)
			return;

		BGridLayout* layout = controls->GridLayout();

		float inset = ceilf(be_plain_font->Size() * 0.7);
		rootLayout->SetInsets(inset, inset, inset, inset);
		rootLayout->SetSpacing(inset);
		layout->SetSpacing(inset, inset);

		BStringView* label = new(std::nothrow) BStringView("keyringLabel",
			B_TRANSLATE("Keyring:"));
		if (label == NULL)
			return;

		int32 row = 0;
		layout->AddView(label, 0, row);

		fKeyringName = new(std::nothrow) BStringView("keyringName", "");
		if (fKeyringName == NULL)
			return;

		layout->AddView(fKeyringName, 1, row++);

		fPassword = new(std::nothrow) BTextControl(B_TRANSLATE("Password:"******"", NULL);
		if (fPassword == NULL)
			return;

		BLayoutItem* layoutItem = fPassword->CreateTextViewLayoutItem();
		layoutItem->SetExplicitMinSize(BSize(fPassword->StringWidth(
				"0123456789012345678901234567890123456789") + inset,
			B_SIZE_UNSET));

		layout->AddItem(fPassword->CreateLabelLayoutItem(), 0, row);
		layout->AddItem(layoutItem, 1, row++);

		BGroupView* buttons = new(std::nothrow) BGroupView(B_HORIZONTAL);
		if (buttons == NULL)
			return;

		fCancelButton = new(std::nothrow) BButton(B_TRANSLATE("Cancel"),
			new BMessage(kMessageCancel));
		buttons->GroupLayout()->AddView(fCancelButton);

		buttons->GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue());

		fUnlockButton = new(std::nothrow) BButton(B_TRANSLATE("Unlock"),
			new BMessage(kMessageUnlock));
		buttons->GroupLayout()->AddView(fUnlockButton);

		BTextView* message = new(std::nothrow) BTextView("message");
		message->SetText(B_TRANSLATE("An application wants to access the "
			"keyring below, but it is locked with a passphrase. Please enter "
			"the passphrase to unlock the keyring.\n"
			"If you unlock the keyring, it stays unlocked until the system is "
			"shut down or the keyring is manually locked again.\n"
			"If you cancel this dialog the keyring will remain locked."));
		message->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
		rgb_color textColor = ui_color(B_PANEL_TEXT_COLOR);
		message->SetFontAndColor(be_plain_font, B_FONT_ALL, &textColor);
		message->MakeEditable(false);
		message->MakeSelectable(false);
		message->SetWordWrap(true);

		rootLayout->AddView(message);
		rootLayout->AddView(controls);
		rootLayout->AddView(buttons);
	}
/*!	\brief		Init user interface regardless of the parameter of constructor.
 */
void		EventEditorMainWindow::InitUI() 
{
	ClearUI();
	
	MainView = new BView( BWindow::Bounds(),
								  "Event Editor Main View",
								  B_FOLLOW_ALL,
								  B_WILL_DRAW | B_FRAME_EVENTS );
	if ( MainView != NULL )
	{
		MainView->SetViewColor( ui_color(B_PANEL_BACKGROUND_COLOR ) );
		BWindow::AddChild( MainView );
	}
	else
	{
		global_toReturn = B_NO_MEMORY;
		be_app->PostMessage( B_QUIT_REQUESTED );
	}
	
	BGridLayout* layout = new BGridLayout( B_VERTICAL );
	if ( !layout ) {
		global_toReturn = B_NO_MEMORY;
		be_app->PostMessage( B_QUIT_REQUESTED );
	}
	MainView->SetLayout( layout );
	layout->SetInsets( 0, 0, 0, 5 );
	layout->SetSpacing( 0, 2 );
	
	menuBar = CreateMenuBar();
	layout->AddView( menuBar, 0, 0 );
	
	BTabView* tabView = new BTabView( Bounds().InsetBySelf( 5, 30 ),
												 "Tab view" );
	if ( !tabView ) {
		global_toReturn = B_NO_MEMORY;
		be_app->PostMessage( B_QUIT_REQUESTED );
	}
	BLayoutItem* layoutItem = layout->AddView( tabView, 0, 1 );
	if ( layoutItem ) {
		layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT ) );
	}
	
	BRect individualTab = tabView->Bounds();
	individualTab.bottom -= ( tabView->TabHeight() + 20 + menuBar->Bounds().Height() );
	
	// Enable firing the activity in any case
	fData.SetEventActivityFired( false );
	
	// General view
	genView = new EventEditor_GeneralView( individualTab, &fData );
	if ( !genView || genView->InitCheck() != B_OK ) {		
		global_toReturn = B_NO_MEMORY;
		be_app->PostMessage( B_QUIT_REQUESTED );
	}	
	BTab* tab = new BTab();	
	tabView->AddTab( genView, tab );
	tab->SetLabel( "General" );
	
	// Reminder view
	remView = new EventEditor_ReminderView( individualTab, &fData );
	if ( !remView || remView->InitCheck() != B_OK ) {
		global_toReturn = B_NO_MEMORY;
		be_app->PostMessage( B_QUIT_REQUESTED );
	}	
	tab = new BTab();	
	tabView->AddTab( remView, tab );
	tab->SetLabel( "Reminder" );
	
	// Event activity
	actView = new ActivityView( individualTab.InsetByCopy( 5, 5 ), "Event activity", fData.GetEventActivity() );
	if ( !actView || actView->InitCheck() != B_OK ) {
		global_toReturn = B_NO_MEMORY;
		be_app->PostMessage( B_QUIT_REQUESTED );
	}	
	tab = new BTab();	
	tabView->AddTab( actView, tab );
	tab->SetLabel( "Activity" );
	
	// Note view
	noteView = new EventEditor_NoteView( individualTab.InsetByCopy( 5, 5 ), &fData );
	if ( !noteView || noteView->InitCheck() != B_OK ) {
		global_toReturn = B_NO_MEMORY;
		be_app->PostMessage( B_QUIT_REQUESTED );
	}
	tab = new BTab();	
	tabView->AddTab( noteView, tab );
	tab->SetLabel( "Note" );
	
	menuBar->SetTargetForItems( this );
	
	// Save button
	saveAndClose = new BButton( BRect( 0, 0, 1, 1 ),
												  "Save",
												  "Save",
												  new BMessage( kFileSave ) );
	if ( !saveAndClose ) {
		global_toReturn = B_NO_MEMORY;
		be_app->PostMessage( B_QUIT_REQUESTED );
	}										  
	BLayoutItem* layoutItem2 = layout->AddView( saveAndClose, 0, 2 );
	if ( layoutItem ) {
		layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_RIGHT, B_ALIGN_BOTTOM ) );
	}
	saveAndClose->SetTarget( this );
	
	layout->SetMaxRowHeight( 1, 520 );
	layout->SetMinRowHeight( 2, 25 );
	
	// Refresh view
	InvalidateLayout();
	MainView->Invalidate();
}	// <-- end of UI initialization for MainWindow
Exemplo n.º 3
0
EthernetSettingsView::EthernetSettingsView()
    :
    BView("EthernetSettingsView", 0, NULL),
    fCurrentSettings(NULL)
{
    SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

    fSocket = socket(AF_INET, SOCK_DGRAM, 0);
    _GatherInterfaces();

    // build the GUI
    BGroupLayout* rootLayout = new BGroupLayout(B_VERTICAL);
    SetLayout(rootLayout);

    BGridView* controlsGroup = new BGridView();
    BGridLayout* layout = controlsGroup->GridLayout();

    // insets
    float inset = ceilf(be_plain_font->Size() * 0.7);
    rootLayout->SetInsets(inset, inset, inset, inset);
    rootLayout->SetSpacing(inset);
    layout->SetSpacing(inset, inset);

    BPopUpMenu* deviceMenu = new BPopUpMenu(B_TRANSLATE("<no adapter>"));
    for (int32 i = 0; i < fInterfaces.CountItems(); i++) {
        BString& name = *fInterfaces.ItemAt(i);
        BString label = name;
        BMessage* info = new BMessage(kMsgInfo);
        info->AddString("interface", name.String());
        BMenuItem* item = new BMenuItem(label.String(), info);
        deviceMenu->AddItem(item);
    }

    BPopUpMenu* modeMenu = new BPopUpMenu("modes");
    modeMenu->AddItem(new BMenuItem(B_TRANSLATE("Static"),
                                    new BMessage(kMsgStaticMode)));
    modeMenu->AddItem(new BMenuItem(B_TRANSLATE("DHCP"),
                                    new BMessage(kMsgDHCPMode)));
    modeMenu->AddSeparatorItem();
    modeMenu->AddItem(new BMenuItem(B_TRANSLATE("Disabled"),
                                    new BMessage(kMsgDisabledMode)));

    BPopUpMenu* networkMenu = new BPopUpMenu("networks");

    fDeviceMenuField = new BMenuField(B_TRANSLATE("Adapter:"), deviceMenu);
    layout->AddItem(fDeviceMenuField->CreateLabelLayoutItem(), 0, 0);
    layout->AddItem(fDeviceMenuField->CreateMenuBarLayoutItem(), 1, 0);

    fNetworkMenuField = new BMenuField(B_TRANSLATE("Network:"), networkMenu);
    layout->AddItem(fNetworkMenuField->CreateLabelLayoutItem(), 0, 1);
    layout->AddItem(fNetworkMenuField->CreateMenuBarLayoutItem(), 1, 1);

    fTypeMenuField = new BMenuField(B_TRANSLATE("Mode:"), modeMenu);
    layout->AddItem(fTypeMenuField->CreateLabelLayoutItem(), 0, 2);
    layout->AddItem(fTypeMenuField->CreateMenuBarLayoutItem(), 1, 2);

    fIPTextControl = new BTextControl(B_TRANSLATE("IP address:"), "", NULL);
    SetupTextControl(fIPTextControl);

    BLayoutItem* layoutItem = fIPTextControl->CreateTextViewLayoutItem();
    layoutItem->SetExplicitMinSize(BSize(
                                       fIPTextControl->StringWidth("XXX.XXX.XXX.XXX") + inset,
                                       B_SIZE_UNSET));

    layout->AddItem(fIPTextControl->CreateLabelLayoutItem(), 0, 3);
    layout->AddItem(layoutItem, 1, 3);

    fNetMaskTextControl = new BTextControl(B_TRANSLATE("Netmask:"), "", NULL);
    SetupTextControl(fNetMaskTextControl);
    layout->AddItem(fNetMaskTextControl->CreateLabelLayoutItem(), 0, 4);
    layout->AddItem(fNetMaskTextControl->CreateTextViewLayoutItem(), 1, 4);

    fGatewayTextControl = new BTextControl(B_TRANSLATE("Gateway:"), "", NULL);
    SetupTextControl(fGatewayTextControl);
    layout->AddItem(fGatewayTextControl->CreateLabelLayoutItem(), 0, 5);
    layout->AddItem(fGatewayTextControl->CreateTextViewLayoutItem(), 1, 5);

    // TODO: Replace the DNS text controls by a BListView with add/remove
    // functionality and so on...
    fPrimaryDNSTextControl = new BTextControl(B_TRANSLATE("DNS #1:"), "",
            NULL);
    SetupTextControl(fPrimaryDNSTextControl);
    layout->AddItem(fPrimaryDNSTextControl->CreateLabelLayoutItem(), 0, 6);
    layout->AddItem(fPrimaryDNSTextControl->CreateTextViewLayoutItem(), 1, 6);

    fSecondaryDNSTextControl = new BTextControl(B_TRANSLATE("DNS #2:"), "",
            NULL);
    SetupTextControl(fSecondaryDNSTextControl);
    layout->AddItem(fSecondaryDNSTextControl->CreateLabelLayoutItem(), 0, 7);
    layout->AddItem(fSecondaryDNSTextControl->CreateTextViewLayoutItem(), 1, 7);

    fDomainTextControl = new BTextControl(B_TRANSLATE("Domain:"), "", NULL);
    SetupTextControl(fDomainTextControl);
    layout->AddItem(fDomainTextControl->CreateLabelLayoutItem(), 0, 8);
    layout->AddItem(fDomainTextControl->CreateTextViewLayoutItem(), 1, 8);

    fErrorMessage = new BStringView("error", "");
    fErrorMessage->SetAlignment(B_ALIGN_LEFT);
    fErrorMessage->SetFont(be_bold_font);
    fErrorMessage->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));

    layout->AddView(fErrorMessage, 1, 9);

    // button group (TODO: move to window, but take care of
    // enabling/disabling)
    BGroupView* buttonGroup = new BGroupView(B_HORIZONTAL);

    fRevertButton = new BButton(B_TRANSLATE("Revert"),
                                new BMessage(kMsgRevert));
    fRevertButton->SetEnabled(false);
    buttonGroup->GroupLayout()->AddView(fRevertButton);

    buttonGroup->GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue());

    fApplyButton = new BButton(B_TRANSLATE("Apply"), new BMessage(kMsgApply));
    fApplyButton->SetEnabled(false);
    buttonGroup->GroupLayout()->AddView(fApplyButton);

    rootLayout->AddView(controlsGroup);
    rootLayout->AddView(buttonGroup);
}
Exemplo n.º 4
0
void
MainWindow::_CreateGUI()
{
    SetLayout(new BGroupLayout(B_HORIZONTAL));

    BGridLayout* layout = new BGridLayout();
    layout->SetSpacing(0, 0);
    BView* rootView = new BView("root view", 0, layout);
    AddChild(rootView);
    rootView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

    BGroupView* leftTopView = new BGroupView(B_VERTICAL, 0);
    layout->AddView(leftTopView, 0, 0);

    // views along the left side
    leftTopView->AddChild(_CreateMenuBar());

    float splitWidth = 13 * be_plain_font->Size();
    BSize minSize = leftTopView->MinSize();
    splitWidth = std::max(splitWidth, minSize.width);
    leftTopView->SetExplicitMaxSize(BSize(splitWidth, B_SIZE_UNSET));
    leftTopView->SetExplicitMinSize(BSize(splitWidth, B_SIZE_UNSET));

    BGroupView* iconPreviews = new BGroupView(B_HORIZONTAL);
    iconPreviews->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
    iconPreviews->GroupLayout()->SetSpacing(5);

    // icon previews
    fIconPreview16Folder = new IconView(BRect(0, 0, 15, 15),
                                        "icon preview 16 folder");
    fIconPreview16Menu = new IconView(BRect(0, 0, 15, 15),
                                      "icon preview 16 menu");
    fIconPreview16Menu->SetLowColor(ui_color(B_MENU_BACKGROUND_COLOR));

    fIconPreview32Folder = new IconView(BRect(0, 0, 31, 31),
                                        "icon preview 32 folder");
    fIconPreview32Desktop = new IconView(BRect(0, 0, 31, 31),
                                         "icon preview 32 desktop");
    fIconPreview32Desktop->SetLowColor(ui_color(B_DESKTOP_COLOR));

    fIconPreview64 = new IconView(BRect(0, 0, 63, 63), "icon preview 64");
    fIconPreview64->SetLowColor(ui_color(B_DESKTOP_COLOR));


    BGroupView* smallPreviews = new BGroupView(B_VERTICAL);
    smallPreviews->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
    smallPreviews->GroupLayout()->SetSpacing(5);

    smallPreviews->AddChild(fIconPreview16Folder);
    smallPreviews->AddChild(fIconPreview16Menu);

    BGroupView* mediumPreviews = new BGroupView(B_VERTICAL);
    mediumPreviews->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
    mediumPreviews->GroupLayout()->SetSpacing(5);

    mediumPreviews->AddChild(fIconPreview32Folder);
    mediumPreviews->AddChild(fIconPreview32Desktop);

//	iconPreviews->AddChild(fIconPreview48);

    iconPreviews->AddChild(smallPreviews);
    iconPreviews->AddChild(mediumPreviews);
    iconPreviews->AddChild(fIconPreview64);
    iconPreviews->SetExplicitMaxSize(BSize(B_SIZE_UNSET, B_SIZE_UNLIMITED));

    leftTopView->AddChild(iconPreviews);


    BGroupView* leftSideView = new BGroupView(B_VERTICAL, 0);
    layout->AddView(leftSideView, 0, 1);
    leftSideView->SetExplicitMaxSize(BSize(splitWidth, B_SIZE_UNSET));

    // path menu and list view
    BMenuBar* menuBar = new BMenuBar("path menu bar");
    menuBar->AddItem(fPathMenu);
    leftSideView->AddChild(menuBar);

    fPathListView = new PathListView(BRect(0, 0, splitWidth, 100),
                                     "path list view", new BMessage(MSG_PATH_SELECTED), this);

    BView* scrollView = new BScrollView("path list scroll view",
                                        fPathListView, B_FOLLOW_NONE, 0, false, true, B_NO_BORDER);
    leftSideView->AddChild(scrollView);

    // shape list view
    menuBar = new BMenuBar("shape menu bar");
    menuBar->AddItem(fShapeMenu);
    leftSideView->AddChild(menuBar);

    fShapeListView = new ShapeListView(BRect(0, 0, splitWidth, 100),
                                       "shape list view", new BMessage(MSG_SHAPE_SELECTED), this);
    scrollView = new BScrollView("shape list scroll view",
                                 fShapeListView, B_FOLLOW_NONE, 0, false, true, B_NO_BORDER);
    leftSideView->AddChild(scrollView);

    // transformer list view
    menuBar = new BMenuBar("transformer menu bar");
    menuBar->AddItem(fTransformerMenu);
    leftSideView->AddChild(menuBar);

    fTransformerListView = new TransformerListView(BRect(0, 0, splitWidth, 100),
            "transformer list view");
    scrollView = new BScrollView("transformer list scroll view",
                                 fTransformerListView, B_FOLLOW_NONE, 0, false, true, B_NO_BORDER);
    leftSideView->AddChild(scrollView);

    // property list view
    menuBar = new BMenuBar("property menu bar");
    menuBar->AddItem(fPropertyMenu);
    leftSideView->AddChild(menuBar);

    fPropertyListView = new IconObjectListView();

    // scroll view around property list view
    ScrollView* propScrollView = new ScrollView(fPropertyListView,
            SCROLL_VERTICAL, BRect(0, 0, splitWidth, 100), "property scroll view",
            B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS, B_PLAIN_BORDER,
            BORDER_RIGHT);
    leftSideView->AddChild(propScrollView);

    BGroupLayout* topSide = new BGroupLayout(B_HORIZONTAL);
    topSide->SetSpacing(0);
    BView* topSideView = new BView("top side view", 0, topSide);
    layout->AddView(topSideView, 1, 0);

    // canvas view
    BRect canvasBounds = BRect(0, 0, 200, 200);
    fCanvasView = new CanvasView(canvasBounds);

    // scroll view around canvas view
    canvasBounds.bottom += B_H_SCROLL_BAR_HEIGHT;
    canvasBounds.right += B_V_SCROLL_BAR_WIDTH;
    ScrollView* canvasScrollView = new ScrollView(fCanvasView, SCROLL_VERTICAL
            | SCROLL_HORIZONTAL | SCROLL_VISIBLE_RECT_IS_CHILD_BOUNDS,
            canvasBounds, "canvas scroll view", B_FOLLOW_NONE,
            B_WILL_DRAW | B_FRAME_EVENTS, B_NO_BORDER);
    layout->AddView(canvasScrollView, 1, 1);

    // views along the top

    BGroupLayout* styleGroup = new BGroupLayout(B_VERTICAL, 0);
    BView* styleGroupView = new BView("style group", 0, styleGroup);
    topSide->AddView(styleGroupView);

    // style list view
    menuBar = new BMenuBar("style menu bar");
    menuBar->AddItem(fStyleMenu);
    styleGroup->AddView(menuBar);

    fStyleListView = new StyleListView(BRect(0, 0, splitWidth, 100),
                                       "style list view", new BMessage(MSG_STYLE_SELECTED), this);
    scrollView = new BScrollView("style list scroll view", fStyleListView,
                                 B_FOLLOW_NONE, 0, false, true, B_NO_BORDER);
    scrollView->SetExplicitMaxSize(BSize(splitWidth, B_SIZE_UNLIMITED));
    styleGroup->AddView(scrollView);

    // style view
    fStyleView = new StyleView(BRect(0, 0, 200, 100));
    topSide->AddView(fStyleView);

    // swatch group
    BGroupLayout* swatchGroup = new BGroupLayout(B_VERTICAL);
    swatchGroup->SetSpacing(0);
    BView* swatchGroupView = new BView("swatch group", 0, swatchGroup);
    topSide->AddView(swatchGroupView);

    menuBar = new BMenuBar("swatches menu bar");
    menuBar->AddItem(fSwatchMenu);
    swatchGroup->AddView(menuBar);

    fSwatchGroup = new SwatchGroup(BRect(0, 0, 100, 100));
    swatchGroup->AddView(fSwatchGroup);

    swatchGroupView->SetExplicitMaxSize(swatchGroupView->MinSize());

    // make sure the top side has fixed height
    topSideView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED,
                                          swatchGroupView->MinSize().height));
}
Exemplo n.º 5
0
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);
}
Exemplo n.º 6
0
void
PageSetupView::AttachedToWindow()
{
	BMenuItem  *item = NULL;
	bool       marked;
	int        count;

	// margin
	MarginUnit units = fJobData->GetMarginUnit();
	BRect paper = fJobData->GetPaperRect();
	BRect margin = fJobData->GetPrintableRect();

	// re-calculate the margin from the printable rect in points
	margin.top -= paper.top;
	margin.left -= paper.left;
	margin.right = paper.right - margin.right;
	margin.bottom = paper.bottom - margin.bottom;

	fMarginView = new MarginView(
		paper.IntegerWidth(),
		paper.IntegerHeight(),
			margin, units);

	// paper selection
	marked = false;
	fPaper = new BPopUpMenu("paperSize");
	fPaper->SetRadioMode(true);
	count = fPrinterCap->CountCap(PrinterCap::kPaper);
	PaperCap **paper_cap = (PaperCap **)fPrinterCap->GetCaps(PrinterCap::kPaper);
	while (count--) {
		BMessage *msg = new BMessage(kMsgPaperChanged);
		msg->AddPointer("paperCap", *paper_cap);
		item = new BMenuItem((*paper_cap)->fLabel.c_str(), msg);
		fPaper->AddItem(item);
		item->SetTarget(this);
		if ((*paper_cap)->fPaper == fJobData->GetPaper()) {
			item->SetMarked(true);
			marked = true;
		}
		paper_cap++;
	}
	if (!marked)
		item->SetMarked(true);
	BMenuField* paperSize = new BMenuField("paperSize", "Paper size:", fPaper);

	// orientation
	fOrientation = new BPopUpMenu("orientation");
	fOrientation->SetRadioMode(true);

	BMenuField* orientation = new BMenuField("orientation", "Orientation:", fOrientation);

	count = fPrinterCap->CountCap(PrinterCap::kOrientation);
	if (count == 0) {
		AddOrientationItem("Portrait", JobData::kPortrait);
		AddOrientationItem("Landscape", JobData::kLandscape);
	} else {
		OrientationCap **orientation_cap = (OrientationCap **)fPrinterCap->GetCaps(PrinterCap::kOrientation);
		while (count--) {
			AddOrientationItem((*orientation_cap)->fLabel.c_str(),
				(*orientation_cap)->fOrientation);
			orientation_cap++;
		}
	}

	// resolution
	marked = false;
	fResolution = new BPopUpMenu("resolution");
	fResolution->SetRadioMode(true);
	count = fPrinterCap->CountCap(PrinterCap::kResolution);
	ResolutionCap **resolution_cap = (ResolutionCap **)fPrinterCap->GetCaps(PrinterCap::kResolution);
	while (count--) {
		item = new BMenuItem((*resolution_cap)->fLabel.c_str(), NULL);
		fResolution->AddItem(item);
		item->SetTarget(this);
		if (((*resolution_cap)->fXResolution == fJobData->GetXres()) &&
			((*resolution_cap)->fYResolution == fJobData->GetYres())) {
			item->SetMarked(true);
			marked = true;
		}
		resolution_cap++;
	}
	if (!marked)
		item->SetMarked(true);
	BMenuField* resolution = new BMenuField("resolution", "Resolution:", fResolution);

	// scale
	BString scale;
	scale << (int)fJobData->GetScaling();
	fScaling = new BTextControl("scale", "Scale [%]:",
									scale.String(),
	                                NULL);
	int num;
	for (num = 0; num <= 255; num++) {
		fScaling->TextView()->DisallowChar(num);
	}
	for (num = 0; num <= 9; num++) {
		fScaling->TextView()->AllowChar('0' + num);
	}
	fScaling->TextView()->SetMaxBytes(3);

	// cancel and ok
	BButton* cancel = new BButton("cancel", "Cancel", new BMessage(kMsgCancel));
	BButton* ok = new BButton("ok", "OK", new BMessage(kMsgOK));

	ok->MakeDefault(true);

	BGridView* settings = new BGridView();
	BGridLayout* settingsLayout = settings->GridLayout();
	settingsLayout->AddItem(paperSize->CreateLabelLayoutItem(), 0, 0);
	settingsLayout->AddItem(paperSize->CreateMenuBarLayoutItem(), 1, 0);
	settingsLayout->AddItem(orientation->CreateLabelLayoutItem(), 0, 1);
	settingsLayout->AddItem(orientation->CreateMenuBarLayoutItem(), 1, 1);
	settingsLayout->AddItem(resolution->CreateLabelLayoutItem(), 0, 2);
	settingsLayout->AddItem(resolution->CreateMenuBarLayoutItem(), 1, 2);
	settingsLayout->AddItem(fScaling->CreateLabelLayoutItem(), 0, 3);
	settingsLayout->AddItem(fScaling->CreateTextViewLayoutItem(), 1, 3);
	settingsLayout->SetSpacing(0, 0);

	SetLayout(new BGroupLayout(B_VERTICAL));
	AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
		.AddGroup(B_HORIZONTAL, 5, 1.0f)
			.AddGroup(B_VERTICAL, 0, 1.0f)
				.Add(fMarginView)
				.AddGlue()
			.End()
			.AddGroup(B_VERTICAL, 0, 1.0f)
				.Add(settings)
				.AddGlue()
			.End()
		.End()
		.AddGroup(B_HORIZONTAL, 10, 1.0f)
			.AddGlue()
			.Add(cancel)
			.Add(ok)
		.End()
		.SetInsets(10, 10, 10, 10)
	);
}
Exemplo n.º 7
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();
}
Exemplo n.º 8
0
/**
 * _ConstructGUI()
 *
 * Creates the GUI for the View. MUST be called AFTER the View is attached to
 *	the Window, or will crash and/or create strange behaviour
 *
 * @param none
 * @return void
 */
void
MarginView::_ConstructGUI()
{
	fPage = new PageView();
	fPage->SetViewColor(ViewColor());

	fPageSize = new BStringView("pageSize", "?x?");

	BString str;
	// Create text fields

	// top
	str << fMargins.top/fUnitValue;
	fTop = new BTextControl("top", "Top:", str.String(), NULL);

	fTop->SetModificationMessage(new BMessage(TOP_MARGIN_CHANGED));
	fTop->SetTarget(this);
	_AllowOnlyNumbers(fTop, kNumCount);

	//left
    str = "";
	str << fMargins.left/fUnitValue;
	fLeft = new BTextControl("left", "Left:", str.String(), NULL);

	fLeft->SetModificationMessage(new BMessage(LEFT_MARGIN_CHANGED));
	fLeft->SetTarget(this);
	_AllowOnlyNumbers(fLeft, kNumCount);

	//bottom
    str = "";
	str << fMargins.bottom/fUnitValue;
	fBottom = new BTextControl("bottom", "Bottom:", str.String(), NULL);

	fBottom->SetModificationMessage(new BMessage(BOTTOM_MARGIN_CHANGED));
	fBottom->SetTarget(this);
	_AllowOnlyNumbers(fBottom, kNumCount);

	//right
    str = "";
	str << fMargins.right/fUnitValue;
	fRight = new BTextControl("right", "Right:", str.String(), NULL);

	fRight->SetModificationMessage(new BMessage(RIGHT_MARGIN_CHANGED));
	fRight->SetTarget(this);
	_AllowOnlyNumbers(fRight, kNumCount);

	// Create Units popup

	BPopUpMenu *menu = new BPopUpMenu("units");
	BMenuField *units = new BMenuField("units", "Units:", menu);

	BMenuItem *item;
	// Construct menu items
	for (int32 i = 0; kUnitNames[i] != NULL; i++) {
		BMessage *msg = new BMessage(MARGIN_UNIT_CHANGED);
		msg->AddInt32("marginUnit", kUnitMsg[i]);
		menu->AddItem(item = new BMenuItem(kUnitNames[i], msg));
		item->SetTarget(this);
		if (fMarginUnit == kUnitMsg[i])
			item->SetMarked(true);
	}

	BGridView* settings = new BGridView();
	BGridLayout* settingsLayout = settings->GridLayout();
	settingsLayout->AddItem(fTop->CreateLabelLayoutItem(), 0, 0);
	settingsLayout->AddItem(fTop->CreateTextViewLayoutItem(), 1, 0);
	settingsLayout->AddItem(fLeft->CreateLabelLayoutItem(), 0, 1);
	settingsLayout->AddItem(fLeft->CreateTextViewLayoutItem(), 1, 1);
	settingsLayout->AddItem(fBottom->CreateLabelLayoutItem(), 0, 2);
	settingsLayout->AddItem(fBottom->CreateTextViewLayoutItem(), 1, 2);
	settingsLayout->AddItem(fRight->CreateLabelLayoutItem(), 0, 3);
	settingsLayout->AddItem(fRight->CreateTextViewLayoutItem(), 1, 3);
	settingsLayout->AddItem(units->CreateLabelLayoutItem(), 0, 4);
	settingsLayout->AddItem(units->CreateMenuBarLayoutItem(), 1, 4);
	settingsLayout->SetSpacing(0, 0);

	BGroupView* groupView = new BGroupView(B_HORIZONTAL, 10);
	BGroupLayout* groupLayout = groupView->GroupLayout();
	groupLayout->AddView(BGroupLayoutBuilder(B_VERTICAL, 0)
		.Add(fPage)
		.Add(fPageSize)
		.SetInsets(0, 0, 0, 0)
		.TopView()
	);
	groupLayout->AddView(settings);
	groupLayout->SetInsets(5, 5, 5, 5);

	AddChild(groupView);

	UpdateView(MARGIN_CHANGED);
}
/*!	
 *	\brief			The constructor of CalendarControl.
 *	\param[in]	frame			The outer bounds of the control.
 *	\param[in]	name			Name of the control.
 *	\param[in]	labelInForCalendar		The label of the calendar part of control.
 *	\param[in]	calModuleName				ID of the calendar module used.
 *	\param[in]	initialTime					The initial time to be set, passed in seconds.
 *													If 0, current time is set.
 *	\param[in]	toSend						Message sent when the control's value is changed.
 *	\attention		It's assumed that calendar modules were already initialized prior
 *						to calling this function.
 */
CalendarControl::CalendarControl(BRect frame,
								 const char* name,
								 const BString& labelInForCalendar,
								 const BString& calModuleName,
								 time_t	initialTime,
								 BMessage* toSend )
	:
	BControl( frame, name, labelInForCalendar.String(), toSend,
			 B_FOLLOW_ALL_SIDES,
			 B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS ),
	fLabel(NULL),
	fDateLabel(NULL),
	fDateSelector( NULL ),
	fLastError( B_OK )
{
	// Firstly, set the calendar module
	this->fCalModule = utl_FindCalendarModule( calModuleName );
	if ( this->fCalModule == NULL ) {
		fLastError = B_BAD_VALUE;
		return;
	}
	
	// Load the preferences of this calendar module
	ParsePreferences();
	
	// Init the internal data to submitted time representation
	InitTimeRepresentation( initialTime );
	
	// Create the UI elements
	fLabel = new BStringView( BRect( 0, 0, 1, 1 ), 
									  "label", 
									  labelInForCalendar.String() );
	if ( !fLabel) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fLabel->ResizeToPreferred();
	
	fDateLabel = new BStringView( BRect( 0, 0, 1, 1 ), 
											"dateLabel", 
											NULL );
	if ( !fDateLabel ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	
	
	fCalendarModuleLabel = new BStringView( BRect( 0, 0, 1, 1 ),
														 "label for the calendar module selector",
														 "Calendar:" );
	if ( !fCalendarModuleLabel ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fCalendarModuleLabel->ResizeToPreferred();
	
	fCalendarsMenu = CreateMenuOfCalendarModules();
	if ( !fCalendarsMenu ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	
	fCalendarModuleSelector = new BMenuField( BRect( 0, 0, 1, 1 ),
															"calendar module selector",
															NULL,		// Label is created separately
															fCalendarsMenu );
	if ( !fCalendarModuleSelector ) {
		/* Panic! */
		fLastError = B_NO_MEMORY;
		return;
	}
	fCalendarModuleSelector->ResizeToPreferred();
	
	// Create the menu
	CreateMenu();
	
	BRect stringViewFrame = fLabel->Frame();
	
	BPoint topLeftCorner = stringViewFrame.RightTop();
	BSize size( BUTTON_WIDTH, stringViewFrame.Height() + SPACING );
	
	
	fMenuBar = new BMenuBar( BRect(topLeftCorner, size),
								"menuBar",
								B_FOLLOW_RIGHT | B_FOLLOW_TOP,
								B_ITEMS_IN_ROW,
								false);
	if (! fMenuBar) {
		// Panic!
		fLastError = B_NO_MEMORY;
		return;
	}
	fMenuBar->SetBorder( B_BORDER_EACH_ITEM );
	fMenuBar->AddItem( fDateSelector );

	// Update the selected date label to currently selected moment of time
	UpdateText();
	
	// Initializing the layout
	BGridLayout* lay = new BGridLayout( );
	
	if (!lay) { 
		// Panic! 
		fLastError = B_NO_MEMORY;
		return; 
	}
	lay->SetInsets(0, 5, 0, 0);
	lay->SetSpacing( 10, 5 );
	lay->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_MIDDLE ) );
	this->SetLayout(lay);
	
	BLayoutItem* layoutItem;
	
	layoutItem = lay->AddView( fLabel, 0, 0 );
	layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_LEFT, B_ALIGN_TOP ) );
	layoutItem = lay->AddView( fDateLabel, 1, 0 );
	layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_TOP ) );
	layoutItem = lay->AddView( fMenuBar, 2, 0 );	
	layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_RIGHT, B_ALIGN_TOP ) );
	layoutItem->SetExplicitMaxSize( size );
	
	layoutItem = lay->AddView( fCalendarModuleLabel, 0, 1 );
	layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_LEFT, B_ALIGN_MIDDLE ) );
	
	layoutItem = lay->AddView( fCalendarModuleSelector, 1, 1 );
	layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_USE_FULL_WIDTH, B_ALIGN_TOP ) );

	lay->SetColumnWeight( 0, 0 );
	lay->SetColumnWeight( 1, 1000 );
	lay->SetColumnWeight( 2, 0 );
	
	lay->SetMaxColumnWidth( 2, BUTTON_WIDTH );
	
	this->InvalidateLayout();
	this->Relayout();
	this->Invalidate();
	
	fLastError = B_OK;
}
Exemplo n.º 10
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);
}
Exemplo n.º 11
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)
	);
}