* Added a Desktop::BroadcastToAllWindows() method that sends all ServerWindows

a message.
* The DesktopSettings class is now using that to send the new
  AS_SYSTEM_FONT_CHANGED message to all windows.
* The ServerWindow now propagates font changes to its decorator, causing it
  to update its drawing. That means changing the bold font in the "Fonts"
  preferences application will instantly change all window titles.
* Factored out a _RebuildAndRedrawAfterWindowChange() out of several Desktop
  methods, simplifying some code.
* The DefaultDecorator no longer calls _DoLayout() twice (through SetLook()),
  but instead calls the new _UpdateFont() method now also called by
  FontsChanged(), and SetLook().
* BWindow::GetDecoratorSettings() now also includes "tab frame" BRect with the
  exact footprint of the tab, allowing apps to know the size of the tab to
  position itself accordingly.
* Automatic white space cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28664 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-11-16 21:59:05 +00:00
parent 554bfd699c
commit 0a3f410f30
11 changed files with 159 additions and 103 deletions
+1
View File
@@ -110,6 +110,7 @@ enum {
AS_SET_SYSTEM_FONT,
AS_GET_SYSTEM_FONTS,
AS_GET_SYSTEM_DEFAULT_FONT,
AS_SYSTEM_FONT_CHANGED,
AS_GET_FONT_LIST_REVISION,
AS_GET_FAMILY_AND_STYLES,
+2 -5
View File
@@ -100,14 +100,11 @@ Decorator::SetFlags(uint32 flags, BRegion* updateRegion)
}
/*! \brief Sets the decorator's font
\param font The new font object to copy from
/*! \brief Called whenever the system fonts are changed.
*/
void
Decorator::SetFont(ServerFont *font)
Decorator::FontsChanged(DesktopSettings& settings, BRegion* updateRegion)
{
if (font)
fDrawState.SetFont(*font);
}
+2 -1
View File
@@ -53,8 +53,9 @@ public:
void SetDrawingEngine(DrawingEngine *driver);
inline DrawingEngine* GetDrawingEngine() const
{ return fDrawingEngine; }
void SetFont(ServerFont *font);
virtual void FontsChanged(DesktopSettings& settings,
BRegion* updateRegion = NULL);
virtual void SetLook(DesktopSettings& settings, window_look look,
BRegion* updateRegion = NULL);
virtual void SetFlags(uint32 flags,
+46 -15
View File
@@ -90,7 +90,7 @@ DefaultDecorator::DefaultDecorator(DesktopSettings& settings, BRect rect,
fTabLocation(0.0),
fLastClicked(0)
{
DefaultDecorator::SetLook(settings, look);
_UpdateFont(settings);
// common colors to both focus and non focus state
fFrameColors[0] = (rgb_color){ 152, 152, 152, 255 };
@@ -159,6 +159,27 @@ DefaultDecorator::SetTitle(const char* string, BRegion* updateRegion)
}
void
DefaultDecorator::FontsChanged(DesktopSettings& settings, BRegion* updateRegion)
{
// get previous extent
if (updateRegion != NULL) {
BRegion extent;
GetFootprint(&extent);
updateRegion->Include(&extent);
}
_UpdateFont(settings);
_DoLayout();
if (updateRegion != NULL) {
BRegion extent;
GetFootprint(&extent);
updateRegion->Include(&extent);
}
}
void
DefaultDecorator::SetLook(DesktopSettings& settings, window_look look,
BRegion* updateRegion)
@@ -172,19 +193,9 @@ DefaultDecorator::SetLook(DesktopSettings& settings, window_look look,
updateRegion->Include(&extent);
}
ServerFont font;
if (look == B_FLOATING_WINDOW_LOOK || look == kLeftTitledWindowLook) {
settings.GetDefaultPlainFont(font);
if (look == kLeftTitledWindowLook)
font.SetRotation(90.0f);
} else
settings.GetDefaultBoldFont(font);
fLook = look;
font.SetFlags(B_FORCE_ANTIALIASING);
font.SetSpacing(B_STRING_SPACING);
SetFont(&font);
Decorator::SetLook(settings, look, updateRegion);
_UpdateFont(settings);
_DoLayout();
if (updateRegion != NULL) {
@@ -435,6 +446,9 @@ DefaultDecorator::GetSettings(BMessage* settings) const
if (!fTabRect.IsValid())
return false;
if (settings->AddRect("tab frame", fTabRect) != B_OK)
return false;
return settings->AddFloat("tab location", (float)fTabOffset) == B_OK;
}
@@ -669,8 +683,8 @@ DefaultDecorator::_DoLayout()
fMinTabSize += offset + size;
// fMaxTabSize contains fMinWidth + the width required for the title
fMaxTabSize = fDrawingEngine ?
ceilf(fDrawingEngine->StringWidth(Title(), strlen(Title()),
fMaxTabSize = fDrawingEngine
? ceilf(fDrawingEngine->StringWidth(Title(), strlen(Title()),
fDrawState.Font())) : 0.0;
if (fMaxTabSize > 0.0)
fMaxTabSize += fTextOffset;
@@ -1098,6 +1112,23 @@ DefaultDecorator::_SetColors()
}
void
DefaultDecorator::_UpdateFont(DesktopSettings& settings)
{
ServerFont font;
if (fLook == B_FLOATING_WINDOW_LOOK || fLook == kLeftTitledWindowLook) {
settings.GetDefaultPlainFont(font);
if (fLook == kLeftTitledWindowLook)
font.SetRotation(90.0f);
} else
settings.GetDefaultBoldFont(font);
font.SetFlags(B_FORCE_ANTIALIASING);
font.SetSpacing(B_STRING_SPACING);
fDrawState.SetFont(font);
}
void
DefaultDecorator::_DrawButtonBitmap(ServerBitmap* bitmap, BRect rect)
{
+3
View File
@@ -25,6 +25,8 @@ public:
virtual void SetTitle(const char* string,
BRegion* updateRegion = NULL);
virtual void FontsChanged(DesktopSettings& settings,
BRegion* updateRegion);
virtual void SetLook(DesktopSettings& settings,
window_look look,
BRegion* updateRegion = NULL);
@@ -68,6 +70,7 @@ protected:
virtual void _SetColors();
private:
void _UpdateFont(DesktopSettings& settings);
void _DrawButtonBitmap(ServerBitmap* bitmap,
BRect rect);
void _DrawBlendedRect(DrawingEngine *engine,
+58 -62
View File
@@ -709,8 +709,7 @@ Desktop::_ActivateApp(team_id team)
}
/*!
\brief Send a quick (no attachments) message to all applications
/*! \brief Send a quick (no attachments) message to all applications.
Quite useful for notification for things like server shutdown, system
color changes, etc.
@@ -726,6 +725,20 @@ Desktop::BroadcastToAllApps(int32 code)
}
/*! \brief Send a quick (no attachments) message to all windows.
*/
void
Desktop::BroadcastToAllWindows(int32 code)
{
AutoWriteLocker _(fWindowLock);
for (Window* window = fAllWindows.FirstWindow(); window != NULL;
window = window->NextWindow(kAllWindowList)) {
window->ServerWindow()->PostMessage(code);
}
}
// #pragma mark -
@@ -1967,22 +1980,12 @@ Desktop::ResizeWindowBy(Window* window, float x, float y)
bool
Desktop::SetWindowTabLocation(Window* window, float location)
{
if (!LockAllWindows())
return false;
AutoWriteLocker _(fWindowLock);
BRegion dirty;
bool changed = window->SetTabLocation(location, dirty);
if (changed && window->IsVisible() && dirty.CountRects() > 0) {
BRegion stillAvailableOnScreen;
_RebuildClippingForAllWindows(stillAvailableOnScreen);
_SetBackground(stillAvailableOnScreen);
_WindowChanged(window);
_TriggerWindowRedrawing(dirty);
}
UnlockAllWindows();
if (changed)
_RebuildAndRedrawAfterWindowChange(window, dirty);
return changed;
}
@@ -1991,23 +1994,12 @@ Desktop::SetWindowTabLocation(Window* window, float location)
bool
Desktop::SetWindowDecoratorSettings(Window* window, const BMessage& settings)
{
// TODO: almost exact code duplication to above function...
if (!LockAllWindows())
return false;
AutoWriteLocker _(fWindowLock);
BRegion dirty;
bool changed = window->SetDecoratorSettings(settings, dirty);
if (changed && window->IsVisible() && dirty.CountRects() > 0) {
BRegion stillAvailableOnScreen;
_RebuildClippingForAllWindows(stillAvailableOnScreen);
_SetBackground(stillAvailableOnScreen);
_TriggerWindowRedrawing(dirty);
}
UnlockAllWindows();
if (changed)
_RebuildAndRedrawAfterWindowChange(window, dirty);
return changed;
}
@@ -2211,32 +2203,36 @@ Desktop::RemoveWindowFromSubset(Window* subset, Window* window)
void
Desktop::SetWindowLook(Window *window, window_look newLook)
Desktop::FontsChanged(Window* window)
{
AutoWriteLocker _(fWindowLock);
BRegion dirty;
window->FontsChanged(&dirty);
_RebuildAndRedrawAfterWindowChange(window, dirty);
}
void
Desktop::SetWindowLook(Window* window, window_look newLook)
{
if (window->Look() == newLook)
return;
if (!LockAllWindows())
return;
AutoWriteLocker _(fWindowLock);
BRegion dirty;
window->SetLook(newLook, &dirty);
// TODO: test what happens when the window
// finds out it needs to resize itself...
BRegion stillAvailableOnScreen;
_RebuildClippingForAllWindows(stillAvailableOnScreen);
_SetBackground(stillAvailableOnScreen);
_WindowChanged(window);
_TriggerWindowRedrawing(dirty);
UnlockAllWindows();
_RebuildAndRedrawAfterWindowChange(window, dirty);
}
void
Desktop::SetWindowFeel(Window *window, window_feel newFeel)
Desktop::SetWindowFeel(Window* window, window_feel newFeel)
{
if (window->Feel() == newFeel)
return;
@@ -2340,43 +2336,26 @@ Desktop::SetWindowFlags(Window *window, uint32 newFlags)
if (window->Flags() == newFlags)
return;
if (!LockAllWindows())
return;
AutoWriteLocker _(fWindowLock);
BRegion dirty;
window->SetFlags(newFlags, &dirty);
// TODO: test what happens when the window
// finds out it needs to resize itself...
BRegion stillAvailableOnScreen;
_RebuildClippingForAllWindows(stillAvailableOnScreen);
_SetBackground(stillAvailableOnScreen);
_WindowChanged(window);
_TriggerWindowRedrawing(dirty);
UnlockAllWindows();
_RebuildAndRedrawAfterWindowChange(window, dirty);
}
void
Desktop::SetWindowTitle(Window *window, const char* title)
{
if (!LockAllWindows())
return;
AutoWriteLocker _(fWindowLock);
BRegion dirty;
window->SetTitle(title, dirty);
if (window->IsVisible() && dirty.CountRects() > 0) {
BRegion stillAvailableOnScreen;
_RebuildClippingForAllWindows(stillAvailableOnScreen);
_SetBackground(stillAvailableOnScreen);
_TriggerWindowRedrawing(dirty);
}
UnlockAllWindows();
_RebuildAndRedrawAfterWindowChange(window, dirty);
}
@@ -2755,3 +2734,20 @@ Desktop::_SetBackground(BRegion& background)
}
}
}
//! The all window lock must be held when calling this function.
void
Desktop::_RebuildAndRedrawAfterWindowChange(Window* window, BRegion& dirty)
{
if (!window->IsVisible() || dirty.CountRects() == 0)
return;
BRegion stillAvailableOnScreen;
_RebuildClippingForAllWindows(stillAvailableOnScreen);
_SetBackground(stillAvailableOnScreen);
_WindowChanged(window);
_TriggerWindowRedrawing(dirty);
}
+5
View File
@@ -69,6 +69,7 @@ class Desktop : public MessageLooper, public ScreenOwner {
::EventDispatcher& EventDispatcher() { return fEventDispatcher; }
void BroadcastToAllApps(int32 code);
void BroadcastToAllWindows(int32 code);
// Screen and drawing related methods
@@ -142,6 +143,8 @@ class Desktop : public MessageLooper, public ScreenOwner {
void RemoveWindowFromSubset(Window* subset,
Window* window);
void FontsChanged(Window* window);
void SetWindowLook(Window* window, window_look look);
void SetWindowFeel(Window* window, window_feel feel);
void SetWindowFlags(Window* window, uint32 flags);
@@ -240,6 +243,8 @@ class Desktop : public MessageLooper, public ScreenOwner {
void _TriggerWindowRedrawing(
BRegion& newDirtyRegion);
void _SetBackground(BRegion& background);
void _RebuildAndRedrawAfterWindowChange(
Window* window, BRegion& dirty);
void _UpdateFloating(int32 previousWorkspace = -1,
int32 nextWorkspace = -1,
+1
View File
@@ -778,6 +778,7 @@ void
LockedDesktopSettings::SetDefaultBoldFont(const ServerFont &font)
{
fSettings->SetDefaultBoldFont(font);
fDesktop->BroadcastToAllWindows(AS_SYSTEM_FONT_CHANGED);
}
+8
View File
@@ -1082,6 +1082,13 @@ ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
break;
}
case AS_SYSTEM_FONT_CHANGED:
{
fDesktop->FontsChanged(fWindow);
// TODO: tell client about this, too, and relayout...
break;
}
case AS_REDRAW:
// Nothing to do here - the redraws are actually handled by looking
// at the fRedrawRequested member variable in _MessageLooper().
@@ -3692,6 +3699,7 @@ ServerWindow::_MessageNeedsAllWindowsLocked(uint32 code) const
case AS_WINDOW_MOVE:
case AS_WINDOW_RESIZE:
case AS_SET_SIZE_LIMITS:
case AS_SYSTEM_FONT_CHANGED:
case AS_SET_DECORATOR_SETTINGS:
case AS_GET_MOUSE:
case AS_DIRECT_WINDOW_SET_FULLSCREEN:
+11
View File
@@ -1287,6 +1287,17 @@ Window::GetDecoratorSettings(BMessage* settings)
}
void
Window::FontsChanged(BRegion* updateRegion)
{
if (fDecorator != NULL) {
DesktopSettings settings(fDesktop);
fDecorator->FontsChanged(settings, updateRegion);
fBorderRegionValid = false;
}
}
void
Window::SetLook(window_look look, BRegion* updateRegion)
{
+2
View File
@@ -177,6 +177,8 @@ public:
void HighlightDecorator(bool active);
void FontsChanged(BRegion* updateRegion);
void SetLook(window_look look, BRegion* updateRegion);
void SetFeel(window_feel feel);
void SetFlags(uint32 flags, BRegion* updateRegion);