summaryrefslogtreecommitdiffstats
path: root/private/unimodem/modemui/ring.c
blob: f8579e7bf75354903fe537a39a703ff2ab4985ba (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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
//---------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation 1993-1995
//
// File: ring.c
//
// This files contains the dialog code for the Voice settings
// property pages.
//
// History:
//  07-05-95 ScottH     Created
//
//---------------------------------------------------------------------------


#include "proj.h"         // common headers

#if defined(WIN95) && defined(CS_HELP)
#include "..\..\..\..\win\core\inc\help.h"
#endif 

#define CX_PATTERN      40
#define CY_PATTERN      5

typedef struct tagRING
    {
    HWND hdlg;              // dialog handle
    LPMODEMINFO pmi;        // modeminfo struct passed into dialog

    HBITMAP hbmStrip;
    HDC hdcStrip;
    HFONT hfont;
    int cyText;

    } RING, FAR * PRING;


typedef struct tagRINGPAT
    {
    DWORD dwPattern;
    LPARAM lParam;
    } RINGPAT, FAR * PRINGPAT;

static RINGPAT s_rgrp[] = 
    {
    { DRP_NONE, 0 },
    { DRP_SHORT, 0 },
    { DRP_LONG, 0 },
    { DRP_SHORTSHORT, 0 },
    { DRP_SHORTLONG, 0 },
    { DRP_LONGSHORT, 0 },
    { DRP_LONGLONG, 0 },
    { DRP_SHORTSHORTLONG, 0 },
    { DRP_SHORTLONGSHORT, 0 },
    { DRP_LONGSHORTSHORT, 0 },
    { DRP_LONGSHORTLONG, 0 },
    };

#pragma data_seg(DATASEG_READONLY)

const static UINT c_rgidcPattern[] = 
    {
    IDC_ADDR_PRI,
    IDC_ADDR1,
    IDC_ADDR2,
    IDC_ADDR3,
    IDC_PRI_CALLERS,
    IDC_CALLBACK,
    };
const static UINT c_rgidcTypeOfCalls[] = 
    {
    IDC_TYPE_ADDR_PRI,
    IDC_TYPE_ADDR1,
    IDC_TYPE_ADDR2,
    IDC_TYPE_ADDR3,
    IDC_TYPE_PRI_CALLERS,
    IDC_TYPE_CALLBACK,
    };

static DWORD c_rgdwCheapPatterns[] = 
    {
    DRP_SINGLE,
    DRP_DOUBLE,
    DRP_TRIPLE,
    };

const static UINT c_rgidcTypeOfCheapCalls[] = 
    {
    IDC_TYPE_RING1,
    IDC_TYPE_RING2,
    IDC_TYPE_RING3,
    };

TCHAR const FAR c_szUnimdmHelpFile[] = TEXT("unimdm.hlp");

#pragma data_seg()


#define Ring_GetPtr(hwnd)           (PRING)GetWindowLong(hwnd, DWL_USER)
#define Ring_SetPtr(hwnd, lp)       (PRING)SetWindowLong(hwnd, DWL_USER, (LONG)(lp))


//-----------------------------------------------------------------------------------
//  Voice settings dialog code
//-----------------------------------------------------------------------------------


/*----------------------------------------------------------
Purpose: Initialize the bitmap strip

Returns: --
Cond:    --
*/
void PRIVATE Ring_InitStrip(
    PRING this,
    HDC hdc)
    {
    ASSERT(hdc);

    this->hbmStrip = LoadBitmap(g_hinst, MAKEINTRESOURCE(IDB_PATTERNS));
    ASSERT(this->hbmStrip);

    this->hdcStrip = CreateCompatibleDC(hdc);
    if (this->hdcStrip)
        {
        SelectObject(this->hdcStrip, this->hbmStrip);
        }
    }


/*----------------------------------------------------------
Purpose: Initialize the specified Pattern combobox.

Returns: --
Cond:    --
*/
void PRIVATE Ring_InitPattern(
    PRING this,
    HWND hwndCB,
    DWORD dwPattern)
    {
    int i;
    int iSel = 0;
    int n;

    // Fill the listbox
    for (i = 0; i < ARRAY_ELEMENTS(s_rgrp); i++)
        {
        n = ComboBox_AddString(hwndCB, &s_rgrp[i]);

        // Keep our eyes peeled for the selected type
        if (dwPattern == s_rgrp[i].dwPattern)
            {
            iSel = n;
            }
        }

    ComboBox_SetCurSel(hwndCB, iSel);
    }


/*----------------------------------------------------------
Purpose: Initialize the specified Type of Call combobox.

Returns: --
Cond:    --
*/
void PRIVATE Ring_InitTypeOfCall(
    PRING this,
    HWND hwndCB,
    DWORD dwType)
    {
#pragma data_seg(DATASEG_READONLY)
    static const struct 
        {
        UINT ids;
        DWORD dwType;       // DRT_*
        } s_rgTypes[] = 
            {
            { IDS_UNSPECIFIED, DRT_UNSPECIFIED },
            { IDS_DATA, DRT_DATA },
            { IDS_FAX, DRT_FAX },
            { IDS_VOICE, DRT_VOICE },
            };
#pragma data_seg()

    int i;
    int iSel = 0;
    int n;
    TCHAR sz[MAXMEDLEN];

    // Fill the listbox
    for (i = 0; i < ARRAY_ELEMENTS(s_rgTypes); i++)
        {
        n = ComboBox_AddString(hwndCB, SzFromIDS(g_hinst, s_rgTypes[i].ids, sz, SIZECHARS(sz)));
        ComboBox_SetItemData(hwndCB, n, s_rgTypes[i].dwType);

        // Keep our eyes peeled for the selected type
        if (dwType == s_rgTypes[i].dwType)
            {
            iSel = n;
            }
        }

    ComboBox_SetCurSel(hwndCB, iSel);
    }


/*----------------------------------------------------------
Purpose: Enable/disable all the controls

Returns: --
Cond:    --
*/
void PRIVATE Ring_EnableControls(
    PRING this,
    BOOL bEnable)
    {
    HWND hwnd = this->hdlg;

    EnableWindow(GetDlgItem(hwnd, IDC_LBL_ADDR_PRI), bEnable);
    EnableWindow(GetDlgItem(hwnd, IDC_ADDR_PRI), bEnable);
    EnableWindow(GetDlgItem(hwnd, IDC_TYPE_ADDR_PRI), bEnable);

    EnableWindow(GetDlgItem(hwnd, IDC_LBL_ADDR1), bEnable);
    EnableWindow(GetDlgItem(hwnd, IDC_ADDR1), bEnable);
    EnableWindow(GetDlgItem(hwnd, IDC_TYPE_ADDR1), bEnable);

    EnableWindow(GetDlgItem(hwnd, IDC_LBL_ADDR2), bEnable);
    EnableWindow(GetDlgItem(hwnd, IDC_ADDR2), bEnable);
    EnableWindow(GetDlgItem(hwnd, IDC_TYPE_ADDR2), bEnable);

    EnableWindow(GetDlgItem(hwnd, IDC_LBL_ADDR3), bEnable);
    EnableWindow(GetDlgItem(hwnd, IDC_ADDR3), bEnable);
    EnableWindow(GetDlgItem(hwnd, IDC_TYPE_ADDR3), bEnable);

    EnableWindow(GetDlgItem(hwnd, IDC_LBL_PRI_CALLERS), bEnable);
    EnableWindow(GetDlgItem(hwnd, IDC_PRI_CALLERS), bEnable);
    EnableWindow(GetDlgItem(hwnd, IDC_TYPE_PRI_CALLERS), bEnable);

    EnableWindow(GetDlgItem(hwnd, IDC_LBL_CALLBACK), bEnable);
    EnableWindow(GetDlgItem(hwnd, IDC_CALLBACK), bEnable);
    EnableWindow(GetDlgItem(hwnd, IDC_TYPE_CALLBACK), bEnable);
    }


/*----------------------------------------------------------
Purpose: WM_INITDIALOG Handler
Returns: FALSE when we assign the control focus
Cond:    --
*/
BOOL PRIVATE Ring_OnInitDialog(
    PRING this,
    HWND hwndFocus,
    LPARAM lParam)              // expected to be PROPSHEETINFO 
    {
    LPPROPSHEETPAGE lppsp = (LPPROPSHEETPAGE)lParam;
    HWND hwnd = this->hdlg;
    HWND hwndCtl;
    LPDWORD lpdw;
    BOOL bEnable;
    int i;
    PVOICEFEATURES pvs;
    HDC hdc;
    LOGFONT lf;
    
    ASSERT((LPTSTR)lppsp->lParam);

    this->pmi = (LPMODEMINFO)lppsp->lParam;
    pvs = &this->pmi->pglobal->vs;

    // Determine some font things

    SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, FALSE);
    this->hfont = CreateFontIndirect(&lf);
    
    // Create bitmap strip
    
    hdc = GetDC(hwnd);
    if (hdc)
        {
        Ring_InitStrip(this, hdc);
        ReleaseDC(hwnd, hdc);
        }
        
    // Enable/disable controls

    bEnable = IsFlagSet(this->pmi->pglobal->vs.dwFlags, VSF_DIST_RING);

    Button_SetCheck(GetDlgItem(hwnd, IDC_RING_CHECK), bEnable);
    Ring_EnableControls(this, bEnable);

    // Initialize controls

    for (i = 0; i < ARRAY_ELEMENTS(c_rgidcPattern); i++)
        {
        hwndCtl = GetDlgItem(hwnd, c_rgidcPattern[i]);
        lpdw = &pvs->DistRing[i].dwPattern;

        Ring_InitPattern(this, hwndCtl, *lpdw);
        }

    for (i = 0; i < ARRAY_ELEMENTS(c_rgidcTypeOfCalls); i++)
        {
        hwndCtl = GetDlgItem(hwnd, c_rgidcTypeOfCalls[i]);
        lpdw = &pvs->DistRing[i].dwMediaType;

        Ring_InitTypeOfCall(this, hwndCtl, *lpdw);
        }

    return TRUE;   // default initial focus
    }


