1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * VirtualBox Qt extensions: QIHotKeyEdit class declaration
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
19 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
20 | * additional information or have any questions.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #ifndef ___QIHotKeyEdit_h___
|
---|
24 | #define ___QIHotKeyEdit_h___
|
---|
25 |
|
---|
26 | #include <QLabel>
|
---|
27 | #if defined (Q_WS_X11)
|
---|
28 | #include <QMap>
|
---|
29 | #endif
|
---|
30 | #if defined (Q_WS_MAC)
|
---|
31 | # include <Carbon/Carbon.h>
|
---|
32 | /* Carbon.h includes AssertMacros.h which defines the macro "check". In
|
---|
33 | * QItemDelegate a class method is called check also. As we not used the macro
|
---|
34 | * undefine it here. */
|
---|
35 | # undef check
|
---|
36 | #endif
|
---|
37 |
|
---|
38 | #if defined (Q_WS_PM)
|
---|
39 | /* Extra virtual keys returned by QIHotKeyEdit::virtualKey() */
|
---|
40 | #define VK_LSHIFT VK_USERFIRST + 0
|
---|
41 | #define VK_LCTRL VK_USERFIRST + 1
|
---|
42 | #define VK_LWIN VK_USERFIRST + 2
|
---|
43 | #define VK_RWIN VK_USERFIRST + 3
|
---|
44 | #define VK_WINMENU VK_USERFIRST + 4
|
---|
45 | #define VK_FORWARD VK_USERFIRST + 5
|
---|
46 | #define VK_BACKWARD VK_USERFIRST + 6
|
---|
47 | #endif
|
---|
48 |
|
---|
49 | class QIHotKeyEdit : public QLabel
|
---|
50 | {
|
---|
51 | Q_OBJECT
|
---|
52 |
|
---|
53 | public:
|
---|
54 |
|
---|
55 | QIHotKeyEdit (QWidget *aParent);
|
---|
56 | virtual ~QIHotKeyEdit();
|
---|
57 |
|
---|
58 | void setKey (int aKeyVal);
|
---|
59 | int key() const { return mKeyVal; }
|
---|
60 |
|
---|
61 | QString symbolicName() const { return mSymbName; }
|
---|
62 |
|
---|
63 | QSize sizeHint() const;
|
---|
64 | QSize minimumSizeHint() const;
|
---|
65 |
|
---|
66 | #if defined (Q_WS_PM)
|
---|
67 | static int virtualKey (QMSG *aMsg);
|
---|
68 | #endif
|
---|
69 |
|
---|
70 | #if defined (Q_WS_PM) || defined (Q_WS_X11)
|
---|
71 | static void retranslateUi();
|
---|
72 | #endif
|
---|
73 | static QString keyName (int aKeyVal);
|
---|
74 | static bool isValidKey (int aKeyVal);
|
---|
75 |
|
---|
76 | public slots:
|
---|
77 |
|
---|
78 | void clear();
|
---|
79 |
|
---|
80 | protected:
|
---|
81 |
|
---|
82 | #if defined (Q_WS_WIN32)
|
---|
83 | bool winEvent (MSG *aMsg, long *aResult);
|
---|
84 | #elif defined (Q_WS_PM)
|
---|
85 | bool pmEvent (QMSG *aMsg);
|
---|
86 | #elif defined (Q_WS_X11)
|
---|
87 | bool x11Event (XEvent *event);
|
---|
88 | #elif defined (Q_WS_MAC)
|
---|
89 | # ifdef QT_MAC_USE_COCOA
|
---|
90 | static bool darwinEventHandlerProc (const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);
|
---|
91 | # else
|
---|
92 | static pascal OSStatus darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData);
|
---|
93 | # endif
|
---|
94 | bool darwinKeyboardEvent (const void *pvCocoaEvent, EventRef inEvent);
|
---|
95 | #endif
|
---|
96 |
|
---|
97 | void focusInEvent (QFocusEvent *);
|
---|
98 | void focusOutEvent (QFocusEvent *);
|
---|
99 |
|
---|
100 | void paintEvent (QPaintEvent *);
|
---|
101 |
|
---|
102 | private:
|
---|
103 |
|
---|
104 | void updateText();
|
---|
105 |
|
---|
106 | int mKeyVal;
|
---|
107 | QString mSymbName;
|
---|
108 |
|
---|
109 | #if defined (Q_WS_PM)
|
---|
110 | static QMap <int, QString> sKeyNames;
|
---|
111 | #elif defined (Q_WS_X11)
|
---|
112 | static QMap <QString, QString> sKeyNames;
|
---|
113 | #endif
|
---|
114 |
|
---|
115 | #if defined (Q_WS_MAC)
|
---|
116 | # ifndef QT_MAC_USE_COCOA
|
---|
117 | /** Event handler reference. NULL if the handler isn't installed. */
|
---|
118 | EventHandlerRef mDarwinEventHandlerRef;
|
---|
119 | # endif
|
---|
120 | /** The current modifier key mask. Used to figure out which modifier
|
---|
121 | * key was pressed when we get a kEventRawKeyModifiersChanged event. */
|
---|
122 | UInt32 mDarwinKeyModifiers;
|
---|
123 | #endif
|
---|
124 |
|
---|
125 | static const char *kNoneSymbName;
|
---|
126 | };
|
---|
127 |
|
---|
128 | #endif // !___QIHotKeyEdit_h___
|
---|
129 |
|
---|