← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3145: plug leaks in dwt

 

------------------------------------------------------------
revno: 3145
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2012-11-25 19:27:27 +0100
message:
  plug leaks in dwt
removed:
  win32/ComboBox.cpp
  win32/ComboBox.h
modified:
  dwt/include/dwt/Widget.h
  dwt/include/dwt/WidgetCreator.h
  dwt/include/dwt/widgets/ComboBox.h
  dwt/include/dwt/widgets/Control.h
  dwt/src/Taskbar.cpp
  dwt/src/Widget.cpp
  dwt/src/widgets/ComboBox.cpp
  win32/MDIChildFrame.h
  win32/WinUtil.h
  win32/forward.h
  win32/stdafx.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/Widget.h'
--- dwt/include/dwt/Widget.h	2012-10-29 18:19:03 +0000
+++ dwt/include/dwt/Widget.h	2012-11-25 18:27:27 +0000
@@ -165,12 +165,30 @@
 
 	/**
 	 * Attaches the instance to an existing window.
+	 * @return the previous window proc, if there was one.
 	 */
-	void setHandle(HWND hwnd);
+	WNDPROC setHandle(HWND hwnd);
 
 	/// get the top-most parent window of this widget (either a main window or a modal dialog).
 	Widget* getRoot() const;
 
+	/** Callback to execute when creating the widget. */
+	void onCreate(std::function<void (const CREATESTRUCT&)> f) {
+		addCallback(Message(WM_CREATE), [f](const MSG& msg, LRESULT&) -> bool {
+			auto cs = reinterpret_cast<const CREATESTRUCT*>(msg.lParam);
+			f(*cs);
+			return false;
+		});
+	}
+
+	/** Callback to execute right before destroying the widget. */
+	void onDestroy(std::function<void ()> f) {
+		addCallback(Message(WM_DESTROY), [f](const MSG&, LRESULT&) -> bool {
+			f();
+			return false;
+		});
+	}
+
 protected:
 	/** Most Widgets can override the creational parameters which sets the style and the
 	  * initial position of the Widget, those Widgets will take an object of this type to

=== modified file 'dwt/include/dwt/WidgetCreator.h'
--- dwt/include/dwt/WidgetCreator.h	2012-01-22 20:27:14 +0000
+++ dwt/include/dwt/WidgetCreator.h	2012-11-25 18:27:27 +0000
@@ -81,11 +81,14 @@
 		return retVal;
 	}
 
-	static typename WidgetType::ObjectType attach( Widget * parent, HWND hwnd )
+	/** Attach to an existing window. */
+	static typename WidgetType::ObjectType attach(Widget* parent, HWND hwnd)
 	{
-		typename WidgetType::ObjectType retVal(new WidgetType( parent ));
-		retVal->setHandle( hwnd );
-		return retVal;
+		typename WidgetType::ObjectType w(new WidgetType(parent));
+		auto proc = w->setHandle(hwnd);
+		// "detach" from the window before the parent is destroyed.
+		parent->onDestroy([=] { ::SetWindowLongPtr(w->handle(), GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(proc)); w->kill(); });
+		return w;
 	}
 };
 

=== modified file 'dwt/include/dwt/widgets/ComboBox.h'
--- dwt/include/dwt/widgets/ComboBox.h	2012-05-10 08:01:35 +0000
+++ dwt/include/dwt/widgets/ComboBox.h	2012-11-25 18:27:27 +0000
@@ -69,6 +69,24 @@
 	friend class aspects::Clickable<ComboBox>;
 	friend class aspects::Data<ComboBox, int>;
 
+	/** @internal Wraps the drop-down list of a ComboBox. Carefully named to avoid clashes with
+	regular ListBox controls. */
+	class DropListBox :
+		public Control
+	{
+		typedef Control BaseType;
+		friend class WidgetCreator<DropListBox>;
+	public:
+		typedef DropListBox ThisType;
+		typedef ThisType* ObjectType;
+		struct Seed : BaseType::Seed { typedef ThisType WidgetType; };
+		explicit DropListBox(Widget* parent) : BaseType(parent, ChainingDispatcher::superClass<DropListBox>()) { }
+	private:
+		friend class ChainingDispatcher;
+		static const TCHAR windowClass[];
+	};
+	typedef DropListBox::ObjectType DropListBoxPtr;
+
 public:
 	/// Class type
 	typedef ComboBox ThisType;
