* The L-shaped "enter" key can now also be drawn almost right (uses

BControlLook plus some clipping to do its magic).
* Fixed scancode only mode of the keyboard layout view.
* Fixed filter thanks to Rene.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29712 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-03-25 22:25:07 +00:00
parent c31467186f
commit a869d32e0c
4 changed files with 70 additions and 32 deletions
+63 -28
View File
@@ -9,6 +9,7 @@
#include <Bitmap.h> #include <Bitmap.h>
#include <ControlLook.h> #include <ControlLook.h>
#include <LayoutUtils.h> #include <LayoutUtils.h>
#include <Region.h>
#include <Window.h> #include <Window.h>
#include "Keymap.h" #include "Keymap.h"
@@ -145,8 +146,7 @@ KeyboardLayoutView::MouseUp(BPoint point)
if (key != NULL) { if (key != NULL) {
fKeyState[key->code / 8] &= ~(1 << (7 - (key->code & 7))); fKeyState[key->code / 8] &= ~(1 << (7 - (key->code & 7)));
if (fKeymap != NULL && _HandleDeadKey(key->code, fModifiers) if (_HandleDeadKey(key->code, fModifiers) && fDeadKey != 0)
&& fDeadKey != 0)
return; return;
_InvalidateKey(key); _InvalidateKey(key);
@@ -376,6 +376,17 @@ KeyboardLayoutView::_LayoutKeyboard()
} }
void
KeyboardLayoutView::_DrawKeyButton(BView* view, BRect rect, BRect updateRect,
rgb_color base, bool pressed)
{
be_control_look->DrawButtonFrame(view, rect, updateRect, base,
pressed ? BControlLook::B_ACTIVATED : 0);
be_control_look->DrawButtonBackground(view, rect, updateRect,
base, pressed ? BControlLook::B_ACTIVATED : 0);
}
void void
KeyboardLayoutView::_DrawKey(BView* view, BRect updateRect, const Key* key, KeyboardLayoutView::_DrawKey(BView* view, BRect updateRect, const Key* key,
BRect rect, bool pressed) BRect rect, bool pressed)
@@ -383,7 +394,7 @@ KeyboardLayoutView::_DrawKey(BView* view, BRect updateRect, const Key* key,
rgb_color base = key->dark ? kDarkColor : kBrightColor; rgb_color base = key->dark ? kDarkColor : kBrightColor;
key_kind keyKind = kNormalKey; key_kind keyKind = kNormalKey;
int32 deadKey = 0; int32 deadKey = 0;
bool secondDeadKey; bool secondDeadKey = false;
char text[32]; char text[32];
if (fKeymap != NULL) { if (fKeymap != NULL) {
@@ -404,31 +415,52 @@ KeyboardLayoutView::_DrawKey(BView* view, BRect updateRect, const Key* key,
base = kDeadKeyColor; base = kDeadKeyColor;
if (key->shape == kRectangleKeyShape) { if (key->shape == kRectangleKeyShape) {
be_control_look->DrawButtonFrame(view, rect, updateRect, base, _DrawKeyButton(view, rect, updateRect, base, pressed);
pressed ? BControlLook::B_ACTIVATED : 0);
be_control_look->DrawButtonBackground(view, rect, updateRect,
base, pressed ? BControlLook::B_ACTIVATED : 0);
// TODO: make font size depend on key size!
rect.InsetBy(1, 1); rect.InsetBy(1, 1);
be_control_look->DrawLabel(view, text, rect, updateRect, be_control_look->DrawLabel(view, text, rect, updateRect,
base, 0, BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE)); base, 0, BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE));
} else if (key->shape == kEnterKeyShape) { } else if (key->shape == kEnterKeyShape) {
// TODO: make better! BRegion region(rect);
rect.bottom -= 20; BRect originalRect = rect;
be_control_look->DrawButtonBackground(view, rect, updateRect, BRect missingRect = rect;
base, 0, BControlLook::B_LEFT_BORDER // TODO: for some reason, this does not always equal the bottom of
| BControlLook::B_RIGHT_BORDER // the other keys...
| BControlLook::B_TOP_BORDER); missingRect.top = floorf(rect.bottom - fGap + 2
- fLayout->DefaultKeySize().height * fFactor);
missingRect.right = floorf(missingRect.left
+ (key->frame.Width() - key->second_row) * fFactor - fGap - 2);
region.Exclude(missingRect);
ConstrainClippingRegion(&region);
rect = _FrameFor(key); _DrawKeyButton(view, rect, updateRect, base, pressed);
rect.top += 20;
rect.left += 10; rect.left = missingRect.right;
be_control_look->DrawButtonBackground(view, rect, updateRect, be_control_look->DrawLabel(view, text, rect, updateRect,
base, 0, BControlLook::B_LEFT_BORDER base, 0, BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE));
| BControlLook::B_RIGHT_BORDER
| BControlLook::B_BOTTOM_BORDER); missingRect.right--;
missingRect.top -= 2;
region.Set(missingRect);
ConstrainClippingRegion(&region);
rect = originalRect;
rect.bottom = missingRect.top + 2;
_DrawKeyButton(view, rect, updateRect, base, pressed);
missingRect.left = missingRect.right;
missingRect.right++;
missingRect.top += 2;
region.Set(missingRect);
ConstrainClippingRegion(&region);
rect = originalRect;
rect.left = missingRect.right - 2;
rect.top = missingRect.top - 2;
_DrawKeyButton(view, rect, updateRect, base, pressed);
ConstrainClippingRegion(NULL);
} }
} }
@@ -620,13 +652,15 @@ KeyboardLayoutView::_InvalidateKey(const Key* key)
/*! Updates the fDeadKey member, and invalidates the view if needed. /*! Updates the fDeadKey member, and invalidates the view if needed.
fKeymap must be valid when calling this method.
\return true if the view has been invalidated. \return true if the view has been invalidated.
*/ */
bool bool
KeyboardLayoutView::_HandleDeadKey(int32 key, int32 modifiers) KeyboardLayoutView::_HandleDeadKey(int32 key, int32 modifiers)
{ {
if (fKeymap == NULL)
return false;
int32 deadKey = fKeymap->IsDeadKey(key, modifiers); int32 deadKey = fKeymap->IsDeadKey(key, modifiers);
if (fDeadKey != deadKey) { if (fDeadKey != deadKey) {
Invalidate(); Invalidate();
@@ -660,6 +694,9 @@ KeyboardLayoutView::_KeyChanged(const BMessage* message)
if (message->what == B_KEY_DOWN || message->what == B_UNMAPPED_KEY_DOWN) { if (message->what == B_KEY_DOWN || message->what == B_UNMAPPED_KEY_DOWN) {
if (_HandleDeadKey(key, fModifiers)) if (_HandleDeadKey(key, fModifiers))
checkSingle = false; checkSingle = false;
if (_KeyForCode(key) == NULL)
printf("no key for code %ld\n", key);
} }
for (int32 i = 0; i < 16; i++) { for (int32 i = 0; i < 16; i++) {
@@ -709,12 +746,10 @@ BRect
KeyboardLayoutView::_FrameFor(BRect keyFrame) KeyboardLayoutView::_FrameFor(BRect keyFrame)
{ {
BRect rect; BRect rect;
rect.left = keyFrame.left * fFactor; rect.left = ceilf(keyFrame.left * fFactor);
rect.right = (keyFrame.right - keyFrame.left) * fFactor + rect.left rect.right = floorf((keyFrame.Width()) * fFactor + rect.left - fGap - 1);
- fGap - 1; rect.top = ceilf(keyFrame.top * fFactor);
rect.top = keyFrame.top * fFactor; rect.bottom = floorf((keyFrame.Height()) * fFactor + rect.top - fGap - 1);
rect.bottom = (keyFrame.bottom - keyFrame.top) * fFactor + rect.top
- fGap - 1;
rect.OffsetBy(fOffset); rect.OffsetBy(fOffset);
return rect; return rect;
@@ -51,6 +51,8 @@ private:
}; };
void _LayoutKeyboard(); void _LayoutKeyboard();
void _DrawKeyButton(BView* view, BRect rect,
BRect updateRect, rgb_color base, bool pressed);
void _DrawKey(BView* view, BRect updateRect, void _DrawKey(BView* view, BRect updateRect,
const Key* key, BRect frame, bool pressed); const Key* key, BRect frame, bool pressed);
const char* _SpecialKeyLabel(const key_map& map, uint32 code); const char* _SpecialKeyLabel(const key_map& map, uint32 code);
+3
View File
@@ -504,6 +504,9 @@ Keymap::_Offset(uint32 keyCode, uint32 modifiers, uint32* _table)
int32 offset; int32 offset;
uint32 table; uint32 table;
if (keyCode >= 128)
return -1;
switch (modifiers & kModifierKeys) { switch (modifiers & kModifierKeys) {
case B_SHIFT_KEY: case B_SHIFT_KEY:
offset = fKeys.shift_map[keyCode]; offset = fKeys.shift_map[keyCode];
+2 -4
View File
@@ -83,10 +83,8 @@ KeymapWindow::KeymapWindow()
fKeyboardLayoutView->SetTarget(fTextControl->TextView()); fKeyboardLayoutView->SetTarget(fTextControl->TextView());
fTextControl->MakeFocus(); fTextControl->MakeFocus();
AddCommonFilter(new KeymapMessageFilter(B_PROGRAMMED_DELIVERY, B_ANY_SOURCE, fTextControl->TextView()->AddFilter(new KeymapMessageFilter(
&fCurrentMap)); B_PROGRAMMED_DELIVERY, B_ANY_SOURCE, &fCurrentMap));
// TODO: this does not work for some reason, investigate!
// fTextControl->AddFilter(fTextFilter);
_UpdateButtons(); _UpdateButtons();