OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
eventhan.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1992, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of class TEventHandler
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/defs.h>
10#include <owl/eventhan.h>
11
12using namespace std;
13
14namespace owl {
15
17
19 // diagnostic group for message tracing
20
21#if defined(__TRACE) || defined(__WARN)
22
23 struct TWMStr {
24 TMsgId msg;
25 const char* str;
26 };
27#define DEFINE_MESSAGE(wm) { wm, #wm }
28
29 static TWMStr StrTab[] = {
30 { 0x0000, "WM_NULL" },
31 { 0x0001, "WM_CREATE" },
32 { 0x0002, "WM_DESTROY" },
33 { 0x0003, "WM_MOVE" },
34 { 0x0004, "WM_SIZEWAIT" },
35 { 0x0005, "WM_SIZE" },
36 { 0x0006, "WM_ACTIVATE" },
37 { 0x0007, "WM_SETFOCUS" },
38 { 0x0008, "WM_KILLFOCUS" },
39 { 0x0009, "WM_SETVISIBLE" },
40 { 0x000A, "WM_ENABLE" },
41 { 0x000B, "WM_SETREDRAW" },
42 { 0x000C, "WM_SETTEXT" },
43 { 0x000D, "WM_GETTEXT" },
44 { 0x000E, "WM_GETTEXTLENGTH" },
45 { 0x000F, "WM_PAINT" },
46 { 0x0010, "WM_CLOSE" },
47 { 0x0011, "WM_QUERYENDSESSION" },
48 { 0x0012, "WM_QUIT" },
49 { 0x0013, "WM_QUERYOPEN" },
50 { 0x0014, "WM_ERASEBKGND" },
51 { 0x0015, "WM_SYSCOLORCHANGE" },
52 { 0x0016, "WM_ENDSESSION" },
53 { 0x0017, "WM_SYSTEMERROR" }, // Obsolete
54 { 0x0018, "WM_SHOWWINDOW" },
55 { 0x0019, "WM_CTLCOLOR" }, // Obsolete
56 { 0x001A, "WM_SETTINGCHANGE" },
57 { 0x001B, "WM_DEVMODECHANGE" },
58 { 0x001C, "WM_ACTIVATEAPP" },
59 { 0x001D, "WM_FONTCHANGE" },
60 { 0x001E, "WM_TIMECHANGE" },
61 { 0x001F, "WM_CANCELMODE" },
62 { 0x0020, "WM_SETCURSOR" },
63 { 0x0021, "WM_MOUSEACTIVATE" },
64 { 0x0022, "WM_CHILDACTIVATE" },
65 { 0x0023, "WM_QUEUESYNC" },
66 { 0x0024, "WM_GETMINMAXINFO" },
67 // 0x0025
68 { 0x0026, "WM_PAINTICON" }, // Obsolete
69 { 0x0027, "WM_ICONERASEBKGND" }, // Obsolete
70 { 0x0028, "WM_NEXTDLGCTL" },
71 { 0x0029, "WM_ALTTABACTIVE" },
72 { 0x002A, "WM_SPOOLERSTATUS" },
73 { 0x002B, "WM_DRAWITEM" },
74 { 0x002C, "WM_MEASUREITEM" },
75 { 0x002D, "WM_DELETEITEM" },
76 { 0x002E, "WM_VKEYTOITEM" },
77 { 0x002F, "WM_CHARTOITEM" },
78 { 0x0030, "WM_SETFONT" },
79 { 0x0031, "WM_GETFONT" },
80 { 0x0032, "WM_SETHOTKEY" },
81 { 0x0033, "WM_GETHOTKEY" },
82 { 0x0034, "WM_FILESYSCHANGE" },
83 { 0x0035, "WM_ISACTIVEICON" },
84 { 0x0036, "WM_QUERYPARKICON" },
85 { 0x0037, "WM_QUERYDRAGICON" },
86 { 0x0038, "WM_QUERYSAVESTATE" },
87 { 0x0039, "WM_COMPAREITEM" },
88 { 0x0040, "WM_TESTING" },
89 { 0x0041, "WM_COMPACTING" },
90 { 0x0042, "WM_OTHERWINDOWCREATED" },
91 { 0x0043, "WM_OTHERWINDOWDESTROYED" },
92 { 0x0044, "WM_COMMNOTIFY" }, // Obsolete
93 { 0x0045, "WM_HOTKEYEVENT" },
94 { 0x0046, "WM_WINDOWPOSCHANGING" },
95 { 0x0047, "WM_WINDOWPOSCHANGED" },
96 { 0x0048, "WM_POWER" }, // Obsolete
97 { 0x004A, "WM_COPYDATA" },
98 { 0x004B, "WM_CANCELJOURNAL" },
99 // 0x004C
100 // 0x004D
101 { 0x004E, "WM_NOTIFY" },
102 // 0x004F
103 { 0x0050, "WM_INPUTLANGCHANGEREQUEST"},
104 { 0x0051, "WM_INPUTLANGCHANGE" },
105 { 0x0052, "WM_TCARD" },
106 { 0x0053, "WM_HELP" },
107 { 0x0054, "WM_USERCHANGED" },
108 { 0x0055, "WM_NOTIFYFORMAT" },
109 // ...
110 { 0x007B, "WM_CONTEXTMENU" },
111 { 0x007C, "WM_STYLECHANGING" },
112 { 0x007D, "WM_STYLECHANGED" },
113 { 0x007E, "WM_DISPLAYCHANGED" },
114 { 0x007F, "WM_GETICON" },
115 { 0x0080, "WM_SETICON" },
116 { 0x0081, "WM_NCCREATE" },
117 { 0x0082, "WM_NCDESTROY" },
118 { 0x0083, "WM_NCCALCSIZE" },
119 { 0x0084, "WM_NCHITTEST" },
120 { 0x0085, "WM_NCPAINT" },
121 { 0x0086, "WM_NCACTIVATE" },
122 { 0x0087, "WM_GETDLGCODE" },
123 { 0x0088, "WM_SYNCPAINT" },
124 { 0x0089, "WM_SYNCTASK" },
125 { 0x00A0, "WM_NCMOUSEMOVE" },
126 { 0x00A1, "WM_NCLBUTTONDOWN" },
127 { 0x00A2, "WM_NCLBUTTONUP" },
128 { 0x00A3, "WM_NCLBUTTONDBLCLK" },
129 { 0x00A4, "WM_NCRBUTTONDOWN" },
130 { 0x00A5, "WM_NCRBUTTONUP" },
131 { 0x00A6, "WM_NCRBUTTONDBLCLK" },
132 { 0x00A7, "WM_NCMBUTTONDOWN" },
133 { 0x00A8, "WM_NCMBUTTONUP" },
134 { 0x00A9, "WM_NCMBUTTONDBLCLK" },
135 // ...
136 { 0x0100, "WM_KEYDOWN" },
137 { 0x0101, "WM_KEYUP" },
138 { 0x0102, "WM_CHAR" },
139 { 0x0103, "WM_DEADCHAR" },
140 { 0x0104, "WM_SYSKEYDOWN" },
141 { 0x0105, "WM_SYSKEYUP" },
142 { 0x0106, "WM_SYSCHAR" },
143 { 0x0107, "WM_SYSDEADCHAR" },
144 { 0x0108, "WM_YOMICHAR" },
145 // ...
146 { 0x010A, "WM_CONVERTREQUEST" },
147 { 0x010B, "WM_CONVERTRESULT" },
148 { 0x010C, "WM_INTERIM" },
149 { 0x010D, "WM_IME_STARTCOMPOSITION" },
150 { 0x010E, "WM_IME_ENDCOMPOSITION" },
151 { 0x010F, "WM_IME_COMPOSITION" },
152 { 0x010F, "WM_IME_KEYLAST" },
153 { 0x0110, "WM_INITDIALOG" },
154 { 0x0111, "WM_COMMAND" },
155 { 0x0112, "WM_SYSCOMMAND" },
156 { 0x0113, "WM_TIMER" },
157 { 0x0114, "WM_HSCROLL" },
158 { 0x0115, "WM_VSCROLL" },
159 { 0x0116, "WM_INITMENU" },
160 { 0x0117, "WM_INITMENUPOPUP" },
161 { 0x0118, "WM_SYSTIMER" },
162 // ...
163 { 0x011F, "WM_MENUSELECT" },
164 { 0x0120, "WM_MENUCHAR" },
165 { 0x0121, "WM_ENTERIDLE" },
166 { 0x0131, "WM_LBTRACKPOINT" },
167 { 0x0132, "WM_CTLCOLORMSGBOX" }, // Obsolete message. No longer documented at MSDN.
168 { 0x0133, "WM_CTLCOLOREDIT" },
169 { 0x0134, "WM_CTLCOLORLISTBOX" },
170 { 0x0135, "WM_CTLCOLORBTN" },
171 { 0x0136, "WM_CTLCOLORDLG" },
172 { 0x0137, "WM_CTLCOLORSCROLLBAR" },
173 { 0x0138, "WM_CTLCOLORSTATIC" },
174 // ...
175 { 0x0200, "WM_MOUSEMOVE" },
176 { 0x0201, "WM_LBUTTONDOWN" },
177 { 0x0202, "WM_LBUTTONUP" },
178 { 0x0203, "WM_LBUTTONDBLCLK" },
179 { 0x0204, "WM_RBUTTONDOWN" },
180 { 0x0205, "WM_RBUTTONUP" },
181 { 0x0206, "WM_RBUTTONDBLCLK" },
182 { 0x0207, "WM_MBUTTONDOWN" },
183 { 0x0208, "WM_MBUTTONUP" },
184 { 0x0209, "WM_MBUTTONDBLCLK" },
185 { 0x020A, "WM_MOUSEWHEEL" },
186 { 0x020E, "WM_MOUSEHWHEEL" },
187 //...
188 { 0x0210, "WM_PARENTNOTIFY" },
189 { 0x0211, "WM_ENTERMENULOOP" },
190 { 0x0212, "WM_EXITMENULOOP" },
191 { 0x0213, "WM_NEXTMENU" },
192 { 0x0214, "WM_SIZING" },
193 { 0x0215, "WM_CAPTURECHANGED" },
194 { 0x0216, "WM_MOVING" },
195 //0x0217
196 { 0x0218, "WM_POWERBROADCAST" },
197 { 0x0219, "WM_DEVICECHANGE" },
198 // ...
199 { 0x0220, "WM_MDICREATE" },
200 { 0x0221, "WM_MDIDESTROY" },
201 { 0x0222, "WM_MDIACTIVATE" },
202 { 0x0223, "WM_MDIRESTORE" },
203 { 0x0224, "WM_MDINEXT" },
204 { 0x0225, "WM_MDIMAXIMIZE" },
205 { 0x0226, "WM_MDITILE" },
206 { 0x0227, "WM_MDICASCADE" },
207 { 0x0228, "WM_MDIICONARRANGE" },
208 { 0x0229, "WM_MDIGETACTIVE" },
209 { 0x022A, "WM_DROPOBJECT" },
210 { 0x022B, "WM_QUERYDROPOBJECT" },
211 { 0x022C, "WM_BEGINDRAG" },
212 { 0x022D, "WM_DRAGLOOP" },
213 { 0x022E, "WM_DRAGSELECT" },
214 { 0x022F, "WM_DRAGMOVE" },
215 { 0x0230, "WM_MDISETMENU" },
216 { 0x0231, "WM_ENTERSIZEMOVE" },
217 { 0x0232, "WM_EXITSIZEMOVE" },
218 { 0x0233, "WM_DROPFILES" },
219 { 0x0234, "WM_MDIREFRESHMENU" },
220 // ...
221 { 0x0281, "WM_IME_SETCONTEXT" },
222 { 0x0282, "WM_IME_NOTIFY" },
223 { 0x0283, "WM_IME_CONTROL" },
224 { 0x0284, "WM_IME_COMPOSITIONFULL" },
225 { 0x0285, "WM_IME_SELECT" },
226 { 0x0286, "WM_IME_CHAR" },
227 { 0x0290, "WM_IME_KEYDOWN" },
228 { 0x0291, "WM_IME_KEYUP" },
229 // ...
230 { 0x02A0, "WM_NCMOUSEHOVER" },
231 { 0x02A1, "WM_MOUSEHOVER" },
232 { 0x02A2, "WM_NCMOUSELEAVE" },
233 { 0x02A3, "WM_MOUSELEAVE" },
234 // ...
235 { 0x0300, "WM_CUT" },
236 { 0x0301, "WM_COPY" },
237 { 0x0302, "WM_PASTE" },
238 { 0x0303, "WM_CLEAR" },
239 { 0x0304, "WM_UNDO" },
240 { 0x0305, "WM_RENDERFORMAT" },
241 { 0x0306, "WM_RENDERALLFORMATS" },
242 { 0x0307, "WM_DESTROYCLIPBOARD" },
243 { 0x0308, "WM_DRAWCLIPBOARD" },
244 { 0x0309, "WM_PAINTCLIPBOARD" },
245 { 0x030A, "WM_VSCROLLCLIPBOARD" },
246 { 0x030B, "WM_SIZECLIPBOARD" },
247 { 0x030C, "WM_ASKCBFORMATNAME" },
248 { 0x030D, "WM_CHANGECBCHAIN" },
249 { 0x030E, "WM_HSCROLLCLIPBOARD" },
250 { 0x030F, "WM_QUERYNEWPALETTE" },
251 { 0x0310, "WM_PALETTEISCHANGING" },
252 { 0x0311, "WM_PALETTECHANGED" },
253 { 0x0312, "WM_HOTKEY" },
254 // ...
255 { 0x0317, "WM_PRINT" },
256 { 0x0318, "WM_PRINTCLIENT" },
257 // ...
258 { 0x031A, "WM_THEMECHANGED" },
259 // ...
260 { 0x0358, "WM_HANDHELDFIRST" },
261 // ...
262 { 0x035F, "WM_HANDHELDLAST" },
263 { 0x0360, "WM_AFXFIRST" },
264 // ...
265 { 0x037F, "WM_AFXLAST" },
266 { 0x0380, "WM_PENWINFIRST" },
267 // ...
268 { 0x038F, "WM_PENWINLAST" },
269 // ...
270 { 0x03E0, "WM_DDE_INITIATE" },
271 { 0x03E1, "WM_DDE_TERMINATE" },
272 { 0x03E2, "WM_DDE_ADVISE" },
273 { 0x03E3, "WM_DDE_UNADVISE" },
274 { 0x03E4, "WM_DDE_ACK" },
275 { 0x03E5, "WM_DDE_DATA" },
276 { 0x03E6, "WM_DDE_REQUEST" },
277 { 0x03E7, "WM_DDE_POKE" },
278 { 0x03E8, "WM_DDE_EXECUTE" },
279 // ...
280 { 0x0400, "WM_USER" },
281 // ...
282 { 0x8000, "WM_APP" },
283
284 // OWL Specific
285 { WM_OWLHELPHIT, "WM_OWLHELPHIT"}, // 0x7EF1
286 { WM_OWLCREATETTIP, "WM_OWLCREATETTIP"}, // 0x7EF2
287 { WM_OWLWINDOWDOCKED, "WM_OWLWINDOWDOCKED"}, // 0x7EF3 Notify window it was [un]docked/reparented
288 { WM_OWLSLIPDBLCLK, "WM_OWLSLIPDBLCLK"}, // 0x7EF4 Notify parent of user dblclick of edge slip
289 { WM_OWLFRAMESIZE, "WM_OWLFRAMESIZE"}, // 0x7EF5 Notify children of frame resizing
290 { WM_OWLWAKEUP, "WM_OWLWAKEUP"}, // 0x7EF6
291 { WM_VBXBASE, "WM_VBXBASE"}, // 0x7EF7
292 { WM_VBXNAME, "WM_VBXNAME"}, // 0x7FF7
293 { WM_VBXINITFORM, "WM_VBXINITFORM"}, // 0x7FF8
294 { WM_OWLCANCLOSE, "WM_OWLCANCLOSE"}, // 0x7FF9
295 { WM_OWLPREPROCMENU, "WM_OWLPREPROCMENU"}, // 0x7FFA
296 { WM_OWLNOTIFY, "WM_OWLNOTIFY"}, // 0x7FFB
297 { WM_OWLVIEW, "WM_OWLVIEW"}, // 0x7FFC
298 { WM_OWLDOCUMENT, "WM_OWLDOCUMENT"}, // 0x7FFD
299 { WM_CHILDINVALID, "WM_CHILDINVALID"}, // 0x7FFE
300 { WM_COMMAND_ENABLE, "WM_COMMAND_ENABLE"}, // 0x7FFF
301 };
302
303 //
304 // MsgCompare: this internal function is used by the qsort() and
305 // bsearch() functions to compare two StrTab elements.
306 //
307 static int
308 MsgCompare(const void* e1, const void* e2)
309 {
310 return ((TWMStr*)e1)->msg - ((TWMStr*)e2)->msg;
311 }
312
314 {
315 TWMStr key;
316 TWMStr* item;
317
318 if( msg.Message == WM_MOUSEMOVE || msg.Message == WM_NCMOUSEMOVE ||
319 msg.Message == WM_NCHITTEST || msg.Message == WM_SETCURSOR ||
320 msg.Message == WM_CTLCOLORBTN || msg.Message == WM_CTLCOLORDLG ||
321 msg.Message == WM_CTLCOLOREDIT || msg.Message == WM_CTLCOLORLISTBOX ||
322 msg.Message == WM_CTLCOLORMSGBOX || msg.Message == WM_CTLCOLORSCROLLBAR ||
323 msg.Message == WM_CTLCOLORSTATIC || msg.Message == WM_ENTERIDLE ||
324 msg.Message == WM_CANCELMODE || msg.Message == WM_COMMAND_ENABLE ||
325 msg.Message == 0x0118)// WM_SYSTIMER (caret blink)
326 {
327 // don't report very frequently sent messages
328 return os;
329 }
330 // find message name
331 if (msg.Message >= 0xC000){
332 // Window message registered with 'RegisterWindowMessage'
333 // (actually a USER atom)
334 tchar szBuf[80];
335 if (::GetClipboardFormatName(msg.Message, szBuf, COUNTOF(szBuf)))
336 return os << _T("Message ") << hex << msg.Message;
337 return os;
338 }
339
340 // if it's a user message, then just show the offset value
341 else if (msg.Message >= WM_USER)
342 return os << _T("WM_USER+") << hex << (msg.Message - WM_USER);
343
344 // otherwise, search for it in the table
345 else {
346 // initialize the search key
347 key.msg = msg.Message;
348
349 // let bsearch() do the work
350 item = (TWMStr*)bsearch(&key, StrTab, COUNTOF(StrTab), sizeof(TWMStr), MsgCompare);
351
352 // if message found, then insert the name
353 if (item){
355 return os << _A2W(item->str);
356 }
357
358 // otherwise, just insert the message number
359 else
360 return os << _T("Message ") << hex << msg.Message;
361 }
362 }
363#endif
364
365//
366/// Searches the list of response table entries looking for a match. Because
367/// TEventHandler doesn't have any entries, TEventHandler's implementation of this
368/// routine returns false.
369//
370bool
372{
373 return false;
374}
375
376#if OWL_NEW_RESPONSE_TABLE // New response table implementation:
377
378//
379/// Takes the message data from TEventInfo's Msg data member and forwards it to
380/// the registered dispatcher.
381//
384{
385 PRECONDITION(eventInfo.Entry);
386 return (*eventInfo.Entry->Dispatcher)(eventInfo.Object, param1, param2);
387}
388
389#else // Old response table implementation:
390
391//
392/// Takes the message data from TEventInfo's Msg data member and dispatches it to
393/// the correct event-handling function.
394//
397{
398 PRECONDITION(eventInfo.Entry);
399 return (*eventInfo.Entry->Dispatcher)(
400 *eventInfo.Object,
401 (TAnyPMF &)eventInfo.Entry->Pmf,
403 );
404}
405
406#endif
407
408//
409/// Search for the event given the message and it and dispatch to the
410/// event handler if found.
411//
414{
416 if (Find(eventInfo))
417 return Dispatch(eventInfo, p1, p2);
418 return 0;
419}
420
421//
422/// Low-level response table search function. Allows optional equal operator
423/// function to be provided.
424//
425/// Searches the entries in the response table for an entry that matches TEventInfo
426/// or, if so designated, an entry that TEqualOperator specifies is a match.
427//
428/// Fills in Entry member of eventInfo and returns true if found.
429//
430bool
433 TEqualOperator equal)
434{
435 if (equal) {
436 while (entries->Dispatcher != nullptr) {
437 if (equal(*entries, eventInfo)) {
438 eventInfo.Entry = entries;
439 return true;
440 }
441 entries++;
442 }
443 }
444 else {
445 while (entries->Dispatcher != nullptr) {
446 if (entries->Msg == eventInfo.Msg && entries->Id == eventInfo.Id) {
447 eventInfo.Entry = entries;
448 return true;
449 }
450 entries++;
451 }
452 }
453
454 return false;
455}
456
457} // OWL namespace
458/* ========================================================================== */
459
#define PRECONDITION(condition)
Definition checks.h:227
#define DIAG_DEFINE_GROUP_INIT(f, g, e, l)
Definition checks.h:429
A nested class, TEventInfo provides specific information about the type of message sent,...
Definition eventhan.h:170
virtual bool Find(TEventInfo &info, TEqualOperator op=0)
Searches the list of response table entries looking for a match.
Definition eventhan.cpp:371
TResult DispatchMsg(TMsgId, uint id, TParam1, TParam2)
Search for the event given the message and it and dispatch to the event handler if found.
Definition eventhan.cpp:413
bool SearchEntries(const TGenericTableEntry *entries, TEventInfo &info, TEqualOperator op)
Low-level response table search function.
Definition eventhan.cpp:431
TResult Dispatch(TEventInfo &info, TParam1, TParam2=0)
Takes the message data from TEventInfo's Msg data member and dispatches it to the correct event-handl...
Definition eventhan.cpp:396
A template class, TResponseTableEntry lets you define a pattern for entries into a response table.
Definition eventhan.h:217
#define _T(x)
Definition cygwin.h:51
#define WM_VBXINITFORM
Definition dispatch.h:4110
#define WM_OWLVIEW
Definition dispatch.h:4106
#define WM_OWLWINDOWDOCKED
Notify window it was [un]docked/reparented.
Definition dispatch.h:4116
#define WM_OWLSLIPDBLCLK
Notify parent of user dblclick of edge slip.
Definition dispatch.h:4115
#define WM_OWLWAKEUP
Definition dispatch.h:4113
#define WM_OWLNOTIFY
Definition dispatch.h:4107
#define WM_OWLFRAMESIZE
Notify children of frame resizing.
Definition dispatch.h:4114
#define WM_OWLCANCLOSE
Definition dispatch.h:4109
#define WM_COMMAND_ENABLE
Definition dispatch.h:4103
#define WM_VBXBASE
Definition dispatch.h:4112
#define WM_OWLHELPHIT
Notify Help manager with hit point.
Definition dispatch.h:4118
#define WM_VBXNAME
Definition dispatch.h:4111
#define WM_CHILDINVALID
Definition dispatch.h:4104
#define WM_OWLCREATETTIP
Notify gadget window to create tooltips.
Definition dispatch.h:4117
#define WM_OWLDOCUMENT
Definition dispatch.h:4105
#define WM_OWLPREPROCMENU
Definition dispatch.h:4108
Definition of TEventHandler and related classes & macros.
#define _A2W(lpw)
Definition memory.h:220
#define _USES_CONVERSION
Definition memory.h:217
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
UINT TMsgId
Message ID type.
Definition dispatch.h:53
void(TGeneric::* TAnyPMF)()
Definition dispatch.h:108
owl::opstream & operator<<(owl::opstream &os, const TColor &c)
Insert the color value into a persistent output stream.
Definition color.h:498
char tchar
Definition defs.h:77
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
OWL_DIAGINFO
Definition animctrl.cpp:14
LRESULT TResult
Result type.
Definition dispatch.h:52
unsigned int uint
Definition number.h:25
std::ostream tostream
Definition strmdefs.h:40
General definitions used by all ObjectWindows programs.
#define OWL_INI
Definition defs.h:170
#define _OWLCFUNC(p)
Definition defs.h:342
#define COUNTOF(s)
Array element count Important: Only use this with an argument of array type.
Definition defs.h:376