@@ -122,6 +140,12 @@
 	  */
 	void create( const Seed & cs = Seed() );
 
+	/** Get a widget that controls the drop-down list box used by this combo box. */
+	DropListBoxPtr getListBox();
+
+	/** Get a widget that controls the text box used by this combo box. */
+	TextBoxPtr getTextBox();
+
 	virtual Point getPreferredSize();
 
 	using aspects::Clickable<ThisType>::onClicked;
@@ -139,6 +163,9 @@
 	friend class ChainingDispatcher;
 	static const TCHAR windowClass[];
 
+	DropListBoxPtr listBox;
+	TextBoxPtr textBox;
+
 	// aspects::Selection
 	int getSelectedImpl() const;
 	void setSelectedImpl( int idx );

=== modified file 'dwt/include/dwt/widgets/Control.h'
--- dwt/include/dwt/widgets/Control.h	2012-01-13 20:55:20 +0000
+++ dwt/include/dwt/widgets/Control.h	2012-11-25 18:27:27 +0000
@@ -77,29 +77,6 @@
 	typedef Widget BaseType;
 
 public:
-
-	/// Setting the event handler for the "create" event
-	/** The event handler must have the signature "void foo( CREATESTRUCT * )" where
-	  * the WidgetType is the type of Widget that realizes the Aspect. <br>
-	  * If you supply an event handler for this event your handler will be called
-	  * when Widget is initially created. <br>
-	  */
-	void onCreate(std::function<void (const CREATESTRUCT&)> f) {
-		addCallback(Message(WM_CREATE), [f](const MSG& msg, LRESULT&) -> bool {
-			auto cs = reinterpret_cast<const CREATESTRUCT*>(msg.lParam);
-			f(*cs);
-			return false;
-		});
-	}
-
-	/// Callback to execute right before destroying the control.
-	void onDestroy(std::function<void ()> f) {
-		addCallback(Message(WM_DESTROY), [f](const MSG&, LRESULT&) -> bool {
-			f();
-			return false;
-		});
-	}
-
 	/**
 	* add a combination of keys that will launch a function when they are hit. see the ACCEL
 	* structure doc for information about the "fVirt" and "key" arguments.

=== modified file 'dwt/src/Taskbar.cpp'
--- dwt/src/Taskbar.cpp	2012-11-05 20:39:11 +0000
+++ dwt/src/Taskbar.cpp	2012-11-25 18:27:27 +0000
@@ -205,7 +205,7 @@
 void Taskbar::removeFromTaskbar(ContainerPtr tab) {
 	auto proxy = tabs[tab];
 	taskbar->UnregisterTab(proxy->handle());
-	proxy->close();
+	::DestroyWindow(proxy->handle());
 	tabs.erase(tab);
 }
 

=== modified file 'dwt/src/Widget.cpp'
--- dwt/src/Widget.cpp	2012-10-29 18:19:03 +0000
+++ dwt/src/Widget.cpp	2012-11-25 18:27:27 +0000
@@ -84,7 +84,7 @@
 	return hWnd;
 }
 
-void Widget::setHandle(HWND h) {
+WNDPROC Widget::setHandle(HWND h) {
 	if(hwnd) {
 		throw DWTException("You may not attach to a widget that's already attached");
 	}
@@ -93,7 +93,7 @@
 
 	::SetProp(hwnd, propAtom, reinterpret_cast<HANDLE>(this));
 
-	::SetWindowLongPtr(hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(WindowProc::wndProc));
+	return reinterpret_cast<WNDPROC>(::SetWindowLongPtr(hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(WindowProc::wndProc)));
 }
 
 Widget* Widget::getRoot() const {

=== modified file 'dwt/src/widgets/ComboBox.cpp'
--- dwt/src/widgets/ComboBox.cpp	2012-05-10 08:01:35 +0000
+++ dwt/src/widgets/ComboBox.cpp	2012-11-25 18:27:27 +0000
@@ -31,10 +31,15 @@
 
 #include <dwt/widgets/ComboBox.h>
 
+#include <dwt/WidgetCreator.h>
+#include <dwt/widgets/TextBox.h>
+
 namespace dwt {
 
 const TCHAR ComboBox::windowClass[] = WC_COMBOBOX;
 
+const TCHAR ComboBox::DropListBox::windowClass[] = _T("ComboLBox"); // undocumented
+
 ComboBox::Seed::Seed() :
 BaseType::Seed(CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_CHILD | WS_TABSTOP | WS_VSCROLL),
 font(0),
@@ -42,8 +47,10 @@
 {
 }
 
-ComboBox::ComboBox(Widget* parent ) :
-BaseType(parent, ChainingDispatcher::superClass<ComboBox>())
+ComboBox::ComboBox(Widget* parent) :
+	BaseType(parent, ChainingDispatcher::superClass<ComboBox>()),
+	listBox(nullptr),
+	textBox(nullptr)
 {
 }
 
@@ -66,6 +73,24 @@
 	return ComboBox_FindStringExact(handle(), -1, text.c_str()); 
 }
 
+ComboBox::DropListBoxPtr ComboBox::getListBox() {
+	if(!listBox) {
+		COMBOBOXINFO info = { sizeof(COMBOBOXINFO) };
+		if(::GetComboBoxInfo(handle(), &info) && info.hwndList && info.hwndList != handle())
+			listBox = WidgetCreator<DropListBox>::attach(this, info.hwndList);
+	}
+	return listBox;
+}
+
+TextBoxPtr ComboBox::getTextBox() {
+	if(!textBox) {
+		COMBOBOXINFO info = { sizeof(COMBOBOXINFO) };
+		if(::GetComboBoxInfo(handle(), &info) && info.hwndItem && info.hwndItem != handle())
+			textBox = WidgetCreator<TextBox>::attach(this, info.hwndItem);
+	}
+	return textBox;
+}
+
 Point ComboBox::getPreferredSize() {
 	// Pixels between text and arrow
 	const int MARGIN = 2;

=== removed file 'win32/ComboBox.cpp'
--- win32/ComboBox.cpp	2012-01-13 20:55:20 +0000
+++ win32/ComboBox.cpp	1970-01-01 00:00:00 +0000
@@ -1,57 +0,0 @@
-/*
-o * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include "stdafx.h"
-#include "ComboBox.h"
-
-#include <dwt/widgets/TextBox.h>
-#include <dwt/WidgetCreator.h>
-
-using dwt::TextBox;
-
-const TCHAR ListBox::windowClass[] = WC_LISTBOX;
-
-ComboBox::Seed::Seed() :
-BaseType::Seed()
-{
-}
-
-ComboBox::ComboBox(dwt::Widget* parent) :
-BaseType(parent),
-listBox(0),
-textBox(0)
-{
-}
-
-ListBoxPtr ComboBox::getListBox() {
-	if(!listBox) {
-		COMBOBOXINFO info = { sizeof(COMBOBOXINFO) };
-		if(::GetComboBoxInfo(handle(), &info) && info.hwndList && info.hwndList != handle())
-			listBox = dwt::WidgetCreator<ListBox>::attach(this, info.hwndList);
-	}
-	return listBox;
-}
-
-TextBoxPtr ComboBox::getTextBox() {
-	if(!textBox) {
-		COMBOBOXINFO info = { sizeof(COMBOBOXINFO) };
-		if(::GetComboBoxInfo(handle(), &info) && info.hwndItem && info.hwndItem != handle())
-			textBox = dwt::WidgetCreator<TextBox>::attach(this, info.hwndItem);
-	}
-	return textBox;
-}

=== removed file 'win32/ComboBox.h'
--- win32/ComboBox.h	2012-01-13 20:55:20 +0000
+++ win32/ComboBox.h	1970-01-01 00:00:00 +0000
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifndef DCPLUSPLUS_WIN32_ComboBox_H_
-#define DCPLUSPLUS_WIN32_ComboBox_H_
-
-#include <dwt/widgets/ComboBox.h>
-
-#include "forward.h"
-
-/// @todo this should obviously be moved somewhere else
-/** Wraps the drop-down control of a ComboBox */
-class ListBox :
-	public dwt::Control
-{
-	typedef dwt::Control BaseType;
-	friend class dwt::WidgetCreator<ListBox>;
-public:
-	typedef ListBox ThisType;
-	typedef ThisType* ObjectType;
-	struct Seed : BaseType::Seed { typedef ThisType WidgetType; };
-	explicit ListBox(dwt::Widget* parent) : BaseType(parent, dwt::ChainingDispatcher::superClass<ListBox>()) { }
-private:
-	friend class dwt::ChainingDispatcher;
-	static const TCHAR windowClass[];
-};
-typedef ListBox::ObjectType ListBoxPtr;
-
-class ComboBox : public dwt::ComboBox {
-	typedef dwt::ComboBox BaseType;
-	friend class dwt::WidgetCreator<ComboBox>;
-public:
-	typedef ComboBox ThisType;
-
-	typedef ThisType* ObjectType;
-
-	struct Seed : public BaseType::Seed {
-		typedef ThisType WidgetType;
-
-		Seed();
-	};
-
-	explicit ComboBox(dwt::Widget* parent);
-
-	ListBoxPtr getListBox();
-	TextBoxPtr getTextBox();
-
-private:
-	ListBoxPtr listBox;
-	TextBoxPtr textBox;
-};
-
-typedef ComboBox::ObjectType ComboBoxPtr;
-
-#endif /*ComboBox_H_*/

