-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCALLWIN.H
More file actions
646 lines (555 loc) · 15.4 KB
/
CALLWIN.H
File metadata and controls
646 lines (555 loc) · 15.4 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
/*
Project: Windows Class Library
Module: CALLWIN.H
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-2026 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.
*/
#ifndef CALL_WIN_H
#define CALL_WIN_H
// --------------------------------------------------------------------- //
// ----- 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 <shellapi.h>
#include <commdlg.h>
#include <Commctrl.h>
#ifdef _MSC_VER
# pragma warning( pop )
#endif
#include <gak/list.h>
#include <gak/string.h>
#include <winlib/basicwin.h>
#include <winlib/winapp.h>
#include <winlib/font.h>
#include <WINLIB/Layout.h>
#include "accelerators.h"
// --------------------------------------------------------------------- //
// ----- module switches ----------------------------------------------- //
// --------------------------------------------------------------------- //
#ifdef __BORLANDC__
# pragma option -RT-
# pragma option -b
# pragma option -a4
# pragma option -pc
#endif
#ifdef _MSC_VER
# pragma comment( lib, "Comctl32.lib" )
#endif
namespace winlib
{
// --------------------------------------------------------------------- //
// ----- constants ----------------------------------------------------- //
// --------------------------------------------------------------------- //
const int STATUS_HEIGHT =20;
const int APPL_TIMER_ID =1;
const int TOOL_WIN_TIMER_ID =2;
// --------------------------------------------------------------------- //
// ----- type definitions ---------------------------------------------- //
// --------------------------------------------------------------------- //
enum _ProcessStatus { psPROCESSED, psDO_DEFAULT, psSEND_TO_PARENT, psPOST_TO_PARENT };
typedef EnumWrapper<_ProcessStatus> ProcessStatus;
enum HorizScrollCode
{
hscLEFT=SB_LEFT,
hscLINE_LEFT=SB_LINELEFT, hscPAGE_LEFT=SB_PAGELEFT,
hscLINE_RIGHT=SB_LINERIGHT, hscPAGE_RIGHT=SB_PAGERIGHT,
hscRIGHT=SB_RIGHT,
hscTHUMB_POSITION=SB_THUMBPOSITION,hscTHUMB_TRACK=SB_THUMBTRACK
};
enum VertScrollCode
{
vscTOP=SB_TOP,
vscLINE_UP=SB_LINEUP, vscPAGE_UP=SB_PAGEUP,
vscLINE_DOWN=SB_LINEDOWN, vscPAGE_DOWN=SB_PAGEDOWN,
vscBOTTOM=SB_BOTTOM,
vscTHUMB_POSITION=SB_THUMBPOSITION,vscTHUMB_TRACK=SB_THUMBTRACK
};
enum LeftButton
{
lbDOUBLE_CLICK=WM_LBUTTONDBLCLK,
lbDOWN=WM_LBUTTONDOWN,
lbUP=WM_LBUTTONUP
};
enum RightButton
{
rbDOUBLE_CLICK=WM_RBUTTONDBLCLK,
rbDOWN=WM_RBUTTONDOWN,
rbUP=WM_RBUTTONUP
};
// --------------------------------------------------------------------- //
// ----- class definitions --------------------------------------------- //
// --------------------------------------------------------------------- //
class SearchDialog;
class ToolTipWindow;
class ControlWindow;
class TreeView;
class TreeNode;
class EDIT;
class Device;
/*
The Call Window Class
=====================
The "Call Window Class" describes a window which has a call back.
*/
class CallbackWindow : public BasicWindow, public gak::ListEntry
{
friend LRESULT PASCAL WindowProc( HWND, UINT, WPARAM, LPARAM );
friend LRESULT PASCAL MDIchildWindowProc( HWND, UINT, WPARAM, LPARAM );
#ifdef _MSC_VER
friend LRESULT CALLBACK controlProcedure(HWND, UINT, WPARAM, LPARAM, UINT_PTR, DWORD_PTR );
#endif
friend class MDIwindow;
friend class ModalDialog;
friend class NonModalDialog;
friend class MDIchildWindow;
// data
private:
static HACCEL s_hAccel;
static AcceleratorMap s_accelerators;
static UINT s_findMessage;
static SearchDialog *s_findDialog;
Menu *m_menu;
EDIT *m_statusBar;
ToolTipWindow *m_toolWin;
bool m_applicationTimer, m_toolWinTimer;
TreeView *m_dragTreeView;
TreeNode *m_dragItem;
bool m_allowNotifications;
bool m_dialogProcessing;
bool m_terminate, m_closed, m_destroyed;
bool m_altKey, m_shiftKey, m_controlKey;
#ifndef NDEBUG
gak::Stack<UINT> m_messageStack;
bool m_watchMe;
#endif
int m_callBackCount;
LayoutManager *m_layoutManager;
Size m_clientSize;
protected:
LRESULT m_callBackValue;
protected:
void watch()
{
#ifndef NDEBUG
m_watchMe = true;
#endif
}
static void fillDefaultClass( WNDCLASS *wc )
{
/*
make the class global, so that it can be used by resource DLLs
*/
wc->style = CS_GLOBALCLASS;
wc->lpfnWndProc = WindowProc;
wc->cbClsExtra = 0;
wc->cbWndExtra = 0;
wc->hInstance = Application::getAppInstance();
wc->hIcon = appObject->getIcon();
wc->hCursor = LoadCursor( 0, IDC_ARROW );
wc->hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc->lpszMenuName = NULL;
}
static bool registerClass( WNDCLASS *wc )
{
return ::RegisterClass( wc ) ? true : false;
}
// creating and destroying
protected:
CallbackWindow( BasicWindow *owner );
~CallbackWindow();
public:
static void registerSearchDialog( SearchDialog *newFindDialog );
protected:
bool isShiftKey() const
{
return m_shiftKey;
}
bool isAltKey() const
{
return m_altKey;
}
bool isControlKey() const
{
return m_controlKey;
}
void setClosedFlag()
{
m_closed = true;
}
bool mayBeDeleted() const
{
return bool(m_closed && m_destroyed);
}
protected:
SuccessCode create( BasicWindow *parent, LPSTR lpParam=NULL )
{
SuccessCode error = BasicWindow::create( parent, m_menu, lpParam );
if( error == scSUCCESS )
{
getFont().selectFont( Font::sfAnsiVar );
// getFont().setFontName("MS Sans Serif").setFontSize(8).create();
}
return error;
}
public:
virtual SuccessCode close();
void acceptFiles()
{
DragAcceptFiles( handle(), true );
}
void noFileAccept()
{
DragAcceptFiles( handle(), true );
}
// mouse capture
protected:
void captureMouse()
{
SetCapture( handle() );
}
void releaseMouse()
{
ReleaseCapture();
}
/*
===============================================================================================
the message functions routines
===============================================================================================
*/
// WM_INITDIALOG and WM_CREATE
public:
virtual ProcessStatus handleCreate();
virtual void getControls();
// WM_CLOSE
virtual SuccessCode handleClose();
// WM_DESTROY
virtual ProcessStatus handleDestroy();
// WM_SHOWWINDOW
virtual ProcessStatus handleShow();
virtual ProcessStatus handleHide();
// WM_MDIACTIVATE
virtual void handleActivate( bool );
// WM_ERASEBKGND
virtual ProcessStatus handleErase( Device &hDC );
// WM_PAINT
virtual ProcessStatus handleRepaint( Device &hDC );
// WM_COMMAND
virtual ProcessStatus handleEditChange( int control );
virtual ProcessStatus handleButtonClick( int control );
virtual ProcessStatus handleSelectionChange( int control );
virtual ProcessStatus handleNotification( int notification, int control );
virtual ProcessStatus handleCommand( int cmd );
// WM_VSCROLL, WM_HSCROLL
virtual ProcessStatus handleScrollControl( int control );
virtual ProcessStatus handleVertScroll( VertScrollCode scrollCode, int nPos, HWND scrollBar );
virtual ProcessStatus handleHorizScroll( HorizScrollCode scrollCode, int nPos, HWND scrollBar );
// WM_CAPTURECHANGED
virtual ProcessStatus handleMouseRelease();
// WM_MOUSEMOVE
virtual ProcessStatus handleMouseMove( WPARAM modifier, const Point &position );
// WM_LBUTTONDBLCLK, WM_LBUTTONDOWN, WM_LBUTTONUP
virtual ProcessStatus handleLeftButton( LeftButton leftButton, WPARAM modifier, const Point &position );
// WM_RBUTTONDBLCLK, WM_RBUTTONDOWN, WM_RBUTTONUP
virtual ProcessStatus handleRightButton( RightButton rightButton, WPARAM modifier, const Point &position );
// WM_RESIZE
virtual ProcessStatus handleResize( const Size &newSize );
// WM_DROPFILES
virtual void handleFile( const char *filename, size_t idx, size_t numFiles );
private:
void handleFiles( HDROP );
protected:
// find & replace dialogs
virtual void handleFind( const char *, bool, bool, bool );
virtual void handleReplace( const char *, const char *,
bool, bool, bool );
// WM_DDE_INITIATE
virtual ProcessStatus ddeInitiate( const char *app, const char *topic );
// WM_DDE_EXECUTE
virtual ProcessStatus ddeExecute( const char *command );
// WM_HELP
virtual void showHelp( int controlType, int controlId );
// WM_TIMER
virtual void handleTimer();
// WM_SETFOCUS
virtual void handleFocus();
// WM_SYSKEYDOWN, WM_KEYDOWN
virtual ProcessStatus handleKeyDown( int key );
// WM_SYSKEYUP, WM_KEYUP
virtual ProcessStatus handleKeyUp( int key );
// WM_CHAR
virtual ProcessStatus handleCharacterInput( int c );
// WM_KILLFOCUS
virtual void handleKillFocus();
// WM_ASYNC_TASK_END
virtual void handleAsyncTaskEnd( void *data );
// WM_COPYDATA
virtual ProcessStatus handleData(const ForeignWindow &src, int dataType, const void *data, size_t size);
// all other messages
virtual ProcessStatus handleMessage( UINT msg, WPARAM wParam, LPARAM lParam );
virtual LRESULT doDefault( UINT, WPARAM, LPARAM );
void handleFindReplace( FINDREPLACE *buffer );
void checkModifiers( unsigned msg, WPARAM wParam, LPARAM lParam );
void checkModifiers( const MSG &msg )
{
checkModifiers( msg.message, msg.wParam, msg.lParam );
}
LRESULT callBack( const unsigned msg, const WPARAM wParam, const LPARAM lParam );
bool active() const
{
return m_callBackCount > 0;
}
static LRESULT dispatch( HWND handle, unsigned msg, WPARAM wParam, LPARAM lParam );
virtual bool handleTreeViewDrag( TreeView *m_dragTreeView, TreeNode *m_dragItem, TreeNode *dragOver );
virtual void handleTreeViewDrop( TreeView *m_dragTreeView, TreeNode *m_dragItem, TreeNode *dropTarget );
/*
message loop
*/
protected:
void terminateLoop()
{
m_terminate = true;
}
public:
void mainLoop();
void exitApplication( int exitCode = 0 )
{
PostQuitMessage( exitCode );
}
/*
control messages
*/
#ifdef _MSC_VER
private:
LRESULT controlCallback( BasicWindow *control, unsigned uMsg, WPARAM wParam, LPARAM lParam );
protected:
virtual ProcessStatus preControlCallback( BasicWindow *control, unsigned uMsg, WPARAM wParam, LPARAM lParam );
virtual void postControlCallback( BasicWindow *control, unsigned uMsg, WPARAM wParam, LPARAM lParam );
void catchControl( BasicWindow *control )
{
SetWindowSubclass( control->handle(), controlProcedure, UINT_PTR(control), DWORD_PTR(this) );
}
void releaseControl( BasicWindow *control )
{
RemoveWindowSubclass( control->handle(), controlProcedure, UINT_PTR(control) );
}
public:
#endif
/*
accelerators
*/
virtual bool translateAccell( MSG &msg ) const;
static void setAccelerators( const char *accelerators )
{
s_hAccel = accelerators ? appObject->loadAccelerators( accelerators ) : 0;
}
static void setAccelerators( int id )
{
s_hAccel = appObject->loadAccelerators( id );
}
static void setAccelerators( ACCEL *accelerators, int numItems )
{
s_hAccel = CreateAcceleratorTable( accelerators, numItems );
s_accelerators.addElements( static_cast<Accelerators*>(accelerators), numItems );
}
static Accelerators* getAccelerator( int comand )
{
return s_accelerators.hasElement( comand ) ? &s_accelerators[comand] : NULL;
}
/*
dialogs
*/
private:
bool isDialogMessage( MSG &msg );
public:
void allowDialogProcessing()
{
m_dialogProcessing = true;
}
void allowNotifications()
{
m_allowNotifications = true;
}
void disallowNotifications()
{
m_allowNotifications = false;
}
void doModalDialog( int id );
/*
menu_bar
*/
template <class MENU_T>
const Menu *setMenu( MENU_T menuName )
{
if( m_menu )
delete m_menu;
return m_menu = appObject->loadMenu( menuName );
}
const Menu *getMenu() const
{
return m_menu;
}
void drawMenuBar() const
{
DrawMenuBar( handle() );
}
/*
timer
*/
private:
void removeTimer( bool appTimer )
{
KillTimer( handle(), appTimer ? APPL_TIMER_ID : TOOL_WIN_TIMER_ID );
if( appTimer )
m_applicationTimer = false;
else
m_toolWinTimer = false;
}
void createTimer( int milliSeconds, bool appTimer )
{
if( milliSeconds )
{
SetTimer( handle(), appTimer ? APPL_TIMER_ID : TOOL_WIN_TIMER_ID, milliSeconds, NULL );
if( appTimer )
m_applicationTimer = true;
else
m_toolWinTimer = true;
}
else
removeTimer( appTimer );
}
public:
void createToolTimer()
{
createTimer( 3000, false );
}
void setTimer( int milliSeconds )
{
createTimer( milliSeconds, true );
}
void removeTimer()
{
removeTimer( true );
}
bool hasTimer() const
{
return m_applicationTimer;
}
/*
tool help
*/
void showToolHelp( const char *text );
void removeToolHelp();
void processTooltipTimer();
/*
status bar
*/
private:
void resizeStatusBar( Size *mySize );
public:
void addStatusBar();
bool hasStatusBar() const
{
return( m_statusBar ) ? true : false;
}
void setStatusText( const STRING &value );
void removeStatusBar();
/*
scrolling
*/
void scrollHorizontal( int position )
{
handleHorizScroll( hscTHUMB_POSITION, position, NULL );
}
void scrollVertical( int position )
{
handleVertScroll( vscTHUMB_POSITION, position, NULL );
}
/*
control windows
*/
private:
ProcessStatus checkControlColor( HWND handle, HDC device );
/*
children and layout manager
*/
public:
void setLayoutManager( LayoutManager *newLayoutManager )
{
if( m_layoutManager )
delete m_layoutManager;
m_layoutManager = newLayoutManager;
}
LayoutManager *getLayoutManager() const
{
return m_layoutManager;
}
Size calcSize( const Size &newSize ) const
{
Size result;
if( m_layoutManager )
{
result = m_layoutManager->calcSize( getChildren(), newSize );
}
else
{
result = newSize;
}
return result;
}
void doLayout( const Size &newSize ) const
{
if( m_layoutManager )
{
m_layoutManager->doLayout( getChildren(), newSize );
invalidateWindow();
}
}
void doLayout() const
{
if( m_layoutManager )
{
m_layoutManager->doLayout( getChildren(), getClientSize() );
invalidateWindow();
}
}
};
} // namespace winlib
#ifdef __BORLANDC__
# pragma option -RT.
# pragma option -b.
# pragma option -a.
# pragma option -p.
#endif
#endif