------------------------------------------------------------ revno: 2345 committer: poy <p...@123gen.com> branch nick: trunk timestamp: Mon 2010-12-13 00:10:36 +0100 message: plug GDI mem leaks (missing DeleteDC calls) removed: dwt/include/dwt.hpp dwt/include/dwt/dwt.hpp renamed: dwt/include/dwt/widgets/CoolBar.h => dwt/include/dwt/widgets/Rebar.h dwt/src/widgets/CoolBar.cpp => dwt/src/widgets/Rebar.cpp modified: dwt/include/dwt/CanvasClasses.h dwt/include/dwt/aspects/AspectEraseBackground.h dwt/include/dwt/resources/Bitmap.h dwt/src/Bitmap.cpp dwt/src/CanvasClasses.cpp dwt/src/Taskbar.cpp dwt/src/widgets/Menu.cpp dwt/src/widgets/Table.cpp dwt/include/dwt/widgets/Rebar.h dwt/src/widgets/Rebar.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
=== removed file 'dwt/include/dwt.hpp' --- dwt/include/dwt.hpp 2010-02-11 21:44:13 +0000 +++ dwt/include/dwt.hpp 1970-01-01 00:00:00 +0000 @@ -1,36 +0,0 @@ -/* - DC++ Widget Toolkit - - Copyright (c) 2007-2010, Jacek Sieka - - SmartWin++ - - Copyright (c) 2005 Thomas Hansen - - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of the DWT nor SmartWin++ nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include "dwt/dwt.hpp" === modified file 'dwt/include/dwt/CanvasClasses.h' --- dwt/include/dwt/CanvasClasses.h 2010-03-08 18:55:17 +0000 +++ dwt/include/dwt/CanvasClasses.h 2010-12-12 23:10:36 +0000 @@ -549,6 +549,15 @@ virtual ~FreeCanvas() { } }; +/// Calls CreateCompatibleDC and returns a managed canvas. +class CompatibleCanvas : public FreeCanvas +{ +public: + explicit CompatibleCanvas(HDC hdc); + + virtual ~CompatibleCanvas(); +}; + #ifndef WINCE // TODO: Create custom enums for typesafety... ? /// Helper class for setting and resetting the ROP2 mode === modified file 'dwt/include/dwt/aspects/AspectEraseBackground.h' --- dwt/include/dwt/aspects/AspectEraseBackground.h 2010-07-10 14:36:48 +0000 +++ dwt/include/dwt/aspects/AspectEraseBackground.h 2010-12-12 23:10:36 +0000 @@ -55,22 +55,18 @@ { WidgetType& W() { return *static_cast<WidgetType*>(this); } - struct EraseBackgroundDispatcher { - typedef std::function<void (Canvas&)> F; - - EraseBackgroundDispatcher(const F& f_, WidgetType* widget_) : f(f_), widget(widget_) { } + struct EraseBackgroundDispatcher : Dispatchers::Base<void (Canvas&)> { + typedef Dispatchers::Base<void (Canvas&)> BaseType; + EraseBackgroundDispatcher(const F& f_) : BaseType(f_) { } bool operator()(const MSG& msg, LRESULT& ret) const { - FreeCanvas canvas( widget->handle(), reinterpret_cast< HDC >( msg.wParam ) ); - + FreeCanvas canvas(reinterpret_cast<HDC>(msg.wParam)); f(canvas); ret = 1; return true; } - - F f; - WidgetType* widget; }; + public: /// \ingroup EventHandlersAspectEraseBackground /// Setting the event handler for the "erase background" event === removed file 'dwt/include/dwt/dwt.hpp' --- dwt/include/dwt/dwt.hpp 2010-11-13 16:49:19 +0000 +++ dwt/include/dwt/dwt.hpp 1970-01-01 00:00:00 +0000 @@ -1,83 +0,0 @@ -/* - DC++ Widget Toolkit - - Copyright (c) 2007-2010, Jacek Sieka - - SmartWin++ - - Copyright (c) 2005 Thomas Hansen - - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of the DWT nor SmartWin++ nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef DWT_SmartWin_h -#define DWT_SmartWin_h - -#include "WindowsHeaders.h" - -#include "Application.h" -#include "ClipBoard.h" -#include "Cursor.h" -#include "LibraryLoader.h" -#include "Point.h" -#include "Rectangle.h" -#include "resources/Accelerator.h" -#include "resources/Bitmap.h" -#include "resources/Brush.h" -#include "resources/Font.h" -#include "resources/Icon.h" -#include "resources/ImageList.h" -#include "resources/Pen.h" -#include "tstring.h" -#include "widgets/Button.h" -#include "widgets/CheckBox.h" -#include "widgets/ComboBox.h" -#include "widgets/Container.h" -#include "widgets/CoolBar.h" -#include "widgets/DateTime.h" -#include "widgets/GroupBox.h" -#include "widgets/Label.h" -#include "widgets/Menu.h" -#include "widgets/MDIChild.h" -#include "widgets/MDIFrame.h" -#include "widgets/MDIParent.h" -#include "widgets/ModalDialog.h" -#include "widgets/ModelessDialog.h" -#include "widgets/ProgressBar.h" -#include "widgets/RadioButton.h" -#include "widgets/RichTextBox.h" -#include "widgets/Slider.h" -#include "widgets/Spinner.h" -#include "widgets/StatusBar.h" -#include "widgets/Table.h" -#include "widgets/TabView.h" -#include "widgets/TextBox.h" -#include "widgets/Tree.h" -#include "widgets/ToolBar.h" -#include "widgets/ToolTip.h" -#include "widgets/Window.h" - -#endif === modified file 'dwt/include/dwt/resources/Bitmap.h' --- dwt/include/dwt/resources/Bitmap.h 2010-02-11 21:44:13 +0000 +++ dwt/include/dwt/resources/Bitmap.h 2010-12-12 23:10:36 +0000 @@ -107,7 +107,7 @@ /** This function is IMMUTABLE meaning it will not modify the given bitmap at all * but rather return a new Bitmap containing the resized Bitmap. */ - BitmapPtr resize( const Point & newSize ) const; + BitmapPtr resize(const Point& newSize) const; private: friend class Handle<GdiPolicy<HBITMAP> >; === renamed file 'dwt/include/dwt/widgets/CoolBar.h' => 'dwt/include/dwt/widgets/Rebar.h' --- dwt/include/dwt/widgets/CoolBar.h 2010-02-11 21:44:13 +0000 +++ dwt/include/dwt/widgets/Rebar.h 2010-12-12 23:10:36 +0000 @@ -33,59 +33,34 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef DWT_CoolBar_h -#define DWT_CoolBar_h - -#ifndef WINCE // Doesn't exist in Windows CE based systems - -#include "../aspects/AspectEnabled.h" -#include "../aspects/AspectKeyboard.h" -#include "../aspects/AspectFont.h" -#include "../aspects/AspectRaw.h" -#include "../aspects/AspectSizable.h" -#include "../aspects/AspectVisible.h" -#include "../util/check.h" +#ifndef DWT_Rebar_h +#define DWT_Rebar_h + +#include "Control.h" namespace dwt { -/// Coolbar Control class +/// Rebar Control class /** \ingroup WidgetControls * \WidgetUsageInfo - * \image html coolbar.PNG - * A coolbar is a strip of buttons normally associated with menu commands, like for + * \image html Rebar.PNG + * A Rebar is a strip of buttons normally associated with menu commands, like for * instance Internet Explorer has ( unless you have made them invisible ) a toolbar * of buttons, one for going "home", one to stop rendering of the current page, one * to view the log of URL's you have been to etc... In addition to serving like a - * dockable toolbar ( see ToolBar ) a Coolbar Widget can also contain more + * dockable toolbar ( see ToolBar ) a Rebar Widget can also contain more * complex Widgets lke for instance a ComboBox, a TextBox and so on... - * - * @todo This class needs some love... */ -class CoolBar : - public Widget, - - // Aspects - public AspectEnabled< CoolBar >, - public AspectKeyboard< CoolBar >, - public AspectFont< CoolBar >, - public AspectRaw< CoolBar >, - private AspectSizable< CoolBar >, - public AspectVisible< CoolBar > +class Rebar : + public Control { - typedef Widget BaseType; - typedef dwt::AspectSizable< CoolBar > AspectSizable; - friend class WidgetCreator< CoolBar >; + typedef Control BaseType; + + friend class WidgetCreator<Rebar>; + public: - // Including the stuff we need from AspectSizable to make it accessible - // Note here that since we DON'T want the setBounds functions we must - // inherit privately from AspectSizable and include the stuff we WAN'T to - // expose from AspectSizable in a public block of the class. - using AspectSizable::bringToFront; - using AspectSizable::onSized; - using AspectSizable::onMoved; - /// Class type - typedef CoolBar ThisType; + typedef Rebar ThisType; /// Object type typedef ThisType* ObjectType; @@ -101,27 +76,25 @@ Seed(); }; - /// Actually creates the Coolbar - /** You should call WidgetFactory::createCoolbar if you instantiate class + /// Actually creates the Rebar + /** You should call WidgetFactory::createRebar if you instantiate class * directly. <br> * Only if you DERIVE from class you should call this function directly. */ - void create( const Seed & cs = Seed() ); + void create(const Seed& cs = Seed()); - /// Refreshes the Coolbar +#if 0 + /// Refreshes the Rebar /** Call this one after the container widget has been resized to make sure the - * coolbar is having the right size... + * Rebar is having the right size... */ void refresh(); +#endif protected: - // CTOR - explicit CoolBar(Widget *parent ); - - // To assure nobody accidentally deletes any heaped object of this type, parent - // is supposed to do so when parent is killed... - virtual ~CoolBar() - {} + // Protected to avoid direct instantiation + explicit Rebar(Widget* parent); + virtual ~Rebar() { } private: friend class ChainingDispatcher; @@ -131,29 +104,6 @@ void addChild( Widget * child, unsigned width, unsigned height, const tstring & txt ); }; -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Implementation of class -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/* -inline CoolBar::CoolBar( Widget * parent ) - : BaseType( parent ) -{ - // Can't have a text box without a parent... - dwtassert( parent, _T( "Can't have a Button without a parent..." ) ); -} -*/ -inline void CoolBar::refresh() { - // This might look a bit stupid, but Windows API have some minor flaws. One of - // those flaws is that a Coolbar (and a Toolbar) control must be "resized" with - // a dummy value to make sure the Coolbar (&& the Toolbar) fills up the - // complete area of the container Widget... - - if ( ::MoveWindow( this->handle(), 0, 0, 0, 0, TRUE ) == 0 ) { - dwtWin32DebugFail("Couldn't reposition windows"); - } -} - -} - -#endif //WINCE -#endif //CoolBar_h +} + +#endif === modified file 'dwt/src/Bitmap.cpp' --- dwt/src/Bitmap.cpp 2010-02-11 21:44:13 +0000 +++ dwt/src/Bitmap.cpp 2010-12-12 23:10:36 +0000 @@ -34,6 +34,8 @@ */ #include <dwt/resources/Bitmap.h> + +#include <dwt/CanvasClasses.h> #include <dwt/Point.h> namespace dwt { @@ -75,25 +77,18 @@ return Point( bm.bmWidth, bm.bmHeight ); } -BitmapPtr Bitmap::resize( const Point & newSize ) const -{ - HDC hdc1 = ::CreateCompatibleDC( 0 ); - HBITMAP hBitmapOld1 = ( HBITMAP )::SelectObject( hdc1, handle() ); +BitmapPtr Bitmap::resize(const Point& newSize) const { + CompatibleCanvas dc1(0); + Canvas::Selector select1(dc1, *this); - HDC hdc2 = ::CreateCompatibleDC( 0 ); - HBITMAP hBitmapNew = ::CreateCompatibleBitmap( hdc1, newSize.x, newSize.y ); - HBITMAP hBitmapOld2 = ( HBITMAP )::SelectObject( hdc2, hBitmapNew ); + CompatibleCanvas dc2(0); + BitmapPtr ret(new Bitmap(::CreateCompatibleBitmap(dc1.handle(), newSize.x, newSize.y))); + Canvas::Selector select2(dc2, *ret); const Point oldSize = getSize(); - ::StretchBlt( hdc2, 0, 0, newSize.x, newSize.y, hdc1, 0, 0, oldSize.x, oldSize.y, SRCCOPY ); - - hBitmapNew = ( HBITMAP )::SelectObject( hdc2, hBitmapOld2 ); - - // Clean up - ::SelectObject( hdc1, hBitmapOld1 ); - ::DeleteDC( hdc2 ); - ::DeleteDC( hdc1 ); - return BitmapPtr( new Bitmap( hBitmapNew ) ); + ::StretchBlt(dc2.handle(), 0, 0, newSize.x, newSize.y, dc1.handle(), 0, 0, oldSize.x, oldSize.y, SRCCOPY); + + return ret; } } === modified file 'dwt/src/CanvasClasses.cpp' --- dwt/src/CanvasClasses.cpp 2010-03-08 18:55:17 +0000 +++ dwt/src/CanvasClasses.cpp 2010-12-12 23:10:36 +0000 @@ -280,6 +280,15 @@ itsHdc = hdc; } +CompatibleCanvas::CompatibleCanvas(HDC hdc) : +FreeCanvas(::CreateCompatibleDC(hdc)) +{ +} + +CompatibleCanvas::~CompatibleCanvas() { + ::DeleteDC(itsHdc); +} + #ifndef WINCE HdcModeSetter::HdcModeSetter( Canvas & canvas, int mode ) : itsOldMode( ::GetROP2( canvas.handle() ) ), === modified file 'dwt/src/Taskbar.cpp' --- dwt/src/Taskbar.cpp 2010-11-02 16:09:03 +0000 +++ dwt/src/Taskbar.cpp 2010-12-12 23:10:36 +0000 @@ -220,7 +220,7 @@ BITMAPINFO info = { { sizeof(BITMAPINFOHEADER), size_full.x, size_full.y, 1, 32, BI_RGB } }; BitmapPtr bitmap_full(new Bitmap(::CreateDIBSection(canvas.handle(), &info, DIB_RGB_COLORS, 0, 0, 0))); - FreeCanvas canvas_full(::CreateCompatibleDC(canvas.handle())); + CompatibleCanvas canvas_full(canvas.handle()); Canvas::Selector select_full(canvas_full, *bitmap_full); tab->sendMessage(WM_PRINT, reinterpret_cast<WPARAM>(canvas_full.handle()), PRF_CLIENT | PRF_NONCLIENT | PRF_CHILDREN | PRF_ERASEBKGND); @@ -243,7 +243,7 @@ info.bmiHeader.biHeight = size_thumb.y; BitmapPtr bitmap_thumb(new Bitmap(::CreateDIBSection(canvas.handle(), &info, DIB_RGB_COLORS, 0, 0, 0))); - FreeCanvas canvas_thumb(::CreateCompatibleDC(canvas.handle())); + CompatibleCanvas canvas_thumb(canvas.handle()); Canvas::Selector select_thumb(canvas_thumb, *bitmap_thumb); ::SetStretchBltMode(canvas_thumb.handle(), HALFTONE); === modified file 'dwt/src/widgets/Menu.cpp' --- dwt/src/widgets/Menu.cpp 2010-11-30 18:55:29 +0000 +++ dwt/src/widgets/Menu.cpp 2010-12-12 23:10:36 +0000 @@ -662,21 +662,19 @@ canvas.fill(iconRectangle, Brush(highlight ? colors.highlightBackground : colors.stripBar)); // create memory DC and set bitmap on it - HDC memoryDC = ::CreateCompatibleDC( canvas.handle() ); - HGDIOBJ old = ::SelectObject( memoryDC, ::CreateCompatibleBitmap( canvas.handle(), iconSize.x, iconSize.y ) ); + CompatibleCanvas canvas_compat(canvas.handle()); + BitmapPtr bitmap_compat(new Bitmap(::CreateCompatibleBitmap(canvas.handle(), iconSize.x, iconSize.y))); + Canvas::Selector select_compat(canvas_compat, *bitmap_compat); // draw into memory RECT rc( Rectangle( 0, 0, iconSize.x, iconSize.y ) ); - ::DrawFrameControl( memoryDC, & rc, DFC_MENU, ( info.fType & MFT_RADIOCHECK ) == 0 ? DFCS_MENUCHECK : DFCS_MENUBULLET ); + ::DrawFrameControl(canvas_compat.handle(), & rc, DFC_MENU, ( info.fType & MFT_RADIOCHECK ) == 0 ? DFCS_MENUCHECK : DFCS_MENUBULLET ); const int adjustment = 2; // adjustment for mark to be in the center // bit - blast into out canvas - ::BitBlt( canvas.handle(), iconRectangle.left() + adjustment, iconRectangle.top(), iconSize.x, iconSize.y, memoryDC, 0, 0, SRCAND ); - - // delete memory dc - ::DeleteObject( ::SelectObject( memoryDC, old ) ); - ::DeleteDC( memoryDC ); + ::BitBlt(canvas.handle(), iconRectangle.left() + adjustment, iconRectangle.top(), + iconSize.x, iconSize.y, canvas_compat.handle(), 0, 0, SRCAND); } if(isChecked && !theme && popup && !wrapper->isTitle) { === renamed file 'dwt/src/widgets/CoolBar.cpp' => 'dwt/src/widgets/Rebar.cpp' --- dwt/src/widgets/CoolBar.cpp 2010-02-11 21:44:13 +0000 +++ dwt/src/widgets/Rebar.cpp 2010-12-12 23:10:36 +0000 @@ -29,21 +29,41 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <dwt/widgets/CoolBar.h> +#include <dwt/widgets/Rebar.h> #include <dwt/DWTException.h> namespace dwt { -CoolBar::Seed::Seed() : - BaseType::Seed(WS_CHILD | WS_VISIBLE | RBS_VARHEIGHT | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CCS_NODIVIDER) -{ -} - -void CoolBar::create( const Seed & cs ) { +const TCHAR Rebar::windowClass[] = REBARCLASSNAME; + +Rebar::Seed::Seed() : +BaseType::Seed(WS_CHILD | RBS_VARHEIGHT | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CCS_NODIVIDER) +{ +} + +Rebar::Rebar(Widget* parent) : +BaseType(parent, ChainingDispatcher::superClass<Rebar>()) +{ +} + +void Rebar::create(const Seed& cs) { BaseType::create(cs); } -void CoolBar::addChild( Widget * child, +#if 0 +void Rebar::refresh() { + // This might look a bit stupid, but Windows API have some minor flaws. One of + // those flaws is that a Rebar (and a Toolbar) control must be "resized" with + // a dummy value to make sure the Rebar (&& the Toolbar) fills up the + // complete area of the container Widget... + + if ( ::MoveWindow( this->handle(), 0, 0, 0, 0, TRUE ) == 0 ) { + dwtWin32DebugFail("Couldn't reposition windows"); + } +} +#endif + +void Rebar::addChild( Widget * child, unsigned width, unsigned height, const tstring & txt ) { @@ -62,9 +82,8 @@ rbBand.fStyle = 0; //RBBS_GRIPPERALWAYS; if ( sendMessage( RB_INSERTBAND, ( WPARAM ) - 1, ( LPARAM ) & rbBand ) == 0 ) { - throw DWTException( "There was a problem when trying to insert a band into your Coolbar object!"); + throw DWTException( "There was a problem when trying to insert a band into your Rebar object!"); } } - } === modified file 'dwt/src/widgets/Table.cpp' --- dwt/src/widgets/Table.cpp 2010-12-08 23:15:35 +0000 +++ dwt/src/widgets/Table.cpp 2010-12-12 23:10:36 +0000 @@ -535,7 +535,7 @@ triangle.push_back(Point(10, 6)); UpdateCanvas dc(this); - FreeCanvas dc_compat(::CreateCompatibleDC(dc.handle())); + CompatibleCanvas dc_compat(dc.handle()); upArrow = BitmapPtr(new Bitmap(::CreateCompatibleBitmap(dc.handle(), size.x, size.y))); downArrow = BitmapPtr(new Bitmap(::CreateCompatibleBitmap(dc.handle(), size.x, size.y)));
_______________________________________________ Mailing list: https://launchpad.net/~linuxdcpp-team Post to : linuxdcpp-team@lists.launchpad.net Unsubscribe : https://launchpad.net/~linuxdcpp-team More help : https://help.launchpad.net/ListHelp