/*----------------------------------------------------------
Purpose: WM_COMMAND Handler
Returns: --
Cond:    --
*/
void PRIVATE Ring_OnCommand(
    PRING this,
    int id,
    HWND hwndCtl,
    UINT uNotifyCode)
    {
    BOOL bCheck;

    switch (id)
        {
    case IDC_RING_CHECK:
        bCheck = Button_GetCheck(hwndCtl);
        Ring_EnableControls(this, bCheck);
        break;

    default:
        break;
        }
    }


/*----------------------------------------------------------
Purpose: Validate the user's settings.

         The ring patterns must be unique, except that
         any/all may be set to DRP_NONE.

Returns: TRUE if valid

Cond:    --
*/
BOOL PRIVATE Ring_ValidateSettings(
    PRING this)
    {
    HWND hwnd = this->hdlg;
    int i;
    int iSel;
    HWND hwndCtl;
    PRINGPAT prp;

    for (i = 0; i < ARRAY_ELEMENTS(s_rgrp); i++)
        {
        // Initialize lParam to 0
        s_rgrp[i].lParam = 0;
        }

    // Get the ring pattern settings

    for (i = 0; i < ARRAY_ELEMENTS(c_rgidcPattern); i++)
        {
        hwndCtl = GetDlgItem(hwnd, c_rgidcPattern[i]);

        iSel = ComboBox_GetCurSel(hwndCtl);
        ASSERT(LB_ERR != iSel);

        ComboBox_GetLBText(hwndCtl, iSel, &prp);

        // Is this pattern already selected,
        // and is it something other than none?
        if (DRP_NONE != prp->dwPattern && prp->lParam)
            {
            // Yes; can't have duplicate values
            MsgBox(g_hinst,
                   hwnd, 
                   MAKEINTRESOURCE(IDS_ERR_DUP_PATTERN), 
                   MAKEINTRESOURCE(IDS_CAP_RING),
                   NULL,
                   MB_ERROR);

            // Set the focus on the offending control
            PostMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)hwndCtl, (LPARAM)TRUE);
            return FALSE;
            }
        prp->lParam = TRUE;
        }
    return TRUE;
    }


