Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: views/controls/textfield/native_textfield_gtk.cc

Issue 177026: Make the views bookmark bubble work on GTK.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/controls/textfield/native_textfield_gtk.h ('k') | views/widget/widget_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "views/controls/textfield/native_textfield_gtk.h" 5 #include "views/controls/textfield/native_textfield_gtk.h"
6 6
7 #include "base/string_util.h"
8 #include "views/controls/textfield/textfield.h"
9
7 namespace views { 10 namespace views {
8 11
9 //////////////////////////////////////////////////////////////////////////////// 12 ////////////////////////////////////////////////////////////////////////////////
10 // NativeTextfieldGtk, public: 13 // NativeTextfieldGtk, public:
11 14
12 NativeTextfieldGtk::NativeTextfieldGtk(Textfield* textfield) 15 NativeTextfieldGtk::NativeTextfieldGtk(Textfield* textfield)
13 : NativeControlGtk() { 16 : NativeControlGtk(),
17 textfield_(textfield) {
18 DCHECK(!(textfield_->style() & Textfield::STYLE_MULTILINE)) <<
sky 2009/08/28 20:23:51 Can you add a todo or make this a NOTIMPLEMENTED s
19 "We don't support multiline yet.";
14 } 20 }
15 21
16 NativeTextfieldGtk::~NativeTextfieldGtk() { 22 NativeTextfieldGtk::~NativeTextfieldGtk() {
17 } 23 }
18 24
19 //////////////////////////////////////////////////////////////////////////////// 25 ////////////////////////////////////////////////////////////////////////////////
20 // NativeTextfieldGtk, NativeTextfieldWrapper implementation: 26 // NativeTextfieldGtk, NativeTextfieldWrapper implementation:
21 27
22 std::wstring NativeTextfieldGtk::GetText() const { 28 std::wstring NativeTextfieldGtk::GetText() const {
23 return std::wstring(); 29 if (!native_view())
30 return std::wstring();
31 return UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(native_view())));
24 } 32 }
25 33
26 void NativeTextfieldGtk::UpdateText() { 34 void NativeTextfieldGtk::UpdateText() {
35 if (!native_view())
36 return;
37 gtk_entry_set_text(GTK_ENTRY(native_view()),
38 WideToUTF8(textfield_->text()).c_str());
27 } 39 }
28 40
29 void NativeTextfieldGtk::AppendText(const std::wstring& text) { 41 void NativeTextfieldGtk::AppendText(const std::wstring& text) {
42 if (!native_view())
43 return;
44 gtk_entry_append_text(GTK_ENTRY(native_view()), WideToUTF8(text).c_str());
30 } 45 }
31 46
32 std::wstring NativeTextfieldGtk::GetSelectedText() const { 47 std::wstring NativeTextfieldGtk::GetSelectedText() const {
33 return std::wstring(); 48 if (!native_view())
49 return std::wstring();
50
51 int begin, end;
52 if (!gtk_editable_get_selection_bounds(GTK_EDITABLE(native_view()),
53 &begin, &end))
54 return std::wstring(); // Nothing selected.
55
56 return UTF8ToWide(std::string(
57 &gtk_entry_get_text(GTK_ENTRY(native_view()))[begin],
58 end - begin));
34 } 59 }
35 60
36 void NativeTextfieldGtk::SelectAll() { 61 void NativeTextfieldGtk::SelectAll() {
62 if (!native_view())
63 return;
64 // -1 as the end position selects to the end of the text.
65 gtk_editable_select_region(GTK_EDITABLE(native_view()),
66 0, -1);
37 } 67 }
38 68
39 void NativeTextfieldGtk::ClearSelection() { 69 void NativeTextfieldGtk::ClearSelection() {
70 if (!native_view())
71 return;
72 gtk_editable_select_region(GTK_EDITABLE(native_view()), 0, 0);
40 } 73 }
41 74
42 void NativeTextfieldGtk::UpdateBorder() { 75 void NativeTextfieldGtk::UpdateBorder() {
76 if (!native_view())
77 return;
78 NOTIMPLEMENTED();
43 } 79 }
44 80
45 void NativeTextfieldGtk::UpdateBackgroundColor() { 81 void NativeTextfieldGtk::UpdateBackgroundColor() {
82 if (!native_view())
83 return;
84 NOTIMPLEMENTED();
46 } 85 }
47 86
48 void NativeTextfieldGtk::UpdateReadOnly() { 87 void NativeTextfieldGtk::UpdateReadOnly() {
88 if (!native_view())
89 return;
90 gtk_editable_set_editable(GTK_EDITABLE(native_view()), textfield_->IsEnabled() );
sky 2009/08/28 20:23:51 nit: > 80
49 } 91 }
50 92
51 void NativeTextfieldGtk::UpdateFont() { 93 void NativeTextfieldGtk::UpdateFont() {
94 if (!native_view())
95 return;
96 NOTIMPLEMENTED();
52 } 97 }
53 98
54 void NativeTextfieldGtk::UpdateEnabled() { 99 void NativeTextfieldGtk::UpdateEnabled() {
100 if (!native_view())
101 return;
102 NOTIMPLEMENTED();
55 } 103 }
56 104
57 void NativeTextfieldGtk::SetHorizontalMargins(int left, int right) { 105 void NativeTextfieldGtk::SetHorizontalMargins(int left, int right) {
106 if (!native_view())
107 return;
108 NOTIMPLEMENTED();
58 } 109 }
59 110
60 void NativeTextfieldGtk::SetFocus() { 111 void NativeTextfieldGtk::SetFocus() {
112 Focus();
61 } 113 }
62 114
63 View* NativeTextfieldGtk::GetView() { 115 View* NativeTextfieldGtk::GetView() {
64 return this; 116 return this;
65 } 117 }
66 118
67 gfx::NativeView NativeTextfieldGtk::GetTestingHandle() const { 119 gfx::NativeView NativeTextfieldGtk::GetTestingHandle() const {
68 return native_view(); 120 return native_view();
69 } 121 }
70 122
71 //////////////////////////////////////////////////////////////////////////////// 123 ////////////////////////////////////////////////////////////////////////////////
72 // NativeTextfieldGtk, NativeControlGtk overrides: 124 // NativeTextfieldGtk, NativeControlGtk overrides:
73 125
74 void NativeTextfieldGtk::CreateNativeControl() { 126 void NativeTextfieldGtk::CreateNativeControl() {
75 // TODO(port): create gtk text field 127 GtkWidget* widget = gtk_entry_new();
128 // TODO(brettw) hook in an observer to get text change events so we can call
129 // the controller.
130 NativeControlCreated(widget);
76 } 131 }
77 132
78 void NativeTextfieldGtk::NativeControlCreated(GtkWidget* widget) { 133 void NativeTextfieldGtk::NativeControlCreated(GtkWidget* widget) {
79 NativeControlGtk::NativeControlCreated(widget); 134 NativeControlGtk::NativeControlCreated(widget);
80 // TODO(port): post-creation init 135 // TODO(port): post-creation init
81 } 136 }
82 137
138 ////////////////////////////////////////////////////////////////////////////////
139 // NativeTextfieldWrapper, public:
140
141 // static
142 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper(
143 Textfield* field) {
144 return new NativeTextfieldGtk(field);
145 }
146
83 } // namespace views 147 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/textfield/native_textfield_gtk.h ('k') | views/widget/widget_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698