1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2001-2002, OpenBeOS 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 // 22 // File Name: Window.h 23 // Author: Erik Jaesler (erik@cgsoftware.com) 24 // Description: BWindow is the base class for all windows (graphic areas 25 // displayed on-screen). 26 //------------------------------------------------------------------------------ 27 28 #ifndef _WINDOW_H 29 #define _WINDOW_H 30 31 // Standard Includes ----------------------------------------------------------- 32 33 // System Includes ------------------------------------------------------------- 34 #include <BeBuild.h> 35 #include <InterfaceDefs.h> 36 #include <List.h> 37 #include <Looper.h> 38 #include <Rect.h> 39 #include <StorageDefs.h> 40 41 // Project Includes ------------------------------------------------------------ 42 43 // Local Includes -------------------------------------------------------------- 44 45 // Local Defines --------------------------------------------------------------- 46 47 // Globals --------------------------------------------------------------------- 48 49 50 // window definitions ---------------------------------------------------------- 51 52 enum window_type { 53 B_UNTYPED_WINDOW = 0, 54 B_TITLED_WINDOW = 1, 55 B_MODAL_WINDOW = 3, 56 B_DOCUMENT_WINDOW = 11, 57 B_BORDERED_WINDOW = 20, 58 B_FLOATING_WINDOW = 21 59 }; 60 61 //---------------------------------------------------------------- 62 63 enum window_look { 64 B_BORDERED_WINDOW_LOOK = 20, 65 B_NO_BORDER_WINDOW_LOOK = 19, 66 B_TITLED_WINDOW_LOOK = 1, 67 B_DOCUMENT_WINDOW_LOOK = 11, 68 B_MODAL_WINDOW_LOOK = 3, 69 B_FLOATING_WINDOW_LOOK = 7 70 }; 71 72 //---------------------------------------------------------------- 73 74 enum window_feel { 75 B_NORMAL_WINDOW_FEEL = 0, 76 B_MODAL_SUBSET_WINDOW_FEEL = 2, 77 B_MODAL_APP_WINDOW_FEEL = 1, 78 B_MODAL_ALL_WINDOW_FEEL = 3, 79 B_FLOATING_SUBSET_WINDOW_FEEL = 5, 80 B_FLOATING_APP_WINDOW_FEEL = 4, 81 B_FLOATING_ALL_WINDOW_FEEL = 6 82 }; 83 84 //---------------------------------------------------------------- 85 86 enum window_alignment { 87 B_BYTE_ALIGNMENT = 0, 88 B_PIXEL_ALIGNMENT = 1 89 }; 90 91 //---------------------------------------------------------------- 92 93 enum { 94 B_NOT_MOVABLE = 0x00000001, 95 B_NOT_CLOSABLE = 0x00000020, 96 B_NOT_ZOOMABLE = 0x00000040, 97 B_NOT_MINIMIZABLE = 0x00004000, 98 B_NOT_RESIZABLE = 0x00000002, 99 B_NOT_H_RESIZABLE = 0x00000004, 100 B_NOT_V_RESIZABLE = 0x00000008, 101 B_AVOID_FRONT = 0x00000080, 102 B_AVOID_FOCUS = 0x00002000, 103 B_WILL_ACCEPT_FIRST_CLICK = 0x00000010, 104 B_OUTLINE_RESIZE = 0x00001000, 105 B_NO_WORKSPACE_ACTIVATION = 0x00000100, 106 B_NOT_ANCHORED_ON_ACTIVATE = 0x00020000, 107 B_ASYNCHRONOUS_CONTROLS = 0x00080000, 108 B_QUIT_ON_WINDOW_CLOSE = 0x00100000 109 }; 110 111 #define B_CURRENT_WORKSPACE 0 112 #define B_ALL_WORKSPACES 0xffffffff 113 114 //---------------------------------------------------------------- 115 116 class _BSession_; 117 class BButton; 118 class BMenuBar; 119 class BMenuItem; 120 class BMessage; 121 class BMessageRunner; 122 class BMessenger; 123 class BView; 124 125 struct message; 126 struct _cmd_key_; 127 struct _view_attr_; 128 129 // BWindow class --------------------------------------------------------------- 130 class BWindow : public BLooper { 131 132 public: 133 BWindow(BRect frame, 134 const char* title, 135 window_type type, 136 uint32 flags, 137 uint32 workspace = B_CURRENT_WORKSPACE); 138 BWindow(BRect frame, 139 const char* title, 140 window_look look, 141 window_feel feel, 142 uint32 flags, 143 uint32 workspace = B_CURRENT_WORKSPACE); 144 virtual ~BWindow(); 145 146 BWindow(BMessage* data); 147 static BArchivable *Instantiate(BMessage* data); 148 virtual status_t Archive(BMessage* data, bool deep = true) const; 149 150 virtual void Quit(); 151 void Close(); // Synonym of Quit() 152 153 void AddChild(BView* child, BView* before = NULL); 154 bool RemoveChild(BView* child); 155 int32 CountChildren() const; 156 BView *ChildAt(int32 index) const; 157 158 virtual void DispatchMessage(BMessage* message, BHandler* handler); 159 virtual void MessageReceived(BMessage* message); 160 virtual void FrameMoved(BPoint new_position); 161 virtual void WorkspacesChanged(uint32 old_ws, uint32 new_ws); 162 virtual void WorkspaceActivated(int32 ws, bool state); 163 virtual void FrameResized(float new_width, float new_height); 164 virtual void Minimize(bool minimize); 165 virtual void Zoom( BPoint rec_position, 166 float rec_width, 167 float rec_height); 168 void Zoom(); 169 void SetZoomLimits(float max_h, float max_v); 170 virtual void ScreenChanged(BRect screen_size, color_space depth); 171 void SetPulseRate(bigtime_t rate); 172 bigtime_t PulseRate() const; 173 void AddShortcut( uint32 key, 174 uint32 modifiers, 175 BMessage* msg); 176 void AddShortcut( uint32 key, 177 uint32 modifiers, 178 BMessage* msg, 179 BHandler* target); 180 void RemoveShortcut(uint32 key, uint32 modifiers); 181 void SetDefaultButton(BButton* button); 182 BButton *DefaultButton() const; 183 virtual void MenusBeginning(); 184 virtual void MenusEnded(); 185 bool NeedsUpdate() const; 186 void UpdateIfNeeded(); 187 BView *FindView(const char* view_name) const; 188 BView *FindView(BPoint) const; 189 BView *CurrentFocus() const; 190 void Activate(bool = true); 191 virtual void WindowActivated(bool state); 192 void ConvertToScreen(BPoint* pt) const; 193 BPoint ConvertToScreen(BPoint pt) const; 194 void ConvertFromScreen(BPoint* pt) const; 195 BPoint ConvertFromScreen(BPoint pt) const; 196 void ConvertToScreen(BRect* rect) const; 197 BRect ConvertToScreen(BRect rect) const; 198 void ConvertFromScreen(BRect* rect) const; 199 BRect ConvertFromScreen(BRect rect) const; 200 void MoveBy(float dx, float dy); 201 void MoveTo(BPoint); 202 void MoveTo(float x, float y); 203 void ResizeBy(float dx, float dy); 204 void ResizeTo(float width, float height); 205 virtual void Show(); 206 virtual void Hide(); 207 bool IsHidden() const; 208 bool IsMinimized() const; 209 210 void Flush() const; 211 void Sync() const; 212 213 status_t SendBehind(const BWindow* window); 214 215 void DisableUpdates(); 216 void EnableUpdates(); 217 218 void BeginViewTransaction(); 219 void EndViewTransaction(); 220 221 BRect Bounds() const; 222 BRect Frame() const; 223 const char *Title() const; 224 void SetTitle(const char* title); 225 bool IsFront() const; 226 bool IsActive() const; 227 void SetKeyMenuBar(BMenuBar* bar); 228 BMenuBar *KeyMenuBar() const; 229 void SetSizeLimits( float min_h, 230 float max_h, 231 float min_v, 232 float max_v); 233 void GetSizeLimits( float* min_h, 234 float* max_h, 235 float* min_v, 236 float* max_v); 237 uint32 Workspaces() const; 238 void SetWorkspaces(uint32); 239 BView *LastMouseMovedView() const; 240 241 virtual BHandler *ResolveSpecifier(BMessage* msg, 242 int32 index, 243 BMessage* specifier, 244 int32 form, 245 const char* property); 246 virtual status_t GetSupportedSuites(BMessage* data); 247 248 status_t AddToSubset(BWindow* window); 249 status_t RemoveFromSubset(BWindow* window); 250 251 virtual status_t Perform(perform_code d, void* arg); 252 253 status_t SetType(window_type type); 254 window_type Type() const; 255 256 status_t SetLook(window_look look); 257 window_look Look() const; 258 259 status_t SetFeel(window_feel feel); 260 window_feel Feel() const; 261 262 status_t SetFlags(uint32); 263 uint32 Flags() const; 264 265 bool IsModal() const; 266 bool IsFloating() const; 267 268 status_t SetWindowAlignment(window_alignment mode, 269 int32 h, 270 int32 hOffset = 0, 271 int32 width = 0, 272 int32 widthOffset = 0, 273 int32 v = 0, 274 int32 vOffset = 0, 275 int32 height = 0, 276 int32 heightOffset = 0); 277 status_t GetWindowAlignment(window_alignment* mode = NULL, 278 int32* h = NULL, 279 int32* hOffset = NULL, 280 int32* width = NULL, 281 int32* widthOffset = NULL, 282 int32* v = NULL, 283 int32* vOffset = NULL, 284 int32* height = NULL, 285 int32* heightOffset = NULL) const; 286 287 virtual bool QuitRequested(); 288 virtual thread_id Run(); 289 290 // Private or reserved --------------------------------------------------------- 291 private: 292 293 typedef BLooper inherited; 294 295 friend class BApplication; 296 friend class BBitmap; 297 friend class BScrollBar; 298 friend class BView; 299 friend class BMenuItem; 300 friend class BWindowScreen; 301 friend class BDirectWindow; 302 friend class BFilePanel; 303 friend class _CEventPort_; 304 friend void _set_menu_sem_(BWindow* w, sem_id sem); 305 friend status_t _safe_get_server_token_(const BLooper* , int32* ); 306 307 virtual void _ReservedWindow1(); 308 virtual void _ReservedWindow2(); 309 virtual void _ReservedWindow3(); 310 virtual void _ReservedWindow4(); 311 virtual void _ReservedWindow5(); 312 virtual void _ReservedWindow6(); 313 virtual void _ReservedWindow7(); 314 virtual void _ReservedWindow8(); 315 316 BWindow(); 317 BWindow(BWindow&); 318 BWindow &operator=(BWindow&); 319 320 BWindow(BRect frame, color_space depth, 321 uint32 bitmapFlags, int32 rowBytes); 322 void InitData(BRect frame, 323 const char* title, 324 window_look look, 325 window_feel feel, 326 uint32 flags, 327 uint32 workspace); 328 status_t ArchiveChildren(BMessage* data, bool deep) const; 329 status_t UnarchiveChildren(BMessage* data); 330 void BitmapClose(); 331 virtual void task_looper(); 332 void start_drag( BMessage* msg, 333 int32 token, 334 BPoint offset, 335 BRect track_rect, 336 BHandler* reply_to); 337 void start_drag( BMessage* msg, 338 int32 token, 339 BPoint offset, 340 int32 bitmap_token, 341 drawing_mode dragMode, 342 BHandler* reply_to); 343 void view_builder(BView* a_view); 344 void attach_builder(BView* a_view); 345 void detach_builder(BView* a_view); 346 int32 get_server_token() const; 347 BMessage *extract_drop(BMessage* an_event, BHandler* *target); 348 void movesize(uint32 opcode, float h, float v); 349 350 BMessage* ReadMessageFromPort(bigtime_t tout = B_INFINITE_TIMEOUT); 351 int32 MessagesWaiting(); 352 353 void handle_activate(BMessage* an_event); 354 void do_view_frame(BMessage* an_event); 355 void do_value_change(BMessage* an_event, BHandler* handler); 356 void do_mouse_down(BMessage* an_event, BView* target); 357 void do_mouse_moved(BMessage* an_event, BView* target); 358 void do_key_down(BMessage* an_event, BHandler* handler); 359 void do_key_up(BMessage* an_event, BHandler* handler); 360 void do_menu_event(BMessage* an_event); 361 void do_draw_views(); 362 virtual BMessage *ConvertToMessage(void* raw, int32 code); 363 _cmd_key_ *allocShortcut(uint32 key, uint32 modifiers); 364 _cmd_key_ *FindShortcut(uint32 key, uint32 modifiers); 365 void AddShortcut(uint32 key, 366 uint32 modifiers, 367 BMenuItem* item); 368 void post_message(BMessage* message); 369 void SetLocalTitle(const char* new_title); 370 void enable_pulsing(bool enable); 371 BHandler *determine_target(BMessage* msg, BHandler* target, bool pref); 372 void kb_navigate(); 373 void navigate_to_next(int32 direction, bool group = false); 374 void set_focus(BView* focus, bool notify_input_server); 375 bool InUpdate(); 376 void DequeueAll(); 377 bool find_token_and_handler(BMessage* msg, 378 int32* token, 379 BHandler* *handler); 380 window_type compose_type(window_look look, 381 window_feel feel) const; 382 void decompose_type(window_type type, 383 window_look* look, 384 window_feel* feel) const; 385 386 void SetIsFilePanel(bool panel); 387 bool IsFilePanel() const; 388 389 // 3 deprecated calls 390 void AddFloater(BWindow* a_floating_window); 391 void RemoveFloater(BWindow* a_floating_window); 392 window_type WindowType() const; 393 394 char *fTitle; 395 int32 server_token; 396 char fInUpdate; 397 char f_active; 398 short fShowLevel; 399 uint32 fFlags; 400 401 port_id send_port; 402 port_id receive_port; 403 404 BView *top_view; 405 BView *fFocus; 406 BView *fLastMouseMovedView; 407 _BSession_ *a_session; 408 BMenuBar *fKeyMenuBar; 409 BButton *fDefaultButton; 410 BList accelList; 411 int32 top_view_token; 412 bool pulse_enabled; 413 bool fViewsNeedPulse; 414 bool fIsFilePanel; 415 bool fUnused1; 416 bigtime_t pulse_rate; 417 bool fWaitingForMenu; 418 bool fOffscreen; 419 sem_id fMenuSem; 420 float fMaxZoomH; 421 float fMaxZoomV; 422 float fMinWindH; 423 float fMinWindV; 424 float fMaxWindH; 425 float fMaxWindV; 426 BRect fFrame; 427 window_look fLook; 428 _view_attr_ *fCurDrawViewState; 429 window_feel fFeel; 430 int32 fLastViewToken; 431 _CEventPort_* fEventPort; 432 BMessageRunner *fPulseRunner; 433 BRect fCurrentFrame; 434 435 uint32 _reserved[2]; // was 8 436 #if !_PR3_COMPATIBLE_ 437 uint32 _more_reserved[4]; 438 #endif 439 }; 440 441 // inline definitions ---------------------------------------------------------- 442 inline void BWindow::Close() 443 { 444 Quit(); 445 } 446 //------------------------------------------------------------------------------ 447 448 #endif // _WINDOW_H 449 450 /* 451 * $Log $ 452 * 453 * $Id $ 454 * 455 */ 456 457