1/* 2 * Copyright 2008, Stephan A��mus <superstippi@gmx.de>. 3 * Copyright 2007, Ingo Weinhold <bonefish@cs.tu-berlin.de>. 4 * All rights reserved. Distributed under the terms of the MIT License. 5 */ 6 7#include "TextViewTest.h" 8 9#include <TextView.h> 10 11#include "CheckBox.h" 12#include "GroupView.h" 13#include "TestView.h" 14 15 16// messages 17enum { 18 MSG_UPDATE_INSETS = 'upin', 19 MSG_UPDATE_TEXT = 'uptx', 20 MSG_UPDATE_FONT = 'upfn', 21}; 22 23 24static const char* kNormalText = "Some text to get something on the screen.\n" 25 "There is even a line break to see that as well."; 26static const char* kAlternativeText = "This is some different Text to " 27 "check out what happens when the text changes."; 28 29 30TextViewTest::TextViewTest() 31 : Test("TextView", NULL), 32 33 fTextView(new BTextView("text view")), 34 35// fTextView(new BTextView(BRect(0, 0, 49, 49), "name", 36// BRect(0, 0, 49, 49), B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED 37// | B_SUPPORTS_LAYOUT)), 38 39 40 fUseInsetsCheckBox(NULL), 41 fTextCheckBox(NULL), 42 fFontCheckBox(NULL) 43{ 44 SetView(fTextView); 45 fTextView->SetText(kNormalText); 46} 47 48 49Test* 50TextViewTest::CreateTest() 51{ 52 return new TextViewTest; 53} 54 55 56void 57TextViewTest::ActivateTest(View* controls) 58{ 59 GroupView* group = new GroupView(B_VERTICAL); 60 group->SetFrame(controls->Bounds()); 61 group->SetSpacing(0, 4); 62 controls->AddChild(group); 63 64 // insets 65 fUseInsetsCheckBox = new LabeledCheckBox("Use text rect insets", 66 new BMessage(MSG_UPDATE_INSETS), this); 67 group->AddChild(fUseInsetsCheckBox); 68 69 // text 70 fTextCheckBox = new LabeledCheckBox("Use alternative text", 71 new BMessage(MSG_UPDATE_TEXT), this); 72 group->AddChild(fTextCheckBox); 73 74 // font 75 fFontCheckBox = new LabeledCheckBox("Use large font", 76 new BMessage(MSG_UPDATE_FONT), this); 77 group->AddChild(fFontCheckBox); 78 79 // glue 80 group->AddChild(new Glue()); 81} 82 83 84void 85TextViewTest::DectivateTest() 86{ 87} 88 89 90void 91TextViewTest::MessageReceived(BMessage* message) 92{ 93 switch (message->what) { 94 case MSG_UPDATE_INSETS: 95 _UpdateInsets(); 96 break; 97 case MSG_UPDATE_TEXT: 98 _UpdateText(); 99 break; 100 case MSG_UPDATE_FONT: 101 _UpdateFont(); 102 break; 103 default: 104 Test::MessageReceived(message); 105 break; 106 } 107} 108 109 110// #pragma mark - private 111 112 113void 114TextViewTest::_UpdateInsets() 115{ 116 if (fUseInsetsCheckBox == NULL) 117 return; 118 119 if (fUseInsetsCheckBox->IsSelected()) 120 fTextView->SetInsets(10, 10, 10, 10); 121 else 122 fTextView->SetInsets(0, 0, 0, 0); 123} 124 125 126void 127TextViewTest::_UpdateText() 128{ 129 if (fTextCheckBox == NULL) 130 return; 131 132 if (fTextCheckBox->IsSelected()) 133 fTextView->SetText(kAlternativeText); 134 else 135 fTextView->SetText(kNormalText); 136} 137 138 139void 140TextViewTest::_UpdateFont() 141{ 142 if (fFontCheckBox == NULL) 143 return; 144 145 BFont font(be_plain_font); 146 if (fFontCheckBox->IsSelected()) { 147 font.SetSize(ceilf(font.Size() * 1.5)); 148 fTextView->SetFontAndColor(&font); 149 } else { 150 fTextView->SetFontAndColor(&font); 151 } 152} 153 154 155 156