Modal empty dialog is no fun!
Here come a template Add Printer dialog. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1066 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -26,6 +26,10 @@
|
|||||||
// BeOS API
|
// BeOS API
|
||||||
#include <Box.h>
|
#include <Box.h>
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
|
#include <TextControl.h>
|
||||||
|
#include <MenuField.h>
|
||||||
|
#include <PopUpMenu.h>
|
||||||
|
#include <StringView.h>
|
||||||
#include <ListView.h>
|
#include <ListView.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
@@ -36,7 +40,8 @@ status_t AddPrinterDialog::Start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AddPrinterDialog::AddPrinterDialog()
|
AddPrinterDialog::AddPrinterDialog()
|
||||||
: Inherited(BRect(78.0, 71.0, 561.0, 409.0), "Add Printer", B_MODAL_WINDOW, B_NOT_H_RESIZABLE)
|
: Inherited(BRect(78.0, 71.0, 400, 300), "Add Printer",
|
||||||
|
B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
|
||||||
{
|
{
|
||||||
BuildGUI(0);
|
BuildGUI(0);
|
||||||
|
|
||||||
@@ -48,6 +53,13 @@ void AddPrinterDialog::MessageReceived(BMessage* msg)
|
|||||||
{
|
{
|
||||||
switch(msg->what)
|
switch(msg->what)
|
||||||
{
|
{
|
||||||
|
case B_OK:
|
||||||
|
// TODO: create the new spooler!
|
||||||
|
// fallback not to dialog cancelling case...
|
||||||
|
case B_CANCEL:
|
||||||
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Inherited::MessageReceived(msg);
|
Inherited::MessageReceived(msg);
|
||||||
}
|
}
|
||||||
@@ -55,14 +67,126 @@ void AddPrinterDialog::MessageReceived(BMessage* msg)
|
|||||||
|
|
||||||
void AddPrinterDialog::BuildGUI(int stage)
|
void AddPrinterDialog::BuildGUI(int stage)
|
||||||
{
|
{
|
||||||
const float boxInset = 10.0;
|
BRect r, tr;
|
||||||
BRect r(Bounds());
|
float x, y, w, h;
|
||||||
|
BButton * ok;
|
||||||
|
BButton * cancel;
|
||||||
|
BTextControl * tc;
|
||||||
|
BPopUpMenu * pum;
|
||||||
|
BMenuField * mf;
|
||||||
|
BStringView * sv;
|
||||||
|
BBox * bb;
|
||||||
|
|
||||||
|
#define H_MARGIN 8
|
||||||
|
#define V_MARGIN 8
|
||||||
|
#define LINE_MARGIN 3
|
||||||
|
|
||||||
|
#define NAME_LABEL "Printer Name:"
|
||||||
|
#define KIND_LABEL "Printer Type:"
|
||||||
|
#define PORT_LABEL "Connected to:"
|
||||||
|
#define DRIVER_SETTINGS_AREA_TEXT "Driver settings area, if any."
|
||||||
|
#define TRANSPORT_SETTINGS_AREA_TEXT "Transport settings area, if any."
|
||||||
|
|
||||||
// ------------------------ First of all, create a nice grey backdrop
|
// ------------------------ First of all, create a nice grey backdrop
|
||||||
BBox * backdrop = new BBox(Bounds(), "backdrop", B_FOLLOW_ALL_SIDES,
|
BBox * panel = new BBox(Bounds(), "backdrop", B_FOLLOW_ALL,
|
||||||
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
|
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
|
||||||
B_PLAIN_BORDER);
|
B_PLAIN_BORDER);
|
||||||
AddChild(backdrop);
|
AddChild(panel);
|
||||||
|
|
||||||
|
r = panel->Bounds();
|
||||||
|
|
||||||
|
r.InsetBy(H_MARGIN, V_MARGIN);
|
||||||
|
|
||||||
|
// add a "printer name" input field
|
||||||
|
tc = new BTextControl(r, "printer_name",
|
||||||
|
NAME_LABEL, B_EMPTY_STRING, NULL);
|
||||||
|
tc->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT);
|
||||||
|
panel->AddChild(tc);
|
||||||
|
tc->SetFont(be_bold_font);
|
||||||
|
tc->GetPreferredSize(&w, &h);
|
||||||
|
tc->SetDivider(be_bold_font->StringWidth(NAME_LABEL "#"));
|
||||||
|
tc->ResizeTo(tc->Bounds().Width(), h);
|
||||||
|
|
||||||
|
r.OffsetBy(0, h + 2*V_MARGIN);
|
||||||
|
|
||||||
|
// add a "driver" settings box
|
||||||
|
bb = new BBox(r, "driver_box", B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT,
|
||||||
|
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
|
||||||
|
B_FANCY_BORDER);
|
||||||
|
panel->AddChild(bb);
|
||||||
|
|
||||||
|
pum = new BPopUpMenu("<pick one>");
|
||||||
|
mf = new BMenuField(r, "drivers_list", KIND_LABEL, pum,
|
||||||
|
B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT,
|
||||||
|
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE);
|
||||||
|
mf->SetFont(be_plain_font);
|
||||||
|
mf->SetDivider(be_plain_font->StringWidth(NAME_LABEL "#"));
|
||||||
|
bb->SetLabel(mf);
|
||||||
|
mf->ResizeToPreferred();
|
||||||
|
mf->GetPreferredSize(&w, &h);
|
||||||
|
|
||||||
|
tr = bb->Bounds();
|
||||||
|
tr.top += h;
|
||||||
|
tr.InsetBy(H_MARGIN, V_MARGIN);
|
||||||
|
|
||||||
|
sv = new BStringView(tr, NULL, DRIVER_SETTINGS_AREA_TEXT);
|
||||||
|
bb->AddChild(sv);
|
||||||
|
sv->ResizeToPreferred();
|
||||||
|
|
||||||
|
bb->ResizeTo(bb->Bounds().Width(), 200);
|
||||||
|
|
||||||
|
r.OffsetBy(0, bb->Frame().Height() + V_MARGIN);
|
||||||
|
|
||||||
|
// add a "transport" settings box
|
||||||
|
bb = new BBox(r, "driver_box", B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT,
|
||||||
|
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
|
||||||
|
B_FANCY_BORDER);
|
||||||
|
panel->AddChild(bb);
|
||||||
|
|
||||||
|
// add a "connected to" (aka transports list) menu field
|
||||||
|
pum = new BPopUpMenu("<pick one>");
|
||||||
|
mf = new BMenuField(r, "transports_list", PORT_LABEL, pum,
|
||||||
|
B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT,
|
||||||
|
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE);
|
||||||
|
mf->SetFont(be_plain_font);
|
||||||
|
mf->SetDivider(be_plain_font->StringWidth(PORT_LABEL "#"));
|
||||||
|
bb->SetLabel(mf);
|
||||||
|
mf->ResizeToPreferred();
|
||||||
|
mf->GetPreferredSize(&w, &h);
|
||||||
|
|
||||||
|
tr = bb->Bounds();
|
||||||
|
tr.top += h;
|
||||||
|
tr.InsetBy(H_MARGIN, V_MARGIN);
|
||||||
|
|
||||||
|
sv = new BStringView(tr, NULL, TRANSPORT_SETTINGS_AREA_TEXT);
|
||||||
|
bb->AddChild(sv);
|
||||||
|
sv->ResizeToPreferred();
|
||||||
|
|
||||||
|
bb->ResizeTo(bb->Bounds().Width(), 100);
|
||||||
|
|
||||||
|
r.OffsetBy(0, bb->Frame().Height() + V_MARGIN);
|
||||||
|
|
||||||
|
// make some space before the buttons row
|
||||||
|
r.OffsetBy(0, V_MARGIN);
|
||||||
|
|
||||||
|
// add a "OK" button, and make it default
|
||||||
|
ok = new BButton(r, NULL, "Add", new BMessage(B_OK), B_FOLLOW_RIGHT | B_FOLLOW_TOP);
|
||||||
|
ok->MakeDefault(true);
|
||||||
|
ok->ResizeToPreferred();
|
||||||
|
ok->GetPreferredSize(&w, &h);
|
||||||
|
x = r.right - w;
|
||||||
|
ok->MoveTo(x, ok->Frame().top); // put the ok bottom at bottom right corner
|
||||||
|
panel->AddChild(ok);
|
||||||
|
|
||||||
|
// add a "Cancel button
|
||||||
|
cancel = new BButton(r, NULL, "Cancel", new BMessage(B_CANCEL), B_FOLLOW_RIGHT | B_FOLLOW_TOP);
|
||||||
|
cancel->ResizeToPreferred();
|
||||||
|
cancel->GetPreferredSize(&w, &h);
|
||||||
|
cancel->MoveTo(x - w - H_MARGIN, r.top); // put cancel button left next the ok button
|
||||||
|
panel->AddChild(cancel);
|
||||||
|
|
||||||
|
// Auto resize window
|
||||||
|
ResizeTo(ok->Frame().right + H_MARGIN, ok->Frame().bottom + V_MARGIN);
|
||||||
|
|
||||||
// Stage == 0
|
// Stage == 0
|
||||||
// init_icon 64x114 Add a Local or Network Printer
|
// init_icon 64x114 Add a Local or Network Printer
|
||||||
|
|||||||
Reference in New Issue
Block a user