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"
39 #include "wx/module.h"
43 #include "wx/clipbrd.h"
46 #include "wx/textfile.h"
52 #include "wx/palmos/missing.h"
54 #endif // wxUSE_RICHEDIT
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
62 // this module initializes RichEdit DLL(s) if needed
63 class wxRichEditModule
: public wxModule
66 virtual bool OnInit();
67 virtual void OnExit();
69 // load the richedit DLL of at least of required version
70 static bool Load(int version
= 1);
73 // the handles to richedit 1.0 and 2.0 (or 3.0) DLLs
74 static HINSTANCE ms_hRichEdit
[2];
76 DECLARE_DYNAMIC_CLASS(wxRichEditModule
)
79 HINSTANCE wxRichEditModule
::ms_hRichEdit
[2] = { NULL
, NULL
};
81 IMPLEMENT_DYNAMIC_CLASS(wxRichEditModule
, wxModule
)
83 #endif // wxUSE_RICHEDIT
85 // ----------------------------------------------------------------------------
86 // event tables and other macros
87 // ----------------------------------------------------------------------------
89 BEGIN_EVENT_TABLE(wxTextCtrl
, wxTextCtrlBase
)
90 EVT_CHAR(wxTextCtrl
::OnChar
)
91 EVT_DROP_FILES(wxTextCtrl
::OnDropFiles
)
94 EVT_RIGHT_UP(wxTextCtrl
::OnRightClick
)
97 EVT_MENU(wxID_CUT
, wxTextCtrl
::OnCut
)
98 EVT_MENU(wxID_COPY
, wxTextCtrl
::OnCopy
)
99 EVT_MENU(wxID_PASTE
, wxTextCtrl
::OnPaste
)
100 EVT_MENU(wxID_UNDO
, wxTextCtrl
::OnUndo
)
101 EVT_MENU(wxID_REDO
, wxTextCtrl
::OnRedo
)
102 EVT_MENU(wxID_CLEAR
, wxTextCtrl
::OnDelete
)
103 EVT_MENU(wxID_SELECTALL
, wxTextCtrl
::OnSelectAll
)
105 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl
::OnUpdateCut
)
106 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl
::OnUpdateCopy
)
107 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl
::OnUpdatePaste
)
108 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl
::OnUpdateUndo
)
109 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl
::OnUpdateRedo
)
110 EVT_UPDATE_UI(wxID_CLEAR
, wxTextCtrl
::OnUpdateDelete
)
111 EVT_UPDATE_UI(wxID_SELECTALL
, wxTextCtrl
::OnUpdateSelectAll
)
113 EVT_SET_FOCUS(wxTextCtrl
::OnSetFocus
)
116 // ============================================================================
118 // ============================================================================
120 // ----------------------------------------------------------------------------
122 // ----------------------------------------------------------------------------
124 void wxTextCtrl
::Init()
128 wxTextCtrl
::~wxTextCtrl()
132 bool wxTextCtrl
::Create(wxWindow
*parent
, wxWindowID id
,
133 const wxString
& value
,
137 const wxValidator
& validator
,
138 const wxString
& name
)
143 // ----------------------------------------------------------------------------
144 // set/get the controls text
145 // ----------------------------------------------------------------------------
147 wxString wxTextCtrl
::GetValue() const
153 wxString wxTextCtrl
::GetRange(long from
, long to
) const
159 void wxTextCtrl
::DoSetValue(const wxString
& value
, int flags
)
163 void wxTextCtrl
::WriteText(const wxString
& value
)
167 void wxTextCtrl
::DoWriteText(const wxString
& text
, int flags
)
171 void wxTextCtrl
::AppendText(const wxString
& text
)
175 void wxTextCtrl
::Clear()
179 // ----------------------------------------------------------------------------
180 // Clipboard operations
181 // ----------------------------------------------------------------------------
183 void wxTextCtrl
::Copy()
187 void wxTextCtrl
::Cut()
191 void wxTextCtrl
::Paste()
195 bool wxTextCtrl
::CanCopy() const
200 bool wxTextCtrl
::CanCut() const
205 bool wxTextCtrl
::CanPaste() const
210 // ----------------------------------------------------------------------------
212 // ----------------------------------------------------------------------------
214 void wxTextCtrl
::SetEditable(bool editable
)
218 void wxTextCtrl
::SetInsertionPoint(long pos
)
222 void wxTextCtrl
::SetInsertionPointEnd()
226 long wxTextCtrl
::GetInsertionPoint() const
231 wxTextPos wxTextCtrl
::GetLastPosition() const
236 // If the return values from and to are the same, there is no
238 void wxTextCtrl
::GetSelection(long* from
, long* to
) const
242 bool wxTextCtrl
::IsEditable() const
247 // ----------------------------------------------------------------------------
249 // ----------------------------------------------------------------------------
251 void wxTextCtrl
::SetSelection(long from
, long to
)
255 void wxTextCtrl
::DoSetSelection(long from
, long to
, int flags
)
259 // ----------------------------------------------------------------------------
260 // Working with files
261 // ----------------------------------------------------------------------------
263 bool wxTextCtrl
::DoLoadFile(const wxString
& file
, int fileType
)
268 // ----------------------------------------------------------------------------
270 // ----------------------------------------------------------------------------
272 void wxTextCtrl
::Replace(long from
, long to
, const wxString
& value
)
276 void wxTextCtrl
::Remove(long from
, long to
)
280 bool wxTextCtrl
::IsModified() const
285 void wxTextCtrl
::MarkDirty()
289 void wxTextCtrl
::DiscardEdits()
293 int wxTextCtrl
::GetNumberOfLines() const
298 // ----------------------------------------------------------------------------
299 // Positions <-> coords
300 // ----------------------------------------------------------------------------
302 long wxTextCtrl
::XYToPosition(long x
, long y
) const
307 bool wxTextCtrl
::PositionToXY(long pos
, long *x
, long *y
) const
312 wxTextCtrlHitTestResult
313 wxTextCtrl
::HitTest(const wxPoint
& pt
, long *pos
) const
315 return wxTE_HT_UNKNOWN
;
318 // ----------------------------------------------------------------------------
320 // ----------------------------------------------------------------------------
322 void wxTextCtrl
::ShowPosition(long pos
)
326 long wxTextCtrl
::GetLengthOfLineContainingPos(long pos
) const
331 int wxTextCtrl
::GetLineLength(long lineNo
) const
336 wxString wxTextCtrl
::GetLineText(long lineNo
) const
343 void wxTextCtrl
::SetMaxLength(unsigned long len
)
347 // ----------------------------------------------------------------------------
349 // ----------------------------------------------------------------------------
351 void wxTextCtrl
::Undo()
355 void wxTextCtrl
::Redo()
359 bool wxTextCtrl
::CanUndo() const
364 bool wxTextCtrl
::CanRedo() const
369 // ----------------------------------------------------------------------------
370 // caret handling (Windows only)
371 // ----------------------------------------------------------------------------
373 bool wxTextCtrl
::ShowNativeCaret(bool show
)
378 // ----------------------------------------------------------------------------
379 // implemenation details
380 // ----------------------------------------------------------------------------
382 void wxTextCtrl
::Command(wxCommandEvent
& event
)
386 void wxTextCtrl
::OnDropFiles(wxDropFilesEvent
& event
)
390 // ----------------------------------------------------------------------------
391 // kbd input processing
392 // ----------------------------------------------------------------------------
394 void wxTextCtrl
::OnChar(wxKeyEvent
& event
)
398 // ----------------------------------------------------------------------------
399 // text control event processing
400 // ----------------------------------------------------------------------------
402 bool wxTextCtrl
::SendUpdateEvent()
407 bool wxTextCtrl
::AdjustSpaceLimit()
412 wxSize wxTextCtrl
::DoGetBestSize() const
417 // ----------------------------------------------------------------------------
418 // standard handlers for standard edit menu events
419 // ----------------------------------------------------------------------------
421 void wxTextCtrl
::OnCut(wxCommandEvent
& WXUNUSED(event
))
425 void wxTextCtrl
::OnCopy(wxCommandEvent
& WXUNUSED(event
))
429 void wxTextCtrl
::OnPaste(wxCommandEvent
& WXUNUSED(event
))
433 void wxTextCtrl
::OnUndo(wxCommandEvent
& WXUNUSED(event
))
437 void wxTextCtrl
::OnRedo(wxCommandEvent
& WXUNUSED(event
))
441 void wxTextCtrl
::OnDelete(wxCommandEvent
& WXUNUSED(event
))
445 void wxTextCtrl
::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
449 void wxTextCtrl
::OnUpdateCut(wxUpdateUIEvent
& event
)
453 void wxTextCtrl
::OnUpdateCopy(wxUpdateUIEvent
& event
)
457 void wxTextCtrl
::OnUpdatePaste(wxUpdateUIEvent
& event
)
461 void wxTextCtrl
::OnUpdateUndo(wxUpdateUIEvent
& event
)
465 void wxTextCtrl
::OnUpdateRedo(wxUpdateUIEvent
& event
)
469 void wxTextCtrl
::OnUpdateDelete(wxUpdateUIEvent
& event
)
473 void wxTextCtrl
::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
477 void wxTextCtrl
::OnSetFocus(wxFocusEvent
& WXUNUSED(event
))
481 wxVisualAttributes wxTextCtrl
::GetDefaultAttributes() const
483 wxVisualAttributes attrs
;
484 attrs
.font
= wxSystemSettings
::GetFont(wxSYS_DEFAULT_GUI_FONT
);
485 attrs
.colFg
= wxSystemSettings
::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
486 attrs
.colBg
= wxSystemSettings
::GetColour(wxSYS_COLOUR_WINDOW
); //white
490 bool wxTextCtrl
::EmulateKeyPress(const wxKeyEvent
& rEvent
)
494 bool wxTextCtrl
::CanApplyThemeBorder() const
498 bool wxTextCtrl
::IsEmpty() const
502 bool wxTextCtrl
::AcceptsFocusFromKeyboard() const
506 void wxTextCtrl
::AdoptAttributesFromHWND()
509 void wxTextCtrl
::SetWindowStyleFlag(long lStyle
)
513 // the rest of the file only deals with the rich edit controls
516 // ----------------------------------------------------------------------------
517 // EN_LINK processing
518 // ----------------------------------------------------------------------------
520 bool wxTextCtrl
::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
525 // ----------------------------------------------------------------------------
526 // colour setting for the rich edit controls
527 // ----------------------------------------------------------------------------
529 bool wxTextCtrl
::SetBackgroundColour(const wxColour
& colour
)
534 bool wxTextCtrl
::SetForegroundColour(const wxColour
& colour
)
539 // ----------------------------------------------------------------------------
541 // ----------------------------------------------------------------------------
543 bool wxRichEditModule
::OnInit()
548 void wxRichEditModule
::OnExit()
553 bool wxRichEditModule
::Load(int version
)
558 #endif // wxUSE_RICHEDIT
560 // ----------------------------------------------------------------------------
561 // styling support for rich edit controls
562 // ----------------------------------------------------------------------------
566 bool wxTextCtrl
::SetStyle(long start
, long end
, const wxTextAttr
& style
)
571 bool wxTextCtrl
::SetDefaultStyle(const wxTextAttr
& style
)
576 bool wxTextCtrl
::GetStyle(long position
, wxTextAttr
& style
)
581 #endif // wxUSE_RICHEDIT
583 #endif // wxUSE_TEXTCTRL