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