=== modified file 'win32/MDIChildFrame.h'
--- win32/MDIChildFrame.h	2012-10-16 16:17:56 +0000
+++ win32/MDIChildFrame.h	2012-11-25 18:27:27 +0000
@@ -159,7 +159,7 @@
 
 	void addDlgCodeMessage(ComboBox* widget, bool autoTab = true) {
 		widget->onRaw([=](WPARAM w, LPARAM) { return this->handleGetDlgCode(w, autoTab); }, dwt::Message(WM_GETDLGCODE));
-		TextBox* text = widget->getTextBox();
+		auto text = widget->getTextBox();
 		if(text)
 			text->onRaw([=](WPARAM w, LPARAM) { return this->handleGetDlgCode(w, autoTab); }, dwt::Message(WM_GETDLGCODE));
 	}
@@ -172,11 +172,11 @@
 	void addColor(ComboBox* widget) {
 		// do not apply our custom colors to the combo itself, but apply it to its drop-down and edit controls
 
-		ListBoxPtr listBox = widget->getListBox();
+		auto listBox = widget->getListBox();
 		if(listBox)
 			addColor(listBox);
 
-		TextBoxPtr text = widget->getTextBox();
+		auto text = widget->getTextBox();
 		if(text)
 			addColor(text);
 	}

