1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2001-2005, Haiku 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 (adioanca@gmail.com) 24 // Description: BWindow is the base class for all windows (graphic areas 25 // displayed on-screen). 26 //------------------------------------------------------------------------------ 27 #ifndef _WINDOW_H 28 #define _WINDOW_H 29 30 #include <BeBuild.h> 31 #include <InterfaceDefs.h> 32 #include <List.h> 33 #include <Looper.h> 34 #include <Rect.h> 35 #include <StorageDefs.h> 36 #include <View.h> 37 38 namespace BPrivate { 39 class PortLink; 40 }; 41 42 43 // window definitions ---------------------------------------------------------- 44 45 enum window_type { 46 B_UNTYPED_WINDOW = 0, 47 B_TITLED_WINDOW = 1, 48 B_MODAL_WINDOW = 3, 49 B_DOCUMENT_WINDOW = 11, 50 B_BORDERED_WINDOW = 20, 51 B_FLOATING_WINDOW = 21 52 }; 53 54 //---------------------------------------------------------------- 55 56 enum window_look { 57 B_BORDERED_WINDOW_LOOK = 20, 58 B_NO_BORDER_WINDOW_LOOK = 19, 59 B_TITLED_WINDOW_LOOK = 1, 60 B_DOCUMENT_WINDOW_LOOK = 11, 61 B_MODAL_WINDOW_LOOK = 3, 62 B_FLOATING_WINDOW_LOOK = 7 63 }; 64 65 //---------------------------------------------------------------- 66 67 enum window_feel { 68 B_NORMAL_WINDOW_FEEL = 0, 69 B_MODAL_SUBSET_WINDOW_FEEL = 2, 70 B_MODAL_APP_WINDOW_FEEL = 1, 71 B_MODAL_ALL_WINDOW_FEEL = 3, 72 B_FLOATING_SUBSET_WINDOW_FEEL = 5, 73 B_FLOATING_APP_WINDOW_FEEL = 4, 74 B_FLOATING_ALL_WINDOW_FEEL = 6 75 }; 76 77 //---------------------------------------------------------------- 78 79 enum window_alignment { 80 B_BYTE_ALIGNMENT = 0, 81 B_PIXEL_ALIGNMENT = 1 82 }; 83 84 //---------------------------------------------------------------- 85 86 enum { 87 B_NOT_MOVABLE = 0x00000001, 88 B_NOT_CLOSABLE = 0x00000020, 89 B_NOT_ZOOMABLE = 0x00000040, 90 B_NOT_MINIMIZABLE = 0x00004000, 91 B_NOT_RESIZABLE = 0x00000002, 92 B_NOT_H_RESIZABLE = 0x00000004, 93 B_NOT_V_RESIZABLE = 0x00000008, 94 B_AVOID_FRONT = 0x00000080, 95 B_AVOID_FOCUS = 0x00002000, 96 B_WILL_ACCEPT_FIRST_CLICK = 0x00000010, 97 B_OUTLINE_RESIZE = 0x00001000, 98 B_NO_WORKSPACE_ACTIVATION = 0x00000100, 99 B_NOT_ANCHORED_ON_ACTIVATE = 0x00020000, 100 B_ASYNCHRONOUS_CONTROLS = 0x00080000, 101 B_QUIT_ON_WINDOW_CLOSE = 0x00100000 102 }; 103 104 #define B_CURRENT_WORKSPACE 0 105 #define B_ALL_WORKSPACES 0xffffffff 106 107 //---------------------------------------------------------------- 108 109 class BButton; 110 class BMenuBar; 111 class BMenuItem; 112 class BMessage; 113 class BMessageRunner; 114 class BMessenger; 115 class BView; 116 117 struct message; 118 struct _cmd_key_; 119 class ViewAttr; 120 121 // BWindow class --------------------------------------------------------------- 122 class BWindow : public BLooper { 123 public: 124 BWindow(BRect frame, const char* title, 125 window_type type, uint32 flags, 126 uint32 workspace = B_CURRENT_WORKSPACE); 127 BWindow(BRect frame, const char* title, 128 window_look look, window_feel feel, 129 uint32 flags, 130 uint32 workspace = B_CURRENT_WORKSPACE); 131 virtual ~BWindow(); 132 133 BWindow(BMessage* data); 134 static BArchivable *Instantiate(BMessage* data); 135 virtual status_t Archive(BMessage* data, bool deep = true) const; 136 137 virtual void Quit(); 138 void Close() { Quit(); } 139 140 void AddChild(BView* child, BView* before = NULL); 141 bool RemoveChild(BView* child); 142 int32 CountChildren() const; 143 BView *ChildAt(int32 index) const; 144 145 virtual void DispatchMessage(BMessage* message, BHandler* handler); 146 virtual void MessageReceived(BMessage* message); 147 virtual void FrameMoved(BPoint new_position); 148 virtual void WorkspacesChanged(uint32 old_ws, uint32 new_ws); 149 virtual void WorkspaceActivated(int32 ws, bool state); 150 virtual void FrameResized(float new_width, float new_height); 151 virtual void Minimize(bool minimize); 152 virtual void Zoom(BPoint origin, float width, float height); 153 void Zoom(); 154 void SetZoomLimits(float maxWidth, float maxHeight); 155 virtual void ScreenChanged(BRect screen_size, color_space depth); 156 void SetPulseRate(bigtime_t rate); 157 bigtime_t PulseRate() const; 158 void AddShortcut(uint32 key, uint32 modifiers, 159 BMessage *msg); 160 void AddShortcut(uint32 key, uint32 modifiers, 161 BMessage *msg, BHandler *target); 162 void RemoveShortcut(uint32 key, uint32 modifiers); 163 void SetDefaultButton(BButton* button); 164 BButton *DefaultButton() const; 165 virtual void MenusBeginning(); 166 virtual void MenusEnded(); 167 bool NeedsUpdate() const; 168 void UpdateIfNeeded(); 169 BView *FindView(const char *viewName) const; 170 BView *FindView(BPoint) const; 171 BView *CurrentFocus() const; 172 void Activate(bool = true); 173 virtual void WindowActivated(bool state); 174 175 void ConvertToScreen(BPoint* pt) const; 176 BPoint ConvertToScreen(BPoint pt) const; 177 void ConvertFromScreen(BPoint* pt) const; 178 BPoint ConvertFromScreen(BPoint pt) const; 179 void ConvertToScreen(BRect* rect) const; 180 BRect ConvertToScreen(BRect rect) const; 181 void ConvertFromScreen(BRect* rect) const; 182 BRect ConvertFromScreen(BRect rect) const; 183 184 void MoveBy(float dx, float dy); 185 void MoveTo(BPoint); 186 void MoveTo(float x, float y); 187 void ResizeBy(float dx, float dy); 188 void ResizeTo(float width, float height); 189 190 virtual void Show(); 191 virtual void Hide(); 192 bool IsHidden() const; 193 bool IsMinimized() const; 194 195 void Flush() const; 196 void Sync() const; 197 198 status_t SendBehind(const BWindow* window); 199 200 void DisableUpdates(); 201 void EnableUpdates(); 202 203 void BeginViewTransaction(); // referred as OpenViewTransaction() in BeBook 204 void EndViewTransaction(); // referred as CommitViewTransaction() in BeBook 205 206 BRect Bounds() const; 207 BRect Frame() const; 208 const char *Title() const; 209 void SetTitle(const char* title); 210 bool IsFront() const; 211 bool IsActive() const; 212 void SetKeyMenuBar(BMenuBar* bar); 213 BMenuBar *KeyMenuBar() const; 214 void SetSizeLimits(float minWidth, float maxWidth, 215 float minHeight, float maxHeight); 216 void GetSizeLimits(float *minWidth, float *maxWidth, 217 float *minHeight, float *maxHeight); 218 uint32 Workspaces() const; 219 void SetWorkspaces(uint32); 220 BView *LastMouseMovedView() const; 221 222 virtual BHandler *ResolveSpecifier(BMessage* msg, int32 index, 223 BMessage* specifier, int32 form, const char* property); 224 virtual status_t GetSupportedSuites(BMessage* data); 225 226 status_t AddToSubset(BWindow* window); 227 status_t RemoveFromSubset(BWindow* window); 228 229 virtual status_t Perform(perform_code d, void* arg); 230 231 status_t SetType(window_type type); 232 window_type Type() const; 233 234 status_t SetLook(window_look look); 235 window_look Look() const; 236 237 status_t SetFeel(window_feel feel); 238 window_feel Feel() const; 239 240 status_t SetFlags(uint32); 241 uint32 Flags() const; 242 243 bool IsModal() const; 244 bool IsFloating() const; 245 246 status_t SetWindowAlignment(window_alignment mode, int32 h, 247 int32 hOffset = 0, int32 width = 0, int32 widthOffset = 0, 248 int32 v = 0, int32 vOffset = 0, int32 height = 0, 249 int32 heightOffset = 0); 250 status_t GetWindowAlignment(window_alignment* mode = NULL, 251 int32* h = NULL, int32* hOffset = NULL, 252 int32* width = NULL, int32* widthOffset = NULL, 253 int32* v = NULL, int32* vOffset = NULL, 254 int32* height = NULL, int32* heightOffset = NULL) const; 255 256 virtual bool QuitRequested(); 257 virtual thread_id Run(); 258 259 // Private or reserved --------------------------------------------------------- 260 private: 261 typedef BLooper inherited; 262 class Shortcut; 263 264 friend class BApplication; 265 friend class BBitmap; 266 friend class BScrollBar; 267 friend class BView; 268 friend class BMenuItem; 269 friend class BWindowScreen; 270 friend class BDirectWindow; 271 friend class BFilePanel; 272 friend class BHandler; 273 friend class _BEventMask; 274 friend void _set_menu_sem_(BWindow* w, sem_id sem); 275 friend status_t _safe_get_server_token_(const BLooper* , int32* ); 276 277 virtual void _ReservedWindow1(); 278 virtual void _ReservedWindow2(); 279 virtual void _ReservedWindow3(); 280 virtual void _ReservedWindow4(); 281 virtual void _ReservedWindow5(); 282 virtual void _ReservedWindow6(); 283 virtual void _ReservedWindow7(); 284 virtual void _ReservedWindow8(); 285 286 BWindow(); 287 BWindow(BWindow&); 288 BWindow &operator=(BWindow&); 289 290 BWindow(BRect frame, int32 bitmapToken); 291 void _InitData(BRect frame, const char* title, 292 window_look look, window_feel feel, 293 uint32 flags, uint32 workspace, 294 int32 bitmapToken = -1); 295 status_t ArchiveChildren(BMessage* data, bool deep) const; 296 status_t UnarchiveChildren(BMessage* data); 297 void BitmapClose(); // to be implemented 298 virtual void task_looper(); // thread function - it's here where app_server messages are received 299 /* void start_drag( BMessage* msg, 300 int32 token, 301 BPoint offset, 302 BRect track_rect, 303 BHandler* reply_to); 304 void start_drag( BMessage* msg, 305 int32 token, 306 BPoint offset, 307 int32 bitmap_token, 308 drawing_mode dragMode, 309 BHandler* reply_to); 310 */ 311 void prepareView(BView* aView); 312 void attachView(BView* aView); 313 void detachView(BView* aView); 314 //int32 get_server_token() const; 315 BMessage *extract_drop(BMessage* an_event, BHandler* *target); 316 //void movesize(uint32 opcode, float h, float v); 317 318 //int32 MessagesWaiting(); 319 320 void handle_activate(BMessage* an_event); 321 //void do_view_frame(BMessage* an_event); 322 //void do_value_change(BMessage* an_event, BHandler* handler); 323 //void do_mouse_down(BMessage* an_event, BView* target); 324 //void do_mouse_moved(BMessage* an_event, BView* target); 325 //void do_key_down(BMessage* an_event, BHandler* handler); 326 //void do_key_up(BMessage* an_event, BHandler* handler); 327 void do_menu_event(BMessage* an_event); 328 //void do_draw_views(); 329 virtual BMessage *ConvertToMessage(void* raw, int32 code); 330 //_cmd_key_ *allocShortcut(uint32 key, uint32 modifiers); 331 //_cmd_key_ *FindShortcut(uint32 key, uint32 modifiers); 332 void AddShortcut(uint32 key, // !!! - and menu shortcuts to list when a menu is added 333 uint32 modifiers, 334 BMenuItem* item); 335 //void post_message(BMessage* message); 336 //void SetLocalTitle(const char* new_title); 337 //void enable_pulsing(bool enable); 338 BHandler *_DetermineTarget(BMessage* message, BHandler* target); 339 //void kb_navigate(); 340 //void navigate_to_next(int32 direction, bool group = false); 341 //void set_focus(BView* focus, bool notify_input_server); // what does notify_input_server mean??? why??? 342 bool InUpdate(); 343 void DequeueAll(); 344 //bool find_token_and_handler(BMessage* msg, int32* token, BHandler* *handler); 345 window_type _ComposeType(window_look look, 346 window_feel feel) const; 347 void _DecomposeType(window_type type, 348 window_look* look, 349 window_feel* feel) const; 350 351 void SetIsFilePanel(bool yes); 352 bool IsFilePanel() const; 353 354 void BuildTopView(); 355 void setFocus(BView *focusView, bool notifyIputServer = false); 356 357 Shortcut* _FindShortcut(uint32 key, uint32 modifiers); 358 bool findHandler(BView* start, BHandler* handler); 359 BView* findView(BView* aView, const char* viewName) const; 360 BView* findView(BView* aView, BPoint point) const; 361 BView* findView(BView* aView, int32 token); 362 BView* findLastChild(BView *parent); 363 364 BView* _FindNextNavigable(BView *focus, uint32 flags); 365 BView* _FindPreviousNavigable(BView *focus, uint32 flags); 366 bool _HandleKeyDown(char key, uint32 modifiers); 367 void _KeyboardNavigation(); 368 void handleActivation(bool active); 369 370 void drawAllViews(BView* view); 371 void DoUpdate(BView* view, BRect& area); 372 373 // Debug 374 void PrintToStream() const; 375 376 // 3 deprecated calls 377 //void AddFloater(BWindow* a_floating_window); 378 //void RemoveFloater(BWindow* a_floating_window); 379 //window_type WindowType() const; 380 381 private: 382 char *fTitle; 383 int32 server_token; // not yet used 384 bool fInTransaction; 385 bool fActive; 386 short fShowLevel; 387 uint32 fFlags; 388 389 uint32 _unused0[2]; 390 BView *fTopView; 391 BView *fFocus; 392 BView *fLastMouseMovedView; 393 uint32 _unused1; 394 BMenuBar *fKeyMenuBar; 395 BButton *fDefaultButton; 396 BList fShortcuts; 397 int32 fTopViewToken; 398 bool fPulseEnabled; 399 bool fViewsNeedPulse; // not yet used 400 bool fIsFilePanel; 401 bool fMaskActivated; 402 bigtime_t fPulseRate; 403 bool fWaitingForMenu; 404 bool fMinimized; 405 sem_id fMenuSem; 406 float fMaxZoomHeight; 407 float fMaxZoomWidth; 408 float fMinHeight; 409 float fMinWidth; 410 float fMaxHeight; 411 float fMaxWidth; 412 BRect fFrame; 413 window_look fLook; 414 ViewAttr *fCurDrawViewState; // not yet used 415 window_feel fFeel; 416 int32 fLastViewToken; 417 BPrivate::PortLink *fLink; 418 BMessageRunner *fPulseRunner; 419 BRect fCurrentFrame; // not yet used 420 421 uint32 _reserved[2]; // was 8 422 #if !_PR3_COMPATIBLE_ 423 uint32 _more_reserved[4]; 424 #endif 425 }; 426 427 #endif // _WINDOW_H 428