xref: /haiku/headers/libs/print/libprint/BlockingWindow.h (revision 4c8e85b316c35a9161f5a1c50ad70bc91c83a76f)
1 /*
2 
3 InterfaceUtils.cpp
4 
5 Copyright (c) 2002 Haiku.
6 
7 Author:
8 	Michael Pfeiffer
9 
10 Permission is hereby granted, free of charge, to any person obtaining a copy of
11 this software and associated documentation files (the "Software"), to deal in
12 the Software without restriction, including without limitation the rights to
13 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
14 of the Software, and to permit persons to whom the Software is furnished to do
15 so, subject to the following conditions:
16 
17 The above copyright notice and this permission notice shall be included in all
18 copies or substantial portions of the Software.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 THE SOFTWARE.
27 
28 */
29 #ifndef _INTERFACE_UTILS_H
30 #define _INTERFACE_UTILS_H
31 
32 
33 #include <AppDefs.h>
34 #include <MessageFilter.h>
35 #include <Window.h>
36 
37 
38 class BHandler;
39 class BMessage;
40 
41 
42 class EscapeMessageFilter : public BMessageFilter
43 {
44 public:
45 							EscapeMessageFilter(BWindow *window, int32 what);
46 			filter_result	Filter(BMessage *msg, BHandler **target);
47 
48 private:
49 			BWindow*		fWindow;
50 			int32			fWhat;
51 };
52 
53 
54 class HWindow : public BWindow
55 {
56 	typedef BWindow 		inherited;
57 public:
58 							HWindow(BRect frame, const char *title,
59 								window_type type, uint32 flags,
60 								uint32 workspace = B_CURRENT_WORKSPACE,
61 								uint32 escape_msg = B_QUIT_REQUESTED);
62 							HWindow(BRect frame, const char *title,
63 								window_look look, window_feel feel, uint32 flags,
64 								uint32 workspace = B_CURRENT_WORKSPACE,
65 								uint32 escape_msg = B_QUIT_REQUESTED);
66 	virtual					~HWindow() {}
67 
68 	virtual void			MessageReceived(BMessage* m);
69 	virtual void			AboutRequested();
70 	virtual const char*		AboutText() const { return NULL; }
71 
72 protected:
73 			void			Init(uint32 escape_msg);
74 };
75 
76 
77 class BlockingWindow : public HWindow
78 {
79 	typedef HWindow 		inherited;
80 public:
81 							BlockingWindow(BRect frame, const char *title,
82 								window_type type, uint32 flags,
83 								uint32 workspace = B_CURRENT_WORKSPACE,
84 								uint32 escape_msg = B_QUIT_REQUESTED);
85 							BlockingWindow(BRect frame, const char *title,
86 								window_look look, window_feel feel, uint32 flags,
87 								uint32 workspace = B_CURRENT_WORKSPACE,
88 								uint32 escape_msg = B_QUIT_REQUESTED);
89 	virtual					~BlockingWindow();
90 
91 	virtual bool			QuitRequested();
92 	// Quit() is called by child class with result code
93 			void			Quit(status_t result);
94 	// Show window and wait for it to quit, returns result code
95 	virtual status_t		Go();
96 	// Or quit window e.g. something went wrong in constructor
97 	virtual void			Quit();
98 	// Sets the result that is returned when the user closes the window.
99 	// Default is B_OK.
100 			void			SetUserQuitResult(status_t result);
101 
102 private:
103 			void			Init(const char* title);
104 
105 private:
106 			status_t		fUserQuitResult;
107 			bool			fReadyToQuit;
108 			sem_id			fExitSem;
109 			status_t*		fResult;
110 };
111 
112 #endif
113