]> git.saurik.com Git - wxWidgets.git/blame - src/common/textentrycmn.cpp
[ 1944519 ] improve left down event handling for wxPopupTransientWindow
[wxWidgets.git] / src / common / textentrycmn.cpp
CommitLineData
0ec1179b
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/common/textentrycmn.cpp
3// Purpose: wxTextEntryBase implementation
4// Author: Vadim Zeitlin
5// Created: 2007-09-26
6// RCS-ID: $Id$
7// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19// for compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#if wxUSE_TEXTCTRL || wxUSE_COMBOBOX
27
28#ifndef WX_PRECOMP
86116620
RR
29 #include "wx/window.h"
30 #include "wx/dataobj.h"
0ec1179b
VZ
31#endif //WX_PRECOMP
32
33#include "wx/textentry.h"
fa2f57be 34#include "wx/clipbrd.h"
0ec1179b
VZ
35
36// ============================================================================
37// wxTextEntryBase implementation
38// ============================================================================
39
40wxString wxTextEntryBase::GetRange(long from, long to) const
41{
42 wxString sel;
43 if ( from < to )
44 {
45 sel = GetValue().substr(from, to - from);
46 }
47
48 return sel;
49}
50
51void wxTextEntryBase::AppendText(const wxString& text)
52{
53 SetInsertionPointEnd();
54 WriteText(text);
55}
56
57void wxTextEntryBase::DoSetValue(const wxString& value, int flags)
58{
59 EventsSuppressor noeventsIf(this, !(flags & SetValue_SendEvent));
60
61 SelectAll();
62 WriteText(value);
63}
64
65void wxTextEntryBase::Replace(long from, long to, const wxString& value)
66{
67 {
68 EventsSuppressor noevents(this);
69 Remove(from, to);
70 }
71
72 WriteText(value);
73}
74
75bool wxTextEntryBase::HasSelection() const
76{
77 long from, to;
78 GetSelection(&from, &to);
79
80 return from < to;
81}
82
5a25f858
VZ
83void wxTextEntryBase::RemoveSelection()
84{
85 long from, to;
86 GetSelection(& from, & to);
87 if (from != -1 && to != -1)
88 Remove(from, to);
89}
90
0ec1179b
VZ
91wxString wxTextEntryBase::GetStringSelection() const
92{
93 long from, to;
94 GetSelection(&from, &to);
95
96 return GetRange(from, to);
97}
98
99bool wxTextEntryBase::CanCopy() const
100{
101 return HasSelection();
102}
103
104bool wxTextEntryBase::CanCut() const
105{
106 return CanCopy() && IsEditable();
107}
108
109bool wxTextEntryBase::CanPaste() const
110{
fa2f57be
VZ
111 if ( IsEditable() )
112 {
113#if wxUSE_CLIPBOARD
114 // check if there is any text on the clipboard
fa9cd5d3
VZ
115 if ( wxTheClipboard->IsSupported(wxDF_TEXT)
116#if wxUSE_UNICODE
117 || wxTheClipboard->IsSupported(wxDF_UNICODETEXT)
118#endif // wxUSE_UNICODE
119 )
120 {
fa2f57be 121 return true;
fa9cd5d3 122 }
fa2f57be
VZ
123#endif // wxUSE_CLIPBOARD
124 }
125
126 return false;
0ec1179b
VZ
127}
128
129#endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX