summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/GNUmakefile9
-rw-r--r--src/autocheck.cpp4
-rw-r--r--src/button.cpp4
-rw-r--r--src/control.cpp48
-rw-r--r--src/debug.cpp2
-rw-r--r--src/dialog.cpp61
-rw-r--r--src/static.cpp1
-rw-r--r--src/test/w32dtst.cpp7
-rw-r--r--src/text.cpp1
-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
17 files changed, 226 insertions, 189 deletions
diff --git a/src/GNUmakefile b/src/GNUmakefile
index 1a4c078..4ab212c 100644
--- a/src/GNUmakefile
+++ b/src/GNUmakefile
@@ -18,7 +18,7 @@
#
# -------------------------------------------------------------------------
#
-# $Id: GNUmakefile,v 1.3 2005-03-24 02:09:12 ianc Exp $
+# $Id: GNUmakefile,v 1.4 2005-03-25 01:23:52 ianc Exp $
#
@@ -55,7 +55,8 @@ SOURCES = autocheck.cpp \
dialog.cpp \
text.cpp \
static.cpp \
- debug.cpp
+ debug.cpp \
+ window.cpp
HEADERS = w32dlib/*.h
@@ -73,6 +74,10 @@ $(TARGET): $(OBJECTS) GNUMakefile
doc: $(DOCDIR)/html/index.html
+cleandoc:
+ -rm -rf $(DOCDIR)/*
+
+
$(DOCDIR)/html/index.html: $(HEADERS)
-rm -rf $(DOCDIR)/*
cd w32dlib ; doxygen
diff --git a/src/autocheck.cpp b/src/autocheck.cpp
index 203fe0d..bfb45c7 100644
--- a/src/autocheck.cpp
+++ b/src/autocheck.cpp
@@ -18,6 +18,7 @@
//
// -------------------------------------------------------------------------
//
+#include "w32dlib/window.h"
#include "w32dlib/autocheck.h"
#include "w32dlib/dialog.h"
@@ -42,8 +43,7 @@ AutoCheck::~AutoCheck()
// ------------------------------------------------------------
//
-void AutoCheck::OnPress(W32DLibCallbackInterface *owner,
- W32DLibCallback callback)
+void AutoCheck::OnPress(Window *owner, W32DLibCallback callback)
{
Control::AddCallback(WM_COMMAND,owner,callback);
}
diff --git a/src/button.cpp b/src/button.cpp
index c14840a..f08f474 100644
--- a/src/button.cpp
+++ b/src/button.cpp
@@ -18,6 +18,7 @@
//
// -------------------------------------------------------------------------
//
+#include "w32dlib/window.h"
#include "w32dlib/button.h"
#include "w32dlib/dialog.h"
@@ -41,8 +42,7 @@ Button::~Button()
// ------------------------------------------------------------
//
-void Button::OnPress(W32DLibCallbackInterface *owner,
- W32DLibCallback callback)
+void Button::OnPress(Window *owner, W32DLibCallback callback)
{
Control::AddCallback(WM_COMMAND,owner,callback);
}
diff --git a/src/control.cpp b/src/control.cpp
index 392c72e..75f96a1 100644
--- a/src/control.cpp
+++ b/src/control.cpp
@@ -18,6 +18,7 @@
//
// -------------------------------------------------------------------------
//
+#include "w32dlib/window.h"
#include "w32dlib/control.h"
#include "w32dlib/dialog.h"
@@ -28,6 +29,7 @@ namespace W32DLib
// ------------------------------------------------------------
//
Control::Control(Dialog *parent, int resource_id) :
+ Window(),
m_parent(parent),
m_resid(resource_id),
m_cblist()
@@ -52,48 +54,6 @@ int Control::ResourceID()
// ------------------------------------------------------------
//
-void Control::SetText(const char *text)
-{
- SetDlgItemText(m_parent->GetHWND(),m_resid,text);
-}
-
-
-// ------------------------------------------------------------
-//
-std::string Control::GetText(int maxlen)
-{
- char *buff=new char[maxlen+1];
- std::string res;
-
- if (GetDlgItemText(m_parent->GetHWND(),m_resid,buff,maxlen))
- {
- res=buff;
- }
-
- delete[] buff;
-
- return res;
-}
-
-
-// ------------------------------------------------------------
-//
-HWND Control::GetHWND()
-{
- return m_wnd;
-}
-
-
-// ------------------------------------------------------------
-//
-void Control::Enable(bool enable)
-{
- EnableWindow(m_wnd,enable);
-}
-
-
-// ------------------------------------------------------------
-//
BOOL Control::ProcessMessage(UINT msg, WPARAM wp, LPARAM lp)
{
if (msg==WM_INITDIALOG)
@@ -104,7 +64,7 @@ BOOL Control::ProcessMessage(UINT msg, WPARAM wp, LPARAM lp)
if (m_cblist.count(msg)>0)
{
CallbackDetails details=m_cblist[msg];
- W32DLibCallbackInterface *owner=details.owner;
+ Window *owner=details.owner;
W32DLibCallback cb=details.cb;
return (owner->*cb)(msg,wp,lp);
@@ -117,7 +77,7 @@ BOOL Control::ProcessMessage(UINT msg, WPARAM wp, LPARAM lp)
// ------------------------------------------------------------
//
void Control::AddCallback(UINT msg,
- W32DLibCallbackInterface *owner,
+ Window *owner,
W32DLibCallback callback)
{
CallbackDetails details;
diff --git a/src/debug.cpp b/src/debug.cpp
index 593069f..f697041 100644
--- a/src/debug.cpp
+++ b/src/debug.cpp
@@ -221,7 +221,7 @@ const char *MsgName(UINT msg)
const char *MsgName(UINT msg)
{
- return "Not available";
+ return "";
}
#endif // W32D_DEBUG
diff --git a/src/dialog.cpp b/src/dialog.cpp
index 9291268..96d80f9 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -18,19 +18,16 @@
//
// -------------------------------------------------------------------------
//
+#include "w32dlib/window.h"
#include "w32dlib/dialog.h"
#include "w32dlib/control.h"
namespace W32DLib
{
-// ------------------------------------------------------------
-//
-Dialog::ProcSet Dialog::m_procset;
-
// ------------------------------------------------------------
//
-Dialog::Dialog()
+Dialog::Dialog() : Window()
{
}
@@ -58,20 +55,12 @@ void Dialog::OnClose()
// ------------------------------------------------------------
//
-HWND Dialog::GetHWND()
-{
- return m_wnd;
-}
-
-
-// ------------------------------------------------------------
-//
INT_PTR Dialog::ShowModal(HINSTANCE inst, HWND parent)
{
return ::DialogBoxParam(inst,
MAKEINTRESOURCE(ResourceID()),
parent,
- &DialogProc,
+ &Window::WindowProc,
reinterpret_cast<LPARAM>(this));
}
@@ -86,9 +75,12 @@ void Dialog::Close(INT_PTR result)
// ------------------------------------------------------------
//
-void Dialog::SetTitle(const char *text)
+void Dialog::Enable(bool enable)
{
- SendMessage(m_wnd,WM_SETTEXT,0,reinterpret_cast<LPARAM>(text));
+ for(ControlSet::iterator i=m_cset.begin();i!=m_cset.end();++i)
+ {
+ (*i)->Enable(enable);
+ }
}
@@ -103,20 +95,16 @@ void Dialog::AddControl(Control *control)
// ------------------------------------------------------------
//
-BOOL Dialog::InstanceDialogProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
+BOOL Dialog::InstanceProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
{
BOOL ret=FALSE;
WORD lo=LOWORD(wp);
- W32DEBUGOUT("resource=" << ResourceID() <<
- " wnd= " << wnd << " msg=" << MsgName(msg) <<
- " wp=" << wp << " lp=" << lp);
-
switch(msg)
{
case WM_INITDIALOG:
+ Window::InstanceProc(wnd,msg,wp,lp);
m_wnd=wnd;
- m_procset[wnd]=this;
for(ControlSet::iterator i=m_cset.begin();i!=m_cset.end();++i)
{
@@ -130,7 +118,10 @@ BOOL Dialog::InstanceDialogProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
case WM_CLOSE:
OnClose();
- m_procset.erase(wnd);
+ break;
+
+ case WM_DESTROY:
+ ret=Window::InstanceProc(wnd,msg,wp,lp);
break;
default:
@@ -149,30 +140,6 @@ BOOL Dialog::InstanceDialogProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
return ret;
}
-// ------------------------------------------------------------
-//
-
-BOOL CALLBACK Dialog::DialogProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
-{
- if (msg==WM_INITDIALOG)
- {
- Dialog *dlg=reinterpret_cast<Dialog*>(lp);
- return dlg->InstanceDialogProc(wnd,msg,wp,lp);
- }
- else
- {
- if (m_procset.count(wnd))
- {
- return m_procset[wnd]->InstanceDialogProc(wnd,msg,wp,lp);
- }
- else
- {
- return FALSE;
- }
- }
-}
-
-
}; // namespace w32dlib
// END OF FILE
diff --git a/src/static.cpp b/src/static.cpp
index 0dc10e3..bf0c20e 100644
--- a/src/static.cpp
+++ b/src/static.cpp
@@ -18,6 +18,7 @@
//
// -------------------------------------------------------------------------
//
+#include "w32dlib/window.h"
#include "w32dlib/static.h"
namespace W32DLib
diff --git a/src/test/w32dtst.cpp b/src/test/w32dtst.cpp
index 984df33..6ce87d1 100644
--- a/src/test/w32dtst.cpp
+++ b/src/test/w32dtst.cpp
@@ -59,7 +59,7 @@ public:
{
std::cout << "OnInit()" << std::endl;
m_text.SetText("Hello");
- m_check.SetState(W32DLib::AutoCheck::eIndeterminate);
+ m_check.SetState(W32DLib::AutoCheck::eChecked);
m_quit.Enable(true);
}
@@ -85,7 +85,7 @@ private:
std::cout << "text=" << txt << std::endl;
std::cout << "check=" << m_check.GetState() << std::endl;
m_static.SetText(txt.c_str());
- SetTitle((txt+" [Title]").c_str());
+ SetText((txt+" [Title]").c_str());
return TRUE;
}
@@ -95,7 +95,8 @@ private:
std::cout << "Called OnCheck() - state " << state << std::endl;
- m_quit.Enable(state==W32DLib::AutoCheck::eChecked);
+ //m_quit.Enable(state==W32DLib::AutoCheck::eChecked);
+ Enable(state==W32DLib::AutoCheck::eChecked);
return TRUE;
}
diff --git a/src/text.cpp b/src/text.cpp
index d8f1f82..ff4241d 100644
--- a/src/text.cpp
+++ b/src/text.cpp
@@ -18,6 +18,7 @@
//
// -------------------------------------------------------------------------
//
+#include "w32dlib/window.h"
#include "w32dlib/text.h"
namespace W32DLib
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