xref: /haiku/src/preferences/input/KeyboardView.cpp (revision caed67a8cba83913b9c21ac2b06ebc6bd1cb3111)
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 <Bitmap.h>
15 #include <Catalog.h>
16 #include <InterfaceDefs.h>
17 #include <LayoutBuilder.h>
18 #include <Locale.h>
19 #include <Slider.h>
20 #include <TextControl.h>
21 
22 #include "InputConstants.h"
23 
24 #undef B_TRANSLATION_CONTEXT
25 #define B_TRANSLATION_CONTEXT "KeyboardView"
26 
27 
28 KeyboardView::KeyboardView()
29 	:
30 	BGroupView()
31 {
32 	// Create the "Key repeat rate" slider...
33 	fRepeatSlider
34 		= new BSlider("key_repeat_rate", B_TRANSLATE("Key repeat rate"),
35 			new BMessage(kMsgSliderrepeatrate), 20, 300, B_HORIZONTAL);
36 	fRepeatSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
37 	fRepeatSlider->SetHashMarkCount(5);
38 	fRepeatSlider->SetLimitLabels(B_TRANSLATE("Slow"), B_TRANSLATE("Fast"));
39 	fRepeatSlider->SetExplicitMinSize(BSize(200, B_SIZE_UNSET));
40 
41 
42 	// Create the "Delay until key repeat" slider...
43 	fDelaySlider = new BSlider("delay_until_key_repeat",
44 		B_TRANSLATE("Delay until key repeat"),
45 		new BMessage(kMsgSliderdelayrate), 250000, 1000000, B_HORIZONTAL);
46 	fDelaySlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
47 	fDelaySlider->SetHashMarkCount(4);
48 	fDelaySlider->SetLimitLabels(B_TRANSLATE("Short"), B_TRANSLATE("Long"));
49 
50 	// Create the "Typing test area" text box...
51 	BTextControl* textcontrol = new BTextControl(
52 		NULL, B_TRANSLATE("Typing test area"), new BMessage('TTEA'));
53 	textcontrol->SetAlignment(B_ALIGN_LEFT, B_ALIGN_CENTER);
54 	textcontrol->SetExplicitMinSize(
55 		BSize(textcontrol->StringWidth(B_TRANSLATE("Typing test area")),
56 			B_SIZE_UNSET));
57 
58 	// Build the layout
59 	BLayoutBuilder::Group<>(this, B_VERTICAL, B_USE_DEFAULT_SPACING)
60 		.Add(fRepeatSlider)
61 		.Add(fDelaySlider)
62 		.Add(textcontrol)
63 		.AddGlue();
64 }
65 
66 
67 KeyboardView::~KeyboardView()
68 {
69 }
70 
71 
72 void
73 KeyboardView::Draw(BRect updateFrame)
74 {
75 	BPoint pt;
76 	pt.x = fRepeatSlider->Frame().right + 10;
77 
78 	if (fIconBitmap != NULL) {
79 		pt.y = fRepeatSlider->Frame().bottom - 35
80 			- fIconBitmap->Bounds().Height() / 3;
81 		DrawBitmap(fIconBitmap, pt);
82 	}
83 
84 	if (fClockBitmap != NULL) {
85 		pt.y = fDelaySlider->Frame().bottom - 35
86 			- fClockBitmap->Bounds().Height() / 3;
87 		DrawBitmap(fClockBitmap, pt);
88 	}
89 }
90