1 /* 2 * Copyright 2001-2006, 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 }; 85 86 #define B_CURRENT_WORKSPACE 0 87 #define B_ALL_WORKSPACES 0xffffffff 88 89 //---------------------------------------------------------------- 90 91 class BWindow : public BLooper { 92 public: 93 BWindow(BRect frame, const char* title, 94 window_type type, uint32 flags, 95 uint32 workspace = B_CURRENT_WORKSPACE); 96 BWindow(BRect frame, const char* title, 97 window_look look, window_feel feel, 98 uint32 flags, 99 uint32 workspace = B_CURRENT_WORKSPACE); 100 virtual ~BWindow(); 101 102 BWindow(BMessage* data); 103 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 new_position); 119 virtual void WorkspacesChanged(uint32 oldWorkspaces, 120 uint32 newWorkspaces); 121 virtual void WorkspaceActivated(int32 workspace, 122 bool state); 123 virtual void FrameResized(float newWidth, float newHeight); 124 virtual void Minimize(bool minimize); 125 virtual void Zoom(BPoint origin, float width, float height); 126 void Zoom(); 127 void SetZoomLimits(float maxWidth, float maxHeight); 128 virtual void ScreenChanged(BRect screenSize, 129 color_space format); 130 131 void SetPulseRate(bigtime_t rate); 132 bigtime_t PulseRate() const; 133 134 void AddShortcut(uint32 key, uint32 modifiers, 135 BMessage *message); 136 void AddShortcut(uint32 key, uint32 modifiers, 137 BMessage *message, 138 BHandler *target); 139 void RemoveShortcut(uint32 key, uint32 modifiers); 140 141 void SetDefaultButton(BButton* button); 142 BButton* DefaultButton() const; 143 144 virtual void MenusBeginning(); 145 virtual void MenusEnded(); 146 147 bool NeedsUpdate() const; 148 void UpdateIfNeeded(); 149 150 BView* FindView(const char* viewName) const; 151 BView* FindView(BPoint) const; 152 BView* CurrentFocus() const; 153 154 void Activate(bool = true); 155 virtual void WindowActivated(bool state); 156 157 void ConvertToScreen(BPoint* point) const; 158 BPoint ConvertToScreen(BPoint point) const; 159 void ConvertFromScreen(BPoint* point) const; 160 BPoint ConvertFromScreen(BPoint point) const; 161 void ConvertToScreen(BRect* rect) const; 162 BRect ConvertToScreen(BRect rect) const; 163 void ConvertFromScreen(BRect* rect) const; 164 BRect ConvertFromScreen(BRect rect) const; 165 166 void MoveBy(float dx, float dy); 167 void MoveTo(BPoint); 168 void MoveTo(float x, float y); 169 void ResizeBy(float dx, float dy); 170 void ResizeTo(float width, float height); 171 172 virtual void Show(); 173 virtual void Hide(); 174 bool IsHidden() const; 175 bool IsMinimized() const; 176 177 void Flush() const; 178 void Sync() const; 179 180 status_t SendBehind(const BWindow* window); 181 182 void DisableUpdates(); 183 void EnableUpdates(); 184 185 void BeginViewTransaction(); 186 // referred as OpenViewTransaction() in BeBook 187 void EndViewTransaction(); 188 // referred as CommitViewTransaction() in BeBook 189 190 BRect Bounds() const; 191 BRect Frame() const; 192 const char* Title() const; 193 void SetTitle(const char* title); 194 bool IsFront() const; 195 bool IsActive() const; 196 197 void SetKeyMenuBar(BMenuBar* bar); 198 BMenuBar* KeyMenuBar() const; 199 200 void SetSizeLimits(float minWidth, float maxWidth, 201 float minHeight, float maxHeight); 202 void GetSizeLimits(float* minWidth, float* maxWidth, 203 float* minHeight, float* maxHeight); 204 205 status_t SetDecoratorSettings(const BMessage& settings); 206 status_t GetDecoratorSettings(BMessage* settings) const; 207 208 uint32 Workspaces() const; 209 void SetWorkspaces(uint32); 210 211 BView* LastMouseMovedView() const; 212 213 virtual BHandler* ResolveSpecifier(BMessage* message, int32 index, 214 BMessage* specifier, int32 form, 215 const char* property); 216 virtual status_t GetSupportedSuites(BMessage* data); 217 218 status_t AddToSubset(BWindow* window); 219 status_t RemoveFromSubset(BWindow* window); 220 221 virtual status_t Perform(perform_code d, void* arg); 222 223 status_t SetType(window_type type); 224 window_type Type() const; 225 226 status_t SetLook(window_look look); 227 window_look Look() const; 228 229 status_t SetFeel(window_feel feel); 230 window_feel Feel() const; 231 232 status_t SetFlags(uint32); 233 uint32 Flags() const; 234 235 bool IsModal() const; 236 bool IsFloating() const; 237 238 status_t SetWindowAlignment(window_alignment mode, 239 int32 h, 240 int32 hOffset = 0, 241 int32 width = 0, 242 int32 widthOffset = 0, 243 int32 v = 0, 244 int32 vOffset = 0, 245 int32 height = 0, 246 int32 heightOffset = 0); 247 status_t GetWindowAlignment(window_alignment* mode = NULL, 248 int32* h = NULL, 249 int32* hOffset = NULL, 250 int32* width = NULL, 251 int32* widthOffset = NULL, 252 int32* v = NULL, 253 int32* vOffset = NULL, 254 int32* height = NULL, 255 int32* heightOffset = NULL) const; 256 257 virtual bool QuitRequested(); 258 virtual thread_id Run(); 259 260 private: 261 typedef BLooper inherited; 262 struct unpack_cookie; 263 class Shortcut; 264 265 friend class BApplication; 266 friend class BBitmap; 267 friend class BScrollBar; 268 friend class BView; 269 friend class BMenuItem; 270 friend class BWindowScreen; 271 friend class BDirectWindow; 272 friend class BFilePanel; 273 friend class BHandler; 274 friend class _BEventMask; 275 friend void _set_menu_sem_(BWindow* w, sem_id sem); 276 friend status_t _safe_get_server_token_(const BLooper*, int32*); 277 278 virtual void _ReservedWindow1(); 279 virtual void _ReservedWindow2(); 280 virtual void _ReservedWindow3(); 281 virtual void _ReservedWindow4(); 282 virtual void _ReservedWindow5(); 283 virtual void _ReservedWindow6(); 284 virtual void _ReservedWindow7(); 285 virtual void _ReservedWindow8(); 286 287 BWindow(); 288 BWindow(BWindow&); 289 BWindow& operator=(BWindow&); 290 291 BWindow(BRect frame, int32 bitmapToken); 292 void _InitData(BRect frame, const char* title, 293 window_look look, window_feel feel, 294 uint32 flags, uint32 workspace, 295 int32 bitmapToken = -1); 296 297 void BitmapClose(); // to be implemented 298 virtual void task_looper(); 299 300 virtual BMessage* ConvertToMessage(void* raw, int32 code); 301 302 void AddShortcut(uint32 key, uint32 modifiers, 303 BMenuItem* item); 304 BHandler* _DetermineTarget(BMessage* message, 305 BHandler* target); 306 bool _UnpackMessage(unpack_cookie& state, 307 BMessage** _message, 308 BHandler** _target, 309 bool* _usePreferred); 310 void _SanitizeMessage(BMessage* message, 311 BHandler* target, 312 bool usePreferred); 313 314 bool InUpdate(); 315 void _DequeueAll(); 316 window_type _ComposeType(window_look look, 317 window_feel feel) const; 318 void _DecomposeType(window_type type, 319 window_look* look, 320 window_feel* feel) const; 321 322 void SetIsFilePanel(bool yes); 323 bool IsFilePanel() const; 324 325 void _CreateTopView(); 326 void _AdoptResize(); 327 void _SetFocus(BView* focusView, 328 bool notifyIputServer = false); 329 330 Shortcut* _FindShortcut(uint32 key, uint32 modifiers); 331 BView* _FindView(BView* view, BPoint point) const; 332 BView* _FindView(int32 token); 333 BView* _LastViewChild(BView* parent); 334 335 BView* _FindNextNavigable(BView *focus, uint32 flags); 336 BView* _FindPreviousNavigable(BView *focus, 337 uint32 flags); 338 bool _HandleKeyDown(char key, uint32 modifiers); 339 void _KeyboardNavigation(); 340 341 // Debug (TODO: to be removed) 342 void PrintToStream() const; 343 344 private: 345 char* fTitle; 346 int32 server_token; // not yet used 347 bool fInTransaction; 348 bool fActive; 349 short fShowLevel; 350 uint32 fFlags; 351 352 BView* fTopView; 353 BView* fFocus; 354 BView* fLastMouseMovedView; 355 uint32 _unused1; 356 BMenuBar* fKeyMenuBar; 357 BButton* fDefaultButton; 358 BList fShortcuts; 359 int32 fTopViewToken; 360 bool _unused2; // was fPulseEnabled 361 bool fViewsNeedPulse; // not yet used 362 bool fIsFilePanel; 363 bool fMaskActivated; 364 bigtime_t fPulseRate; 365 bool fWaitingForMenu; 366 bool fMinimized; 367 bool fNoQuitShortcut; 368 bool _unused3; 369 sem_id fMenuSem; 370 float fMaxZoomHeight; 371 float fMaxZoomWidth; 372 float fMinHeight; 373 float fMinWidth; 374 float fMaxHeight; 375 float fMaxWidth; 376 BRect fFrame; 377 window_look fLook; 378 window_feel fFeel; 379 int32 fLastViewToken; 380 BPrivate::PortLink* fLink; 381 BMessageRunner* fPulseRunner; 382 BRect fPreviousFrame; 383 384 uint32 _reserved[9]; 385 }; 386 387 #endif // _WINDOW_H 388