linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #04814
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2683: No need to restart DC++ to apply new colors
------------------------------------------------------------
revno: 2683
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sat 2011-11-19 01:10:54 +0100
message:
No need to restart DC++ to apply new colors
modified:
changelog.txt
dwt/include/dwt/aspects/Colorable.h
dwt/include/dwt/aspects/Command.h
dwt/include/dwt/widgets/Button.h
dwt/include/dwt/widgets/ComboBox.h
dwt/include/dwt/widgets/Control.h
dwt/include/dwt/widgets/GroupBox.h
dwt/include/dwt/widgets/Label.h
dwt/include/dwt/widgets/RichTextBox.h
dwt/include/dwt/widgets/Table.h
dwt/include/dwt/widgets/TextBox.h
dwt/include/dwt/widgets/Tree.h
dwt/src/widgets/TextBox.cpp
win32/ComboBox.h
win32/MDIChildFrame.h
win32/MainWindow.cpp
win32/TransferView.cpp
win32/WinUtil.cpp
win32/WinUtil.h
win32/resource.h
--
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-10-30 15:24:29 +0000
+++ changelog.txt 2011-11-19 00:10:54 +0000
@@ -49,6 +49,8 @@
* Increase minimum download segment size from 64KiB to 256KiB (cologic)
* [L#874282] Fix the "Close disconnected hubs" command (poy)
* [L#721102] Close tabs when releasing the mouse button (poy)
+* [L#729684] Fix the /userlist chat command (poy)
+* No need to restart DC++ to apply new colors (poy)
-- 0.782 2011-03-05 --
* Prevent a remote crash triggered via malformed user commands (poy)
=== modified file 'dwt/include/dwt/aspects/Colorable.h'
--- dwt/include/dwt/aspects/Colorable.h 2011-11-18 18:27:17 +0000
+++ dwt/include/dwt/aspects/Colorable.h 2011-11-19 00:10:54 +0000
@@ -41,9 +41,9 @@
namespace dwt { namespace aspects {
-/** Aspect class used by Widgets that have the possibility of changing colors. They must provide a
-void setColorImpl(COLORREF text, COLORREF background) function. If they understand WM_CTLCOLOR,
-that function can be provided by using ColorableCtlImpl as a base class. */
+/** Aspect class used by Widgets that have the possibility of changing colors. By default, this is
+done by catching WM_CTLCOLOR. Widgets that don't support WM_CTLCOLOR can customize this behavior by
+providing a void setColorImpl(COLORREF text, COLORREF background) function. */
template<typename WidgetType>
class Colorable {
WidgetType& W() { return *static_cast<WidgetType*>(this); }
@@ -52,17 +52,9 @@
void setColor(COLORREF text, COLORREF background) {
W().setColorImpl(text, background);
}
-};
-
-/// Helper class for controls that are colorable via WM_CTLCOLOR
-template<typename WidgetType>
-class ColorableCtlImpl {
- friend class Colorable<WidgetType>;
-
- WidgetType& W() { return *static_cast<WidgetType*>(this); }
-
- /// Set the background, text and text colors
- void setColorImpl(COLORREF text, COLORREF background) {
+
+private:
+ virtual void setColorImpl(COLORREF text, COLORREF background) {
BrushPtr brush(new Brush(background));
W().setCallback(Message(WM_CTLCOLOR), [text, background, brush](const MSG& msg, LRESULT& ret) -> bool {
HDC dc = reinterpret_cast<HDC>(msg.wParam);
=== modified file 'dwt/include/dwt/aspects/Command.h'
--- dwt/include/dwt/aspects/Command.h 2011-11-07 20:53:49 +0000
+++ dwt/include/dwt/aspects/Command.h 2011-11-19 00:10:54 +0000
@@ -39,9 +39,14 @@
template<typename WidgetType>
class Command {
+ const WidgetType& W() const { return *static_cast<const WidgetType*>(this); }
WidgetType& W() { return *static_cast<WidgetType*>(this); }
+
+ HWND H() const { return W().handle(); }
+
public:
typedef Dispatchers::VoidVoid<> CommandDispatcher;
+
void onCommand(const CommandDispatcher::F& f, unsigned id) {
W().addCallback(Message(WM_COMMAND, id), CommandDispatcher(f));
}
@@ -53,6 +58,10 @@
void onSysCommand(const CommandDispatcher::F& f, unsigned id) {
W().addCallback(Message(WM_SYSCOMMAND, id), CommandDispatcher(f));
}
+
+ void sendCommand(unsigned id) {
+ W().sendMessage(WM_COMMAND, MAKEWPARAM(0, id), reinterpret_cast<LPARAM>(H()));
+ }
};
} }
=== modified file 'dwt/include/dwt/widgets/Button.h'
--- dwt/include/dwt/widgets/Button.h 2011-11-07 20:53:49 +0000
+++ dwt/include/dwt/widgets/Button.h 2011-11-19 00:10:54 +0000
@@ -37,7 +37,6 @@
#define DWT_ASPECTBUTTON_H_
#include "../aspects/Caption.h"
-#include "../aspects/Colorable.h"
#include "../aspects/Clickable.h"
#include "Control.h"
@@ -47,9 +46,7 @@
class Button :
public CommonControl,
public aspects::Caption<Button>,
- private aspects::Clickable<Button>,
- public aspects::Colorable<Button>,
- public aspects::ColorableCtlImpl<Button>
+ private aspects::Clickable<Button>
{
typedef CommonControl BaseType;
friend class aspects::Clickable<Button>;
=== modified file 'dwt/include/dwt/widgets/ComboBox.h'
--- dwt/include/dwt/widgets/ComboBox.h 2011-11-18 18:27:17 +0000
+++ dwt/include/dwt/widgets/ComboBox.h 2011-11-19 00:10:54 +0000
@@ -37,7 +37,6 @@
#define DWT_ComboBox_h
#include "../aspects/Caption.h"
-#include "../aspects/Colorable.h"
#include "../aspects/Clickable.h"
#include "../aspects/Collection.h"
#include "../aspects/Data.h"
@@ -60,8 +59,6 @@
public aspects::Caption<ComboBox>,
private aspects::Clickable<ComboBox>,
public aspects::Collection<ComboBox, int>,
- public aspects::Colorable<ComboBox>,
- public aspects::ColorableCtlImpl<ComboBox>,
public aspects::Data<ComboBox, int>,
public aspects::Selection<ComboBox, int>
{
=== modified file 'dwt/include/dwt/widgets/Control.h'
--- dwt/include/dwt/widgets/Control.h 2011-11-07 22:11:39 +0000
+++ dwt/include/dwt/widgets/Control.h 2011-11-19 00:10:54 +0000
@@ -36,6 +36,7 @@
#include "../aspects/Border.h"
#include "../aspects/Closeable.h"
+#include "../aspects/Colorable.h"
#include "../aspects/Command.h"
#include "../aspects/ContextMenu.h"
#include "../aspects/DragDrop.h"
@@ -58,6 +59,7 @@
public aspects::Border<Control>,
public aspects::Closeable<Control>,
+ public aspects::Colorable<Control>,
public aspects::Command<Control>,
public aspects::ContextMenu<Control>,
public aspects::DragDrop<Control>,
=== modified file 'dwt/include/dwt/widgets/GroupBox.h'
--- dwt/include/dwt/widgets/GroupBox.h 2011-11-07 20:53:49 +0000
+++ dwt/include/dwt/widgets/GroupBox.h 2011-11-19 00:10:54 +0000
@@ -45,7 +45,6 @@
* add up your RadioButtons into an object of this type
*/
#include "../aspects/Caption.h"
-#include "../aspects/Colorable.h"
#include "../aspects/Child.h"
#include "Control.h"
@@ -55,8 +54,6 @@
class GroupBox :
public CommonControl,
public aspects::Caption<GroupBox>,
- public aspects::Colorable<GroupBox>,
- public aspects::ColorableCtlImpl<GroupBox>,
public aspects::Child<GroupBox>
{
typedef CommonControl BaseType;
=== modified file 'dwt/include/dwt/widgets/Label.h'
--- dwt/include/dwt/widgets/Label.h 2011-11-07 20:53:49 +0000
+++ dwt/include/dwt/widgets/Label.h 2011-11-19 00:10:54 +0000
@@ -37,7 +37,6 @@
#define DWT_Label_h
#include "../aspects/Caption.h"
-#include "../aspects/Colorable.h"
#include "../aspects/Clickable.h"
#include "Control.h"
@@ -58,9 +57,7 @@
class Label :
public CommonControl,
public aspects::Caption<Label>,
- private aspects::Clickable<Label>,
- public aspects::Colorable<Label>,
- public aspects::ColorableCtlImpl<Label>
+ private aspects::Clickable<Label>
{
typedef CommonControl BaseType;
friend class WidgetCreator< Label >;
=== modified file 'dwt/include/dwt/widgets/RichTextBox.h'
--- dwt/include/dwt/widgets/RichTextBox.h 2011-11-18 18:27:17 +0000
+++ dwt/include/dwt/widgets/RichTextBox.h 2011-11-19 00:10:54 +0000
@@ -57,14 +57,11 @@
* notepad ( TextBox ) and wordpad ( RichTextBox )
*/
class RichTextBox :
- public TextBoxBase,
- public aspects::Colorable<RichTextBox>
+ public TextBoxBase
{
friend class WidgetCreator<RichTextBox>;
typedef TextBoxBase BaseType;
- friend class aspects::Colorable<RichTextBox>;
-
public:
/// Class type
typedef RichTextBox ThisType;
=== modified file 'dwt/include/dwt/widgets/Table.h'
--- dwt/include/dwt/widgets/Table.h 2011-11-16 18:12:07 +0000
+++ dwt/include/dwt/widgets/Table.h 2011-11-19 00:10:54 +0000
@@ -40,7 +40,6 @@
#include "../resources/ImageList.h"
#include "../aspects/Clickable.h"
#include "../aspects/Collection.h"
-#include "../aspects/Colorable.h"
#include "../aspects/CustomDraw.h"
#include "../aspects/Data.h"
#include "../aspects/Scrollable.h"
@@ -70,7 +69,6 @@
public CommonControl,
public aspects::Clickable<Table>,
public aspects::Collection<Table, int>,
- public aspects::Colorable<Table>,
public aspects::CustomDraw<Table, NMLVCUSTOMDRAW>,
public aspects::Data<Table, int>,
public aspects::Scrollable<Table>,
@@ -80,7 +78,6 @@
friend class WidgetCreator<Table>;
friend class aspects::Collection<Table, int>;
- friend class aspects::Colorable<Table>;
friend class aspects::Data<Table, int>;
friend class aspects::Selection<Table, int>;
friend class aspects::Clickable<Table>;
=== modified file 'dwt/include/dwt/widgets/TextBox.h'
--- dwt/include/dwt/widgets/TextBox.h 2011-11-18 18:27:17 +0000
+++ dwt/include/dwt/widgets/TextBox.h 2011-11-19 00:10:54 +0000
@@ -37,7 +37,6 @@
#define DWT_TextBox_h
#include "../aspects/Caption.h"
-#include "../aspects/Colorable.h"
#include "../aspects/Scrollable.h"
#include "../aspects/Update.h"
#include "Control.h"
@@ -202,9 +201,7 @@
};
class TextBox :
- public TextBoxBase,
- public aspects::Colorable<TextBox>,
- public aspects::ColorableCtlImpl<TextBox>
+ public TextBoxBase
{
typedef TextBoxBase BaseType;
=== modified file 'dwt/include/dwt/widgets/Tree.h'
--- dwt/include/dwt/widgets/Tree.h 2011-11-07 22:11:39 +0000
+++ dwt/include/dwt/widgets/Tree.h 2011-11-19 00:10:54 +0000
@@ -40,7 +40,6 @@
#include "../resources/ImageList.h"
#include "../aspects/Clickable.h"
#include "../aspects/Collection.h"
-#include "../aspects/Colorable.h"
#include "../aspects/CustomDraw.h"
#include "../aspects/Data.h"
#include "../aspects/Selection.h"
@@ -75,7 +74,6 @@
public CommonControl,
public aspects::Clickable<Tree>,
public aspects::Collection<Tree, HTREEITEM>,
- public aspects::Colorable<Tree>,
public aspects::CustomDraw<Tree, NMTVCUSTOMDRAW>,
public aspects::Data<Tree, HTREEITEM>,
public aspects::Selection<Tree, HTREEITEM>
@@ -85,7 +83,6 @@
protected:
friend class WidgetCreator<Tree>;
friend class aspects::Collection<Tree, HTREEITEM>;
- friend class aspects::Colorable<Tree>;
friend class aspects::Data<Tree, HTREEITEM>;
friend class aspects::Selection<Tree, HTREEITEM>;
friend class aspects::Clickable<Tree>;
=== modified file 'dwt/src/widgets/TextBox.cpp'
--- dwt/src/widgets/TextBox.cpp 2011-11-07 20:53:49 +0000
+++ dwt/src/widgets/TextBox.cpp 2011-11-19 00:10:54 +0000
@@ -85,8 +85,8 @@
// multiline text-boxes don't fire EN_CHANGE / EN_UPDATE when they receive WM_SETTTEXT
if(hasStyle(ES_MULTILINE)) {
- sendMessage(WM_COMMAND, MAKEWPARAM(0, EN_UPDATE), reinterpret_cast<LPARAM>(handle()));
- sendMessage(WM_COMMAND, MAKEWPARAM(0, EN_CHANGE), reinterpret_cast<LPARAM>(handle()));
+ sendCommand(EN_UPDATE);
+ sendCommand(EN_CHANGE);
}
}
=== modified file 'win32/ComboBox.h'
--- win32/ComboBox.h 2011-11-07 20:53:49 +0000
+++ win32/ComboBox.h 2011-11-19 00:10:54 +0000
@@ -26,9 +26,7 @@
/// @todo this should obviously be moved somewhere else
/** Wraps the drop-down control of a ComboBox */
class ListBox :
- public dwt::Control,
- public dwt::aspects::Colorable<ListBox>,
- public dwt::aspects::ColorableCtlImpl<ListBox>
+ public dwt::Control
{
typedef dwt::Control BaseType;
friend class dwt::WidgetCreator<ListBox>;
=== modified file 'win32/MDIChildFrame.h'
--- win32/MDIChildFrame.h 2011-11-07 20:53:49 +0000
+++ win32/MDIChildFrame.h 2011-11-19 00:10:54 +0000
@@ -186,7 +186,7 @@
template<typename A>
void addColor(dwt::aspects::Colorable<A>* widget) {
- widget->setColor(WinUtil::textColor, WinUtil::bgColor);
+ WinUtil::setColor(static_cast<dwt::Control*>(widget));
}
// Catch-rest for the above
=== modified file 'win32/MainWindow.cpp'
--- win32/MainWindow.cpp 2011-10-30 14:24:14 +0000
+++ win32/MainWindow.cpp 2011-11-19 00:10:54 +0000
@@ -1050,6 +1050,18 @@
dwt::Application::instance().removeFilter(filterIter);
}
+namespace {
+
+BOOL CALLBACK updateColors(HWND hwnd, LPARAM) {
+ dwt::Control* widget = dwt::hwnd_cast<dwt::Control*>(hwnd);
+ if(widget) {
+ widget->sendCommand(ID_UPDATECOLOR);
+ }
+ return TRUE;
+}
+
+} // unnamed namespace
+
void MainWindow::handleSettings() {
// this may be called directly from the tray icon when the main window is still hidden
if(isIconic())
@@ -1099,6 +1111,19 @@
GeoManager::getInstance()->rebuild();
}
+ bool newColors = false;
+ if(static_cast<COLORREF>(SETTING(TEXT_COLOR)) != WinUtil::textColor) {
+ WinUtil::textColor = SETTING(TEXT_COLOR);
+ newColors = true;
+ }
+ if(static_cast<COLORREF>(SETTING(BACKGROUND_COLOR)) != WinUtil::bgColor) {
+ WinUtil::bgColor = SETTING(BACKGROUND_COLOR);
+ newColors = true;
+ }
+ if(newColors) {
+ ::EnumChildWindows(handle(), updateColors, 0);
+ }
+
if(BOOLSETTING(ALWAYS_TRAY) != prevTray)
notifier->setVisible(BOOLSETTING(ALWAYS_TRAY));
=== modified file 'win32/TransferView.cpp'
--- win32/TransferView.cpp 2011-11-15 19:05:59 +0000
+++ win32/TransferView.cpp 2011-11-19 00:10:54 +0000
@@ -120,7 +120,7 @@
WinUtil::makeColumns(connections, connectionColumns, CONNECTION_COLUMN_LAST, SETTING(CONNECTIONS_ORDER), SETTING(CONNECTIONS_WIDTHS));
- connections->setColor(WinUtil::textColor, WinUtil::bgColor);
+ WinUtil::setColor(connections);
connections->setSort(CONNECTION_COLUMN_USER);
connections->onContextMenu([this](const dwt::ScreenCoordinate &sc) { return handleConnectionsMenu(sc); });
@@ -136,7 +136,7 @@
WinUtil::makeColumns(downloads, downloadColumns, DOWNLOAD_COLUMN_LAST, SETTING(DOWNLOADS_ORDER), SETTING(DOWNLOADS_WIDTHS));
downloads->setSort(DOWNLOAD_COLUMN_STATUS);
- downloads->setColor(WinUtil::textColor, WinUtil::bgColor);
+ WinUtil::setColor(downloads);
downloads->setSmallImageList(WinUtil::fileImages);
downloads->onContextMenu([this](const dwt::ScreenCoordinate &sc) { return handleDownloadsMenu(sc); });
=== modified file 'win32/WinUtil.cpp'
--- win32/WinUtil.cpp 2011-11-18 18:27:17 +0000
+++ win32/WinUtil.cpp 2011-11-19 00:10:54 +0000
@@ -1004,6 +1004,15 @@
return make_pair(ok, cancel);
}
+void WinUtil::setColor(dwt::Control* widget) {
+ widget->setColor(textColor, bgColor);
+
+ widget->onCommand([widget] {
+ widget->setColor(textColor, bgColor);
+ widget->redraw();
+ }, ID_UPDATECOLOR);
+}
+
HLSCOLOR RGB2HLS(COLORREF rgb) {
unsigned char minval = min(GetRValue(rgb), min(GetGValue(rgb), GetBValue(rgb)));
unsigned char maxval = max(GetRValue(rgb), max(GetGValue(rgb), GetBValue(rgb)));
=== modified file 'win32/WinUtil.h'
--- win32/WinUtil.h 2011-11-10 10:23:08 +0000
+++ win32/WinUtil.h 2011-11-19 00:10:54 +0000
@@ -225,6 +225,8 @@
return ret;
}
+ static void setColor(dwt::Control* widget);
+
static size_t getFileIcon(const string& fileName);
static size_t getFileIcon(const tstring& fileName);
=== modified file 'win32/resource.h'
--- win32/resource.h 2011-11-15 19:05:59 +0000
+++ win32/resource.h 2011-11-19 00:10:54 +0000
@@ -89,4 +89,7 @@
#define IDH_BEGIN 10000
#define IDH_END 11999
+// WM_APP messages
+#define ID_UPDATECOLOR (WM_APP + 0)
+
#endif