linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #05163
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2797: Avoid inheriting point from windows struct
------------------------------------------------------------
revno: 2797
committer: Jacek Sieka <arnetheduck@xxxxxxxxx>
branch nick: dcplusplus
timestamp: Sat 2012-01-07 21:59:41 +0100
message:
Avoid inheriting point from windows struct
modified:
dwt/include/dwt/Point.h
dwt/include/dwt/aspects/DragDrop.h
dwt/src/Events.cpp
dwt/src/Point.cpp
dwt/src/Region.cpp
dwt/src/Taskbar.cpp
win32/MainWindow.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/Point.h'
--- dwt/include/dwt/Point.h 2011-01-02 17:12:02 +0000
+++ dwt/include/dwt/Point.h 2012-01-07 20:59:41 +0000
@@ -33,8 +33,8 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef DWT_BasicTypes_h
-#define DWT_BasicTypes_h
+#ifndef DWT_POINT_H
+#define DWT_POINT_H
#include "WindowsHeaders.h"
@@ -43,26 +43,33 @@
/// POD structure for defining a point
/** Used in e.g. functions that take a mouse position etc...
*/
-struct Point : public ::POINT
+struct Point
{
+ long x;
+ long y;
+
+ /// Constructor Initializing the point to (0,0)
+ /** Default constructor initializing x and y member to 0 and 0
+ */
+ Point();
+
/// Constructor initializing the point with the given arguments.
/** Constructor initializing the structure with the given arguments. Takes x and
* y coordinate to be used.
*/
Point( long x, long y );
- /// Constructor Initializing the point to (0,0)
- /** Default constructor initializing x and y member to 0 and 0
- */
- Point();
-
Point(const POINT& pt);
+ Point& operator=(const POINT& pt);
+
static Point fromMSG(const MSG& msg);
static Point fromLParam(LPARAM lParam);
LPARAM toLParam() const;
+ ::POINT toPOINT() const;
+ operator ::POINT() const;
/// Sets this Point to the maximum value for each x y dimension.
/** Each x,y dimension is adjusted by the p Point.
@@ -160,13 +167,16 @@
inline Point::Point() { x = y = 0; }
-inline Point::Point(const POINT& pt) : POINT(pt) { }
+inline Point::Point(const POINT& pt) : x(pt.x), y(pt.y) { }
+inline Point& Point::operator=(const POINT& pt) { x = pt.x; y = pt.y; return *this; }
inline Point Point::fromLParam(LPARAM lParam) { return Point(GET_X_LPARAM( lParam ), GET_Y_LPARAM( lParam )); }
inline Point Point::fromMSG(const MSG& msg) { return fromLParam(msg.lParam); }
inline LPARAM Point::toLParam() const { return MAKELPARAM(x, y); }
+inline POINT Point::toPOINT() const { POINT ret = { x, y }; return ret; }
+inline Point::operator POINT() const { return toPOINT(); }
inline bool operator == ( const Point & lhs, const Point & rhs ) {
return lhs.x == rhs.x && lhs.y == rhs.y;
=== modified file 'dwt/include/dwt/aspects/DragDrop.h'
--- dwt/include/dwt/aspects/DragDrop.h 2011-11-07 22:11:39 +0000
+++ dwt/include/dwt/aspects/DragDrop.h 2012-01-07 20:59:41 +0000
@@ -72,7 +72,7 @@
void onDragDrop(std::function<void (const std::vector<tstring>&, Point)> f) {
W().addCallback(Message(WM_DROPFILES), [f](const MSG& msg, LRESULT& ret) -> bool {
std::vector<tstring> files;
- Point pt;
+ POINT pt = { 0 };
HDROP handle = reinterpret_cast<HDROP>(msg.wParam);
if(handle) {
=== modified file 'dwt/src/Events.cpp'
--- dwt/src/Events.cpp 2011-01-02 17:12:02 +0000
+++ dwt/src/Events.cpp 2012-01-07 20:59:41 +0000
@@ -41,8 +41,11 @@
{
}
-MouseEvent::MouseEvent(const MSG& msg) : pos(Point::fromLParam(msg.lParam)) {
- ::ClientToScreen(msg.hwnd, &pos.getPoint());
+MouseEvent::MouseEvent(const MSG& msg) {
+ POINT pt = { GET_X_LPARAM( msg.lParam ), GET_Y_LPARAM( msg.lParam ) };
+ ::ClientToScreen(msg.hwnd, &pt);
+
+ pos = ScreenCoordinate(Point(pt));
DWORD keys;
if(msg.message == WM_XBUTTONDOWN || msg.message == WM_XBUTTONUP || msg.message == WM_XBUTTONDBLCLK) {
=== modified file 'dwt/src/Point.cpp'
--- dwt/src/Point.cpp 2011-01-02 17:12:02 +0000
+++ dwt/src/Point.cpp 2012-01-07 20:59:41 +0000
@@ -78,18 +78,22 @@
ClientCoordinate::ClientCoordinate(const ClientCoordinate& cc, Widget* w_) : point(cc.getPoint()), w(w_) {
if(cc.w != w) {
- ::MapWindowPoints(cc.w->handle(), w->handle(), &point, 1);
+ auto pt = point.toPOINT();
+ ::MapWindowPoints(cc.w->handle(), w->handle(), &pt, 1);
+ point = pt;
}
}
ClientCoordinate::ClientCoordinate(const ScreenCoordinate& sc, Widget* w_) : point(sc.getPoint()), w(w_) {
- ::ScreenToClient(w->handle(), &point);
+ auto pt = point.toPOINT();
+ ::ScreenToClient(w->handle(), &pt);
+ point = pt;
}
ClientCoordinate::operator ScreenCoordinate() const {
- ScreenCoordinate pt(getPoint());
- ::ClientToScreen(w->handle(), &pt.getPoint());
- return pt;
+ auto pt = point.toPOINT();
+ ::ClientToScreen(w->handle(), &pt);
+ return ScreenCoordinate(Point(pt));
}
}
=== modified file 'dwt/src/Region.cpp'
--- dwt/src/Region.cpp 2011-01-27 22:57:05 +0000
+++ dwt/src/Region.cpp 2012-01-07 20:59:41 +0000
@@ -29,6 +29,7 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <boost/range/algorithm/transform.hpp>
#include <dwt/resources/Region.h>
#include <dwt/DWTException.h>
@@ -40,7 +41,12 @@
Region::Region(const Rectangle& rect) : ResourceType(::CreateRectRgn(rect.left(), rect.top(), rect.right(), rect.bottom()), true) { }
-Region::Region(const std::vector<Point>& points, PolyFillMode mode) : ResourceType(::CreatePolygonRgn(&points[0], points.size(), mode), true) { }
+Region::Region(const std::vector<Point>& points, PolyFillMode mode)
+{
+ std::vector<POINT> tmp(points.size());
+ boost::transform(points, tmp.begin(), [](const Point& pt) { return pt.toPOINT(); });
+ init(::CreatePolygonRgn(&tmp[0], tmp.size(), mode), true);
+}
RegionPtr Region::transform(const PXFORM pxform) const {
DWORD bytes = ::GetRegionData(handle(), 0, NULL);
=== modified file 'dwt/src/Taskbar.cpp'
--- dwt/src/Taskbar.cpp 2011-12-23 14:07:18 +0000
+++ dwt/src/Taskbar.cpp 2012-01-07 20:59:41 +0000
@@ -183,7 +183,7 @@
// generate a preview of the tab to be shown in "Aero Peek" when the user hovers the thumbnail.
BitmapPtr bitmap = getBitmap(tab, 0);
if(bitmap) {
- Point offset;
+ POINT offset { 0 };
::MapWindowPoints(tab->handle(), window->handle(), &offset, 1);
MENUBARINFO info = { sizeof(MENUBARINFO) };
if(::GetMenuBarInfo(window->handle(), OBJID_MENU, 0, &info))
=== modified file 'win32/MainWindow.cpp'
--- win32/MainWindow.cpp 2011-12-31 18:53:24 +0000
+++ win32/MainWindow.cpp 2012-01-07 20:59:41 +0000
@@ -1604,9 +1604,9 @@
menu->appendSeparator();
menu->appendItem(T_("Exit"), [this] { close(true); }, WinUtil::menuIcon(IDI_EXIT));
- dwt::ScreenCoordinate pt;
- ::GetCursorPos(&pt.getPoint());
- menu->open(pt, TPM_BOTTOMALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON);
+ POINT pt;
+ ::GetCursorPos(&pt);
+ menu->open(dwt::ScreenCoordinate(dwt::Point(pt)), TPM_BOTTOMALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON);
}
void MainWindow::handleTrayClicked() {