=== modified file 'win32/WinUtil.h'
--- win32/WinUtil.h	2012-09-10 22:14:27 +0000
+++ win32/WinUtil.h	2012-11-25 18:27:27 +0000
@@ -31,13 +31,13 @@
 #include <dwt/forward.h>
 #include <dwt/widgets/Button.h>
 #include <dwt/widgets/CheckBox.h>
+#include <dwt/widgets/ComboBox.h>
 #include <dwt/widgets/GroupBox.h>
 #include <dwt/widgets/Label.h>
 #include <dwt/widgets/TabView.h>
 #include <dwt/widgets/Tree.h>
 
 #include "forward.h"
-#include "ComboBox.h"
 #include "RichTextBox.h"
 #include "Table.h"
 
@@ -45,6 +45,7 @@
 
 using dwt::Button;
 using dwt::CheckBox;
+using dwt::ComboBox;
 using dwt::GroupBox;
 using dwt::Label;
 using dwt::Menu;

=== modified file 'win32/forward.h'
--- win32/forward.h	2012-07-11 17:13:42 +0000
+++ win32/forward.h	2012-11-25 18:27:27 +0000
@@ -24,6 +24,7 @@
 
 using dwt::ButtonPtr;
 using dwt::CheckBoxPtr;
+using dwt::ComboBoxPtr;
 using dwt::ContainerPtr;
 using dwt::GridPtr;
 using dwt::GroupBoxPtr;
@@ -40,9 +41,6 @@
 using dwt::ToolBarPtr;
 using dwt::ToolTipPtr;
 
-class ComboBox;
-typedef ComboBox* ComboBoxPtr;
-
 class HubFrame;
 
 class ShellMenu;

=== modified file 'win32/stdafx.h'
--- win32/stdafx.h	2012-11-14 19:53:25 +0000
+++ win32/stdafx.h	2012-11-25 18:27:27 +0000
@@ -51,7 +51,6 @@
 #include <dwt/widgets/Tree.h>
 #include <dwt/widgets/Window.h>
 
-#include "ComboBox.h"
 #include "RichTextBox.h"
 #include "ShellMenu.h"
 #include "Table.h"