|
From: <arn...@us...> - 2008-03-26 14:11:26
|
Revision: 1062
http://dcplusplus.svn.sourceforge.net/dcplusplus/?rev=1062&view=rev
Author: arnetheduck
Date: 2008-03-26 07:11:12 -0700 (Wed, 26 Mar 2008)
Log Message:
-----------
Streamline event handlers, redo common control color setting
Modified Paths:
--------------
dcplusplus/trunk/smartwin/include/smartwin/Dispatchers.h
dcplusplus/trunk/smartwin/include/smartwin/Message.h
dcplusplus/trunk/smartwin/include/smartwin/Point.h
dcplusplus/trunk/smartwin/include/smartwin/Policies.h
dcplusplus/trunk/smartwin/include/smartwin/Widget.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectActivate.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectBackgroundColor.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectBorder.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectButton.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectClickable.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectCollection.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectCommand.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectContextMenu.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectData.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectDblClickable.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectEnabled.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectEraseBackground.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectFocus.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectFont.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectHelp.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectKeyboard.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectMouse.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectPainting.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectRaw.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectScrollable.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectSelection.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectSizable.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectText.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectUpdate.h
dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectVisible.h
dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetComboBox.h
dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetStatic.h
dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTabView.h
dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTextBox.h
dcplusplus/trunk/smartwin/source/Application.cpp
dcplusplus/trunk/smartwin/source/Point.cpp
dcplusplus/trunk/smartwin/source/Widget.cpp
dcplusplus/trunk/smartwin/source/widgets/WidgetTabView.cpp
dcplusplus/trunk/win32/Appearance2Page.cpp
dcplusplus/trunk/win32/Appearance2Page.h
dcplusplus/trunk/win32/AspectSpeaker.h
dcplusplus/trunk/win32/MDIChildFrame.h
dcplusplus/trunk/win32/MainWindow.cpp
dcplusplus/trunk/win32/MainWindow.h
dcplusplus/trunk/win32/TransferView.cpp
dcplusplus/trunk/win32/TransferView.h
Added Paths:
-----------
dcplusplus/trunk/smartwin/include/smartwin/Events.h
dcplusplus/trunk/smartwin/source/Events.cpp
Property Changed:
----------------
dcplusplus/trunk/
Property changes on: dcplusplus/trunk
___________________________________________________________________
Name: bzr:revision-info
- timestamp: 2008-03-25 01:46:02.440000057 +0100
committer: zouzou123gen
properties:
branch-nick: bzr
+ timestamp: 2008-03-25 11:06:59.213000059 +0100
committer: Jacek Sieka <arn...@gm...>
properties:
branch-nick: dcplusplus
Name: bzr:file-ids
-
+ smartwin/include/smartwin/Events.h events.h-20080325100557-k77vniqlbeo19c72-1
smartwin/source/Events.cpp events.cpp-20080325100557-k77vniqlbeo19c72-2
Name: bzr:revision-id:v3-trunk1
- 1027 arn...@gm...-20080323183926-schknwnkgeo7ivdn
1028 zouzou123gen-20080323220411-r8usuc3qxwuh7zsn
1029 zouzou123gen-20080323221249-0su72zaj13e706mk
1030 arn...@gm...-20080324140623-muba1dl46m000o8c
1031 zouzou123gen-20080324141933-qbgr93ugpe0297m6
1032 arn...@gm...-20080324153706-siidja05n84i00b1
1033 arn...@gm...-20080324153823-lhn3awurnu77riln
1034 arn...@gm...-20080324165650-zapppziji67yf5a2
1035 zouzou123gen-20080324175936-4mqc2kh0lo5wtdu2
1036 zouzou123gen-20080325004602-6wdsoym95mjuhwd3
+ 1027 arn...@gm...-20080323183926-schknwnkgeo7ivdn
1028 zouzou123gen-20080323220411-r8usuc3qxwuh7zsn
1029 zouzou123gen-20080323221249-0su72zaj13e706mk
1030 arn...@gm...-20080324140623-muba1dl46m000o8c
1031 zouzou123gen-20080324141933-qbgr93ugpe0297m6
1032 arn...@gm...-20080324153706-siidja05n84i00b1
1033 arn...@gm...-20080324153823-lhn3awurnu77riln
1034 arn...@gm...-20080324165650-zapppziji67yf5a2
1035 zouzou123gen-20080324175936-4mqc2kh0lo5wtdu2
1036 zouzou123gen-20080325004602-6wdsoym95mjuhwd3
1037 arn...@gm...-20080325100659-8fqy6q65itmghlep
Modified: dcplusplus/trunk/smartwin/include/smartwin/Dispatchers.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/Dispatchers.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/Dispatchers.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -5,26 +5,45 @@
#include <functional>
-namespace SmartWin
-{
+namespace SmartWin {
// begin namespace SmartWin
namespace Dispatchers {
-template<LRESULT value = 0, bool handled = true>
-struct VoidVoid
-{
- typedef std::tr1::function<void ()> F;
+template<typename T>
+struct Base {
+ typedef std::tr1::function<T> F;
+
+ Base(const F& f_) : f(f_) { }
+ F f;
+};
+
+template<typename T>
+T convert(const MSG& msg) {
+ return T(msg);
+}
+
+template<typename P, P (*C)(const MSG&) = convert<P>, bool handled = true >
+struct ConvertBase : public Base<void(const P&)> {
+ typedef Base<void(const P&)> BaseType;
+ ConvertBase(const typename BaseType::F& f_) : BaseType(f_) { }
- VoidVoid(const F& f_) : f(f_) { }
+ bool operator()(const MSG& msg, LRESULT& ret) {
+ f((*C)(msg));
+ return handled;
+ }
+};
+template<LRESULT value = 0, bool handled = true>
+struct VoidVoid : public Base<void ()> {
+
+ VoidVoid(const F& f_) : Base<void ()>(f_) { }
+
bool operator()(const MSG& msg, LRESULT& ret) {
f();
ret = value;
return handled;
}
-
- F f;
};
// end namespace SmartWin
Added: dcplusplus/trunk/smartwin/include/smartwin/Events.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/Events.h (rev 0)
+++ dcplusplus/trunk/smartwin/include/smartwin/Events.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -0,0 +1,35 @@
+#ifndef EVENTS_H_
+#define EVENTS_H_
+
+#include "WindowsHeaders.h"
+#include "Point.h"
+
+namespace SmartWin {
+
+struct SizedEvent {
+ SizedEvent(const MSG& msg);
+
+ /// Sise
+ /** New size of the window
+ */
+ Point size;
+
+ /// is window maximized
+ /** true if window was being maximized, otherwise false
+ */
+ bool isMaximized;
+
+ /// is window minimized
+ /** true if window was being minimized, otherwise false
+ */
+ bool isMinimized;
+
+ /// is window restored
+ /** true if window was being restored, otherwise false
+ */
+ bool isRestored;
+};
+
+}
+
+#endif /*EVENTS_H_*/
Modified: dcplusplus/trunk/smartwin/include/smartwin/Message.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/Message.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/Message.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -50,7 +50,7 @@
* only interesting parameter to figure out what Message to handle is the actual
* Message.
*/
- Message( UINT msg );
+ explicit Message( UINT msg );
/// Normally used with e.g. WM_COMMAND or WM_NOTIFY messages
/** In such cases WM_COMMAND or WM_NOTIFY should be added as the msg and the
@@ -59,7 +59,7 @@
* Use this one if you need to e.g. handle an AspectRaw::onRaw Event and it's a
* WM_COMMAND, WM_NOTIFY or similar type of Message
*/
- Message( UINT msg, LPARAM param );
+ explicit Message( UINT msg, LPARAM param );
// Note!
// We're asserting this constructor call comes from the mainWndProc...
Modified: dcplusplus/trunk/smartwin/include/smartwin/Point.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/Point.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/Point.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -37,7 +37,7 @@
/// POD structure for defining a point
/** Used in e.g. functions that take a mouse position etc...
*/
-struct Point : ::POINT
+struct Point : public ::POINT
{
/// Constructor initializing the point with the given arguments.
/** Constructor initializing the structure with the given arguments. Takes x and
@@ -52,8 +52,12 @@
Point(const POINT& pt);
- operator POINT() const;
+ static Point fromMSG(const MSG& msg);
+ static Point fromLParam(LPARAM lParam);
+
+ LPARAM toLParam() const;
+
/// Sets this Point to the maximum value for each x y dimension.
/** Each x,y dimension is adjusted by the p Point.
*/
@@ -146,6 +150,25 @@
*/
bool operator != ( const Point & lhs, const Point & rhs );
+inline Point::Point( long pX, long pY ) { x = pX; y = pY; }
+
+inline Point::Point() { x = y = 0; }
+
+inline Point::Point(const POINT& pt) : POINT(pt) { }
+
+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 bool operator == ( const Point & lhs, const Point & rhs ) {
+ return lhs.x == rhs.x && lhs.y == rhs.y;
+}
+
+inline bool operator != ( const Point & lhs, const Point & rhs ) { return !( lhs == rhs ); }
+
+
// end namespace SmartWin
}
Modified: dcplusplus/trunk/smartwin/include/smartwin/Policies.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/Policies.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/Policies.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -83,7 +83,7 @@
}
private:
- static HWND getHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+ static HWND getHandler(HWND hwnd, UINT& uMsg, WPARAM& wParam, LPARAM& lParam) {
HWND handler;
// Check who should handle the message - parent or child
switch(uMsg) {
@@ -93,7 +93,8 @@
case WM_CTLCOLORLISTBOX :
case WM_CTLCOLORSCROLLBAR : {
handler = reinterpret_cast<HWND>(lParam);
-
+ // We change message to avoid handling different messages of read-only vs normal edit controls
+ uMsg = WM_CTLCOLOR;
} break;
case WM_NOTIFY : {
NMHDR* nmhdr = reinterpret_cast<NMHDR*>(lParam);
@@ -233,11 +234,15 @@
virtual HWND create(const Widget::Seed& seed) {
HWND hWnd = Widget::create(seed);
- oldProc = reinterpret_cast< WNDPROC >( ::SetWindowLongPtr( hWnd, GWL_WNDPROC, ( LONG_PTR ) &MessageMapPolicy<Subclassed>::wndProc ) );
attach(hWnd);
return hWnd;
}
+ virtual void attach(HWND hWnd) {
+ Normal::attach(hWnd);
+ oldProc = reinterpret_cast< WNDPROC >( ::SetWindowLongPtr( hWnd, GWL_WNDPROC, ( LONG_PTR ) &MessageMapPolicy<Subclassed>::wndProc ) );
+ }
+ using Widget::attach;
private:
WNDPROC oldProc;
};
Modified: dcplusplus/trunk/smartwin/include/smartwin/Widget.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/Widget.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/Widget.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -160,6 +160,9 @@
/// Adds a new callback - multiple callbacks for the same message will be called in the order they were added
void addCallback(const Message& msg, const CallbackType& callback );
+ /// Sets the callback for msg - clears any other callbacks registered for the same message
+ void setCallback(const Message& msg, const CallbackType& callback );
+
CallbackCollectionType & getCallbacks();
/// Returns true if fired, else false
@@ -176,7 +179,7 @@
*/
void attach( unsigned id );
- void attach(HWND wnd);
+ virtual void attach(HWND wnd);
protected:
Widget(Widget * parent);
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectActivate.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectActivate.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectActivate.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -28,8 +28,9 @@
#ifndef AspectActivate_h
#define AspectActivate_h
-namespace SmartWin
-{
+#include "../Dispatchers.h"
+
+namespace SmartWin {
// begin namespace SmartWin
/// Aspect class used by Widgets that can be activated.
@@ -41,19 +42,14 @@
template< class WidgetType >
class AspectActivate
{
- struct Dispatcher {
- typedef std::tr1::function<void (bool)> F;
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
- Dispatcher(const F& f_) : f(f_) { }
-
- bool operator()(const MSG& msg, LRESULT& ret) {
- f(LOWORD( msg.wParam ) == WA_ACTIVE || LOWORD( msg.wParam ) == WA_CLICKACTIVE);
- return true;
- }
-
- F f;
- };
-
+ static bool isActive(const MSG& msg) {
+ return LOWORD( msg.wParam ) == WA_ACTIVE || LOWORD( msg.wParam ) == WA_CLICKACTIVE;
+ }
+
+ typedef Dispatchers::ConvertBase<bool, &AspectActivate<WidgetType>::isActive> Dispatcher;
+ friend class Dispatchers::ConvertBase<bool, &AspectActivate<WidgetType>::isActive>;
public:
/// Activates the Widget
/** Changes the activated property of the Widget. <br>
@@ -76,14 +72,12 @@
* Parameter passed is bool
*/
void onActivate(const typename Dispatcher::F& f) {
- static_cast<WidgetType*>(this)->addCallback(
- Message(WM_ACTIVATE), Dispatcher(f)
- );
+ W().addCallback(Message(WM_ACTIVATE), Dispatcher(f));
}
protected:
- virtual ~AspectActivate()
- {}
+ virtual ~AspectActivate() { }
+
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectBackgroundColor.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectBackgroundColor.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectBackgroundColor.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -42,50 +42,33 @@
* realizes the AspectEnabled through inheritance.
*/
template< class WidgetType >
-class AspectBackgroundColor
-{
+class AspectCtlColor {
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
+
struct Dispatcher {
- typedef std::tr1::function<BrushPtr (Canvas&)> F;
-
- Dispatcher(const F& f_, WidgetType* widget_) : f(f_), widget(widget_) { }
+ Dispatcher(const BrushPtr& brush_, COLORREF text_, COLORREF bg_) : brush(brush_), text(text_), bg(bg_) { }
bool operator()(const MSG& msg, LRESULT& ret) {
- FreeCanvas canvas( widget->handle(), reinterpret_cast< HDC >( msg.wParam ) );
-
- BrushPtr retBrush = f(canvas);
- ret = retBrush ? reinterpret_cast< HRESULT >( retBrush->handle() ) : 0;
+ HDC dc = (HDC) msg.wParam;
+ ::SetTextColor(dc, text);
+ ::SetBkColor(dc, bg);
+ ret = brush ? reinterpret_cast< LRESULT >( brush->handle() ) : 0;
return true;
}
- F f;
- WidgetType* widget;
+ BrushPtr brush;
+ COLORREF text;
+ COLORREF bg;
};
public:
- /// \ingroup EventHandlersAspectBackgroundColor
- /// Setting the event handler for the "erase background" event
- /** The erase background event is raised when the Widget needs to redraw its
- * background. <br>
- * Since the Brush object needs to live past the function call we use a BrushPtr
- * to wrap the Brush object into, you can for instance add a BrushPtr object as
- * a member of your Widget class and return that BrushPtr from your event
- * handler. <br>
- * The parameter passed is Canvas & and return value is BrushPtr <br>
- * Note! <br>
- * It is imperative that you keep a reference to the BrushPtr yourself somewhere
- * e.g. as member of class since otherwise the brush will be released before it
- * is returned to the system and cannot be used!
- */
- void onBackgroundColor(const typename Dispatcher::F& f) {
- WidgetType* This = static_cast<WidgetType*>(this);
- This->addCallback(
- This->getBackgroundColorMessage(), Dispatcher(f, This )
- );
+ /// Set the background, text and text colors
+ void setColor(const BrushPtr& brush, COLORREF text, COLORREF textBackground) {
+ W().setCallback(Message(WM_CTLCOLOR), Dispatcher( brush, text, textBackground ));
}
protected:
- virtual ~AspectBackgroundColor()
- {}
+ virtual ~AspectCtlColor() { }
};
// end namespace SmartWin
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectBorder.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectBorder.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectBorder.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -40,6 +40,7 @@
template< class WidgetType >
class AspectBorder
{
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
public:
/// Set or remove the simple border (solid line)
void setBorder( bool value = true );
@@ -60,25 +61,25 @@
template< class WidgetType >
void AspectBorder< WidgetType >::setBorder( bool value )
{
- static_cast< WidgetType * >( this )->addRemoveStyle( WS_BORDER, value );
+ W().addRemoveStyle( WS_BORDER, value );
}
template< class WidgetType >
void AspectBorder< WidgetType >::setSunkenBorder( bool value )
{
- static_cast< WidgetType * >( this )->addRemoveExStyle( WS_EX_CLIENTEDGE, value );
+ W().addRemoveExStyle( WS_EX_CLIENTEDGE, value );
}
template< class WidgetType >
void AspectBorder< WidgetType >::setSmoothSunkenBorder( bool value )
{
- static_cast< WidgetType * >( this )->addRemoveExStyle( WS_EX_STATICEDGE, value );
+ W().addRemoveExStyle( WS_EX_STATICEDGE, value );
}
template< class WidgetType >
void AspectBorder< WidgetType >::setRaisedBorder( bool value )
{
- static_cast< WidgetType * >( this )->addRemoveStyle( WS_THICKFRAME, value );
+ W().addRemoveStyle( WS_THICKFRAME, value );
}
// end namespace SmartWin
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectButton.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectButton.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectButton.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -15,7 +15,7 @@
/** Common stuff for all buttons */
template<typename WidgetType>
class AspectButton :
- public AspectBackgroundColor<WidgetType>,
+ public AspectCtlColor<WidgetType>,
public AspectBorder< WidgetType >,
public AspectClickable<WidgetType>,
public AspectControl<WidgetType>,
@@ -25,11 +25,9 @@
public AspectPainting< WidgetType >,
public AspectText< WidgetType >
{
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
public:
- // Contract needed by AspectBackgroundColor Aspect class
- static const Message & getBackgroundColorMessage();
-
// Contract needed by AspectClickable Aspect class
Message getClickMessage();
@@ -46,13 +44,6 @@
};
template<typename WidgetType>
-inline const Message & AspectButton<WidgetType>::getBackgroundColorMessage()
-{
- static Message retVal = Message( WM_CTLCOLORBTN );
- return retVal;
-}
-
-template<typename WidgetType>
Message AspectButton<WidgetType>::getClickMessage() {
return Message( WM_COMMAND, MAKEWPARAM(static_cast<WidgetType*>(this)->getControlId(), BN_CLICKED) );
}
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectClickable.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectClickable.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectClickable.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -43,6 +43,7 @@
template< class WidgetType >
class AspectClickable
{
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
typedef Dispatchers::VoidVoid<> Dispatcher;
public:
@@ -54,14 +55,11 @@
* something else. No parameters are passed.
*/
void onClicked(const typename Dispatcher::F& f) {
- static_cast<WidgetType*>(this)->addCallback(
- static_cast<WidgetType*>(this)->getClickMessage(), Dispatcher(f)
- );
+ W().addCallback(W().getClickMessage(), Dispatcher(f));
}
protected:
- virtual ~AspectClickable()
- {}
+ virtual ~AspectClickable() { }
};
// end namespace SmartWin
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectCollection.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectCollection.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectCollection.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -4,20 +4,22 @@
/** A control that holds a collection of items, such as a list or tree */
template<typename WidgetType, typename IndexType>
class AspectCollection {
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
+ const WidgetType& W() const { return *static_cast<const WidgetType*>(this); }
public:
/** Erase a particular item */
void erase(IndexType i) {
- static_cast<WidgetType*>(this)->eraseImpl(i);
+ W().eraseImpl(i);
}
/** Erase all items from collection */
void clear() {
- static_cast<WidgetType*>(this)->clearImpl();
+ W().clearImpl();
}
/** Return number of items in collection */
size_t size() const {
- return static_cast<const WidgetType*>(this)->sizeImpl();
+ return W().sizeImpl();
}
bool empty() const {
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectCommand.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectCommand.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectCommand.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -7,26 +7,20 @@
template<typename WidgetType>
class AspectCommand {
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
typedef Dispatchers::VoidVoid<> Dispatcher;
public:
void onCommand(const Dispatcher::F& f, unsigned id) {
- static_cast<WidgetType*>(this)->addCallback(
- Message(WM_COMMAND, id), Dispatcher(f)
- );
+ W().addCallback(Message(WM_COMMAND, id), Dispatcher(f));
}
void onCommand(const Dispatcher::F& f, unsigned controlId, unsigned code) {
- static_cast<WidgetType*>(this)->addCallback(
- Message(WM_COMMAND, MAKEWPARAM(controlId, code)), Dispatcher(f)
- );
+ W().addCallback(Message(WM_COMMAND, MAKEWPARAM(controlId, code)), Dispatcher(f));
}
void onSysCommand(const Dispatcher::F& f, unsigned id) {
- static_cast<WidgetType*>(this)->addCallback(
- Message(WM_SYSCOMMAND, id), Dispatcher(f)
- );
+ W().addCallback(Message(WM_SYSCOMMAND, id), Dispatcher(f));
}
-
};
}
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectContextMenu.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectContextMenu.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectContextMenu.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -2,29 +2,28 @@
#define ASPECTCONTEXTMENU_H_
#include "../Point.h"
+#include "../Dispatchers.h"
namespace SmartWin {
template<typename WidgetType>
class AspectContextMenu {
- struct Dispatcher {
- typedef std::tr1::function<bool (const ScreenCoordinate &)> F;
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
- Dispatcher(const F& f_) : f(f_) { }
+ struct Dispatcher : Dispatchers::Base<bool (const ScreenCoordinate&)> {
+ typedef Dispatchers::Base<bool(const ScreenCoordinate&)> BaseType;
+ Dispatcher(const F& f_) : BaseType(f_) { }
bool operator()(const MSG& msg, LRESULT& ret) {
- ret = f(ScreenCoordinate(Point(GET_X_LPARAM(msg.lParam), GET_Y_LPARAM(msg.lParam))));
- return ret;
+ bool shown = f(ScreenCoordinate(Point::fromLParam(msg.lParam)));
+ ret = shown;
+ return shown;
}
-
- F f;
};
public:
void onContextMenu(const typename Dispatcher::F& f) {
- static_cast<WidgetType*>(this)->addCallback(
- Message( WM_CONTEXTMENU ), Dispatcher(f)
- );
+ W().addCallback(Message( WM_CONTEXTMENU ), Dispatcher(f));
}
};
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectData.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectData.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectData.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -4,21 +4,22 @@
/** A Widget that associates some sort of data with each item */
template<typename WidgetType, typename IndexType>
class AspectData {
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
public:
IndexType findData(LPARAM data) {
- return static_cast<WidgetType*>(this)->findDataImpl(data);
+ return W().findDataImpl(data);
}
IndexType findData(LPARAM data, IndexType start) {
- return static_cast<WidgetType*>(this)->findDataImpl(data, start);
+ return W().findDataImpl(data, start);
}
LPARAM getData(IndexType i) {
- return static_cast<WidgetType*>(this)->getDataImpl(i);
+ return W().getDataImpl(i);
}
void setData(IndexType i, LPARAM data) {
- return static_cast<WidgetType*>(this)->setDataImpl(i, data);
+ return W().setDataImpl(i, data);
}
LPARAM operator[](IndexType i) {
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectDblClickable.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectDblClickable.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectDblClickable.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -43,6 +43,7 @@
template< class WidgetType >
class AspectDblClickable
{
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
typedef Dispatchers::VoidVoid<> Dispatcher;
public:
/// \ingroup EventHandlersAspectDblClickable
@@ -52,14 +53,11 @@
*/
void onDblClicked(const Dispatcher::F& f) {
- static_cast<WidgetType*>(this)->addCallback(
- WidgetType::getDblClickMessage(), Dispatcher(f)
- );
+ W().addCallback(WidgetType::getDblClickMessage(), Dispatcher(f));
}
protected:
- virtual ~AspectDblClickable()
- {}
+ virtual ~AspectDblClickable() { }
};
// end namespace SmartWin
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectEnabled.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectEnabled.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectEnabled.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -28,7 +28,7 @@
#ifndef AspectEnabled_h
#define AspectEnabled_h
-#include <functional>
+#include "../Dispatchers.h"
namespace SmartWin
{
@@ -47,21 +47,13 @@
template< class WidgetType >
class AspectEnabled
{
- struct Dispatcher
- {
- typedef std::tr1::function<void (bool)> F;
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
- Dispatcher(const F& f_) : f(f_) { }
+ static bool isEnabled(const MSG& msg) { return msg.wParam > 0; }
+
+ typedef Dispatchers::ConvertBase<bool, &AspectEnabled<WidgetType>::isEnabled> Dispatcher;
+ friend class Dispatchers::ConvertBase<bool, &AspectEnabled<WidgetType>::isEnabled>;
- bool operator()(const MSG& msg, LRESULT& ret) {
- f(msg.wParam > 0);
- return true;
- }
-
- F f;
- };
-
-
public:
/// Sets the enabled property of the Widget
/** Changes the enabled property of the Widget. Use this function to change the
@@ -84,14 +76,11 @@
* No parameters are passed.
*/
void onEnabled(const typename Dispatcher::F& f) {
- static_cast<WidgetType*>(this)->addCallback(
- Message( WM_ENABLE ), Dispatcher(f)
- );
+ W().addCallback(Message( WM_ENABLE ), Dispatcher(f));
}
protected:
- virtual ~AspectEnabled()
- {}
+ virtual ~AspectEnabled() { }
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -100,13 +89,13 @@
template< class WidgetType >
void AspectEnabled< WidgetType >::setEnabled( bool enabled )
{
- ::EnableWindow( static_cast< WidgetType * >( this )->handle(), enabled ? TRUE : FALSE );
+ ::EnableWindow( W().handle(), enabled ? TRUE : FALSE );
}
template< class WidgetType >
bool AspectEnabled< WidgetType >::getEnabled() const
{
- return ::IsWindowEnabled( static_cast< const WidgetType * >( this )->handle() ) != 0;
+ return ::IsWindowEnabled( W().handle() ) != 0;
}
// end namespace SmartWin
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectEraseBackground.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectEraseBackground.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectEraseBackground.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -46,6 +46,8 @@
template< class WidgetType >
class AspectEraseBackground
{
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
+
struct Dispatcher {
typedef std::tr1::function<void (Canvas&)> F;
@@ -70,19 +72,14 @@
* background property of the Widget.
*/
void onEraseBackground(const typename Dispatcher::F& f) {
- static_cast<WidgetType*>(this)->addCallback(
- Message( WM_ERASEBKGND ), Dispatcher(f, static_cast<WidgetType*>(this) )
- );
+ W().setCallback(Message( WM_ERASEBKGND ), Dispatcher(f, &W() ) );
}
void noEraseBackground() {
- static_cast<WidgetType*>(this)->addCallback(
- Message( WM_ERASEBKGND ), &AspectEraseBackground<WidgetType>::noEraseDispatcher
- );
+ W().setCallback(Message( WM_ERASEBKGND ), &AspectEraseBackground<WidgetType>::noEraseDispatcher);
}
protected:
- virtual ~AspectEraseBackground()
- {}
+ virtual ~AspectEraseBackground() { }
static bool noEraseDispatcher(const MSG& msg, LRESULT& ret) {
ret = 1;
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectFocus.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectFocus.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectFocus.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -45,7 +45,9 @@
template< class WidgetType >
class AspectFocus
{
-
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
+ HWND H() { return W().handle(); }
+
typedef Dispatchers::VoidVoid<0, false> FocusDispatcher;
typedef Dispatchers::VoidVoid<0, true> KillFocusDispatcher;
@@ -68,9 +70,7 @@
* parameters are passed.
*/
void onKillFocus(const typename KillFocusDispatcher::F& f) {
- static_cast<WidgetType*>(this)->addCallback(
- Message( WM_KILLFOCUS ), KillFocusDispatcher(f)
- );
+ W().addCallback(Message( WM_KILLFOCUS ), KillFocusDispatcher(f));
}
/// \ingroup EventHandlersAspectAspectFocus
@@ -79,14 +79,11 @@
* parameters are passed.
*/
void onFocus(const typename FocusDispatcher::F& f) {
- static_cast<WidgetType*>(this)->addCallback(
- Message( WM_SETFOCUS ), FocusDispatcher(f)
- );
+ W().addCallback(Message( WM_SETFOCUS ), FocusDispatcher(f));
}
protected:
- virtual ~AspectFocus()
- {}
+ virtual ~AspectFocus() { }
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -95,13 +92,13 @@
template< class WidgetType >
void AspectFocus< WidgetType >::setFocus()
{
- ::SetFocus( static_cast< WidgetType * >( this )->handle() );
+ ::SetFocus( H() );
}
template< class WidgetType >
bool AspectFocus< WidgetType >::getFocus() const
{
- return ::GetFocus() == static_cast< const WidgetType * >( this )->handle();
+ return ::GetFocus() == H();
}
// end namespace SmartWin
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectFont.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectFont.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectFont.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -48,6 +48,7 @@
template< class WidgetType >
class AspectFont
{
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
public:
/// Sets the font used by the Widget
/** Changes the font of the Widget to the given font. Use the class Font to
@@ -78,14 +79,14 @@
void AspectFont< WidgetType >::setFont( const FontPtr& font_, bool forceUpdate )
{
font = font_;
- static_cast< WidgetType * >( this )->sendMessage(WM_SETFONT, reinterpret_cast< WPARAM >( font->handle() ), static_cast< LPARAM >( forceUpdate ) );
+ W().sendMessage(WM_SETFONT, reinterpret_cast< WPARAM >( font->handle() ), static_cast< LPARAM >( forceUpdate ) );
}
template< class WidgetType >
const FontPtr& AspectFont< WidgetType >::getFont()
{
if(!font) {
- HFONT f = ( HFONT )static_cast< WidgetType * >( this )->sendMessage(WM_GETFONT);
+ HFONT f = ( HFONT )W().sendMessage(WM_GETFONT);
font = FontPtr( new Font( f, false ) );
}
return font;
@@ -96,7 +97,7 @@
{
font = FontPtr();
HANDLE hFont = static_cast< HFONT >( ::GetStockObject( stockObjectFont ) );
- static_cast< WidgetType * >( this )->sendMessage(WM_SETFONT, reinterpret_cast< WPARAM >( hFont ), static_cast< LPARAM >( forceUpdate ) );
+ W().sendMessage(WM_SETFONT, reinterpret_cast< WPARAM >( hFont ), static_cast< LPARAM >( forceUpdate ) );
}
// end namespace SmartWin
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectHelp.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectHelp.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectHelp.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -1,6 +1,8 @@
#ifndef ASPECTHELP_H_
#define ASPECTHELP_H_
+#include <functional>
+
namespace SmartWin {
template<typename WidgetType>
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectKeyboard.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectKeyboard.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectKeyboard.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -110,6 +110,8 @@
template< class WidgetType >
class AspectKeyboard : public AspectKeyboardBase
{
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
+
struct Dispatcher
{
typedef std::tr1::function<bool (int)> F;
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectMouse.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectMouse.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectMouse.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -29,6 +29,7 @@
#define AspectMouse_h
#include "../Point.h"
+#include <functional>
namespace SmartWin
{
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectPainting.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectPainting.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectPainting.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -43,6 +43,8 @@
template< class WidgetType >
class AspectPainting
{
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
+
struct Dispatcher {
typedef std::tr1::function<void (PaintCanvas&)> F;
@@ -66,9 +68,7 @@
* Parameters passed is Canvas &
*/
void onPainting(const typename Dispatcher::F& f) {
- static_cast<WidgetType*>(this)->addCallback(
- Message( WM_PAINT ), Dispatcher(f, static_cast<WidgetType*>(this) )
- );
+ W().addCallback(Message( WM_PAINT ), Dispatcher(f, &W()));
}
protected:
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectRaw.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectRaw.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectRaw.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -47,6 +47,7 @@
template< class WidgetType >
class AspectRaw
{
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
struct Dispatcher {
typedef std::tr1::function<LRESULT (WPARAM, LPARAM)> F;
@@ -80,9 +81,7 @@
/// WARNING, this function uses the natural wparam/lparam order, not the inverted that previous
/// smartwin versions did. The two functions above emulate the old behaviour though...
void onRaw(const typename Dispatcher::F& f, const Message & msg) {
- static_cast<WidgetType*>(this)->addCallback(
- msg, Dispatcher(f)
- );
+ W().addCallback(msg, Dispatcher(f));
}
protected:
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectScrollable.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectScrollable.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectScrollable.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -42,6 +42,8 @@
template< class WidgetType >
class AspectScrollable
{
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
+
typedef Dispatchers::VoidVoid<> Dispatcher;
public:
bool scrollIsAtEnd();
@@ -54,9 +56,7 @@
* No parameters are passed.
*/
void onScrollHorz(const Dispatcher::F& f) {
- static_cast<WidgetType*>(this)->addCallback(
- Message( WM_HSCROLL ), Dispatcher(f)
- );
+ W().addCallback(Message( WM_HSCROLL ), Dispatcher(f));
}
/// \ingroup EventHandlersAspectScrollable
@@ -67,9 +67,7 @@
* No parameters are passed.
*/
void onScrollVert(const Dispatcher::F& f) {
- static_cast<WidgetType*>(this)->addCallback(
- Message( WM_VSCROLL ), Dispatcher(f)
- );
+ W().addCallback(Message( WM_VSCROLL ), Dispatcher(f));
}
protected:
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectSelection.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectSelection.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectSelection.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -41,6 +41,8 @@
template< class WidgetType >
class AspectSelection
{
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
+
struct Dispatcher
{
typedef std::tr1::function<void ()> F;
@@ -64,9 +66,7 @@
* No parameters are passed.
*/
void onSelectionChanged(const typename Dispatcher::F& f) {
- static_cast<WidgetType*>(this)->addCallback(
- static_cast<WidgetType*>(this)->getSelectionChangedMessage(), Dispatcher(f)
- );
+ W().addCallback(W().getSelectionChangedMessage(), Dispatcher(f));
}
/// Sets the selected index of the Widget
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectSizable.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectSizable.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectSizable.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -31,42 +31,13 @@
#include "../Widget.h"
#include "../Place.h"
#include "../xCeption.h"
+#include "../Dispatchers.h"
+#include "../Events.h"
namespace SmartWin
{
// begin namespace SmartWin
-/// Widget sized POD structure
-/** Several event handlers supply an object of this type as one or more parameters to
- * the event handler callback function. <br>
- * E.g. the "onSized" event handler
- */
-struct WidgetSizedEventResult
-{
- WidgetSizedEventResult(WPARAM wParam, LPARAM lParam);
-
- /// Sise
- /** New size of the window
- */
- Point newSize;
-
- /// is window maximized
- /** true if window was being maximized, otherwise false
- */
- bool isMaximized;
-
- /// is window minimized
- /** true if window was being minimized, otherwise false
- */
- bool isMinimized;
-
- /// is window restored
- /** true if window was being restored, otherwise false
- */
- bool isRestored;
-};
-
-
/// \ingroup AspectClasses
/// \ingroup WidgetLayout
/// Aspect class used by Widgets that have the possibility of setting and getting a
@@ -88,30 +59,14 @@
template< class WidgetType >
class AspectSizable
{
- struct SizeDispatcher {
- typedef std::tr1::function<bool (const WidgetSizedEventResult & )> F;
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
+ const WidgetType& W() const { return *static_cast<const WidgetType*>(this); }
- SizeDispatcher(const F& f_) : f(f_) { }
+ HWND H() const { return W().handle(); }
- bool operator()(const MSG& msg, LRESULT& ret) {
- return f(WidgetSizedEventResult( msg.wParam, msg.lParam ));
- }
+ typedef Dispatchers::ConvertBase<SizedEvent> SizeDispatcher;
+ typedef Dispatchers::ConvertBase<Point, &Point::fromMSG> MoveDispatcher;
- F f;
- };
-
- struct MoveDispatcher {
- typedef std::tr1::function<void (const Point & )> F;
-
- MoveDispatcher(const F& f_) : f(f_) { }
-
- bool operator()(const MSG& msg, LRESULT& ret) {
- f(Point( GET_X_LPARAM( msg.lParam ), GET_Y_LPARAM( msg.lParam ) ));
- return true;
- }
-
- F f;
- };
public:
/// Sets the new size and position of the window
/** The input parameter Rectangle defines the new size (and position) of the
@@ -295,9 +250,7 @@
* information.
*/
void onSized(const typename SizeDispatcher::F& f) {
- static_cast<WidgetType*>(this)->addCallback(
- Message( WM_SIZE ), SizeDispatcher(f)
- );
+ W().addCallback(Message( WM_SIZE ), SizeDispatcher(f));
}
/// \ingroup EventHandlersAspectSizable
@@ -306,14 +259,11 @@
* passed is Point which is the new position of the Widget
*/
void onMoved(const typename MoveDispatcher::F& f) {
- static_cast<WidgetType*>(this)->addCallback(
- Message( WM_MOVE ), MoveDispatcher(f)
- );
+ W().addCallback(Message( WM_MOVE ), MoveDispatcher(f));
}
protected:
- virtual ~AspectSizable()
- {}
+ virtual ~AspectSizable() { }
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -322,7 +272,7 @@
template< class WidgetType >
void AspectSizable< WidgetType >::setBounds( const Rectangle & rect, bool updateWindow )
{
- if ( ::MoveWindow( static_cast< WidgetType * >( this )->handle(),
+ if ( ::MoveWindow( H(),
rect.x(), rect.y(), rect.width(), rect.height(), updateWindow ? TRUE : FALSE ) == 0 )
{
xCeption err( _T( "Couldn't reposition windows" ) );
@@ -333,7 +283,7 @@
template< class WidgetType >
void AspectSizable< WidgetType >::setBounds( const Point & newPos, const Point & newSize, bool updateWindow )
{
- if ( ::MoveWindow( static_cast< WidgetType * >( this )->handle(), newPos.x, newPos.y, newSize.x, newSize.y, updateWindow ? TRUE : FALSE ) == 0 )
+ if ( ::MoveWindow( H(), newPos.x, newPos.y, newSize.x, newSize.y, updateWindow ? TRUE : FALSE ) == 0 )
{
xCeption err( _T( "Couldn't reposition windows" ) );
throw err;
@@ -343,7 +293,7 @@
template< class WidgetType >
void AspectSizable< WidgetType >::setBounds( int x, int y, int width, int height, bool updateWindow )
{
- if ( ::MoveWindow( static_cast< WidgetType * >( this )->handle(), x, y, width, height, updateWindow ? TRUE : FALSE ) == 0 )
+ if ( ::MoveWindow( H(), x, y, width, height, updateWindow ? TRUE : FALSE ) == 0 )
{
xCeption err( _T( "Couldn't reposition windows" ) );
throw err;
@@ -371,7 +321,7 @@
int yPos = rect.pos.y + border; // Start with current y and first border.
yPos += rownum * ( border + ySize ); // Accumulate other rows and borders
- ::MoveWindow( static_cast< WidgetType * >( this )->handle(), rect.x(), yPos,
+ ::MoveWindow( H(), rect.x(), yPos,
rect.width(), ySize, updateWindow ? TRUE : FALSE );
}
@@ -384,7 +334,7 @@
int xPos = rect.x() + border; // Start with current X and first border
xPos += colnum * ( border + xSize ); // Accumulate other columns and borders
- ::MoveWindow( static_cast< WidgetType * >( this )->handle(), xPos, rect.y(), xSize, rect.height(), updateWindow ? TRUE : FALSE );
+ ::MoveWindow( H(), xPos, rect.y(), xSize, rect.height(), updateWindow ? TRUE : FALSE );
}
template< class WidgetType >
@@ -436,7 +386,7 @@
int width, height;
RECT rc;
POINT pt;
- HWND hwnd = const_cast < WidgetType * >( static_cast< const WidgetType * >( this ) )->handle();
+ HWND hwnd = H();
::GetWindowRect( hwnd, & rc );
width = rc.right - rc.left;
height = rc.bottom - rc.top;
@@ -444,7 +394,7 @@
pt.y = rc.top;
if( adjustForParent )
{
- Widget* parent = static_cast< const WidgetType * >( this )->getParent();
+ Widget* parent = W().getParent();
if( parent )
{
//if it's a child, adjust coordinates relative to parent
@@ -471,7 +421,7 @@
Point AspectSizable< WidgetType >::getScreenPosition() const
{
RECT rc;
- ::GetWindowRect( const_cast < WidgetType * >( static_cast< const WidgetType * >( this ) )->handle(), & rc );
+ ::GetWindowRect( H(), & rc );
return Point( rc.left, rc.top );
}
@@ -481,7 +431,7 @@
Point AspectSizable< WidgetType >::getClientAreaSize() const
{
RECT rc;
- ::GetClientRect( const_cast < WidgetType * >( static_cast< const WidgetType * >( this ) )->handle(), & rc );
+ ::GetClientRect( H(), & rc );
return Point( rc.right, rc.bottom );
}
@@ -490,7 +440,7 @@
::getTextSize( const SmartUtil::tstring & text )
{
// Some win32 api code to determine the actual size of the string
- HWND hWnd = static_cast< WidgetType * >( this )->handle();
+ HWND hWnd = H();
HDC hDC = ::GetDC( hWnd );
HFONT hf = ( HFONT ) ::SendMessage( hWnd, WM_GETFONT, 0, 0 );
if ( 0 != hf )
@@ -498,13 +448,11 @@
SelectFont( hDC, hf );
}
- RECT wRect =
- { 0, 0, 0, 0
- };
+ RECT wRect = { 0, 0, 0, 0 };
DrawText( hDC, text.c_str(), ( int ) text.size(), & wRect, DT_CALCRECT );
::ReleaseDC( hWnd, hDC );
- return( Point( wRect.right, wRect.bottom ) );
+ return(Point( wRect.right, wRect.bottom ) );
}
template< class WidgetType >
@@ -518,7 +466,7 @@
#else
typename WidgetType::MaxiMiniRestorable checker;
#endif
- ::ShowWindow( static_cast< WidgetType * >( this )->handle(), SW_SHOWMAXIMIZED );
+ ::ShowWindow(H(), SW_SHOWMAXIMIZED );
}
template< class WidgetType >
@@ -532,7 +480,7 @@
#else
typename WidgetType::MaxiMiniRestorable checker;
#endif
- ::ShowWindow( static_cast< WidgetType * >( this )->handle(), SW_MINIMIZE );
+ ::ShowWindow(H(), SW_MINIMIZE );
}
template< class WidgetType >
@@ -546,31 +494,31 @@
#else
typename WidgetType::MaxiMiniRestorable checker;
#endif
- ::ShowWindow( static_cast< WidgetType * >( this )->handle(), SW_RESTORE );
+ ::ShowWindow(H(), SW_RESTORE );
}
template< class WidgetType >
void AspectSizable< WidgetType >::bringToFront()
{
- ::SetWindowPos( static_cast< WidgetType * >( this )->handle(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
+ ::SetWindowPos(H(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
}
template< class WidgetType >
void AspectSizable< WidgetType >::bringToBottom()
{
- ::SetWindowPos( static_cast< WidgetType * >( this )->handle(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
+ ::SetWindowPos(H(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
}
template< class WidgetType >
bool AspectSizable< WidgetType >::isIconic()
{
- return ::IsIconic( static_cast< WidgetType * >( this )->handle()) > 0;
+ return ::IsIconic(H()) > 0;
}
template< class WidgetType >
bool AspectSizable< WidgetType >::isZoomed()
{
- return ::IsZoomed( static_cast< WidgetType * >( this )->handle()) > 0;
+ return ::IsZoomed(H()) > 0;
}
// end namespace SmartWin
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectText.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectText.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectText.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -29,6 +29,7 @@
#define AspectText_h
#include "../../SmartUtil.h"
+#include "../Dispatchers.h"
namespace SmartWin
{
@@ -43,19 +44,15 @@
template< class WidgetType >
class AspectText
{
- struct Dispatcher
- {
- typedef std::tr1::function<void (const SmartUtil::tstring &)> F;
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
+ const WidgetType& W() const { return *static_cast<const WidgetType*>(this); }
- Dispatcher(const F& f_) : f(f_) { }
-
- bool operator()(const MSG& msg, LRESULT& ret) {
- f(SmartUtil::tstring( reinterpret_cast< TCHAR * >( msg.lParam ) ));
- return false;
- }
-
- F f;
- };
+ static SmartUtil::tstring isActive(const MSG& msg) {
+ return SmartUtil::tstring( reinterpret_cast< TCHAR * >( msg.lParam ) );
+ }
+
+ typedef Dispatchers::ConvertBase<SmartUtil::tstring, &AspectText<WidgetType>::isActive, false> Dispatcher;
+ friend class Dispatchers::ConvertBase<SmartUtil::tstring, &AspectText<WidgetType>::isActive, false>;
public:
/// Sets the text of the AspectText realizing class
/** The txt parameter is the new text to put into the realizing object.
@@ -88,9 +85,7 @@
* Widget.
*/
void onTextChanging(const typename Dispatcher::F& f) {
- static_cast<WidgetType*>(this)->addCallback(
- Message( WM_SETTEXT ), Dispatcher(f)
- );
+ W().addCallback(Message( WM_SETTEXT ), Dispatcher(f));
}
protected:
@@ -104,7 +99,7 @@
template< class WidgetType >
void AspectText< WidgetType >::setText( const SmartUtil::tstring & txt )
{
- static_cast< WidgetType * >( this )->sendMessage(WM_SETTEXT, 0, reinterpret_cast< LPARAM >(txt.c_str()) );
+ W().sendMessage(WM_SETTEXT, 0, reinterpret_cast< LPARAM >(txt.c_str()) );
}
@@ -135,7 +130,7 @@
template< class WidgetType >
size_t AspectText< WidgetType >::length( ) const {
- return static_cast<size_t>(static_cast<const WidgetType*>(this)->sendMessage(WM_GETTEXTLENGTH));
+ return W().sendMessage(WM_GETTEXTLENGTH);
}
template< class WidgetType >
@@ -145,7 +140,7 @@
if ( textLength == 0 )
return _T( "" );
SmartUtil::tstring retVal(textLength + 1, 0);
- retVal.resize(static_cast<const WidgetType*>(this)->sendMessage(WM_GETTEXT, static_cast<WPARAM>(textLength + 1), reinterpret_cast<LPARAM>(&retVal[0])));
+ retVal.resize(W().sendMessage(WM_GETTEXT, static_cast<WPARAM>(textLength + 1), reinterpret_cast<LPARAM>(&retVal[0])));
return retVal;
}
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectUpdate.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectUpdate.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectUpdate.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -45,6 +45,7 @@
template< class WidgetType >
class AspectUpdate
{
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
typedef Dispatchers::VoidVoid<> Dispatcher;
public:
/// \ingroup EventHandlersAspectUpdate
@@ -52,14 +53,11 @@
/** When the Widget value/text is being updated this event will be raised.
*/
void onUpdate(const Dispatcher::F& f) {
- static_cast<WidgetType*>(this)->addCallback(
- WidgetType::getUpdateMessage(), Dispatcher(f)
- );
+ W().addCallback(WidgetType::getUpdateMessage(), Dispatcher(f));
}
protected:
- virtual ~AspectUpdate()
- {}
+ virtual ~AspectUpdate() { }
};
// end namespace SmartWin
Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectVisible.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectVisible.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectVisible.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -28,6 +28,8 @@
#ifndef AspectVisible_h
#define AspectVisible_h
+#include "../Dispatchers.h"
+
namespace SmartWin
{
// begin namespace SmartWin
@@ -46,19 +48,15 @@
template< class WidgetType >
class AspectVisible
{
- struct Dispatcher
- {
- typedef std::tr1::function<void (bool)> F;
+ WidgetType& W() { return *static_cast<WidgetType*>(this); }
+ const WidgetType& W() const { return *static_cast<const WidgetType*>(this); }
+ HWND H() const { return W().handle(); }
- Dispatcher(const F& f_) : f(f_) { }
+ static bool isVisible(const MSG& msg) { return msg.wParam > 0; }
+
+ typedef Dispatchers::ConvertBase<bool, &AspectVisible<WidgetType>::isVisible> Dispatcher;
+ friend class Dispatchers::ConvertBase<bool, &AspectVisible<WidgetType>::isVisible>;
- bool operator()(const MSG& msg, LRESULT& ret) {
- f(msg.wParam > 0);
- return true;
- }
-
- F f;
- };
public:
/// Sets the visibility property of the Widget
/** Changes the visibility property of the Widget. <br>
@@ -81,9 +79,7 @@
* invisible.
*/
void onVisibilityChanged(const typename Dispatcher::F& f) {
- static_cast<WidgetType*>(this)->addCallback(
- Message( WM_SHOWWINDOW ), Dispatcher(f)
- );
+ W().addCallback(Message( WM_SHOWWINDOW ), Dispatcher(f));
}
protected:
@@ -97,13 +93,13 @@
template< class WidgetType >
void AspectVisible< WidgetType >::setVisible( bool visible )
{
- ::ShowWindow( static_cast< WidgetType * >( this )->handle(), visible ? SW_SHOW : SW_HIDE );
+ ::ShowWindow( H(), visible ? SW_SHOW : SW_HIDE );
}
template< class WidgetType >
bool AspectVisible< WidgetType >::getVisible() const
{
- return ::IsWindowVisible( static_cast< const WidgetType * >( this )->handle() ) != 0;
+ return ::IsWindowVisible( H() ) != 0;
}
// end namespace SmartWin
}
Modified: dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetComboBox.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetComboBox.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetComboBox.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -58,7 +58,7 @@
*/
class WidgetComboBox :
// Aspects
- public AspectBackgroundColor< WidgetComboBox >,
+ public AspectCtlColor< WidgetComboBox >,
public AspectBorder< WidgetComboBox >,
public AspectClickable< WidgetComboBox >,
public AspectControl<WidgetComboBox>,
Modified: dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetStatic.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetStatic.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetStatic.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -62,7 +62,7 @@
*/
class WidgetStatic :
// Aspects
- public AspectBackgroundColor< WidgetStatic >,
+ public AspectCtlColor< WidgetStatic >,
public AspectBorder< WidgetStatic >,
public AspectClickable< WidgetStatic >,
public AspectControl<WidgetStatic>,
Modified: dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTabView.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTabView.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTabView.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -109,7 +109,7 @@
void setTop(WidgetChildWindow* w);
bool handleTextChanging(WidgetChildWindow* w, const SmartUtil::tstring& newText);
- bool handleSized(const WidgetSizedEventResult&);
+ void handleSized(const SizedEvent&);
void handleTabSelected();
LRESULT handleToolTip(LPARAM lParam);
void handleLeftMouseDown(const MouseEventResult& mouseEventResult);
Modified: dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTextBox.h
===================================================================
--- dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTextBox.h 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetTextBox.h 2008-03-26 14:11:12 UTC (rev 1062)
@@ -66,7 +66,7 @@
*/
class WidgetTextBoxBase :
// Aspect classes
- public AspectBackgroundColor< WidgetTextBoxBase >,
+ public AspectCtlColor< WidgetTextBoxBase >,
public AspectBorder< WidgetTextBoxBase >,
public AspectControl< WidgetTextBoxBase >,
public AspectFocus< WidgetTextBoxBase >,
Modified: dcplusplus/trunk/smartwin/source/Application.cpp
===================================================================
--- dcplusplus/trunk/smartwin/source/Application.cpp 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/source/Application.cpp 2008-03-26 14:11:12 UTC (rev 1062)
@@ -367,15 +367,7 @@
#endif // not __WINE__
-WidgetSizedEventResult::WidgetSizedEventResult( WPARAM wP, LPARAM lP )
-{
- newSize = Point( GET_X_LPARAM( lP ), GET_Y_LPARAM( lP ) );
- isMaximized = ( wP == SIZE_MAXIMIZED );
- isMinimized = ( wP == SIZE_MINIMIZED );
- isRestored = ( wP == SIZE_RESTORED );
-}
-
-MouseEventResult::MouseEventResult(HWND hwnd, WPARAM wP, LPARAM lP ) : pos(Point(GET_X_LPARAM( lP ), GET_Y_LPARAM( lP ))) {
+MouseEventResult::MouseEventResult(HWND hwnd, WPARAM wP, LPARAM lP ) : pos(Point::fromLParam(lP)) {
isShiftPressed = ( ( wP & MK_SHIFT ) == MK_SHIFT );
::ClientToScreen(hwnd, &pos.getPoint());
Added: dcplusplus/trunk/smartwin/source/Events.cpp
===================================================================
--- dcplusplus/trunk/smartwin/source/Events.cpp (rev 0)
+++ dcplusplus/trunk/smartwin/source/Events.cpp 2008-03-26 14:11:12 UTC (rev 1062)
@@ -0,0 +1,14 @@
+#include "../include/smartwin/Events.h"
+
+namespace SmartWin {
+
+SizedEvent::SizedEvent( const MSG& msg ) :
+ size(Point::fromLParam(msg.lParam)),
+ isMaximized(msg.wParam == SIZE_MAXIMIZED),
+ isMinimized(msg.wParam == SIZE_MINIMIZED),
+ isRestored(msg.wParam == SIZE_RESTORED)
+{
+}
+
+}
+
Modified: dcplusplus/trunk/smartwin/source/Point.cpp
===================================================================
--- dcplusplus/trunk/smartwin/source/Point.cpp 2008-03-26 14:04:21 UTC (rev 1061)
+++ dcplusplus/trunk/smartwin/source/Point.cpp 2008-03-26 14:11:12 UTC (rev 1062)
@@ -33,73 +33,44 @@
{
// begin namespace SmartWin
-Point::Point( long pX, long pY )
-{ x = pX; y = pY; }
-
-Point::Point()
-{ x = y = 0; }
-
-Point::Point(const POINT& pt) : POINT(pt) { }
-
-Point::operator POINT() const {
- POINT pt = { x, y };
- return pt;
-}
-
-void Point::maxOf( const Point & p )
-{
+void Point::maxOf( const Point & p ) {
if ( p.x > x )
x = p.x;
if ( p.y > y )
y = p.y;
}
-void Point::minOf( const Point & p )
-{
+void Point::minOf( const Point & p ) {
if ( p.x < x )
x = p.x;
if ( p.y < y )
y = p.y;
}
-Point & operator += ( Point & lhs, const Point & rhs )
-{
+Point & operator += ( Point & lhs, const Point & rhs ) {
lhs.x += rhs.x;
lhs.y += rhs.y;
return lhs;
}
-Point operator +( const Point & lhs, const Point & rhs )
-{
+Point operator +( const Point & lhs, const Point & rhs ) {
Point retVal = lhs;
retVal += rhs;
return retVal;
}
-Point & operator -= ( Point & lhs, const Point & rhs )
-{
+Point & operator -= ( Point & lhs, const Point & rhs ) {
lhs.x -= rhs.x;
lhs.y -= rhs.y;
return lhs;
}
-Point operator -( const Point & lhs, const Point & rhs )
-{
+Point operator -( const Point & lhs, const Point & rhs ) {
Point retVal = lhs;
retVal -= rhs;
return retVal;
}
-bool operator == ( const Point & lhs, const Point & rhs )
-{
- ...
[truncated message content] |