-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCALLWIN.CPP
More file actions
1397 lines (1213 loc) · 30.7 KB
/
CALLWIN.CPP
File metadata and controls
1397 lines (1213 loc) · 30.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Project: Windows Class Library
Module: CALLWIN.CPP
Description: Implementation of CallbackWindow-class
A CallbackWindow is a window that has an application
specific callback function
Author: Martin Gäckler
Address: Hofmannsthalweg 14, A-4030 Linz
Web: https://www.gaeckler.at/
Copyright: (c) 1988-2025 Martin Gäckler
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
THIS SOFTWARE IS PROVIDED BY Martin Gäckler, Linz, Austria ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
// --------------------------------------------------------------------- //
// ----- switches ------------------------------------------------------ //
// --------------------------------------------------------------------- //
#ifndef STRICT
#define STRICT 1
#endif
// --------------------------------------------------------------------- //
// ----- includes ------------------------------------------------------ //
// --------------------------------------------------------------------- //
#ifdef _MSC_VER
# pragma warning( push )
# pragma warning( disable: 4986 4820 4668 )
#endif
#include <windows.h>
#include <dde.h>
#include <commdlg.h>
#ifdef _MSC_VER
# pragma warning( pop )
#endif
#include <winlib/callwin.h>
#include <winlib/winapp.h>
#include <winlib/dialogwi.h>
#include <winlib/stddlg.h>
#include <winlib/tooltip.h>
#include <winlib/CONTROLW.H>
#include <winlib/messages.h>
// --------------------------------------------------------------------- //
// ----- module switches ----------------------------------------------- //
// --------------------------------------------------------------------- //
#ifdef __BORLANDC__
# pragma option -RT-
# pragma option -b
# pragma option -a4
# pragma option -pc
#endif
namespace winlib
{
using namespace gak;
#undef FINDMSGSTRING
#define FINDMSGSTRING "commdlg_FindReplace"
// --------------------------------------------------------------------- //
// ----- module statics ------------------------------------------------ //
// --------------------------------------------------------------------- //
static ListContainer *openWin = NULL;
// --------------------------------------------------------------------- //
// ----- class statics ------------------------------------------------- //
// --------------------------------------------------------------------- //
HACCEL CallbackWindow::s_hAccel = 0;
AcceleratorMap CallbackWindow::s_accelerators;
UINT CallbackWindow::s_findMessage = UINT(-1);
SearchDialog *CallbackWindow::s_findDialog = NULL;
// --------------------------------------------------------------------- //
// ----- class constructors/destructors -------------------------------- //
// --------------------------------------------------------------------- //
CallbackWindow::CallbackWindow( BasicWindow *owner )
: BasicWindow( CallbackWindowFlag, owner )
{
doEnterFunctionEx(gakLogging::llDetail, "CallbackWindow::CallbackWindow");
#ifndef NDEBUG
m_watchMe = false;
#endif
if( int(s_findMessage) < 0 )
{
s_findMessage = RegisterWindowMessage( FINDMSGSTRING );
}
m_menu = 0;
m_statusBar = NULL;
m_toolWin = NULL;
m_toolWinTimer = m_applicationTimer = 0;
m_layoutManager = NULL;
m_callBackCount = 0;
m_allowNotifications = true;
m_dialogProcessing = false;
m_altKey = m_shiftKey = m_controlKey = false;
m_terminate = m_closed = m_destroyed = false;
m_dragTreeView = NULL;
m_dragItem = NULL;
if( !openWin )
{
openWin = new ListContainer;
}
openWin->addElement( (ListEntry *)this );
}
CallbackWindow::~CallbackWindow()
{
assert( !m_callBackCount );
removeTimer();
removeToolHelp();
removeStatusBar();
openWin->removeObject( (ListEntry *)this );
if( m_layoutManager )
{
delete m_layoutManager;
}
if( m_menu )
{
delete m_menu;
}
}
// --------------------------------------------------------------------- //
// ----- class static functions ---------------------------------------- //
// --------------------------------------------------------------------- //
void CallbackWindow::registerSearchDialog( SearchDialog *newFindDialog )
{
if( s_findDialog )
{
s_findDialog->close();
delete s_findDialog;
}
s_findDialog = newFindDialog;
}
LRESULT CallbackWindow::dispatch( HWND handle, unsigned msg, WPARAM wParam, LPARAM lParam )
{
doEnterFunctionEx(gakLogging::llDetail, "CallbackWindow::dispatch");
CallbackWindow *curWindow;
ListCursor cursor;
LRESULT returnVal = true;
for(
curWindow = openWin ? (CallbackWindow*)openWin->getFirst( &cursor ) : NULL;
curWindow;
curWindow = (CallbackWindow *)cursor.getNext()
)
{
if( curWindow->handle() == handle )
{
curWindow->m_callBackCount++;
#ifndef NDEBUG
curWindow->m_messageStack.push( msg );
#endif
try
{
#ifndef NDEBUG
if( curWindow->m_watchMe )
{
doLogValue( msg );
doLogValue( wParam );
doLogValue( lParam );
doLogValue( curWindow->m_callBackCount );
}
#endif
returnVal = curWindow->callBack( msg, wParam, lParam );
#ifndef NDEBUG
curWindow->m_messageStack.pop();
#endif
curWindow->m_callBackCount--;
#ifndef NDEBUG
if( curWindow->m_watchMe )
{
doLogValue( msg );
doLogValue( wParam );
doLogValue( lParam );
doLogValue( curWindow->m_callBackCount );
}
#endif
}
catch( ... )
{
#ifndef NDEBUG
curWindow->m_messageStack.pop();
#endif
curWindow->m_callBackCount--;
throw;
}
if( curWindow->mayBeDeleted() && !curWindow->m_callBackCount )
{
bool deleted = false;
BasicWindow *parent = const_cast<BasicWindow *>(curWindow->getParent());
BasicWindow *owner = const_cast<BasicWindow *>(curWindow->getOwner());
if( parent )
{
deleted = parent->handleChildClose( curWindow, deleted );
}
if( owner && owner != parent )
{
owner->handleChildClose( curWindow, deleted );
}
}
/*v*/ break;
}
}
return returnVal;
}
// --------------------------------------------------------------------- //
// ----- class privates ------------------------------------------------ //
// --------------------------------------------------------------------- //
inline void CallbackWindow::resizeStatusBar( Size *mySize )
{
if( m_statusBar )
{
m_statusBar->sizeNmove( 0, mySize->height - STATUS_HEIGHT, mySize->width, STATUS_HEIGHT );
// mySize->y -= STATUS_HEIGHT;
}
}
void CallbackWindow::handleFiles( HDROP drop )
{
size_t numFiles,
i;
char fileName[1024];
numFiles = DragQueryFile( drop, UINT(-1), NULL, 0 );
for( i=0; i < numFiles; )
{
UINT result = DragQueryFile( drop, UINT(i), fileName, sizeof( fileName ) );
if( result )
handleFile( fileName, ++i, numFiles );
}
DragFinish( drop );
}
void CallbackWindow::handleFindReplace( FINDREPLACE *findReplace )
{
if( findReplace->Flags & FR_DIALOGTERM )
{
delete s_findDialog;
s_findDialog = NULL;
return;
}
else if( findReplace->Flags & FR_FINDNEXT )
{
handleFind( s_findDialog->getFindText(),
findReplace->Flags & FR_WHOLEWORD ? true : false,
findReplace->Flags & FR_MATCHCASE ? true : false,
findReplace->Flags & FR_DOWN ? true : false );
}
else if( findReplace->Flags & FR_REPLACE )
{
handleReplace( s_findDialog->getFindText(),
((ReplaceDialog*)s_findDialog)->getReplaceText(),
false,
findReplace->Flags & FR_WHOLEWORD ? true : false,
findReplace->Flags & FR_MATCHCASE ? true : false );
}
else if( findReplace->Flags & FR_REPLACEALL )
{
handleReplace( s_findDialog->getFindText(),
((ReplaceDialog*)s_findDialog)->getReplaceText(),
true,
findReplace->Flags & FR_WHOLEWORD ? true : false,
findReplace->Flags & FR_MATCHCASE ? true : false );
}
}
bool CallbackWindow::isDialogMessage( MSG &msg )
{
if( m_dialogProcessing )
{
checkModifiers( msg );
#if 0
// this prevent the control to receive tabs
if( findChild( msg->hwnd ) && msg->message == WM_KEYDOWN && msg->wParam == VK_TAB )
{
int direction = isShiftKey() ? GW_HWNDPREV : GW_HWNDNEXT;
for(
HWND next = GetNextWindow( msg->hwnd, direction );
next;
next = GetNextWindow( next, direction )
)
{
BasicWindow *child = findChild( next );
if( child )
{
if( child->hasStyle( WS_TABSTOP ) && child->isEnabled() )
{
child->focus();
break;
}
}
}
return true;
}
else
#endif
return IsDialogMessage( handle(), &msg );
}
return false;
}
LRESULT CallbackWindow::callBack( const unsigned int message, const WPARAM wParam, const LPARAM lParam )
{
doEnterFunctionEx(gakLogging::llDetail, "CallbackWindow::callBack");
ProcessStatus msgStatus = psPROCESSED;
m_callBackValue = 0; // show that we have processed the message
// find/replace
if( message == s_findMessage )
{
handleFindReplace( (FINDREPLACE *)lParam );
}
else switch( message )
{
// The window messages
// creating/destroying
case WM_INITDIALOG:
m_callBackValue = 1; // set the input focus to the first item
case WM_CREATE:
{
m_closed = m_destroyed = false;
setIcon( appObject->getIcon() );
if( !getResource() )
{
// we cannot handle the creation before all controls were created
msgStatus = handleCreate();
}
break;
}
case WM_SHOWWINDOW:
if( wParam )
msgStatus = handleShow();
else
msgStatus = handleHide();
break;
case WM_ENDSESSION:
if( !wParam )
break;
case WM_CLOSE:
m_closed = (handleClose() == scSUCCESS);
break;
case WM_DESTROY:
msgStatus = handleDestroy();
if( this == appObject->getMainWindow() )
exitApplication();
m_destroyed = true;
break;
// activation
case WM_MDIACTIVATE:
handleActivate( (HWND)lParam == handle() ? true : false );
break;
// sizing
// WM_WINDOWPOSCHANGED
case WM_SIZE:
{
m_clientSize = MAKESIZE( DWORD(lParam) );
resizeStatusBar( &m_clientSize );
msgStatus = handleResize( m_clientSize );
break;
}
// repainting
case WM_ERASEBKGND:
{
m_callBackValue = 1;
BackgroundDevice dc( this, HDC(wParam) );
msgStatus = handleErase( dc );
break;
}
case WM_PAINT:
{
RepaintDevice dc( this );
msgStatus = handleRepaint( dc );
break;
}
// scroll bars
case WM_VSCROLL:
if( m_toolWin )
{
removeToolHelp();
}
msgStatus = handleVertScroll( VertScrollCode( LOWORD( wParam ) ), HIWORD( wParam ), HWND(lParam) );
break;
case WM_HSCROLL:
if( m_toolWin )
{
removeToolHelp();
}
msgStatus = handleHorizScroll( HorizScrollCode( LOWORD( wParam ) ), HIWORD( wParam ), HWND(lParam) );
break;
// command buttons / menus
case WM_NOTIFY:
{
if( m_toolWin )
{
removeToolHelp();
}
if( !m_allowNotifications )
{
msgStatus = psDO_DEFAULT;
}
else
{
NMHDR *notify = reinterpret_cast<NMHDR *>(lParam);
if( notify->code == TVN_SELCHANGED )
{
NM_TREEVIEW *notify = reinterpret_cast<NM_TREEVIEW *>(lParam);
if( notify->action != TVC_UNKNOWN )
{
msgStatus = handleSelectionChange( int(notify->hdr.idFrom) );
}
}
else if( notify->code == TVN_BEGINDRAG )
{
TreeView *treeView = static_cast<TreeView *>(findChild( notify->hwndFrom ));
if( treeView )
{
NM_TREEVIEW *notify = reinterpret_cast<NM_TREEVIEW *>(lParam);
if( (m_dragItem = treeView->startDrag( notify )) != NULL )
{
msgStatus = psPROCESSED;
m_dragTreeView = treeView;
//ShowCursor( FALSE );
captureMouse();
}
}
}
else if( notify->code == DTN_DATETIMECHANGE )
{
msgStatus = handleSelectionChange( int(notify->idFrom) );
}
}
break;
}
case WM_COMMAND:
if( m_toolWin )
{
removeToolHelp();
}
if( !m_allowNotifications )
{
msgStatus = psDO_DEFAULT;
}
else
{
{
int command = LOWORD( wParam );
if( lParam == 0 )
{
msgStatus = handleCommand( command );
}
else
{
int notify = HIWORD( wParam );
switch( notify )
{
case EN_CHANGE:
case CBN_EDITCHANGE:
msgStatus = handleEditChange( command );
break;
case BN_CLICKED:
msgStatus = handleButtonClick( command );
break;
case TVN_SELCHANGED:
case LBN_SELCHANGE:
// case CBN_SELCHANGE:
msgStatus = handleSelectionChange( command );
break;
default:
msgStatus = handleNotification( notify, command );
break;
}
}
}
}
break;
// The mouse
case WM_CAPTURECHANGED:
msgStatus = handleMouseRelease();
break;
case WM_MOUSEMOVE:
{
m_controlKey = wParam & MK_CONTROL;
m_shiftKey = wParam & MK_SHIFT;
Point point = MAKEPOINT( DWORD(lParam) );
if( m_dragTreeView )
{
msgStatus = psPROCESSED;
mouseToChildPosition( m_dragTreeView, &point );
TreeNode *dragOver = m_dragTreeView->doDrag( point );
if( dragOver )
{
handleTreeViewDrag( m_dragTreeView, m_dragItem, dragOver );
}
}
else
{
msgStatus = handleMouseMove( wParam, point );
}
break;
}
case WM_LBUTTONUP:
if( m_dragTreeView )
{
TreeNode *dropTarget = m_dragTreeView->doDrop();
if( dropTarget && dropTarget != m_dragItem )
{
handleTreeViewDrop( m_dragTreeView, m_dragItem, dropTarget );
}
//ShowCursor( TRUE );
releaseMouse();
m_dragTreeView = NULL;
msgStatus = psPROCESSED;
break;
}
case WM_LBUTTONDBLCLK:
case WM_LBUTTONDOWN:
m_controlKey = wParam & MK_CONTROL;
m_shiftKey = wParam & MK_SHIFT;
if( m_toolWin )
{
removeToolHelp();
}
else
{
Point point = MAKEPOINT( DWORD(lParam) );
msgStatus = handleLeftButton( LeftButton(message), wParam, point );
}
break;
case WM_RBUTTONDBLCLK:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
m_controlKey = wParam & MK_CONTROL;
m_shiftKey = wParam & MK_SHIFT;
if( m_toolWin )
{
removeToolHelp();
}
else
{
Point point = MAKEPOINT( DWORD(lParam) );
msgStatus = handleRightButton( RightButton(message), wParam, point );
}
break;
// Drag and Drop
case WM_DROPFILES:
msgStatus = psPROCESSED;
handleFiles( (HDROP)wParam );
break;
// DDE messages
case WM_DDE_INITIATE:
{
ATOM appAtom;
ATOM topicAtom;
char application[32];
char topic[32];
appAtom = LOWORD( lParam );
topicAtom = HIWORD( lParam );
GlobalGetAtomName( appAtom, application, sizeof( application ) );
GlobalGetAtomName( topicAtom, topic, sizeof( topic ) );
if( ddeInitiate( application, topic ) == psPROCESSED )
{
LPARAM lParam = PackDDElParam( WM_DDE_ACK, appAtom, topicAtom );
SendMessage( HWND(wParam), WM_DDE_ACK, WPARAM(handle()), lParam );
}
else
{
msgStatus = psDO_DEFAULT;
}
break;
}
case WM_DDE_EXECUTE:
{
HGLOBAL command = HGLOBAL(lParam);
char *commandPtr = static_cast<char *>(GlobalLock( command ));
if( commandPtr )
{
if( ddeExecute( commandPtr ) == psPROCESSED )
{
GlobalUnlock( command );
LPARAM lParam = PackDDElParam( WM_DDE_ACK, 0, UINT(command) );
PostMessage( HWND(wParam), WM_DDE_ACK, WPARAM(handle()), lParam );
}
else
{
GlobalUnlock( command );
msgStatus = psDO_DEFAULT;
}
}
break;
}
case WM_DDE_TERMINATE:
PostMessage( HWND(wParam), WM_DDE_TERMINATE, WPARAM(handle()), 0L );
break;
// help
case WM_HELP:
{
if( m_toolWin )
{
removeToolHelp();
}
LPHELPINFO info = LPHELPINFO(lParam);
showHelp( info->iContextType, info->iCtrlId );
break;
}
// timer
case WM_TIMER:
if( wParam == APPL_TIMER_ID )
{
handleTimer();
}
else if( wParam == TOOL_WIN_TIMER_ID )
{
processTooltipTimer();
}
break;
// keyboard input
case WM_GETDLGCODE:
m_callBackValue = DLGC_WANTCHARS|DLGC_WANTARROWS|DLGC_WANTTAB|DLGC_WANTALLKEYS;
if( wParam != 0 )
{
m_callBackValue |= DLGC_WANTTAB;
}
break;
case WM_SETFOCUS:
msgStatus = psDO_DEFAULT;
handleFocus();
break;
case WM_KILLFOCUS:
msgStatus = psDO_DEFAULT;
if( hasCaret() )
destroyCaret();
handleKillFocus();
break;
case WM_SYSKEYDOWN:
case WM_KEYDOWN:
if( wParam == VK_MENU )
m_altKey = true;
else if( wParam == VK_SHIFT )
m_shiftKey = true;
else if( wParam == VK_CONTROL )
m_controlKey = true;
msgStatus = handleKeyDown( int(wParam) );
break;
case WM_SYSKEYUP:
case WM_KEYUP:
if( wParam == VK_MENU )
m_altKey = false;
else if( wParam == VK_SHIFT )
m_shiftKey = false;
else if( wParam == VK_CONTROL )
m_controlKey = false;
msgStatus = handleKeyUp( int(wParam) );
break;
case WM_CHAR:
m_altKey = lParam & (1<<29);
msgStatus = handleCharacterInput( int(wParam) );
break;
case WM_CTLCOLORLISTBOX:
case WM_CTLCOLORBTN:
case WM_CTLCOLOREDIT:
case WM_CTLCOLORSTATIC:
msgStatus = checkControlColor( HWND( lParam ), HDC(wParam) );
break;
case WM_SETFONT:
{
const ChildWindows &children = getChildren();
for(
ChildWindows::const_iterator it = children.cbegin(), endIT = children.cend();
it != endIT;
++it
)
{
BasicWindow *child = *it;
if( !child->getFont().isAssigned() )
{
child->message( WM_SETFONT, wParam, lParam );
}
}
break;
}
case WM_GETFONT:
m_callBackValue = LRESULT(HFONT(getFont()));
if( !m_callBackValue && getParent() )
m_callBackValue = getParent()->message( WM_GETFONT );
msgStatus = psPROCESSED;
break;
case WM_ASYNC_TASK_END:
handleAsyncTaskEnd( reinterpret_cast<void*>(lParam) );
break;
// The special (rarely used) messages
default:
msgStatus = handleMessage( message, wParam, lParam );
break;
}
const BasicWindow *parent;
if( (parent=getParent()) != NULL )
{
if( msgStatus == psSEND_TO_PARENT )
{
parent->message( message, wParam, lParam );
msgStatus = psPROCESSED;
}
else if( msgStatus == psPOST_TO_PARENT )
{
parent->postMessage( message, wParam, lParam );
msgStatus = psPROCESSED;
}
}
LRESULT result = msgStatus == psDO_DEFAULT ? doDefault( message, wParam, lParam ) : m_callBackValue;
if( m_destroyed && m_callBackCount <= 1 )
{
clrHandle();
}
return result;
}
void CallbackWindow::checkModifiers( unsigned uMsg, WPARAM wParam, LPARAM lParam )
{
switch( uMsg )
{
case WM_SYSKEYDOWN:
case WM_KEYDOWN:
if( wParam == VK_MENU )
m_altKey = true;
else if( wParam == VK_SHIFT )
m_shiftKey = true;
else if( wParam == VK_CONTROL )
m_controlKey = true;
break;
case WM_SYSKEYUP:
case WM_KEYUP:
if( wParam == VK_MENU )
m_altKey = false;
else if( wParam == VK_SHIFT )
m_shiftKey = false;
else if( wParam == VK_CONTROL )
m_controlKey = false;
break;
case WM_CHAR:
m_altKey = lParam & (1<<29);
break;
}
}
#ifdef _MSC_VER
LRESULT CallbackWindow::controlCallback( BasicWindow *control, unsigned uMsg, WPARAM wParam, LPARAM lParam )
{
checkModifiers( uMsg, wParam, lParam );
ProcessStatus doDefault = preControlCallback( control, uMsg, wParam, lParam );
if( doDefault == psDO_DEFAULT )
m_callBackValue = DefSubclassProc( control->handle(), uMsg, wParam, lParam );
postControlCallback( control, uMsg, wParam, lParam );
return m_callBackValue;
}
#endif
ProcessStatus CallbackWindow::checkControlColor( HWND handle, HDC device )
{
BasicWindow *control = findChild( handle );
if( control )
{
const Brush &brush = control->getBackgroundBrush();
if( bool(brush) )
{
COLORREF backgroundColor = brush.getBackgroundColor();
SetBkColor( device, backgroundColor );
m_callBackValue = LRESULT(HBRUSH(brush));
return psPROCESSED;
}
}
return psDO_DEFAULT;
}
// --------------------------------------------------------------------- //
// ----- class virtuals ------------------------------------------------ //
// --------------------------------------------------------------------- //
bool CallbackWindow::handleTreeViewDrag( TreeView *m_dragTreeView, TreeNode *m_dragItem, TreeNode *dragOver )
{
bool allow = false;
const BasicWindow *parent = getParent();
if( parent && (parent->getWindowClass() & CallbackWindowFlag) )
{
CallbackWindow *cbParent = static_cast<CallbackWindow *>(
const_cast<BasicWindow*>( parent )
);
allow = cbParent->handleTreeViewDrag( m_dragTreeView, m_dragItem, dragOver );
}
return allow;
}
void CallbackWindow::handleTreeViewDrop( TreeView *m_dragTreeView, TreeNode *m_dragItem, TreeNode *dropTarget )
{
const BasicWindow *parent = getParent();
if( parent && (parent->getWindowClass() & CallbackWindowFlag) )
{
CallbackWindow *cbParent = static_cast<CallbackWindow *>(
const_cast<BasicWindow*>( parent )
);
cbParent->handleTreeViewDrop( m_dragTreeView, m_dragItem, dropTarget );
}
}
SuccessCode CallbackWindow::close()
{
removeTimer();
removeToolHelp();
removeStatusBar();
m_closed = true;
return BasicWindow::close();
}
ProcessStatus CallbackWindow::handleShow()
{
return psDO_DEFAULT;
}
ProcessStatus CallbackWindow::handleHide()
{
return psDO_DEFAULT;
}
ProcessStatus CallbackWindow::handleCreate()
{
return psPROCESSED; // don't call default funtion
}
void CallbackWindow::getControls()
{
}
SuccessCode CallbackWindow::handleClose()
{
if( canClose() )
return close();
return scERROR;
}
ProcessStatus CallbackWindow::handleDestroy()
{
return psPROCESSED;
}
void CallbackWindow::handleActivate( bool )
{
}
ProcessStatus CallbackWindow::handleResize( const Size &newSize )
{
doLayout( newSize );
return psDO_DEFAULT;
}
ProcessStatus CallbackWindow::handleErase( Device &hDC )
{
const Brush &background = getBackgroundBrush();
if( bool(background) )
{
Size size = getClientSize();
hDC.getPen().selectPen( Pen::spNull );
hDC.selectBrush( background );
hDC.rectangle( 0, 0, size.width+1, size.height+1 );
return psPROCESSED;
}
return psDO_DEFAULT;
}
ProcessStatus CallbackWindow::handleRepaint( Device & )
{
return psDO_DEFAULT;
}
ProcessStatus CallbackWindow::handleEditChange( int /* editControl */ )
{
return psSEND_TO_PARENT;
}
ProcessStatus CallbackWindow::handleSelectionChange( int /* control */ )
{
return psSEND_TO_PARENT;
}
ProcessStatus CallbackWindow::handleNotification( int /* notification*/ , int /* control */ )
{
return psSEND_TO_PARENT;
}
ProcessStatus CallbackWindow::handleButtonClick( int buttonControl )
{
// for legacy code
return handleCommand( buttonControl );
}
ProcessStatus CallbackWindow::handleCommand( int /* command */ )
{
return psPOST_TO_PARENT;