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: Adrian Oanca (e2joseph@hotpop.com) 24 // Description: BWindow is the base class for all windows (graphic areas 25 // displayed on-screen). 26 // 27 // 28 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 29 // NOTE(!!!) All private non virtual functions are to be renamed following 30 // this scheme: word_another_third <-> wordAnotherThird 31 // OBOS Team: If you use one of BWindow's private functions, please addapt to this code 32 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 33 //------------------------------------------------------------------------------ 34 35 #ifndef _WINDOW_H 36 #define _WINDOW_H 37 38 // Standard Includes ----------------------------------------------------------- 39 40 // System Includes ------------------------------------------------------------- 41 #include <BeBuild.h> 42 #include <InterfaceDefs.h> 43 #include <List.h> 44 #include <Looper.h> 45 #include <Rect.h> 46 #include <StorageDefs.h> 47 48 // Project Includes ------------------------------------------------------------ 49 #include <View.h> 50 51 // Local Includes -------------------------------------------------------------- 52 53 // Local Defines --------------------------------------------------------------- 54 class PortLink; 55 56 // Globals --------------------------------------------------------------------- 57 58 59 // window definitions ---------------------------------------------------------- 60 61 enum window_type { 62 B_UNTYPED_WINDOW = 0, 63 B_TITLED_WINDOW = 1, 64 B_MODAL_WINDOW = 3, 65 B_DOCUMENT_WINDOW = 11, 66 B_BORDERED_WINDOW = 20, 67 B_FLOATING_WINDOW = 21 68 }; 69 70 //---------------------------------------------------------------- 71 72 enum window_look { 73 B_BORDERED_WINDOW_LOOK = 20, 74 B_NO_BORDER_WINDOW_LOOK = 19, 75 B_TITLED_WINDOW_LOOK = 1, 76 B_DOCUMENT_WINDOW_LOOK = 11, 77 B_MODAL_WINDOW_LOOK = 3, 78 B_FLOATING_WINDOW_LOOK = 7 79 }; 80 81 //---------------------------------------------------------------- 82 83 enum window_feel { 84 B_NORMAL_WINDOW_FEEL = 0, 85 B_MODAL_SUBSET_WINDOW_FEEL = 2, 86 B_MODAL_APP_WINDOW_FEEL = 1, 87 B_MODAL_ALL_WINDOW_FEEL = 3, 88 B_FLOATING_SUBSET_WINDOW_FEEL = 5, 89 B_FLOATING_APP_WINDOW_FEEL = 4, 90 B_FLOATING_ALL_WINDOW_FEEL = 6 91 }; 92 93 //---------------------------------------------------------------- 94 95 enum window_alignment { 96 B_BYTE_ALIGNMENT = 0, 97 B_PIXEL_ALIGNMENT = 1 98 }; 99 100 //---------------------------------------------------------------- 101 102 enum { 103 B_NOT_MOVABLE = 0x00000001, 104 B_NOT_CLOSABLE = 0x00000020, 105 B_NOT_ZOOMABLE = 0x00000040, 106 B_NOT_MINIMIZABLE = 0x00004000, 107 B_NOT_RESIZABLE = 0x00000002, 108 B_NOT_H_RESIZABLE = 0x00000004, 109 B_NOT_V_RESIZABLE = 0x00000008, 110 B_AVOID_FRONT = 0x00000080, 111 B_AVOID_FOCUS = 0x00002000, 112 B_WILL_ACCEPT_FIRST_CLICK = 0x00000010, 113 B_OUTLINE_RESIZE = 0x00001000, 114 B_NO_WORKSPACE_ACTIVATION = 0x00000100, 115 B_NOT_ANCHORED_ON_ACTIVATE = 0x00020000, 116 B_ASYNCHRONOUS_CONTROLS = 0x00080000, 117 B_QUIT_ON_WINDOW_CLOSE = 0x00100000 118 }; 119 120 #define B_CURRENT_WORKSPACE 0 121 #define B_ALL_WORKSPACES 0xffffffff 122 123 //---------------------------------------------------------------- 124 125 class BSession; 126 class BButton; 127 class BMenuBar; 128 class BMenuItem; 129 class BMessage; 130 class BMessageRunner; 131 class BMessenger; 132 class BView; 133 134 struct message; 135 struct _cmd_key_; 136 struct _view_attr_; 137 138 // BWindow class --------------------------------------------------------------- 139 class BWindow : public BLooper { 140 141 public: 142 BWindow(BRect frame, 143 const char* title, 144 window_type type, 145 uint32 flags, 146 uint32 workspace = B_CURRENT_WORKSPACE); 147 BWindow(BRect frame, 148 const char* title, 149 window_look look, 150 window_feel feel, 151 uint32 flags, 152 uint32 workspace = B_CURRENT_WORKSPACE); 153 virtual ~BWindow(); 154 155 BWindow(BMessage* data); 156 static BArchivable *Instantiate(BMessage* data); 157 virtual status_t Archive(BMessage* data, bool deep = true) const; 158 159 virtual void Quit(); 160 void Close(); // Synonym of Quit() 161 162 void AddChild(BView* child, BView* before = NULL); 163 bool RemoveChild(BView* child); 164 int32 CountChildren() const; 165 BView *ChildAt(int32 index) const; 166 167 virtual void DispatchMessage(BMessage* message, BHandler* handler); 168 virtual void MessageReceived(BMessage* message); 169 virtual void FrameMoved(BPoint new_position); 170 virtual void WorkspacesChanged(uint32 old_ws, uint32 new_ws); 171 virtual void WorkspaceActivated(int32 ws, bool state); 172 virtual void FrameResized(float new_width, float new_height); 173 virtual void Minimize(bool minimize); 174 virtual void Zoom( BPoint rec_position, 175 float rec_width, 176 float rec_height); 177 void Zoom(); 178 void SetZoomLimits(float maxWidth, float maxHeight); // changed from: SetZoomLimits(float max_h, float max_v); 179 virtual void ScreenChanged(BRect screen_size, color_space depth); 180 void SetPulseRate(bigtime_t rate); 181 bigtime_t PulseRate() const; 182 void AddShortcut( uint32 key, 183 uint32 modifiers, 184 BMessage* msg); 185 void AddShortcut( uint32 key, 186 uint32 modifiers, 187 BMessage* msg, 188 BHandler* target); 189 void RemoveShortcut(uint32 key, uint32 modifiers); 190 void SetDefaultButton(BButton* button); 191 BButton *DefaultButton() const; 192 virtual void MenusBeginning(); 193 virtual void MenusEnded(); 194 bool NeedsUpdate() const; 195 void UpdateIfNeeded(); 196 BView *FindView(const char* viewName) const; // changed from: FindView( const char* view_name ); 197 BView *FindView(BPoint) const; 198 BView *CurrentFocus() const; 199 void Activate(bool = true); 200 virtual void WindowActivated(bool state); 201 void ConvertToScreen(BPoint* pt) const; 202 BPoint ConvertToScreen(BPoint pt) const; 203 void ConvertFromScreen(BPoint* pt) const; 204 BPoint ConvertFromScreen(BPoint pt) const; 205 void ConvertToScreen(BRect* rect) const; 206 BRect ConvertToScreen(BRect rect) const; 207 void ConvertFromScreen(BRect* rect) const; 208 BRect ConvertFromScreen(BRect rect) const; 209 void MoveBy(float dx, float dy); 210 void MoveTo(BPoint); 211 void MoveTo(float x, float y); 212 void ResizeBy(float dx, float dy); 213 void ResizeTo(float width, float height); 214 virtual void Show(); 215 virtual void Hide(); 216 bool IsHidden() const; 217 bool IsMinimized() const; 218 219 void Flush() const; 220 void Sync() const; 221 222 status_t SendBehind(const BWindow* window); 223 224 void DisableUpdates(); 225 void EnableUpdates(); 226 227 void BeginViewTransaction(); // referred as OpenViewTransaction() in BeBook 228 void EndViewTransaction(); // referred as CommitViewTransaction() in BeBook 229 230 BRect Bounds() const; 231 BRect Frame() const; 232 const char *Title() const; 233 void SetTitle(const char* title); 234 bool IsFront() const; 235 bool IsActive() const; 236 void SetKeyMenuBar(BMenuBar* bar); 237 BMenuBar *KeyMenuBar() const; 238 void SetSizeLimits( float minWidth, // changed from: SetSizeLimits(float min_h, float max_h, float min_v, float max_v); 239 float maxWidth, 240 float minHeight, 241 float maxHeight); 242 void GetSizeLimits( float *minWidth, // changed from: SetSizeLimits(float* min_h, float* max_h, float* min_v, float* max_v); 243 float *maxWidth, 244 float *minHeight, 245 float *maxHeight); 246 uint32 Workspaces() const; 247 void SetWorkspaces(uint32); 248 BView *LastMouseMovedView() const; 249 250 virtual BHandler *ResolveSpecifier(BMessage* msg, 251 int32 index, 252 BMessage* specifier, 253 int32 form, 254 const char* property); 255 virtual status_t GetSupportedSuites(BMessage* data); 256 257 status_t AddToSubset(BWindow* window); 258 status_t RemoveFromSubset(BWindow* window); 259 260 virtual status_t Perform(perform_code d, void* arg); 261 262 status_t SetType(window_type type); 263 window_type Type() const; 264 265 status_t SetLook(window_look look); 266 window_look Look() const; 267 268 status_t SetFeel(window_feel feel); 269 window_feel Feel() const; 270 271 status_t SetFlags(uint32); 272 uint32 Flags() const; 273 274 bool IsModal() const; 275 bool IsFloating() const; 276 277 status_t SetWindowAlignment(window_alignment mode, 278 int32 h, 279 int32 hOffset = 0, 280 int32 width = 0, 281 int32 widthOffset = 0, 282 int32 v = 0, 283 int32 vOffset = 0, 284 int32 height = 0, 285 int32 heightOffset = 0); 286 status_t GetWindowAlignment(window_alignment* mode = NULL, 287 int32* h = NULL, 288 int32* hOffset = NULL, 289 int32* width = NULL, 290 int32* widthOffset = NULL, 291 int32* v = NULL, 292 int32* vOffset = NULL, 293 int32* height = NULL, 294 int32* heightOffset = NULL) const; 295 296 virtual bool QuitRequested(); 297 virtual thread_id Run(); 298 299 // Private or reserved --------------------------------------------------------- 300 private: 301 302 typedef BLooper inherited; 303 304 friend class BApplication; 305 friend class BBitmap; 306 friend class BScrollBar; 307 friend class BView; 308 friend class BMenuItem; 309 friend class BWindowScreen; 310 friend class BDirectWindow; 311 friend class BFilePanel; 312 friend class BHandler; 313 friend class _BEventMask; 314 friend void _set_menu_sem_(BWindow* w, sem_id sem); 315 friend status_t _safe_get_server_token_(const BLooper* , int32* ); 316 317 virtual void _ReservedWindow1(); 318 virtual void _ReservedWindow2(); 319 virtual void _ReservedWindow3(); 320 virtual void _ReservedWindow4(); 321 virtual void _ReservedWindow5(); 322 virtual void _ReservedWindow6(); 323 virtual void _ReservedWindow7(); 324 virtual void _ReservedWindow8(); 325 326 BWindow(); 327 BWindow(BWindow&); 328 BWindow &operator=(BWindow&); 329 330 BWindow(BRect frame, color_space depth, // to be implemented 331 uint32 bitmapFlags, int32 rowBytes); 332 void InitData(BRect frame, 333 const char* title, 334 window_look look, 335 window_feel feel, 336 uint32 flags, 337 uint32 workspace); 338 status_t ArchiveChildren(BMessage* data, bool deep) const; // call made from within Archive 339 status_t UnarchiveChildren(BMessage* data); // Instantiate(BMessage* data)->BWindow(BMessage)->UnarchiveChildren(BMessage* data) 340 void BitmapClose(); // to be implemented 341 virtual void task_looper(); // thread function - it's here where app_server messages are received 342 /* void start_drag( BMessage* msg, 343 int32 token, 344 BPoint offset, 345 BRect track_rect, 346 BHandler* reply_to); 347 void start_drag( BMessage* msg, 348 int32 token, 349 BPoint offset, 350 int32 bitmap_token, 351 drawing_mode dragMode, 352 BHandler* reply_to); 353 */ 354 void prepareView(BView* aView); // changed from view_builder(BView* a_view); 355 void attachView(BView* aView); // changed from attach_builder(BView* a_view); 356 void detachView(BView* aView); // changed from detach_builder(BView* a_view); 357 //int32 get_server_token() const; 358 BMessage *extract_drop(BMessage* an_event, BHandler* *target); 359 //void movesize(uint32 opcode, float h, float v); 360 361 BMessage* ReadMessageFromPort(bigtime_t tout = B_INFINITE_TIMEOUT); 362 //int32 MessagesWaiting(); 363 364 void handle_activate(BMessage* an_event); 365 //void do_view_frame(BMessage* an_event); 366 //void do_value_change(BMessage* an_event, BHandler* handler); 367 //void do_mouse_down(BMessage* an_event, BView* target); 368 //void do_mouse_moved(BMessage* an_event, BView* target); 369 //void do_key_down(BMessage* an_event, BHandler* handler); 370 //void do_key_up(BMessage* an_event, BHandler* handler); 371 void do_menu_event(BMessage* an_event); 372 //void do_draw_views(); 373 virtual BMessage *ConvertToMessage(void* raw, int32 code); // HUGE function - it converts PortLink messages into BMessages 374 //_cmd_key_ *allocShortcut(uint32 key, uint32 modifiers); 375 //_cmd_key_ *FindShortcut(uint32 key, uint32 modifiers); 376 void AddShortcut(uint32 key, // !!! - and menu shortcuts to list when a menu is added 377 uint32 modifiers, 378 BMenuItem* item); 379 //void post_message(BMessage* message); 380 //void SetLocalTitle(const char* new_title); 381 //void enable_pulsing(bool enable); 382 BHandler *determine_target(BMessage* msg, BHandler* target, bool pref); 383 //void kb_navigate(); 384 //void navigate_to_next(int32 direction, bool group = false); 385 //void set_focus(BView* focus, bool notify_input_server); // what does notify_input_server mean??? why??? 386 bool InUpdate(); 387 void DequeueAll(); 388 //bool find_token_and_handler(BMessage* msg, int32* token, BHandler* *handler); 389 window_type composeType(window_look look, // changed from: compose_type(...) 390 window_feel feel) const; 391 void decomposeType(window_type type, // changed from: decompose_type(...) 392 window_look* look, 393 window_feel* feel) const; 394 395 void SetIsFilePanel(bool yes); 396 bool IsFilePanel() const; 397 // OBOS BWindow's addon functions 398 uint32 WindowLookToInteger(window_look wl); 399 uint32 WindowFeelToInteger(window_feel wf); 400 void BuildTopView(); 401 void stopConnection(); 402 void setFocus(BView *focusView, bool notifyIputServer=false); 403 404 bool handleKeyDown( uint32 key, uint32 modifiers); 405 406 // message: B_MOUSE_UP, B_MOUSE_DOWN, B_MOUSE_MOVED 407 void sendMessageUsingEventMask( int32 message, BPoint where ); 408 BView* sendMessageUsingEventMask2( BView* aView, int32 message, BPoint where ); 409 void sendPulse( BView* ); 410 int32 findShortcut(uint32 key, uint32 modifiers); 411 bool findHandler( BView* start, BHandler* handler ); 412 BView* findView(BView* aView, const char* viewName) const; 413 BView* findView(BView* aView, BPoint point) const; 414 BView* findView(BView* aView, int32 token); 415 416 BView* findNextView( BView *focus, uint32 flags); 417 BView* findPrevView( BView *focus, uint32 flags); 418 BView* findLastChild(BView *parent); 419 bool handleKeyDown( int32 raw_char, uint32 modifiers); 420 void handleActivation( bool active ); 421 void activateView( BView *aView, bool active ); 422 423 void drawAllViews(BView* aView); 424 void drawView(BView* aView, BRect area); 425 426 // Debug 427 void PrintToStream() const; 428 // END: OBOS addon functions 429 430 // 3 deprecated calls 431 //void AddFloater(BWindow* a_floating_window); 432 //void RemoveFloater(BWindow* a_floating_window); 433 //window_type WindowType() const; 434 435 char *fTitle; // used 436 int32 server_token; 437 bool fInTransaction; // used // changed from: char fInUpdate; 438 bool fActive; // used // changed from: char f_active; 439 short fShowLevel; // used 440 uint32 fFlags; // used 441 442 port_id send_port; // used 443 port_id receive_port; // used 444 445 BView *top_view; // used 446 BView *fFocus; // used 447 BView *fLastMouseMovedView; // used 448 BSession *session; // used 449 BMenuBar *fKeyMenuBar; // used 450 BButton *fDefaultButton; // used 451 BList accelList; // used 452 int32 fTopViewToken; // // changed from: int32 top_view_token; 453 bool fPulseEnabled; // used // changed from: bool pulse_enabled; 454 bool fViewsNeedPulse; 455 bool fIsFilePanel; // used 456 bool fMaskActivated; 457 bigtime_t fPulseRate; // used // changed from: bigtime_t pulse_rate; 458 bool fWaitingForMenu; 459 bool fMinimized; // used // changed from: bool fOffscreen; 460 sem_id fMenuSem; 461 float fMaxZoomHeight; // used // changed from: float fMaxZoomH; 462 float fMaxZoomWidth; // used // changed from: float fMaxZoomV; 463 float fMinWindHeight; // used // changed from: float fMinWindH; 464 float fMinWindWidth; // used // changed from: float fMinWindV; 465 float fMaxWindHeight; // used // changed from: float fMaxWindH; 466 float fMaxWindWidth; // used // changed from: float fMaxWindV; 467 BRect fFrame; // used 468 window_look fLook; // used 469 ViewAttr *fCurDrawViewState; 470 window_feel fFeel; // used 471 int32 fLastViewToken; 472 PortLink *fServerLink; // changed from: _CEventPort_* fEventPort; 473 BMessageRunner *fPulseRunner; // used 474 BRect fCurrentFrame; 475 476 uint32 _reserved[2]; // was 8 477 #if !_PR3_COMPATIBLE_ 478 uint32 _more_reserved[4]; 479 #endif 480 }; 481 482 // inline definitions ---------------------------------------------------------- 483 inline void BWindow::Close() 484 { 485 Quit(); 486 } 487 //------------------------------------------------------------------------------ 488 489 #endif // _WINDOW_H 490 491 /* 492 * $Log $ 493 * 494 * $Id $ 495 * 496 */ 497 498