From 5a11b5f4b59c46e919989a0fdd05d81ba5ac9347 Mon Sep 17 00:00:00 2001 From: Ian C Date: Thu, 24 Mar 2005 00:07:40 +0000 Subject: Code updates --- src/GNUmakefile | 13 +++++--- src/autocheck.cpp | 7 ++--- src/button.cpp | 8 ++--- src/common.cpp | 2 -- src/control.cpp | 31 +++++++----------- src/dialog.cpp | 2 -- src/test/.cvsignore | 2 ++ src/test/GNUmakefile | 61 +++++++++++++++++++++++++++++++++++ src/test/dialog.h | 6 ++++ src/test/dialog.rc | 14 +++++++++ src/test/w32dtst.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ src/text.cpp | 2 -- src/w32dlib/Doxyfile | 4 +-- src/w32dlib/autocheck.h | 8 +++-- src/w32dlib/base.h | 21 ++++++++++++- src/w32dlib/button.h | 8 +++-- src/w32dlib/common.h | 2 +- src/w32dlib/control.h | 29 ++++++++++------- src/w32dlib/dialog.h | 4 +-- src/w32dlib/static.h | 59 ++++++++++++++++++++++++++++++++++ src/w32dlib/text.h | 2 +- src/w32dlib/w32dlib.h | 3 +- 22 files changed, 308 insertions(+), 64 deletions(-) create mode 100644 src/test/.cvsignore create mode 100644 src/test/GNUmakefile create mode 100644 src/test/dialog.h create mode 100644 src/test/dialog.rc create mode 100644 src/test/w32dtst.cpp create mode 100644 src/w32dlib/static.h diff --git a/src/GNUmakefile b/src/GNUmakefile index a1cbcfb..9891e01 100644 --- a/src/GNUmakefile +++ b/src/GNUmakefile @@ -18,7 +18,7 @@ # # ------------------------------------------------------------------------- # -# $Id: GNUmakefile,v 1.1 2005-03-22 01:43:54 ianc Exp $ +# $Id: GNUmakefile,v 1.2 2005-03-24 00:07:40 ianc Exp $ # @@ -35,6 +35,10 @@ INSTALLDIR = C:/w32dlib # CREATECONF = 1 +# Uncomment this if you want a debug build +# +DEBUG = -g + # # **************************************** END OF CONFIGURATION @@ -49,20 +53,21 @@ SOURCES = autocheck.cpp \ common.cpp \ control.cpp \ dialog.cpp \ - text.cpp + text.cpp \ + static.cpp HEADERS = w32dlib/*.h OBJECTS = $(SOURCES:.cpp=.o) -FLAGS = -I. # -Wall +FLAGS = -I. -Wall $(DEBUG) DEPEND = depend.mak DOCDIR = ../doc -$(TARGET): depend $(OBJECTS) GNUMakefile +$(TARGET): $(OBJECTS) GNUMakefile ar rcusv $(TARGET) $(OBJECTS) doc: $(DOCDIR)/html/index.html diff --git a/src/autocheck.cpp b/src/autocheck.cpp index dfa1bf5..203fe0d 100644 --- a/src/autocheck.cpp +++ b/src/autocheck.cpp @@ -18,8 +18,6 @@ // // ------------------------------------------------------------------------- // -// $Log$ -// #include "w32dlib/autocheck.h" #include "w32dlib/dialog.h" @@ -44,9 +42,10 @@ AutoCheck::~AutoCheck() // ------------------------------------------------------------ // -void AutoCheck::OnPress(W32DLibCallback callback) +void AutoCheck::OnPress(W32DLibCallbackInterface *owner, + W32DLibCallback callback) { - m_parent->AddCallback(WM_COMMAND,callback); + Control::AddCallback(WM_COMMAND,owner,callback); } diff --git a/src/button.cpp b/src/button.cpp index 047d9d6..c14840a 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -18,9 +18,6 @@ // // ------------------------------------------------------------------------- // -// $Log$ -// - #include "w32dlib/button.h" #include "w32dlib/dialog.h" @@ -44,9 +41,10 @@ Button::~Button() // ------------------------------------------------------------ // -void Button::OnPress(W32DLibCallback callback) +void Button::OnPress(W32DLibCallbackInterface *owner, + W32DLibCallback callback) { - Dialog::AddCallback(WM_COMMAND,callback); + Control::AddCallback(WM_COMMAND,owner,callback); } diff --git a/src/common.cpp b/src/common.cpp index a096fe6..ced7779 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -18,8 +18,6 @@ // // ------------------------------------------------------------------------- // -// $Log$ -// #include "w32dlib/common.h" namespace W32DLib diff --git a/src/control.cpp b/src/control.cpp index abcf8fb..b824cca 100644 --- a/src/control.cpp +++ b/src/control.cpp @@ -18,8 +18,6 @@ // // ------------------------------------------------------------------------- // -// $Log$ -// #include "w32dlib/control.h" #include "w32dlib/dialog.h" @@ -83,12 +81,11 @@ BOOL Control::ProcessMessage(UINT msg, WPARAM wp, LPARAM lp) { if (m_cblist.count(msg)>0) { - W32DLibCallback cb=m_cblist[msg]; + CallbackDetails details=m_cblist[msg]; + W32DLibCallbackInterface *owner=details.owner; + W32DLibCallback cb=details.cb; - if (cb) - { - return cb(msg,wp,lp); - } + return (owner->*cb)(msg,wp,lp); } return false; @@ -97,19 +94,15 @@ BOOL Control::ProcessMessage(UINT msg, WPARAM wp, LPARAM lp) // ------------------------------------------------------------ // -void Control::AddCallback(UINT msg, W32DLibCallback callback) +void Control::AddCallback(UINT msg, + W32DLibCallbackInterface *owner, + W32DLibCallback callback) { - if (callback) - { - m_cblist[msg]=callback; - } - else - { - if (m_cblist.count(msg)) - { - m_cblist.remove(msg); - } - } + CallbackDetails details; + + details.owner=owner; + details.cb=callback; + m_cblist[msg]=details; } diff --git a/src/dialog.cpp b/src/dialog.cpp index 75b7e04..e84e22d 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -18,8 +18,6 @@ // // ------------------------------------------------------------------------- // -// $Log$ -// #include "w32dlib/dialog.h" #include "w32dlib/control.h" diff --git a/src/test/.cvsignore b/src/test/.cvsignore new file mode 100644 index 0000000..0ad1fae --- /dev/null +++ b/src/test/.cvsignore @@ -0,0 +1,2 @@ +depend.mak +w32dtst.exe \ No newline at end of file diff --git a/src/test/GNUmakefile b/src/test/GNUmakefile new file mode 100644 index 0000000..97ca9c0 --- /dev/null +++ b/src/test/GNUmakefile @@ -0,0 +1,61 @@ +# w32dlib - Win32 Dialog 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 +# +# ------------------------------------------------------------------------- +# +# $Id: GNUmakefile,v 1.1 2005-03-24 00:07:40 ianc Exp $ +# + + +TARGET = w32dtst.exe + +SOURCES = w32dtst.cpp + +LIB = ../w32dlib.a + +RES = dialog + +OBJECTS = $(SOURCES:.cpp=.o) $(RES).o + +FLAGS = -I.. -Wall -L.. -g + +DEPEND = depend.mak + +$(TARGET): $(OBJECTS) $(LIB) + $(CXX) -o $(TARGET) $(FLAGS) $(OBJECTS) -mwindows -mconsole $(LIB) + +$(RES).o: $(RES).rc $(RES).h + windres -i $(RES).rc -o $(RES).o + + +%.o: %.cpp + $(CXX) -c $(FLAGS) $< -o $@ + +-include depend.mak + +clean: + -rm -f $(TARGET) $(OBJECTS) depend.mak + +depend: $(DEPEND) + +$(DEPEND): $(SOURCES) $(HEADERS) GNUMakefile + @echo Dependencies updated.... + $(CXX) -MM $(FLAGS) $(SOURCES) > $(DEPEND) + + +# END OF FILE diff --git a/src/test/dialog.h b/src/test/dialog.h new file mode 100644 index 0000000..d1dee42 --- /dev/null +++ b/src/test/dialog.h @@ -0,0 +1,6 @@ +#define TESTDLG 1 +#define IDSTATIC1 2 +#define IDTEXT 3 +#define IDBUTTON 4 +#define IDQUIT 5 +#define IDCHECK 6 diff --git a/src/test/dialog.rc b/src/test/dialog.rc new file mode 100644 index 0000000..5655da6 --- /dev/null +++ b/src/test/dialog.rc @@ -0,0 +1,14 @@ +#include +#include "dialog.h" + +TESTDLG DIALOG 10, 10, 240, 100 + STYLE WS_POPUP | WS_BORDER CAPTION + "Test Dialog" + FONT 8,"MS Shell Dlg" +{ + LTEXT "Text:", IDSTATIC1, 10, 10, 50, 12 + EDITTEXT IDTEXT, 50, 10, 100, 12 + PUSHBUTTON "Try Me!", IDBUTTON, 10, 30, 150, 18 + AUTOCHECKBOX "Check", IDCHECK, 10,50,150,18 + PUSHBUTTON "Quit", IDQUIT, 10,70,150,18 +} diff --git a/src/test/w32dtst.cpp b/src/test/w32dtst.cpp new file mode 100644 index 0000000..ca796db --- /dev/null +++ b/src/test/w32dtst.cpp @@ -0,0 +1,84 @@ +// w32dlib - Win32 Control 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 +// +// ------------------------------------------------------------------------- +// +#include +#include +#include + +#include "dialog.h" + +class Test : public W32DLib::Dialog +{ +public: + Test() : //m_static(this,IDSTATIC1), + m_text(this,IDTEXT), + m_check(this,IDCHECK), + m_button(this,IDBUTTON), + m_quit(this,IDQUIT) + { + m_quit.OnPress + (this,static_cast(&Test::OnQuit)); + } + + virtual ~Test() + { + } + + int ResourceID() + { + return TESTDLG; + } + +private: + //W32DLib::StaticText m_static; + W32DLib::Text m_text; + W32DLib::AutoCheck m_check; + W32DLib::Button m_button; + W32DLib::Button m_quit; + + BOOL OnQuit(UINT msg, WPARAM wp, LPARAM lp) + { + std::cout << "Called OnQuit()" << std::endl; + Dialog::Close(IDOK); + return TRUE; + } +}; + +int WINAPI WinMain (HINSTANCE hInstance, + HINSTANCE hPrevInstance, + PSTR szCmdLine, + int iCmdShow) +{ + Test t; + INT_PTR i; + + i=t.ShowModal(hInstance,NULL); + + if (i==IDOK) + { + std::cout << "res=IDOK" << std::endl; + } + else + { + std::cout << "res=" << i << std::endl; + } + + return 0; +} diff --git a/src/text.cpp b/src/text.cpp index 8f8d1eb..d8f1f82 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -18,8 +18,6 @@ // // ------------------------------------------------------------------------- // -// $Log$ -// #include "w32dlib/text.h" namespace W32DLib diff --git a/src/w32dlib/Doxyfile b/src/w32dlib/Doxyfile index 55febc5..d74787d 100644 --- a/src/w32dlib/Doxyfile +++ b/src/w32dlib/Doxyfile @@ -41,10 +41,10 @@ SUBGROUPING = YES #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- -EXTRACT_ALL = NO +EXTRACT_ALL = YES EXTRACT_PRIVATE = NO EXTRACT_STATIC = NO -EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_CLASSES = NO EXTRACT_LOCAL_METHODS = NO HIDE_UNDOC_MEMBERS = YES HIDE_UNDOC_CLASSES = YES diff --git a/src/w32dlib/autocheck.h b/src/w32dlib/autocheck.h index 0246c03..e58d5f9 100644 --- a/src/w32dlib/autocheck.h +++ b/src/w32dlib/autocheck.h @@ -20,7 +20,7 @@ // #ifndef W32DLIB_AUTOCHECK_H -#define W32DLIB_AUTOCHECK_H "$Id$" +#define W32DLIB_AUTOCHECK_H "$Id$" #include "w32dlib/base.h" #include "w32dlib/control.h" @@ -58,9 +58,11 @@ namespace W32DLib /// \brief Sets a callback for a button press /// - /// \param callback The callback. Set to NULL to clear the callback. + /// \param owner The class the callback reside in. + /// \param callback The callback. /// - void OnPress(W32DLibCallback callback); + void OnPress(W32DLibCallbackInterface *owner, + W32DLibCallback callback); /// \brief Sets the tickstate. diff --git a/src/w32dlib/base.h b/src/w32dlib/base.h index 5dfcbfc..0d6f453 100644 --- a/src/w32dlib/base.h +++ b/src/w32dlib/base.h @@ -20,7 +20,7 @@ // #ifndef W32DLIB_BASE_H -#define W32DLIB_BASE_H "$Id$" +#define W32DLIB_BASE_H "$Id$" #include #include @@ -31,6 +31,25 @@ namespace W32DLib { 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); + + }; #endif // W32DLIB_BASE_H diff --git a/src/w32dlib/button.h b/src/w32dlib/button.h index 0ab0b8d..3ba48b3 100644 --- a/src/w32dlib/button.h +++ b/src/w32dlib/button.h @@ -20,7 +20,7 @@ // #ifndef W32DLIB_BUTTON_H -#define W32DLIB_BUTTON_H "$Id$" +#define W32DLIB_BUTTON_H "$Id$" #include "w32dlib/base.h" #include "w32dlib/control.h" @@ -47,9 +47,11 @@ namespace W32DLib /// \brief Sets a callback for a button press /// - /// \param callback The callback. Set to NULL to clear the callback. + /// \param owner The class the callback reside in. + /// \param callback The callback. /// - void OnPress(W32DLibCallback callback); + void OnPress(W32DLibCallbackInterface *owner, + W32DLibCallback callback); protected: diff --git a/src/w32dlib/common.h b/src/w32dlib/common.h index 004d81f..bb9547f 100644 --- a/src/w32dlib/common.h +++ b/src/w32dlib/common.h @@ -20,7 +20,7 @@ // #ifndef W32DLIB_COMMON_H -#define W32DLIB_COMMON_H "$Id$" +#define W32DLIB_COMMON_H "$Id$" #include "w32dlib/base.h" diff --git a/src/w32dlib/control.h b/src/w32dlib/control.h index bd1d39c..7aef528 100644 --- a/src/w32dlib/control.h +++ b/src/w32dlib/control.h @@ -20,22 +20,16 @@ // #ifndef W32DLIB_CONTROL_H -#define W32DLIB_CONTROL_H "$Id$" +#define W32DLIB_CONTROL_H "$Id$" #include "w32dlib/base.h" namespace W32DLib { - /// \brief Defines a callback. - /// - /// Return TRUE if the message was handled. - /// - typedef BOOL (*W32DLibCallback)(UINT msg, WPARAM wp, LPARAM lp); - /// \brief The base Control class. /// - class Control + class Control : public W32DLibCallbackInterface { public: @@ -80,12 +74,17 @@ namespace W32DLib protected: - /// \brief Add or remove a callback for the control. + /// \brief Add a callback for the control. /// /// \param msg The Windows event message to respond to. - /// \param callback The callback. Pass NULL to remove the callback. + /// \param owner The class (generally a Dialog derived one) in which + /// the callback resides. The class must be derived from + /// W32DLibCallbackInterface. + /// \param callback The callback. /// - void AddCallback(UINT msg, W32DLibCallback callback); + void AddCallback(UINT msg, + W32DLibCallbackInterface *owner, + W32DLibCallback callback); /// \brief Filled in by the constructor with the parent dialog. /// @@ -97,7 +96,13 @@ namespace W32DLib private: - typedef std::map CallbackList; + struct CallbackDetails + { + W32DLibCallbackInterface *owner; + W32DLibCallback cb; + }; + + typedef std::map CallbackList; CallbackList m_cblist; diff --git a/src/w32dlib/dialog.h b/src/w32dlib/dialog.h index fbe36e3..cac003e 100644 --- a/src/w32dlib/dialog.h +++ b/src/w32dlib/dialog.h @@ -20,7 +20,7 @@ // #ifndef W32DLIB_DIALOG_H -#define W32DLIB_DIALOG_H "$Id$" +#define W32DLIB_DIALOG_H "$Id$" #include "w32dlib/base.h" @@ -28,7 +28,7 @@ namespace W32DLib { /// \brief The base Dialog class. /// - class Dialog + class Dialog : public W32DLibCallbackInterface { public: diff --git a/src/w32dlib/static.h b/src/w32dlib/static.h new file mode 100644 index 0000000..3eca8af --- /dev/null +++ b/src/w32dlib/static.h @@ -0,0 +1,59 @@ +// w32dlib - Win32 Control 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_TEXT_H + +#define W32DLIB_TEXT_H "$Id$" + +#include "w32dlib/base.h" +#include "w32dlib/control.h" + +namespace W32DLib +{ + + /// \brief The StaticText class. + /// + class StaticText : public Control + { + public: + + /// \brief Constructor + /// + /// \param parent The dialog the control belongs to. + /// \param resource_id The ID of the control in the resource file. + /// + StaticText(Dialog *parent, int resource_id); + + /// \brief Destructor + /// + virtual ~StaticText(); + + protected: + + private: + + }; // class StaticText + +}; // namespace w32dlib + +#endif // W32DLIB_TEXT_H + + +// END OF FILE diff --git a/src/w32dlib/text.h b/src/w32dlib/text.h index fa00705..3614950 100644 --- a/src/w32dlib/text.h +++ b/src/w32dlib/text.h @@ -20,7 +20,7 @@ // #ifndef W32DLIB_TEXT_H -#define W32DLIB_TEXT_H "$Id$" +#define W32DLIB_TEXT_H "$Id$" #include "w32dlib/base.h" #include "w32dlib/control.h" diff --git a/src/w32dlib/w32dlib.h b/src/w32dlib/w32dlib.h index 6c6947f..a295226 100644 --- a/src/w32dlib/w32dlib.h +++ b/src/w32dlib/w32dlib.h @@ -20,12 +20,13 @@ // #ifndef W32DLIB_H -#define W32DLIB_H "$Id$" +#define W32DLIB_H "$Id$" #include "w32dlib/dialog.h" #include "w32dlib/control.h" #include "w32dlib/button.h" #include "w32dlib/text.h" +#include "w32dlib/static.h" #include "w32dlib/autocheck.h" #endif // W32DLIB_H -- cgit v1.2.3