← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2983: go back to SetProp because link controls sometimes contain user data

 

------------------------------------------------------------
revno: 2983
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sat 2012-07-07 17:36:18 +0200
message:
  go back to SetProp because link controls sometimes contain user data
modified:
  dwt/include/dwt/Widget.h
  dwt/include/dwt/WindowsHeaders.h
  dwt/src/Widget.cpp
  dwt/src/widgets/Link.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/Widget.h'
--- dwt/include/dwt/Widget.h	2012-05-13 11:48:45 +0000
+++ dwt/include/dwt/Widget.h	2012-07-07 15:36:18 +0000
@@ -37,6 +37,7 @@
 #define DWT_Widget_h
 
 #include "Application.h"
+#include "Atom.h"
 #include "forward.h"
 #include "Rectangle.h"
 #include "Point.h"
@@ -236,6 +237,9 @@
 
 	static Rectangle getDesktopSize(HMONITOR mon);
 
+	/// The atom with which the pointer to the Widget is registered on the HWND
+	static GlobalAtom propAtom;
+
 	// Contains the list of signals we're (this window) processing
 	CallbackCollectionType handlers;
 
@@ -317,7 +321,7 @@
 
 template<typename T>
 T hwnd_cast(HWND hwnd) {
-	Widget* w = reinterpret_cast<Widget*>(::GetWindowLongPtr(hwnd, GWLP_USERDATA));
+	Widget* w = reinterpret_cast<Widget*>(::GetProp(hwnd, Widget::propAtom));
 	return dynamic_cast<T>(w);
 }
 

=== modified file 'dwt/include/dwt/WindowsHeaders.h'
--- dwt/include/dwt/WindowsHeaders.h	2012-07-07 13:21:05 +0000
+++ dwt/include/dwt/WindowsHeaders.h	2012-07-07 15:36:18 +0000
@@ -81,7 +81,7 @@
 // Other quirks
 
 // LM_GETIDEALSIZE is a >=Vista message; we check the OS version before using it.
-#if WINVER < 0x600
+#ifndef LM_GETIDEALSIZE
 #define LM_GETIDEALSIZE LM_GETIDEALHEIGHT
 #endif
 

=== modified file 'dwt/src/Widget.cpp'
--- dwt/src/Widget.cpp	2012-05-13 11:48:45 +0000
+++ dwt/src/Widget.cpp	2012-07-07 15:36:18 +0000
@@ -53,6 +53,8 @@
 
 namespace dwt {
 
+GlobalAtom Widget::propAtom(_T("dwt::Widget*"));
+
 Widget::Widget(Widget* parent_, Dispatcher& dispatcher_) :
 	hwnd(NULL), parent(parent_), dispatcher(dispatcher_)
 {
@@ -60,7 +62,9 @@
 }
 
 Widget::~Widget() {
-
+	if(hwnd) {
+		::RemoveProp(hwnd, propAtom);
+	}
 }
 
 void Widget::kill() {
@@ -87,13 +91,7 @@
 
 	hwnd = h;
 
-	dwtassert((::GetWindowLongPtr(hwnd, GWLP_USERDATA) == 0), "Userdata already set");
-
-	::SetLastError(0);
-	LONG_PTR ret = ::SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
-	if(ret == 0 && ::GetLastError() != 0) {
-		throw Win32Exception("Error while setting pointer");
-	}
+	::SetProp(hwnd, propAtom, reinterpret_cast<HANDLE>(this));
 
 	::SetWindowLongPtr(hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(WindowProc::wndProc));
 }

=== modified file 'dwt/src/widgets/Link.cpp'
--- dwt/src/widgets/Link.cpp	2012-07-07 13:21:05 +0000
+++ dwt/src/widgets/Link.cpp	2012-07-07 15:36:18 +0000
@@ -68,7 +68,7 @@
 Point Link::getPreferredSize() {
 	if(util::win32::ensureVersion(util::win32::VISTA)) {
 		SIZE size = { 0 };
-		sendMessage(LM_GETIDEALSIZE, getParent()->getClientSize().x, reinterpret_cast<LPARAM>(&size));
+		sendMessage(LM_GETIDEALSIZE, getRoot()->getClientSize().x, reinterpret_cast<LPARAM>(&size));
 		return Point(size.cx, size.cy);
 	}