VirtualKeyboard: Fold KeyboardLayoutView back into the Keymap preferences one.
Only one #ifdef, the rest is all in basic if-tests. Relatively minimal changes, and now the virtual keyboard device gets all the improvements made to the keyboard layout view over the last 6 years.
This commit is contained in:
parent
ae61e1b716
commit
2aa85f5f78
@ -3,6 +3,8 @@ SubDir HAIKU_TOP src add-ons input_server devices virtualkeyboard ;
|
||||
UsePrivateHeaders input interface shared tracker ;
|
||||
UsePrivateSystemHeaders ;
|
||||
|
||||
SubDirC++Flags -DVIRTUAL_KEYBOARD_DEVICE ;
|
||||
|
||||
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src preferences keymap ] ;
|
||||
|
||||
AddResources <input>virtualkeyboard : VirtualKeyboard.rdef ;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef KEYBOARD_LAYOUT_VIEW_H
|
||||
#define KEYBOARD_LAYOUT_VIEW_H
|
||||
|
||||
|
||||
#include <InputServerDevice.h>
|
||||
#include <Messenger.h>
|
||||
#include <View.h>
|
||||
|
||||
#include "KeyboardLayout.h"
|
||||
|
||||
|
||||
class Keymap;
|
||||
|
||||
|
||||
class KeyboardLayoutView : public BView {
|
||||
public:
|
||||
KeyboardLayoutView(const char* name,
|
||||
BInputServerDevice* dev);
|
||||
~KeyboardLayoutView();
|
||||
|
||||
void SetKeyboardLayout(KeyboardLayout* layout);
|
||||
void SetKeymap(Keymap* keymap);
|
||||
void SetTarget(BMessenger target);
|
||||
|
||||
KeyboardLayout* GetKeyboardLayout() { return fLayout; }
|
||||
|
||||
void SetBaseFont(const BFont& font);
|
||||
|
||||
void SetEditable(bool editable);
|
||||
|
||||
protected:
|
||||
virtual void AttachedToWindow();
|
||||
virtual void FrameResized(float width, float height);
|
||||
virtual BSize MinSize();
|
||||
|
||||
virtual void KeyDown(const char* bytes, int32 numBytes);
|
||||
virtual void KeyUp(const char* bytes, int32 numBytes);
|
||||
virtual void MouseDown(BPoint point);
|
||||
virtual void MouseUp(BPoint point);
|
||||
virtual void MouseMoved(BPoint point, uint32 transit,
|
||||
const BMessage* dragMessage);
|
||||
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual void WindowActivated(bool active);
|
||||
|
||||
private:
|
||||
enum key_kind {
|
||||
kNormalKey,
|
||||
kSpecialKey,
|
||||
kSymbolKey,
|
||||
kIndicator
|
||||
};
|
||||
|
||||
void _InitOffscreen();
|
||||
void _LayoutKeyboard();
|
||||
void _DrawKeyButton(BView* view, BRect& rect,
|
||||
BRect updateRect, rgb_color base,
|
||||
rgb_color background, bool pressed);
|
||||
void _DrawKey(BView* view, BRect updateRect,
|
||||
const Key* key, BRect frame, bool pressed);
|
||||
void _DrawIndicator(BView* view, BRect updateRect,
|
||||
const Indicator* indicator, BRect rect,
|
||||
bool lit);
|
||||
const char* _SpecialKeyLabel(const key_map& map,
|
||||
uint32 code, bool abbreviated = false);
|
||||
const char* _SpecialMappedKeySymbol(const char* bytes,
|
||||
size_t numBytes);
|
||||
const char* _SpecialMappedKeyLabel(const char* bytes,
|
||||
size_t numBytes, bool abbreviated = false);
|
||||
bool _FunctionKeyLabel(uint32 code, char* text,
|
||||
size_t textSize);
|
||||
void _GetAbbreviatedKeyLabelIfNeeded(BView* view,
|
||||
BRect rect, const Key* key, char* text,
|
||||
size_t textSize);
|
||||
void _GetKeyLabel(const Key* key, char* text,
|
||||
size_t textSize, key_kind& keyKind);
|
||||
bool _IsKeyPressed(uint32 code);
|
||||
bool _KeyState(uint32 code) const;
|
||||
void _SetKeyState(uint32 code, bool pressed);
|
||||
Key* _KeyForCode(uint32 code);
|
||||
void _InvalidateKey(uint32 code);
|
||||
void _InvalidateKey(const Key* key);
|
||||
bool _HandleDeadKey(uint32 key, int32 modifiers);
|
||||
void _KeyChanged(const BMessage* message);
|
||||
Key* _KeyAt(BPoint point);
|
||||
BRect _FrameFor(BRect keyFrame);
|
||||
BRect _FrameFor(const Key* key);
|
||||
void _SetFontSize(BView* view, key_kind keyKind);
|
||||
void _EvaluateDropTarget(BPoint point);
|
||||
void _SendKeyDown(const Key* key);
|
||||
|
||||
BBitmap* fOffscreenBitmap;
|
||||
BView* fOffscreenView;
|
||||
|
||||
KeyboardLayout* fLayout;
|
||||
Keymap* fKeymap;
|
||||
BMessenger fTarget;
|
||||
bool fEditable;
|
||||
|
||||
uint8 fKeyState[16];
|
||||
int32 fModifiers;
|
||||
int32 fDeadKey;
|
||||
int32 fButtons;
|
||||
|
||||
BPoint fClickPoint;
|
||||
Key* fDragKey;
|
||||
int32 fDragModifiers;
|
||||
Key* fDropTarget;
|
||||
BPoint fDropPoint;
|
||||
|
||||
BSize fOldSize;
|
||||
BFont fBaseFont;
|
||||
BFont fSpecialFont;
|
||||
float fBaseFontHeight;
|
||||
float fBaseFontSize;
|
||||
BPoint fOffset;
|
||||
float fFactor;
|
||||
float fGap;
|
||||
|
||||
BInputServerDevice* fDevice;
|
||||
};
|
||||
|
||||
|
||||
#endif // KEYBOARD_LAYOUT_VIEW_H
|
@ -61,7 +61,6 @@ VirtualKeyboardWindow::VirtualKeyboardWindow(BInputServerDevice* dev)
|
||||
|
||||
fKeyboardView = new KeyboardLayoutView("Keyboard",fDevice);
|
||||
fKeyboardView->GetKeyboardLayout()->SetDefault();
|
||||
fKeyboardView->SetEditable(false);
|
||||
fKeyboardView->SetKeymap(&fCurrentKeymap);
|
||||
|
||||
AddChild(BGroupLayoutBuilder(B_VERTICAL)
|
||||
@ -130,7 +129,7 @@ VirtualKeyboardWindow::_LoadMaps()
|
||||
|
||||
if (directory.SetTo(path.Path()) == B_OK) {
|
||||
while (directory.GetNextRef(&ref) == B_OK) {
|
||||
fMapListView->AddItem(new KeymapListItem(ref));
|
||||
fMapListView->AddItem(new KeymapListItem(ref));
|
||||
}
|
||||
}
|
||||
fMapListView->SortItems(&compare_key_list_items);
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <Bitmap.h>
|
||||
#include <ControlLook.h>
|
||||
#include <LayoutUtils.h>
|
||||
#include <InputServerDevice.h>
|
||||
#include <MenuItem.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <Region.h>
|
||||
@ -80,17 +81,18 @@ is_mappable_to_modifier(uint32 keyCode)
|
||||
// #pragma mark - KeyboardLayoutView
|
||||
|
||||
|
||||
KeyboardLayoutView::KeyboardLayoutView(const char* name)
|
||||
KeyboardLayoutView::KeyboardLayoutView(const char* name, BInputServerDevice* dev)
|
||||
:
|
||||
BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS),
|
||||
fKeymap(NULL),
|
||||
fEditable(true),
|
||||
fEditable(dev == NULL),
|
||||
fModifiers(0),
|
||||
fDeadKey(0),
|
||||
fButtons(0),
|
||||
fDragKey(NULL),
|
||||
fDropTarget(NULL),
|
||||
fOldSize(0, 0)
|
||||
fOldSize(0, 0),
|
||||
fDevice(dev)
|
||||
{
|
||||
fLayout = new KeyboardLayout;
|
||||
memset(fKeyState, 0, sizeof(fKeyState));
|
||||
@ -210,7 +212,7 @@ KeyboardLayoutView::MouseDown(BPoint point)
|
||||
|| ((buttons & B_PRIMARY_MOUSE_BUTTON) != 0
|
||||
&& (modifiers() & B_CONTROL_KEY) != 0)) {
|
||||
// secondary mouse button, pop up a swap context menu
|
||||
if (!is_mappable_to_modifier(key->code)) {
|
||||
if (fEditable && !is_mappable_to_modifier(key->code)) {
|
||||
// ToDo: Pop up a list of alternative characters to map
|
||||
// the key to. Currently we only add an option to remove the
|
||||
// current key mapping.
|
||||
@ -224,7 +226,7 @@ KeyboardLayoutView::MouseDown(BPoint point)
|
||||
alternativesPopUp->SetAsyncAutoDestruct(true);
|
||||
if (alternativesPopUp->SetTargetForItems(Window()) == B_OK)
|
||||
alternativesPopUp->Go(ConvertToScreen(point), true);
|
||||
} else {
|
||||
} else if (fEditable) {
|
||||
// pop up the modifier keys menu
|
||||
BPopUpMenu* modifiersPopUp = new BPopUpMenu("Modifiers pop up",
|
||||
true, true, B_ITEMS_IN_COLUMN);
|
||||
@ -403,7 +405,7 @@ KeyboardLayoutView::MouseUp(BPoint point)
|
||||
_InvalidateKey(key);
|
||||
|
||||
if (fDragKey == NULL)
|
||||
_SendFakeKeyDown(key);
|
||||
_SendKeyDown(key);
|
||||
}
|
||||
|
||||
fDragKey = NULL;
|
||||
@ -417,6 +419,10 @@ KeyboardLayoutView::MouseMoved(BPoint point, uint32 transit,
|
||||
if (fKeymap == NULL)
|
||||
return;
|
||||
|
||||
// Ignore mouse-moved events if we are acting as a real input device.
|
||||
if (fDevice != NULL)
|
||||
return;
|
||||
|
||||
// prevent dragging for tertiary mouse button
|
||||
if ((fButtons & B_TERTIARY_MOUSE_BUTTON) != 0)
|
||||
return;
|
||||
@ -607,7 +613,7 @@ KeyboardLayoutView::MessageReceived(BMessage* message)
|
||||
}
|
||||
} else {
|
||||
// Send the old key to the target, so it's not lost entirely
|
||||
_SendFakeKeyDown(fDropTarget);
|
||||
_SendKeyDown(fDropTarget);
|
||||
|
||||
fKeymap->SetKey(fDropTarget->code, fModifiers, fDeadKey,
|
||||
(const char*)data, dataSize);
|
||||
@ -1290,7 +1296,7 @@ KeyboardLayoutView::_EvaluateDropTarget(BPoint point)
|
||||
|
||||
|
||||
void
|
||||
KeyboardLayoutView::_SendFakeKeyDown(const Key* key)
|
||||
KeyboardLayoutView::_SendKeyDown(const Key* key)
|
||||
{
|
||||
BMessage message(B_KEY_DOWN);
|
||||
message.AddInt64("when", system_time());
|
||||
@ -1298,7 +1304,10 @@ KeyboardLayoutView::_SendFakeKeyDown(const Key* key)
|
||||
sizeof(fKeyState));
|
||||
message.AddInt32("key", key->code);
|
||||
message.AddInt32("modifiers", fModifiers);
|
||||
message.AddPointer("keymap", fKeymap);
|
||||
message.AddInt32("be:key_repeat", 1);
|
||||
|
||||
if (fDevice == NULL)
|
||||
message.AddPointer("keymap", fKeymap);
|
||||
|
||||
char* string;
|
||||
int32 numBytes;
|
||||
@ -1316,7 +1325,15 @@ KeyboardLayoutView::_SendFakeKeyDown(const Key* key)
|
||||
delete[] string;
|
||||
}
|
||||
|
||||
fTarget.SendMessage(&message);
|
||||
if (fDevice == NULL) {
|
||||
fTarget.SendMessage(&message);
|
||||
} else {
|
||||
#if defined(VIRTUAL_KEYBOARD_DEVICE)
|
||||
BMessage* deviceMessage = new BMessage(message);
|
||||
if (fDevice->EnqueueMessage(deviceMessage) != B_OK)
|
||||
delete deviceMessage;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,13 +17,15 @@
|
||||
#include "KeyboardLayout.h"
|
||||
|
||||
|
||||
class BInputServerDevice;
|
||||
class BMenuItem;
|
||||
class Keymap;
|
||||
|
||||
|
||||
class KeyboardLayoutView : public BView {
|
||||
public:
|
||||
KeyboardLayoutView(const char* name);
|
||||
KeyboardLayoutView(const char* name,
|
||||
BInputServerDevice* dev = NULL);
|
||||
~KeyboardLayoutView();
|
||||
|
||||
void SetKeyboardLayout(KeyboardLayout* layout);
|
||||
@ -95,7 +97,7 @@ private:
|
||||
BRect _FrameFor(const Key* key);
|
||||
void _SetFontSize(BView* view, key_kind keyKind);
|
||||
void _EvaluateDropTarget(BPoint point);
|
||||
void _SendFakeKeyDown(const Key* key);
|
||||
void _SendKeyDown(const Key* key);
|
||||
|
||||
BMenuItem* _CreateSwapModifiersMenuItem(uint32 modifier,
|
||||
uint32 displayModifier, uint32 oldCode,
|
||||
@ -126,6 +128,8 @@ private:
|
||||
BPoint fOffset;
|
||||
float fFactor;
|
||||
float fGap;
|
||||
|
||||
BInputServerDevice* fDevice;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user