Ticket #4997: keyboard.patch

File keyboard.patch, 14.4 KB (added by mt, 14 years ago)

patch file

  • Keyboard.cpp

     
    1515
    1616#include <Alert.h>
    1717
     18#undef TR_CONTEXT
     19#define TR_CONTEXT "KeyboardApplication"
    1820
    1921KeyboardApplication::KeyboardApplication()
    2022    : BApplication("application/x-vnd.Haiku-Keyboard")
    2123{
     24    be_locale->GetAppCatalog(&fCatalog);
    2225    new KeyboardWindow();
    2326}
    2427
     
    2629void
    2730KeyboardApplication::MessageReceived(BMessage* message)
    2831{
    29     switch(message->what) {
     32    switch (message->what) {
    3033        case ERROR_DETECTED:
    3134        {
    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,
    3437                B_WARNING_ALERT);
    3538            errorAlert->Go();
    3639            be_app->PostMessage(B_QUIT_REQUESTED);
     
    4649void
    4750KeyboardApplication::AboutRequested()
    4851{
    49     (new BAlert("about", "Written by Andrew Edward McCall", "OK"))->Go();
     52    (new BAlert("about", TR("Written by Andrew Edward McCall"), TR("OK")))->Go();
    5053}
    5154
    5255
  • KeyboardView.h

     
    1111#define KEYBOARD_VIEW_H
    1212
    1313
    14 #include <Box.h>
     14#include <GroupView.h>
    1515#include <Slider.h>
    1616#include <SupportDefs.h>
    1717#include <InterfaceDefs.h>
    1818#include <Application.h>
    1919
    20 class KeyboardView : public BView
     20
     21class KeyboardView : public BGroupView
    2122{
    2223public:
    23             KeyboardView(BRect frame);
     24    KeyboardView();
     25    virtual ~KeyboardView();
    2426    void    Draw(BRect frame);
    25     void    AttachedToWindow(void);
    26    
     27
    2728private:
    2829    BBitmap     *fIconBitmap;
    2930    BBitmap     *fClockBitmap;
    30     BBox        *fBox;
    3131    BSlider     *fDelaySlider;
    3232    BSlider     *fRepeatSlider;
    3333};
  • Keyboard.h

     
    1111#define KEYBOARD_H
    1212
    1313#include <Application.h>
     14#include <Catalog.h>
     15#include <Locale.h>
    1416
    1517class KeyboardApplication : public BApplication
    1618{
    1719public:
    18             KeyboardApplication();
     20    KeyboardApplication();
    1921   
    20     void    MessageReceived(BMessage *message);
     22    void    MessageReceived(BMessage* message);
    2123    void    AboutRequested(void);
     24   
     25private:
     26    BCatalog fCatalog;
    2227};
    2328
    2429#endif
  • Jamfile

     
    1414    KeyboardSettings.cpp
    1515    KeyboardView.cpp
    1616    KeyboardWindow.cpp
    17     : translation be $(TARGET_LIBSUPC++)
     17    : translation be $(TARGET_LIBSUPC++) liblocale.so
    1818    : Keyboard.rdef
    1919    ;
     20
     21DoCatalogs Keyboard :
     22    x-vnd.Haiku-Keyboard
     23    :
     24    Keyboard.cpp
     25    KeyboardWindow.cpp
     26    KeyboardView.cpp
     27    : en.catalog
     28    ;
  • KeyboardWindow.cpp

     
    1313#include "KeyboardView.h"
    1414#include "KeyboardWindow.h"
    1515
     16#include <Box.h>
    1617#include <Button.h>
     18#include <Catalog.h>
     19#include <GroupLayout.h>
     20#include <GroupLayoutBuilder.h>
     21#include <Locale.h>
    1722#include <Message.h>
    1823#include <Screen.h>
    1924#include <Slider.h>
    2025#include <TextControl.h>
    2126
     27#undef TR_CONTEXT
     28#define TR_CONTEXT "KeyboardWindow"
    2229
    2330KeyboardWindow::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)
    2634{
    2735    MoveTo(fSettings.WindowCorner());
    2836
    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    );
    3661
    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");
    4163    if (slider !=NULL)
    4264        slider->SetValue(fSettings.KeyboardRepeatRate());
    4365
    44     slider = (BSlider *)FindView("delay_until_key_repeat");
     66    slider = (BSlider* )FindView("delay_until_key_repeat");
    4567    if (slider !=NULL)
    4668        slider->SetValue(fSettings.KeyboardRepeatDelay());
    4769
    48     BButton *button = (BButton *)FindView("keyboard_defaults");
    49     if (button !=NULL)
    50         button->SetEnabled(fSettings.IsDefaultable());
     70    fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
    5171
     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
    5279#ifdef DEBUG
    5380    fSettings.Dump();
    5481#endif
     
    75102KeyboardWindow::MessageReceived(BMessage* message)
    76103{
    77104    BSlider* slider = NULL;
    78     BButton* button = NULL;
    79105
    80106    switch (message->what) {
    81107        case BUTTON_DEFAULTS:
    82108        {
    83109            fSettings.Defaults();
    84110
    85             slider = (BSlider *)FindView("key_repeat_rate");
     111            slider = (BSlider* )FindView("key_repeat_rate");
    86112            if (slider !=NULL)
    87113                slider->SetValue(fSettings.KeyboardRepeatRate());
    88114
    89             slider = (BSlider *)FindView("delay_until_key_repeat");
     115            slider = (BSlider* )FindView("delay_until_key_repeat");
    90116            if (slider !=NULL)
    91117                slider->SetValue(fSettings.KeyboardRepeatDelay());
    92118
    93             button = (BButton *)FindView("keyboard_defaults");
    94             if (button !=NULL)
    95                 button->SetEnabled(false);
     119            fDefaultsButton->SetEnabled(false);
    96120
    97             button = (BButton *)FindView("keyboard_revert");
    98             if (button !=NULL)
    99                 button->SetEnabled(true);
     121            fRevertButton->SetEnabled(true);
    100122            break;
    101123        }
    102124        case BUTTON_REVERT:
    103125        {
    104126            fSettings.Revert();
    105127           
    106             slider = (BSlider *)FindView("key_repeat_rate");
     128            slider = (BSlider* )FindView("key_repeat_rate");
    107129            if (slider !=NULL)
    108130                slider->SetValue(fSettings.KeyboardRepeatRate());
    109131
    110             slider = (BSlider *)FindView("delay_until_key_repeat");
     132            slider = (BSlider* )FindView("delay_until_key_repeat");
    111133            if (slider !=NULL)
    112134                slider->SetValue(fSettings.KeyboardRepeatDelay());
    113135
    114             button = (BButton *)FindView("keyboard_defaults");
    115             if (button !=NULL)
    116                 button->SetEnabled(fSettings.IsDefaultable());
     136            fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
    117137
    118             button = (BButton *)FindView("keyboard_revert");
    119             if (button !=NULL)
    120                 button->SetEnabled(false);
     138            fRevertButton->SetEnabled(false);
    121139            break;
    122140        }
    123141        case SLIDER_REPEAT_RATE:
     
    127145                break;
    128146            fSettings.SetKeyboardRepeatRate(rate);
    129147
    130             button = (BButton *)FindView("keyboard_defaults");
    131             if (button !=NULL)
    132                 button->SetEnabled(fSettings.IsDefaultable());
     148            fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
    133149
    134             button = (BButton *)FindView("keyboard_revert");
    135             if (button !=NULL)
    136                 button->SetEnabled(true);
     150            fRevertButton->SetEnabled(true);
    137151            break;
    138152        }
    139153        case SLIDER_DELAY_RATE:
     
    154168            if (delay >= 875000)
    155169                delay = 1000000;
    156170
    157             fSettings.SetKeyboardRepeatDelay(delay);
    158 
    159             slider = (BSlider *)FindView("delay_until_key_repeat");
     171            slider = (BSlider* )FindView("delay_until_key_repeat");
    160172            if (slider !=NULL)
    161173                slider->SetValue(delay);
    162174
    163             button = (BButton *)FindView("keyboard_defaults");
    164             if (button !=NULL)
    165                 button->SetEnabled(fSettings.IsDefaultable());
     175            fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
    166176
    167             button = (BButton *)FindView("keyboard_revert");
    168             if (button !=NULL)
    169                 button->SetEnabled(true);
     177            fRevertButton->SetEnabled(true);
    170178            break;
    171179        }
    172180
  • KeyboardView.cpp

     
    1111#include <TranslationUtils.h>
    1212#include <Bitmap.h>
    1313#include <Button.h>
     14#include <Catalog.h>
     15#include <GroupLayout.h>
     16#include <GroupLayoutBuilder.h>
     17#include <Locale.h>
    1418#include <Slider.h>
    1519#include <TextControl.h>
    1620#include <Window.h>
    17 #include <Font.h>
    1821
    1922#include "KeyboardView.h"
    2023#include "KeyboardMessages.h"
     24#include "KeyboardSettings.h"
    2125
    22 // user interface
    23 const uint32 kBorderSpace = 10;
    24 const uint32 kItemSpace = 7;
     26#undef TR_CONTEXT
     27#define TR_CONTEXT "KeyboardView"
    2528
    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    
     29KeyboardView::KeyboardView()
     30 :  BGroupView()
     31{   
    3432    fIconBitmap = BTranslationUtils::GetBitmap("key_bmap");
    3533    fClockBitmap = BTranslationUtils::GetBitmap("clock_bmap");
    3634
    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    
    4535    // 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);
    5240    fRepeatSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
    5341    fRepeatSlider->SetHashMarkCount(5);
    54     fRepeatSlider->SetLimitLabels("Slow","Fast");
     42    fRepeatSlider->SetLimitLabels(TR("Slow"),TR("Fast"));
    5543   
    5644   
    5745    // 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);
    6350    fDelaySlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
    6451    fDelaySlider->SetHashMarkCount(4);
    65     fDelaySlider->SetLimitLabels("Short","Long");
     52    fDelaySlider->SetLimitLabels(TR("Short"),TR("Long"));
    6653   
    6754    // 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));
    9364
    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    );
    11471}
    11572
     73
     74KeyboardView::~KeyboardView()
     75{
     76
     77}
     78
     79
    11680void
    11781KeyboardView::Draw(BRect updateFrame)
    11882{
     
    12286    if (fIconBitmap != NULL) {
    12387        pt.y = fRepeatSlider->Frame().bottom - 35
    12488            - fIconBitmap->Bounds().Height() / 3;
    125         fBox->DrawBitmap(fIconBitmap,pt);
     89        DrawBitmap(fIconBitmap, pt);
    12690    }
    12791
    12892    if (fClockBitmap != NULL) {
    12993        pt.y = fDelaySlider->Frame().bottom - 35
    13094            - fClockBitmap->Bounds().Height() / 3;
    131         fBox->DrawBitmap(fClockBitmap,pt);
     95        DrawBitmap(fClockBitmap, pt);
    13296    }
    13397}
    134 
    135 void
    136 KeyboardView::AttachedToWindow(void)
    137 {
    138     Window()->ResizeTo(Bounds().Width(), Bounds().Height());
    139 }
    140 
  • KeyboardWindow.h

     
    1010#ifndef KEYBOARD_WINDOW_H
    1111#define KEYBOARD_WINDOW_H
    1212
     13#include <Button.h>
    1314#include <Window.h>
    1415
    1516#include "KeyboardSettings.h"
     
    2122            KeyboardWindow();
    2223   
    2324    bool    QuitRequested();
    24     void    MessageReceived(BMessage *message);
     25    void    MessageReceived(BMessage* message);
    2526   
    2627private:
    27     KeyboardView        *fView;
     28    KeyboardView    *fSettingsView;
    2829    KeyboardSettings    fSettings;
     30    BButton     *fDefaultsButton;
     31    BButton     *fRevertButton;
    2932};
    3033
    3134#endif