1 /////////////////////////////////////////////////////////////////////////////
2 // Name: palmos/textctrl.cpp
4 // Author: William Osborne
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 #pragma implementation "textctrl.h"
20 // ----------------------------------------------------------------------------
22 // ----------------------------------------------------------------------------
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
34 #include "wx/textctrl.h"
35 #include "wx/settings.h"
44 #include "wx/module.h"
47 #include "wx/clipbrd.h"
50 #include "wx/textfile.h"
52 #include "wx/palmos/private.h"
53 #include "wx/palmos/winundef.h"
59 #include "wx/palmos/missing.h"
61 #endif // wxUSE_RICHEDIT
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
69 // this module initializes RichEdit DLL(s) if needed
70 class wxRichEditModule
: public wxModule
73 virtual bool OnInit();
74 virtual void OnExit();
76 // load the richedit DLL of at least of required version
77 static bool Load(int version
= 1);
80 // the handles to richedit 1.0 and 2.0 (or 3.0) DLLs
81 static HINSTANCE ms_hRichEdit
[2];
83 DECLARE_DYNAMIC_CLASS(wxRichEditModule
)
86 HINSTANCE
wxRichEditModule::ms_hRichEdit
[2] = { NULL
, NULL
};
88 IMPLEMENT_DYNAMIC_CLASS(wxRichEditModule
, wxModule
)
90 #endif // wxUSE_RICHEDIT
92 // ----------------------------------------------------------------------------
93 // event tables and other macros
94 // ----------------------------------------------------------------------------
96 #if wxUSE_EXTENDED_RTTI
97 WX_DEFINE_FLAGS( wxTextCtrlStyle
)
99 wxBEGIN_FLAGS( wxTextCtrlStyle
)
100 // new style border flags, we put them first to
101 // use them for streaming out
102 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
103 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
104 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
105 wxFLAGS_MEMBER(wxBORDER_RAISED
)
106 wxFLAGS_MEMBER(wxBORDER_STATIC
)
107 wxFLAGS_MEMBER(wxBORDER_NONE
)
109 // old style border flags
110 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
111 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
112 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
113 wxFLAGS_MEMBER(wxRAISED_BORDER
)
114 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
115 wxFLAGS_MEMBER(wxBORDER
)
117 // standard window styles
118 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
119 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
120 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
121 wxFLAGS_MEMBER(wxWANTS_CHARS
)
122 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
123 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
124 wxFLAGS_MEMBER(wxVSCROLL
)
125 wxFLAGS_MEMBER(wxHSCROLL
)
127 wxFLAGS_MEMBER(wxTE_PROCESS_ENTER
)
128 wxFLAGS_MEMBER(wxTE_PROCESS_TAB
)
129 wxFLAGS_MEMBER(wxTE_MULTILINE
)
130 wxFLAGS_MEMBER(wxTE_PASSWORD
)
131 wxFLAGS_MEMBER(wxTE_READONLY
)
132 wxFLAGS_MEMBER(wxHSCROLL
)
133 wxFLAGS_MEMBER(wxTE_RICH
)
134 wxFLAGS_MEMBER(wxTE_RICH2
)
135 wxFLAGS_MEMBER(wxTE_AUTO_URL
)
136 wxFLAGS_MEMBER(wxTE_NOHIDESEL
)
137 wxFLAGS_MEMBER(wxTE_LEFT
)
138 wxFLAGS_MEMBER(wxTE_CENTRE
)
139 wxFLAGS_MEMBER(wxTE_RIGHT
)
140 wxFLAGS_MEMBER(wxTE_DONTWRAP
)
141 wxFLAGS_MEMBER(wxTE_LINEWRAP
)
142 wxFLAGS_MEMBER(wxTE_WORDWRAP
)
144 wxEND_FLAGS( wxTextCtrlStyle
)
146 IMPLEMENT_DYNAMIC_CLASS_XTI(wxTextCtrl
, wxControl
,"wx/textctrl.h")
148 wxBEGIN_PROPERTIES_TABLE(wxTextCtrl
)
149 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
150 wxEVENT_PROPERTY( TextEnter
, wxEVT_COMMAND_TEXT_ENTER
, wxCommandEvent
)
152 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
153 wxPROPERTY( Value
, wxString
, SetValue
, GetValue
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
154 wxPROPERTY_FLAGS( WindowStyle
, wxTextCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
155 wxEND_PROPERTIES_TABLE()
157 wxBEGIN_HANDLERS_TABLE(wxTextCtrl
)
158 wxEND_HANDLERS_TABLE()
160 wxCONSTRUCTOR_6( wxTextCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Value
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
162 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
166 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
167 EVT_CHAR(wxTextCtrl::OnChar
)
168 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
171 EVT_RIGHT_UP(wxTextCtrl::OnRightClick
)
174 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
175 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
176 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
177 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
178 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
179 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
180 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
182 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
183 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
184 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
185 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
186 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
187 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
188 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
190 EVT_SET_FOCUS(wxTextCtrl::OnSetFocus
)
193 // ============================================================================
195 // ============================================================================
197 // ----------------------------------------------------------------------------
199 // ----------------------------------------------------------------------------
201 void wxTextCtrl::Init()
205 wxTextCtrl::~wxTextCtrl()
209 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
210 const wxString
& value
,
214 const wxValidator
& validator
,
215 const wxString
& name
)
220 // Make sure the window style (etc.) reflects the HWND style (roughly)
221 void wxTextCtrl::AdoptAttributesFromHWND()
225 WXDWORD
wxTextCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
230 void wxTextCtrl::SetWindowStyleFlag(long style
)
234 // ----------------------------------------------------------------------------
235 // set/get the controls text
236 // ----------------------------------------------------------------------------
238 wxString
wxTextCtrl::GetValue() const
245 wxString
wxTextCtrl::GetRange(long from
, long to
) const
252 void wxTextCtrl::SetValue(const wxString
& value
)
256 #if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU)
258 // TODO: using memcpy() would improve performance a lot for big amounts of text
261 wxRichEditStreamIn(DWORD dwCookie
, BYTE
*buf
, LONG cb
, LONG
*pcb
)
266 // helper struct used to pass parameters from wxTextCtrl to wxRichEditStreamOut
267 struct wxStreamOutData
274 wxRichEditStreamOut(DWORD_PTR dwCookie
, BYTE
*buf
, LONG cb
, LONG
*pcb
)
280 #if wxUSE_UNICODE_MSLU
281 #define UNUSED_IF_MSLU(param)
283 #define UNUSED_IF_MSLU(param) param
287 wxTextCtrl::StreamIn(const wxString
& value
,
288 wxFontEncoding
UNUSED_IF_MSLU(encoding
),
294 #if !wxUSE_UNICODE_MSLU
297 wxTextCtrl::StreamOut(wxFontEncoding encoding
, bool selectionOnly
) const
304 #endif // !wxUSE_UNICODE_MSLU
306 #endif // wxUSE_RICHEDIT
308 void wxTextCtrl::WriteText(const wxString
& value
)
312 void wxTextCtrl::DoWriteText(const wxString
& value
, bool selectionOnly
)
316 void wxTextCtrl::AppendText(const wxString
& text
)
320 void wxTextCtrl::Clear()
326 bool wxTextCtrl::EmulateKeyPress(const wxKeyEvent
& event
)
333 // ----------------------------------------------------------------------------
334 // Clipboard operations
335 // ----------------------------------------------------------------------------
337 void wxTextCtrl::Copy()
341 void wxTextCtrl::Cut()
345 void wxTextCtrl::Paste()
349 bool wxTextCtrl::HasSelection() const
354 bool wxTextCtrl::CanCopy() const
359 bool wxTextCtrl::CanCut() const
364 bool wxTextCtrl::CanPaste() const
369 // ----------------------------------------------------------------------------
371 // ----------------------------------------------------------------------------
373 void wxTextCtrl::SetEditable(bool editable
)
377 void wxTextCtrl::SetInsertionPoint(long pos
)
381 void wxTextCtrl::SetInsertionPointEnd()
385 long wxTextCtrl::GetInsertionPoint() const
390 long wxTextCtrl::GetLastPosition() const
395 // If the return values from and to are the same, there is no
397 void wxTextCtrl::GetSelection(long* from
, long* to
) const
401 bool wxTextCtrl::IsEditable() const
406 // ----------------------------------------------------------------------------
408 // ----------------------------------------------------------------------------
410 void wxTextCtrl::SetSelection(long from
, long to
)
414 void wxTextCtrl::DoSetSelection(long from
, long to
, bool scrollCaret
)
418 // ----------------------------------------------------------------------------
419 // Working with files
420 // ----------------------------------------------------------------------------
422 bool wxTextCtrl::LoadFile(const wxString
& file
)
427 // ----------------------------------------------------------------------------
429 // ----------------------------------------------------------------------------
431 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
435 void wxTextCtrl::Remove(long from
, long to
)
439 bool wxTextCtrl::IsModified() const
444 void wxTextCtrl::MarkDirty()
448 void wxTextCtrl::DiscardEdits()
452 int wxTextCtrl::GetNumberOfLines() const
457 // ----------------------------------------------------------------------------
458 // Positions <-> coords
459 // ----------------------------------------------------------------------------
461 long wxTextCtrl::XYToPosition(long x
, long y
) const
466 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
471 wxTextCtrlHitTestResult
472 wxTextCtrl::HitTest(const wxPoint
& pt
, wxTextCoord
*col
, wxTextCoord
*row
) const
474 return wxTE_HT_UNKNOWN
;
477 // ----------------------------------------------------------------------------
479 // ----------------------------------------------------------------------------
481 void wxTextCtrl::ShowPosition(long pos
)
485 long wxTextCtrl::GetLengthOfLineContainingPos(long pos
) const
490 int wxTextCtrl::GetLineLength(long lineNo
) const
495 wxString
wxTextCtrl::GetLineText(long lineNo
) const
502 void wxTextCtrl::SetMaxLength(unsigned long len
)
506 // ----------------------------------------------------------------------------
508 // ----------------------------------------------------------------------------
510 void wxTextCtrl::Undo()
514 void wxTextCtrl::Redo()
518 bool wxTextCtrl::CanUndo() const
522 bool wxTextCtrl::CanRedo() const
526 // ----------------------------------------------------------------------------
527 // caret handling (Windows only)
528 // ----------------------------------------------------------------------------
530 bool wxTextCtrl::ShowNativeCaret(bool show
)
535 // ----------------------------------------------------------------------------
536 // implemenation details
537 // ----------------------------------------------------------------------------
539 void wxTextCtrl::Command(wxCommandEvent
& event
)
543 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
547 // ----------------------------------------------------------------------------
548 // kbd input processing
549 // ----------------------------------------------------------------------------
551 bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG
* pMsg
)
556 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
560 WXLRESULT
wxTextCtrl::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
565 // ----------------------------------------------------------------------------
566 // text control event processing
567 // ----------------------------------------------------------------------------
569 bool wxTextCtrl::SendUpdateEvent()
574 bool wxTextCtrl::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
579 WXHBRUSH
wxTextCtrl::OnCtlColor(WXHDC pDC
, WXHWND
WXUNUSED(pWnd
), WXUINT
WXUNUSED(nCtlColor
),
585 WXUINT
WXUNUSED(message
),
586 WXWPARAM
WXUNUSED(wParam
),
587 WXLPARAM
WXUNUSED(lParam
)
594 bool wxTextCtrl::AdjustSpaceLimit()
599 bool wxTextCtrl::AcceptsFocus() const
604 wxSize
wxTextCtrl::DoGetBestSize() const
609 // ----------------------------------------------------------------------------
610 // standard handlers for standard edit menu events
611 // ----------------------------------------------------------------------------
613 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
617 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
621 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
625 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
629 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
633 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
637 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
641 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
645 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
649 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
653 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
657 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
661 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
665 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
669 void wxTextCtrl::OnRightClick(wxMouseEvent
& event
)
673 void wxTextCtrl::OnSetFocus(wxFocusEvent
& WXUNUSED(event
))
677 // the rest of the file only deals with the rich edit controls
680 // ----------------------------------------------------------------------------
681 // EN_LINK processing
682 // ----------------------------------------------------------------------------
684 bool wxTextCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
689 // ----------------------------------------------------------------------------
690 // colour setting for the rich edit controls
691 // ----------------------------------------------------------------------------
693 bool wxTextCtrl::SetBackgroundColour(const wxColour
& colour
)
698 bool wxTextCtrl::SetForegroundColour(const wxColour
& colour
)
703 // ----------------------------------------------------------------------------
704 // styling support for rich edit controls
705 // ----------------------------------------------------------------------------
709 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
714 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
719 bool wxTextCtrl::GetStyle(long position
, wxTextAttr
& style
)
726 // ----------------------------------------------------------------------------
728 // ----------------------------------------------------------------------------
730 bool wxRichEditModule::OnInit()
735 void wxRichEditModule::OnExit()
740 bool wxRichEditModule::Load(int version
)
745 #endif // wxUSE_RICHEDIT
747 #endif // wxUSE_TEXTCTRL