/*----------------------------------------------------------
Purpose: PSN_APPLY handler

Returns: TRUE if validation succeeded
         FALSE if not

Cond:    --
*/
BOOL PRIVATE Ring_OnApply(
    PRING this)
    {
    BOOL bRet;
    HWND hwnd = this->hdlg;
    HWND hwndCtl;
    LPDWORD lpdw;
    int i;
    int iSel;
    PVOICEFEATURES pvs = &this->pmi->pglobal->vs;
    PRINGPAT prp;

    bRet = Ring_ValidateSettings(this);

    // Are the user's settings valid?
    if (bRet)
        {
        // Yes
        if (Button_GetCheck(GetDlgItem(hwnd, IDC_RING_CHECK)))
            {
            SetFlag(pvs->dwFlags, VSF_DIST_RING);
            }
        else
            {
            ClearFlag(pvs->dwFlags, VSF_DIST_RING);
            }


        // Get the ring pattern settings

        for (i = 0; i < ARRAY_ELEMENTS(c_rgidcPattern); i++)
            {
            hwndCtl = GetDlgItem(hwnd, c_rgidcPattern[i]);
            lpdw = &pvs->DistRing[i].dwPattern;

            iSel = ComboBox_GetCurSel(hwndCtl);
            ASSERT(LB_ERR != iSel);

            ComboBox_GetLBText(hwndCtl, iSel, &prp);

            *lpdw = prp->dwPattern;
            }

        // Get the type of call settings

        for (i = 0; i < ARRAY_ELEMENTS(c_rgidcTypeOfCalls); i++)
            {
            hwndCtl = GetDlgItem(hwnd, c_rgidcTypeOfCalls[i]);
            lpdw = &pvs->DistRing[i].dwMediaType;

            iSel = ComboBox_GetCurSel(hwndCtl);
            ASSERT(LB_ERR != iSel);

            *lpdw = ComboBox_GetItemData(hwndCtl, iSel);
            }


        }
    return bRet;
    }


/*----------------------------------------------------------
Purpose: WM_NOTIFY handler
Returns: varies
Cond:    --
*/
LRESULT PRIVATE Ring_OnNotify(
    PRING this,
    int idFrom,
    NMHDR FAR * lpnmhdr)
    {
    LRESULT lRet = 0;
    
    switch (lpnmhdr->code)
        {
    case PSN_SETACTIVE:
        break;

    case PSN_KILLACTIVE:
        // N.b. This message is not sent if user clicks Cancel!
        // N.b. This message is sent prior to PSN_APPLY
        //
        break;

    case PSN_APPLY:
        lRet = Ring_OnApply(this) ? PSNRET_NOERROR : PSNRET_INVALID;
        break;

    default:
        break;
        }

    return lRet;
    }


/*----------------------------------------------------------
Purpose: WM_DESTROY handler

Returns: --
Cond:    --
*/
void PRIVATE Ring_OnDestroy(
    PRING this)
    {
    if (this->hdcStrip)
        DeleteDC(this->hdcStrip);

    if (this->hbmStrip)
        DeleteObject(this->hbmStrip);

    if (this->hfont)
        DeleteFont(this->hfont);
    }


/*----------------------------------------------------------
Purpose: WM_MEASUREITEM handler
Returns: --

Cond:    !!!  WM_MEASUREITEM is received before WM_INITDIALOG !!!

         The contents of 'this' will be uninitialized.
*/
void PRIVATE Ring_OnMeasureItem(
    PRING this,
    LPMEASUREITEMSTRUCT lpmis)
    {
    HWND hwnd = this->hdlg;
    HDC hdc;

    ASSERT(ODT_COMBOBOX == lpmis->CtlType);
    
    hdc = GetDC(hwnd);
    if (hdc)
        {
        TEXTMETRIC tm;

        GetTextMetrics(hdc, &tm);
        lpmis->itemHeight = max(tm.tmHeight, CY_PATTERN);

        ReleaseDC(hwnd, hdc);
        }
    }


/*----------------------------------------------------------
Purpose: WM_DRAWITEM handler
Returns: --
Cond:    --
*/
void PRIVATE Ring_OnDrawCBItem(
    PRING this,
    const DRAWITEMSTRUCT FAR * lpcdis)
    {
    HWND hwnd = this->hdlg;
    PRINGPAT prp = (PRINGPAT)lpcdis->itemData;

    ASSERT(ODT_COMBOBOX == lpcdis->CtlType);
    ASSERT(prp);

    if (prp)
        {
        HDC hdc = lpcdis->hDC;
        RECT rc = lpcdis->rcItem;
        RECT rcFrame;
        POINT ptSav;
        int x;
        int y;
        int nBkMode;
        COLORREF crText;
        COLORREF crBk;
        COLORREF crTextSav;
        COLORREF crBkSav;

        ASSERT(hdc);

        SetViewportOrgEx(hdc, rc.left, rc.top, &ptSav);
    
        rcFrame.top = 0;
        rcFrame.left = 0;
        rcFrame.bottom = rc.bottom - rc.top;
        rcFrame.right = rc.right - rc.left;

        // Set the colors

        nBkMode = SetBkMode(hdc, TRANSPARENT);

        TextAndBkCr(lpcdis, &crText, &crBk);
        crTextSav = SetTextColor(hdc, crText);
        crBkSav = SetBkColor(hdc, crBk);

        // Do we need to redraw everything?
        if (IsFlagSet(lpcdis->itemAction, ODA_DRAWENTIRE) ||
            IsFlagSet(lpcdis->itemAction, ODA_SELECT))
            {
            // Yes
            TCHAR sz[MAXSHORTLEN];
            LPTSTR psz = sz;
            int cch;
            HFONT hfontSav;

            // Show bitmap or text?
            if (DRP_NONE == prp->dwPattern)
                {
                // Text
                hfontSav = SelectFont(hdc, this->hfont);
                SzFromIDS(g_hinst, IDS_AUTOMATIC, sz, SIZECHARS(sz));
                cch = lstrlen(sz);
                }
            else
                {
                // Bitmap
                hfontSav = NULL;
                *psz = 0;
                cch = 0;
                }

            ASSERT(rc.right - rc.left >= CX_PATTERN);
            ASSERT(rc.bottom - rc.top >= CY_PATTERN);

            x = (rc.right - rc.left - CX_PATTERN) / 2;
            y = (rc.bottom - rc.top - CY_PATTERN) / 2;

            // Fill background (with optional text)
            ExtTextOut(hdc, 2, 2, ETO_OPAQUE, &rcFrame, psz, cch, NULL);

            if (DRP_NONE != prp->dwPattern)
                {
                // Draw bitmap
                BitBlt(hdc, x, y, CX_PATTERN, CY_PATTERN,
                    this->hdcStrip, ((int)prp->dwPattern - 1) * CX_PATTERN, 0,
                    SRCCOPY);
                }

            if (hfontSav)
                SelectFont(hdc, hfontSav);
            }

        // Draw the caret?
        if (IsFlagSet(lpcdis->itemAction, ODA_FOCUS) ||
            IsFlagSet(lpcdis->itemState, ODS_FOCUS))
            {
            // Yes
            DrawFocusRect(hdc, &rcFrame);
            }

        // Clean up
        SetTextColor(hdc, crTextSav);
        SetBkColor(hdc, crBkSav);
        SetBkMode(hdc, nBkMode);
        SetViewportOrgEx(hdc, ptSav.x, ptSav.y, NULL);
        }
    }


