185768872SFreeman Lou/*
285768872SFreeman Lou * Copyright 2009, Axel D��rfler, axeld@pinc-software.de.
385768872SFreeman Lou * Distributed under the terms of the MIT License.
485768872SFreeman Lou */
585768872SFreeman Lou#ifndef KEYBOARD_LAYOUT_VIEW_H
685768872SFreeman Lou#define KEYBOARD_LAYOUT_VIEW_H
785768872SFreeman Lou
885768872SFreeman Lou
9a9fd76aeSFreeman Lou#include <InputServerDevice.h>
1085768872SFreeman Lou#include <Messenger.h>
1185768872SFreeman Lou#include <View.h>
1285768872SFreeman Lou
1385768872SFreeman Lou#include "KeyboardLayout.h"
1485768872SFreeman Lou
1585768872SFreeman Lou
1685768872SFreeman Louclass Keymap;
1785768872SFreeman Lou
1885768872SFreeman Lou
1985768872SFreeman Louclass KeyboardLayoutView : public BView {
2085768872SFreeman Loupublic:
21a9fd76aeSFreeman Lou								KeyboardLayoutView(const char* name,
22a9fd76aeSFreeman Lou									BInputServerDevice* dev);
2385768872SFreeman Lou								~KeyboardLayoutView();
2485768872SFreeman Lou
2585768872SFreeman Lou			void				SetKeyboardLayout(KeyboardLayout* layout);
2685768872SFreeman Lou			void				SetKeymap(Keymap* keymap);
2785768872SFreeman Lou			void				SetTarget(BMessenger target);
2885768872SFreeman Lou
2985768872SFreeman Lou			KeyboardLayout*		GetKeyboardLayout() { return fLayout; }
3085768872SFreeman Lou
3185768872SFreeman Lou			void				SetBaseFont(const BFont& font);
3285768872SFreeman Lou
3385768872SFreeman Lou			void				SetEditable(bool editable);
3485768872SFreeman Lou
3585768872SFreeman Louprotected:
3685768872SFreeman Lou	virtual void				AttachedToWindow();
3785768872SFreeman Lou	virtual void				FrameResized(float width, float height);
3885768872SFreeman Lou	virtual BSize				MinSize();
3985768872SFreeman Lou
4085768872SFreeman Lou	virtual void				KeyDown(const char* bytes, int32 numBytes);
4185768872SFreeman Lou	virtual void				KeyUp(const char* bytes, int32 numBytes);
4285768872SFreeman Lou	virtual void				MouseDown(BPoint point);
4385768872SFreeman Lou	virtual void				MouseUp(BPoint point);
4485768872SFreeman Lou	virtual void				MouseMoved(BPoint point, uint32 transit,
4585768872SFreeman Lou									const BMessage* dragMessage);
4685768872SFreeman Lou
4785768872SFreeman Lou	virtual void				Draw(BRect updateRect);
4885768872SFreeman Lou	virtual void				MessageReceived(BMessage* message);
4985768872SFreeman Lou	virtual void				WindowActivated(bool active);
5085768872SFreeman Lou
5185768872SFreeman Louprivate:
5285768872SFreeman Lou			enum key_kind {
5385768872SFreeman Lou				kNormalKey,
5485768872SFreeman Lou				kSpecialKey,
5585768872SFreeman Lou				kSymbolKey,
5685768872SFreeman Lou				kIndicator
5785768872SFreeman Lou			};
5885768872SFreeman Lou
5985768872SFreeman Lou			void				_InitOffscreen();
6085768872SFreeman Lou			void				_LayoutKeyboard();
6185768872SFreeman Lou			void				_DrawKeyButton(BView* view, BRect& rect,
6285768872SFreeman Lou									BRect updateRect, rgb_color base,
6385768872SFreeman Lou									rgb_color background, bool pressed);
6485768872SFreeman Lou			void				_DrawKey(BView* view, BRect updateRect,
6585768872SFreeman Lou									const Key* key, BRect frame, bool pressed);
6685768872SFreeman Lou			void				_DrawIndicator(BView* view, BRect updateRect,
6785768872SFreeman Lou									const Indicator* indicator, BRect rect,
6885768872SFreeman Lou									bool lit);
6985768872SFreeman Lou			const char*			_SpecialKeyLabel(const key_map& map,
7085768872SFreeman Lou									uint32 code, bool abbreviated = false);
7185768872SFreeman Lou			const char*			_SpecialMappedKeySymbol(const char* bytes,
7285768872SFreeman Lou									size_t numBytes);
7385768872SFreeman Lou			const char*			_SpecialMappedKeyLabel(const char* bytes,
7485768872SFreeman Lou									size_t numBytes, bool abbreviated = false);
7585768872SFreeman Lou			bool				_FunctionKeyLabel(uint32 code, char* text,
7685768872SFreeman Lou									size_t textSize);
7785768872SFreeman Lou			void				_GetAbbreviatedKeyLabelIfNeeded(BView* view,
7885768872SFreeman Lou									BRect rect, const Key* key, char* text,
7985768872SFreeman Lou									size_t textSize);
8085768872SFreeman Lou			void				_GetKeyLabel(const Key* key, char* text,
8185768872SFreeman Lou									size_t textSize, key_kind& keyKind);
8285768872SFreeman Lou			bool				_IsKeyPressed(uint32 code);
8385768872SFreeman Lou			bool				_KeyState(uint32 code) const;
8485768872SFreeman Lou			void				_SetKeyState(uint32 code, bool pressed);
8585768872SFreeman Lou			Key*				_KeyForCode(uint32 code);
8685768872SFreeman Lou			void				_InvalidateKey(uint32 code);
8785768872SFreeman Lou			void				_InvalidateKey(const Key* key);
8885768872SFreeman Lou			bool				_HandleDeadKey(uint32 key, int32 modifiers);
8985768872SFreeman Lou			void				_KeyChanged(const BMessage* message);
9085768872SFreeman Lou			Key*				_KeyAt(BPoint point);
9185768872SFreeman Lou			BRect				_FrameFor(BRect keyFrame);
9285768872SFreeman Lou			BRect				_FrameFor(const Key* key);
9385768872SFreeman Lou			void				_SetFontSize(BView* view, key_kind keyKind);
9485768872SFreeman Lou			void				_EvaluateDropTarget(BPoint point);
95a9fd76aeSFreeman Lou			void				_SendKeyDown(const Key* key);
9667b3c677SFreeman Lou
9785768872SFreeman Lou			BBitmap*			fOffscreenBitmap;
9885768872SFreeman Lou			BView*				fOffscreenView;
9985768872SFreeman Lou
10085768872SFreeman Lou			KeyboardLayout*		fLayout;
10185768872SFreeman Lou			Keymap*				fKeymap;
10285768872SFreeman Lou			BMessenger			fTarget;
10385768872SFreeman Lou			bool				fEditable;
10485768872SFreeman Lou
10585768872SFreeman Lou			uint8				fKeyState[16];
10685768872SFreeman Lou			int32				fModifiers;
10785768872SFreeman Lou			int32				fDeadKey;
10885768872SFreeman Lou			int32				fButtons;
10985768872SFreeman Lou
11085768872SFreeman Lou			BPoint				fClickPoint;
11185768872SFreeman Lou			Key*				fDragKey;
11285768872SFreeman Lou			int32				fDragModifiers;
11385768872SFreeman Lou			Key*				fDropTarget;
11485768872SFreeman Lou			BPoint				fDropPoint;
11585768872SFreeman Lou
11685768872SFreeman Lou			BSize				fOldSize;
11785768872SFreeman Lou			BFont				fBaseFont;
11885768872SFreeman Lou			BFont				fSpecialFont;
11985768872SFreeman Lou			float				fBaseFontHeight;
12085768872SFreeman Lou			float				fBaseFontSize;
12185768872SFreeman Lou			BPoint				fOffset;
12285768872SFreeman Lou			float				fFactor;
12385768872SFreeman Lou			float				fGap;
124a9fd76aeSFreeman Lou
12567b3c677SFreeman Lou			BInputServerDevice*	fDevice;
12685768872SFreeman Lou};
12785768872SFreeman Lou
12885768872SFreeman Lou
12985768872SFreeman Lou#endif	// KEYBOARD_LAYOUT_VIEW_H
130