summaryrefslogtreecommitdiff
path: root/src/w32dlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/w32dlib')
-rw-r--r--src/w32dlib/Doxyfile2
-rw-r--r--src/w32dlib/autocheck.h2
-rw-r--r--src/w32dlib/base.h27
-rw-r--r--src/w32dlib/button.h2
-rw-r--r--src/w32dlib/control.h52
-rw-r--r--src/w32dlib/dialog.h45
-rw-r--r--src/w32dlib/w32dlib.h1
-rw-r--r--src/w32dlib/window.h147
8 files changed, 190 insertions, 88 deletions
diff --git a/src/w32dlib/Doxyfile b/src/w32dlib/Doxyfile
index d74787d..9c2aa6d 100644
--- a/src/w32dlib/Doxyfile
+++ b/src/w32dlib/Doxyfile
@@ -23,7 +23,7 @@ ABBREVIATE_BRIEF = "The $name class" \
an \
the
ALWAYS_DETAILED_SEC = NO
-INLINE_INHERITED_MEMB = NO
+INLINE_INHERITED_MEMB = YES
FULL_PATH_NAMES = NO
STRIP_FROM_PATH = ..
STRIP_FROM_INC_PATH = ..
diff --git a/src/w32dlib/autocheck.h b/src/w32dlib/autocheck.h
index e58d5f9..a40c703 100644
--- a/src/w32dlib/autocheck.h
+++ b/src/w32dlib/autocheck.h
@@ -61,7 +61,7 @@ namespace W32DLib
/// \param owner The class the callback reside in.
/// \param callback The callback.
///
- void OnPress(W32DLibCallbackInterface *owner,
+ void OnPress(Window *owner,
W32DLibCallback callback);
diff --git a/src/w32dlib/base.h b/src/w32dlib/base.h
index fbae2e4..062d4c3 100644
--- a/src/w32dlib/base.h
+++ b/src/w32dlib/base.h
@@ -34,25 +34,16 @@
namespace W32DLib
{
+class Window;
class Dialog;
class Control;
-/// \brief Dummy class to allow the use of callbacks.
-///
-class W32DLibCallbackInterface
-{
- public:
- W32DLibCallbackInterface() {}
- virtual ~W32DLibCallbackInterface() {}
-};
-
/// \brief The callback type for W32DLib.
///
/// Simply accepts the usual Windows message parameters, and must return TRUE
/// if the event was handled.
///
-typedef BOOL (W32DLibCallbackInterface::*W32DLibCallback)
- (UINT msg, WPARAM wp, LPARAM lp);
+typedef BOOL (Window::*W32DLibCallback) (UINT msg, WPARAM wp, LPARAM lp);
#ifdef W32D_DEBUG
@@ -67,10 +58,6 @@ typedef BOOL (W32DLibCallbackInterface::*W32DLibCallback)
OutputDebugString(s.str().c_str()); \
} while(0)
-/// \brief A table of Windows message names
-///
-const char *MsgName(UINT msg);
-
#else
/// \brief Debug macro for non-debug builds (does nothing).
@@ -79,6 +66,16 @@ const char *MsgName(UINT msg);
#endif
+/// \brief A table of Windows message names
+///
+/// Only available in debug builds -- returns an empty string otherwise.
+///
+/// \param msg A Windows Message ID
+/// \return The message type as a readable string
+///
+const char *MsgName(UINT msg);
+
+
};
diff --git a/src/w32dlib/button.h b/src/w32dlib/button.h
index 3ba48b3..c35a06c 100644
--- a/src/w32dlib/button.h
+++ b/src/w32dlib/button.h
@@ -50,7 +50,7 @@ namespace W32DLib
/// \param owner The class the callback reside in.
/// \param callback The callback.
///
- void OnPress(W32DLibCallbackInterface *owner,
+ void OnPress(Window *owner,
W32DLibCallback callback);
protected:
diff --git a/src/w32dlib/control.h b/src/w32dlib/control.h
index 85106a9..5096abf 100644
--- a/src/w32dlib/control.h
+++ b/src/w32dlib/control.h
@@ -29,7 +29,7 @@ namespace W32DLib
/// \brief The base Control class.
///
- class Control : public W32DLibCallbackInterface
+ class Control : public Window
{
public:
@@ -48,43 +48,15 @@ namespace W32DLib
///
int ResourceID();
- /// \brief Sets the text in a control
- ///
- /// \param text The control's text
- /// \sa GetText()
- ///
- void SetText(const char *text);
-
- /// \brief Gets the text in a control
- ///
- /// \param maxlen The maximum length to fetch
- /// \return The control's text
- /// \sa SetText()
- ///
- std::string GetText(int maxlen);
-
- /// \brief Enables or disables the control.
- ///
- /// Calling this when the dialog is not on display is undefined.
- ///
- /// \param enable Set true to enable, false to disable.
- ///
- void Enable(bool enable);
-
- /// \brief Gets the control's window handle
- ///
- /// Calling this when the dialog is not on display is undefined.
- ///
- /// \return The window handle
- ///
- HWND GetHWND();
-
/// \brief Processes a windows event.
///
- /// \param msg The Windows event parameters
+ /// This is called by the Dialog when a message is recieved that
+ /// refers to this control's resource ID.
+ ///
+ /// \param msg The Windows event
/// \param wp The Windows event parameters
/// \param lp The Windows event parameters
- /// \return True if the message was processed.
+ /// \return TRUE if the message was processed.
///
BOOL ProcessMessage(UINT msg, WPARAM wp, LPARAM lp);
@@ -95,11 +67,11 @@ namespace W32DLib
/// \param msg The Windows event message to respond to.
/// \param owner The class (generally a Dialog derived one) in which
/// the callback resides. The class must be derived from
- /// W32DLibCallbackInterface.
+ /// Window.
/// \param callback The callback.
///
void AddCallback(UINT msg,
- W32DLibCallbackInterface *owner,
+ Window *owner,
W32DLibCallback callback);
/// \brief Filled in by the constructor with the parent dialog.
@@ -110,16 +82,12 @@ namespace W32DLib
///
int m_resid;
- /// \brief Filled in when the WM_INITDIALOG message is recieved.
- ///
- HWND m_wnd;
-
private:
struct CallbackDetails
{
- W32DLibCallbackInterface *owner;
- W32DLibCallback cb;
+ Window *owner;
+ W32DLibCallback cb;
};
typedef std::map<UINT,CallbackDetails> CallbackList;
diff --git a/src/w32dlib/dialog.h b/src/w32dlib/dialog.h
index bbc1d51..ea9ce4b 100644
--- a/src/w32dlib/dialog.h
+++ b/src/w32dlib/dialog.h
@@ -28,7 +28,7 @@ namespace W32DLib
{
/// \brief The base Dialog class.
///
- class Dialog : public W32DLibCallbackInterface
+ class Dialog : public Window
{
public:
@@ -59,12 +59,11 @@ namespace W32DLib
///
virtual void OnClose();
- /// \brief Returns the HWND for the dialog.
+ /// \brief Enables or disables all Controls in the dialog.
///
- /// This call will only work while the dialog is on display.
- /// The behaviour is undefined if it is called at any other time.
+ /// Overrides Window::Enable.
///
- HWND GetHWND();
+ void Enable(bool enable);
/// \brief Displays a modal dialog.
///
@@ -88,15 +87,6 @@ namespace W32DLib
///
void Close(INT_PTR result);
- /// \brief Sets the title in a dialog box
- ///
- /// This call will only work while the dialog is on display.
- /// The behaviour is undefined if it is called at any other time.
- ///
- /// \param text The title
- ///
- void SetTitle(const char *text);
-
protected:
/// \brief Adds a control to the dialog.
@@ -106,27 +96,26 @@ namespace W32DLib
///
void AddControl(Control *control);
+ /// \brief Handles windows messages.
+ ///
+ /// \param wnd The window handle
+ /// \param msg The message
+ /// \param wp Additional parameters. Depends on the value of msg.
+ /// \param lp Additional parameters. Depends on the value of msg.
+ /// \return TRUE if the message has been handled.
+ /// \sa Window::InstanceProc
+ ///
+ virtual BOOL InstanceProc(HWND wnd,
+ UINT msg,
+ WPARAM wp,
+ LPARAM lp);
private:
typedef std::vector<Control*> ControlSet;
- typedef std::map<HWND,Dialog*> ProcSet;
- HWND m_wnd;
bool m_open;
ControlSet m_cset;
- static ProcSet m_procset;
-
- BOOL InstanceDialogProc(HWND wnd,
- UINT msg,
- WPARAM wp,
- LPARAM lp);
-
- static BOOL CALLBACK DialogProc(HWND wnd,
- UINT msg,
- WPARAM wp,
- LPARAM lp);
-
}; // class Dialog
}; // namespace w32dlib
diff --git a/src/w32dlib/w32dlib.h b/src/w32dlib/w32dlib.h
index 9f9dabb..914179e 100644
--- a/src/w32dlib/w32dlib.h
+++ b/src/w32dlib/w32dlib.h
@@ -22,6 +22,7 @@
#define W32DLIB_H "$Id$"
+#include <w32dlib/window.h>
#include <w32dlib/dialog.h>
#include <w32dlib/control.h>
#include <w32dlib/button.h>
diff --git a/src/w32dlib/window.h b/src/w32dlib/window.h
new file mode 100644
index 0000000..2f2d1a6
--- /dev/null
+++ b/src/w32dlib/window.h
@@ -0,0 +1,147 @@
+// w32dlib - Win32 Window Helpers
+//
+// Copyright (C) 2005 Ian Cowburn (ianc@noddybox.demon.co.uk)
+//
+// 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 W32DLIB_WINDOW_H
+
+#define W32DLIB_WINDOW_H "$Id$"
+
+#include "w32dlib/base.h"
+
+namespace W32DLib
+{
+ /// \brief The base Window class.
+ ///
+ class Window
+ {
+ public:
+
+ /// \brief Constructor
+ ///
+ Window();
+
+ /// \brief Destructor
+ ///
+ virtual ~Window();
+
+ /// \brief Returns the HWND for the window.
+ ///
+ /// This call will only work while the window is on display.
+ /// The behaviour is undefined if it is called at any other time.
+ ///
+ HWND GetHWND();
+
+ /// \brief Sets the window text.
+ ///
+ /// This call will only work while the window is on display.
+ /// The behaviour is undefined if it is called at any other time.
+ ///
+ /// \param text The text
+ /// \sa GetText()
+ ///
+ virtual void SetText(const char *text);
+
+ /// \brief Gets the window text
+ ///
+ /// This call will only work while the window is on display.
+ /// The behaviour is undefined if it is called at any other time.
+ ///
+ /// \param maxlen The maximum length to fetch
+ /// \return The control's text
+ /// \sa SetText()
+ ///
+ virtual std::string GetText(int maxlen);
+
+ /// \brief Enables or disables the window.
+ ///
+ /// This call will only work while the window is on display.
+ /// The behaviour is undefined if it is called at any other time.
+ ///
+ /// \param enable Set true to enable, false to disable.
+ ///
+ virtual void Enable(bool enable);
+
+ protected:
+
+ /// \brief Handles windows messages.
+ ///
+ /// If the window handles messages (like Dialog), then this must
+ /// be overwridden so that Window::WindowProc will pass on the messages.
+ ///
+ /// If the message has not been handled, or is WM_DESTROY, then the base
+ /// version should be called.
+ ///
+ /// Note that the reason it should be called for WM_DESTROY is so that
+ /// the internal mapping of windows to Window class instances can
+ /// be tidied up.
+ ///
+ /// \param wnd The window handle
+ /// \param msg The message
+ /// \param wp Additional parameters. Depends on the value of msg.
+ /// \param lp Additional parameters. Depends on the value of msg.
+ /// \return TRUE if the message has been handled.
+ ///
+ virtual BOOL InstanceProc(HWND wnd,
+ UINT msg,
+ WPARAM wp,
+ LPARAM lp);
+
+ /// \brief The window handle for this window.
+ ///
+ /// The base Window::InstanceProc will set this from the wnd parameter
+ /// for WM_INITDIALOG or WM_CREATE.
+ ///
+ /// Other derived classes should set the window as appropriate (for
+ /// instance controls from GetDlgItem()).
+ ///
+ HWND m_wnd;
+
+ /// \brief The base WindProc.
+ ///
+ /// This is the WindProc/DialogProc that should be used. Note that
+ /// it expects a pointer to a Window in lp when called with
+ /// WM_INITDIALOG or WM_CREATE.
+ ///
+ /// \param wnd The window handle
+ /// \param msg The message
+ /// \param wp Additional parameters. Depends on the value of msg.
+ /// \param lp Additional parameters. Depends on the value of msg.
+ /// \return TRUE if the message has been handled.
+ ///
+ static BOOL CALLBACK WindowProc(HWND wnd,
+ UINT msg,
+ WPARAM wp,
+ LPARAM lp);
+
+ private:
+
+ // Defines a mapping between HWND and Window instances
+ //
+ typedef std::map<HWND,Window*> ProcSet;
+
+ static ProcSet m_procset;
+
+ }; // class Window
+
+}; // namespace w32dlib
+
+#endif // W32DLIB_WINDOW_H
+
+
+// END OF FILE