2 * Copyright 2008 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Julun, <host.haiku@gmx.de
9 #include <PrintPanel.h>
12 #include <GroupLayoutBuilder.h>
13 #include <GroupView.h>
21 // #pragma mark -- _BPrintPanelFilter_
24 BPrintPanel::_BPrintPanelFilter_::_BPrintPanelFilter_(BPrintPanel
* panel
)
25 : BMessageFilter(B_KEY_DOWN
)
32 BPrintPanel::_BPrintPanelFilter_::Filter(BMessage
* msg
, BHandler
** target
)
35 filter_result result
= B_DISPATCH_MESSAGE
;
36 if (msg
->FindInt32("key", &key
) == B_OK
&& key
== 1) {
37 fPrintPanel
->PostMessage(B_QUIT_REQUESTED
);
38 result
= B_SKIP_MESSAGE
;
44 // #pragma mark -- BPrintPanel
47 BPrintPanel::BPrintPanel(const BString
& title
)
48 : BWindow(BRect(0, 0, 640, 480), title
.String(), B_TITLED_WINDOW_LOOK
,
49 B_MODAL_APP_WINDOW_FEEL
, B_NOT_ZOOMABLE
| B_NOT_RESIZABLE
|
50 B_ASYNCHRONOUS_CONTROLS
| B_AUTO_UPDATE_SIZE_LIMITS
| B_CLOSE_ON_ESCAPE
)
51 , fPanel(new BGroupView
)
53 , fPrintPanelResult(B_CANCEL
)
55 BButton
* ok
= new BButton("OK", new BMessage('_ok_'));
56 BButton
* cancel
= new BButton("Cancel", new BMessage('_cl_'));
58 BGroupLayout
*layout
= new BGroupLayout(B_HORIZONTAL
);
61 AddChild(BGroupLayoutBuilder(B_VERTICAL
, 10.0)
63 .Add(BGroupLayoutBuilder(B_HORIZONTAL
, 10.0)
67 .SetInsets(0.0, 0.0, 0.0, 0.0))
68 .SetInsets(10.0, 10.0, 10.0, 10.0)
71 ok
->MakeDefault(true);
72 AddCommonFilter(new _BPrintPanelFilter_(this));
76 BPrintPanel::~BPrintPanel()
78 if (fPrintPanelSem
> 0)
79 delete_sem(fPrintPanelSem
);
83 BPrintPanel::BPrintPanel(BMessage
* data
)
91 BPrintPanel::Instantiate(BMessage
* data
)
99 BPrintPanel::Archive(BMessage
* data
, bool deep
) const
107 BPrintPanel::Panel() const
109 return fPanel
->ChildAt(0);
114 BPrintPanel::AddPanel(BView
* panel
)
116 BView
* child
= Panel();
122 fPanel
->AddChild(panel
);
124 BSize size
= GetLayout()->PreferredSize();
125 ResizeTo(size
.Width(), size
.Height());
130 BPrintPanel::RemovePanel(BView
* child
)
132 BView
* panel
= Panel();
134 return fPanel
->RemoveChild(child
);
141 BPrintPanel::MessageReceived(BMessage
* message
)
143 switch (message
->what
) {
145 fPrintPanelResult
= B_OK
;
149 delete_sem(fPrintPanelSem
);
154 BWindow::MessageReceived(message
);
160 BPrintPanel::FrameResized(float newWidth
, float newHeight
)
162 BWindow::FrameResized(newWidth
, newHeight
);
167 BPrintPanel::ResolveSpecifier(BMessage
* message
, int32 index
, BMessage
* specifier
,
168 int32 form
, const char* property
)
170 return BWindow::ResolveSpecifier(message
, index
, specifier
, form
, property
);
175 BPrintPanel::GetSupportedSuites(BMessage
* data
)
177 return BWindow::GetSupportedSuites(data
);
182 BPrintPanel::Perform(perform_code d
, void* arg
)
184 return BWindow::Perform(d
, arg
);
196 BPrintPanel::QuitRequested()
198 return BWindow::QuitRequested();
203 BPrintPanel::DispatchMessage(BMessage
* message
, BHandler
* handler
)
205 BWindow::DispatchMessage(message
, handler
);
210 BPrintPanel::ShowPanel()
212 fPrintPanelSem
= create_sem(0, "PrintPanel");
213 if (fPrintPanelSem
< 0) {
218 BWindow
* window
= dynamic_cast<BWindow
*> (BLooper::LooperForThread(find_thread(NULL
)));
221 BRect
bounds(Bounds());
222 BRect
frame(BScreen(B_MAIN_SCREEN_ID
).Frame());
223 MoveTo((frame
.Width() - bounds
.Width()) / 2.0,
224 (frame
.Height() - bounds
.Height()) / 2.0);
233 err
= acquire_sem_etc(fPrintPanelSem
, 1, B_RELATIVE_TIMEOUT
, 50000);
234 } while (err
== B_INTERRUPTED
);
236 if (err
== B_BAD_SEM_ID
)
238 window
->UpdateIfNeeded();
241 while (acquire_sem(fPrintPanelSem
) == B_INTERRUPTED
) {}
244 return fPrintPanelResult
;
249 BPrintPanel::AddChild(BView
* child
, BView
* before
)
251 BWindow::AddChild(child
, before
);
256 BPrintPanel::RemoveChild(BView
* child
)
258 return BWindow::RemoveChild(child
);
263 BPrintPanel::ChildAt(int32 index
) const
265 return BWindow::ChildAt(index
);
269 void BPrintPanel::_ReservedBPrintPanel1() {}
270 void BPrintPanel::_ReservedBPrintPanel2() {}
271 void BPrintPanel::_ReservedBPrintPanel3() {}
272 void BPrintPanel::_ReservedBPrintPanel4() {}
273 void BPrintPanel::_ReservedBPrintPanel5() {}
277 } // namespace BPrivate