/*----------------------------------------------------------
Purpose: WM_DRAWITEM handler
Returns: --
Cond:    --
*/
void PRIVATE Ring_OnDrawStaticItem(
    PRING this,
    const DRAWITEMSTRUCT FAR * lpcdis)
    {
    HWND hwnd = this->hdlg;
    HDC hdc = lpcdis->hDC;
    RECT rc = lpcdis->rcItem;
    int x;
    int y;
    int nBkMode;
    COLORREF crText;
    COLORREF crBk;
    COLORREF crTextSav;
    COLORREF crBkSav;

    ASSERT(ODT_STATIC == lpcdis->CtlType);
    ASSERT(hdc);

    // Set the colors

    nBkMode = SetBkMode(hdc, TRANSPARENT);

    TextAndBkCr(lpcdis, &crText, &crBk);
    crTextSav = SetTextColor(hdc, crText);
    crBkSav = SetBkColor(hdc, crBk);

    ASSERT(rc.right - rc.left >= CX_PATTERN);
    ASSERT(rc.bottom - rc.top >= CY_PATTERN);

    x = (rc.right - rc.left - CX_PATTERN) / 2;
    y = (rc.bottom - rc.top - CY_PATTERN) / 2;

    // Fill background (with optional text)
    ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, TEXT(""), 0, NULL);

    // Draw bitmap
    BitBlt(hdc, x, y, CX_PATTERN, CY_PATTERN,
        this->hdcStrip, (int)(DRP_LONG - 1) * CX_PATTERN, 0,
        SRCCOPY);

    // Clean up
    SetTextColor(hdc, crTextSav);
    SetBkColor(hdc, crBkSav);
    SetBkMode(hdc, nBkMode);
    }


/*----------------------------------------------------------
Purpose: WM_DRAWITEM handler
Returns: --
Cond:    --
*/
void PRIVATE Ring_OnDrawItem(
    PRING this,
    const DRAWITEMSTRUCT FAR * lpcdis)
    {
    switch (lpcdis->CtlType)
        {
    case ODT_COMBOBOX:
        Ring_OnDrawCBItem(this, lpcdis);
        break;

    case ODT_STATIC:
        Ring_OnDrawStaticItem(this, lpcdis);
        break;

    default:
        ASSERT(0);
        break;
        }
    }


/*----------------------------------------------------------
Purpose: WM_DELETEITEM handler
Returns: --

Cond:    !!! WM_DELETEITEM is received after WM_DESTROY !!!

*/
void Ring_OnDeleteItem(
    PRING this,
    const DELETEITEMSTRUCT FAR * lpcdis)
    {
    PRINGPAT prp = (PRINGPAT)lpcdis->itemData;

    ASSERT(NULL == this);       // this will be NULL

    ASSERT(ODT_COMBOBOX == lpcdis->CtlType);
    ASSERT(prp);
    }


static BOOL s_bRingRecurse = FALSE;

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

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


