summaryrefslogtreecommitdiffstats
path: root/private/unimodem/modemui/advsett.c
blob: c63c897a0e6e482d025fe17b0c18aa0858d204ee (plain) (blame)
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
//---------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation 1993-1994
//
// File: advsett.c
//
// This files contains the dialog code for the Advanced Connection Settings
// dialog.
//
// History:
//  3-08-94 ScottH     Created
//
//---------------------------------------------------------------------------


/////////////////////////////////////////////////////  INCLUDES

#include "proj.h"         // common headers

#ifdef WIN95
#include "..\..\..\..\win\core\inc\help.h"
#endif

/////////////////////////////////////////////////////  CONTROLLING DEFINES

/////////////////////////////////////////////////////  TYPEDEFS

typedef struct tagADVSETT
    {
    HWND hdlg;              // dialog handle
    HWND hwndErrCtl;
    HWND hwndCompress;
    HWND hwndRequired;
    HWND hwndUseCell;
    HWND hwndUseFlowCtl;
    HWND hwndHard;
    HWND hwndSoft;
    HWND hwndModulations;
    HWND hwndUserInitED;

    LPMODEMINFO pmi;        // modeminfo struct passed into dialog
        
    BOOL bSupportsCompression;
    BOOL bSupportsForcedEC;
    BOOL bSupportsCellular;
    BOOL bSaveCompression;
    BOOL bSaveForcedEC;
    BOOL bSaveCellular;

    UINT idBtnSaveFlowCtl;

    } ADVSETT, FAR * PADVSETT;


#define AdvSett_GetPtr(hwnd)           (PADVSETT)GetWindowLong(hwnd, DWL_USER)
#define AdvSett_SetPtr(hwnd, lp)       (PADVSETT)SetWindowLong(hwnd, DWL_USER, (LONG)(lp))


//-----------------------------------------------------------------------------------
//  Advanced Settings dialog code
//-----------------------------------------------------------------------------------


