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

Side by Side Diff: ui/views/examples/text_example.cc

Issue 9965017: views: Rename ComboboxListener::ItemChanged to something more accurate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: combo_box -> combobox Created 8 years, 8 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 | « ui/views/examples/text_example.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/text_example.h" 5 #include "ui/views/examples/text_example.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "ui/base/resource/resource_bundle.h" 8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/views/controls/button/checkbox.h" 10 #include "ui/views/controls/button/checkbox.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 layout->AddView(checkbox); 183 layout->AddView(checkbox);
184 return checkbox; 184 return checkbox;
185 } 185 }
186 186
187 Combobox* TextExample::AddCombobox(GridLayout* layout, 187 Combobox* TextExample::AddCombobox(GridLayout* layout,
188 const char* name, 188 const char* name,
189 const char** strings, 189 const char** strings,
190 int count) { 190 int count) {
191 layout->StartRow(0, 0); 191 layout->StartRow(0, 0);
192 layout->AddView(new Label(ASCIIToUTF16(name))); 192 layout->AddView(new Label(ASCIIToUTF16(name)));
193 ExampleComboboxModel* new_model = new ExampleComboboxModel(strings, count); 193 ExampleComboboxModel* combobox_model = new ExampleComboboxModel(strings,
194 example_combobox_model_.push_back(new_model); 194 count);
195 Combobox* combo_box = new Combobox(new_model); 195 example_combobox_model_.push_back(combobox_model);
196 combo_box->SetSelectedIndex(0); 196 Combobox* combobox = new Combobox(combobox_model);
197 combo_box->set_listener(this); 197 combobox->SetSelectedIndex(0);
198 layout->AddView(combo_box, kNumColumns - 1, 1); 198 combobox->set_listener(this);
199 return combo_box; 199 layout->AddView(combobox, kNumColumns - 1, 1);
200 return combobox;
200 } 201 }
201 202
202 void TextExample::CreateExampleView(View* container) { 203 void TextExample::CreateExampleView(View* container) {
203 text_view_ = new TextExampleView; 204 text_view_ = new TextExampleView;
204 text_view_->set_border(views::Border::CreateSolidBorder(1, SK_ColorGRAY)); 205 text_view_->set_border(views::Border::CreateSolidBorder(1, SK_ColorGRAY));
205 206
206 GridLayout* layout = new GridLayout(container); 207 GridLayout* layout = new GridLayout(container);
207 container->SetLayoutManager(layout); 208 container->SetLayoutManager(layout);
208 209
209 layout->AddPaddingRow(0, 8); 210 layout->AddPaddingRow(0, 8);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 SetFlagFromCheckbox(break_checkbox_, &flags, gfx::Canvas::CHARACTER_BREAK); 268 SetFlagFromCheckbox(break_checkbox_, &flags, gfx::Canvas::CHARACTER_BREAK);
268 SetFlagFromCheckbox(bold_checkbox_, &style, gfx::Font::BOLD); 269 SetFlagFromCheckbox(bold_checkbox_, &style, gfx::Font::BOLD);
269 SetFlagFromCheckbox(italic_checkbox_, &style, gfx::Font::ITALIC); 270 SetFlagFromCheckbox(italic_checkbox_, &style, gfx::Font::ITALIC);
270 SetFlagFromCheckbox(underline_checkbox_, &style, gfx::Font::UNDERLINED); 271 SetFlagFromCheckbox(underline_checkbox_, &style, gfx::Font::UNDERLINED);
271 text_view_->set_halo(halo_checkbox_->checked()); 272 text_view_->set_halo(halo_checkbox_->checked());
272 text_view_->set_text_flags(flags); 273 text_view_->set_text_flags(flags);
273 text_view_->SetFontStyle(style); 274 text_view_->SetFontStyle(style);
274 text_view_->SchedulePaint(); 275 text_view_->SchedulePaint();
275 } 276 }
276 277
277 void TextExample::ItemChanged(Combobox* combo_box, 278 void TextExample::OnSelectedIndexChanged(Combobox* combobox) {
278 int prev_index,
279 int new_index) {
280 int text_flags = text_view_->text_flags(); 279 int text_flags = text_view_->text_flags();
281 if (combo_box == h_align_cb_) { 280 if (combobox == h_align_cb_) {
282 text_flags &= ~(gfx::Canvas::TEXT_ALIGN_LEFT | 281 text_flags &= ~(gfx::Canvas::TEXT_ALIGN_LEFT |
283 gfx::Canvas::TEXT_ALIGN_CENTER | 282 gfx::Canvas::TEXT_ALIGN_CENTER |
284 gfx::Canvas::TEXT_ALIGN_RIGHT); 283 gfx::Canvas::TEXT_ALIGN_RIGHT);
285 switch (new_index) { 284 switch (combobox->selected_index()) {
286 case 0: 285 case 0:
287 break; 286 break;
288 case 1: 287 case 1:
289 text_flags |= gfx::Canvas::TEXT_ALIGN_LEFT; 288 text_flags |= gfx::Canvas::TEXT_ALIGN_LEFT;
290 break; 289 break;
291 case 2: 290 case 2:
292 text_flags |= gfx::Canvas::TEXT_ALIGN_CENTER; 291 text_flags |= gfx::Canvas::TEXT_ALIGN_CENTER;
293 break; 292 break;
294 case 3: 293 case 3:
295 text_flags |= gfx::Canvas::TEXT_ALIGN_RIGHT; 294 text_flags |= gfx::Canvas::TEXT_ALIGN_RIGHT;
296 break; 295 break;
297 } 296 }
298 } else if (combo_box == v_align_cb_) { 297 } else if (combobox == v_align_cb_) {
299 text_flags &= ~(gfx::Canvas::TEXT_VALIGN_TOP | 298 text_flags &= ~(gfx::Canvas::TEXT_VALIGN_TOP |
300 gfx::Canvas::TEXT_VALIGN_MIDDLE | 299 gfx::Canvas::TEXT_VALIGN_MIDDLE |
301 gfx::Canvas::TEXT_VALIGN_BOTTOM); 300 gfx::Canvas::TEXT_VALIGN_BOTTOM);
302 switch (new_index) { 301 switch (combobox->selected_index()) {
303 case 0: 302 case 0:
304 break; 303 break;
305 case 1: 304 case 1:
306 text_flags |= gfx::Canvas::TEXT_VALIGN_TOP; 305 text_flags |= gfx::Canvas::TEXT_VALIGN_TOP;
307 break; 306 break;
308 case 2: 307 case 2:
309 text_flags |= gfx::Canvas::TEXT_VALIGN_MIDDLE; 308 text_flags |= gfx::Canvas::TEXT_VALIGN_MIDDLE;
310 break; 309 break;
311 case 3: 310 case 3:
312 text_flags |= gfx::Canvas::TEXT_VALIGN_BOTTOM; 311 text_flags |= gfx::Canvas::TEXT_VALIGN_BOTTOM;
313 break; 312 break;
314 } 313 }
315 } else if (combo_box == text_cb_) { 314 } else if (combobox == text_cb_) {
316 switch (new_index) { 315 switch (combobox->selected_index()) {
317 case 0: 316 case 0:
318 text_view_->set_text(ASCIIToUTF16(kShortText)); 317 text_view_->set_text(ASCIIToUTF16(kShortText));
319 break; 318 break;
320 case 1: 319 case 1:
321 text_view_->set_text(ASCIIToUTF16(kMediumText)); 320 text_view_->set_text(ASCIIToUTF16(kMediumText));
322 break; 321 break;
323 case 2: 322 case 2:
324 text_view_->set_text(ASCIIToUTF16(kLongText)); 323 text_view_->set_text(ASCIIToUTF16(kLongText));
325 break; 324 break;
326 case 3: 325 case 3:
327 text_view_->set_text(ASCIIToUTF16(kAmpersandText)); 326 text_view_->set_text(ASCIIToUTF16(kAmpersandText));
328 break; 327 break;
329 case 4: 328 case 4:
330 text_view_->set_text(ASCIIToUTF16(kNewlineText)); 329 text_view_->set_text(ASCIIToUTF16(kNewlineText));
331 break; 330 break;
332 } 331 }
333 } else if (combo_box == eliding_cb_) { 332 } else if (combobox == eliding_cb_) {
334 switch (new_index) { 333 switch (combobox->selected_index()) {
335 case 0: 334 case 0:
336 text_flags &= ~gfx::Canvas::NO_ELLIPSIS; 335 text_flags &= ~gfx::Canvas::NO_ELLIPSIS;
337 text_view_->set_fade(false); 336 text_view_->set_fade(false);
338 break; 337 break;
339 case 1: 338 case 1:
340 text_flags |= gfx::Canvas::NO_ELLIPSIS; 339 text_flags |= gfx::Canvas::NO_ELLIPSIS;
341 text_view_->set_fade(false); 340 text_view_->set_fade(false);
342 break; 341 break;
343 #if defined(OS_WIN) 342 #if defined(OS_WIN)
344 case 2: 343 case 2:
345 text_view_->set_fade_mode(gfx::Canvas::TruncateFadeTail); 344 text_view_->set_fade_mode(gfx::Canvas::TruncateFadeTail);
346 text_view_->set_fade(true); 345 text_view_->set_fade(true);
347 break; 346 break;
348 case 3: 347 case 3:
349 text_view_->set_fade_mode(gfx::Canvas::TruncateFadeHead); 348 text_view_->set_fade_mode(gfx::Canvas::TruncateFadeHead);
350 text_view_->set_fade(true); 349 text_view_->set_fade(true);
351 break; 350 break;
352 case 4: 351 case 4:
353 text_view_->set_fade_mode(gfx::Canvas::TruncateFadeHeadAndTail); 352 text_view_->set_fade_mode(gfx::Canvas::TruncateFadeHeadAndTail);
354 text_view_->set_fade(true); 353 text_view_->set_fade(true);
355 break; 354 break;
356 #endif 355 #endif
357 } 356 }
358 } else if (combo_box == prefix_cb_) { 357 } else if (combobox == prefix_cb_) {
359 text_flags &= ~(gfx::Canvas::SHOW_PREFIX | gfx::Canvas::HIDE_PREFIX); 358 text_flags &= ~(gfx::Canvas::SHOW_PREFIX | gfx::Canvas::HIDE_PREFIX);
360 switch (new_index) { 359 switch (combobox->selected_index()) {
361 case 0: 360 case 0:
362 break; 361 break;
363 case 1: 362 case 1:
364 text_flags |= gfx::Canvas::SHOW_PREFIX; 363 text_flags |= gfx::Canvas::SHOW_PREFIX;
365 break; 364 break;
366 case 2: 365 case 2:
367 text_flags |= gfx::Canvas::HIDE_PREFIX; 366 text_flags |= gfx::Canvas::HIDE_PREFIX;
368 break; 367 break;
369 } 368 }
370 } 369 }
371 text_view_->set_text_flags(text_flags); 370 text_view_->set_text_flags(text_flags);
372 text_view_->SchedulePaint(); 371 text_view_->SchedulePaint();
373 } 372 }
374 373
375 } // namespace examples 374 } // namespace examples
376 } // namespace views 375 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/examples/text_example.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698