/*----------------------------------------------------------
Purpose: Real dialog proc
Returns: varies
Cond:    --
*/
LRESULT Ring_DlgProc(
    PRING this,
    UINT message,
    WPARAM wParam,
    LPARAM lParam)
    {
#ifdef CS_HELP
    // UE used the control IDs as help IDs.  To prevent mix-ups in
    // the future (ie, when the control IDs change), here are the 
    // help IDs.
    #define IDH_UNI_RING_SERVICES           1069          
    #define IDH_UNI_RING_LBL_ADDR_PRI       1070
    #define IDH_UNI_RING_ADDR_PRI           1073
    #define IDH_UNI_RING_TYPE_ADDR_PRI      1082
    #define IDH_UNI_RING_LBL_ADDR1          1071
    #define IDH_UNI_RING_ADDR1              1074
    #define IDH_UNI_RING_TYPE_ADDR1         1083
    #define IDH_UNI_RING_LBL_ADDR2          1072
    #define IDH_UNI_RING_ADDR2              1075
    #define IDH_UNI_RING_TYPE_ADDR2         1084
    #define IDH_UNI_RING_LBL_ADDR3          1076
    #define IDH_UNI_RING_ADDR3              1077
    #define IDH_UNI_RING_TYPE_ADDR3         1085
    #define IDH_UNI_RING_LBL_PRI_CALLERS    1078
    #define IDH_UNI_RING_PRI_CALLERS        1079
    #define IDH_UNI_RING_TYPE_PRI_CALLERS   1086
    #define IDH_UNI_RING_LBL_CALLBACK       1080
    #define IDH_UNI_RING_CALLBACK           1081
    #define IDH_UNI_RING_TYPE_CALLBACK      1087
#pragma data_seg(DATASEG_READONLY)
    const static DWORD rgHelpIDs[] = {
        IDC_RING_CHECK,         IDH_UNI_RING_SERVICES,
        IDC_LBL_ADDR_PRI,       IDH_UNI_RING_LBL_ADDR_PRI,
        IDC_ADDR_PRI,           IDH_UNI_RING_ADDR_PRI,
        IDC_TYPE_ADDR_PRI,      IDH_UNI_RING_TYPE_ADDR_PRI,
        IDC_LBL_ADDR1,          IDH_UNI_RING_LBL_ADDR1,
        IDC_ADDR1,              IDH_UNI_RING_ADDR1,
        IDC_TYPE_ADDR1,         IDH_UNI_RING_TYPE_ADDR1,
        IDC_LBL_ADDR2,          IDH_UNI_RING_LBL_ADDR2,
        IDC_ADDR2,              IDH_UNI_RING_ADDR2,
        IDC_TYPE_ADDR2,         IDH_UNI_RING_TYPE_ADDR2,
        IDC_LBL_ADDR3,          IDH_UNI_RING_LBL_ADDR3,
        IDC_ADDR3,              IDH_UNI_RING_ADDR3,
        IDC_TYPE_ADDR3,         IDH_UNI_RING_TYPE_ADDR3,
        IDC_LBL_PRI_CALLERS,    IDH_UNI_RING_LBL_PRI_CALLERS,
        IDC_PRI_CALLERS,        IDH_UNI_RING_PRI_CALLERS,
        IDC_TYPE_PRI_CALLERS,   IDH_UNI_RING_TYPE_PRI_CALLERS,
        IDC_LBL_CALLBACK,       IDH_UNI_RING_LBL_CALLBACK,
        IDC_CALLBACK,           IDH_UNI_RING_CALLBACK,
        IDC_TYPE_CALLBACK,      IDH_UNI_RING_TYPE_CALLBACK,
        0, 0 };
#pragma data_seg()
#endif

    switch (message)
        {
        HANDLE_MSG(this, WM_INITDIALOG, Ring_OnInitDialog);
        HANDLE_MSG(this, WM_COMMAND, Ring_OnCommand);
        HANDLE_MSG(this, WM_NOTIFY, Ring_OnNotify);
        HANDLE_MSG(this, WM_DESTROY, Ring_OnDestroy);

        HANDLE_MSG(this, WM_MEASUREITEM, Ring_OnMeasureItem);
        HANDLE_MSG(this, WM_DRAWITEM, Ring_OnDrawItem);
        HANDLE_MSG(this, WM_DELETEITEM, Ring_OnDeleteItem);

#ifdef CS_HELP
    case WM_HELP:
        WinHelp(((LPHELPINFO)lParam)->hItemHandle, c_szUnimdmHelpFile, HELP_WM_HELP, (DWORD)(LPVOID)rgHelpIDs);
        return 0;

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

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


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

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

    this = Ring_GetPtr(hDlg);
    if (this == NULL)
        {
        // (WM_SETFONT is the first message received by dialogs)
        if (WM_SETFONT == message)
            {
            this = (PRING)LocalAlloc(LPTR, sizeof(RING));
            if (!this)
                {
                MsgBox(g_hinst,
                       hDlg,
                       MAKEINTRESOURCE(IDS_OOM_SETTINGS), 
                       MAKEINTRESOURCE(IDS_CAP_RING),
                       NULL,
                       MB_ERROR);
                EndDialog(hDlg, IDCANCEL);
                return (BOOL)Ring_DefProc(hDlg, message, wParam, lParam);
                }
            this->hdlg = hDlg;
            Ring_SetPtr(hDlg, this);
            }
        else
            {
            return (BOOL)Ring_DefProc(hDlg, message, wParam, lParam);
            }
        }

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

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


//-----------------------------------------------------------------------------------
//  Cheap ring dialog code
//-----------------------------------------------------------------------------------

#define CheapRing_GetPtr(hwnd)           (PRING)GetWindowLong(hwnd, DWL_USER)
#define CheapRing_SetPtr(hwnd, lp)       (PRING)SetWindowLong(hwnd, DWL_USER, (LONG)(lp))

/*----------------------------------------------------------
Purpose: Initialize the specified Type of Call combobox.

Returns: --
Cond:    --
*/
void PRIVATE CheapRing_InitTypeOfCall(
    PRING this,
    HWND hwndCB,
    DWORD dwType)
    {
#pragma data_seg(DATASEG_READONLY)
    static const struct 
        {
        UINT ids;
        DWORD dwType;       // DRT_*
        } s_rgTypes[] = 
            {
            { IDS_UNSPECIFIED, DRT_UNSPECIFIED },
            { IDS_DATA, DRT_DATA },
            { IDS_FAX, DRT_FAX },
            { IDS_VOICE, DRT_VOICE },
            };
#pragma data_seg()

    int i;
    int iSel = 0;
    int n;
    TCHAR sz[MAXMEDLEN];

    // Fill the listbox
    for (i = 0; i < ARRAY_ELEMENTS(s_rgTypes); i++)
        {
        n = ComboBox_AddString(hwndCB, SzFromIDS(g_hinst, s_rgTypes[i].ids, sz, SIZECHARS(sz)));
        ComboBox_SetItemData(hwndCB, n, s_rgTypes[i].dwType);

        // Keep our eyes peeled for the selected type
        if (dwType == s_rgTypes[i].dwType)
            {
            iSel = n;
            }
        }

    ComboBox_SetCurSel(hwndCB, iSel);
    }


/*----------------------------------------------------------
Purpose: Enable/disable all the controls

Returns: --
Cond:    --
*/
void PRIVATE CheapRing_EnableControls(
    PRING this,
    BOOL bEnable)
    {
    HWND hwnd = this->hdlg;

    EnableWindow(GetDlgItem(hwnd, IDC_LBL_RING1), bEnable);
    EnableWindow(GetDlgItem(hwnd, IDC_TYPE_RING1), bEnable);

    EnableWindow(GetDlgItem(hwnd, IDC_LBL_RING2), bEnable);
    EnableWindow(GetDlgItem(hwnd, IDC_TYPE_RING2), bEnable);

    EnableWindow(GetDlgItem(hwnd, IDC_LBL_RING3), bEnable);
    EnableWindow(GetDlgItem(hwnd, IDC_TYPE_RING3), bEnable);
    }


/*----------------------------------------------------------
Purpose: WM_INITDIALOG Handler
Returns: FALSE when we assign the control focus
Cond:    --
*/
BOOL PRIVATE CheapRing_OnInitDialog(
    PRING this,
    HWND hwndFocus,
    LPARAM lParam)              // expected to be PROPSHEETINFO 
    {

    LPPROPSHEETPAGE lppsp = (LPPROPSHEETPAGE)lParam;
    HWND hwnd = this->hdlg;
    HWND hwndCtl;
    LPDWORD lpdw;
    BOOL bEnable;
    int i;
    PVOICEFEATURES pvs;
    
    ASSERT((LPTSTR)lppsp->lParam);

    this->pmi = (LPMODEMINFO)lppsp->lParam;
    pvs = &this->pmi->pglobal->vs;

    // Enable/disable controls

    bEnable = IsFlagSet(this->pmi->pglobal->vs.dwFlags, VSF_DIST_RING);

    Button_SetCheck(GetDlgItem(hwnd, IDC_RING_CHECK), bEnable);
    CheapRing_EnableControls(this, bEnable);

    // Initialize controls

    for (i = 0; i < ARRAY_ELEMENTS(c_rgidcTypeOfCheapCalls); i++)
        {
        hwndCtl = GetDlgItem(hwnd, c_rgidcTypeOfCheapCalls[i]);
        lpdw = &pvs->DistRing[i].dwMediaType;

        CheapRing_InitTypeOfCall(this, hwndCtl, *lpdw);
        }

    return TRUE;   // default initial focus
    }


/*----------------------------------------------------------
Purpose: WM_COMMAND Handler
Returns: --
Cond:    --
*/
void PRIVATE CheapRing_OnCommand(
    PRING this,
    int id,
    HWND hwndCtl,
    UINT uNotifyCode)
    {
    BOOL bCheck;

    switch (id)
        {
    case IDC_RING_CHECK:
        bCheck = Button_GetCheck(hwndCtl);
        CheapRing_EnableControls(this, bCheck);
        break;

    default:
        break;
        }
    }


/*----------------------------------------------------------
Purpose: PSN_APPLY handler

Returns: TRUE if validation succeeded
         FALSE if not

Cond:    --
*/
BOOL PRIVATE CheapRing_OnApply(
    PRING this)
    {
    HWND hwnd = this->hdlg;
    HWND hwndCtl;
    LPDWORD lpdw;
    int i;
    int iSel;
    PVOICEFEATURES pvs = &this->pmi->pglobal->vs;

    if (Button_GetCheck(GetDlgItem(hwnd, IDC_RING_CHECK)))
        {
        SetFlag(pvs->dwFlags, VSF_DIST_RING);
        }
    else
        {
        ClearFlag(pvs->dwFlags, VSF_DIST_RING);
        }


    // Get the ring pattern settings

    for (i = 0; i < ARRAY_ELEMENTS(c_rgdwCheapPatterns); i++)
        {
        pvs->DistRing[i].dwPattern = c_rgdwCheapPatterns[i];
        }

    // Get the type of call settings

    for (i = 0; i < ARRAY_ELEMENTS(c_rgidcTypeOfCheapCalls); i++)
        {
        hwndCtl = GetDlgItem(hwnd, c_rgidcTypeOfCheapCalls[i]);
        lpdw = &pvs->DistRing[i].dwMediaType;

        iSel = ComboBox_GetCurSel(hwndCtl);
        ASSERT(LB_ERR != iSel);

        *lpdw = ComboBox_GetItemData(hwndCtl, iSel);
        }

    return TRUE;
    }


/*----------------------------------------------------------
Purpose: WM_NOTIFY handler
Returns: varies
Cond:    --
*/
LRESULT PRIVATE CheapRing_OnNotify(
    PRING this,
    int idFrom,
    NMHDR FAR * lpnmhdr)
    {
    LRESULT lRet = 0;
    
    switch (lpnmhdr->code)
        {
    case PSN_SETACTIVE:
        break;

    case PSN_KILLACTIVE:
        // N.b. This message is not sent if user clicks Cancel!
        // N.b. This message is sent prior to PSN_APPLY
        //
        break;

    case PSN_APPLY:
        lRet = CheapRing_OnApply(this) ? PSNRET_NOERROR : PSNRET_INVALID;
        break;

    default:
        break;
        }

    return lRet;
    }


static BOOL s_bCheapRingRecurse = FALSE;

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

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


/*----------------------------------------------------------
Purpose: Real dialog proc
Returns: varies
Cond:    --
*/
LRESULT CheapRing_DlgProc(
    PRING this,
    UINT message,
    WPARAM wParam,
    LPARAM lParam)
    {
#ifdef CS_HELP
    // UE used the control IDs as help IDs.  To prevent mix-ups in
    // the future (ie, when the control IDs change), here are the 
    // help IDs.
    #define IDH_UNI_RING_LBL_RING1          1088
    #define IDH_UNI_RING_TYPE_RING1         1091
    #define IDH_UNI_RING_LBL_RING2          1089
    #define IDH_UNI_RING_TYPE_RING2         1092
    #define IDH_UNI_RING_LBL_RING3          1090
    #define IDH_UNI_RING_TYPE_RING3         1093
#pragma data_seg(DATASEG_READONLY)
    const static DWORD rgHelpIDs[] = {
        IDC_RING_CHECK,         IDH_UNI_RING_SERVICES,
        IDC_LBL_RING1,          IDH_UNI_RING_LBL_RING1,
        IDC_TYPE_RING1,         IDH_UNI_RING_TYPE_RING1,
        IDC_LBL_RING2,          IDH_UNI_RING_LBL_RING2,
        IDC_TYPE_RING2,         IDH_UNI_RING_TYPE_RING2,
        IDC_LBL_RING3,          IDH_UNI_RING_LBL_RING3,
        IDC_TYPE_RING3,         IDH_UNI_RING_TYPE_RING3,
        0, 0 };
#pragma data_seg()
#endif

    switch (message)
        {
        HANDLE_MSG(this, WM_INITDIALOG, CheapRing_OnInitDialog);
        HANDLE_MSG(this, WM_COMMAND, CheapRing_OnCommand);
        HANDLE_MSG(this, WM_NOTIFY, CheapRing_OnNotify);


#ifdef CS_HELP
    case WM_HELP:
        WinHelp(((LPHELPINFO)lParam)->hItemHandle, c_szUnimdmHelpFile, HELP_WM_HELP, (DWORD)(LPVOID)rgHelpIDs);
        return 0;

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

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


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

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

    this = CheapRing_GetPtr(hDlg);
    if (this == NULL)
        {
        // (WM_SETFONT is the first message received by dialogs)
        if (WM_SETFONT == message)
            {
            this = (PRING)LocalAlloc(LPTR, sizeof(RING));
            if (!this)
                {
                MsgBox(g_hinst,
                       hDlg,
                       MAKEINTRESOURCE(IDS_OOM_SETTINGS), 
                       MAKEINTRESOURCE(IDS_CAP_RING),
                       NULL,
                       MB_ERROR);
                EndDialog(hDlg, IDCANCEL);
                return (BOOL)CheapRing_DefProc(hDlg, message, wParam, lParam);
                }
            this->hdlg = hDlg;
            CheapRing_SetPtr(hDlg, this);
            }
        else
            {
            return (BOOL)CheapRing_DefProc(hDlg, message, wParam, lParam);
            }
        }

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

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



//-----------------------------------------------------------------------------------
//  DTMF edit box proc
//-----------------------------------------------------------------------------------


/*----------------------------------------------------------
Purpose: Handle WM_CHAR

Returns: TRUE to let the characters by
         FALSE to prohibit 
Cond:    --
*/
BOOL PRIVATE DTMFEditProc_OnChar(
    HWND hwnd,
    UINT ch,
    int cRepeat)
    {
    BOOL bRet;

    // Is this a numerical digit,
    // a backspace,
    // or a valid DTMF digit?
    if (IsCharAlphaNumeric((TCHAR)ch) && !IsCharAlpha((TCHAR)ch) ||
        VK_BACK == LOBYTE(VkKeyScan((TCHAR)ch)) ||
        'A' == ch || 'B' == ch || 'C' == ch || 'D' == ch ||
        '*' == ch || '#' == ch)
        {
        // Yes
        bRet = TRUE;
        }
    else 
        {
        // No
        MessageBeep(MB_OK);
        bRet = FALSE;
        }
    return bRet;
    }


/*----------------------------------------------------------
Purpose: Number proc.  Only allow numbers to be entered into this edit box.

Returns: varies
Cond:    --
*/
LRESULT CALLBACK DTMFEditProc(
    HWND hwnd,          // std params
    UINT message,
    WPARAM wParam,
    LPARAM lParam)
    {
    WNDPROC pfn = (WNDPROC)GetWindowLong(hwnd, GWL_USERDATA);

    // BUGBUG: doesn't handle paste correctly!

    switch (message)
        {
    case WM_CHAR:
        if (!DTMFEditProc_OnChar(hwnd, (UINT)wParam, LOWORD(lParam)))
            return 1;       // Don't process this character
        break;
        }

    return CallWindowProc(pfn, hwnd, message, wParam, lParam);
    }


//-----------------------------------------------------------------------------------
//  Call forwarding dialog code
//-----------------------------------------------------------------------------------


typedef struct tagCALLFWD
    {
    HWND hdlg;              // dialog handle
    LPMODEMINFO pmi;        // modeminfo struct passed into dialog

    } CALLFWD, FAR * PCALLFWD;


#define CallFwd_GetPtr(hwnd)           (PCALLFWD)GetWindowLong(hwnd, DWL_USER)
#define CallFwd_SetPtr(hwnd, lp)       (PCALLFWD)SetWindowLong(hwnd, DWL_USER, (LONG)(lp))


/*----------------------------------------------------------
Purpose: Enable/disable all the controls

Returns: --
Cond:    --
*/
void PRIVATE CallFwd_EnableControls(
    PCALLFWD this,
    BOOL bEnable)
    {
    HWND hwnd = this->hdlg;
    
    EnableWindow(GetDlgItem(hwnd, IDC_FWD_ACT), bEnable);
    EnableWindow(GetDlgItem(hwnd, IDC_ACT), bEnable);
    EnableWindow(GetDlgItem(hwnd, IDC_FWD_DEACT), bEnable);
    EnableWindow(GetDlgItem(hwnd, IDC_DEACT), bEnable);
    }


/*----------------------------------------------------------
Purpose: WM_INITDIALOG Handler
Returns: FALSE when we assign the control focus
Cond:    --
*/
BOOL PRIVATE CallFwd_OnInitDialog(
    PCALLFWD this,
    HWND hwndFocus,
    LPARAM lParam)              // expected to be PROPSHEETINFO 
    {
    LPPROPSHEETPAGE lppsp = (LPPROPSHEETPAGE)lParam;
    HWND hwnd = this->hdlg;
    HWND hwndCtl;
    BOOL bEnable;
    PVOICEFEATURES pvs;
    WNDPROC pfn;
    
    ASSERT((LPTSTR)lppsp->lParam);

    this->pmi = (LPMODEMINFO)lppsp->lParam;
    pvs = &this->pmi->pglobal->vs;

    // Subclass the edit boxes that only accept DTMF digits
    hwndCtl = GetDlgItem(hwnd, IDC_ACT);
    pfn = SubclassWindow(hwndCtl, DTMFEditProc);
    SetWindowLong(hwndCtl, GWL_USERDATA, (LONG)pfn);
    
    hwndCtl = GetDlgItem(hwnd, IDC_DEACT);
    pfn = SubclassWindow(hwndCtl, DTMFEditProc);
    SetWindowLong(hwndCtl, GWL_USERDATA, (LONG)pfn);

    // Enable/disable controls

    bEnable = IsFlagSet(pvs->dwFlags, VSF_CALL_FWD);

    Button_SetCheck(GetDlgItem(hwnd, IDC_FWD_CHECK), bEnable);
    CallFwd_EnableControls(this, bEnable);

    // Initialize controls

    hwndCtl = GetDlgItem(hwnd, IDC_ACT);
    Edit_SetText(hwndCtl, pvs->szActivationCode);
    Edit_LimitText(hwndCtl, SIZECHARS(pvs->szActivationCode)-1);

    hwndCtl = GetDlgItem(hwnd, IDC_DEACT);
    Edit_SetText(hwndCtl, pvs->szDeactivationCode);
    Edit_LimitText(hwndCtl, SIZECHARS(pvs->szDeactivationCode)-1);

    return TRUE;   // default initial focus
    }


/*----------------------------------------------------------
Purpose: WM_COMMAND Handler
Returns: --
Cond:    --
*/
void PRIVATE CallFwd_OnCommand(
    PCALLFWD this,
    int id,
    HWND hwndCtl,
    UINT uNotifyCode)
    {
    BOOL bCheck;

    switch (id)
        {
    case IDC_FWD_CHECK:
        bCheck = Button_GetCheck(hwndCtl);
        CallFwd_EnableControls(this, bCheck);
        break;

    default:
        break;
        }
    }


/*----------------------------------------------------------
Purpose: Validate the user's settings.

         The call forwarding fields must be filled in if the
         service is turned on.

Returns: TRUE if valid

Cond:    --
*/
BOOL PRIVATE CallFwd_ValidateSettings(
    PCALLFWD this)
    {
    HWND hwnd = this->hdlg;
    HWND hwndCtl;

    // Is the service turned on?
    if (Button_GetCheck(GetDlgItem(hwnd, IDC_FWD_CHECK)))
        {
        // Yes; are the fields filled in?
        hwndCtl = GetDlgItem(hwnd, IDC_ACT);
        if (0 == Edit_GetTextLength(hwndCtl))
            {
            // No; this is naughty
            MsgBox(g_hinst,
                   hwnd, 
                   MAKEINTRESOURCE(IDS_ERR_NEED_VALUE), 
                   MAKEINTRESOURCE(IDS_CAP_CALLFWD),
                   NULL,
                   MB_ERROR);

            // Set the focus on the offending control
            PostMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)hwndCtl, (LPARAM)TRUE);
            return FALSE;
            }


        hwndCtl = GetDlgItem(hwnd, IDC_DEACT);
        if (0 == Edit_GetTextLength(hwndCtl))
            {
            // No; this is naughty
            MsgBox(g_hinst,
                   hwnd, 
                   MAKEINTRESOURCE(IDS_ERR_NEED_VALUE), 
                   MAKEINTRESOURCE(IDS_CAP_CALLFWD),
                   NULL,
                   MB_ERROR);

            // Set the focus on the offending control
            PostMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)hwndCtl, (LPARAM)TRUE);
            return FALSE;
            }
        }
    return TRUE;
    }


