From b30e90211eddde5fc96258dfaf8364f2fefd9695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Thu, 25 May 2006 12:01:28 +0000 Subject: [PATCH] added a way for BWindow to store and restore arbitrary decor settings, currently those include only the tab location git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17583 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/interface/Window.h | 439 +++++++++++++++------------ headers/private/app/ServerProtocol.h | 2 + src/kits/interface/Window.cpp | 115 +++++-- src/servers/app/Decorator.cpp | 15 + src/servers/app/Decorator.h | 4 + src/servers/app/DefaultDecorator.cpp | 27 +- src/servers/app/DefaultDecorator.h | 131 ++++---- src/servers/app/Desktop.cpp | 27 ++ src/servers/app/Desktop.h | 2 + src/servers/app/ServerWindow.cpp | 46 ++- src/servers/app/WindowLayer.cpp | 25 +- src/servers/app/WindowLayer.h | 4 + 12 files changed, 554 insertions(+), 283 deletions(-) diff --git a/headers/os/interface/Window.h b/headers/os/interface/Window.h index 885660ca53..3556d152eb 100644 --- a/headers/os/interface/Window.h +++ b/headers/os/interface/Window.h @@ -90,140 +90,172 @@ enum { class BWindow : public BLooper { public: - BWindow(BRect frame, const char* title, - window_type type, uint32 flags, - uint32 workspace = B_CURRENT_WORKSPACE); - BWindow(BRect frame, const char* title, - window_look look, window_feel feel, - uint32 flags, - uint32 workspace = B_CURRENT_WORKSPACE); - virtual ~BWindow(); + BWindow(BRect frame, const char* title, + window_type type, uint32 flags, + uint32 workspace = B_CURRENT_WORKSPACE); + BWindow(BRect frame, const char* title, + window_look look, window_feel feel, + uint32 flags, + uint32 workspace = B_CURRENT_WORKSPACE); + virtual ~BWindow(); - BWindow(BMessage* data); - static BArchivable *Instantiate(BMessage* data); - virtual status_t Archive(BMessage* data, bool deep = true) const; + BWindow(BMessage* data); - virtual void Quit(); - void Close() { Quit(); } + static BArchivable* Instantiate(BMessage* data); + virtual status_t Archive(BMessage* data, bool deep = true) const; - void AddChild(BView* child, BView* before = NULL); - bool RemoveChild(BView* child); - int32 CountChildren() const; - BView *ChildAt(int32 index) const; + virtual void Quit(); + void Close() { Quit(); } - virtual void DispatchMessage(BMessage* message, BHandler* handler); - virtual void MessageReceived(BMessage* message); - virtual void FrameMoved(BPoint new_position); - virtual void WorkspacesChanged(uint32 old_ws, uint32 new_ws); - virtual void WorkspaceActivated(int32 ws, bool state); - virtual void FrameResized(float new_width, float new_height); - virtual void Minimize(bool minimize); - virtual void Zoom(BPoint origin, float width, float height); - void Zoom(); - void SetZoomLimits(float maxWidth, float maxHeight); - virtual void ScreenChanged(BRect screen_size, color_space depth); - void SetPulseRate(bigtime_t rate); - bigtime_t PulseRate() const; - void AddShortcut(uint32 key, uint32 modifiers, - BMessage *msg); - void AddShortcut(uint32 key, uint32 modifiers, - BMessage *msg, BHandler *target); - void RemoveShortcut(uint32 key, uint32 modifiers); - void SetDefaultButton(BButton* button); - BButton *DefaultButton() const; - virtual void MenusBeginning(); - virtual void MenusEnded(); - bool NeedsUpdate() const; - void UpdateIfNeeded(); - BView *FindView(const char *viewName) const; - BView *FindView(BPoint) const; - BView *CurrentFocus() const; - void Activate(bool = true); - virtual void WindowActivated(bool state); + void AddChild(BView* child, BView* before = NULL); + bool RemoveChild(BView* child); + int32 CountChildren() const; + BView* ChildAt(int32 index) const; - void ConvertToScreen(BPoint* pt) const; - BPoint ConvertToScreen(BPoint pt) const; - void ConvertFromScreen(BPoint* pt) const; - BPoint ConvertFromScreen(BPoint pt) const; - void ConvertToScreen(BRect* rect) const; - BRect ConvertToScreen(BRect rect) const; - void ConvertFromScreen(BRect* rect) const; - BRect ConvertFromScreen(BRect rect) const; + virtual void DispatchMessage(BMessage* message, + BHandler* handler); + virtual void MessageReceived(BMessage* message); + virtual void FrameMoved(BPoint new_position); + virtual void WorkspacesChanged(uint32 oldWorkspaces, + uint32 newWorkspaces); + virtual void WorkspaceActivated(int32 workspace, + bool state); + virtual void FrameResized(float newWidth, float newHeight); + virtual void Minimize(bool minimize); + virtual void Zoom(BPoint origin, float width, float height); + void Zoom(); + void SetZoomLimits(float maxWidth, float maxHeight); + virtual void ScreenChanged(BRect screenSize, + color_space format); - void MoveBy(float dx, float dy); - void MoveTo(BPoint); - void MoveTo(float x, float y); - void ResizeBy(float dx, float dy); - void ResizeTo(float width, float height); + void SetPulseRate(bigtime_t rate); + bigtime_t PulseRate() const; - virtual void Show(); - virtual void Hide(); - bool IsHidden() const; - bool IsMinimized() const; + void AddShortcut(uint32 key, uint32 modifiers, + BMessage *message); + void AddShortcut(uint32 key, uint32 modifiers, + BMessage *message, + BHandler *target); + void RemoveShortcut(uint32 key, uint32 modifiers); - void Flush() const; - void Sync() const; + void SetDefaultButton(BButton* button); + BButton* DefaultButton() const; - status_t SendBehind(const BWindow* window); + virtual void MenusBeginning(); + virtual void MenusEnded(); - void DisableUpdates(); - void EnableUpdates(); + bool NeedsUpdate() const; + void UpdateIfNeeded(); - void BeginViewTransaction(); // referred as OpenViewTransaction() in BeBook - void EndViewTransaction(); // referred as CommitViewTransaction() in BeBook + BView* FindView(const char* viewName) const; + BView* FindView(BPoint) const; + BView* CurrentFocus() const; - BRect Bounds() const; - BRect Frame() const; - const char *Title() const; - void SetTitle(const char* title); - bool IsFront() const; - bool IsActive() const; - void SetKeyMenuBar(BMenuBar* bar); - BMenuBar *KeyMenuBar() const; - void SetSizeLimits(float minWidth, float maxWidth, - float minHeight, float maxHeight); - void GetSizeLimits(float *minWidth, float *maxWidth, - float *minHeight, float *maxHeight); - uint32 Workspaces() const; - void SetWorkspaces(uint32); - BView *LastMouseMovedView() const; + void Activate(bool = true); + virtual void WindowActivated(bool state); - virtual BHandler *ResolveSpecifier(BMessage* msg, int32 index, - BMessage* specifier, int32 form, const char* property); - virtual status_t GetSupportedSuites(BMessage* data); + void ConvertToScreen(BPoint* point) const; + BPoint ConvertToScreen(BPoint point) const; + void ConvertFromScreen(BPoint* point) const; + BPoint ConvertFromScreen(BPoint point) const; + void ConvertToScreen(BRect* rect) const; + BRect ConvertToScreen(BRect rect) const; + void ConvertFromScreen(BRect* rect) const; + BRect ConvertFromScreen(BRect rect) const; - status_t AddToSubset(BWindow* window); - status_t RemoveFromSubset(BWindow* window); + void MoveBy(float dx, float dy); + void MoveTo(BPoint); + void MoveTo(float x, float y); + void ResizeBy(float dx, float dy); + void ResizeTo(float width, float height); - virtual status_t Perform(perform_code d, void* arg); + virtual void Show(); + virtual void Hide(); + bool IsHidden() const; + bool IsMinimized() const; - status_t SetType(window_type type); - window_type Type() const; + void Flush() const; + void Sync() const; - status_t SetLook(window_look look); - window_look Look() const; + status_t SendBehind(const BWindow* window); - status_t SetFeel(window_feel feel); - window_feel Feel() const; + void DisableUpdates(); + void EnableUpdates(); - status_t SetFlags(uint32); - uint32 Flags() const; + void BeginViewTransaction(); + // referred as OpenViewTransaction() in BeBook + void EndViewTransaction(); + // referred as CommitViewTransaction() in BeBook - bool IsModal() const; - bool IsFloating() const; + BRect Bounds() const; + BRect Frame() const; + const char* Title() const; + void SetTitle(const char* title); + bool IsFront() const; + bool IsActive() const; - status_t SetWindowAlignment(window_alignment mode, int32 h, - int32 hOffset = 0, int32 width = 0, int32 widthOffset = 0, - int32 v = 0, int32 vOffset = 0, int32 height = 0, - int32 heightOffset = 0); - status_t GetWindowAlignment(window_alignment* mode = NULL, - int32* h = NULL, int32* hOffset = NULL, - int32* width = NULL, int32* widthOffset = NULL, - int32* v = NULL, int32* vOffset = NULL, - int32* height = NULL, int32* heightOffset = NULL) const; + void SetKeyMenuBar(BMenuBar* bar); + BMenuBar* KeyMenuBar() const; - virtual bool QuitRequested(); - virtual thread_id Run(); + void SetSizeLimits(float minWidth, float maxWidth, + float minHeight, float maxHeight); + void GetSizeLimits(float* minWidth, float* maxWidth, + float* minHeight, float* maxHeight); + + status_t SetDecoratorSettings(const BMessage& settings); + status_t GetDecoratorSettings(BMessage* settings); + + uint32 Workspaces() const; + void SetWorkspaces(uint32); + + BView* LastMouseMovedView() const; + + virtual BHandler* ResolveSpecifier(BMessage* message, int32 index, + BMessage* specifier, int32 form, + const char* property); + virtual status_t GetSupportedSuites(BMessage* data); + + status_t AddToSubset(BWindow* window); + status_t RemoveFromSubset(BWindow* window); + + virtual status_t Perform(perform_code d, void* arg); + + status_t SetType(window_type type); + window_type Type() const; + + status_t SetLook(window_look look); + window_look Look() const; + + status_t SetFeel(window_feel feel); + window_feel Feel() const; + + status_t SetFlags(uint32); + uint32 Flags() const; + + bool IsModal() const; + bool IsFloating() const; + + status_t SetWindowAlignment(window_alignment mode, + int32 h, + int32 hOffset = 0, + int32 width = 0, + int32 widthOffset = 0, + int32 v = 0, + int32 vOffset = 0, + int32 height = 0, + int32 heightOffset = 0); + status_t GetWindowAlignment(window_alignment* mode = NULL, + int32* h = NULL, + int32* hOffset = NULL, + int32* width = NULL, + int32* widthOffset = NULL, + int32* v = NULL, + int32* vOffset = NULL, + int32* height = NULL, + int32* heightOffset = NULL) const; + + virtual bool QuitRequested(); + virtual thread_id Run(); private: typedef BLooper inherited; @@ -241,108 +273,115 @@ private: friend class BHandler; friend class _BEventMask; friend void _set_menu_sem_(BWindow* w, sem_id sem); - friend status_t _safe_get_server_token_(const BLooper* , int32* ); + friend status_t _safe_get_server_token_(const BLooper*, int32*); - virtual void _ReservedWindow1(); - virtual void _ReservedWindow2(); - virtual void _ReservedWindow3(); - virtual void _ReservedWindow4(); - virtual void _ReservedWindow5(); - virtual void _ReservedWindow6(); - virtual void _ReservedWindow7(); - virtual void _ReservedWindow8(); + virtual void _ReservedWindow1(); + virtual void _ReservedWindow2(); + virtual void _ReservedWindow3(); + virtual void _ReservedWindow4(); + virtual void _ReservedWindow5(); + virtual void _ReservedWindow6(); + virtual void _ReservedWindow7(); + virtual void _ReservedWindow8(); - BWindow(); - BWindow(BWindow&); - BWindow &operator=(BWindow&); + BWindow(); + BWindow(BWindow&); + BWindow& operator=(BWindow&); - BWindow(BRect frame, int32 bitmapToken); - void _InitData(BRect frame, const char* title, - window_look look, window_feel feel, - uint32 flags, uint32 workspace, - int32 bitmapToken = -1); - void BitmapClose(); // to be implemented - virtual void task_looper(); + BWindow(BRect frame, int32 bitmapToken); + void _InitData(BRect frame, const char* title, + window_look look, window_feel feel, + uint32 flags, uint32 workspace, + int32 bitmapToken = -1); - virtual BMessage *ConvertToMessage(void* raw, int32 code); + void BitmapClose(); // to be implemented + virtual void task_looper(); - void AddShortcut(uint32 key, uint32 modifiers, - BMenuItem* item); - BHandler* _DetermineTarget(BMessage* message, BHandler* target); - bool _UnpackMessage(unpack_cookie& state, BMessage** _message, - BHandler** _target, bool* _usePreferred); - void _SanitizeMessage(BMessage* message, BHandler* target, - bool usePreferred); + virtual BMessage* ConvertToMessage(void* raw, int32 code); - bool InUpdate(); - void _DequeueAll(); - window_type _ComposeType(window_look look, - window_feel feel) const; - void _DecomposeType(window_type type, - window_look* look, - window_feel* feel) const; + void AddShortcut(uint32 key, uint32 modifiers, + BMenuItem* item); + BHandler* _DetermineTarget(BMessage* message, + BHandler* target); + bool _UnpackMessage(unpack_cookie& state, + BMessage** _message, + BHandler** _target, + bool* _usePreferred); + void _SanitizeMessage(BMessage* message, + BHandler* target, + bool usePreferred); - void SetIsFilePanel(bool yes); - bool IsFilePanel() const; + bool InUpdate(); + void _DequeueAll(); + window_type _ComposeType(window_look look, + window_feel feel) const; + void _DecomposeType(window_type type, + window_look* look, + window_feel* feel) const; - void _CreateTopView(); - void _AdoptResize(); - void _SetFocus(BView *focusView, bool notifyIputServer = false); + void SetIsFilePanel(bool yes); + bool IsFilePanel() const; - Shortcut* _FindShortcut(uint32 key, uint32 modifiers); - BView* _FindView(BView* view, BPoint point) const; - BView* _FindView(int32 token); - BView* _LastViewChild(BView *parent); + void _CreateTopView(); + void _AdoptResize(); + void _SetFocus(BView* focusView, + bool notifyIputServer = false); - BView* _FindNextNavigable(BView *focus, uint32 flags); - BView* _FindPreviousNavigable(BView *focus, uint32 flags); - bool _HandleKeyDown(char key, uint32 modifiers); - void _KeyboardNavigation(); + Shortcut* _FindShortcut(uint32 key, uint32 modifiers); + BView* _FindView(BView* view, BPoint point) const; + BView* _FindView(int32 token); + BView* _LastViewChild(BView* parent); + + BView* _FindNextNavigable(BView *focus, uint32 flags); + BView* _FindPreviousNavigable(BView *focus, + uint32 flags); + bool _HandleKeyDown(char key, uint32 modifiers); + void _KeyboardNavigation(); // Debug (TODO: to be removed) - void PrintToStream() const; + void PrintToStream() const; private: - char *fTitle; - int32 server_token; // not yet used - bool fInTransaction; - bool fActive; - short fShowLevel; - uint32 fFlags; - - BView *fTopView; - BView *fFocus; - BView *fLastMouseMovedView; - uint32 _unused1; - BMenuBar *fKeyMenuBar; - BButton *fDefaultButton; - BList fShortcuts; - int32 fTopViewToken; - bool _unused2; // was fPulseEnabled - bool fViewsNeedPulse; // not yet used - bool fIsFilePanel; - bool fMaskActivated; - bigtime_t fPulseRate; - bool fWaitingForMenu; - bool fMinimized; - bool fNoQuitShortcut; - bool _unused3; - sem_id fMenuSem; - float fMaxZoomHeight; - float fMaxZoomWidth; - float fMinHeight; - float fMinWidth; - float fMaxHeight; - float fMaxWidth; - BRect fFrame; - window_look fLook; - window_feel fFeel; - int32 fLastViewToken; - BPrivate::PortLink *fLink; - BMessageRunner *fPulseRunner; - BRect fPreviousFrame; - - uint32 _reserved[9]; + char* fTitle; + int32 server_token; // not yet used + bool fInTransaction; + bool fActive; + short fShowLevel; + uint32 fFlags; + + BView* fTopView; + BView* fFocus; + BView* fLastMouseMovedView; + uint32 _unused1; + BMenuBar* fKeyMenuBar; + BButton* fDefaultButton; + BList fShortcuts; + int32 fTopViewToken; + bool _unused2; // was fPulseEnabled + bool fViewsNeedPulse; // not yet used + bool fIsFilePanel; + bool fMaskActivated; + bigtime_t fPulseRate; + bool fWaitingForMenu; + bool fMinimized; + bool fNoQuitShortcut; + bool _unused3; + sem_id fMenuSem; + float fMaxZoomHeight; + float fMaxZoomWidth; + float fMinHeight; + float fMinWidth; + float fMaxHeight; + float fMaxWidth; + BRect fFrame; + window_look fLook; + window_feel fFeel; + int32 fLastViewToken; + BPrivate::PortLink* fLink; + BMessageRunner* fPulseRunner; + BRect fPreviousFrame; + + uint32 _reserved[9]; }; #endif // _WINDOW_H diff --git a/headers/private/app/ServerProtocol.h b/headers/private/app/ServerProtocol.h index 8e6a2252cb..b716fa24bb 100644 --- a/headers/private/app/ServerProtocol.h +++ b/headers/private/app/ServerProtocol.h @@ -182,6 +182,8 @@ enum { AS_SET_MOUSE_MODE, AS_GET_MOUSE_MODE, AS_GET_MOUSE, + AS_SET_DECORATOR_SETTINGS, + AS_GET_DECORATOR_SETTINGS, // Graphics calls AS_SET_HIGH_COLOR, diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp index 2e2819eb5d..a76ea04ae0 100644 --- a/src/kits/interface/Window.cpp +++ b/src/kits/interface/Window.cpp @@ -1146,31 +1146,32 @@ BWindow::SetSizeLimits(float minWidth, float maxWidth, if (minWidth > maxWidth || minHeight > maxHeight) return; - if (Lock()) { - fLink->StartMessage(AS_SET_SIZE_LIMITS); - fLink->Attach(minWidth); - fLink->Attach(maxWidth); - fLink->Attach(minHeight); - fLink->Attach(maxHeight); + if (!Lock()) + return; - int32 code; - if (fLink->FlushWithReply(code) == B_OK - && code == B_OK) { - // read the values that were really enforced on - // the server side (the window frame could have - // been changed, too) - fLink->Read(&fFrame); - fLink->Read(&fMinWidth); - fLink->Read(&fMaxWidth); - fLink->Read(&fMinHeight); - fLink->Read(&fMaxHeight); + fLink->StartMessage(AS_SET_SIZE_LIMITS); + fLink->Attach(minWidth); + fLink->Attach(maxWidth); + fLink->Attach(minHeight); + fLink->Attach(maxHeight); - _AdoptResize(); - // TODO: the same has to be done for SetLook() (that can alter - // the size limits, and hence, the size of the window - } - Unlock(); + int32 code; + if (fLink->FlushWithReply(code) == B_OK + && code == B_OK) { + // read the values that were really enforced on + // the server side (the window frame could have + // been changed, too) + fLink->Read(&fFrame); + fLink->Read(&fMinWidth); + fLink->Read(&fMaxWidth); + fLink->Read(&fMinHeight); + fLink->Read(&fMaxHeight); + + _AdoptResize(); + // TODO: the same has to be done for SetLook() (that can alter + // the size limits, and hence, the size of the window } + Unlock(); } @@ -1186,6 +1187,76 @@ BWindow::GetSizeLimits(float *minWidth, float *maxWidth, } +status_t +BWindow::SetDecoratorSettings(const BMessage& settings) +{ + // flatten the given settings into a buffer and send + // it to the app_server to apply the settings to the + // decorator + + int32 size = settings.FlattenedSize(); + char buffer[size]; + status_t ret = settings.Flatten(buffer, size); + + if (ret < B_OK) + return ret; + + if (!Lock()) + return B_ERROR; + + ret = fLink->StartMessage(AS_SET_DECORATOR_SETTINGS); + + if (ret == B_OK) + ret = fLink->Attach(size); + + if (ret == B_OK) + ret = fLink->Attach(buffer, size); + + if (ret == B_OK) + ret = fLink->Flush(); + + Unlock(); + + return ret; +} + + +status_t +BWindow::GetDecoratorSettings(BMessage* settings) +{ + // read a flattened settings message from the app_server + // and put it into settings + + if (!Lock()) + return B_ERROR; + + status_t ret = fLink->StartMessage(AS_GET_DECORATOR_SETTINGS); + + if (ret == B_OK) { + int32 code; + ret = fLink->FlushWithReply(code); + if (ret == B_OK && code != B_OK) + ret = code; + } + + if (ret == B_OK) { + int32 size; + ret = fLink->Read(&size); + if (ret == B_OK) { + char buffer[size]; + ret = fLink->Read(buffer, size); + if (ret == B_OK) { + ret = settings->Unflatten(buffer); + } + } + } + + Unlock(); + + return ret; +} + + void BWindow::SetZoomLimits(float maxWidth, float maxHeight) { diff --git a/src/servers/app/Decorator.cpp b/src/servers/app/Decorator.cpp index 774dfe68c4..0d16dd8258 100644 --- a/src/servers/app/Decorator.cpp +++ b/src/servers/app/Decorator.cpp @@ -399,6 +399,21 @@ Decorator::ResizeBy(float x, float y, BRegion* dirty) ResizeBy(BPoint(x, y), dirty); } + +bool +Decorator::SetSettings(const BMessage& settings, BRegion* updateRegion) +{ + return false; +} + + +bool +Decorator::GetSettings(BMessage* settings) const +{ + return false; +} + + /*! \brief Updates the decorator's look in the area r \param r The area to update. diff --git a/src/servers/app/Decorator.h b/src/servers/app/Decorator.h index ccb4066208..92481fd366 100644 --- a/src/servers/app/Decorator.h +++ b/src/servers/app/Decorator.h @@ -101,6 +101,10 @@ class Decorator { virtual float TabLocation() const { return 0.0; } + virtual bool SetSettings(const BMessage& settings, + BRegion* updateRegion = NULL); + virtual bool GetSettings(BMessage* settings) const; + virtual void Draw(BRect r); virtual void Draw(); virtual void DrawClose(); diff --git a/src/servers/app/DefaultDecorator.cpp b/src/servers/app/DefaultDecorator.cpp index dbe8d4dd33..40ac5dcac5 100644 --- a/src/servers/app/DefaultDecorator.cpp +++ b/src/servers/app/DefaultDecorator.cpp @@ -337,6 +337,7 @@ DefaultDecorator::ResizeBy(BPoint pt, BRegion* dirty) } } + bool DefaultDecorator::SetTabLocation(float location, BRegion* updateRegion) { @@ -367,7 +368,31 @@ DefaultDecorator::SetTabLocation(float location, BRegion* updateRegion) return true; } -// Draw + +bool +DefaultDecorator::SetSettings(const BMessage& settings, BRegion* updateRegion) +{ + float tabLocation; + if (settings.FindFloat("tab location", &tabLocation) == B_OK) + return SetTabLocation(tabLocation, updateRegion); + + return false; +} + + +bool +DefaultDecorator::GetSettings(BMessage* settings) const +{ + if (!_tabrect.IsValid()) + return false; + + return settings->AddFloat("tab location", (float)fTabOffset) == B_OK; +} + + +// #pragma mark - + + void DefaultDecorator::Draw(BRect update) { diff --git a/src/servers/app/DefaultDecorator.h b/src/servers/app/DefaultDecorator.h index 116bb2fdcc..69567bb631 100644 --- a/src/servers/app/DefaultDecorator.h +++ b/src/servers/app/DefaultDecorator.h @@ -17,77 +17,92 @@ class Desktop; class DefaultDecorator: public Decorator { - public: - DefaultDecorator(DesktopSettings& settings, BRect frame, - window_look look, uint32 flags); - virtual ~DefaultDecorator(); + public: + DefaultDecorator(DesktopSettings& settings, + BRect frame, + window_look look, + uint32 flags); + virtual ~DefaultDecorator(); - virtual void SetTitle(const char* string, BRegion* updateRegion = NULL); - virtual void SetLook(DesktopSettings& settings, - window_look look, BRegion* updateRegion = NULL); - virtual void SetFlags(uint32 flags, BRegion* updateRegion = NULL); + virtual void SetTitle(const char* string, + BRegion* updateRegion = NULL); + virtual void SetLook(DesktopSettings& settings, + window_look look, + BRegion* updateRegion = NULL); + virtual void SetFlags(uint32 flags, + BRegion* updateRegion = NULL); - virtual void MoveBy(BPoint pt); - virtual void ResizeBy(BPoint pt, BRegion* dirty); - virtual bool SetTabLocation(float location, BRegion* updateRegion = NULL); - virtual float TabLocation() const { return (float)fTabOffset;; } + virtual void MoveBy(BPoint offset); + virtual void ResizeBy(BPoint offset, BRegion* dirty); - virtual void Draw(BRect r); - virtual void Draw(); + virtual bool SetTabLocation(float location, + BRegion* updateRegion = NULL); + virtual float TabLocation() const + { return (float)fTabOffset; } - virtual void GetSizeLimits(int32* minWidth, int32* minHeight, - int32* maxWidth, int32* maxHeight) const; + virtual bool SetSettings(const BMessage& settings, + BRegion* updateRegion = NULL); + virtual bool GetSettings(BMessage* settings) const; - virtual void GetFootprint(BRegion *region); + virtual void Draw(BRect updateRect); + virtual void Draw(); - virtual click_type Clicked(BPoint pt, int32 buttons, - int32 modifiers); + virtual void GetSizeLimits(int32* minWidth, + int32* minHeight, + int32* maxWidth, + int32* maxHeight) const; - protected: - virtual void _DoLayout(); + virtual void GetFootprint(BRegion* region); - virtual void _DrawFrame(BRect r); - virtual void _DrawTab(BRect r); + virtual click_type Clicked(BPoint pt, int32 buttons, + int32 modifiers); - virtual void _DrawClose(BRect r); - virtual void _DrawTitle(BRect r); - virtual void _DrawZoom(BRect r); + protected: + virtual void _DoLayout(); - virtual void _SetFocus(); - virtual void _SetColors(); + virtual void _DrawFrame(BRect r); + virtual void _DrawTab(BRect r); - private: - void _DrawBlendedRect(BRect r, bool down); - void _GetButtonSizeAndOffset(const BRect& tabRect, - float* offset, float*size) const; - void _LayoutTabItems(const BRect& tabRect); + virtual void _DrawClose(BRect r); + virtual void _DrawTitle(BRect r); + virtual void _DrawZoom(BRect r); - RGBColor fButtonHighColor; - RGBColor fButtonLowColor; - RGBColor fTextColor; - RGBColor fTabColor; + virtual void _SetFocus(); + virtual void _SetColors(); - RGBColor* fFrameColors; + private: + void _DrawBlendedRect(BRect r, bool down); + void _GetButtonSizeAndOffset(const BRect& tabRect, + float* offset, + float*size) const; + void _LayoutTabItems(const BRect& tabRect); - // Individual rects for handling window frame - // rendering the proper way - BRect fRightBorder; - BRect fLeftBorder; - BRect fTopBorder; - BRect fBottomBorder; - - int32 fBorderWidth; - - uint32 fTabOffset; - float fTextOffset; - - float fMinTabSize; - float fMaxTabSize; - BString fTruncatedTitle; - int32 fTruncatedTitleLength; - - bigtime_t fLastClicked; - bool fWasDoubleClick; + RGBColor fButtonHighColor; + RGBColor fButtonLowColor; + RGBColor fTextColor; + RGBColor fTabColor; + + RGBColor* fFrameColors; + + // Individual rects for handling window frame + // rendering the proper way + BRect fRightBorder; + BRect fLeftBorder; + BRect fTopBorder; + BRect fBottomBorder; + + int32 fBorderWidth; + + uint32 fTabOffset; + float fTextOffset; + + float fMinTabSize; + float fMaxTabSize; + BString fTruncatedTitle; + int32 fTruncatedTitleLength; + + bigtime_t fLastClicked; + bool fWasDoubleClick; }; -#endif /* DEFAULT_DECORATOR_H */ +#endif // DEFAULT_DECORATOR_H diff --git a/src/servers/app/Desktop.cpp b/src/servers/app/Desktop.cpp index 4f663b01e5..f349913434 100644 --- a/src/servers/app/Desktop.cpp +++ b/src/servers/app/Desktop.cpp @@ -1575,6 +1575,7 @@ Desktop::ResizeWindowBy(WindowLayer* window, float x, float y) UnlockAllWindows(); } + bool Desktop::SetWindowTabLocation(WindowLayer* window, float location) { @@ -1598,6 +1599,32 @@ Desktop::SetWindowTabLocation(WindowLayer* window, float location) } +bool +Desktop::SetWindowDecoratorSettings(WindowLayer* window, + const BMessage& settings) +{ + // TODO: almost exact code duplication to above function... + + if (!LockAllWindows()) + return false; + + BRegion dirty; + bool changed = window->SetDecoratorSettings(settings, dirty); + + if (changed && window->IsVisible() && dirty.CountRects() > 0) { + BRegion stillAvailableOnScreen; + _RebuildClippingForAllWindows(stillAvailableOnScreen); + _SetBackground(stillAvailableOnScreen); + + _TriggerWindowRedrawing(dirty); + } + + UnlockAllWindows(); + + return changed; +} + + /*! Updates the workspaces of all subset windows with regard to the specifed window. diff --git a/src/servers/app/Desktop.h b/src/servers/app/Desktop.h index 47bec86c18..5653041da4 100644 --- a/src/servers/app/Desktop.h +++ b/src/servers/app/Desktop.h @@ -112,6 +112,8 @@ class Desktop : public MessageLooper, public ScreenOwner { int32 workspace = -1); void ResizeWindowBy(WindowLayer* window, float x, float y); bool SetWindowTabLocation(WindowLayer* window, float location); + bool SetWindowDecoratorSettings(WindowLayer* window, + const BMessage& settings); void SetWindowWorkspaces(WindowLayer* window, uint32 workspaces); diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index d3c254b63e..e41e62869f 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -909,6 +909,50 @@ fDesktop->LockSingleWindow(); break; } + case AS_SET_DECORATOR_SETTINGS: + { + STRACE(("ServerWindow %s: Message AS_SET_DECORATOR_SETTINGS\n")); + + int32 size; + if (fWindowLayer && link.Read(&size) == B_OK) { + char buffer[size]; + if (link.Read(buffer, size) == B_OK) { + BMessage settings; + if (settings.Unflatten(buffer) == B_OK) { +fDesktop->UnlockSingleWindow(); + fDesktop->SetWindowDecoratorSettings(fWindowLayer, settings); +fDesktop->LockSingleWindow(); + } + } + } + break; + } + + case AS_GET_DECORATOR_SETTINGS: + { + STRACE(("ServerWindow %s: Message AS_GET_DECORATOR_SETTINGS\n")); + + bool success = false; + + BMessage settings; + if (fWindowLayer->GetDecoratorSettings(&settings)) { + int32 size = settings.FlattenedSize(); + char buffer[size]; + if (settings.Flatten(buffer, size) == B_OK) { + success = true; + fLink.StartMessage(B_OK); + fLink.Attach(size); + fLink.Attach(buffer, size); + } + } + + if (!success) + fLink.StartMessage(B_ERROR); + + fLink.Flush(); + break; + } + case AS_REDRAW: // Nothing to do here - the redraws are actually handled by looking // at the fRedrawRequested member variable in _MessageLooper(). @@ -936,12 +980,12 @@ fDesktop->LockSingleWindow(); BPoint where; int32 buttons; fDesktop->EventDispatcher().GetMouse(where, buttons); + fDesktop->LockSingleWindow(); fLink.StartMessage(B_OK); fLink.Attach(where); fLink.Attach(buttons); fLink.Flush(); - fDesktop->LockSingleWindow(); break; } diff --git a/src/servers/app/WindowLayer.cpp b/src/servers/app/WindowLayer.cpp index 1933a9d308..d0b7c6b029 100644 --- a/src/servers/app/WindowLayer.cpp +++ b/src/servers/app/WindowLayer.cpp @@ -1220,8 +1220,8 @@ WindowLayer::SetTabLocation(float location, BRegion& dirty) bool ret = false; if (fDecorator) { ret = fDecorator->SetTabLocation(location, &dirty); + // the border region changed if ret is true fBorderRegionValid = fBorderRegionValid && !ret; - // the border very likely changed } return ret; } @@ -1236,6 +1236,29 @@ WindowLayer::TabLocation() const } +bool +WindowLayer::SetDecoratorSettings(const BMessage& settings, BRegion& dirty) +{ + bool ret = false; + if (fDecorator) { + ret = fDecorator->SetSettings(settings, &dirty); + // the border region changed if ret is true + fBorderRegionValid = fBorderRegionValid && !ret; + } + return ret; +} + + +bool +WindowLayer::GetDecoratorSettings(BMessage* settings) +{ + if (fDecorator) + return fDecorator->GetSettings(settings); + + return false; +} + + void WindowLayer::SetLook(window_look look, BRegion* updateRegion) { diff --git a/src/servers/app/WindowLayer.h b/src/servers/app/WindowLayer.h index c04f7a1a84..8c0e7773ee 100644 --- a/src/servers/app/WindowLayer.h +++ b/src/servers/app/WindowLayer.h @@ -172,6 +172,10 @@ class WindowLayer { bool SetTabLocation(float location, BRegion& dirty); float TabLocation() const; + bool SetDecoratorSettings(const BMessage& settings, + BRegion& dirty); + bool GetDecoratorSettings(BMessage* settings); + void HighlightDecorator(bool active); void SetLook(window_look look, BRegion* updateRegion);