linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #04202
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2544: update cached colors on WM_SYSCOLORCHANGE
------------------------------------------------------------
revno: 2544
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Tue 2011-05-31 19:39:38 +0200
message:
update cached colors on WM_SYSCOLORCHANGE
modified:
changelog.txt
dwt/include/dwt/CanvasClasses.h
dwt/include/dwt/widgets/Menu.h
dwt/src/CanvasClasses.cpp
dwt/src/widgets/Menu.cpp
dwt/src/widgets/RichTextBox.cpp
dwt/src/widgets/TabView.cpp
win32/FinishedFrameBase.h
win32/WinUtil.cpp
--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt 2011-05-28 16:22:23 +0000
+++ changelog.txt 2011-05-31 17:39:38 +0000
@@ -27,6 +27,7 @@
* Fix taskbar tab previews when DC++ is elevated (poy)
* When holding shift at start, hubs are opened but not connected to (poy)
* Fix an integer overflow when starting a search 25 days after the previous one
+* DC++ survives a Windows theme change better (poy)
-- 0.782 2011-03-05 --
* Prevent a remote crash triggered via malformed user commands (poy)
=== modified file 'dwt/include/dwt/CanvasClasses.h'
--- dwt/include/dwt/CanvasClasses.h 2011-02-01 21:33:33 +0000
+++ dwt/include/dwt/CanvasClasses.h 2011-05-31 17:39:38 +0000
@@ -48,52 +48,20 @@
/** Helper class for manipulating COLORREF values, contains static functions for
* darken and lightening colors etc. COLORREF values (color variables) etc.
*/
-class ColorUtilities
-{
-public:
+struct Color {
/// Darkens given color by specified factor
/** Factor is in (0..1] range, the higher the factor the more dark the result
* will be. <br>
* Returns the manipulated value
*/
- static COLORREF darkenColor( COLORREF color, double factor )
- {
- if ( factor > 0.0 && factor <= 1.0 )
- {
- BYTE red = GetRValue( color );
- BYTE green = GetGValue( color );
- BYTE blue = GetBValue( color );
-
- BYTE lightred = ( BYTE )( red - ( factor * red ) );
- BYTE lightgreen = ( BYTE )( green - ( factor * green ) );
- BYTE lightblue = ( BYTE )( blue - ( factor * blue ) );
-
- color = RGB( lightred, lightgreen, lightblue );
- }
- return color;
- }
+ static COLORREF darken(COLORREF color, double factor);
/// Lightens given color by specified factor
/** Factor is in (0..1] range, the higher the factor the more light the result
* will be. <br>
* Returns the manipulated value
*/
- static COLORREF lightenColor( COLORREF color, double factor )
- {
- if ( factor > 0.0 && factor <= 1.0 )
- {
- BYTE red = GetRValue( color );
- BYTE green = GetGValue( color );
- BYTE blue = GetBValue( color );
-
- BYTE lightred = ( BYTE )( ( factor * ( 255 - red ) ) + red );
- BYTE lightgreen = ( BYTE )( ( factor * ( 255 - green ) ) + green );
- BYTE lightblue = ( BYTE )( ( factor * ( 255 - blue ) ) + blue );
-
- color = RGB( lightred, lightgreen, lightblue );
- }
- return color;
- }
+ static COLORREF lighten(COLORREF color, double factor);
/// Alpha blends color
/** Factor is in R/255, G/255 and B/255 meaning a value of 255, 255, 255 or
@@ -101,22 +69,10 @@
* will keep all read and blue and discard all green. <br>
* Returns the manipulated value.
*/
- static COLORREF alphaBlend( COLORREF color, COLORREF factor )
- {
- float aRed = GetRValue( factor );
- float aGreen = GetGValue( factor );
- float aBlue = GetBValue( factor );
- float red = GetRValue( color );
- float green = GetGValue( color );
- float blue = GetBValue( color );
-
- BYTE lightred = ( BYTE )( ( aRed / 255.0 ) * red );
- BYTE lightgreen = ( BYTE )( ( aGreen / 255.0 ) * green );
- BYTE lightblue = ( BYTE )( ( aBlue / 255.0 ) * blue );
-
- color = RGB( lightred, lightgreen, lightblue );
- return color;
- }
+ static COLORREF alphaBlend(COLORREF color, COLORREF factor);
+
+ /// wrapper around GetSysColor, see its doc for possible params.
+ static COLORREF predefined(int index);
};
// Forward declarations
@@ -417,11 +373,6 @@
*/
COLORREF getBkColor();
- /// Gets the color for an system display object.
- /** Example: getSysColor( COLOR_WINDOW )
- */
- COLORREF getSysColor( int index );
-
/// Sets the alignment mode for text operations
/** Returns the previous alignement mode and changes the current mode of text
* operations. Possible values can be any combination of these:
=== modified file 'dwt/include/dwt/widgets/Menu.h'
--- dwt/include/dwt/widgets/Menu.h 2011-03-08 22:48:55 +0000
+++ dwt/include/dwt/widgets/Menu.h 2011-05-31 17:39:38 +0000
@@ -57,18 +57,12 @@
typedef Dispatchers::VoidVoid<> Dispatcher;
-public:
- /// Type of object
- typedef Menu ThisType;
-
- /// Object type
- typedef MenuPtr ObjectType;
-
- /// Global colors, can be changed through the seed
- struct Colors {
+ static struct Colors {
Colors();
- static const COLORREF text;
- static const COLORREF gray;
+ void reset();
+
+ COLORREF text;
+ COLORREF gray;
COLORREF background;
COLORREF menuBar;
COLORREF stripBar;
@@ -77,16 +71,21 @@
COLORREF titleText;
} colors;
+public:
+ /// Type of object
+ typedef Menu ThisType;
+
+ /// Object type
+ typedef MenuPtr ObjectType;
+
struct Seed {
typedef ThisType WidgetType;
Seed(bool ownerDrawn_ = true,
- const Colors& colors_ = Colors(),
const Point& iconSize_ = Point(16, 16),
FontPtr font_ = 0);
bool popup;
bool ownerDrawn;
- Colors colors;
Point iconSize;
FontPtr font;
};
@@ -102,7 +101,7 @@
}
Widget* getParent() const {
- return itsParent;
+ return parent;
}
/// Actually creates the menu
@@ -291,9 +290,6 @@
// Specifies if item is menu title
bool isTitle;
- /// Menu item text color
- COLORREF textColor;
-
/// Menu item icon
const IconPtr icon;
@@ -308,7 +304,6 @@
index(index_),
isDefault(false),
isTitle(isTitle_),
- textColor(Colors::text),
icon(icon_)
{}
};
@@ -342,7 +337,7 @@
Menu* parentMenu; /// only defined for sub-menus; this is a link to their container menu
HMENU itsHandle;
- Widget* itsParent;
+ Widget* parent;
bool ownerDrawn;
bool popup;
=== modified file 'dwt/src/CanvasClasses.cpp'
--- dwt/src/CanvasClasses.cpp 2011-02-01 21:33:33 +0000
+++ dwt/src/CanvasClasses.cpp 2011-05-31 17:39:38 +0000
@@ -36,6 +36,58 @@
namespace dwt {
+COLORREF Color::darken(COLORREF color, double factor) {
+ if ( factor > 0.0 && factor <= 1.0 )
+ {
+ BYTE red = GetRValue( color );
+ BYTE green = GetGValue( color );
+ BYTE blue = GetBValue( color );
+
+ BYTE lightred = ( BYTE )( red - ( factor * red ) );
+ BYTE lightgreen = ( BYTE )( green - ( factor * green ) );
+ BYTE lightblue = ( BYTE )( blue - ( factor * blue ) );
+
+ color = RGB( lightred, lightgreen, lightblue );
+ }
+ return color;
+}
+
+COLORREF Color::lighten(COLORREF color, double factor) {
+ if ( factor > 0.0 && factor <= 1.0 )
+ {
+ BYTE red = GetRValue( color );
+ BYTE green = GetGValue( color );
+ BYTE blue = GetBValue( color );
+
+ BYTE lightred = ( BYTE )( ( factor * ( 255 - red ) ) + red );
+ BYTE lightgreen = ( BYTE )( ( factor * ( 255 - green ) ) + green );
+ BYTE lightblue = ( BYTE )( ( factor * ( 255 - blue ) ) + blue );
+
+ color = RGB( lightred, lightgreen, lightblue );
+ }
+ return color;
+}
+
+COLORREF Color::alphaBlend(COLORREF color, COLORREF factor) {
+ float aRed = GetRValue( factor );
+ float aGreen = GetGValue( factor );
+ float aBlue = GetBValue( factor );
+ float red = GetRValue( color );
+ float green = GetGValue( color );
+ float blue = GetBValue( color );
+
+ BYTE lightred = ( BYTE )( ( aRed / 255.0 ) * red );
+ BYTE lightgreen = ( BYTE )( ( aGreen / 255.0 ) * green );
+ BYTE lightblue = ( BYTE )( ( aBlue / 255.0 ) * blue );
+
+ color = RGB( lightred, lightgreen, lightblue );
+ return color;
+}
+
+COLORREF Color::predefined(int index) {
+ return ::GetSysColor(index);
+}
+
int Canvas::getDeviceCaps( int nIndex )
{
return( ::GetDeviceCaps( itsHdc, nIndex ) );
@@ -245,11 +297,6 @@
return ::GetBkColor( itsHdc );
}
-COLORREF Canvas::getSysColor( int index )
-{
- return ::GetSysColor( index );
-}
-
unsigned Canvas::setTextAlign( unsigned fMode )
{
return ::SetTextAlign( itsHdc, fMode );
=== modified file 'dwt/src/widgets/Menu.cpp'
--- dwt/src/widgets/Menu.cpp 2011-03-29 20:40:28 +0000
+++ dwt/src/widgets/Menu.cpp 2011-05-31 17:39:38 +0000
@@ -52,34 +52,32 @@
namespace dwt {
+Menu::Colors Menu::colors;
+
const int Menu::borderGap = 3;
const int Menu::pointerGap = 5;
const int Menu::textIconGap = 8;
const int Menu::textBorderGap = 4;
const unsigned Menu::minWidth = 150;
-/// @todo menus should re-init the cached default colors on WM_SYSCOLORCHANGE
-
-const COLORREF Menu::Colors::text = ::GetSysColor(COLOR_MENUTEXT);
-const COLORREF Menu::Colors::gray = ::GetSysColor(COLOR_GRAYTEXT);
-
-Menu::Colors::Colors() :
-background(::GetSysColor(COLOR_MENU)),
-menuBar(::GetSysColor(util::win32::ensureVersion(util::win32::VISTA) ? COLOR_MENUBAR : COLOR_3DFACE)),
-stripBar(ColorUtilities::darkenColor(background, 0.06)),
-highlightBackground(::GetSysColor(COLOR_HIGHLIGHT)),
-highlightText(::GetSysColor(COLOR_HIGHLIGHTTEXT)),
-titleText(::GetSysColor(COLOR_MENUTEXT))
-{
-}
-
-Menu::Seed::Seed(bool ownerDrawn_,
- const Colors& colors_,
- const Point& iconSize_,
- FontPtr font_) :
+Menu::Colors::Colors() {
+ reset();
+}
+
+void Menu::Colors::reset() {
+ text = Color::predefined(COLOR_MENUTEXT);
+ gray = Color::predefined(COLOR_GRAYTEXT);
+ background = Color::predefined(COLOR_MENU);
+ menuBar = Color::predefined(util::win32::ensureVersion(util::win32::VISTA) ? COLOR_MENUBAR : COLOR_3DFACE);
+ stripBar = Color::darken(background, 0.06);
+ highlightBackground = Color::predefined(COLOR_HIGHLIGHT);
+ highlightText = Color::predefined(COLOR_HIGHLIGHTTEXT);
+ titleText = Color::predefined(COLOR_MENUTEXT);
+}
+
+Menu::Seed::Seed(bool ownerDrawn_, const Point& iconSize_, FontPtr font_) :
popup(true),
ownerDrawn(ownerDrawn_),
-colors(colors_),
iconSize(iconSize_),
font(font_)
{
@@ -87,12 +85,12 @@
Menu::Menu(Widget* parent) :
parentMenu(0),
-itsParent(parent),
+parent(parent),
ownerDrawn(true),
popup(true),
drawSidebar(false)
{
- dwtassert(dynamic_cast<Control*>(itsParent), _T("A Menu must have a parent derived from dwt::Control"));
+ dwtassert(dynamic_cast<Control*>(parent), _T("A Menu must have a parent derived from dwt::Control"));
}
void Menu::createHelper(const Seed& cs) {
@@ -100,7 +98,6 @@
popup = cs.popup;
if(ownerDrawn) {
- colors = cs.colors;
iconSize = cs.iconSize;
if(cs.font)
@@ -114,7 +111,11 @@
itsTitleFont = boldFont = FontPtr(new Font(::CreateFontIndirect(&lf), true));
}
- theme.load(VSCLASS_MENU, itsParent, !popup);
+ if(!popup) {
+ getParent()->addCallback(Message(WM_SYSCOLORCHANGE), Dispatchers::VoidVoid<0, false>([] { colors.reset(); }));
+ }
+
+ theme.load(VSCLASS_MENU, getParent(), !popup);
}
}
@@ -151,7 +152,7 @@
MENUITEMINFO info = { sizeof(MENUITEMINFO), MIIM_FTYPE | MIIM_SUBMENU };
if(::GetMenuItemInfo(itsHandle, i, TRUE, &info)) {
if(info.hSubMenu) {
- ObjectType subMenu(new Menu(itsParent));
+ ObjectType subMenu(new Menu(getParent()));
subMenu->attach(info.hSubMenu, cs);
itsChildren.push_back(subMenu);
}
@@ -233,7 +234,7 @@
Menu::ObjectType Menu::appendPopup(const tstring& text, const IconPtr& icon, bool subTitle) {
// create the sub-menu
ObjectType sub(new Menu(getParent()));
- sub->create(Seed(ownerDrawn, colors, iconSize, font));
+ sub->create(Seed(ownerDrawn, iconSize, font));
sub->parentMenu = this;
if(subTitle && popup) {
@@ -277,10 +278,10 @@
Menu::ObjectType Menu::getSystemMenu()
{
// get system menu for the utmost parent
- HMENU handle = ::GetSystemMenu( itsParent->handle(), FALSE );
+ HMENU handle = ::GetSystemMenu( getParent()->handle(), FALSE );
// create pointer to system menu
- ObjectType sysMenu( new Menu( itsParent->handle() ) );
+ ObjectType sysMenu( new Menu( getParent()->handle() ) );
// create(take) system menu
sysMenu->create( handle, false );
@@ -565,7 +566,7 @@
rectangle.pos.y += rectangle.height() / 2 - 1;
// select color
- auto select(canvas.select(*PenPtr(new Pen(Colors::gray))));
+ auto select(canvas.select(*PenPtr(new Pen(colors.gray))));
// draw separator
canvas.moveTo( rectangle.left(), rectangle.top() );
@@ -627,10 +628,10 @@
auto bkMode(canvas.setBkMode(true));
canvas.setTextColor(
- isGrayed ? Colors::gray :
+ isGrayed ? colors.gray :
wrapper->isTitle ? colors.titleText :
highlight ? colors.highlightText :
- wrapper->textColor);
+ colors.text);
canvas.drawText(text, textRectangle, drawTextFormat);
if(!accelerator.empty())
@@ -680,7 +681,7 @@
stripRectangle.pos.y += 1;
stripRectangle.size.x -= 2;
stripRectangle.size.y -= 2;
- auto select(canvas.select(*PenPtr(new Pen(Colors::gray))));
+ auto select(canvas.select(*PenPtr(new Pen(colors.gray))));
canvas.line(stripRectangle);
}
}
=== modified file 'dwt/src/widgets/RichTextBox.cpp'
--- dwt/src/widgets/RichTextBox.cpp 2011-05-07 18:52:09 +0000
+++ dwt/src/widgets/RichTextBox.cpp 2011-05-31 17:39:38 +0000
@@ -67,8 +67,8 @@
if(cs.font)
setFont(cs.font);
- COLORREF bg = (cs.backgroundColor == NaC) ? ::GetSysColor(COLOR_WINDOW) : cs.backgroundColor;
- COLORREF fg = (cs.foregroundColor == NaC) ? ::GetSysColor(COLOR_WINDOWTEXT) : cs.foregroundColor;
+ COLORREF bg = (cs.backgroundColor == NaC) ? Color::predefined(COLOR_WINDOW) : cs.backgroundColor;
+ COLORREF fg = (cs.foregroundColor == NaC) ? Color::predefined(COLOR_WINDOWTEXT) : cs.foregroundColor;
setBackgroundColor(bg);
=== modified file 'dwt/src/widgets/TabView.cpp'
--- dwt/src/widgets/TabView.cpp 2011-04-15 21:51:55 +0000
+++ dwt/src/widgets/TabView.cpp 2011-05-31 17:39:38 +0000
@@ -746,7 +746,7 @@
if(theme) {
theme.drawText(canvas, part, state, text, dtFormat, rect);
} else {
- canvas.setTextColor(::GetSysColor(isSelected ? COLOR_WINDOWTEXT : isHighlighted ? COLOR_HIGHLIGHTTEXT : COLOR_BTNTEXT));
+ canvas.setTextColor(Color::predefined(isSelected ? COLOR_WINDOWTEXT : isHighlighted ? COLOR_HIGHLIGHTTEXT : COLOR_BTNTEXT));
canvas.drawText(text, rect, dtFormat);
}
=== modified file 'win32/FinishedFrameBase.h'
--- win32/FinishedFrameBase.h 2011-05-30 17:06:19 +0000
+++ win32/FinishedFrameBase.h 2011-05-31 17:39:38 +0000
@@ -59,8 +59,8 @@
};
static void focusFile(TabViewPtr parent, const string& file) {
- openWindow(parent, false);
- frame->focusFile(file);
+ BaseType::openWindow(parent, false);
+ BaseType::frame->focusFile(file);
}
protected:
@@ -389,9 +389,9 @@
tabs->setActive(filesWindow);
files->forEachT([this, &file](FileInfo* fi) {
if(fi->file == file) {
- auto pos = files->find(fi);
- files->setSelected(pos);
- files->ensureVisible(pos);
+ auto pos = this->files->find(fi);
+ this->files->setSelected(pos);
+ this->files->ensureVisible(pos);
}
});
}
=== modified file 'win32/WinUtil.cpp'
--- win32/WinUtil.cpp 2011-05-29 21:40:28 +0000
+++ win32/WinUtil.cpp 2011-05-31 17:39:38 +0000
@@ -130,8 +130,8 @@
void WinUtil::init() {
- SettingsManager::getInstance()->setDefault(SettingsManager::BACKGROUND_COLOR, (int) (GetSysColor(COLOR_WINDOW)));
- SettingsManager::getInstance()->setDefault(SettingsManager::TEXT_COLOR, (int) (GetSysColor(COLOR_WINDOWTEXT)));
+ SettingsManager::getInstance()->setDefault(SettingsManager::BACKGROUND_COLOR, dwt::Color::predefined(COLOR_WINDOW));
+ SettingsManager::getInstance()->setDefault(SettingsManager::TEXT_COLOR, dwt::Color::predefined(COLOR_WINDOWTEXT));
textColor = SETTING(TEXT_COLOR);
bgColor = SETTING(BACKGROUND_COLOR);
@@ -869,8 +869,8 @@
ts.style = WS_CHILD | WS_VISIBLE | ES_READONLY;
ts.exStyle = 0;
ts.location = dwt::Rectangle(margins, dwt::Point(maxWidth, 0));
- ts.foregroundColor = ::GetSysColor(COLOR_INFOTEXT);
- ts.backgroundColor = ::GetSysColor(COLOR_INFOBK);
+ ts.foregroundColor = dwt::Color::predefined(COLOR_INFOTEXT);
+ ts.backgroundColor = dwt::Color::predefined(COLOR_INFOBK);
createBox();
}