-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlgdragi.c
500 lines (439 loc) · 22.6 KB
/
dlgdragi.c
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
/*********************************************************************
* *
* MODULE NAME : dlgdragi.c AUTHOR: Rick Fishman *
* DATE WRITTEN: 07-26-93 *
* *
* MODULE DESCRIPTION: *
* *
* Part of the 'DRGDROP' drag/drop sample program. *
* *
* Dialog box in the Settings notebook that handles all DRAGINFO *
* and DRAGITEM parameters except for the RMF string which is *
* handled in dlgrmf.c. *
* *
* NOTES: *
* *
* FUNCTIONS CALLABLE BY OTHER MODULES: *
* *
* wpDragInfo *
* *
* *
* HISTORY: *
* *
* 07-26-93 - Program coded. *
* 12-05-93 - Use TYPE array to convert to proper DLGINFO.szType. *
* *
* Rick Fishman *
* Code Blazers, Inc. *
* 4113 Apricot *
* Irvine, CA. 92720 *
* CIS ID: 72251,750 *
* *
* *
*********************************************************************/
#pragma strings(readonly) // used for debug version of memory mgmt routines
/*********************************************************************/
/*------- Include relevant sections of the OS/2 header files --------*/
/*********************************************************************/
#define INCL_WINBUTTONS
#define INCL_WINDIALOGS
#define INCL_WINENTRYFIELDS
#define INCL_WINERRORS
#define INCL_WINFRAMEMGR
#define INCL_WINLISTBOXES
#define INCL_WINSTDCNR
#define INCL_WINSTDDRAG
#define INCL_WINWINDOWMGR
/*********************************************************************/
/*----------------------------- INCLUDES ----------------------------*/
/*********************************************************************/
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "drgdrop.h"
/*********************************************************************/
/*------------------- APPLICATION DEFINITIONS -----------------------*/
/*********************************************************************/
/*********************************************************************/
/*---------------------------- STRUCTURES ---------------------------*/
/*********************************************************************/
/*********************************************************************/
/*----------------------- FUNCTION PROTOTYPES -----------------------*/
/*********************************************************************/
static void InitControls( HWND hwndDlg );
static BOOL wmCommand( HWND hwndDlg, USHORT idCommand );
static void wmControl( HWND hwndDlg, USHORT idControl, USHORT usEvent );
static void Undo( HWND hwndDlg );
static void Defaults( HWND hwndDlg );
static void UpdateGlobalDlgInfo( PDLGINFO pDlgInfoNew );
static void UpdateControls( HWND hwndDlg );
static void DumpDlgInfo( HWND hwndDlg );
/*********************************************************************/
/*------------------------ GLOBAL VARIABLES -------------------------*/
/*********************************************************************/
/**********************************************************************/
/*---------------------------- wpDragInfo ----------------------------*/
/* */
/* DIALOG BOX PROCEDURE FOR THE DRAGINFO DIALOG BOX */
/* */
/* PARMS: standard window proc parms */
/* */
/* NOTES: */
/* */
/* RETURNS: message result */
/* */
/*--------------------------------------------------------------------*/
/**********************************************************************/
MRESULT EXPENTRY wpDragInfo( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
switch( msg )
{
case WM_INITDLG:
InitControls( hwnd );
return (MRESULT) TRUE; // Return TRUE to retain any changed focus
case WM_COMMAND:
if( wmCommand( hwnd, SHORT1FROMMP( mp1 ) ) )
return 0;
else
break;
case WM_SETFOCUS:
if( mp2 )
WinPostMsg( hwnd, UM_SET_FOCUS, NULL, NULL );
break;
case UM_SET_FOCUS:
{
PPAGEDATA pPageData = WinQueryWindowPtr( hwnd, QWL_USER );
if( pPageData )
WinSetFocus( HWND_DESKTOP,
WinWindowFromID( hwnd, pPageData->idFocus ) );
return 0;
}
case WM_CONTROL:
wmControl( hwnd, SHORT1FROMMP( mp1 ), SHORT2FROMMP( mp1 ) );
return 0;
case UM_GET_FOCUS_ID:
return (MRESULT) CB_OPERATION;
case UM_DUMP_DLGINFO:
DumpDlgInfo( hwnd );
break;
}
return WinDefDlgProc( hwnd, msg, mp1, mp2 );
}
/**********************************************************************/
/*---------------------------- InitControls --------------------------*/
/* */
/* INITIALIZE ALL CONTROLS ON THE DIALOG BOX. */
/* */
/* PARMS: window handle of dialog box */
/* */
/* NOTES: */
/* */
/* RETURNS: nothing */
/* */
/*--------------------------------------------------------------------*/
/**********************************************************************/
void InitControls( HWND hwndDlg )
{
int i;
HWND hwndLB;
hwndLB = WinWindowFromID( hwndDlg, CB_OPERATION );
for( i = 0; i < cOperations; i++ )
WinInsertLboxItem( hwndLB, LIT_END, dcOperation[ i ].szItem );
hwndLB = WinWindowFromID( hwndDlg, CB_TYPE );
for( i = 0; i < cTypes; i++ )
WinInsertLboxItem( hwndLB, LIT_END, ntsType[ i ].szName );
hwndLB = WinWindowFromID( hwndDlg, LB_CONTROL );
for( i = 0; i < cControlTypes; i++ )
WinInsertLboxItem( hwndLB, LIT_END, dcControl[ i ].szItem );
hwndLB = WinWindowFromID( hwndDlg, LB_SUPPORTEDOPS );
for( i = 0; i < cSupportedOps; i++ )
WinInsertLboxItem( hwndLB, LIT_END, dcSupportedOp[ i ].szItem );
SetEFTextLimit( hwndDlg, EF_ITEMID, 8 );
SetEFTextLimit( hwndDlg, CB_TYPE, TYPE_LEN );
SetEFTextLimit( hwndDlg, EF_CNR_NAME, CCHMAXPATH );
SetEFTextLimit( hwndDlg, EF_SOURCE_NAME, CCHMAXPATH );
SetEFTextLimit( hwndDlg, EF_TARGET_NAME, CCHMAXPATH );
UpdateControls( hwndDlg );
}
/**********************************************************************/
/*---------------------------- wmCommand -----------------------------*/
/* */
/* THE DIALOG PROC GOT A WM_COMMAND MESSAGE. */
/* */
/* PARMS: dialog box window handle, */
/* command id */
/* */
/* NOTES: */
/* */
/* RETURNS: TRUE or FALSE if command was processed */
/* */
/*--------------------------------------------------------------------*/
/**********************************************************************/
BOOL wmCommand( HWND hwndDlg, USHORT idCommand )
{
BOOL fProcessed = FALSE;
switch( idCommand )
{
case DID_OK:
case DID_CANCEL:
fProcessed = TRUE;
break;
case PB_UNDO:
Undo( hwndDlg );
fProcessed = TRUE;
break;
case PB_DEFAULT:
Defaults( hwndDlg );
fProcessed = TRUE;
break;
}
return fProcessed;
}
/**********************************************************************/
/*------------------------------- Undo -------------------------------*/
/* */
/* UNDO (GET THE DLGINFO DATA FROM THE INI FILE) */
/* */
/* PARMS: dialog box window handle */
/* */
/* NOTES: */
/* */
/* RETURNS: nothing */
/* */
/*--------------------------------------------------------------------*/
/**********************************************************************/
void Undo( HWND hwndDlg )
{
DLGINFO dlgInfoLocal;
if( RetrieveDlgInfo( ANCHOR( hwndDlg ), &dlgInfoLocal ) )
{
UpdateGlobalDlgInfo( &dlgInfoLocal );
UpdateControls( hwndDlg );
}
else
Defaults( hwndDlg );
}
/**********************************************************************/
/*---------------------------- Defaults ------------------------------*/
/* */
/* SET THE DLGINFO STRUCTURE BACK TO DEFAULTS (ONLY OUR FIELDS) */
/* */
/* PARMS: dialog box window handle */
/* */
/* NOTES: */
/* */
/* RETURNS: nothing */
/* */
/*--------------------------------------------------------------------*/
/**********************************************************************/
void Defaults( HWND hwndDlg )
{
UpdateGlobalDlgInfo( &dlgInfoDefaults );
UpdateControls( hwndDlg );
}
/**********************************************************************/
/*------------------------ UpdateGlobalDlgInfo -----------------------*/
/* */
/* UPDATE OUR FIELDS IN THE GLOBAL DLGINFO STRUCTURE */
/* */
/* PARMS: pointer to a local DLGINFO structure */
/* */
/* NOTES: */
/* */
/* RETURNS: nothing */
/* */
/*--------------------------------------------------------------------*/
/**********************************************************************/
void UpdateGlobalDlgInfo( PDLGINFO pDlgInfoNew )
{
dlgInfo.fUseDlgDragNames = pDlgInfoNew->fUseDlgDragNames;
dlgInfo.fUseDlgItemID = pDlgInfoNew->fUseDlgItemID;
dlgInfo.ulItemID = pDlgInfoNew->ulItemID;
dlgInfo.usOperation = pDlgInfoNew->usOperation;
dlgInfo.fsControl = pDlgInfoNew->fsControl;
dlgInfo.fsSupportedOps = pDlgInfoNew->fsSupportedOps;
strcpy( dlgInfo.szType, pDlgInfoNew->szType );
strcpy( dlgInfo.szContainerName, pDlgInfoNew->szContainerName );
strcpy( dlgInfo.szSourceName, pDlgInfoNew->szSourceName );
strcpy( dlgInfo.szTargetName, pDlgInfoNew->szTargetName );
}
/**********************************************************************/
/*----------------------------- wmControl ----------------------------*/
/* */
/* THE DIALOG PROC GOT A WM_CONTROL MESSAGE. */
/* */
/* PARMS: dialog box window handle, */
/* control id, */
/* notify code */
/* */
/* NOTES: */
/* */
/* RETURNS: nothing */
/* */
/*--------------------------------------------------------------------*/
/**********************************************************************/
void wmControl( HWND hwndDlg, USHORT idControl, USHORT usEvent )
{
switch( idControl )
{
case CHK_OVERRIDE_HSTRS:
if( usEvent == BN_CLICKED )
{
BOOL fChecked = WinQueryButtonCheckstate( hwndDlg,
CHK_OVERRIDE_HSTRS );
WinEnableControl( hwndDlg, EF_CNR_NAME, fChecked );
WinEnableControl( hwndDlg, EF_SOURCE_NAME, fChecked );
WinEnableControl( hwndDlg, EF_TARGET_NAME, fChecked );
WinEnableControl( hwndDlg, ST_CNR_NAME, fChecked );
WinEnableControl( hwndDlg, ST_SOURCE_NAME, fChecked );
WinEnableControl( hwndDlg, ST_TARGET_NAME, fChecked );
}
break;
case CHK_OVERRIDE_ID:
if( usEvent == BN_CLICKED )
{
BOOL fChecked = WinQueryButtonCheckstate( hwndDlg,
CHK_OVERRIDE_ID );
WinEnableControl( hwndDlg, EF_ITEMID, fChecked );
WinEnableControl( hwndDlg, ST_ITEMID, fChecked );
}
break;
}
}
/**********************************************************************/
/*-------------------------- UpdateControls --------------------------*/
/* */
/* UPDATE THE CONTROLS IN THE DIALOG BOX */
/* */
/* PARMS: dialog box window handle */
/* */
/* NOTES: */
/* */
/* RETURNS: nothing */
/* */
/*--------------------------------------------------------------------*/
/**********************************************************************/
void UpdateControls( HWND hwndDlg )
{
int i;
char szFromUl[ 9 ];
HWND hwndLB;
hwndLB = WinWindowFromID( hwndDlg, LB_CONTROL );
WinSendMsg( hwndLB, LM_SELECTITEM, MPFROMSHORT( LIT_NONE ),
MPFROMLONG( FALSE ) );
for( i = 0; i < cControlTypes; i++ )
if( dlgInfo.fsControl & dcControl[ i ].iItem )
WinSendMsg( hwndLB, LM_SELECTITEM, MPFROMSHORT( i ),
MPFROMLONG( TRUE ) );
hwndLB = WinWindowFromID( hwndDlg, LB_SUPPORTEDOPS );
WinSendMsg( hwndLB, LM_SELECTITEM, MPFROMSHORT( LIT_NONE ),
MPFROMLONG( FALSE ) );
for( i = 0; i < cSupportedOps; i++ )
if( dlgInfo.fsSupportedOps & dcSupportedOp[ i ].iItem )
WinSendMsg( hwndLB, LM_SELECTITEM, MPFROMSHORT( i ),
MPFROMLONG( TRUE ) );
for( i = 0; i < cOperations; i++ )
if( dlgInfo.usOperation == dcOperation[ i ].iItem )
{
WinSetDlgItemText( hwndDlg, CB_OPERATION, dcOperation[ i ].szItem );
break;
}
if( i == cOperations )
WinSetDlgItemText( hwndDlg, CB_OPERATION,
_ultoa( (ULONG)dlgInfo.usOperation, szFromUl, 16 ) );
if( dlgInfo.ulItemID )
WinSetDlgItemText( hwndDlg, EF_ITEMID,
_ultoa( dlgInfo.ulItemID, szFromUl, 16 ) );
else
WinSetDlgItemText( hwndDlg, EF_ITEMID, "" );
WinSetDlgItemText( hwndDlg, CB_TYPE, dlgInfo.szType );
for( i = 0; i < cTypes; i++ )
{
if( !stricmp( ntsType[ i ].szString, dlgInfo.szType ) )
WinSetDlgItemText( hwndDlg, CB_TYPE, ntsType[ i ].szName );
}
WinSetDlgItemText( hwndDlg, EF_CNR_NAME, dlgInfo.szContainerName );
WinSetDlgItemText( hwndDlg, EF_SOURCE_NAME, dlgInfo.szSourceName );
WinSetDlgItemText( hwndDlg, EF_TARGET_NAME, dlgInfo.szTargetName );
WinCheckButton( hwndDlg, CHK_OVERRIDE_ID, dlgInfo.fUseDlgItemID );
WinCheckButton( hwndDlg, CHK_OVERRIDE_HSTRS, dlgInfo.fUseDlgDragNames );
WinEnableControl( hwndDlg, EF_ITEMID, dlgInfo.fUseDlgItemID );
WinEnableControl( hwndDlg, ST_ITEMID, dlgInfo.fUseDlgItemID );
WinEnableControl( hwndDlg, EF_CNR_NAME, dlgInfo.fUseDlgDragNames );
WinEnableControl( hwndDlg, EF_SOURCE_NAME, dlgInfo.fUseDlgDragNames );
WinEnableControl( hwndDlg, EF_TARGET_NAME, dlgInfo.fUseDlgDragNames );
WinEnableControl( hwndDlg, ST_CNR_NAME, dlgInfo.fUseDlgDragNames );
WinEnableControl( hwndDlg, ST_SOURCE_NAME, dlgInfo.fUseDlgDragNames );
WinEnableControl( hwndDlg, ST_TARGET_NAME, dlgInfo.fUseDlgDragNames );
}
/**********************************************************************/
/*--------------------------- DumpDlgInfo ----------------------------*/
/* */
/* DUMP OUR CONTROL TEXT TO THE GLOBAL DLGINFO STRUCTURE */
/* */
/* PARMS: dialog box window handle */
/* */
/* NOTES: */
/* */
/* RETURNS: nothing */
/* */
/*--------------------------------------------------------------------*/
/**********************************************************************/
void DumpDlgInfo( HWND hwndDlg )
{
char szToUl[ 50 ];
int i;
SHORT sItemIndex;
HWND hwndLB;
WinQueryDlgItemText( hwndDlg, CB_OPERATION, sizeof szToUl, szToUl );
for( i = 0; i < cOperations; i++ )
if( strcmp( szToUl, dcOperation[ i ].szItem ) == 0 )
{
dlgInfo.usOperation = dcOperation[ i ].iItem;
break;
}
if( i == cOperations )
dlgInfo.usOperation = atol( szToUl );
hwndLB = WinWindowFromID( hwndDlg, LB_CONTROL );
dlgInfo.fsControl = 0;
sItemIndex = LIT_FIRST;
do
{
sItemIndex = SHORT1FROMMR( WinSendMsg( hwndLB, LM_QUERYSELECTION,
MPFROMSHORT( sItemIndex ), NULL ) );
if( sItemIndex != LIT_NONE )
dlgInfo.fsControl |= dcControl[ sItemIndex ].iItem;
} while( sItemIndex != LIT_NONE );
hwndLB = WinWindowFromID( hwndDlg, LB_SUPPORTEDOPS );
dlgInfo.fsSupportedOps = 0;
sItemIndex = LIT_FIRST;
do
{
sItemIndex = SHORT1FROMMR( WinSendMsg( hwndLB, LM_QUERYSELECTION,
MPFROMSHORT( sItemIndex ), NULL ) );
if( sItemIndex != LIT_NONE )
dlgInfo.fsSupportedOps |= dcSupportedOp[ sItemIndex ].iItem;
} while( sItemIndex != LIT_NONE );
WinQueryDlgItemText( hwndDlg, EF_ITEMID, sizeof szToUl, szToUl );
dlgInfo.ulItemID = atol( szToUl );
WinQueryDlgItemText( hwndDlg, CB_TYPE, sizeof dlgInfo.szType,
dlgInfo.szType );
for( i = 0; i < cTypes; i++ )
{
if( !stricmp( ntsType[ i ].szName, dlgInfo.szType ) )
strcpy( dlgInfo.szType, ntsType[ i ].szString );
}
WinQueryDlgItemText( hwndDlg, EF_CNR_NAME, sizeof dlgInfo.szContainerName,
dlgInfo.szContainerName );
WinQueryDlgItemText( hwndDlg, EF_SOURCE_NAME, sizeof dlgInfo.szSourceName,
dlgInfo.szSourceName );
WinQueryDlgItemText( hwndDlg, EF_TARGET_NAME, sizeof dlgInfo.szTargetName,
dlgInfo.szTargetName );
dlgInfo.fUseDlgItemID = WinQueryButtonCheckstate( hwndDlg,CHK_OVERRIDE_ID );
dlgInfo.fUseDlgDragNames =
WinQueryButtonCheckstate( hwndDlg, CHK_OVERRIDE_HSTRS );
}
/*********************************************************************
* E N D O F S O U R C E *
*********************************************************************/