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