/*----------------------------------------------------------
Purpose: WM_INITDIALOG Handler
Returns: FALSE when we assign the control focus
Cond:    --
*/
BOOL PRIVATE AdvSett_OnInitDialog(
    PADVSETT this,
    HWND hwndFocus,
    LPARAM lParam)              // expected to be PROPSHEETINFO 
    {
    HWND hwnd = this->hdlg;
    WIN32DCB FAR * pdcb;
    DWORD dwOptions;
    DWORD dwCapOptions;
    BOOL bFlowCtlEnabled;
    MODEMSETTINGS msT;
    TCHAR sz[MAXMEDLEN];
        
    ASSERT((LPTSTR)lParam);

    this->pmi = (LPMODEMINFO)lParam;
    pdcb = &this->pmi->dcb;
    dwOptions = this->pmi->ms.dwPreferredModemOptions;
    dwCapOptions = this->pmi->devcaps.dwModemOptions;
        
    // Save away the window handles
    this->hwndErrCtl = GetDlgItem(hwnd, IDC_AM_ERRCTL);
    this->hwndCompress = GetDlgItem(hwnd, IDC_AM_COMPRESS);
    this->hwndRequired = GetDlgItem(hwnd, IDC_AM_REQUIRED);
    this->hwndUseCell = GetDlgItem(hwnd, IDC_AM_USECELL);
    this->hwndUseFlowCtl = GetDlgItem(hwnd, IDC_AM_USEFLOWCTL);
    this->hwndHard = GetDlgItem(hwnd, IDC_AM_HW);
    this->hwndSoft = GetDlgItem(hwnd, IDC_AM_SW);
    this->hwndModulations = GetDlgItem(hwnd, IDC_AM_MODULATION_LIST);
    this->hwndUserInitED = GetDlgItem(hwnd, IDC_AM_EXTRA_ED);

    Edit_LimitText(this->hwndUserInitED, LINE_LEN-1);

    // Enable controls according to the device capabilities
    Button_Enable(this->hwndErrCtl, IsFlagSet(dwCapOptions, MDM_ERROR_CONTROL));

    this->bSupportsCompression = IsFlagSet(dwCapOptions, MDM_COMPRESSION);
    Button_Enable(this->hwndCompress, this->bSupportsCompression);

    this->bSupportsForcedEC = IsFlagSet(dwCapOptions, MDM_FORCED_EC);
    Button_Enable(this->hwndRequired, this->bSupportsForcedEC);

    this->bSupportsCellular = IsFlagSet(dwCapOptions, MDM_CELLULAR);
    Button_Enable(this->hwndUseCell, this->bSupportsCellular);

    // Build modulation list _and_ set it.
    if (IsFlagSet(dwCapOptions, MDM_CCITT_OVERRIDE))
        {
        int n;
        int idSet = -1;
        int idDef;

        SetWindowRedraw(this->hwndModulations, FALSE);
        ComboBox_ResetContent(this->hwndModulations);

        // add Bell
        n = ComboBox_AddString(this->hwndModulations, SzFromIDS(g_hinst, IDS_BELL, sz, ARRAYSIZE(sz)));
        ComboBox_SetItemData(this->hwndModulations, n, 0);
        idDef = n;
        if (IsFlagClear(dwOptions, MDM_CCITT_OVERRIDE))
            {
            idSet = n;
            }

        // add CCITT
        n = ComboBox_AddString(this->hwndModulations, SzFromIDS(g_hinst, IDS_CCITT_V21V22, sz, ARRAYSIZE(sz)));
        ComboBox_SetItemData(this->hwndModulations, n, MDM_CCITT_OVERRIDE);
        if (IsFlagSet(dwOptions, MDM_CCITT_OVERRIDE))
            {
            idSet = n;
            }

        // add V.23, if present
        if (IsFlagSet(dwCapOptions, MDM_V23_OVERRIDE))
            {
            n = ComboBox_AddString(this->hwndModulations, SzFromIDS(g_hinst, IDS_CCITT_V23, sz, ARRAYSIZE(sz)));
            ComboBox_SetItemData(this->hwndModulations, n, MDM_CCITT_OVERRIDE | MDM_V23_OVERRIDE);
            if (IsFlagSet(dwOptions, MDM_CCITT_OVERRIDE) && IsFlagSet(dwOptions, MDM_V23_OVERRIDE))
                {
                idSet = n;
                }
            }

        // set current selection
        if (-1 == idSet)
            {
            idSet = idDef;
            }
        ComboBox_SetCurSel(this->hwndModulations, idSet);
        SetWindowRedraw(this->hwndModulations, TRUE);
        }
    else
        {
        ComboBox_Enable(this->hwndModulations, FALSE);
        EnableWindow(GetDlgItem(hwnd, IDC_AM_MODULATION), FALSE);
        }

    // Set the controls according to the modemsettings 
    Button_SetCheck(this->hwndErrCtl, IsFlagSet(dwCapOptions, MDM_ERROR_CONTROL) &&
                                        IsFlagSet(dwOptions, MDM_ERROR_CONTROL));
    Button_SetCheck(this->hwndCompress, this->bSupportsCompression &&
                                        IsFlagSet(dwOptions, MDM_COMPRESSION));
    Button_SetCheck(this->hwndRequired, this->bSupportsForcedEC &&
                                        IsFlagSet(dwOptions, MDM_FORCED_EC));
    Button_SetCheck(this->hwndUseCell, this->bSupportsCellular &&
                                        IsFlagSet(dwOptions, MDM_CELLULAR));

    // Default compression settings should be on when the user
    // enables error control (when it is initially turned off)
    if (this->bSupportsCompression && IsFlagClear(dwOptions, MDM_COMPRESSION))
        this->bSaveCompression = TRUE;
        
    // Base the flow control on the DCB setting
    ConvertFlowCtl(pdcb, &msT, CFC_DCBTOMS | CFC_HW_CAPABLE | CFC_SW_CAPABLE);
    bFlowCtlEnabled = IsFlagSet(msT.dwPreferredModemOptions, MDM_FLOWCONTROL_HARD) ||
                      IsFlagSet(msT.dwPreferredModemOptions, MDM_FLOWCONTROL_SOFT);
    Button_SetCheck(this->hwndUseFlowCtl, bFlowCtlEnabled);
    
    // Is the flow control enabled?
    if (bFlowCtlEnabled)
        {
        // Yes; use the preferred settings
        this->idBtnSaveFlowCtl = IsFlagSet(msT.dwPreferredModemOptions, MDM_FLOWCONTROL_HARD) ? 
                                    IDC_AM_HW : IDC_AM_SW;
        CheckRadioButton(this->hdlg, IDC_AM_HW, IDC_AM_SW, this->idBtnSaveFlowCtl);
        }
    else
        {
        // No; default to hardware if the user ever enables it
        this->idBtnSaveFlowCtl = IDC_AM_HW;
        CheckRadioButton(this->hdlg, IDC_AM_HW, IDC_AM_SW, -1);
        }

    // Enable buttons based upon setting of "owner" control
    if (FALSE == Button_GetCheck(this->hwndErrCtl))
        {
        Button_Enable(this->hwndCompress, FALSE);
        Button_Enable(this->hwndRequired, FALSE);
        Button_Enable(this->hwndUseCell, FALSE);
        }
    if (FALSE == Button_GetCheck(this->hwndUseFlowCtl))
        {
        Button_Enable(this->hwndHard, FALSE);
        Button_Enable(this->hwndSoft, FALSE);
        }

    // Other settings

    Edit_SetText(this->hwndUserInitED, this->pmi->szUserInit);

    Button_SetCheck(GetDlgItem(hwnd, IDC_LOGGING), IsFlagSet(this->pmi->uFlags, MIF_ENABLE_LOGGING));

    return TRUE;   // let USER set the initial focus
    }


