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
This commit is contained in:
Stephan Aßmus
2006-05-25 12:01:28 +00:00
parent 11893e477d
commit b30e90211e
12 changed files with 554 additions and 283 deletions
+67 -28
View File
@@ -100,6 +100,7 @@ public:
virtual ~BWindow();
BWindow(BMessage* data);
static BArchivable* Instantiate(BMessage* data);
virtual status_t Archive(BMessage* data, bool deep = true) const;
@@ -111,40 +112,52 @@ public:
int32 CountChildren() const;
BView* ChildAt(int32 index) const;
virtual void DispatchMessage(BMessage* message, BHandler* handler);
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 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 screen_size, color_space depth);
virtual void ScreenChanged(BRect screenSize,
color_space format);
void SetPulseRate(bigtime_t rate);
bigtime_t PulseRate() const;
void AddShortcut(uint32 key, uint32 modifiers,
BMessage *msg);
BMessage *message);
void AddShortcut(uint32 key, uint32 modifiers,
BMessage *msg, BHandler *target);
BMessage *message,
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 ConvertToScreen(BPoint* pt) const;
BPoint ConvertToScreen(BPoint pt) const;
void ConvertFromScreen(BPoint* pt) const;
BPoint ConvertFromScreen(BPoint pt) const;
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;
@@ -169,8 +182,10 @@ public:
void DisableUpdates();
void EnableUpdates();
void BeginViewTransaction(); // referred as OpenViewTransaction() in BeBook
void EndViewTransaction(); // referred as CommitViewTransaction() in BeBook
void BeginViewTransaction();
// referred as OpenViewTransaction() in BeBook
void EndViewTransaction();
// referred as CommitViewTransaction() in BeBook
BRect Bounds() const;
BRect Frame() const;
@@ -178,18 +193,26 @@ public:
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);
status_t SetDecoratorSettings(const BMessage& settings);
status_t GetDecoratorSettings(BMessage* settings);
uint32 Workspaces() const;
void SetWorkspaces(uint32);
BView* LastMouseMovedView() const;
virtual BHandler *ResolveSpecifier(BMessage* msg, int32 index,
BMessage* specifier, int32 form, const char* property);
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);
@@ -212,15 +235,24 @@ public:
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,
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;
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();
@@ -261,6 +293,7 @@ private:
window_look look, window_feel feel,
uint32 flags, uint32 workspace,
int32 bitmapToken = -1);
void BitmapClose(); // to be implemented
virtual void task_looper();
@@ -268,10 +301,14 @@ private:
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,
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);
bool InUpdate();
@@ -287,7 +324,8 @@ private:
void _CreateTopView();
void _AdoptResize();
void _SetFocus(BView *focusView, bool notifyIputServer = false);
void _SetFocus(BView* focusView,
bool notifyIputServer = false);
Shortcut* _FindShortcut(uint32 key, uint32 modifiers);
BView* _FindView(BView* view, BPoint point) const;
@@ -295,7 +333,8 @@ private:
BView* _LastViewChild(BView* parent);
BView* _FindNextNavigable(BView *focus, uint32 flags);
BView* _FindPreviousNavigable(BView *focus, uint32 flags);
BView* _FindPreviousNavigable(BView *focus,
uint32 flags);
bool _HandleKeyDown(char key, uint32 modifiers);
void _KeyboardNavigation();
+2
View File
@@ -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,
+73 -2
View File
@@ -1146,7 +1146,9 @@ BWindow::SetSizeLimits(float minWidth, float maxWidth,
if (minWidth > maxWidth || minHeight > maxHeight)
return;
if (Lock()) {
if (!Lock())
return;
fLink->StartMessage(AS_SET_SIZE_LIMITS);
fLink->Attach<float>(minWidth);
fLink->Attach<float>(maxWidth);
@@ -1171,7 +1173,6 @@ BWindow::SetSizeLimits(float minWidth, float maxWidth,
}
Unlock();
}
}
void
@@ -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<int32>(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<int32>(&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)
{
+15
View File
@@ -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.
+4
View File
@@ -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();
+26 -1
View File
@@ -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)
{
+29 -14
View File
@@ -18,25 +18,39 @@ class Desktop;
class DefaultDecorator: public Decorator {
public:
DefaultDecorator(DesktopSettings& settings, BRect frame,
window_look look, uint32 flags);
DefaultDecorator(DesktopSettings& settings,
BRect frame,
window_look look,
uint32 flags);
virtual ~DefaultDecorator();
virtual void SetTitle(const char* string, 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);
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 bool SetTabLocation(float location,
BRegion* updateRegion = NULL);
virtual float TabLocation() const
{ return (float)fTabOffset; }
virtual bool SetSettings(const BMessage& settings,
BRegion* updateRegion = NULL);
virtual bool GetSettings(BMessage* settings) const;
virtual void Draw(BRect updateRect);
virtual void Draw();
virtual void GetSizeLimits(int32* minWidth, int32* minHeight,
int32* maxWidth, int32* maxHeight) const;
virtual void GetSizeLimits(int32* minWidth,
int32* minHeight,
int32* maxWidth,
int32* maxHeight) const;
virtual void GetFootprint(BRegion* region);
@@ -59,7 +73,8 @@ class DefaultDecorator: public Decorator {
private:
void _DrawBlendedRect(BRect r, bool down);
void _GetButtonSizeAndOffset(const BRect& tabRect,
float* offset, float*size) const;
float* offset,
float*size) const;
void _LayoutTabItems(const BRect& tabRect);
RGBColor fButtonHighColor;
@@ -90,4 +105,4 @@ class DefaultDecorator: public Decorator {
bool fWasDoubleClick;
};
#endif /* DEFAULT_DECORATOR_H */
#endif // DEFAULT_DECORATOR_H
+27
View File
@@ -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.
+2
View File
@@ -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);
+45 -1
View File
@@ -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<int32>(&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<int32>(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<BPoint>(where);
fLink.Attach<int32>(buttons);
fLink.Flush();
fDesktop->LockSingleWindow();
break;
}
+24 -1
View File
@@ -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)
{
+4
View File
@@ -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);