linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #03160
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2410: auto-restore the previous bkmode value
------------------------------------------------------------
revno: 2410
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Tue 2011-02-01 22:33:33 +0100
message:
auto-restore the previous bkmode value
modified:
dwt/include/dwt/CanvasClasses.h
dwt/src/CanvasClasses.cpp
dwt/src/widgets/FontDialog.cpp
dwt/src/widgets/Menu.cpp
dwt/src/widgets/TabView.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/CanvasClasses.h'
--- dwt/include/dwt/CanvasClasses.h 2011-01-27 22:57:05 +0000
+++ dwt/include/dwt/CanvasClasses.h 2011-02-01 21:33:33 +0000
@@ -210,6 +210,16 @@
HGDIOBJ h;
};
+ class BkMode {
+ public:
+ BkMode(Canvas& canvas_, int mode);
+ ~BkMode();
+
+ private:
+ Canvas& canvas;
+ int prevMode;
+ };
+
public:
/** select a new resource (brush / font / pen / etc).
* @return object that restores the previous resource when destroyed.
@@ -396,11 +406,10 @@
*/
COLORREF setBkColor( COLORREF crColor );
- /// Sets the background mode
- /** Can either be transparent (true) or opaque (false). Returns true if the
- * previous background mode was transparent, false if it was opaque
- */
- bool setBkMode( bool transparent = false );
+ /** Sets the background mode, see the ::SetBkMode doc for more information.
+ * @return object that restores the previous bkmode value when destroyed.
+ */
+ BkMode setBkMode(bool transparent);
/// Gets the background color for the this Canvas
/** Gets the background color for extTextOut() calls.
=== modified file 'dwt/src/CanvasClasses.cpp'
--- dwt/src/CanvasClasses.cpp 2011-01-27 22:57:05 +0000
+++ dwt/src/CanvasClasses.cpp 2011-02-01 21:33:33 +0000
@@ -226,9 +226,18 @@
return ::SetBkColor( itsHdc, crColor );
}
-bool Canvas::setBkMode( bool transparent )
+Canvas::BkMode::BkMode(Canvas& canvas_, int mode) :
+canvas(canvas_), prevMode(::SetBkMode(canvas.handle(), mode))
{
- return ::SetBkMode( itsHdc, transparent ? TRANSPARENT : OPAQUE ) == TRANSPARENT;
+}
+
+Canvas::BkMode::~BkMode() {
+ if(prevMode)
+ ::SetBkMode(canvas.handle(), prevMode);
+}
+
+Canvas::BkMode Canvas::setBkMode(bool transparent) {
+ return BkMode(*this, transparent ? TRANSPARENT : OPAQUE);
}
COLORREF Canvas::getBkColor()
=== modified file 'dwt/src/widgets/FontDialog.cpp'
--- dwt/src/widgets/FontDialog.cpp 2011-01-27 22:57:05 +0000
+++ dwt/src/widgets/FontDialog.cpp 2011-02-01 21:33:33 +0000
@@ -86,7 +86,7 @@
by ourselves. thanks to Wine (dlls/comdlg32/fontdlg.c) for showing how this is done. */
PaintCanvas canvas(hwnd);
- bool oldMode = canvas.setBkMode(true);
+ auto bkMode(canvas.setBkMode(true));
HWND box = ::GetDlgItem(hwnd, stc5);
@@ -108,8 +108,6 @@
auto select(canvas.select(font));
canvas.drawText(util::win32::getWindowText(box), rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
-
- canvas.setBkMode(oldMode);
return 1;
}
=== modified file 'dwt/src/widgets/Menu.cpp'
--- dwt/src/widgets/Menu.cpp 2011-01-27 22:57:05 +0000
+++ dwt/src/widgets/Menu.cpp 2011-02-01 21:33:33 +0000
@@ -474,7 +474,7 @@
COLORREF oldColor = canvas.setTextColor( colors.titleText );
// set background mode to transparent
- bool oldMode = canvas.setBkMode( true );
+ auto bkMode(canvas.setBkMode(true));
// get rect for sidebar
RECT rect;
@@ -493,7 +493,6 @@
// clear
canvas.setTextColor( oldColor );
- canvas.setBkMode( oldMode );
}
}
@@ -625,7 +624,7 @@
theme.drawText(canvas, part, state, accelerator, drawAccelFormat, textRectangle);
} else {
- bool oldMode = canvas.setBkMode(true);
+ auto bkMode(canvas.setBkMode(true));
canvas.setTextColor(
isGrayed ? Colors::gray :
@@ -636,8 +635,6 @@
canvas.drawText(text, textRectangle, drawTextFormat);
if(!accelerator.empty())
canvas.drawText(accelerator, textRectangle, drawAccelFormat);
-
- canvas.setBkMode(oldMode);
}
}
=== modified file 'dwt/src/widgets/TabView.cpp'
--- dwt/src/widgets/TabView.cpp 2011-01-27 22:57:05 +0000
+++ dwt/src/widgets/TabView.cpp 2011-02-01 21:33:33 +0000
@@ -651,7 +651,7 @@
bool TabView::handlePainting(LPDRAWITEMSTRUCT info, TabInfo* ti) {
FreeCanvas canvas(info->hDC);
- bool oldMode = canvas.setBkMode(true);
+ auto bkMode(canvas.setBkMode(true));
Rectangle rect(info->rcItem);
if(theme) {
@@ -663,8 +663,6 @@
}
draw(canvas, info->itemID, std::move(rect), (info->itemState & ODS_SELECTED) == ODS_SELECTED);
-
- canvas.setBkMode(oldMode);
return true;
}
@@ -673,7 +671,7 @@
if(rect.width() == 0 || rect.height() == 0)
return;
- bool oldMode = canvas.setBkMode(true);
+ auto bkMode(canvas.setBkMode(true));
int sel = getSelected();
Rectangle selRect;
@@ -699,8 +697,6 @@
// draw the selected tab last because it might need to step on others
if(selRect.height() > 0)
draw(canvas, sel, std::move(selRect), true);
-
- canvas.setBkMode(oldMode);
}
void TabView::draw(Canvas& canvas, unsigned index, Rectangle&& rect, bool isSelected) {