linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #05017
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2744: apply new style settings to transfer bars
------------------------------------------------------------
revno: 2744
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2011-12-23 17:21:08 +0100
message:
apply new style settings to transfer bars
modified:
dwt/include/dwt/widgets/Table.h
win32/MainWindow.cpp
win32/TransferView.cpp
win32/WinUtil.cpp
win32/WinUtil.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/widgets/Table.h'
--- dwt/include/dwt/widgets/Table.h 2011-12-14 17:18:00 +0000
+++ dwt/include/dwt/widgets/Table.h 2011-12-23 16:21:08 +0000
@@ -445,6 +445,12 @@
std::pair<int, int> hitTest(const ScreenCoordinate& pt);
+ /// Returns the rect for the item per code (wraps ListView_GetItemRect)
+ Rectangle getRect(int item, int code);
+
+ /// Returns the rect for the subitem item per code (wraps ListView_GetSubItemRect)
+ Rectangle getRect(int item, int subitem, int code);
+
/// Actually creates the Data Grid Control
/** You should call WidgetFactory::createTable if you instantiate class
* directly. <br>
@@ -464,12 +470,6 @@
virtual ~Table() {
}
- // Returns the rect for the item per code (wraps ListView_GetItemRect)
- Rectangle getRect( int item, int code );
-
- // Returns the rect for the subitem item per code (wraps ListView_GetSubItemRect)
- Rectangle getRect( int item, int subitem, int code );
-
private:
friend class ChainingDispatcher;
static const TCHAR windowClass[];
=== modified file 'win32/MainWindow.cpp'
--- win32/MainWindow.cpp 2011-12-22 22:14:45 +0000
+++ win32/MainWindow.cpp 2011-12-23 16:21:08 +0000
@@ -1083,6 +1083,8 @@
auto prevGeoFormat = SETTING(COUNTRY_FORMAT);
auto prevFont = SETTING(MAIN_FONT);
+ auto prevUploadFont = SETTING(UPLOAD_FONT);
+ auto prevDownloadFont = SETTING(DOWNLOAD_FONT);
auto prevTray = BOOLSETTING(ALWAYS_TRAY);
auto prevSortFavUsersFirst = BOOLSETTING(SORT_FAVUSERS_FIRST);
@@ -1124,6 +1126,12 @@
mainMenu->setFont(WinUtil::font);
::DrawMenuBar(handle());
}
+ if(SETTING(UPLOAD_FONT) != prevUploadFont) {
+ WinUtil::updateUploadFont();
+ }
+ if(SETTING(DOWNLOAD_FONT) != prevDownloadFont) {
+ WinUtil::updateDownloadFont();
+ }
bool newColors = false;
if(static_cast<COLORREF>(SETTING(TEXT_COLOR)) != WinUtil::textColor) {
=== modified file 'win32/TransferView.cpp'
--- win32/TransferView.cpp 2011-12-22 22:14:45 +0000
+++ win32/TransferView.cpp 2011-12-23 16:21:08 +0000
@@ -301,9 +301,9 @@
}
}
-static inline void drawProgress(HDC hdc, const dwt::Rectangle& rcItem, int item, int column, const tstring& text, double pos, COLORREF fgColor) {
+namespace { void drawProgress(HDC hdc, const dwt::Rectangle& rcItem, int item, int column, const tstring& text, double pos, bool download) {
// draw something nice...
- COLORREF barBase = fgColor;
+ COLORREF barBase = download ? SETTING(DOWNLOAD_BG_COLOR) : SETTING(UPLOAD_BG_COLOR);
COLORREF bgBase = WinUtil::bgColor;
int mod = (HLS_L(RGB2HLS(bgBase)) >= 128) ? -30 : 30;
@@ -313,66 +313,84 @@
// Two shades of the background color
COLORREF bgPal[2] = { HLS_TRANSFORM(bgBase, mod, 0), HLS_TRANSFORM(bgBase, mod/2, 0) };
+ dwt::FreeCanvas canvas(hdc);
+
dwt::Rectangle rc = rcItem;
// draw background
- HGDIOBJ oldbr = ::SelectObject(hdc, ::CreateSolidBrush(bgPal[1]));
- HGDIOBJ oldpen = ::SelectObject(hdc, ::CreatePen(PS_SOLID, 0, bgPal[0]));
-
- // TODO Don't draw where the finished part will be drawn
- ::Rectangle(hdc, rc.left(), rc.top() - 1, rc.right(), rc.bottom());
+
+ {
+ dwt::Brush brush(::CreateSolidBrush(bgPal[1]));
+ auto selectBg(canvas.select(brush));
+
+ dwt::Pen pen(bgPal[0]);
+ auto selectPen(canvas.select(pen));
+
+ // TODO Don't draw where the finished part will be drawn
+ canvas.rectangle(rc.left(), rc.top() - 1, rc.right(), rc.bottom());
+ }
rc.pos.x += 1;
rc.size.x -= 2;
rc.size.y -= 1;
- long w = rc.width();
-
- ::DeleteObject(::SelectObject(hdc, ::CreateSolidBrush(barPal[1])));
- ::DeleteObject(::SelectObject(hdc, ::CreatePen(PS_SOLID, 0, barPal[0])));
-
- // "Finished" part
- rc.size.x = (int) (w * pos);
-
- ::Rectangle(hdc, rc.left(), rc.top(), rc.right(), rc.bottom());
-
- RECT textRect = rc;
-
- // draw progressbar highlight
- if(rc.width()>2) {
- ::DeleteObject(::SelectObject(hdc, ::CreatePen(PS_SOLID, 1, barPal[2])));
-
- rc.pos.y += 2;
- ::MoveToEx(hdc, rc.left()+1, rc.top(), (LPPOINT)NULL);
- ::LineTo(hdc, rc.right()-2, rc.top());
+ dwt::Rectangle textRect;
+
+ {
+ dwt::Brush brush(::CreateSolidBrush(barPal[1]));
+ auto selectBg(canvas.select(brush));
+
+ {
+ dwt::Pen pen(barPal[0]);
+ auto selectPen(canvas.select(pen));
+
+ // "Finished" part
+ rc.size.x = (int) (rc.width() * pos);
+
+ canvas.rectangle(rc.left(), rc.top(), rc.right(), rc.bottom());
+ }
+
+ textRect = rc;
+
+ // draw progressbar highlight
+ if(rc.width() > 2) {
+ dwt::Pen pen(barPal[2], dwt::Pen::Solid, 1);
+ auto selectPen(canvas.select(pen));
+
+ rc.pos.y += 2;
+ canvas.moveTo(rc.left() + 1, rc.top());
+ canvas.lineTo(rc.right() - 2, rc.top());
+ }
}
// draw status text
- ::DeleteObject(::SelectObject(hdc, oldpen));
- ::DeleteObject(::SelectObject(hdc, oldbr));
-
- int oldMode = ::SetBkMode(hdc, TRANSPARENT);
-
- textRect.left += 6;
-
- long left = textRect.left;
-
- // todo use dwt's canvas and put this there
+
+ canvas.setBkMode(true);
+ auto& font = download ? WinUtil::downloadFont : WinUtil::uploadFont;
+ if(!font.get()) {
+ font = WinUtil::font;
+ }
+ auto selectFont(canvas.select(*font));
+
+ textRect.pos.x += 6;
+
+ long left = textRect.left();
+
TEXTMETRIC tm;
- ::GetTextMetrics(hdc, &tm);
- long top = textRect.top + (textRect.bottom - textRect.top - tm.tmHeight) / 2;
-
- ::SetTextColor(hdc, RGB(255, 255, 255));
- ::ExtTextOut(hdc, left, top, ETO_CLIPPED, &textRect, text.c_str(), text.size(), NULL);
-
- textRect.left = textRect.right;
- textRect.right = rcItem.right();
-
- ::SetTextColor(hdc, WinUtil::textColor);
- ::ExtTextOut(hdc, left, top, ETO_CLIPPED, &textRect, text.c_str(), text.size(), NULL);
-
- ::SetBkMode(hdc, oldMode);
-}
+ canvas.getTextMetrics(tm);
+ long top = textRect.top() + (textRect.bottom() - textRect.top() - tm.tmHeight) / 2;
+
+ canvas.setTextColor(download ? SETTING(DOWNLOAD_TEXT_COLOR) : SETTING(UPLOAD_TEXT_COLOR));
+ /// @todo ExtTextOut to dwt
+ ::RECT r = textRect;
+ ::ExtTextOut(hdc, left, top, ETO_CLIPPED, &r, text.c_str(), text.size(), NULL);
+
+ r.left = r.right;
+ r.right = rcItem.right();
+
+ canvas.setTextColor(WinUtil::textColor);
+ ::ExtTextOut(hdc, left, top, ETO_CLIPPED, &r, text.c_str(), text.size(), NULL);
+} }
LRESULT TransferView::handleCustomDraw(NMLVCUSTOMDRAW& data) {
switch(data.nmcd.dwDrawStage) {
@@ -384,39 +402,23 @@
case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
{
- int item = static_cast<int>(data.nmcd.dwItemSpec);
int column = data.iSubItem;
// Let's draw a box if needed...
if(data.nmcd.hdr.hwndFrom == connections->handle() && column == CONNECTION_COLUMN_STATUS) {
- HDC hdc = data.nmcd.hdc;
- ConnectionInfo* ci = reinterpret_cast<ConnectionInfo*>(data.nmcd.lItemlParam);
-
- if(ci->status == ConnectionInfo::STATUS_RUNNING && ci->chunk > 0 && ci->chunkPos >= 0) {
- const tstring& text = ci->columns[column];
-
- RECT r;
- ListView_GetSubItemRect( connections->handle(), item, column, LVIR_BOUNDS, &r );
-
- double pos = static_cast<double>(ci->chunkPos) / ci->chunk;
-
- drawProgress(hdc, dwt::Rectangle(r), item, column, text, pos, ci->download ? SETTING(DOWNLOAD_BG_COLOR) : SETTING(UPLOAD_BG_COLOR));
-
+ const auto& info = *reinterpret_cast<ConnectionInfo*>(data.nmcd.lItemlParam);
+ if(info.status == ConnectionInfo::STATUS_RUNNING && info.chunk > 0 && info.chunkPos >= 0) {
+ int item = static_cast<int>(data.nmcd.dwItemSpec);
+ drawProgress(data.nmcd.hdc, connections->getRect(item, column, LVIR_BOUNDS), item, column,
+ info.getText(column), static_cast<double>(info.chunkPos) / static_cast<double>(info.chunk), info.download);
return CDRF_SKIPDEFAULT;
}
} else if(data.nmcd.hdr.hwndFrom == downloads->handle() && column == DOWNLOAD_COLUMN_STATUS) {
- HDC hdc = data.nmcd.hdc;
- DownloadInfo* di = reinterpret_cast<DownloadInfo*>(data.nmcd.lItemlParam);
- if(di->size > 0 && di->done >= 0) {
- const tstring& text = di->columns[column];
-
- RECT r;
- ListView_GetSubItemRect( downloads->handle(), item, column, LVIR_BOUNDS, &r );
-
- double pos = static_cast<double>(di->done) / di->size;
-
- drawProgress(hdc, dwt::Rectangle(r), item, column, text, pos, SETTING(DOWNLOAD_BG_COLOR));
-
+ const auto& info = *reinterpret_cast<DownloadInfo*>(data.nmcd.lItemlParam);
+ if(info.size > 0 && info.done >= 0) {
+ int item = static_cast<int>(data.nmcd.dwItemSpec);
+ drawProgress(data.nmcd.hdc, downloads->getRect(item, column, LVIR_BOUNDS), item, column,
+ info.getText(column), static_cast<double>(info.done) / static_cast<double>(info.size), true);
return CDRF_SKIPDEFAULT;
}
}
=== modified file 'win32/WinUtil.cpp'
--- win32/WinUtil.cpp 2011-12-22 22:14:45 +0000
+++ win32/WinUtil.cpp 2011-12-23 16:21:08 +0000
@@ -102,6 +102,8 @@
COLORREF WinUtil::textColor = 0;
COLORREF WinUtil::bgColor = 0;
dwt::FontPtr WinUtil::font;
+dwt::FontPtr WinUtil::uploadFont;
+dwt::FontPtr WinUtil::downloadFont;
unordered_map<string, dwt::FontPtr> WinUtil::userMatchFonts;
dwt::ImageListPtr WinUtil::fileImages;
dwt::ImageListPtr WinUtil::userImages;
@@ -152,7 +154,8 @@
}
initFont();
-
+ updateUploadFont();
+ updateDownloadFont();
updateUserMatchFonts();
fileImages = dwt::ImageListPtr(new dwt::ImageList(dwt::Point(16, 16)));
@@ -361,9 +364,7 @@
}
void WinUtil::initFont() {
- LOGFONT lf;
- decodeFont(Text::toT(SETTING(MAIN_FONT)), lf);
- font.reset(new dwt::Font(lf));
+ updateFont(font, SettingsManager::MAIN_FONT);
initSeeds();
}
@@ -416,6 +417,17 @@
}
}
+void WinUtil::updateFont(dwt::FontPtr& font, int setting) {
+ auto text = SettingsManager::getInstance()->get(static_cast<SettingsManager::StrSetting>(setting));
+ if(text.empty()) {
+ font.reset();
+ } else {
+ LOGFONT lf;
+ decodeFont(Text::toT(text), lf);
+ font.reset(new dwt::Font(lf));
+ }
+}
+
void WinUtil::updateUserMatchFonts() {
userMatchFonts.clear();
@@ -429,6 +441,14 @@
}
}
+void WinUtil::updateUploadFont() {
+ updateFont(uploadFont, SettingsManager::UPLOAD_FONT);
+}
+
+void WinUtil::updateDownloadFont() {
+ updateFont(downloadFont, SettingsManager::DOWNLOAD_FONT);
+}
+
void WinUtil::setStaticWindowState(const string& id, bool open) {
mainWindow->setStaticWindowState(id, open);
}
=== modified file 'win32/WinUtil.h'
--- win32/WinUtil.h 2011-12-18 15:37:20 +0000
+++ win32/WinUtil.h 2011-12-23 16:21:08 +0000
@@ -124,6 +124,8 @@
static COLORREF textColor;
static COLORREF bgColor;
static dwt::FontPtr font;
+ static dwt::FontPtr uploadFont;
+ static dwt::FontPtr downloadFont;
static unordered_map<string, dwt::FontPtr> userMatchFonts;
static tstring commands;
static dwt::ImageListPtr fileImages;
@@ -170,8 +172,12 @@
static void initFont();
static tstring encodeFont(LOGFONT const& font);
static void decodeFont(const tstring& setting, LOGFONT &dest);
+ static void updateFont(dwt::FontPtr& font, int setting);
static void updateUserMatchFonts();
+ static void updateUploadFont();
+ static void updateDownloadFont();
+
static void setStaticWindowState(const string& id, bool open);
static bool checkNick();