summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/autocheck.cpp25
-rw-r--r--src/combobox.cpp16
-rw-r--r--src/common.cpp25
-rw-r--r--src/test/dialog.rc17
-rw-r--r--src/test/w32dtst.cpp39
-rw-r--r--src/text.cpp43
-rw-r--r--src/w32dlib/Doxyfile2
-rw-r--r--src/w32dlib/autocheck.h26
-rw-r--r--src/w32dlib/button.h2
-rw-r--r--src/w32dlib/combobox.h17
-rw-r--r--src/w32dlib/common.h25
-rw-r--r--src/w32dlib/text.h44
-rw-r--r--src/w32dlib/window.h17
-rw-r--r--src/window.cpp15
14 files changed, 277 insertions, 36 deletions
diff --git a/src/autocheck.cpp b/src/autocheck.cpp
index 57ec5bd..f713c19 100644
--- a/src/autocheck.cpp
+++ b/src/autocheck.cpp
@@ -51,7 +51,7 @@ void AutoCheck::OnPress(Window *owner, W32DLibCallback callback)
// ------------------------------------------------------------
//
-void AutoCheck::SetState(EState state)
+void AutoCheck::SetFullState(EState state)
{
CheckDlgButton(m_parent->GetHWND(),
m_resid,
@@ -61,11 +61,32 @@ void AutoCheck::SetState(EState state)
// ------------------------------------------------------------
//
-AutoCheck::EState AutoCheck::GetState()
+AutoCheck::EState AutoCheck::GetFullState()
{
return static_cast<EState>(IsDlgButtonChecked(m_parent->GetHWND(),m_resid));
}
+
+// ------------------------------------------------------------
+//
+void AutoCheck::SetState(bool state)
+{
+ CheckDlgButton(m_parent->GetHWND(),
+ m_resid,
+ state ? BST_CHECKED:BST_UNCHECKED);
+}
+
+
+// ------------------------------------------------------------
+//
+bool AutoCheck::GetState()
+{
+ UINT state=IsDlgButtonChecked(m_parent->GetHWND(),m_resid);
+
+ return (state==BST_CHECKED || state==BST_INDETERMINATE);
+}
+
+
}; // namespace W32DLib
diff --git a/src/combobox.cpp b/src/combobox.cpp
index 9f1108e..f16b619 100644
--- a/src/combobox.cpp
+++ b/src/combobox.cpp
@@ -97,6 +97,14 @@ int ComboBox::AddString(const char *text)
// ------------------------------------------------------------
//
+int ComboBox::AddString(const std::string& text)
+{
+ return AddString(text.c_str());
+}
+
+
+// ------------------------------------------------------------
+//
int ComboBox::AddString(const char *text, int index)
{
return SendMsg(CB_INSERTSTRING,index,reinterpret_cast<LPARAM>(text));
@@ -105,6 +113,14 @@ int ComboBox::AddString(const char *text, int index)
// ------------------------------------------------------------
//
+int ComboBox::AddString(const std::string& text, int index)
+{
+ return AddString(text.c_str(),index);
+}
+
+
+// ------------------------------------------------------------
+//
int ComboBox::RemoveString(int index)
{
return SendMsg(CB_DELETESTRING,index,0);
diff --git a/src/common.cpp b/src/common.cpp
index 2c9d01f..383a773 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -34,6 +34,14 @@ void Common::Message(HWND parent, const char *msg)
// ------------------------------------------------------------
//
+void Common::Message(HWND parent, const std::string& msg)
+{
+ ::MessageBox(parent,msg.c_str(),"Message",MB_ICONINFORMATION|MB_OK);
+}
+
+
+// ------------------------------------------------------------
+//
void Common::Error(HWND parent, const char *msg)
{
::MessageBox(parent,msg,"Error",MB_ICONSTOP|MB_OK);
@@ -42,6 +50,14 @@ void Common::Error(HWND parent, const char *msg)
// ------------------------------------------------------------
//
+void Common::Error(HWND parent, const std::string& msg)
+{
+ ::MessageBox(parent,msg.c_str(),"Error",MB_ICONSTOP|MB_OK);
+}
+
+
+// ------------------------------------------------------------
+//
bool Common::Query(HWND parent, const char *msg)
{
return ::MessageBox(parent,msg,"Question",MB_ICONQUESTION|MB_YESNO)==IDOK;
@@ -50,6 +66,15 @@ bool Common::Query(HWND parent, const char *msg)
// ------------------------------------------------------------
//
+bool Common::Query(HWND parent, const std::string& msg)
+{
+ return ::MessageBox(parent,msg.c_str(),"Question",
+ MB_ICONQUESTION|MB_YESNO)==IDOK;
+}
+
+
+// ------------------------------------------------------------
+//
bool Common::OpenFile(HWND parent,
const char *title,
std::string& path,
diff --git a/src/test/dialog.rc b/src/test/dialog.rc
index e96fa9f..d280453 100644
--- a/src/test/dialog.rc
+++ b/src/test/dialog.rc
@@ -1,22 +1,23 @@
#include <windows.h>
#include "dialog.h"
-TESTDLG DIALOG 10, 10, 240, 300
+TESTDLG DIALOG 10, 10, 500, 300
STYLE WS_POPUP | WS_BORDER
CAPTION "Test Dialog"
FONT 8,"MS Shell Dlg"
{
- LTEXT "Text:", IDSTATIC1, 10, 10, 35, 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
+ PUSHBUTTON "Try Me!", IDBUTTON, 10, 10, 150, 18
+ AUTOCHECKBOX "Check", IDCHECK, 10,30,150,18
+ PUSHBUTTON "Quit", IDQUIT, 10,50,150,18
- EDITTEXT IDLOADTXT, 10, 100, 200, 12
+ EDITTEXT IDLOADTXT, 10, 100, 200, 12, ES_READONLY
PUSHBUTTON "Load ...",IDLOADBUT, 10, 115, 100, 18
- EDITTEXT IDSAVETXT, 10, 140, 200, 12
+ EDITTEXT IDSAVETXT, 10, 140, 200, 12, ES_READONLY
PUSHBUTTON "Save ...",IDSAVEBUT, 10, 155, 100, 18
COMBOBOX IDCOMBO, 10, 180, 100, 100, CBS_SIMPLE | CBS_SORT | WS_VSCROLL | WS_TABSTOP
+
+ LTEXT "Text:", IDSTATIC1, 210, 10, 35, 12
+ EDITTEXT IDTEXT, 250, 10, 100, 100, ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_MULTILINE | ES_WANTRETURN
}
diff --git a/src/test/w32dtst.cpp b/src/test/w32dtst.cpp
index 663c63d..0e09ea2 100644
--- a/src/test/w32dtst.cpp
+++ b/src/test/w32dtst.cpp
@@ -45,6 +45,9 @@ public:
m_check.OnPress
(this,static_cast<W32DLib::W32DLibCallback>(&Test::OnCheck));
+ m_text.OnTextChanged
+ (this,static_cast<W32DLib::W32DLibCallback>(&Test::OnText));
+
m_loadbut.OnPress
(this,static_cast<W32DLib::W32DLibCallback>(&Test::OnLoad));
m_savebut.OnPress
@@ -75,7 +78,7 @@ public:
m_quit.Enable(true);
m_combo.Reset();
- std::cout << "addstring=" << m_combo.AddString("Entry 1") << std::endl;
+ std::cout << "addstring=" << m_combo.AddString(std::string("Entry 1")) << std::endl;
std::cout << "addstring=" << m_combo.AddString("Entry 2") << std::endl;
std::cout << "addstring=" << m_combo.AddString("Entry 3") << std::endl;
@@ -112,24 +115,27 @@ private:
BOOL OnButton(UINT msg, WPARAM wp, LPARAM lp)
{
- std::string txt=m_text.GetText(512);
+ std::string txt=m_text.GetText();
std::cout << "Called OnButton()" << std::endl;
std::cout << "text=" << txt << std::endl;
std::cout << "check=" << m_check.GetState() << std::endl;
- m_static.SetText(txt.c_str());
- SetText((txt+" [Title]").c_str());
- m_combo.AddString(m_combo.GetText().c_str());
+ m_static.SetText(txt);
+ SetText(txt+" [Title]");
+ m_combo.AddString(m_combo.GetText());
+ m_text.AppendText(m_combo.GetText()+"\n");
return TRUE;
}
BOOL OnCheck(UINT msg, WPARAM wp, LPARAM lp)
{
- W32DLib::AutoCheck::EState state=m_check.GetState();
+ bool checked=m_check.GetState();
- std::cout << "Called OnCheck() - state " << state << std::endl;
+ std::cout << "Called OnCheck() - state " << checked << std::endl;
- m_quit.Enable(state==W32DLib::AutoCheck::eChecked);
+ m_quit.Enable(checked);
+ m_load.ReadOnly(checked);
+ m_save.Enable(!checked);
return TRUE;
}
@@ -141,7 +147,7 @@ private:
m_loadpath,
"CPP Files\0*.cpp\0Any File\0*.*\0"))
{
- m_load.SetText(m_loadpath.c_str());
+ m_load.SetText(m_loadpath);
}
return TRUE;
@@ -154,7 +160,7 @@ private:
m_savepath,
NULL))
{
- m_save.SetText(m_savepath.c_str());
+ m_save.SetText(m_savepath);
}
return TRUE;
@@ -167,7 +173,7 @@ private:
std::cout << "Called OnComboSel()" << std::endl;
std::cout << "Sel:selection=" << sel << " (" << str << ")" << std::endl;
- std::cout << "Sel:Window::GetText=" << m_combo.GetText(512) << std::endl;
+ std::cout << "Sel:Window::GetText=" << m_combo.GetText() << std::endl;
return TRUE;
}
@@ -178,14 +184,21 @@ private:
std::cout << "Called OnComboDbl()" << std::endl;
std::cout << "Dbl:selection=" << sel << " (" << str << ")" << std::endl;
- std::cout << "Dbl:Window::GetText=" << m_combo.GetText(512) << std::endl;
+ std::cout << "Dbl:Window::GetText=" << m_combo.GetText() << std::endl;
return TRUE;
}
BOOL OnComboTxt(UINT msg, WPARAM wp, LPARAM lp)
{
std::cout << "Called OnComboSel()" << std::endl;
- std::cout << "Txt:Window::GetText=" << m_combo.GetText(512) << std::endl;
+ std::cout << "Txt:Window::GetText=" << m_combo.GetText() << std::endl;
+ return TRUE;
+ }
+
+ BOOL OnText(UINT msg, WPARAM wp, LPARAM lp)
+ {
+ std::cout << "Called OnText()" << std::endl;
+ std::cout << ":GetText=" << m_text.GetText() << std::endl;
return TRUE;
}
};
diff --git a/src/text.cpp b/src/text.cpp
index ff4241d..4e77387 100644
--- a/src/text.cpp
+++ b/src/text.cpp
@@ -39,6 +39,49 @@ Text::~Text()
}
+// ------------------------------------------------------------
+//
+void Text::OnTextChanged(Window *owner, W32DLibCallback callback)
+{
+ Control::AddCallback(WM_COMMAND,EN_CHANGE,owner,callback);
+}
+
+
+// ------------------------------------------------------------
+//
+void Text::MaxLen(int count)
+{
+ SendMsg(EM_LIMITTEXT,count,0);
+}
+
+
+// ------------------------------------------------------------
+//
+void Text::ReadOnly(bool readonly)
+{
+ SendMsg(EM_SETREADONLY,readonly ? TRUE:FALSE,0);
+}
+
+
+// ------------------------------------------------------------
+//
+void Text::AppendText(const char *text)
+{
+ int len=GetWindowTextLength(GetHWND());
+ SendMsg(EM_SETSEL,len,len);
+ SendMsg(EM_REPLACESEL,FALSE,reinterpret_cast<LPARAM>(text));
+}
+
+
+// ------------------------------------------------------------
+//
+void Text::AppendText(const std::string& text)
+{
+ AppendText(text.c_str());
+}
+
+
+
}; // namespace W32DLib
// END OF FILE
diff --git a/src/w32dlib/Doxyfile b/src/w32dlib/Doxyfile
index 9c2aa6d..d74787d 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 = YES
+INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = NO
STRIP_FROM_PATH = ..
STRIP_FROM_INC_PATH = ..
diff --git a/src/w32dlib/autocheck.h b/src/w32dlib/autocheck.h
index a40c703..f1b110e 100644
--- a/src/w32dlib/autocheck.h
+++ b/src/w32dlib/autocheck.h
@@ -58,7 +58,7 @@ namespace W32DLib
/// \brief Sets a callback for a button press
///
- /// \param owner The class the callback reside in.
+ /// \param owner The class the callback resides in.
/// \param callback The callback.
///
void OnPress(Window *owner,
@@ -67,10 +67,30 @@ namespace W32DLib
/// \brief Sets the tickstate.
///
+ /// This member allows the indeterminate checks to be set.
+ ///
+ /// \param state The tick state
+ /// \sa GetState()
+ ///
+ void SetFullState(EState state);
+
+
+ /// \brief Gets the tickstate.
+ ///
+ /// This member allows the indeterminate state to be tested.
+ ///
+ ///
+ /// \return The tick state
+ /// \sa SetState()
+ ///
+ EState GetFullState();
+
+ /// \brief Sets the tickstate.
+ ///
/// \param state The tick state
/// \sa GetState()
///
- void SetState(EState state);
+ void SetState(bool state);
/// \brief Gets the tickstate.
@@ -78,7 +98,7 @@ namespace W32DLib
/// \return The tick state
/// \sa SetState()
///
- EState GetState();
+ bool GetState();
protected:
diff --git a/src/w32dlib/button.h b/src/w32dlib/button.h
index c35a06c..4ec6449 100644
--- a/src/w32dlib/button.h
+++ b/src/w32dlib/button.h
@@ -47,7 +47,7 @@ namespace W32DLib
/// \brief Sets a callback for a button press
///
- /// \param owner The class the callback reside in.
+ /// \param owner The class the callback resides in.
/// \param callback The callback.
///
void OnPress(Window *owner,
diff --git a/src/w32dlib/combobox.h b/src/w32dlib/combobox.h
index dae30a0..9dfa50a 100644
--- a/src/w32dlib/combobox.h
+++ b/src/w32dlib/combobox.h
@@ -47,7 +47,7 @@ namespace W32DLib
/// \brief Sets a callback for when selection changes.
///
- /// \param owner The class the callback reside in.
+ /// \param owner The class the callback resides in.
/// \param callback The callback.
///
void OnSelection(Window *owner,
@@ -99,11 +99,26 @@ namespace W32DLib
/// \brief Adds a string to the combo box.
///
/// \param text The string to add.
+ /// \return The index of the added string, or CB_ERR or CB_ERRSPACE.
+ ///
+ int AddString(const std::string& text);
+
+ /// \brief Adds a string to the combo box.
+ ///
+ /// \param text The string to add.
/// \param index The index to insert in front of
/// \return The index of the added string, or CB_ERR or CB_ERRSPACE.
///
int AddString(const char *text,int index);
+ /// \brief Adds a string to the combo box.
+ ///
+ /// \param text The string to add.
+ /// \param index The index to insert in front of
+ /// \return The index of the added string, or CB_ERR or CB_ERRSPACE.
+ ///
+ int AddString(const std::string& text,int index);
+
/// \brief Removes a string from the combo box.
///
/// \param index The index of the string to remove.
diff --git a/src/w32dlib/common.h b/src/w32dlib/common.h
index 357297f..ce22e58 100644
--- a/src/w32dlib/common.h
+++ b/src/w32dlib/common.h
@@ -43,6 +43,14 @@ namespace W32DLib
static void Message(HWND parent, const char *msg);
+ /// \brief Displays a message box.
+ ///
+ /// \param parent Parent window (NULL for none)
+ /// \param msg The message to display.
+ ///
+ static void Message(HWND parent, const std::string& msg);
+
+
/// \brief Displays an error message box.
///
/// \param parent Parent window (NULL for none)
@@ -51,6 +59,14 @@ namespace W32DLib
static void Error(HWND parent, const char *msg);
+ /// \brief Displays an error message box.
+ ///
+ /// \param parent Parent window (NULL for none)
+ /// \param msg The error message to display.
+ ///
+ static void Error(HWND parent, const std::string& msg);
+
+
/// \brief Displays a Yes/No message box.
///
/// \param parent Parent window (NULL for none)
@@ -60,6 +76,15 @@ namespace W32DLib
static bool Query(HWND parent, const char *msg);
+ /// \brief Displays a Yes/No message box.
+ ///
+ /// \param parent Parent window (NULL for none)
+ /// \param msg The message to display.
+ /// \return True if the user selects Yes.
+ ///
+ static bool Query(HWND parent, const std::string& msg);
+
+
/// \brief Requests a file to open.
///
/// \param parent The parent window.
diff --git a/src/w32dlib/text.h b/src/w32dlib/text.h
index 3614950..8b68c22 100644
--- a/src/w32dlib/text.h
+++ b/src/w32dlib/text.h
@@ -45,6 +45,50 @@ namespace W32DLib
///
virtual ~Text();
+ /// \brief Sets a callback for when the text is altered.
+ ///
+ /// \param owner The class the callback resides in.
+ /// \param callback The callback.
+ ///
+ void OnTextChanged(Window *owner,
+ W32DLibCallback callback);
+
+ /// \brief Sets the maximum length the user can enter.
+ ///
+ /// \param count The maximum number of characters the user can enter.
+ ///
+ void MaxLen(int count);
+
+
+ /// \brief Sets whether the user can enter text.
+ ///
+ /// \param readonly true for readonly, false for editable.
+ ///
+ void ReadOnly(bool readonly);
+
+
+ /// \brief Appends text.
+ ///
+ /// Note this is mainly for providing logging controls and the suchlike.
+ /// Any current selection and caret position will almost certainly
+ /// be messed up.
+ ///
+ /// \param text The text to add.
+ ///
+ void AppendText(const char *text);
+
+
+ /// \brief Appends text.
+ ///
+ /// Note this is mainly for providing logging controls and the suchlike.
+ /// Any current selection and caret position will almost certainly
+ /// be messed up.
+ ///
+ /// \param text The text to add.
+ ///
+ void AppendText(const std::string& text);
+
+
protected:
private:
diff --git a/src/w32dlib/window.h b/src/w32dlib/window.h
index 94c6179..4dee89b 100644
--- a/src/w32dlib/window.h
+++ b/src/w32dlib/window.h
@@ -67,18 +67,27 @@ namespace W32DLib
/// \param text The text
/// \sa GetText()
///
- virtual void SetText(const char *text);
+ void SetText(const char *text);
+
+ /// \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()
+ ///
+ void SetText(const std::string& 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=512);
+ std::string GetText();
/// \brief Enables or disables the window.
///
@@ -87,7 +96,7 @@ namespace W32DLib
///
/// \param enable Set true to enable, false to disable.
///
- virtual void Enable(bool enable);
+ void Enable(bool enable);
protected:
diff --git a/src/window.cpp b/src/window.cpp
index 492ecfd..af662b9 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -68,14 +68,23 @@ void Window::SetText(const char *text)
// ------------------------------------------------------------
//
-std::string Window::GetText(int maxlen)
+void Window::SetText(const std::string& text)
{
- char *buff=new char[maxlen+1];
+ SetText(text.c_str());
+}
+
+
+// ------------------------------------------------------------
+//
+std::string Window::GetText()
+{
+ int len=GetWindowTextLength(m_wnd);
+ char *buff=new char[len+1];
std::string res;
buff[0]=0;
- SendMsg(WM_GETTEXT,maxlen,reinterpret_cast<LPARAM>(buff));
+ SendMsg(WM_GETTEXT,len+1,reinterpret_cast<LPARAM>(buff));
res=buff;
delete[] buff;