/*----------------------------------------------------------
Purpose: PSN_APPLY handler
Returns: --
Cond:    --
*/
BOOL PRIVATE CallFwd_OnApply(
    PCALLFWD this)
    {
    BOOL bRet;
    HWND hwnd = this->hdlg;
    HWND hwndCtl;
    PVOICEFEATURES pvs = &this->pmi->pglobal->vs;

    bRet = CallFwd_ValidateSettings(this);

    if (bRet)
        {
        if (Button_GetCheck(GetDlgItem(hwnd, IDC_FWD_CHECK)))
            {
            SetFlag(pvs->dwFlags, VSF_CALL_FWD);
            }
        else
            {
            ClearFlag(pvs->dwFlags, VSF_CALL_FWD);
            }

        hwndCtl = GetDlgItem(hwnd, IDC_ACT);
        Edit_GetText(hwndCtl, pvs->szActivationCode, SIZECHARS(pvs->szActivationCode));

        hwndCtl = GetDlgItem(hwnd, IDC_DEACT);
        Edit_GetText(hwndCtl, pvs->szDeactivationCode, SIZECHARS(pvs->szDeactivationCode));
        }

    return bRet;
    }


/*----------------------------------------------------------
Purpose: WM_NOTIFY handler
Returns: varies
Cond:    --
*/
LRESULT PRIVATE CallFwd_OnNotify(
    PCALLFWD this,
    int idFrom,
    NMHDR FAR * lpnmhdr)
    {
    LRESULT lRet = 0;
    
    switch (lpnmhdr->code)
        {
    case PSN_SETACTIVE:
        break;

    case PSN_KILLACTIVE:
        // N.b. This message is not sent if user clicks Cancel!
        // N.b. This message is sent prior to PSN_APPLY
        //
        break;

    case PSN_APPLY:
        lRet = CallFwd_OnApply(this) ? PSNRET_NOERROR : PSNRET_INVALID;
        break;

    default:
        break;
        }

    return lRet;
    }


