source: trunk/autoquest-plugin-mfc/src/main/java/de/ugoe/cs/autoquest/plugin/mfc/eventcore/WindowsMessageType.java @ 927

Last change on this file since 927 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
  • Property svn:mime-type set to text/plain
File size: 9.3 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.plugin.mfc.eventcore;
16
17/**
18 * <p>
19 * Enumeration to deal with MFC message types.
20 * </p>
21 *
22 * @version 1.0
23 * @author Patrick Harms, Steffen Herbold
24 */
25public enum WindowsMessageType {
26
27    WM_NULL(0), WM_CREATE(1), WM_DESTROY(2), WM_MOVE(3), WM_SIZE(5), WM_ACTIVATE(6),
28    WM_SETFOCUS(7), WM_KILLFOCUS(8), WM_ENABLE(10), WM_SETREDRAW(11), WM_SETTEXT(12),
29    WM_GETTEXT(13), WM_GETTEXTLENGTH(14), WM_PAINT(15), WM_CLOSE(16), WM_QUERYENDSESSION(17),
30    WM_QUIT(18), WM_QUERYOPEN(19), WM_ERASEBKGND(20), WM_SYSCOLORCHANGE(21), WM_ENDSESSION(22),
31    WM_SHOWWINDOW(24), WM_CTLCOLOR(25), WM_WININICHANGE(26), WM_DEVMODECHANGE(27), WM_ACTIVATEAPP(
32        28), WM_FONTCHANGE(29), WM_TIMECHANGE(30), WM_CANCELMODE(31), WM_SETCURSOR(32),
33    WM_MOUSEACTIVATE(33), WM_CHILDACTIVATE(34), WM_QUEUESYNC(35), WM_GETMINMAXINFO(36),
34    WM_PAINTICON(38), WM_ICONERASEBKGND(39), WM_NEXTDLGCTL(40), WM_SPOOLERSTATUS(42), WM_DRAWITEM(
35        43), WM_MEASUREITEM(44), WM_DELETEITEM(45), WM_VKEYTOITEM(46), WM_CHARTOITEM(47),
36    WM_SETFONT(48), WM_GETFONT(49), WM_SETHOTKEY(50), WM_GETHOTKEY(51), WM_QUERYDRAGICON(55),
37    WM_COMPAREITEM(57), WM_GETOBJECT(61), WM_COMPACTING(65), WM_COMMNOTIFY(68),
38    WM_WINDOWPOSCHANGING(70), WM_WINDOWPOSCHANGED(71), WM_POWER(72), WM_COPYDATA(74),
39    WM_CANCELJOURNAL(75), WM_NOTIFY(78), WM_INPUTLANGCHANGEREQUEST(80), WM_INPUTLANGCHANGE(81),
40    WM_TCARD(82), WM_HELP(83), WM_USERCHANGED(84), WM_NOTIFYFORMAT(85), WM_CONTEXTMENU(123),
41    WM_STYLECHANGING(124), WM_STYLECHANGED(125), WM_DISPLAYCHANGE(126), WM_GETICON(127),
42    WM_SETICON(128), WM_NCCREATE(129), WM_NCDESTROY(130), WM_NCCALCSIZE(131), WM_NCHITTEST(132),
43    WM_NCPAINT(133), WM_NCACTIVATE(134), WM_GETDLGCODE(135), WM_SYNCPAINT(136),
44    WM_NCMOUSEMOVE(160), WM_NCLBUTTONDOWN(161), WM_NCLBUTTONUP(162), WM_NCLBUTTONDBLCLK(163),
45    WM_NCRBUTTONDOWN(164), WM_NCRBUTTONUP(165), WM_NCRBUTTONDBLCLK(166), WM_NCMBUTTONDOWN(167),
46    WM_NCMBUTTONUP(168), WM_NCMBUTTONDBLCLK(169), WM_NCXBUTTONDOWN(171), WM_NCXBUTTONUP(172),
47    WM_NCXBUTTONDBLCLK(173), SBM_SETPOS(224), BM_CLICK(245), WM_INPUT(255), WM_KEYDOWN(256),
48    WM_KEYFIRST(256), WM_KEYUP(257), WM_CHAR(258), WM_DEADCHAR(259), WM_SYSKEYDOWN(260),
49    WM_SYSKEYUP(261), WM_SYSCHAR(262), WM_SYSDEADCHAR(263), WM_KEYLAST(264),
50    WM_WNT_CONVERTREQUESTEX(265), WM_CONVERTREQUEST(266), WM_CONVERTRESULT(267), WM_INTERIM(268),
51    WM_IME_STARTCOMPOSITION(269), WM_IME_ENDCOMPOSITION(270), WM_IME_COMPOSITION(271),
52    WM_IME_KEYLAST(271), WM_INITDIALOG(272), WM_COMMAND(273), WM_SYSCOMMAND(274), WM_TIMER(275),
53    WM_HSCROLL(276), WM_VSCROLL(277), WM_INITMENU(278), WM_INITMENUPOPUP(279), WM_MENUSELECT(287),
54    WM_MENUCHAR(288), WM_ENTERIDLE(289), WM_MENURBUTTONUP(290), WM_MENUDRAG(291), WM_MENUGETOBJECT(
55        292), WM_UNINTMENUPOPUP(293), WM_MENUCOMMAND(294), WM_CHANGEUISTATE(295), WM_UPDATEUISTATE(
56        296), WM_QUERYUISTATE(297), WM_CTLCOLORMSGBOX(306), WM_CTLCOLOREDIT(307),
57    WM_CTLCOLORLISTBOX(308), WM_CTLCOLORBTN(309), WM_CTLCOLORDLG(310), WM_CTLCOLORSCROLLBAR(311),
58    WM_CTLCOLORSTATIC(312), CB_SHOWDROPDOWN(335), LB_SETCURSEL(390), WM_MOUSEFIRST(512),
59    WM_MOUSEMOVE(512), WM_LBUTTONDOWN(513), WM_LBUTTONUP(514), WM_LBUTTONDBLCLK(515),
60    WM_RBUTTONDOWN(516), WM_RBUTTONUP(517), WM_RBUTTONDBLCLK(518), WM_MBUTTONDOWN(519),
61    WM_MBUTTONUP(520), WM_MBUTTONDBLCLK(521), WM_MOUSELAST(521), WM_MOUSEWHEEL(522),
62    WM_XBUTTONDOWN(523), WM_XBUTTONUP(524), WM_XBUTTONDBLCLK(525), WM_USER(1024),
63    CB_SETCURSEL(334), TBM_SETPOS(1029), UDM_SETRANGE(1125), TCM_SETCURSEL(4876);
64
65    /**
66     * <p>
67     * Numerical representation of the message type.
68     * </p>
69     */
70    private int mNumber;
71
72    /**
73     * <p>
74     * Constructor. Creates a new WindowsMessageType.
75     * </p>
76     *
77     * @param number
78     *            numerical representation of the message type
79     */
80    WindowsMessageType(int number) {
81        mNumber = number;
82    }
83
84    /**
85     * <p>
86     * Returns the numerical representation of the message type.
87     * </p>
88     *
89     * @return the numerical representation
90     */
91    public int getNumber() {
92        return mNumber;
93    }
94
95    /**
96     * <p>
97     * Checks if the type of a message generated is a keyboard interaction.
98     * </p>
99     *
100     * @param msgType
101     *            type of the message
102     * @return true if it is a keyboard interaction; false otherwise
103     */
104    public boolean isKeyMessage() {
105        boolean isKeyMsg = false;
106        switch (this)
107        {
108            case WM_KEYDOWN:
109            case WM_KEYUP:
110            case WM_SYSKEYDOWN:
111            case WM_SYSKEYUP:
112                isKeyMsg = true;
113                break;
114            default:
115                break;
116        }
117        return isKeyMsg;
118    }
119
120    /**
121     * <p>
122     * Checks if the type of a message indicates that the mouse has been pressed down.
123     * </p>
124     *
125     * @param msgType
126     *            type of the message
127     * @return true if it is mouse-down message; false otherwise
128     */
129    public boolean isDownMessage() {
130        boolean isDownMsg = false;
131        switch (this)
132        {
133            case WM_LBUTTONDOWN:
134            case WM_RBUTTONDOWN:
135            case WM_MBUTTONDOWN:
136            case WM_XBUTTONDOWN:
137            case WM_NCLBUTTONDOWN:
138            case WM_NCRBUTTONDOWN:
139            case WM_NCMBUTTONDOWN:
140            case WM_NCXBUTTONDOWN:
141                isDownMsg = true;
142                break;
143            default:
144                break;
145        }
146        return isDownMsg;
147    }
148
149    /**
150     * <p>
151     * Checks if the type of a message indicates that a double click has been performed.
152     * </p>
153     *
154     * @param msgType
155     *            type of the message
156     * @return true if it is a double click message; false otherwise
157     */
158    public boolean isDblclkMessage() {
159        boolean isDblclkMsg = false;
160        switch (this)
161        {
162            case WM_LBUTTONDBLCLK:
163            case WM_RBUTTONDBLCLK:
164            case WM_MBUTTONDBLCLK:
165            case WM_XBUTTONDBLCLK:
166            case WM_NCLBUTTONDBLCLK:
167            case WM_NCRBUTTONDBLCLK:
168            case WM_NCMBUTTONDBLCLK:
169            case WM_NCXBUTTONDBLCLK:
170                isDblclkMsg = true;
171                break;
172            default:
173                break;
174        }
175        return isDblclkMsg;
176    }
177
178    /**
179     * <p>
180     * Checks if the type of a message indicates that the mouse has been released.
181     * </p>
182     *
183     * @param msgType
184     *            type of the message
185     * @return true if it is mouse-up message; false otherwise
186     */
187    public boolean isUpMessage() {
188        boolean isUpMsg = false;
189        switch (this)
190        {
191            case WM_LBUTTONUP:
192            case WM_RBUTTONUP:
193            case WM_MBUTTONUP:
194            case WM_XBUTTONUP:
195            case WM_NCLBUTTONUP:
196            case WM_NCRBUTTONUP:
197            case WM_NCMBUTTONUP:
198            case WM_NCXBUTTONUP:
199                isUpMsg = true;
200                break;
201            default:
202                break;
203        }
204        return isUpMsg;
205    }
206
207    /**
208     * <p>
209     * Parses an {@link String} and returns the respective WindowsMessageType if possible.
210     * </p>
211     *
212     * @param numberString
213     *            String representation of the event type
214     * @return created WindowsMessageType
215     * @throws IllegalArgumentException
216     *             thrown if there is no WindowsMessageType that correlates to numberString
217     */
218    public static WindowsMessageType parseMessageType(String numberString)
219        throws IllegalArgumentException
220    {
221        try {
222            int number = Integer.parseInt(numberString);
223            return valueOf(number);
224        }
225        catch (NumberFormatException e) {
226            return WindowsMessageType.valueOf(WindowsMessageType.class, numberString);
227        }
228    }
229
230    /**
231     * <p>
232     * Returns the WindowsMessageType associated with an integer.
233     * </p>
234     *
235     * @param number
236     *            integer to which the according WindowsMessageType is returned
237     * @return the WindowsMessageType
238     * @throws IllegalArgumentException
239     *             thrown if there is no WindowsMessageType that correlates to number
240     */
241    public static WindowsMessageType valueOf(int number) throws IllegalArgumentException {
242        for (WindowsMessageType type : WindowsMessageType.values()) {
243            if (type.mNumber == number) {
244                return type;
245            }
246        }
247
248        throw new IllegalArgumentException("there is no message type with number " + number);
249    }
250}
Note: See TracBrowser for help on using the repository browser.