linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #04813
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2682: change how rich edits handle custom colors (use the Colorable aspect)
------------------------------------------------------------
revno: 2682
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2011-11-18 19:27:17 +0100
message:
change how rich edits handle custom colors (use the Colorable aspect)
modified:
dwt/include/dwt/aspects/Colorable.h
dwt/include/dwt/widgets/ComboBox.h
dwt/include/dwt/widgets/RichTextBox.h
dwt/include/dwt/widgets/TextBox.h
dwt/src/widgets/RichTextBox.cpp
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 'dwt/include/dwt/aspects/Colorable.h'
--- dwt/include/dwt/aspects/Colorable.h 2011-11-13 16:46:43 +0000
+++ dwt/include/dwt/aspects/Colorable.h 2011-11-18 18:27:17 +0000
@@ -41,10 +41,13 @@
namespace dwt { namespace aspects {
-/// Aspect class used by Widgets that have the possibility of changing colors
+/** 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. */
template<typename WidgetType>
class Colorable {
WidgetType& W() { return *static_cast<WidgetType*>(this); }
+
public:
void setColor(COLORREF text, COLORREF background) {
W().setColorImpl(text, background);
=== modified file 'dwt/include/dwt/widgets/ComboBox.h'
--- dwt/include/dwt/widgets/ComboBox.h 2011-11-07 20:53:49 +0000
+++ dwt/include/dwt/widgets/ComboBox.h 2011-11-18 18:27:17 +0000
@@ -68,7 +68,6 @@
typedef CommonControl BaseType;
friend class WidgetCreator< ComboBox >;
friend class aspects::Collection<ComboBox, int>;
- friend class aspects::Colorable<ComboBox>;
friend class aspects::Selection<ComboBox, int>;
friend class aspects::Clickable<ComboBox>;
friend class aspects::Data<ComboBox, int>;
=== modified file 'dwt/include/dwt/widgets/RichTextBox.h'
--- dwt/include/dwt/widgets/RichTextBox.h 2011-05-07 18:52:09 +0000
+++ dwt/include/dwt/widgets/RichTextBox.h 2011-11-18 18:27:17 +0000
@@ -36,8 +36,6 @@
#ifndef DWT_RichTextBox_h
#define DWT_RichTextBox_h
-#ifndef WINCE // Doesn't exist in Windows CE based systems
-
#include "TextBox.h"
#include "../tstring.h"
#include <richedit.h>
@@ -59,10 +57,14 @@
* notepad ( TextBox ) and wordpad ( RichTextBox )
*/
class RichTextBox :
- public TextBoxBase
+ public TextBoxBase,
+ public aspects::Colorable<RichTextBox>
{
- friend class WidgetCreator< RichTextBox >;
+ friend class WidgetCreator<RichTextBox>;
typedef TextBoxBase BaseType;
+
+ friend class aspects::Colorable<RichTextBox>;
+
public:
/// Class type
typedef RichTextBox ThisType;
@@ -96,10 +98,6 @@
*/
void create( const Seed & cs = Seed() );
- void setBackgroundColor(COLORREF color);
-
- void setDefaultCharFormat(const CHARFORMAT& cf);
-
int charFromPos(const ScreenCoordinate& pt);
int lineFromPos(const ScreenCoordinate& pt);
@@ -159,28 +157,14 @@
void setTextA(const std::string& txt);
void setTextEx(const std::string& txt, DWORD format);
+
+ // aspects::Colorable
+ void setColorImpl(COLORREF text, COLORREF background);
+
+ COLORREF bgColor; // store the current bg color for the onPrinting handler.
};
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Implementation of class
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-inline RichTextBox::RichTextBox( dwt::Widget * parent )
- : TextBoxBase(parent, makeDispatcher())
-{
-}
-
-inline void RichTextBox::setBackgroundColor(COLORREF color) {
- this->sendMessage(EM_SETBKGNDCOLOR, 0, static_cast<LPARAM>(color));
-}
-
-inline void RichTextBox::setDefaultCharFormat(const CHARFORMAT& cf) {
- this->sendMessage(EM_SETCHARFORMAT, 0, reinterpret_cast<LPARAM>(&cf));
-}
-
// end namespace dwt
}
-#endif //! WINCE
-
#endif
=== modified file 'dwt/include/dwt/widgets/TextBox.h'
--- dwt/include/dwt/widgets/TextBox.h 2011-11-07 20:53:49 +0000
+++ dwt/include/dwt/widgets/TextBox.h 2011-11-18 18:27:17 +0000
@@ -62,13 +62,11 @@
class TextBoxBase :
public CommonControl,
public aspects::Caption<TextBoxBase>,
- public aspects::Colorable<TextBoxBase>,
- public aspects::ColorableCtlImpl<TextBoxBase>,
public aspects::Scrollable<TextBoxBase>,
public aspects::Update<TextBoxBase>
{
typedef CommonControl BaseType;
- friend class WidgetCreator< TextBoxBase >;
+ friend class WidgetCreator<TextBoxBase>;
friend class aspects::Update<TextBoxBase>;
public:
@@ -204,9 +202,12 @@
};
class TextBox :
- public TextBoxBase
+ public TextBoxBase,
+ public aspects::Colorable<TextBox>,
+ public aspects::ColorableCtlImpl<TextBox>
{
typedef TextBoxBase BaseType;
+
public:
typedef TextBox ThisType;
=== modified file 'dwt/src/widgets/RichTextBox.cpp'
--- dwt/src/widgets/RichTextBox.cpp 2011-10-10 20:18:18 +0000
+++ dwt/src/widgets/RichTextBox.cpp 2011-11-18 18:27:17 +0000
@@ -66,15 +66,6 @@
BaseType::create(cs);
setFont(cs.font);
- COLORREF bg = (cs.backgroundColor == NaC) ? Color::predefined(COLOR_WINDOW) : cs.backgroundColor;
- COLORREF fg = (cs.foregroundColor == NaC) ? Color::predefined(COLOR_WINDOWTEXT) : cs.foregroundColor;
-
- setBackgroundColor(bg);
-
- CHARFORMAT textFormat = { sizeof(CHARFORMAT), CFM_COLOR };
- textFormat.crTextColor = fg;
- setDefaultCharFormat(textFormat);
-
setScrollBarHorizontally(cs.scrollBarHorizontallyFlag);
setScrollBarVertically(cs.scrollBarVerticallyFlag);
@@ -83,11 +74,11 @@
/* unlike other common controls, Rich Edits ignore WM_PRINTCLIENT messages. as per
<http://msdn.microsoft.com/en-us/library/bb787875(VS.85).aspx>, we have to handle the printing
by ourselves. this is crucial for taskbar thumbnails and "Aero Peek" previews. */
- onPrinting([this, bg](Canvas& canvas) {
+ onPrinting([this](Canvas& canvas) {
Rectangle rect(getClientSize());
// paint a background in case the text doesn't span the whole box.
- canvas.fill(rect, Brush(bg));
+ canvas.fill(rect, Brush(bgColor));
::FORMATRANGE format = { canvas.handle(), canvas.handle() };
format.rc = rect;
@@ -103,6 +94,11 @@
});
}
+RichTextBox::RichTextBox(dwt::Widget* parent) :
+TextBoxBase(parent, makeDispatcher())
+{
+}
+
inline int RichTextBox::charFromPos(const ScreenCoordinate& pt) {
ClientCoordinate cc(pt, this);
// Unlike edit control: "The return value specifies the zero-based character index of the character
@@ -329,4 +325,13 @@
return escaped;
}
+void RichTextBox::setColorImpl(COLORREF text, COLORREF background) {
+ CHARFORMAT textFormat = { sizeof(CHARFORMAT), CFM_COLOR };
+ textFormat.crTextColor = text;
+ sendMessage(EM_SETCHARFORMAT, SCF_DEFAULT, reinterpret_cast<LPARAM>(&textFormat));
+
+ bgColor = background;
+ sendMessage(EM_SETBKGNDCOLOR, 0, static_cast<LPARAM>(bgColor));
+}
+
}
=== modified file 'win32/WinUtil.cpp'
--- win32/WinUtil.cpp 2011-10-26 11:38:50 +0000
+++ win32/WinUtil.cpp 2011-11-18 18:27:17 +0000
@@ -256,8 +256,6 @@
xRichTextBox.exStyle = WS_EX_CLIENTEDGE;
xRichTextBox.font = font;
- xRichTextBox.foregroundColor = textColor;
- xRichTextBox.backgroundColor = bgColor;
xTabs.font = font;
@@ -874,14 +872,13 @@
ts.style = WS_CHILD | WS_VISIBLE | ES_READONLY;
ts.exStyle = 0;
ts.location = dwt::Rectangle(margins, dwt::Point(maxWidth, 0));
- ts.foregroundColor = dwt::Color::predefined(COLOR_INFOTEXT);
- ts.backgroundColor = dwt::Color::predefined(COLOR_INFOBK);
createBox();
}
private:
void createBox() {
box = addChild(ts);
+ box->setColor(dwt::Color::predefined(COLOR_INFOTEXT), dwt::Color::predefined(COLOR_INFOBK));
// let the control figure out what the best size is
box->onRaw([this](WPARAM, LPARAM l) { return resize(l); }, dwt::Message(WM_NOTIFY, EN_REQUESTRESIZE));