static BOOL s_bCallFwdRecurse = FALSE;

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

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


/*----------------------------------------------------------
Purpose: Real dialog proc
Returns: varies
Cond:    --
*/
LRESULT CallFwd_DlgProc(
    PCALLFWD this,
    UINT message,
    WPARAM wParam,
    LPARAM lParam)
    {
#ifdef CS_HELP
    // UE used the control IDs as help IDs.  To prevent mix-ups in
    // the future (ie, when the control IDs change), here are the 
    // help IDs.
    #define IDH_UNI_CALLFWD_SERVICES        1062
    #define IDH_UNI_CALLFWD_FWD_ACT         1063
    #define IDH_UNI_CALLFWD_ACT             1068
    #define IDH_UNI_CALLFWD_FWD_DEACT       1064
    #define IDH_UNI_CALLFWD_DEACT           1067
#pragma data_seg(DATASEG_READONLY)
    const static DWORD rgHelpIDs[] = {
        IDC_FWD_CHECK,          IDH_UNI_CALLFWD_SERVICES,
        IDC_FWD_ACT,            IDH_UNI_CALLFWD_FWD_ACT,
        IDC_ACT,                IDH_UNI_CALLFWD_ACT,
        IDC_FWD_DEACT,          IDH_UNI_CALLFWD_FWD_DEACT,
        IDC_DEACT,              IDH_UNI_CALLFWD_DEACT,
        0, 0 };
#pragma data_seg()
#endif

    switch (message)
        {
        HANDLE_MSG(this, WM_INITDIALOG, CallFwd_OnInitDialog);
        HANDLE_MSG(this, WM_COMMAND, CallFwd_OnCommand);
        HANDLE_MSG(this, WM_NOTIFY, CallFwd_OnNotify);

#ifdef CS_HELP
    case WM_HELP:
        WinHelp(((LPHELPINFO)lParam)->hItemHandle, c_szUnimdmHelpFile, HELP_WM_HELP, (DWORD)(LPVOID)rgHelpIDs);
        return 0;

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

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


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

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

    this = CallFwd_GetPtr(hDlg);
    if (this == NULL)
        {
        if (message == WM_INITDIALOG)
            {
            this = (PCALLFWD)LocalAlloc(LPTR, sizeof(CALLFWD));
            if (!this)
                {
                MsgBox(g_hinst,
                       hDlg,
                       MAKEINTRESOURCE(IDS_OOM_SETTINGS), 
                       MAKEINTRESOURCE(IDS_CAP_RING),
                       NULL,
                       MB_ERROR);
                EndDialog(hDlg, IDCANCEL);
                return (BOOL)CallFwd_DefProc(hDlg, message, wParam, lParam);
                }
            this->hdlg = hDlg;
            CallFwd_SetPtr(hDlg, this);
            }
        else
            {
            return (BOOL)CallFwd_DefProc(hDlg, message, wParam, lParam);
            }
        }

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

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