linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #04811
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2681: add groups to the styles preview list
------------------------------------------------------------
revno: 2681
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Wed 2011-11-16 19:12:07 +0100
message:
add groups to the styles preview list
modified:
dwt/include/dwt/aspects/CustomDraw.h
dwt/include/dwt/widgets/Table.h
dwt/src/widgets/Table.cpp
win32/FavHubsFrame.cpp
win32/StylesPage.cpp
win32/StylesPage.h
win32/TypedTable.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 'dwt/include/dwt/aspects/CustomDraw.h'
--- dwt/include/dwt/aspects/CustomDraw.h 2011-11-07 22:11:39 +0000
+++ dwt/include/dwt/aspects/CustomDraw.h 2011-11-16 18:12:07 +0000
@@ -42,9 +42,14 @@
public:
void onCustomDraw(std::function<LRESULT (DataType&)> f) {
- W().setCallback(Message(WM_NOTIFY, NM_CUSTOMDRAW), [f](const MSG& msg, LRESULT& ret) -> bool {
+ W().addCallback(Message(WM_NOTIFY, NM_CUSTOMDRAW), [f](const MSG& msg, LRESULT& ret) -> bool {
auto& data = *reinterpret_cast<DataType*>(msg.lParam);
- ret = f(data);
+ auto newRet = f(data);
+ /* make sure multiple custom draw handlers can be applied to the same control without
+ stepping on each other. */
+ if(!ret || ret == CDRF_DODEFAULT) {
+ ret = newRet;
+ }
return true;
});
}
=== modified file 'dwt/include/dwt/widgets/Table.h'
--- dwt/include/dwt/widgets/Table.h 2011-11-14 19:24:14 +0000
+++ dwt/include/dwt/widgets/Table.h 2011-11-16 18:12:07 +0000
@@ -292,10 +292,8 @@
bool isGrouped() const { return grouped; }
/** tell dwt to take over painting of group headers in order to allow custom colors that match
- * the background. the theme will be respected.
- * @param bgColor the background of the current widget.
- */
- void handleGroupDraw(COLORREF bgColor);
+ the background. the theme will be respected. */
+ void handleGroupDraw();
/// Returns the checked state of the given row
/** A list view can have checkboxes in each row, if the checkbox for the given
@@ -505,6 +503,7 @@
static int CALLBACK compareFunc( LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort );
static int CALLBACK compareFuncCallback( LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort );
+ void setIndex(LVITEM& item, int index) const;
void updateArrow();
#ifdef PORT_ME
// Private validate function, this ones returns the "read only" property of the list
=== modified file 'dwt/src/widgets/Table.cpp'
--- dwt/src/widgets/Table.cpp 2011-11-07 22:11:39 +0000
+++ dwt/src/widgets/Table.cpp 2011-11-16 18:12:07 +0000
@@ -167,16 +167,7 @@
lvi.lParam = lPar;
- if(grouped) {
- dwtassert(index >= 0, _T("Table::insert in grouped mode: index must be >= 0 since it is a group id"));
- lvi.mask |= LVIF_GROUPID;
- lvi.iGroupId = index;
-
- } else {
- if(index == -1)
- index = size();
- lvi.iItem = index;
- }
+ setIndex(lvi, index);
int ret = ListView_InsertItem(handle(), &lvi);
if(ret == - 1) {
@@ -200,15 +191,26 @@
int Table::insert(int mask, int i, LPCTSTR text, UINT state, UINT stateMask, int image, LPARAM lparam) {
LVITEM item = { mask };
- item.iItem = i;
item.state = state;
item.stateMask = stateMask;
item.pszText = const_cast<LPTSTR>(text);
item.iImage = image;
item.lParam = lparam;
+ setIndex(item, i);
return ListView_InsertItem(handle(), &item);
}
+void Table::setIndex(LVITEM& item, int index) const {
+ if(grouped) {
+ dwtassert(index >= 0, _T("Table::insert in grouped mode: index must be >= 0 since it is a group id"));
+ item.mask |= LVIF_GROUPID;
+ item.iGroupId = index;
+
+ } else {
+ item.iItem = (index == -1) ? size() : index;
+ }
+}
+
void Table::onColumnClick(HeaderF f) {
addCallback(Message(WM_NOTIFY, LVN_COLUMNCLICK), [f](const MSG& msg, LRESULT&) -> bool {
f(reinterpret_cast<LPNMLISTVIEW>(msg.lParam)->iSubItem);
@@ -324,19 +326,20 @@
return tstring();
}
-void Table::handleGroupDraw(COLORREF bgColor) {
+void Table::handleGroupDraw() {
theme.load(VSCLASS_LISTVIEW, this);
- onCustomDraw([this, bgColor](NMLVCUSTOMDRAW& data) -> LRESULT {
+ onCustomDraw([this](NMLVCUSTOMDRAW& data) -> LRESULT {
if(!grouped || data.dwItemType != LVCDI_GROUP)
return CDRF_DODEFAULT;
switch(data.nmcd.dwDrawStage) {
case CDDS_PREPAINT:
{
// got a group! get the current theme text color and compare it to the bg.
- COLORREF color = theme ? theme.getColor(LVP_GROUPHEADER, LVGH_OPEN, TMT_HEADING1TEXTCOLOR) : NaC;
+ auto color = theme ? theme.getColor(LVP_GROUPHEADER, LVGH_OPEN, TMT_HEADING1TEXTCOLOR) : NaC;
if(color == NaC)
color = 0; // assume black
+ auto bgColor = ListView_GetBkColor(handle());
if(abs(GetRValue(color) + GetGValue(color) + GetBValue(color)
- GetRValue(bgColor) - GetGValue(bgColor) - GetBValue(bgColor)) < 300)
{
=== modified file 'win32/FavHubsFrame.cpp'
--- win32/FavHubsFrame.cpp 2011-05-04 19:32:00 +0000
+++ win32/FavHubsFrame.cpp 2011-11-16 18:12:07 +0000
@@ -80,7 +80,7 @@
hubs->onDblClicked([this] { handleDoubleClick(); });
hubs->onKeyDown([this](int c) { return handleKeyDown(c); });
hubs->onContextMenu([this](const dwt::ScreenCoordinate &sc) { return handleContextMenu(sc); });
- hubs->handleGroupDraw(WinUtil::bgColor);
+ hubs->handleGroupDraw();
}
{
=== modified file 'win32/StylesPage.cpp'
--- win32/StylesPage.cpp 2011-11-15 19:05:59 +0000
+++ win32/StylesPage.cpp 2011-11-16 18:12:07 +0000
@@ -72,6 +72,7 @@
seed.style &= ~LVS_SHOWSELALWAYS;
seed.style |= LVS_SINGLESEL | LVS_NOCOLUMNHEADER;
table = cur->addChild(Table::Seed(seed));
+ table->handleGroupDraw();
}
{
@@ -113,18 +114,23 @@
WinUtil::makeColumns(table, columns, COLUMN_LAST);
- auto add = [this](tstring&& text, unsigned helpId, int fontSetting, int textColorSetting, int bgColorSetting) -> Data* {
+ TStringList groups(GROUP_LAST);
+ groups[GROUP_GENERAL] = T_("General");
+ groups[GROUP_TRANSFERS] = T_("Transfers");
+ table->setGroups(groups);
+
+ auto add = [this](tstring&& text, unsigned helpId, int group, int fontSetting, int textColorSetting, int bgColorSetting) -> Data* {
auto data = new Data(forward<tstring>(text), helpId, fontSetting, textColorSetting, bgColorSetting);
- table->insert(data);
+ table->insert(group, data);
return data;
};
- globalData = add(T_("Global application style"), 0/*IDH_SETTINGS_STYLES_GLOBAL*/, SettingsManager::MAIN_FONT,
- SettingsManager::TEXT_COLOR, SettingsManager::BACKGROUND_COLOR);
- add(T_("Uploads"), 0/*IDH_SETTINGS_STYLES_UPLOADS*/, SettingsManager::UPLOAD_FONT,
- SettingsManager::UPLOAD_TEXT_COLOR, SettingsManager::UPLOAD_BG_COLOR);
- add(T_("Downloads"), 0/*IDH_SETTINGS_STYLES_DOWNLOADS*/, SettingsManager::DOWNLOAD_FONT,
- SettingsManager::DOWNLOAD_TEXT_COLOR, SettingsManager::DOWNLOAD_BG_COLOR);
+ globalData = add(T_("Global application style"), 0/*IDH_SETTINGS_STYLES_GLOBAL*/, GROUP_GENERAL,
+ SettingsManager::MAIN_FONT, SettingsManager::TEXT_COLOR, SettingsManager::BACKGROUND_COLOR);
+ add(T_("Uploads"), 0/*IDH_SETTINGS_STYLES_UPLOADS*/, GROUP_TRANSFERS,
+ SettingsManager::UPLOAD_FONT, SettingsManager::UPLOAD_TEXT_COLOR, SettingsManager::UPLOAD_BG_COLOR);
+ add(T_("Downloads"), 0/*IDH_SETTINGS_STYLES_DOWNLOADS*/, GROUP_TRANSFERS,
+ SettingsManager::DOWNLOAD_FONT, SettingsManager::DOWNLOAD_TEXT_COLOR, SettingsManager::DOWNLOAD_BG_COLOR);
globalData->customFont = true;
globalData->customTextColor = true;
=== modified file 'win32/StylesPage.h'
--- win32/StylesPage.h 2011-11-15 19:05:59 +0000
+++ win32/StylesPage.h 2011-11-16 18:12:07 +0000
@@ -33,9 +33,17 @@
private:
enum {
COLUMN_TEXT,
+
COLUMN_LAST
};
+ enum {
+ GROUP_GENERAL,
+ GROUP_TRANSFERS,
+
+ GROUP_LAST
+ };
+
class Data {
public:
Data(tstring&& text, unsigned helpId, int fontSetting, int textColorSetting, int bgColorSetting);
@@ -51,11 +59,11 @@
void write();
const tstring text;
- unsigned helpId;
+ const unsigned helpId;
- int fontSetting;
- int textColorSetting;
- int bgColorSetting;
+ const int fontSetting;
+ const int textColorSetting;
+ const int bgColorSetting;
bool customFont;
dwt::FontPtr font;
=== modified file 'win32/TypedTable.h'
--- win32/TypedTable.h 2011-11-16 16:57:31 +0000
+++ win32/TypedTable.h 2011-11-16 18:12:07 +0000
@@ -277,7 +277,7 @@
return CDRF_NOTIFYITEMDRAW;
}
- if((data.nmcd.dwDrawStage & CDDS_ITEMPREPAINT) == CDDS_ITEMPREPAINT) {
+ if((data.nmcd.dwDrawStage & CDDS_ITEMPREPAINT) == CDDS_ITEMPREPAINT && data.dwItemType == LVCDI_ITEM && data.nmcd.lItemlParam) {
HFONT font = nullptr;
auto ret = reinterpret_cast<ContentType*>(data.nmcd.lItemlParam)->getStyle(font, data.clrText, data.clrTextBk,
((data.nmcd.dwDrawStage & CDDS_SUBITEM) == CDDS_SUBITEM) ? data.iSubItem : -1);