コード例 #1
0
ファイル: MarginView.cpp プロジェクト: mariuz/haiku
/**
 * _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()
{
	BString str;
	// Create text fields
	BRect r(Frame().Width() - be_plain_font->StringWidth("Top#") - kWidth,
			kOffsetY, Frame().Width() - kOffsetX, kWidth);

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

	fTop->SetModificationMessage(new BMessage(TOP_MARGIN_CHANGED));
	fTop->SetDivider(be_plain_font->StringWidth("Top#"));
	fTop->SetTarget(this);
	_AllowOnlyNumbers(fTop, kNumCount);
	AddChild(fTop);




	//left
	r.OffsetBy(0, kOffsetY);
	r.left = Frame().Width() - be_plain_font->StringWidth("Left#") - kWidth;
    str = "";
	str << fMargins.left/fUnitValue;
	fLeft = new BTextControl( r, "left", "Left:", str.String(), NULL,
				B_FOLLOW_RIGHT);

	fLeft->SetModificationMessage(new BMessage(LEFT_MARGIN_CHANGED));
	fLeft->SetDivider(be_plain_font->StringWidth("Left#"));
	fLeft->SetTarget(this);
	_AllowOnlyNumbers(fLeft, kNumCount);
	AddChild(fLeft);




	//bottom
	r.OffsetBy(0, kOffsetY);
	r.left = Frame().Width() - be_plain_font->StringWidth("Bottom#") - kWidth;
    str = "";
	str << fMargins.bottom/fUnitValue;
	fBottom = new BTextControl( r, "bottom", "Bottom:", str.String(), NULL,
				B_FOLLOW_RIGHT);

	fBottom->SetModificationMessage(new BMessage(BOTTOM_MARGIN_CHANGED));
	fBottom->SetDivider(be_plain_font->StringWidth("Bottom#"));
	fBottom->SetTarget(this);

	_AllowOnlyNumbers(fBottom, kNumCount);
	AddChild(fBottom);




	//right
	r.OffsetBy(0, kOffsetY);
	r.left = Frame().Width() - be_plain_font->StringWidth("Right#") - kWidth;
    str = "";
	str << fMargins.right/fUnitValue;
	fRight = new BTextControl( r, "right", "Right:", str.String(), NULL,
				B_FOLLOW_RIGHT);

	fRight->SetModificationMessage(new BMessage(RIGHT_MARGIN_CHANGED));
	fRight->SetDivider(be_plain_font->StringWidth("Right#"));
	fRight->SetTarget(this);
	_AllowOnlyNumbers(fRight, kNumCount);
	AddChild(fRight);



// Create Units popup
	r.OffsetBy(-kOffsetX, kOffsetY);
	r.right += kOffsetY;

	BPopUpMenu *menu = new BPopUpMenu("units");
	BMenuField *mf = new BMenuField(r, "units", "Units", menu,
			B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT);
	mf->ResizeToPreferred();
	mf->SetDivider(be_plain_font->StringWidth("Units#"));

	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);
	}
	AddChild(mf);

	// calculate the sizes for drawing page view
	_CalculateViewSize(MARGIN_CHANGED);
}
コード例 #2
0
ファイル: MarginView.cpp プロジェクト: looncraz/haiku
/**
 * _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);
}