OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "views/examples/button_example.h" | |
6 | |
7 #include "base/utf_string_conversions.h" | |
8 #include "grit/ui_resources.h" | |
9 #include "ui/base/resource/resource_bundle.h" | |
10 #include "views/controls/button/checkbox.h" | |
11 #include "views/layout/fill_layout.h" | |
12 #include "views/view.h" | |
13 | |
14 namespace examples { | |
15 | |
16 ButtonExample::ButtonExample(ExamplesMain* main) | |
17 : ExampleBase(main, "Text Button"), | |
18 alignment_(views::TextButton::ALIGN_LEFT), | |
19 use_native_theme_border_(false), | |
20 icon_(NULL), | |
21 count_(0) { | |
22 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
23 icon_ = rb.GetBitmapNamed(IDR_CLOSE_SA_H); | |
24 } | |
25 | |
26 ButtonExample::~ButtonExample() { | |
27 } | |
28 | |
29 void ButtonExample::CreateExampleView(views::View* container) { | |
30 views::TextButton* tb = new views::TextButton(this, ASCIIToUTF16("Button")); | |
31 button_ = tb; | |
32 container->SetLayoutManager(new views::FillLayout); | |
33 container->AddChildView(button_); | |
34 } | |
35 | |
36 void ButtonExample::ButtonPressed(views::Button* sender, | |
37 const views::Event& event) { | |
38 PrintStatus("Pressed! count: %d", ++count_); | |
39 | |
40 if (event.IsControlDown()) { | |
41 if (event.IsShiftDown()) { | |
42 if (event.IsAltDown()) { | |
43 button_->SetMultiLine(!button_->multi_line()); | |
44 if (button_->multi_line()) { | |
45 button_->SetText(ASCIIToUTF16("Multi-line text\n") + | |
46 ASCIIToUTF16("is here to stay all the way!\n") + | |
47 ASCIIToUTF16("123")); | |
48 } else { | |
49 button_->SetText(ASCIIToUTF16("Button")); | |
50 } | |
51 } else { | |
52 switch(button_->icon_placement()) { | |
53 case views::TextButton::ICON_ON_LEFT: | |
54 button_->set_icon_placement(views::TextButton::ICON_ON_RIGHT); | |
55 break; | |
56 case views::TextButton::ICON_ON_RIGHT: | |
57 button_->set_icon_placement(views::TextButton::ICON_ON_LEFT); | |
58 break; | |
59 } | |
60 } | |
61 } else if (event.IsAltDown()) { | |
62 if (button_->HasIcon()) | |
63 button_->SetIcon(SkBitmap()); | |
64 else | |
65 button_->SetIcon(*icon_); | |
66 } else { | |
67 switch(alignment_) { | |
68 case views::TextButton::ALIGN_LEFT: | |
69 alignment_ = views::TextButton::ALIGN_CENTER; | |
70 break; | |
71 case views::TextButton::ALIGN_CENTER: | |
72 alignment_ = views::TextButton::ALIGN_RIGHT; | |
73 break; | |
74 case views::TextButton::ALIGN_RIGHT: | |
75 alignment_ = views::TextButton::ALIGN_LEFT; | |
76 break; | |
77 } | |
78 button_->set_alignment(alignment_); | |
79 } | |
80 } else if (event.IsShiftDown()) { | |
81 if (event.IsAltDown()) { | |
82 if (button_->text().length() < 10) { | |
83 button_->SetText( | |
84 ASCIIToUTF16("Startof") + | |
85 ASCIIToUTF16("ReallyReallyReallyReallyReallyReallyReally") + | |
86 ASCIIToUTF16("ReallyReallyReallyReallyReallyReallyReally") + | |
87 ASCIIToUTF16("ReallyReallyReallyReallyReallyReallyReally") + | |
88 ASCIIToUTF16("LongButtonText")); | |
89 } else { | |
90 button_->SetText(ASCIIToUTF16("Button")); | |
91 } | |
92 } else { | |
93 use_native_theme_border_ = !use_native_theme_border_; | |
94 if (use_native_theme_border_) | |
95 button_->set_border(new views::TextButtonNativeThemeBorder(button_)); | |
96 else | |
97 button_->set_border(new views::TextButtonBorder()); | |
98 } | |
99 } else if (event.IsAltDown()) { | |
100 button_->SetIsDefault(!button_->is_default()); | |
101 } | |
102 } | |
103 | |
104 } // namespace examples | |
OLD | NEW |