/*----------------------------------------------------------
Purpose: PSN_APPLY handler
Returns: --
Cond:    --
*/
void PRIVATE AdvSett_OnApply(
    PADVSETT this)
    {
    LPDWORD pdw = &this->pmi->ms.dwPreferredModemOptions;
    WIN32DCB FAR * pdcb = &this->pmi->dcb;
    TCHAR szBuf[LINE_LEN];
    BOOL bCheck;
    MODEMSETTINGS msT;
    UINT uFlags;
    int  iSel;

    // Determine error control settings
    if (Button_GetCheck(this->hwndErrCtl))
        SetFlag(*pdw, MDM_ERROR_CONTROL);
    else
        ClearFlag(*pdw, MDM_ERROR_CONTROL);
        
    if (Button_GetCheck(this->hwndCompress))
        SetFlag(*pdw, MDM_COMPRESSION);
    else
        ClearFlag(*pdw, MDM_COMPRESSION);

    if (Button_GetCheck(this->hwndRequired))
        SetFlag(*pdw, MDM_FORCED_EC);
    else
        ClearFlag(*pdw, MDM_FORCED_EC);

    if (Button_GetCheck(this->hwndUseCell))
        SetFlag(*pdw, MDM_CELLULAR);
    else
        ClearFlag(*pdw, MDM_CELLULAR);
        
    // (We use a temporary modemsettings struct to centralize the conversion
    // logic.)
    // Determine flow control settings; enable flow control?
    msT.dwPreferredModemOptions = 0;
    if (Button_GetCheck(this->hwndUseFlowCtl))
        {
        // Yes; is hardware flow control selected?
        if (IsDlgButtonChecked(this->hdlg, IDC_AM_HW))
            {
            // Yes
            SetFlag(msT.dwPreferredModemOptions, MDM_FLOWCONTROL_HARD);
            ClearFlag(msT.dwPreferredModemOptions, MDM_FLOWCONTROL_SOFT);
            }
        else
            {
            // No
            ClearFlag(msT.dwPreferredModemOptions, MDM_FLOWCONTROL_HARD);
            SetFlag(msT.dwPreferredModemOptions, MDM_FLOWCONTROL_SOFT);
            }
        }
    else
        {
        // No
        ClearFlag(msT.dwPreferredModemOptions, MDM_FLOWCONTROL_HARD);
        ClearFlag(msT.dwPreferredModemOptions, MDM_FLOWCONTROL_SOFT);
        }
    // Always set the DCB according to the control settings.  
    ConvertFlowCtl(pdcb, &msT, CFC_MSTODCB);

    // Set the modemsettings according to the DCB.
    uFlags = 0;
    if (IsFlagSet(this->pmi->devcaps.dwModemOptions, MDM_FLOWCONTROL_HARD))
        {
        SetFlag(uFlags, CFC_HW_CAPABLE);
        }
    if (IsFlagSet(this->pmi->devcaps.dwModemOptions, MDM_FLOWCONTROL_SOFT))
        {
        SetFlag(uFlags, CFC_SW_CAPABLE);
        }
    ConvertFlowCtl(pdcb, &this->pmi->ms, CFC_DCBTOMS | uFlags);

    // Set the modulation settings
    *pdw &= ~(MDM_CCITT_OVERRIDE | MDM_V23_OVERRIDE);
    if (IsFlagSet(this->pmi->devcaps.dwModemOptions, MDM_CCITT_OVERRIDE))
        {
        iSel = ComboBox_GetCurSel(this->hwndModulations);
        *pdw |= ComboBox_GetItemData(this->hwndModulations, iSel);
        }

    // Get the user-defined init string
    Edit_GetText(this->hwndUserInitED, szBuf, ARRAYSIZE(szBuf));    
    if (!IsSzEqual(szBuf, this->pmi->szUserInit))
        {
        SetFlag(this->pmi->uFlags, MIF_USERINIT_CHANGED);
        lstrcpyn(this->pmi->szUserInit, szBuf, ARRAYSIZE(this->pmi->szUserInit));
        }

    // Get logging setting
    bCheck = Button_GetCheck(GetDlgItem(this->hdlg, IDC_LOGGING));
    if (bCheck != IsFlagSet(this->pmi->uFlags, MIF_ENABLE_LOGGING))
        {
        SetFlag(this->pmi->uFlags, MIF_LOGGING_CHANGED);
        if (bCheck)
            SetFlag(this->pmi->uFlags, MIF_ENABLE_LOGGING);
        else
            ClearFlag(this->pmi->uFlags, MIF_ENABLE_LOGGING);
        }
    }


