5 Copyright (c) 2002 OpenBeOS.
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:
17 The above copyright notice and this permission notice shall be included in all
18 copies or substantial portions of the Software.
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
30 #include "BlockingWindow.h"
42 // #pragma mark -- EscapeMessageFilter
45 EscapeMessageFilter::EscapeMessageFilter(BWindow
*window
, int32 what
)
46 : BMessageFilter(B_ANY_DELIVERY
, B_ANY_SOURCE
, '_KYD')
54 EscapeMessageFilter::Filter(BMessage
*msg
, BHandler
**target
)
57 filter_result result
= B_DISPATCH_MESSAGE
;
58 if (msg
->FindInt32("key", &key
) == B_OK
&& key
== 1) {
59 fWindow
->PostMessage(fWhat
);
60 result
= B_SKIP_MESSAGE
;
66 // #pragma mark -- HWindow
69 HWindow::HWindow(BRect frame
, const char *title
, window_type type
, uint32 flags
,
70 uint32 workspace
, uint32 escape_msg
)
71 : BWindow(frame
, title
, type
, flags
, workspace
)
77 HWindow::HWindow(BRect frame
, const char *title
, window_look look
, window_feel feel
,
78 uint32 flags
, uint32 workspace
, uint32 escape_msg
)
79 : BWindow(frame
, title
, look
, feel
, flags
, workspace
)
86 HWindow::Init(uint32 escape_msg
)
88 AddShortcut('i', 0, new BMessage(B_ABOUT_REQUESTED
));
89 AddCommonFilter(new EscapeMessageFilter(this, escape_msg
));
94 HWindow::MessageReceived(BMessage
* msg
)
96 if (msg
->what
== B_ABOUT_REQUESTED
) {
99 inherited::MessageReceived(msg
);
105 HWindow::AboutRequested()
107 const char* aboutText
= AboutText();
108 if (aboutText
== NULL
)
111 BAlert
*about
= new BAlert("About", aboutText
, "Cool");
112 BTextView
*v
= about
->TextView();
114 rgb_color red
= {255, 0, 51, 255};
115 rgb_color blue
= {0, 102, 255, 255};
117 v
->SetStylable(true);
118 char *text
= (char*)v
->Text();
120 // set all Be in blue and red
121 while ((s
= strstr(s
, "Be")) != NULL
) {
123 v
->SetFontAndColor(i
, i
+1, NULL
, 0, &blue
);
124 v
->SetFontAndColor(i
+1, i
+2, NULL
, 0, &red
);
128 s
= strchr(text
, '\n');
130 v
->GetFontAndColor(0, &font
);
131 font
.SetSize(12); // font.SetFace(B_OUTLINED_FACE);
132 v
->SetFontAndColor(0, s
-text
+1, &font
, B_FONT_SIZE
);
134 about
->SetFlags(about
->Flags() | B_CLOSE_ON_ESCAPE
);
139 // #pragma mark -- BlockingWindow
142 BlockingWindow::BlockingWindow(BRect frame
, const char *title
, window_type type
,
143 uint32 flags
, uint32 workspace
, uint32 escape_msg
)
144 : HWindow(frame
, title
, type
, flags
, workspace
)
150 BlockingWindow::BlockingWindow(BRect frame
, const char *title
, window_look look
,
151 window_feel feel
, uint32 flags
, uint32 workspace
, uint32 escape_msg
)
152 : HWindow(frame
, title
, look
, feel
, flags
, workspace
)
158 BlockingWindow::~BlockingWindow()
160 delete_sem(fExitSem
);
165 BlockingWindow::Init(const char* title
)
167 fUserQuitResult
= B_OK
;
169 fExitSem
= create_sem(0, title
);
170 fReadyToQuit
= false;
175 BlockingWindow::QuitRequested()
180 // user requested to quit the window
181 *fResult
= fUserQuitResult
;
182 release_sem(fExitSem
);
188 BlockingWindow::Quit()
190 fReadyToQuit
= false; // finally allow window to quit
191 inherited::Quit(); // and quit it
196 BlockingWindow::Quit(status_t result
)
201 release_sem(fExitSem
);
206 BlockingWindow::SetUserQuitResult(status_t result
)
208 fUserQuitResult
= result
;
215 status_t result
= B_ERROR
;
218 acquire_sem(fExitSem
);
219 // here the window still exists, because QuitRequested returns false if
220 // fReadyToQuit is false, now we can quit the window and am sure that the
221 // window thread dies before this thread
225 ASSERT(false); // should not reach here!!!
227 // here the window does not exist, good to have the result in a local variable