From 9a3a5e5eeac0176bb93fa53fb2934a21b6d7c45f Mon Sep 17 00:00:00 2001 From: Stefan Neis Date: Sun, 18 Nov 2007 21:48:11 +0000 Subject: [PATCH] Added wxTextEntry implementation for OS/2. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50064 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- build/bakefiles/files.bkl | 2 + include/wx/os2/textentry.h | 67 ++++++++++++ src/os2/textentry.cpp | 206 +++++++++++++++++++++++++++++++++++++ 3 files changed, 275 insertions(+) create mode 100644 include/wx/os2/textentry.h create mode 100644 src/os2/textentry.cpp diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index 6b5dfec0d2..17372fddde 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -2040,6 +2040,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! src/os2/stattext.cpp src/os2/tabctrl.cpp src/os2/textctrl.cpp + src/os2/textentry.cpp src/os2/tglbtn.cpp src/os2/timer.cpp src/os2/toolbar.cpp @@ -2118,6 +2119,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! wx/os2/stattext.h wx/os2/tabctrl.h wx/os2/textctrl.h + wx/os2/textentry.h wx/os2/tglbtn.h wx/os2/toolbar.h wx/os2/tooltip.h diff --git a/include/wx/os2/textentry.h b/include/wx/os2/textentry.h new file mode 100644 index 0000000000..33bb2320ce --- /dev/null +++ b/include/wx/os2/textentry.h @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/os2/textentry.h +// Purpose: wxOS2-specific wxTextEntry implementation +// Author: Stefan Neis +// Created: 2007-11-18 +// RCS-ID: $Id$ +// Copyright: (c) 2007 Stefan Neis +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_OS2_TEXTENTRY_H_ +#define _WX_OS2_TEXTENTRY_H_ + +// ---------------------------------------------------------------------------- +// wxTextEntry: common part of wxComboBox and (single line) wxTextCtrl +// ---------------------------------------------------------------------------- + +class WXDLLIMPEXP_CORE wxTextEntry : public wxTextEntryBase +{ +public: + wxTextEntry() { } + + // implement wxTextEntryBase pure virtual methods + virtual void WriteText(const wxString& text); + virtual wxString GetValue() const; + virtual void Remove(long from, long to); + + virtual void Copy(); + virtual void Cut(); + virtual void Paste(); + + virtual void Undo(); + virtual void Redo(); + virtual bool CanUndo() const; + virtual bool CanRedo() const; + + virtual void SetInsertionPoint(long pos); + virtual long GetInsertionPoint() const; + virtual long GetLastPosition() const; + + virtual void SetSelection(long from, long to) + { DoSetSelection(from, to); } + virtual void GetSelection(long *from, long *to) const; + + virtual bool IsEditable() const; + virtual void SetEditable(bool editable); + + virtual void SetMaxLength(unsigned long len); + +protected: + // this is really a hook for multiline text controls as the single line + // ones don't need to ever scroll to show the selection but having it here + // allows us to put Remove() in the base class + enum + { + SetSel_NoScroll = 0, // don't do anything special + SetSel_Scroll = 1 // default: scroll to make the selection visible + }; + virtual void DoSetSelection(long from, long to, int flags = SetSel_Scroll); + +private: + // implement this to return the HWND of the EDIT control + virtual WXHWND GetEditHWND() const = 0; +}; + +#endif // _WX_OS2_TEXTENTRY_H_ + diff --git a/src/os2/textentry.cpp b/src/os2/textentry.cpp new file mode 100644 index 0000000000..817390980d --- /dev/null +++ b/src/os2/textentry.cpp @@ -0,0 +1,206 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: src/os2/textentry.cpp +// Purpose: wxTextEntry implementation for wxOS2 +// Author: Stefan Neis +// Created: 2007-11-18 +// RCS-ID: $Id$ +// Copyright: (c) 2007 Stefan Neis +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// for compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/arrstr.h" + #include "wx/string.h" +#endif // WX_PRECOMP + +#if wxUSE_TEXTCTRL || wxUSE_COMBOBOX + +#include "wx/textentry.h" +#include "wx/dynlib.h" + +#include "wx/os2/private.h" + +#define GetEditHwnd() ((HWND)(GetEditHWND())) + +// ============================================================================ +// wxTextEntry implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// operations on text +// ---------------------------------------------------------------------------- + +void wxTextEntry::WriteText(const wxString& text) +{ + wxString newText = wxGetWindowText(GetEditHWND()); + long from, to; + GetSelection(&from, &to); + if (from > to){ + long swp = to; + to = from; + from = swp; + } + // Compose the new Text by replacing the selection of the old text + newText.replace(from, to - from, text); + // Set control to the new text + ::WinSetWindowText(GetEditHwnd(), text.c_str()); +} + +wxString wxTextEntry::GetValue() const +{ + return wxGetWindowText(GetEditHWND()); +} + +void wxTextEntry::Remove(long from, long to) +{ + DoSetSelection(from, to, SetSel_NoScroll); + WriteText(wxString()); +} + +// ---------------------------------------------------------------------------- +// clipboard operations +// ---------------------------------------------------------------------------- + +void wxTextEntry::Copy() +{ + ::WinSendMsg(GetEditHwnd(), EM_COPY, 0, 0); +} + +void wxTextEntry::Cut() +{ + ::WinSendMsg(GetEditHwnd(), EM_CUT, 0, 0); +} + +void wxTextEntry::Paste() +{ + ::WinSendMsg(GetEditHwnd(), EM_PASTE, 0, 0); +} + +// ---------------------------------------------------------------------------- +// undo/redo +// ---------------------------------------------------------------------------- + +void wxTextEntry::Undo() +{ +} + +void wxTextEntry::Redo() +{ + // same as Undo, since Undo undoes the undo + Undo(); + return; +} + +bool wxTextEntry::CanUndo() const +{ + return false; +} + +bool wxTextEntry::CanRedo() const +{ + // see comment in Redo() + return CanUndo(); +} + +// ---------------------------------------------------------------------------- +// insertion point and selection +// ---------------------------------------------------------------------------- + +void wxTextEntry::SetInsertionPoint(long pos) +{ + // be careful to call DoSetSelection() which is overridden in wxTextCtrl + // and not just SetSelection() here + DoSetSelection(pos, pos); +} + +long wxTextEntry::GetInsertionPoint() const +{ + long from; + GetSelection(&from, NULL); + return from; +} + +long wxTextEntry::GetLastPosition() const +{ + WNDPARAMS vParams; + + vParams.fsStatus = WPM_CCHTEXT; + if (::WinSendMsg( GetEditHwnd() + ,WM_QUERYWINDOWPARAMS + ,&vParams + ,0 + )) + { + return vParams.cchText; + } + return 0; +} + +void wxTextEntry::DoSetSelection(long from, long to, int WXUNUSED(flags)) +{ + // if from and to are both -1, it means (in wxWidgets) that all text should + // be selected, translate this into Windows convention + if ( (from == -1) && (to == -1) ) + { + from = 0; + } + + ::WinSendMsg(GetEditHwnd(), EM_SETSEL, MPFROM2SHORT((USHORT)from, (USHORT)to), 0); +} + +void wxTextEntry::GetSelection(long *from, long *to) const +{ + long dwPos; + dwPos = (long)::WinSendMsg(GetEditHwnd(), EM_QUERYSEL, 0, 0); + + if ( from ) + *from = SHORT1FROMMP((MPARAM)dwPos); + if ( to ) + *to = SHORT2FROMMP((MPARAM)dwPos); +} + +// ---------------------------------------------------------------------------- +// editable state +// ---------------------------------------------------------------------------- + +bool wxTextEntry::IsEditable() const +{ + return (bool)LONGFROMMR(::WinSendMsg(GetEditHwnd(), EM_QUERYREADONLY, 0, 0)); +} + +void wxTextEntry::SetEditable(bool editable) +{ + ::WinSendMsg(GetEditHwnd(), EM_SETREADONLY, MPFROMLONG(!editable), 0); +} + +// ---------------------------------------------------------------------------- +// max length +// ---------------------------------------------------------------------------- + +void wxTextEntry::SetMaxLength(unsigned long len) +{ + if ( len >= 0x7fff ) + { + // this will set it to a platform-specific maximum (32Kb under OS/2) + len = 0x7fff; + } + + ::WinSendMsg(GetEditHwnd(), EM_SETTEXTLIMIT, MPFROMSHORT(len), 0); +} + +#endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX -- 2.45.2