/*----------------------------------------------------------
Purpose: WM_COMMAND Handler
Returns: --
Cond:    --
*/
void PRIVATE AdvSett_OnCommand(
    PADVSETT this,
    int id,
    HWND hwndCtl,
    UINT uNotifyCode)
    {
    HWND hwnd = this->hdlg;
    BOOL bCheck;
    
    switch (id)
        {
    case IDC_AM_ERRCTL:
        bCheck = Button_GetCheck(hwndCtl);
        Button_Enable(this->hwndCompress, bCheck && this->bSupportsCompression);
        Button_Enable(this->hwndRequired, bCheck && this->bSupportsForcedEC);
        Button_Enable(this->hwndUseCell, bCheck && this->bSupportsCellular);

        // Is the user unchecking this box?
        if (FALSE == bCheck)
            {
            // Yes; uncheck the boxes inside, too
            this->bSaveCompression = Button_GetCheck(this->hwndCompress);
            this->bSaveForcedEC = Button_GetCheck(this->hwndRequired);
            this->bSaveCellular = Button_GetCheck(this->hwndUseCell);

            Button_SetCheck(this->hwndCompress, FALSE);
            Button_SetCheck(this->hwndRequired, FALSE);
            Button_SetCheck(this->hwndUseCell, FALSE);
            }
        else
            {
            // No
            Button_SetCheck(this->hwndCompress, this->bSaveCompression);
            Button_SetCheck(this->hwndRequired, this->bSaveForcedEC);
            Button_SetCheck(this->hwndUseCell, this->bSaveCellular);
            }
        break;

    case IDC_AM_USEFLOWCTL: {
        UINT idBtn;

        bCheck = Button_GetCheck(hwndCtl);
        Button_Enable(this->hwndHard, bCheck);
        Button_Enable(this->hwndSoft, bCheck);

        // Is the user unchecking this box?
        if (FALSE == bCheck)
            {
            // Yes; uncheck the radio buttons
            if (IsDlgButtonChecked(this->hdlg, IDC_AM_HW))
                this->idBtnSaveFlowCtl = IDC_AM_HW;
            else
                this->idBtnSaveFlowCtl = IDC_AM_SW;
            idBtn = (UINT)-1;
            }
        else
            {
            // No
            idBtn = this->idBtnSaveFlowCtl;
            }
        CheckRadioButton(this->hdlg, IDC_AM_HW, IDC_AM_SW, idBtn);
        }
        break;

    case IDOK:
        AdvSett_OnApply(this);
        // Fall thru
        //   |   |
        //   v   v
    case IDCANCEL:
        EndDialog(this->hdlg, id);
        break;

    default:
        break;
        }
    }


/*----------------------------------------------------------
Purpose: WM_DESTROY handler
Returns: --
Cond:    --
*/
void PRIVATE AdvSett_OnDestroy(
    PADVSETT this)
    {
    }


/////////////////////////////////////////////////////  EXPORTED FUNCTIONS

static BOOL s_bAdvSettRecurse = FALSE;

LRESULT INLINE AdvSett_DefProc(
    HWND hDlg, 
    UINT msg,
    WPARAM wParam,
    LPARAM lParam) 
    {
    ENTER_X()
        {
        s_bAdvSettRecurse = TRUE;
        }
    LEAVE_X()

    return DefDlgProc(hDlg, msg, wParam, lParam); 
    }


