xref: /haiku/src/preferences/input/KeyboardView.cpp (revision 21258e2674226d6aa732321b6f8494841895af5f)
1 /*
2  * Copyright 2004-2006, the Haiku project. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors in chronological order:
6  *  mccall@digitalparadise.co.uk
7  *  Jérôme Duval
8  *  Marcus Overhagen
9 */
10 
11 
12 #include "KeyboardView.h"
13 
14 #include <InterfaceDefs.h>
15 #include <Bitmap.h>
16 #include <Button.h>
17 #include <Catalog.h>
18 #include <LayoutBuilder.h>
19 #include <Locale.h>
20 #include <Slider.h>
21 #include <TextControl.h>
22 #include <Window.h>
23 
24 #include "InputConstants.h"
25 #include "KeyboardSettings.h"
26 
27 #undef B_TRANSLATION_CONTEXT
28 #define B_TRANSLATION_CONTEXT "KeyboardView"
29 
30 KeyboardView::KeyboardView()
31  :	BGroupView()
32 {
33 	// Create the "Key repeat rate" slider...
34 	fRepeatSlider = new BSlider("key_repeat_rate",
35 						B_TRANSLATE("Key repeat rate"),
36 						new BMessage(kMsgSliderrepeatrate),
37 						20, 300, B_HORIZONTAL);
38 	fRepeatSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
39 	fRepeatSlider->SetHashMarkCount(5);
40 	fRepeatSlider->SetLimitLabels(B_TRANSLATE("Slow"),B_TRANSLATE("Fast"));
41 	fRepeatSlider->SetExplicitMinSize(BSize(200, B_SIZE_UNSET));
42 
43 
44 	// Create the "Delay until key repeat" slider...
45 	fDelaySlider = new BSlider("delay_until_key_repeat",
46 						B_TRANSLATE("Delay until key repeat"),
47 						new BMessage(kMsgSliderdelayrate),
48 						250000, 1000000, B_HORIZONTAL);
49 	fDelaySlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
50 	fDelaySlider->SetHashMarkCount(4);
51 	fDelaySlider->SetLimitLabels(B_TRANSLATE("Short"),B_TRANSLATE("Long"));
52 
53 	// Create the "Typing test area" text box...
54 	BTextControl* textcontrol = new BTextControl(NULL,
55 									B_TRANSLATE("Typing test area"),
56 									new BMessage('TTEA'));
57 	textcontrol->SetAlignment(B_ALIGN_LEFT, B_ALIGN_CENTER);
58 	textcontrol->SetExplicitMinSize(BSize(
59 		textcontrol->StringWidth(B_TRANSLATE("Typing test area")), B_SIZE_UNSET));
60 
61 	// Build the layout
62 	BLayoutBuilder::Group<>(this, B_VERTICAL, B_USE_DEFAULT_SPACING)
63 		.Add(fRepeatSlider)
64 		.Add(fDelaySlider)
65 		.Add(textcontrol)
66 		.AddGlue();
67 }
68 
69 
70 KeyboardView::~KeyboardView()
71 {
72 
73 }
74 
75 
76 void
77 KeyboardView::Draw(BRect updateFrame)
78 {
79 	BPoint pt;
80 	pt.x = fRepeatSlider->Frame().right + 10;
81 
82 	if (fIconBitmap != NULL) {
83 		pt.y = fRepeatSlider->Frame().bottom - 35
84 			- fIconBitmap->Bounds().Height() / 3;
85 		DrawBitmap(fIconBitmap, pt);
86 	}
87 
88 	if (fClockBitmap != NULL) {
89 		pt.y = fDelaySlider->Frame().bottom - 35
90 			- fClockBitmap->Bounds().Height() / 3;
91 		DrawBitmap(fClockBitmap, pt);
92 	}
93 }
94