]> git.saurik.com Git - wxWidgets.git/blame - src/common/textentrycmn.cpp
Use gdk_window_invalidate instead of gtk_widget_queue_draw as the latter doesn't...
[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;
e9863f4e 43 wxString value = GetValue();
2b42a870
VZ
44
45 if ( from < to && (long)value.length() >= to )
0ec1179b 46 {
2b42a870 47 sel = value.substr(from, to - from);
0ec1179b
VZ
48 }
49
50 return sel;
51}
52
53void wxTextEntryBase::AppendText(const wxString& text)
54{
55 SetInsertionPointEnd();
56 WriteText(text);
57}
58
59void wxTextEntryBase::DoSetValue(const wxString& value, int flags)
60{
61 EventsSuppressor noeventsIf(this, !(flags & SetValue_SendEvent));
62
63 SelectAll();
64 WriteText(value);
a5125dc6
VZ
65
66 SetInsertionPoint(0);
0ec1179b
VZ
67}
68
69void wxTextEntryBase::Replace(long from, long to, const wxString& value)
70{
71 {
72 EventsSuppressor noevents(this);
73 Remove(from, to);
74 }
75
059979d8 76 SetInsertionPoint(from);
0ec1179b
VZ
77 WriteText(value);
78}
79
80bool wxTextEntryBase::HasSelection() const
81{
82 long from, to;
83 GetSelection(&from, &to);
84
85 return from < to;
86}
87
5a25f858
VZ
88void wxTextEntryBase::RemoveSelection()
89{
90 long from, to;
91 GetSelection(& from, & to);
92 if (from != -1 && to != -1)
93 Remove(from, to);
94}
95
0ec1179b
VZ
96wxString wxTextEntryBase::GetStringSelection() const
97{
98 long from, to;
99 GetSelection(&from, &to);
100
101 return GetRange(from, to);
102}
103
104bool wxTextEntryBase::CanCopy() const
105{
106 return HasSelection();
107}
108
109bool wxTextEntryBase::CanCut() const
110{
111 return CanCopy() && IsEditable();
112}
113
114bool wxTextEntryBase::CanPaste() const
115{
fa2f57be
VZ
116 if ( IsEditable() )
117 {
118#if wxUSE_CLIPBOARD
119 // check if there is any text on the clipboard
fa9cd5d3
VZ
120 if ( wxTheClipboard->IsSupported(wxDF_TEXT)
121#if wxUSE_UNICODE
122 || wxTheClipboard->IsSupported(wxDF_UNICODETEXT)
123#endif // wxUSE_UNICODE
124 )
125 {
fa2f57be 126 return true;
fa9cd5d3 127 }
fa2f57be
VZ
128#endif // wxUSE_CLIPBOARD
129 }
130
131 return false;
0ec1179b
VZ
132}
133
134#endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX