1 /* 2 * Copyright 2001-2011, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _WINDOW_H 6 #define _WINDOW_H 7 8 9 #include <Looper.h> 10 #include <StorageDefs.h> 11 #include <View.h> 12 13 14 class BButton; 15 class BMenuBar; 16 class BMenuItem; 17 class BMessage; 18 class BMessageRunner; 19 class BMessenger; 20 class BView; 21 22 namespace BPrivate { 23 class PortLink; 24 }; 25 26 27 enum window_type { 28 B_UNTYPED_WINDOW = 0, 29 B_TITLED_WINDOW = 1, 30 B_MODAL_WINDOW = 3, 31 B_DOCUMENT_WINDOW = 11, 32 B_BORDERED_WINDOW = 20, 33 B_FLOATING_WINDOW = 21 34 }; 35 36 enum window_look { 37 B_BORDERED_WINDOW_LOOK = 20, 38 B_NO_BORDER_WINDOW_LOOK = 19, 39 B_TITLED_WINDOW_LOOK = 1, 40 B_DOCUMENT_WINDOW_LOOK = 11, 41 B_MODAL_WINDOW_LOOK = 3, 42 B_FLOATING_WINDOW_LOOK = 7 43 }; 44 45 enum window_feel { 46 B_NORMAL_WINDOW_FEEL = 0, 47 B_MODAL_SUBSET_WINDOW_FEEL = 2, 48 B_MODAL_APP_WINDOW_FEEL = 1, 49 B_MODAL_ALL_WINDOW_FEEL = 3, 50 B_FLOATING_SUBSET_WINDOW_FEEL = 5, 51 B_FLOATING_APP_WINDOW_FEEL = 4, 52 B_FLOATING_ALL_WINDOW_FEEL = 6 53 }; 54 55 enum window_alignment { 56 B_BYTE_ALIGNMENT = 0, 57 B_PIXEL_ALIGNMENT = 1 58 }; 59 60 // window flags 61 enum { 62 B_NOT_MOVABLE = 0x00000001, 63 B_NOT_CLOSABLE = 0x00000020, 64 B_NOT_ZOOMABLE = 0x00000040, 65 B_NOT_MINIMIZABLE = 0x00004000, 66 B_NOT_RESIZABLE = 0x00000002, 67 B_NOT_H_RESIZABLE = 0x00000004, 68 B_NOT_V_RESIZABLE = 0x00000008, 69 B_AVOID_FRONT = 0x00000080, 70 B_AVOID_FOCUS = 0x00002000, 71 B_WILL_ACCEPT_FIRST_CLICK = 0x00000010, 72 B_OUTLINE_RESIZE = 0x00001000, 73 B_NO_WORKSPACE_ACTIVATION = 0x00000100, 74 B_NOT_ANCHORED_ON_ACTIVATE = 0x00020000, 75 B_ASYNCHRONOUS_CONTROLS = 0x00080000, 76 B_QUIT_ON_WINDOW_CLOSE = 0x00100000, 77 B_SAME_POSITION_IN_ALL_WORKSPACES = 0x00200000, 78 B_AUTO_UPDATE_SIZE_LIMITS = 0x00400000, 79 B_CLOSE_ON_ESCAPE = 0x00800000, 80 B_NO_SERVER_SIDE_WINDOW_MODIFIERS = 0x00000200 81 }; 82 83 #define B_CURRENT_WORKSPACE 0 84 #define B_ALL_WORKSPACES 0xffffffff 85 86 87 class BWindow : public BLooper { 88 public: 89 BWindow(BRect frame, const char* title, 90 window_type type, uint32 flags, 91 uint32 workspace = B_CURRENT_WORKSPACE); 92 BWindow(BRect frame, const char* title, 93 window_look look, window_feel feel, 94 uint32 flags, uint32 workspace 95 = B_CURRENT_WORKSPACE); 96 virtual ~BWindow(); 97 98 BWindow(BMessage* archive); 99 static BArchivable* Instantiate(BMessage* archive); 100 virtual status_t Archive(BMessage* archive, 101 bool deep = true) const; 102 103 virtual void Quit(); 104 void Close() { Quit(); } 105 106 void AddChild(BView* child, BView* before = NULL); 107 void AddChild(BLayoutItem* child); 108 bool RemoveChild(BView* child); 109 int32 CountChildren() const; 110 BView* ChildAt(int32 index) const; 111 112 virtual void DispatchMessage(BMessage* message, 113 BHandler* handler); 114 virtual void MessageReceived(BMessage* message); 115 virtual void FrameMoved(BPoint newPosition); 116 virtual void WorkspacesChanged(uint32 oldWorkspaces, 117 uint32 newWorkspaces); 118 virtual void WorkspaceActivated(int32 workspace, 119 bool state); 120 virtual void FrameResized(float newWidth, float newHeight); 121 virtual void Minimize(bool minimize); 122 virtual void Zoom(BPoint origin, float width, float height); 123 void Zoom(); 124 void SetZoomLimits(float maxWidth, float maxHeight); 125 virtual void ScreenChanged(BRect screenSize, 126 color_space depth); 127 128 void SetPulseRate(bigtime_t rate); 129 bigtime_t PulseRate() const; 130 131 void AddShortcut(uint32 key, uint32 modifiers, 132 BMessage* message); 133 void AddShortcut(uint32 key, uint32 modifiers, 134 BMessage* message, BHandler* target); 135 bool HasShortcut(uint32 key, uint32 modifiers); 136 void RemoveShortcut(uint32 key, uint32 modifiers); 137 138 void SetDefaultButton(BButton* button); 139 BButton* DefaultButton() const; 140 141 virtual void MenusBeginning(); 142 virtual void MenusEnded(); 143 144 bool NeedsUpdate() const; 145 void UpdateIfNeeded(); 146 147 BView* FindView(const char* viewName) const; 148 BView* FindView(BPoint) const; 149 BView* CurrentFocus() const; 150 151 void Activate(bool = true); 152 virtual void WindowActivated(bool focus); 153 154 void ConvertToScreen(BPoint* point) const; 155 BPoint ConvertToScreen(BPoint point) const; 156 void ConvertFromScreen(BPoint* point) const; 157 BPoint ConvertFromScreen(BPoint point) const; 158 void ConvertToScreen(BRect* rect) const; 159 BRect ConvertToScreen(BRect rect) const; 160 void ConvertFromScreen(BRect* rect) const; 161 BRect ConvertFromScreen(BRect rect) const; 162 163 void MoveBy(float dx, float dy); 164 void MoveTo(BPoint); 165 void MoveTo(float x, float y); 166 void ResizeBy(float dx, float dy); 167 void ResizeTo(float width, float height); 168 169 void CenterIn(const BRect& rect); 170 void CenterOnScreen(); 171 void CenterOnScreen(screen_id id); 172 173 virtual void Show(); 174 virtual void Hide(); 175 bool IsHidden() const; 176 bool IsMinimized() const; 177 178 void Flush() const; 179 void Sync() const; 180 181 status_t SendBehind(const BWindow* window); 182 183 void DisableUpdates(); 184 void EnableUpdates(); 185 186 void BeginViewTransaction(); 187 // referred as OpenViewTransaction() 188 // in BeBook 189 void EndViewTransaction(); 190 // referred as CommitViewTransaction() 191 // in BeBook 192 bool InViewTransaction() const; 193 194 BRect Bounds() const; 195 BRect Frame() const; 196 BRect DecoratorFrame() const; 197 BSize Size() const; 198 const char* Title() const; 199 void SetTitle(const char* title); 200 bool IsFront() const; 201 bool IsActive() const; 202 203 void SetKeyMenuBar(BMenuBar* bar); 204 BMenuBar* KeyMenuBar() const; 205 206 void SetSizeLimits(float minWidth, float maxWidth, 207 float minHeight, float maxHeight); 208 void GetSizeLimits(float* minWidth, float* maxWidth, 209 float* minHeight, float* maxHeight); 210 void UpdateSizeLimits(); 211 212 status_t SetDecoratorSettings(const BMessage& settings); 213 status_t GetDecoratorSettings(BMessage* settings) const; 214 215 uint32 Workspaces() const; 216 void SetWorkspaces(uint32); 217 218 BView* LastMouseMovedView() const; 219 220 virtual BHandler* ResolveSpecifier(BMessage* message, 221 int32 index, BMessage* specifier, 222 int32 what, const char* property); 223 virtual status_t GetSupportedSuites(BMessage* data); 224 225 status_t AddToSubset(BWindow* window); 226 status_t RemoveFromSubset(BWindow* window); 227 228 virtual status_t Perform(perform_code code, void* data); 229 230 status_t SetType(window_type type); 231 window_type Type() const; 232 233 status_t SetLook(window_look look); 234 window_look Look() const; 235 236 status_t SetFeel(window_feel feel); 237 window_feel Feel() const; 238 239 status_t SetFlags(uint32); 240 uint32 Flags() const; 241 242 bool IsModal() const; 243 bool IsFloating() const; 244 245 status_t SetWindowAlignment(window_alignment mode, 246 int32 h, int32 hOffset = 0, 247 int32 width = 0, int32 widthOffset = 0, 248 int32 v = 0, int32 vOffset = 0, 249 int32 height = 0, int32 heightOffset = 0); 250 status_t GetWindowAlignment( 251 window_alignment* mode = NULL, 252 int32* h = NULL, int32* hOffset = NULL, 253 int32* width = NULL, 254 int32* widthOffset = NULL, 255 int32* v = NULL, int32* vOffset = NULL, 256 int32* height = NULL, 257 int32* heightOffset = NULL) const; 258 259 virtual bool QuitRequested(); 260 virtual thread_id Run(); 261 262 virtual void SetLayout(BLayout* layout); 263 BLayout* GetLayout() const; 264 265 void InvalidateLayout(bool descendants = false); 266 void Layout(bool force); 267 268 private: 269 // FBC padding and forbidden methods 270 virtual void _ReservedWindow2(); 271 virtual void _ReservedWindow3(); 272 virtual void _ReservedWindow4(); 273 virtual void _ReservedWindow5(); 274 virtual void _ReservedWindow6(); 275 virtual void _ReservedWindow7(); 276 virtual void _ReservedWindow8(); 277 278 BWindow(); 279 BWindow(BWindow&); 280 BWindow& operator=(BWindow&); 281 282 private: 283 typedef BLooper inherited; 284 struct unpack_cookie; 285 class Shortcut; 286 287 friend class BAlert; 288 friend class BApplication; 289 friend class BBitmap; 290 friend class BView; 291 friend class BMenuItem; 292 friend class BWindowScreen; 293 friend class BDirectWindow; 294 friend class BFilePanel; 295 friend class BWindowStack; 296 297 friend void _set_menu_sem_(BWindow* w, sem_id sem); 298 friend status_t _safe_get_server_token_(const BLooper*, int32*); 299 300 BWindow(BRect frame, int32 bitmapToken); 301 void _InitData(BRect frame, const char* title, 302 window_look look, window_feel feel, 303 uint32 flags, uint32 workspace, 304 int32 bitmapToken = -1); 305 306 virtual void task_looper(); 307 308 BPoint AlertPosition(const BRect& frame); 309 virtual BMessage* ConvertToMessage(void* raw, int32 code); 310 311 void AddShortcut(uint32 key, uint32 modifiers, 312 BMenuItem* item); 313 BHandler* _DetermineTarget(BMessage* message, 314 BHandler* target); 315 bool _IsFocusMessage(BMessage* message); 316 bool _UnpackMessage(unpack_cookie& state, 317 BMessage** _message, BHandler** _target, 318 bool* _usePreferred); 319 void _SanitizeMessage(BMessage* message, 320 BHandler* target, bool usePreferred); 321 bool _StealMouseMessage(BMessage* message, 322 bool& deleteMessage); 323 uint32 _TransitForMouseMoved(BView* view, 324 BView* viewUnderMouse) const; 325 326 bool InUpdate(); 327 void _DequeueAll(); 328 window_type _ComposeType(window_look look, 329 window_feel feel) const; 330 void _DecomposeType(window_type type, 331 window_look* look, 332 window_feel* feel) const; 333 334 void SetIsFilePanel(bool yes); 335 bool IsFilePanel() const; 336 337 void _CreateTopView(); 338 void _AdoptResize(); 339 void _SetFocus(BView* focusView, 340 bool notifyIputServer = false); 341 void _SetName(const char* title); 342 343 Shortcut* _FindShortcut(uint32 key, uint32 modifiers); 344 BView* _FindView(BView* view, BPoint point) const; 345 BView* _FindView(int32 token); 346 BView* _LastViewChild(BView* parent); 347 348 BView* _FindNextNavigable(BView* focus, uint32 flags); 349 BView* _FindPreviousNavigable(BView* focus, 350 uint32 flags); 351 void _Switcher(int32 rawKey, uint32 modifiers, 352 bool repeat); 353 bool _HandleKeyDown(BMessage* event); 354 bool _HandleUnmappedKeyDown(BMessage* event); 355 void _KeyboardNavigation(); 356 357 void _GetDecoratorSize(float* _borderWidth, 358 float* _tabHeight) const; 359 void _SendShowOrHideMessage(); 360 361 private: 362 char* fTitle; 363 int32 _unused0; 364 bool fInTransaction; 365 bool fActive; 366 short fShowLevel; 367 uint32 fFlags; 368 369 BView* fTopView; 370 BView* fFocus; 371 BView* fLastMouseMovedView; 372 uint32 _unused1; 373 BMenuBar* fKeyMenuBar; 374 BButton* fDefaultButton; 375 BList fShortcuts; 376 int32 fTopViewToken; 377 bool fUpdateRequested; 378 bool fOffscreen; 379 bool fIsFilePanel; 380 bool _unused4; 381 bigtime_t fPulseRate; 382 bool _unused5; 383 bool fMinimized; 384 bool fNoQuitShortcut; 385 bool _unused6; 386 sem_id fMenuSem; 387 float fMaxZoomHeight; 388 float fMaxZoomWidth; 389 float fMinHeight; 390 float fMinWidth; 391 float fMaxHeight; 392 float fMaxWidth; 393 BRect fFrame; 394 window_look fLook; 395 window_feel fFeel; 396 int32 fLastViewToken; 397 ::BPrivate::PortLink* fLink; 398 BMessageRunner* fPulseRunner; 399 BRect fPreviousFrame; 400 401 uint32 _reserved[9]; 402 }; 403 404 405 #endif // _WINDOW_H 406