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