2 * Copyright 2008-2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Julun, <host.haiku@gmx.de>
9 #include <JobSetupPanel.h>
14 #include <GridLayoutBuilder.h>
15 #include <GroupLayoutBuilder.h>
16 #include <GroupView.h>
17 #include <MenuField.h>
19 #include <PopUpMenu.h>
21 #include <PrinterRoster.h>
22 #include <RadioButton.h>
23 #include <StringView.h>
24 #include <TextControl.h>
34 BJobSetupPanel::BJobSetupPanel(BPrinter
* printer
)
35 : BPrintPanel("Print document")
37 , fPrinterRoster(NULL
)
38 , fPrintRange(B_ALL_PAGES
)
39 , fJobPanelFlags(B_NO_OPTIONS
)
46 BJobSetupPanel::BJobSetupPanel(BPrinter
* printer
, uint32 flags
)
47 : BPrintPanel("Print document")
49 , fPrinterRoster(NULL
)
50 , fPrintRange(B_ALL_PAGES
)
51 , fJobPanelFlags(flags
)
58 BJobSetupPanel::~BJobSetupPanel()
60 delete fPrinterRoster
;
64 BJobSetupPanel::BJobSetupPanel(BMessage
* data
)
72 BJobSetupPanel::Instantiate(BMessage
* data
)
80 BJobSetupPanel::Archive(BMessage
* data
, bool deep
) const
88 BJobSetupPanel::MessageReceived(BMessage
* message
)
91 BPrintPanel::MessageReceived(message
);
98 status_t status
= ShowPanel();
100 if (status
== B_OK
) {
101 // TODO: check if we did work on an real printer
102 // TODO: set all selected values on printer object
113 BJobSetupPanel::Printer() const
120 BJobSetupPanel::SetPrinter(BPrinter
* printer
, bool keepSettings
)
127 BJobSetupPanel::PrintRange() const
134 BJobSetupPanel::SetPrintRange(print_range range
)
139 fPrintAll
->SetValue(B_CONTROL_ON
);
144 SetOptionFlags(OptionFlags() | B_PRINT_SELECTION
);
145 fSelection
->SetValue(B_CONTROL_ON
);
150 SetOptionFlags(OptionFlags() | B_PRINT_PAGE_RANGE
);
151 fPagesFrom
->SetValue(B_CONTROL_ON
);
158 BJobSetupPanel::FirstPage() const
160 BString
text(fFirstPage
->Text());
161 if (text
.Length() <= 0)
164 return atoi(text
.String());
169 BJobSetupPanel::LastPage() const
171 BString
text(fLastPage
->Text());
172 if (text
.Length() <= 0)
175 return atoi(text
.String());
180 BJobSetupPanel::SetPageRange(int32 firstPage
, int32 lastPage
)
183 SetPrintRange(B_PAGE_RANGE
);
186 fFirstPage
->SetText(text
.String());
189 fLastPage
->SetText(text
.String());
194 BJobSetupPanel::OptionFlags() const
196 return fJobPanelFlags
;
201 BJobSetupPanel::SetOptionFlags(uint32 flags
)
204 if (flags
& B_PRINT_TO_FILE
)
206 fPrintToFile
->SetEnabled(value
);
209 if (flags
& B_PRINT_PAGE_RANGE
)
211 fPagesFrom
->SetEnabled(value
);
212 fFirstPage
->SetEnabled(value
);
213 fLastPage
->SetEnabled(value
);
216 if (flags
& B_PRINT_SELECTION
)
218 fSelection
->SetEnabled(value
);
221 if (flags
& B_PRINT_COLLATE_COPIES
)
223 fCollate
->SetEnabled(value
);
225 fJobPanelFlags
= flags
;
230 BJobSetupPanel::_InitObject()
232 fPrinterRoster
= new BPrinterRoster();
233 fPrinterRoster
->StartWatching(this);
235 if (!fPrinter
->IsValid()) {
236 BPrinter defaultPrinter
;
237 fPrinterRoster
->GetDefaultPrinter(&defaultPrinter
);
238 *fPrinter
= defaultPrinter
;
244 BJobSetupPanel::_SetupInterface()
246 BGroupView
* groupView
= new BGroupView(B_VERTICAL
, 10.0);
249 fPrinterPopUp
= new BPopUpMenu("");
250 fPrinterPopUp
->SetRadioMode(true);
251 fPrinterMenuField
= new BMenuField("", fPrinterPopUp
);
252 fPrinterMenuField
->Menu()->SetLabelFromMarked(true);
255 while (fPrinterRoster
->GetNextPrinter(&printer
) == B_OK
) {
256 BMenuItem
* item
= new BMenuItem(printer
.Name().String(), NULL
);
257 fPrinterPopUp
->AddItem(item
);
258 if (printer
== *fPrinter
)
259 item
->SetMarked(true);
262 if (fPrinterRoster
->CountPrinters() > 0)
263 fPrinterPopUp
->AddItem(new BSeparatorItem
);
265 BMenuItem
* pdf
= new BMenuItem("Save as PDF file" , NULL
);
266 fPrinterPopUp
->AddItem(pdf
);
267 if (fPrinterPopUp
->FindMarked() == NULL
)
268 pdf
->SetMarked(true);
270 fProperties
= new BButton("Properties" B_UTF8_ELLIPSIS
, new BMessage('prop'));
271 fPrinterInfo
= new BStringView("label", "");
272 fPrinterInfo
->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED
, B_SIZE_UNSET
));
273 BBox
* divider
= new BBox(B_FANCY_BORDER
, NULL
);
274 divider
->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED
, 1));
275 fPrintToFile
= new BCheckBox("Print to file");
277 BView
* view
= BGroupLayoutBuilder(B_VERTICAL
, 5.0)
278 .Add(BGroupLayoutBuilder(B_HORIZONTAL
, 10.0)
279 .Add(fPrinterMenuField
->CreateMenuBarLayoutItem())
281 .Add(BGroupLayoutBuilder(B_HORIZONTAL
,5.0)
282 .Add(new BStringView("label", "Printer info:"))
286 .SetInsets(10.0, 5.0, 10.0, 5.0);
288 BBox
*box
= new BBox(B_FANCY_BORDER
, view
);
289 box
->SetLabel(BGroupLayoutBuilder()
290 .Add(new BStringView("", "Printer"))
291 .SetInsets(2.0, 0.0, 2.0, 0.0));
292 groupView
->AddChild(box
);
295 fPrintAll
= new BRadioButton("Print all", new BMessage('prrg'));
296 fPrintAll
->SetValue(B_CONTROL_ON
);
297 fPagesFrom
= new BRadioButton("Pages from:", new BMessage('prrg'));
298 fFirstPage
= new BTextControl("", "", NULL
);
299 _DisallowChar(fFirstPage
->TextView());
300 fLastPage
= new BTextControl("to:", "", NULL
);
301 _DisallowChar(fLastPage
->TextView());
302 fSelection
= new BRadioButton("Print selection", new BMessage('prrg'));
304 fFirstPage
->CreateLabelLayoutItem();
305 view
= BGroupLayoutBuilder(B_VERTICAL
, 5.0)
307 .Add(BGroupLayoutBuilder(B_HORIZONTAL
, 5.0)
309 .Add(fFirstPage
->CreateTextViewLayoutItem())
310 .Add(fLastPage
->CreateLabelLayoutItem())
311 .Add(fLastPage
->CreateTextViewLayoutItem()))
313 .SetInsets(10.0, 5.0, 10.0, 5.0);
315 box
= new BBox(B_FANCY_BORDER
, view
);
316 box
->SetLabel(BGroupLayoutBuilder()
317 .Add(new BStringView("", "Page range"))
318 .SetInsets(2.0, 0.0, 2.0, 0.0));
321 fNumberOfCopies
= new BTextControl("Number of copies:", "1", NULL
);
322 _DisallowChar(fNumberOfCopies
->TextView());
323 fCollate
= new BCheckBox("Collate");
324 fReverse
= new BCheckBox("Reverse");
326 BView
* view2
= BGroupLayoutBuilder(B_VERTICAL
, 5.0)
327 .Add(BGroupLayoutBuilder(B_HORIZONTAL
, 5.0)
328 .Add(fNumberOfCopies
->CreateLabelLayoutItem())
329 .Add(fNumberOfCopies
->CreateTextViewLayoutItem()))
332 .SetInsets(10.0, 5.0, 10.0, 5.0);
334 BBox
* box2
= new BBox(B_FANCY_BORDER
, view2
);
335 box2
->SetLabel(BGroupLayoutBuilder()
336 .Add(new BStringView("", "Copies"))
337 .SetInsets(2.0, 0.0, 2.0, 0.0));
339 groupView
->AddChild(BGroupLayoutBuilder(B_HORIZONTAL
, 10.0)
344 fColor
= new BCheckBox("Print in color");
345 fDuplex
= new BCheckBox("Double side printing");
347 view
= BGroupLayoutBuilder(B_VERTICAL
, 5.0)
350 .SetInsets(10.0, 5.0, 10.0, 5.0);
352 box
= new BBox(B_FANCY_BORDER
, view
);
353 box
->SetLabel(BGroupLayoutBuilder()
354 .Add(new BStringView("", "Other"))
355 .SetInsets(2.0, 0.0, 2.0, 0.0));
356 groupView
->AddChild(box
);
359 SetOptionFlags(fJobPanelFlags
);
364 BJobSetupPanel::_DisallowChar(BTextView
* textView
)
366 for (uint32 i
= 0; i
< '0'; ++i
)
367 textView
->DisallowChar(i
);
369 for (uint32 i
= '9' + 1; i
< 255; ++i
)
370 textView
->DisallowChar(i
);
375 } // namespace BPrivate