1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/textctrl.cpp
4 // Author: William Osborne - minimal working wxPalmOS port
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/textctrl.h"
32 #include "wx/settings.h"
41 #include "wx/module.h"
44 #include "wx/clipbrd.h"
47 #include "wx/textfile.h"
49 #include "wx/palmos/private.h"
50 #include "wx/palmos/winundef.h"
56 #include "wx/palmos/missing.h"
58 #endif // wxUSE_RICHEDIT
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
66 // this module initializes RichEdit DLL(s) if needed
67 class wxRichEditModule
: public wxModule
70 virtual bool OnInit();
71 virtual void OnExit();
73 // load the richedit DLL of at least of required version
74 static bool Load(int version
= 1);
77 // the handles to richedit 1.0 and 2.0 (or 3.0) DLLs
78 static HINSTANCE ms_hRichEdit
[2];
80 DECLARE_DYNAMIC_CLASS(wxRichEditModule
)
83 HINSTANCE
wxRichEditModule::ms_hRichEdit
[2] = { NULL
, NULL
};
85 IMPLEMENT_DYNAMIC_CLASS(wxRichEditModule
, wxModule
)
87 #endif // wxUSE_RICHEDIT
89 // ----------------------------------------------------------------------------
90 // event tables and other macros
91 // ----------------------------------------------------------------------------
93 #if wxUSE_EXTENDED_RTTI
94 WX_DEFINE_FLAGS( wxTextCtrlStyle
)
96 wxBEGIN_FLAGS( wxTextCtrlStyle
)
97 // new style border flags, we put them first to
98 // use them for streaming out
99 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
100 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
101 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
102 wxFLAGS_MEMBER(wxBORDER_RAISED
)
103 wxFLAGS_MEMBER(wxBORDER_STATIC
)
104 wxFLAGS_MEMBER(wxBORDER_NONE
)
106 // old style border flags
107 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
108 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
109 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
110 wxFLAGS_MEMBER(wxRAISED_BORDER
)
111 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
112 wxFLAGS_MEMBER(wxBORDER
)
114 // standard window styles
115 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
116 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
117 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
118 wxFLAGS_MEMBER(wxWANTS_CHARS
)
119 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
120 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
121 wxFLAGS_MEMBER(wxVSCROLL
)
122 wxFLAGS_MEMBER(wxHSCROLL
)
124 wxFLAGS_MEMBER(wxTE_PROCESS_ENTER
)
125 wxFLAGS_MEMBER(wxTE_PROCESS_TAB
)
126 wxFLAGS_MEMBER(wxTE_MULTILINE
)
127 wxFLAGS_MEMBER(wxTE_PASSWORD
)
128 wxFLAGS_MEMBER(wxTE_READONLY
)
129 wxFLAGS_MEMBER(wxHSCROLL
)
130 wxFLAGS_MEMBER(wxTE_RICH
)
131 wxFLAGS_MEMBER(wxTE_RICH2
)
132 wxFLAGS_MEMBER(wxTE_AUTO_URL
)
133 wxFLAGS_MEMBER(wxTE_NOHIDESEL
)
134 wxFLAGS_MEMBER(wxTE_LEFT
)
135 wxFLAGS_MEMBER(wxTE_CENTRE
)
136 wxFLAGS_MEMBER(wxTE_RIGHT
)
137 wxFLAGS_MEMBER(wxTE_DONTWRAP
)
138 wxFLAGS_MEMBER(wxTE_CHARWRAP
)
139 wxFLAGS_MEMBER(wxTE_WORDWRAP
)
141 wxEND_FLAGS( wxTextCtrlStyle
)
143 IMPLEMENT_DYNAMIC_CLASS_XTI(wxTextCtrl
, wxControl
,"wx/textctrl.h")
145 wxBEGIN_PROPERTIES_TABLE(wxTextCtrl
)
146 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
147 wxEVENT_PROPERTY( TextEnter
, wxEVT_COMMAND_TEXT_ENTER
, wxCommandEvent
)
149 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
150 wxPROPERTY( Value
, wxString
, SetValue
, GetValue
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
151 wxPROPERTY_FLAGS( WindowStyle
, wxTextCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
152 wxEND_PROPERTIES_TABLE()
154 wxBEGIN_HANDLERS_TABLE(wxTextCtrl
)
155 wxEND_HANDLERS_TABLE()
157 wxCONSTRUCTOR_6( wxTextCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Value
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
159 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxTextCtrlBase
)
163 BEGIN_EVENT_TABLE(wxTextCtrl
, wxTextCtrlBase
)
164 EVT_CHAR(wxTextCtrl::OnChar
)
165 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
168 EVT_RIGHT_UP(wxTextCtrl::OnRightClick
)
171 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
172 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
173 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
174 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
175 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
176 EVT_MENU(wxID_CLEAR
, wxTextCtrl::OnDelete
)
177 EVT_MENU(wxID_SELECTALL
, wxTextCtrl::OnSelectAll
)
179 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
180 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
181 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
182 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
183 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
184 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl::OnUpdateDelete
)
185 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl::OnUpdateSelectAll
)
187 EVT_SET_FOCUS(wxTextCtrl::OnSetFocus
)
190 // ============================================================================
192 // ============================================================================
194 // ----------------------------------------------------------------------------
196 // ----------------------------------------------------------------------------
198 void wxTextCtrl::Init()
202 wxTextCtrl::~wxTextCtrl()
206 bool wxTextCtrl::Create(wxWindow
*parent
, wxWindowID id
,
207 const wxString
& value
,
211 const wxValidator
& validator
,
212 const wxString
& name
)
217 WXDWORD
wxTextCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
222 // ----------------------------------------------------------------------------
223 // set/get the controls text
224 // ----------------------------------------------------------------------------
226 wxString
wxTextCtrl::GetValue() const
233 void wxTextCtrl::SetValue(const wxString
& value
)
237 #if wxUSE_RICHEDIT && (!wxUSE_UNICODE || wxUSE_UNICODE_MSLU)
239 // TODO: using memcpy() would improve performance a lot for big amounts of text
242 wxRichEditStreamIn(DWORD dwCookie
, BYTE
*buf
, LONG cb
, LONG
*pcb
)
247 // helper struct used to pass parameters from wxTextCtrl to wxRichEditStreamOut
248 struct wxStreamOutData
255 wxRichEditStreamOut(DWORD_PTR dwCookie
, BYTE
*buf
, LONG cb
, LONG
*pcb
)
261 #if wxUSE_UNICODE_MSLU
262 #define UNUSED_IF_MSLU(param)
264 #define UNUSED_IF_MSLU(param) param
268 wxTextCtrl::StreamIn(const wxString
& value
,
269 wxFontEncoding
UNUSED_IF_MSLU(encoding
),
275 #if !wxUSE_UNICODE_MSLU
278 wxTextCtrl::StreamOut(wxFontEncoding encoding
, bool selectionOnly
) const
285 #endif // !wxUSE_UNICODE_MSLU
287 #endif // wxUSE_RICHEDIT
289 void wxTextCtrl::WriteText(const wxString
& value
)
293 void wxTextCtrl::DoWriteText(const wxString
& value
, bool selectionOnly
)
297 void wxTextCtrl::AppendText(const wxString
& text
)
301 void wxTextCtrl::Clear()
305 // ----------------------------------------------------------------------------
306 // Clipboard operations
307 // ----------------------------------------------------------------------------
309 void wxTextCtrl::Copy()
313 void wxTextCtrl::Cut()
317 void wxTextCtrl::Paste()
321 bool wxTextCtrl::HasSelection() const
326 bool wxTextCtrl::CanCopy() const
331 bool wxTextCtrl::CanCut() const
336 bool wxTextCtrl::CanPaste() const
341 // ----------------------------------------------------------------------------
343 // ----------------------------------------------------------------------------
345 void wxTextCtrl::SetEditable(bool editable
)
349 void wxTextCtrl::SetInsertionPoint(long pos
)
353 void wxTextCtrl::SetInsertionPointEnd()
357 long wxTextCtrl::GetInsertionPoint() const
362 wxTextPos
wxTextCtrl::GetLastPosition() const
367 // If the return values from and to are the same, there is no
369 void wxTextCtrl::GetSelection(long* from
, long* to
) const
373 bool wxTextCtrl::IsEditable() const
378 // ----------------------------------------------------------------------------
380 // ----------------------------------------------------------------------------
382 void wxTextCtrl::SetSelection(long from
, long to
)
386 void wxTextCtrl::DoSetSelection(long from
, long to
, bool scrollCaret
)
390 // ----------------------------------------------------------------------------
391 // Working with files
392 // ----------------------------------------------------------------------------
394 bool wxTextCtrl::LoadFile(const wxString
& file
)
399 // ----------------------------------------------------------------------------
401 // ----------------------------------------------------------------------------
403 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
407 void wxTextCtrl::Remove(long from
, long to
)
411 bool wxTextCtrl::IsModified() const
416 void wxTextCtrl::MarkDirty()
420 void wxTextCtrl::DiscardEdits()
424 int wxTextCtrl::GetNumberOfLines() const
429 // ----------------------------------------------------------------------------
430 // Positions <-> coords
431 // ----------------------------------------------------------------------------
433 long wxTextCtrl::XYToPosition(long x
, long y
) const
438 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
443 wxTextCtrlHitTestResult
444 wxTextCtrl::HitTest(const wxPoint
& pt
, wxTextCoord
*col
, wxTextCoord
*row
) const
446 return wxTE_HT_UNKNOWN
;
449 // ----------------------------------------------------------------------------
451 // ----------------------------------------------------------------------------
453 void wxTextCtrl::ShowPosition(long pos
)
457 long wxTextCtrl::GetLengthOfLineContainingPos(long pos
) const
462 int wxTextCtrl::GetLineLength(long lineNo
) const
467 wxString
wxTextCtrl::GetLineText(long lineNo
) const
474 void wxTextCtrl::SetMaxLength(unsigned long len
)
478 // ----------------------------------------------------------------------------
480 // ----------------------------------------------------------------------------
482 void wxTextCtrl::Undo()
486 void wxTextCtrl::Redo()
490 bool wxTextCtrl::CanUndo() const
494 bool wxTextCtrl::CanRedo() const
498 // ----------------------------------------------------------------------------
499 // caret handling (Windows only)
500 // ----------------------------------------------------------------------------
502 bool wxTextCtrl::ShowNativeCaret(bool show
)
507 // ----------------------------------------------------------------------------
508 // implemenation details
509 // ----------------------------------------------------------------------------
511 void wxTextCtrl::Command(wxCommandEvent
& event
)
515 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
519 // ----------------------------------------------------------------------------
520 // kbd input processing
521 // ----------------------------------------------------------------------------
523 bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG
* pMsg
)
528 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
532 WXLRESULT
wxTextCtrl::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
537 // ----------------------------------------------------------------------------
538 // text control event processing
539 // ----------------------------------------------------------------------------
541 bool wxTextCtrl::SendUpdateEvent()
546 bool wxTextCtrl::MSWCommand(WXUINT param
, WXWORD
WXUNUSED(id
))
551 bool wxTextCtrl::AdjustSpaceLimit()
556 bool wxTextCtrl::AcceptsFocus() const
561 wxSize
wxTextCtrl::DoGetBestSize() const
566 // ----------------------------------------------------------------------------
567 // standard handlers for standard edit menu events
568 // ----------------------------------------------------------------------------
570 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
574 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
578 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
582 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
586 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
590 void wxTextCtrl::OnDelete(wxCommandEvent
& WXUNUSED(event
))
594 void wxTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
598 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
602 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
606 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
610 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
614 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
618 void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent
& event
)
622 void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
626 void wxTextCtrl::OnRightClick(wxMouseEvent
& event
)
630 void wxTextCtrl::OnSetFocus(wxFocusEvent
& WXUNUSED(event
))
634 // the rest of the file only deals with the rich edit controls
637 // ----------------------------------------------------------------------------
638 // EN_LINK processing
639 // ----------------------------------------------------------------------------
641 bool wxTextCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
646 // ----------------------------------------------------------------------------
647 // colour setting for the rich edit controls
648 // ----------------------------------------------------------------------------
650 bool wxTextCtrl::SetBackgroundColour(const wxColour
& colour
)
655 bool wxTextCtrl::SetForegroundColour(const wxColour
& colour
)
660 // ----------------------------------------------------------------------------
661 // styling support for rich edit controls
662 // ----------------------------------------------------------------------------
666 bool wxTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
671 bool wxTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
676 bool wxTextCtrl::GetStyle(long position
, wxTextAttr
& style
)
683 // ----------------------------------------------------------------------------
685 // ----------------------------------------------------------------------------
687 bool wxRichEditModule::OnInit()
692 void wxRichEditModule::OnExit()
697 bool wxRichEditModule::Load(int version
)
702 #endif // wxUSE_RICHEDIT
704 #endif // wxUSE_TEXTCTRL