summaryrefslogtreecommitdiffstats
path: root/views/examples/textfield_example.cc
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-01 11:40:04 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-01 11:40:04 +0000
commit1a5c97540834be79830865a401368c75f3138381 (patch)
tree433545cba236b0c628ae8d0002ccf98bce5411ce /views/examples/textfield_example.cc
parent7d121994978c05073f4d63bf44311465fcdb2251 (diff)
downloadchromium_src-1a5c97540834be79830865a401368c75f3138381.zip
chromium_src-1a5c97540834be79830865a401368c75f3138381.tar.gz
chromium_src-1a5c97540834be79830865a401368c75f3138381.tar.bz2
views: Move the implementation of more examples from header to source file.
BUG=None TEST=run out/Debug/views_examples, everything should works as before. Review URL: http://codereview.chromium.org/6347030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73276 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/examples/textfield_example.cc')
-rw-r--r--views/examples/textfield_example.cc84
1 files changed, 84 insertions, 0 deletions
diff --git a/views/examples/textfield_example.cc b/views/examples/textfield_example.cc
new file mode 100644
index 0000000..3266e56
--- /dev/null
+++ b/views/examples/textfield_example.cc
@@ -0,0 +1,84 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "views/examples/textfield_example.h"
+
+#include "base/utf_string_conversions.h"
+#include "views/controls/label.h"
+#include "views/layout/grid_layout.h"
+#include "views/view.h"
+
+namespace examples {
+
+TextfieldExample::TextfieldExample(ExamplesMain* main)
+ : ExampleBase(main) {
+}
+
+TextfieldExample::~TextfieldExample() {
+}
+
+std::wstring TextfieldExample::GetExampleTitle() {
+ return L"Textfield";
+}
+
+void TextfieldExample::CreateExampleView(views::View* container) {
+ name_ = new views::Textfield();
+ password_ = new views::Textfield(views::Textfield::STYLE_PASSWORD);
+ password_->set_text_to_display_when_empty(ASCIIToUTF16("password"));
+ show_password_ = new views::TextButton(this, L"Show password");
+ clear_all_ = new views::TextButton(this, L"Clear All");
+ append_ = new views::TextButton(this, L"Append");
+ name_->SetController(this);
+ password_->SetController(this);
+
+ views::GridLayout* layout = new views::GridLayout(container);
+ container->SetLayoutManager(layout);
+
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL,
+ 0.2f, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.8f, views::GridLayout::USE_PREF, 0, 0);
+ layout->StartRow(0, 0);
+ layout->AddView(new views::Label(L"Name:"));
+ layout->AddView(name_);
+ layout->StartRow(0, 0);
+ layout->AddView(new views::Label(L"Password:"));
+ layout->AddView(password_);
+ layout->StartRow(0, 0);
+ layout->AddView(show_password_);
+ layout->StartRow(0, 0);
+ layout->AddView(clear_all_);
+ layout->StartRow(0, 0);
+ layout->AddView(append_);
+}
+
+void TextfieldExample::ContentsChanged(views::Textfield* sender,
+ const string16& new_contents) {
+ if (sender == name_) {
+ PrintStatus(L"Name [%ls]", UTF16ToWideHack(new_contents).c_str());
+ } else if (sender == password_) {
+ PrintStatus(L"Password [%ls]", UTF16ToWideHack(new_contents).c_str());
+ }
+}
+
+bool TextfieldExample::HandleKeyEvent(views::Textfield* sender,
+ const views::KeyEvent& key_event) {
+ return false;
+}
+
+void TextfieldExample::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ if (sender == show_password_) {
+ PrintStatus(L"Password [%ls]", UTF16ToWideHack(password_->text()).c_str());
+ } else if (sender == clear_all_) {
+ string16 empty;
+ name_->SetText(empty);
+ password_->SetText(empty);
+ } else if (sender == append_) {
+ name_->AppendText(WideToUTF16(L"[append]"));
+ }
+}
+
+} // namespace examples