1 #include "AddPrinterDlg.h"
3 #include <GroupLayoutBuilder.h>
5 #include "PrinterCap.h"
6 #include "PrinterData.h"
12 kMsgProtocolClassChanged
,
16 ProtocolClassItem::ProtocolClassItem(const ProtocolClassCap
* cap
)
17 : BStringItem(cap
->fLabel
.c_str())
18 , fProtocolClassCap(cap
)
24 ProtocolClassItem::GetProtocolClass() const
26 return fProtocolClassCap
->fProtocolClass
;
30 ProtocolClassItem::GetDescription() const
32 return fProtocolClassCap
->fDescription
.c_str();
36 AddPrinterView::AddPrinterView(PrinterData
* printerData
,
37 const PrinterCap
* printerCap
)
39 BView("addPrinter", B_WILL_DRAW
),
40 fPrinterData(printerData
),
41 fPrinterCap(printerCap
)
46 AddPrinterView::~AddPrinterView()
52 AddPrinterView::AttachedToWindow()
55 BBox
* protocolClassBox
= new BBox("protocolClass");
56 protocolClassBox
->SetLabel("Protocol classes:");
59 fProtocolClassList
= new BListView("protocolClassList");
60 fProtocolClassList
->SetExplicitMinSize(BSize(500, 200));
61 BScrollView
* protocolClassScroller
= new BScrollView(
62 "protocolClassListScroller",
68 fProtocolClassList
->SetSelectionMessage(
69 new BMessage(kMsgProtocolClassChanged
));
70 fProtocolClassList
->SetTarget(this);
72 protocolClassBox
->AddChild(protocolClassScroller
);
74 int count
= fPrinterCap
->CountCap(PrinterCap::kProtocolClass
);
75 ProtocolClassCap
**protocolClasses
=
76 (ProtocolClassCap
**)fPrinterCap
->GetCaps(PrinterCap::kProtocolClass
);
78 const ProtocolClassCap
*protocolClass
= *protocolClasses
;
80 BStringItem
* item
= new ProtocolClassItem(protocolClass
);
81 fProtocolClassList
->AddItem(item
);
82 if (protocolClass
->fIsDefault
) {
83 int index
= fProtocolClassList
->IndexOf(item
);
84 fProtocolClassList
->Select(index
);
89 // description of protocol class box
90 BBox
* descriptionBox
= new BBox("descriptionBox");
91 descriptionBox
->SetLabel("Description:");
93 // description of protocol class
94 fDescription
= new BTextView("description");
95 fDescription
->SetExplicitMinSize(BSize(200, 200));
96 fDescription
->SetViewColor(descriptionBox
->ViewColor());
97 BScrollView
* descriptionScroller
= new BScrollView("descriptionScroller",
103 fDescription
->MakeEditable(false);
105 descriptionBox
->AddChild(descriptionScroller
);
108 BBox
*separator
= new BBox("separator");
109 separator
->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED
, 1));
112 BButton
* cancel
= new BButton("cancel", "Cancel",
113 new BMessage(kMsgCancel
));
114 BButton
* ok
= new BButton("ok", "OK", new BMessage(kMsgOK
));
115 ok
->MakeDefault(true);
117 SetLayout(new BGroupLayout(B_VERTICAL
));
118 AddChild(BGroupLayoutBuilder(B_VERTICAL
, 0)
119 .Add(protocolClassBox
)
123 .AddGroup(B_HORIZONTAL
, 10, 1.0f
)
128 .SetInsets(0, 0, 0, 0)
132 // update description
133 BMessage
updateDescription(kMsgProtocolClassChanged
);
134 MessageReceived(&updateDescription
);
139 AddPrinterView::CurrentSelection()
141 int selected
= fProtocolClassList
->CurrentSelection();
143 return (ProtocolClassItem
*)fProtocolClassList
->ItemAt(selected
);
150 AddPrinterView::MessageReceived(BMessage
* msg
)
152 if (msg
->what
== kMsgProtocolClassChanged
) {
153 ProtocolClassItem
*item
= CurrentSelection();
155 fDescription
->SetText(item
->GetDescription());
158 BView::MessageReceived(msg
);
164 AddPrinterView::Save()
166 ProtocolClassItem
* item
= CurrentSelection();
168 fPrinterData
->SetProtocolClass(item
->GetProtocolClass());
169 fPrinterData
->Save();
174 AddPrinterDlg::AddPrinterDlg(PrinterData
* printerData
,
175 const PrinterCap
*printerCap
)
177 DialogWindow(BRect(100, 100, 120, 120),
178 "Add printer", B_TITLED_WINDOW_LOOK
, B_MODAL_APP_WINDOW_FEEL
,
179 B_NOT_MINIMIZABLE
| B_NOT_ZOOMABLE
| B_ASYNCHRONOUS_CONTROLS
180 | B_AUTO_UPDATE_SIZE_LIMITS
)
184 fAddPrinterView
= new AddPrinterView(printerData
, printerCap
);
185 SetLayout(new BGroupLayout(B_VERTICAL
));
186 AddChild(BGroupLayoutBuilder(B_VERTICAL
, 0)
187 .Add(fAddPrinterView
)
188 .SetInsets(10, 10, 10, 10)
194 AddPrinterDlg::MessageReceived(BMessage
* msg
)
198 fAddPrinterView
->Save();
199 SetResult(B_NO_ERROR
);
200 PostMessage(B_QUIT_REQUESTED
);
204 PostMessage(B_QUIT_REQUESTED
);
208 DialogWindow::MessageReceived(msg
);