1 /* 2 * Copyright 2009, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef KEYBOARD_LAYOUT_VIEW_H 6 #define KEYBOARD_LAYOUT_VIEW_H 7 8 9 #include <Messenger.h> 10 #include <View.h> 11 12 #include "KeyboardLayout.h" 13 14 15 class Keymap; 16 17 18 class KeyboardLayoutView : public BView { 19 public: 20 KeyboardLayoutView(const char* name); 21 ~KeyboardLayoutView(); 22 23 void SetKeyboardLayout(KeyboardLayout* layout); 24 void SetKeymap(Keymap* keymap); 25 void SetTarget(BMessenger target); 26 27 KeyboardLayout* GetKeyboardLayout() { return fLayout; } 28 29 void SetBaseFont(const BFont& font); 30 31 void SetEditable(bool editable); 32 33 protected: 34 virtual void AttachedToWindow(); 35 virtual void FrameResized(float width, float height); 36 virtual BSize MinSize(); 37 38 virtual void KeyDown(const char* bytes, int32 numBytes); 39 virtual void KeyUp(const char* bytes, int32 numBytes); 40 virtual void MouseDown(BPoint point); 41 virtual void MouseUp(BPoint point); 42 virtual void MouseMoved(BPoint point, uint32 transit, 43 const BMessage* dragMessage); 44 45 virtual void Draw(BRect updateRect); 46 virtual void MessageReceived(BMessage* message); 47 virtual void WindowActivated(bool active); 48 49 private: 50 enum key_kind { 51 kNormalKey, 52 kSpecialKey, 53 kSymbolKey, 54 kIndicator 55 }; 56 57 void _InitOffscreen(); 58 void _LayoutKeyboard(); 59 void _DrawKeyButton(BView* view, BRect& rect, 60 BRect updateRect, rgb_color base, 61 rgb_color background, bool pressed); 62 void _DrawKey(BView* view, BRect updateRect, 63 const Key* key, BRect frame, bool pressed); 64 void _DrawIndicator(BView* view, BRect updateRect, 65 const Indicator* indicator, BRect rect, 66 bool lit); 67 const char* _SpecialKeyLabel(const key_map& map, 68 uint32 code, bool abbreviated = false); 69 const char* _SpecialMappedKeySymbol(const char* bytes, 70 size_t numBytes); 71 const char* _SpecialMappedKeyLabel(const char* bytes, 72 size_t numBytes, bool abbreviated = false); 73 bool _FunctionKeyLabel(uint32 code, char* text, 74 size_t textSize); 75 void _GetAbbreviatedKeyLabelIfNeeded(BView* view, 76 BRect rect, const Key* key, char* text, 77 size_t textSize); 78 void _GetKeyLabel(const Key* key, char* text, 79 size_t textSize, key_kind& keyKind); 80 bool _IsKeyPressed(uint32 code); 81 bool _KeyState(uint32 code) const; 82 void _SetKeyState(uint32 code, bool pressed); 83 Key* _KeyForCode(uint32 code); 84 void _InvalidateKey(uint32 code); 85 void _InvalidateKey(const Key* key); 86 bool _HandleDeadKey(uint32 key, int32 modifiers); 87 void _KeyChanged(const BMessage* message); 88 Key* _KeyAt(BPoint point); 89 BRect _FrameFor(BRect keyFrame); 90 BRect _FrameFor(const Key* key); 91 void _SetFontSize(BView* view, key_kind keyKind); 92 void _EvaluateDropTarget(BPoint point); 93 void _SendFakeKeyDown(const Key* key); 94 95 BBitmap* fOffscreenBitmap; 96 BView* fOffscreenView; 97 98 KeyboardLayout* fLayout; 99 Keymap* fKeymap; 100 BMessenger fTarget; 101 bool fEditable; 102 103 uint8 fKeyState[16]; 104 int32 fModifiers; 105 int32 fDeadKey; 106 int32 fButtons; 107 108 BPoint fClickPoint; 109 Key* fDragKey; 110 int32 fDragModifiers; 111 Key* fDropTarget; 112 BPoint fDropPoint; 113 114 BSize fOldSize; 115 BFont fBaseFont; 116 BFont fSpecialFont; 117 float fBaseFontHeight; 118 float fBaseFontSize; 119 BPoint fOffset; 120 float fFactor; 121 float fGap; 122 }; 123 124 125 #endif // KEYBOARD_LAYOUT_VIEW_H 126