/*----------------------------------------------------------
Purpose: Real dialog proc
Returns: varies
Cond:    --
*/
LRESULT AdvSett_DlgProc(
    PADVSETT this,
    UINT message,
    WPARAM wParam,
    LPARAM lParam)
    {
#pragma data_seg(DATASEG_READONLY)
    const static DWORD rgHelpIDs[] = {
        IDC_AM_ERRCTL,      IDH_UNI_CON_ADV_ERROR,
        IDC_AM_REQUIRED,    IDH_UNI_CON_ADV_REQUIRED,
        IDC_AM_COMPRESS,    IDH_UNI_CON_ADV_COMPRESS,
        IDC_AM_USECELL,     IDH_UNI_CON_ADV_CELLULAR,
        IDC_AM_USEFLOWCTL,  IDH_UNI_CON_ADV_FLOW,
        IDC_AM_HW,          IDH_UNI_CON_ADV_FLOW,
        IDC_AM_SW,          IDH_UNI_CON_ADV_FLOW,
        IDC_AM_MODULATION,  IDH_UNI_CON_ADV_MODULATION,
        IDC_AM_MODULATION_LIST, IDH_UNI_CON_ADV_MODULATION,
        IDC_AM_EXTRA,       IDH_UNI_CON_ADV_EXTRA,
        IDC_AM_EXTRA_ED,    IDH_UNI_CON_ADV_EXTRA,
        IDC_LOGGING,        IDH_UNI_CON_ADV_AUDIT,
        0, 0 };
#pragma data_seg()

    switch (message)
        {
        HANDLE_MSG(this, WM_INITDIALOG, AdvSett_OnInitDialog);
        HANDLE_MSG(this, WM_COMMAND, AdvSett_OnCommand);
        HANDLE_MSG(this, WM_DESTROY, AdvSett_OnDestroy);

    case WM_HELP:
        WinHelp(((LPHELPINFO)lParam)->hItemHandle, c_szWinHelpFile, HELP_WM_HELP, (DWORD)(LPVOID)rgHelpIDs);
        return 0;

    case WM_CONTEXTMENU:
        WinHelp((HWND)wParam, c_szWinHelpFile, HELP_CONTEXTMENU, (DWORD)(LPVOID)rgHelpIDs);
        return 0;

    default:
        return AdvSett_DefProc(this->hdlg, message, wParam, lParam);
        }
    }


/*----------------------------------------------------------
Purpose: Dialog Wrapper
Returns: varies
Cond:    --
*/
BOOL CALLBACK AdvSett_WrapperProc(
    HWND hDlg,          // std params
    UINT message,
    WPARAM wParam,
    LPARAM lParam)
    {
    PADVSETT this;

    // Cool windowsx.h dialog technique.  For full explanation, see
    //  WINDOWSX.TXT.  This supports multiple-instancing of dialogs.
    //
    ENTER_X()
        {
        if (s_bAdvSettRecurse)
            {
            s_bAdvSettRecurse = FALSE;
            LEAVE_X()
            return FALSE;
            }
        }
    LEAVE_X()

    this = AdvSett_GetPtr(hDlg);
    if (this == NULL)
        {
        if (message == WM_INITDIALOG)
            {
            this = (PADVSETT)LocalAlloc(LPTR, sizeof(ADVSETT));
            if (!this)
                {
                MsgBox(g_hinst,
                       hDlg, 
                       MAKEINTRESOURCE(IDS_OOM_SETTINGS), 
                       MAKEINTRESOURCE(IDS_CAP_SETTINGS),
                       NULL,
                       MB_ERROR);
                EndDialog(hDlg, IDCANCEL);
                return (BOOL)AdvSett_DefProc(hDlg, message, wParam, lParam);
                }
            this->hdlg = hDlg;
            AdvSett_SetPtr(hDlg, this);
            }
        else
            {
            return (BOOL)AdvSett_DefProc(hDlg, message, wParam, lParam);
            }
        }

    if (message == WM_DESTROY)
        {
        AdvSett_DlgProc(this, message, wParam, lParam);
        LocalFree((HLOCAL)OFFSETOF(this));
        AdvSett_SetPtr(hDlg, NULL);
        return 0;
        }

    return SetDlgMsgResult(hDlg, message, AdvSett_DlgProc(this, message, wParam, lParam));
    }