linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #04823
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2689: set default colors on rich edits
------------------------------------------------------------
revno: 2689
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Tue 2011-11-22 19:01:45 +0100
message:
set default colors on rich edits
modified:
dwt/src/widgets/RichTextBox.cpp
win32/StylesPage.cpp
win32/StylesPage.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 'dwt/src/widgets/RichTextBox.cpp'
--- dwt/src/widgets/RichTextBox.cpp 2011-11-20 18:04:00 +0000
+++ dwt/src/widgets/RichTextBox.cpp 2011-11-22 18:01:45 +0000
@@ -64,6 +64,8 @@
BaseType::create(cs);
setFont(cs.font);
+ setColor(Color::predefined(COLOR_WINDOWTEXT), Color::predefined(COLOR_WINDOW));
+
setScrollBarHorizontally(cs.scrollBarHorizontallyFlag);
setScrollBarVertically(cs.scrollBarVerticallyFlag);
=== modified file 'win32/StylesPage.cpp'
--- win32/StylesPage.cpp 2011-11-21 19:14:55 +0000
+++ win32/StylesPage.cpp 2011-11-22 18:01:45 +0000
@@ -140,9 +140,6 @@
add(T_("Downloads"), IDH_SETTINGS_STYLES_DOWNLOADS, GROUP_TRANSFERS,
SettingsManager::DOWNLOAD_FONT, SettingsManager::DOWNLOAD_TEXT_COLOR, SettingsManager::DOWNLOAD_BG_COLOR);
- globalData->customFont = true;
- globalData->customTextColor = true;
- globalData->customBgColor = true;
update(globalData);
handleSelectionChanged();
@@ -178,8 +175,8 @@
customBgColor(!SettingsManager::getInstance()->isDefault(static_cast<SettingsManager::IntSetting>(bgColorSetting))),
bgColor(SettingsManager::getInstance()->get(static_cast<SettingsManager::IntSetting>(bgColorSetting)))
{
- WinUtil::decodeFont(Text::toT(SettingsManager::getInstance()->get(static_cast<SettingsManager::StrSetting>(fontSetting))), logFont);
- updateFont();
+ makeFont(font, SettingsManager::getInstance()->get(static_cast<SettingsManager::StrSetting>(fontSetting)));
+ makeFont(defaultFont, SettingsManager::getInstance()->getDefault(static_cast<SettingsManager::StrSetting>(fontSetting)));
}
const tstring& StylesPage::Data::getText(int) const {
@@ -187,20 +184,28 @@
}
int StylesPage::Data::getStyle(HFONT& font, COLORREF& textColor, COLORREF& bgColor, int) const {
- if(customFont) {
- font = this->font->handle();
+ auto f = getFont();
+ if(f.first) {
+ font = f.first->handle();
}
+
auto color = getTextColor();
if(color >= 0) {
textColor = color;
}
+
color = getBgColor();
if(color >= 0) {
bgColor = color;
}
+
return CDRF_NEWFONT;
}
+const StylesPage::Data::Font& StylesPage::Data::getFont() const {
+ return customFont ? font : defaultFont;
+}
+
COLORREF StylesPage::Data::getTextColor() const {
return customTextColor ? textColor : SettingsManager::getInstance()->getDefault(static_cast<SettingsManager::IntSetting>(textColorSetting));
}
@@ -209,13 +214,9 @@
return customBgColor ? bgColor : SettingsManager::getInstance()->getDefault(static_cast<SettingsManager::IntSetting>(bgColorSetting));
}
-void StylesPage::Data::updateFont() {
- font.reset(customFont ? new dwt::Font(logFont) : nullptr);
-}
-
void StylesPage::Data::write() {
if(customFont) {
- SettingsManager::getInstance()->set(static_cast<SettingsManager::StrSetting>(fontSetting), Text::fromT(WinUtil::encodeFont(logFont)));
+ SettingsManager::getInstance()->set(static_cast<SettingsManager::StrSetting>(fontSetting), Text::fromT(WinUtil::encodeFont(font.second)));
} else {
SettingsManager::getInstance()->unset(static_cast<SettingsManager::StrSetting>(fontSetting));
}
@@ -233,6 +234,13 @@
}
}
+void StylesPage::Data::makeFont(Font& dest, const string& setting) {
+ if(!setting.empty()) {
+ WinUtil::decodeFont(Text::toT(setting), dest.second);
+ dest.first.reset(new dwt::Font(dest.second));
+ }
+}
+
void StylesPage::handleSelectionChanged() {
auto data = table->getSelectedData();
@@ -245,21 +253,19 @@
preview->setVisible(enable);
preview->getParent()->layout();
- bool customizable = data && data != globalData;
-
enable = data && data->customFont;
customFont->setChecked(enable);
- customFont->setEnabled(customizable);
+ customFont->setEnabled(data);
font->setEnabled(enable);
enable = data && data->customTextColor;
customTextColor->setChecked(enable);
- customTextColor->setEnabled(customizable);
+ customTextColor->setEnabled(data);
textColor->setEnabled(enable);
enable = data && data->customBgColor;
customBgColor->setChecked(enable);
- customBgColor->setEnabled(customizable);
+ customBgColor->setEnabled(data);
bgColor->setEnabled(enable);
}
@@ -283,7 +289,6 @@
void StylesPage::handleCustomFont() {
auto data = table->getSelectedData();
data->customFont = customFont->getChecked();
- data->updateFont();
update(data);
handleSelectionChanged();
}
@@ -295,8 +300,12 @@
options.underline = false;
options.color = false;
options.bgColor = data->bgColor;
- if(FontDialog(this).open(data->logFont, data->textColor, &options)) {
- data->updateFont();
+ if(!data->font.first) {
+ // initialize the LOGFONT structure.
+ data->font.second = data->defaultFont.first ? data->defaultFont.second : globalData->getFont().second;
+ }
+ if(FontDialog(this).open(data->font.second, data->textColor, &options)) {
+ data->font.first.reset(new dwt::Font(data->font.second));
update(data);
}
}
@@ -336,8 +345,8 @@
void StylesPage::update(Data* const data) {
if(data == globalData) {
- table->setFont(globalData->font);
- table->setColor(globalData->textColor, globalData->bgColor);
+ table->setFont(globalData->getFont().first);
+ table->setColor(globalData->getTextColor(), globalData->getBgColor());
table->Control::redraw(true);
} else {
table->update(data);
@@ -347,9 +356,10 @@
}
void StylesPage::updatePreview(Data* const data) {
- preview->setFont(data->customFont ? data->font : globalData->font);
+ auto font = data->getFont();
+ preview->setFont(font.first ? font.first : globalData->getFont().first);
auto textColor = data->getTextColor();
auto bgColor = data->getBgColor();
- preview->setColor((textColor >= 0) ? textColor : globalData->textColor, (bgColor >= 0) ? bgColor : globalData->bgColor);
+ preview->setColor((textColor >= 0) ? textColor : globalData->getTextColor(), (bgColor >= 0) ? bgColor : globalData->getBgColor());
preview->redraw(true);
}
=== modified file 'win32/StylesPage.h'
--- win32/StylesPage.h 2011-11-16 18:12:07 +0000
+++ win32/StylesPage.h 2011-11-22 18:01:45 +0000
@@ -45,17 +45,18 @@
};
class Data {
+ typedef pair<dwt::FontPtr, LOGFONT> Font;
+
public:
Data(tstring&& text, unsigned helpId, int fontSetting, int textColorSetting, int bgColorSetting);
const tstring& getText(int) const;
int getStyle(HFONT& font, COLORREF& textColor, COLORREF& bgColor, int) const;
+ const Font& getFont() const;
COLORREF getTextColor() const;
COLORREF getBgColor() const;
- void updateFont();
-
void write();
const tstring text;
@@ -66,14 +67,17 @@
const int bgColorSetting;
bool customFont;
- dwt::FontPtr font;
- LOGFONT logFont;
+ Font font;
+ Font defaultFont;
bool customTextColor;
COLORREF textColor;
bool customBgColor;
COLORREF bgColor;
+
+ private:
+ static void makeFont(Font& dest, const string& setting);
};
Data* globalData;
=== modified file 'win32/WinUtil.cpp'
--- win32/WinUtil.cpp 2011-11-20 16:59:46 +0000
+++ win32/WinUtil.cpp 2011-11-22 18:01:45 +0000
@@ -139,7 +139,7 @@
bgColor = SETTING(BACKGROUND_COLOR);
bgBrush = dwt::BrushPtr(new dwt::Brush(bgColor));
- if(SettingsManager::getInstance()->isDefault(SettingsManager::MAIN_FONT)) {
+ {
NONCLIENTMETRICS metrics = { sizeof(NONCLIENTMETRICS) };
::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &metrics, 0);
SettingsManager::getInstance()->setDefault(SettingsManager::MAIN_FONT, Text::fromT(encodeFont(metrics.lfMessageFont)));