Ticket #4997: keyboard.patch
File keyboard.patch, 14.4 KB (added by , 15 years ago) |
---|
-
Keyboard.cpp
15 15 16 16 #include <Alert.h> 17 17 18 #undef TR_CONTEXT 19 #define TR_CONTEXT "KeyboardApplication" 18 20 19 21 KeyboardApplication::KeyboardApplication() 20 22 : BApplication("application/x-vnd.Haiku-Keyboard") 21 23 { 24 be_locale->GetAppCatalog(&fCatalog); 22 25 new KeyboardWindow(); 23 26 } 24 27 … … 26 29 void 27 30 KeyboardApplication::MessageReceived(BMessage* message) 28 31 { 29 switch (message->what) {32 switch (message->what) { 30 33 case ERROR_DETECTED: 31 34 { 32 BAlert *errorAlert = new BAlert("Error", "Something has gone wrong!",33 "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_OFFSET_SPACING,35 BAlert* errorAlert = new BAlert("Error", TR("Something has gone wrong!"), 36 TR("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_OFFSET_SPACING, 34 37 B_WARNING_ALERT); 35 38 errorAlert->Go(); 36 39 be_app->PostMessage(B_QUIT_REQUESTED); … … 46 49 void 47 50 KeyboardApplication::AboutRequested() 48 51 { 49 (new BAlert("about", "Written by Andrew Edward McCall", "OK"))->Go();52 (new BAlert("about", TR("Written by Andrew Edward McCall"), TR("OK")))->Go(); 50 53 } 51 54 52 55 -
KeyboardView.h
11 11 #define KEYBOARD_VIEW_H 12 12 13 13 14 #include < Box.h>14 #include <GroupView.h> 15 15 #include <Slider.h> 16 16 #include <SupportDefs.h> 17 17 #include <InterfaceDefs.h> 18 18 #include <Application.h> 19 19 20 class KeyboardView : public BView 20 21 class KeyboardView : public BGroupView 21 22 { 22 23 public: 23 KeyboardView(BRect frame); 24 KeyboardView(); 25 virtual ~KeyboardView(); 24 26 void Draw(BRect frame); 25 void AttachedToWindow(void); 26 27 27 28 private: 28 29 BBitmap *fIconBitmap; 29 30 BBitmap *fClockBitmap; 30 BBox *fBox;31 31 BSlider *fDelaySlider; 32 32 BSlider *fRepeatSlider; 33 33 }; -
Keyboard.h
11 11 #define KEYBOARD_H 12 12 13 13 #include <Application.h> 14 #include <Catalog.h> 15 #include <Locale.h> 14 16 15 17 class KeyboardApplication : public BApplication 16 18 { 17 19 public: 18 20 KeyboardApplication(); 19 21 20 void MessageReceived(BMessage *message);22 void MessageReceived(BMessage* message); 21 23 void AboutRequested(void); 24 25 private: 26 BCatalog fCatalog; 22 27 }; 23 28 24 29 #endif -
Jamfile
14 14 KeyboardSettings.cpp 15 15 KeyboardView.cpp 16 16 KeyboardWindow.cpp 17 : translation be $(TARGET_LIBSUPC++) 17 : translation be $(TARGET_LIBSUPC++) liblocale.so 18 18 : Keyboard.rdef 19 19 ; 20 21 DoCatalogs Keyboard : 22 x-vnd.Haiku-Keyboard 23 : 24 Keyboard.cpp 25 KeyboardWindow.cpp 26 KeyboardView.cpp 27 : en.catalog 28 ; -
KeyboardWindow.cpp
13 13 #include "KeyboardView.h" 14 14 #include "KeyboardWindow.h" 15 15 16 #include <Box.h> 16 17 #include <Button.h> 18 #include <Catalog.h> 19 #include <GroupLayout.h> 20 #include <GroupLayoutBuilder.h> 21 #include <Locale.h> 17 22 #include <Message.h> 18 23 #include <Screen.h> 19 24 #include <Slider.h> 20 25 #include <TextControl.h> 21 26 27 #undef TR_CONTEXT 28 #define TR_CONTEXT "KeyboardWindow" 22 29 23 30 KeyboardWindow::KeyboardWindow() 24 : BWindow(BRect(0, 0, 200, 200), "Keyboard", B_TITLED_WINDOW, 25 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS) 31 : BWindow(BRect(0, 0, 200, 200), TR("Keyboard"), B_TITLED_WINDOW, 32 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS 33 | B_AUTO_UPDATE_SIZE_LIMITS) 26 34 { 27 35 MoveTo(fSettings.WindowCorner()); 28 36 29 // center window if it would be off-screen 30 BScreen screen; 31 if (screen.Frame().right < Frame().right 32 || screen.Frame().bottom < Frame().bottom) { 33 MoveTo((screen.Frame().right - Bounds().right) / 2, 34 (screen.Frame().bottom - Bounds().bottom) / 2); 35 } 37 // Add the main settings view 38 fSettingsView = new KeyboardView(); 39 BBox* fSettingsBox = new BBox("keyboard_box"); 40 fSettingsBox->AddChild(fSettingsView); 41 42 // Add the "Default" button.. 43 fDefaultsButton = new BButton(TR("Defaults"), new BMessage(BUTTON_DEFAULTS)); 44 45 // Add the "Revert" button... 46 fRevertButton = new BButton(TR("Revert"), new BMessage(BUTTON_REVERT)); 47 fRevertButton->SetEnabled(false); 48 49 // Build the layout 50 SetLayout(new BGroupLayout(B_VERTICAL)); 51 52 AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) 53 .Add(fSettingsBox) 54 .AddGroup(B_HORIZONTAL, 7) 55 .Add(fDefaultsButton) 56 .Add(fRevertButton) 57 .AddGlue() 58 .End() 59 .SetInsets(10, 10, 10, 10) 60 ); 36 61 37 fView = new KeyboardView(Bounds()); 38 AddChild(fView); 39 40 BSlider *slider = (BSlider *)FindView("key_repeat_rate"); 62 BSlider* slider = (BSlider* )FindView("key_repeat_rate"); 41 63 if (slider !=NULL) 42 64 slider->SetValue(fSettings.KeyboardRepeatRate()); 43 65 44 slider = (BSlider *)FindView("delay_until_key_repeat");66 slider = (BSlider* )FindView("delay_until_key_repeat"); 45 67 if (slider !=NULL) 46 68 slider->SetValue(fSettings.KeyboardRepeatDelay()); 47 69 48 BButton *button = (BButton *)FindView("keyboard_defaults"); 49 if (button !=NULL) 50 button->SetEnabled(fSettings.IsDefaultable()); 70 fDefaultsButton->SetEnabled(fSettings.IsDefaultable()); 51 71 72 // center window if it would be off-screen 73 BScreen screen; 74 if (screen.Frame().right < Frame().right 75 || screen.Frame().bottom < Frame().bottom) { 76 CenterOnScreen(); 77 } 78 52 79 #ifdef DEBUG 53 80 fSettings.Dump(); 54 81 #endif … … 75 102 KeyboardWindow::MessageReceived(BMessage* message) 76 103 { 77 104 BSlider* slider = NULL; 78 BButton* button = NULL;79 105 80 106 switch (message->what) { 81 107 case BUTTON_DEFAULTS: 82 108 { 83 109 fSettings.Defaults(); 84 110 85 slider = (BSlider *)FindView("key_repeat_rate");111 slider = (BSlider* )FindView("key_repeat_rate"); 86 112 if (slider !=NULL) 87 113 slider->SetValue(fSettings.KeyboardRepeatRate()); 88 114 89 slider = (BSlider *)FindView("delay_until_key_repeat");115 slider = (BSlider* )FindView("delay_until_key_repeat"); 90 116 if (slider !=NULL) 91 117 slider->SetValue(fSettings.KeyboardRepeatDelay()); 92 118 93 button = (BButton *)FindView("keyboard_defaults"); 94 if (button !=NULL) 95 button->SetEnabled(false); 119 fDefaultsButton->SetEnabled(false); 96 120 97 button = (BButton *)FindView("keyboard_revert"); 98 if (button !=NULL) 99 button->SetEnabled(true); 121 fRevertButton->SetEnabled(true); 100 122 break; 101 123 } 102 124 case BUTTON_REVERT: 103 125 { 104 126 fSettings.Revert(); 105 127 106 slider = (BSlider *)FindView("key_repeat_rate");128 slider = (BSlider* )FindView("key_repeat_rate"); 107 129 if (slider !=NULL) 108 130 slider->SetValue(fSettings.KeyboardRepeatRate()); 109 131 110 slider = (BSlider *)FindView("delay_until_key_repeat");132 slider = (BSlider* )FindView("delay_until_key_repeat"); 111 133 if (slider !=NULL) 112 134 slider->SetValue(fSettings.KeyboardRepeatDelay()); 113 135 114 button = (BButton *)FindView("keyboard_defaults"); 115 if (button !=NULL) 116 button->SetEnabled(fSettings.IsDefaultable()); 136 fDefaultsButton->SetEnabled(fSettings.IsDefaultable()); 117 137 118 button = (BButton *)FindView("keyboard_revert"); 119 if (button !=NULL) 120 button->SetEnabled(false); 138 fRevertButton->SetEnabled(false); 121 139 break; 122 140 } 123 141 case SLIDER_REPEAT_RATE: … … 127 145 break; 128 146 fSettings.SetKeyboardRepeatRate(rate); 129 147 130 button = (BButton *)FindView("keyboard_defaults"); 131 if (button !=NULL) 132 button->SetEnabled(fSettings.IsDefaultable()); 148 fDefaultsButton->SetEnabled(fSettings.IsDefaultable()); 133 149 134 button = (BButton *)FindView("keyboard_revert"); 135 if (button !=NULL) 136 button->SetEnabled(true); 150 fRevertButton->SetEnabled(true); 137 151 break; 138 152 } 139 153 case SLIDER_DELAY_RATE: … … 154 168 if (delay >= 875000) 155 169 delay = 1000000; 156 170 157 fSettings.SetKeyboardRepeatDelay(delay); 158 159 slider = (BSlider *)FindView("delay_until_key_repeat"); 171 slider = (BSlider* )FindView("delay_until_key_repeat"); 160 172 if (slider !=NULL) 161 173 slider->SetValue(delay); 162 174 163 button = (BButton *)FindView("keyboard_defaults"); 164 if (button !=NULL) 165 button->SetEnabled(fSettings.IsDefaultable()); 175 fDefaultsButton->SetEnabled(fSettings.IsDefaultable()); 166 176 167 button = (BButton *)FindView("keyboard_revert"); 168 if (button !=NULL) 169 button->SetEnabled(true); 177 fRevertButton->SetEnabled(true); 170 178 break; 171 179 } 172 180 -
KeyboardView.cpp
11 11 #include <TranslationUtils.h> 12 12 #include <Bitmap.h> 13 13 #include <Button.h> 14 #include <Catalog.h> 15 #include <GroupLayout.h> 16 #include <GroupLayoutBuilder.h> 17 #include <Locale.h> 14 18 #include <Slider.h> 15 19 #include <TextControl.h> 16 20 #include <Window.h> 17 #include <Font.h>18 21 19 22 #include "KeyboardView.h" 20 23 #include "KeyboardMessages.h" 24 #include "KeyboardSettings.h" 21 25 22 // user interface 23 const uint32 kBorderSpace = 10; 24 const uint32 kItemSpace = 7; 26 #undef TR_CONTEXT 27 #define TR_CONTEXT "KeyboardView" 25 28 26 KeyboardView::KeyboardView(BRect rect) 27 : BView(rect, "keyboard_view", B_FOLLOW_LEFT | B_FOLLOW_TOP, 28 B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP) 29 { 30 BRect frame; 31 32 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 33 29 KeyboardView::KeyboardView() 30 : BGroupView() 31 { 34 32 fIconBitmap = BTranslationUtils::GetBitmap("key_bmap"); 35 33 fClockBitmap = BTranslationUtils::GetBitmap("clock_bmap"); 36 34 37 float labelwidth = StringWidth("Delay until key repeat")+20;38 39 font_height fontHeight;40 be_plain_font->GetHeight(&fontHeight);41 42 float labelheight = fontHeight.ascent + fontHeight.descent +43 fontHeight.leading;44 45 35 // Create the "Key repeat rate" slider... 46 frame.Set(kBorderSpace,kBorderSpace,kBorderSpace + labelwidth,kBorderSpace + (labelheight*2) + (kBorderSpace*2)); 47 fRepeatSlider = new BSlider(frame,"key_repeat_rate", 48 "Key repeat rate", 49 new BMessage(SLIDER_REPEAT_RATE), 50 20,300,B_BLOCK_THUMB, 51 B_FOLLOW_LEFT,B_WILL_DRAW); 36 fRepeatSlider = new BSlider("key_repeat_rate", 37 TR("Key repeat rate"), 38 new BMessage(SLIDER_REPEAT_RATE), 39 20, 300, B_HORIZONTAL); 52 40 fRepeatSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); 53 41 fRepeatSlider->SetHashMarkCount(5); 54 fRepeatSlider->SetLimitLabels( "Slow","Fast");42 fRepeatSlider->SetLimitLabels(TR("Slow"),TR("Fast")); 55 43 56 44 57 45 // Create the "Delay until key repeat" slider... 58 frame.OffsetBy(0,frame.Height() + kBorderSpace); 59 fDelaySlider = new BSlider(frame,"delay_until_key_repeat", 60 "Delay until key repeat", 61 new BMessage(SLIDER_DELAY_RATE),250000,1000000, 62 B_BLOCK_THUMB,B_FOLLOW_LEFT,B_WILL_DRAW); 46 fDelaySlider = new BSlider("delay_until_key_repeat", 47 TR("Delay until key repeat"), 48 new BMessage(SLIDER_DELAY_RATE), 49 250000, 1000000, B_HORIZONTAL); 63 50 fDelaySlider->SetHashMarks(B_HASH_MARKS_BOTTOM); 64 51 fDelaySlider->SetHashMarkCount(4); 65 fDelaySlider->SetLimitLabels( "Short","Long");52 fDelaySlider->SetLimitLabels(TR("Short"),TR("Long")); 66 53 67 54 // Create the "Typing test area" text box... 68 frame.OffsetBy(0,frame.Height() + 15); 69 frame.right = fDelaySlider->Frame().right + kBorderSpace 70 + (fIconBitmap != NULL ? fIconBitmap->Bounds().Width() : 0); 71 BTextControl *textcontrol = new BTextControl(frame,"typing_test_area",NULL, 72 "Typing test area", 73 new BMessage('TTEA'), 74 B_FOLLOW_LEFT,B_WILL_DRAW); 75 textcontrol->SetAlignment(B_ALIGN_LEFT,B_ALIGN_CENTER); 76 77 float width, height; 78 textcontrol->GetPreferredSize(&width, &height); 79 textcontrol->ResizeTo(frame.Width(),height); 80 81 // Create the box for the sliders... 82 frame.left = frame.top = kBorderSpace; 83 frame.right = frame.left + fDelaySlider->Frame().right + (kBorderSpace * 2) 84 + (fClockBitmap != NULL ? fClockBitmap->Bounds().Width() : 0); 85 frame.bottom = textcontrol->Frame().bottom + (kBorderSpace * 2); 86 fBox = new BBox(frame,"keyboard_box",B_FOLLOW_LEFT, B_WILL_DRAW, 87 B_FANCY_BORDER); 88 AddChild(fBox); 89 90 fBox->AddChild(fRepeatSlider); 91 fBox->AddChild(fDelaySlider); 92 fBox->AddChild(textcontrol); 55 BTextControl* textcontrol = new BTextControl(NULL, 56 TR("Typing test area"), 57 new BMessage('TTEA')); 58 textcontrol->SetAlignment(B_ALIGN_LEFT, B_ALIGN_CENTER); 59 textcontrol->SetExplicitMinSize(BSize( 60 textcontrol->StringWidth(TR("Typing test area")), B_SIZE_UNSET)); 61 62 // Build the layout 63 SetLayout(new BGroupLayout(B_HORIZONTAL)); 93 64 94 //Add the "Default" button.. 95 frame.left = kBorderSpace; 96 frame.top = fBox->Frame().bottom + kBorderSpace; 97 frame.right = frame.left + 1; 98 frame.bottom = frame.top + 1; 99 BButton *button = new BButton(frame,"keyboard_defaults","Defaults", 100 new BMessage(BUTTON_DEFAULTS)); 101 button->ResizeToPreferred(); 102 AddChild(button); 103 104 // Add the "Revert" button... 105 frame = button->Frame(); 106 frame.OffsetBy(frame.Width() + kItemSpace, 0); 107 button = new BButton(frame,"keyboard_revert","Revert", 108 new BMessage(BUTTON_REVERT)); 109 button->ResizeToPreferred(); 110 button->SetEnabled(false); 111 AddChild(button); 112 113 ResizeTo(fBox->Frame().right + kBorderSpace, button->Frame().bottom + kBorderSpace); 65 AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) 66 .Add(fRepeatSlider) 67 .Add(fDelaySlider) 68 .Add(textcontrol) 69 .SetInsets(10, 10, 10, 10) 70 ); 114 71 } 115 72 73 74 KeyboardView::~KeyboardView() 75 { 76 77 } 78 79 116 80 void 117 81 KeyboardView::Draw(BRect updateFrame) 118 82 { … … 122 86 if (fIconBitmap != NULL) { 123 87 pt.y = fRepeatSlider->Frame().bottom - 35 124 88 - fIconBitmap->Bounds().Height() / 3; 125 fBox->DrawBitmap(fIconBitmap,pt);89 DrawBitmap(fIconBitmap, pt); 126 90 } 127 91 128 92 if (fClockBitmap != NULL) { 129 93 pt.y = fDelaySlider->Frame().bottom - 35 130 94 - fClockBitmap->Bounds().Height() / 3; 131 fBox->DrawBitmap(fClockBitmap,pt);95 DrawBitmap(fClockBitmap, pt); 132 96 } 133 97 } 134 135 void136 KeyboardView::AttachedToWindow(void)137 {138 Window()->ResizeTo(Bounds().Width(), Bounds().Height());139 }140 -
KeyboardWindow.h
10 10 #ifndef KEYBOARD_WINDOW_H 11 11 #define KEYBOARD_WINDOW_H 12 12 13 #include <Button.h> 13 14 #include <Window.h> 14 15 15 16 #include "KeyboardSettings.h" … … 21 22 KeyboardWindow(); 22 23 23 24 bool QuitRequested(); 24 void MessageReceived(BMessage *message);25 void MessageReceived(BMessage* message); 25 26 26 27 private: 27 KeyboardView *fView;28 KeyboardView *fSettingsView; 28 29 KeyboardSettings fSettings; 30 BButton *fDefaultsButton; 31 BButton *fRevertButton; 29 32 }; 30 33 31 34 #endif