forked from RealDeuce/OpenDoors
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathODFrame.c
More file actions
1760 lines (1506 loc) · 60.5 KB
/
Copy pathODFrame.c
File metadata and controls
1760 lines (1506 loc) · 60.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* OpenDoors Online Software Programming Toolkit
* (C) Copyright 1991 - 1999 by Brian Pirie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* File: ODFrame.c
*
* Description: Implements the OpenDoors frame window which provides the
* menu, toolbar, and status bar. The frame window's client
* area contains the display window which shows the door's
* output as the remote user would see it. This file should
* not be built into non-Windows versions of OpenDoors.
*
* Revisions: Date Ver Who Change
* ---------------------------------------------------------------
* Aug 20, 1995 6.00 BP Created.
* Dec 20, 1995 6.00 BP Remember toolbar & statusbar settings.
* Dec 22, 1995 6.00 BP Added od_connect_speed.
* Jan 20, 1996 6.00 BP Made ODFrameCenter...() shared.
* Jan 21, 1996 6.00 BP Added ODScrnShowMessage() and related.
* Feb 17, 1996 6.00 BP Add ...Accelerator() return value.
* Feb 17, 1996 6.00 BP Pass WM_MENUSELECT to DefWindowProc().
* Feb 19, 1996 6.00 BP Changed version number to 6.00.
* Feb 21, 1996 6.00 BP Fixed user keyboard off command.
* Feb 22, 1996 6.00 BP Allow escape to close Help About box.
* Feb 23, 1996 6.00 BP Properly update when toolbar turned on
* Mar 03, 1996 6.10 BP Begin version 6.10.
* Mar 14, 1996 6.10 BP Added configuration menu option.
* Aug 10, 2003 6.23 SH *nix support
*/
#define BUILDING_OPENDOORS
#include <stdio.h>
#include "ws2tcpip.h"
#include "windows.h"
#include "commctrl.h"
#include "OpenDoor.h"
#include "ODRes.h"
#include "ODFrame.h"
#include "ODGen.h"
#include "ODScrn.h"
#include "ODKrnl.h"
#ifdef ODPLAT_WIN32
/* Frame window information structure. */
typedef struct
{
HINSTANCE hInstance;
BOOL bToolbarOn;
HWND hwndToolbar;
BOOL bStatusBarOn;
HWND hwndStatusBar;
HWND hwndTimeEdit;
HWND hwndTimeUpDown;
BOOL bWantsChatIndicator;
HACCEL hacclFrameCommands;
HWND hwndMessageWindow;
char *pszCurrentMessage;
int nCurrentMessageFlags;
} tODFrameWindowInfo;
/* Toolbar button information. */
TBBUTTON atbButtons[] =
{
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
{0, ID_DOOR_CHATMODE, TBSTATE_ENABLED, TBSTYLE_BUTTON,},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
{1, ID_DOOR_USERKEYBOARDOFF, TBSTATE_ENABLED, TBSTYLE_BUTTON},
{2, ID_DOOR_SYSOPNEXT, TBSTATE_ENABLED, TBSTYLE_BUTTON},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP},
{3, ID_DOOR_HANGUP, TBSTATE_ENABLED, TBSTYLE_BUTTON},
{4, ID_DOOR_LOCKOUT, TBSTATE_ENABLED, TBSTYLE_BUTTON},
{5, ID_DOOR_EXIT, TBSTATE_ENABLED, TBSTYLE_BUTTON},
};
/* Other toolbar settings. */
#define NUM_TOOLBAR_BITMAPS 6
#define MIN_TIME 0
#define MAX_TIME 1440
/* Pointer to default edit box window procedure. */
WNDPROC pfnDefEditProc = NULL;
WNDPROC pfnDefToolbarProc = NULL;
/* Global frame window handle. */
static HWND hwndCurrentFrame;
/* Status bar settings. */
#define NUM_STATUS_PARTS 2
#define NODE_PART_WIDTH 65
/* Child window IDs. */
#define ID_TOOLBAR 1000
#define ID_TIME_EDIT 1001
#define ID_TIME_UPDOWN 1002
#define ID_STATUSBAR 1003
/* Private function prototypes. */
static HWND ODFrameCreateToolbar(HWND hwndParent, HANDLE hInstance,
tODFrameWindowInfo *pWindowInfo);
static void ODFrameDestroyToolbar(HWND hwndToolbar,
tODFrameWindowInfo *pWindowInfo);
static HWND ODFrameCreateStatusBar(HWND hwndParent, HANDLE hInstance);
static void ODFrameSetMainStatusText(HWND hwndStatusBar);
static void ODFrameDestroyStatusBar(HWND hwndStatusBar);
static void ODFrameSizeStatusBar(HWND hwndStatusBar);
LRESULT CALLBACK ODFrameWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
LPARAM lParam);
LRESULT CALLBACK ODFrameToolbarProc(HWND hwnd, UINT uMsg, WPARAM wParam,
LPARAM lParam);
static void ODFrameUpdateTimeLeft(tODFrameWindowInfo *pWindowInfo);
LRESULT CALLBACK ODFrameTimeEditProc(HWND hwnd, UINT uMsg, WPARAM wParam,
LPARAM lParam);
INT_PTR CALLBACK ODFrameAboutDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam);
static HWND ODFrameCreateWindow(HANDLE hInstance);
static void ODFrameDestroyWindow(HWND hwndFrame);
static void ODFrameMessageLoop(HANDLE hInstance, HWND hwndFrame);
DWORD OD_THREAD_FUNC ODFrameThreadProc(void *pParam);
INT_PTR CALLBACK ODFrameMessageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam);
/* ----------------------------------------------------------------------------
* ODFrameCreateWindow() *** PRIVATE FUNCTION ***
*
* Creates the OpenDoors frame window and its children.
*
* Parameters: hInstance - Handle to application instance.
*
* Return: A handle to the newly created window, or NULL on failure.
*/
static HWND ODFrameCreateWindow(HANDLE hInstance)
{
HWND hwndFrameWindow = NULL;
WNDCLASS wcFrameWindow;
tODFrameWindowInfo *pWindowInfo = NULL;
tODThreadHandle hScreenThread;
HKEY hOpenDoorsKey;
DWORD cbData;
/* Register the main frame window's window class. */
memset(&wcFrameWindow, 0, sizeof(wcFrameWindow));
wcFrameWindow.style = CS_HREDRAW | CS_VREDRAW;
wcFrameWindow.lpfnWndProc = ODFrameWindowProc;
wcFrameWindow.cbClsExtra = 0;
wcFrameWindow.cbWndExtra = 0;
wcFrameWindow.hInstance = hInstance;
if(od_control.od_app_icon != NULL)
{
wcFrameWindow.hIcon = od_control.od_app_icon;
}
else
{
wcFrameWindow.hIcon
= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_OPENDOORS));
}
wcFrameWindow.hCursor = LoadCursor(NULL, IDC_ARROW);
wcFrameWindow.hbrBackground = NULL;
wcFrameWindow.lpszMenuName = MAKEINTRESOURCE(IDR_FRAME_MENU);
wcFrameWindow.lpszClassName = "ODFrame";
RegisterClass(&wcFrameWindow);
/* Setup window information structure. */
pWindowInfo = malloc(sizeof(tODFrameWindowInfo));
if(!pWindowInfo)
{
return(NULL);
}
pWindowInfo->hInstance = hInstance;
pWindowInfo->hwndTimeEdit = NULL;
pWindowInfo->hwndTimeUpDown = NULL;
pWindowInfo->bWantsChatIndicator = FALSE;
pWindowInfo->hwndMessageWindow = NULL;
/* Determine whether or not the toolbar and status bar are on. */
RegCreateKey(HKEY_CURRENT_USER, "Software\\Pirie\\OpenDoors",
&hOpenDoorsKey);
cbData = sizeof(pWindowInfo->bToolbarOn);
if(RegQueryValueEx(hOpenDoorsKey, "ToolBarOn", NULL, NULL,
(LPBYTE)&pWindowInfo->bToolbarOn,
&cbData) != ERROR_SUCCESS)
{
pWindowInfo->bToolbarOn = TRUE;
RegSetValueEx(hOpenDoorsKey, "ToolBarOn", 0, REG_DWORD,
(LPBYTE)&pWindowInfo->bToolbarOn,
sizeof(pWindowInfo->bToolbarOn));
}
cbData = sizeof(pWindowInfo->bStatusBarOn);
if(RegQueryValueEx(hOpenDoorsKey, "StatusBarOn", NULL, NULL,
(LPBYTE)&pWindowInfo->bStatusBarOn,
&cbData) != ERROR_SUCCESS)
{
pWindowInfo->bStatusBarOn = TRUE;
RegSetValueEx(hOpenDoorsKey, "StatusBarOn", 0, REG_DWORD,
(LPBYTE)&pWindowInfo->bStatusBarOn,
sizeof(pWindowInfo->bStatusBarOn));
}
RegCloseKey(hOpenDoorsKey);
/* Create the main frame window. */
if((hwndFrameWindow = CreateWindowEx(
0L,
wcFrameWindow.lpszClassName,
od_control.od_prog_name,
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_BORDER | WS_MINIMIZEBOX,
CW_USEDEFAULT,
0,
0,
0,
NULL,
NULL,
hInstance,
pWindowInfo)) == NULL)
{
/* On window creation failure, return NULL. */
return(NULL);
}
/* Load accelerator table for the frame window. */
pWindowInfo->hacclFrameCommands
= LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_FRAME));
/* Create the OpenDoors toolbar. On failure, we will continue anyhow. */
if(pWindowInfo->bToolbarOn)
{
pWindowInfo->hwndToolbar =
ODFrameCreateToolbar(hwndFrameWindow, hInstance, pWindowInfo);
}
/* Create the status bar. On failure, we will continue anyhow. */
if(pWindowInfo->bStatusBarOn)
{
pWindowInfo->hwndStatusBar =
ODFrameCreateStatusBar(hwndFrameWindow, hInstance);
}
/* Updates state of the window from whether or not the user has */
/* requested a chat with the sysop. */
ODFrameUpdateWantChat();
/* Create the local screen window, which occupies the remaining */
/* client area of the frame window. */
ODScrnStartWindow(hInstance, &hScreenThread, hwndFrameWindow);
return(hwndFrameWindow);
}
/* ----------------------------------------------------------------------------
* ODFrameCreateToolbar() *** PRIVATE FUNCTION ***
*
* Creates the OpenDoors toolbar.
*
* Parameters: hwndParent - Handle to the parent window.
*
* hInstance - Handle to the executable file's module instance.
*
* pWindowInfo - Pointer to frame window information structure.
*
* Return: A handle to the toolbar on success, or NULL on failure.
*/
static HWND ODFrameCreateToolbar(HWND hwndParent, HANDLE hInstance,
tODFrameWindowInfo *pWindowInfo)
{
HWND hwndToolbar = NULL;
HWND hwndTimeEdit = NULL;
HWND hwndTimeUpDown = NULL;
HWND hwndToolTip;
BOOL bSuccess = FALSE;
ASSERT(hwndParent != NULL);
ASSERT(hInstance != NULL);
ASSERT(pWindowInfo != NULL);
/* First, attempt to create the toolbar window. */
hwndToolbar = CreateToolbarEx(hwndParent,
WS_CHILD | WS_BORDER | WS_VISIBLE | TBSTYLE_TOOLTIPS,
ID_TOOLBAR, NUM_TOOLBAR_BITMAPS, hInstance, IDB_TOOLBAR,
atbButtons, DIM(atbButtons), 0, 0, 0, 0, sizeof(TBBUTTON));
if(hwndToolbar == NULL)
{
goto CleanUp;
}
/* Change the window proc for the toolbar window to our own, keeping a */
/* pointer to the original window proc. */
pfnDefToolbarProc = (WNDPROC)GetWindowLongPtr(hwndToolbar, GWLP_WNDPROC);
SetWindowLongPtr(hwndToolbar, GWLP_WNDPROC, (LONG_PTR)ODFrameToolbarProc);
/* Next, create an edit control on the toolbar, to allow the user's */
/* time remaining online to be adjusted. */
hwndTimeEdit = CreateWindowEx(WS_EX_STATICEDGE, "EDIT", "",
WS_CHILD | WS_BORDER | WS_VISIBLE | ES_LEFT,
0, 0, 70, 22, hwndToolbar, (HMENU)ID_TIME_EDIT, hInstance, NULL);
if(hwndTimeEdit == NULL)
{
goto CleanUp;
}
/* Now that the edit window has the appropriate parent, we set its */
/* position accordingly. */
SetWindowPos(hwndTimeEdit, NULL, 2, 2, 0, 0,
SWP_NOZORDER | SWP_NOSIZE);
/* Set font of the edit control to be the standard non-bold font. */
SendMessage(hwndTimeEdit, WM_SETFONT,
(WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(FALSE, 0));
/* Change the window proc for the edit window to our own, keeping a */
/* pointer to the original window proc. */
pfnDefEditProc = (WNDPROC)GetWindowLongPtr(hwndTimeEdit, GWLP_WNDPROC);
SetWindowLongPtr(hwndTimeEdit, GWLP_WNDPROC, (LONG_PTR)ODFrameTimeEditProc);
/* Add the time edit control to the tooltip control. */
/* Obtain a handle to the toolbar's tooltip control. */
hwndToolTip = (HWND)SendMessage(hwndToolbar, TB_GETTOOLTIPS, 0, 0);
if(hwndToolTip)
{
TOOLINFO ToolInfo;
/* Fill TOOLINFO structure. */
ToolInfo.cbSize = sizeof(ToolInfo);
ToolInfo.uFlags = TTF_IDISHWND | TTF_CENTERTIP;
ToolInfo.lpszText = "User's Time Remaining";
ToolInfo.hwnd = hwndParent;
ToolInfo.uId = (UINT_PTR)hwndTimeEdit;
ToolInfo.hinst = hInstance;
/* Setup tooltips for the time edit box. */
SendMessage(hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ToolInfo);
}
/* Now, we create an up-down control to buddy with the edit control. */
hwndTimeUpDown = CreateWindowEx(0L, UPDOWN_CLASS, "",
WS_CHILD | WS_BORDER | WS_VISIBLE | UDS_ARROWKEYS |
UDS_ALIGNRIGHT, 0, 0, 8, 8,
hwndToolbar, (HMENU)ID_TIME_UPDOWN, hInstance, NULL);
if(hwndTimeUpDown == NULL)
{
goto CleanUp;
}
/* Set the up-down control's buddy control to be the edit control that */
/* we just created. */
SendMessage(hwndTimeUpDown, UDM_SETBUDDY, (LPARAM)hwndTimeEdit, 0L);
/* Set the valid range of values for the edit control. */
SendMessage(hwndTimeUpDown, UDM_SETRANGE, 0L, MAKELONG(MAX_TIME, MIN_TIME));
/* Store handles to time limit edit and up-down controls. */
pWindowInfo->hwndTimeEdit = hwndTimeEdit;
pWindowInfo->hwndTimeUpDown = hwndTimeUpDown;
/* Next, we set the default text for the edit control. */
ODFrameUpdateTimeLeft(pWindowInfo);
/* Return with success. */
bSuccess = TRUE;
CleanUp:
if(!bSuccess)
{
/* On failure, free any allocated resources. */
if(hwndTimeUpDown != NULL)
{
DestroyWindow(hwndTimeUpDown);
}
if(hwndTimeEdit != NULL)
{
DestroyWindow(hwndTimeUpDown);
}
if(hwndToolbar != NULL)
{
DestroyWindow(hwndToolbar);
hwndToolbar = NULL;
}
}
/* Return handle to newly created toolbar, or NULL on failure. */
return(hwndToolbar);
}
/* ----------------------------------------------------------------------------
* ODFrameDestroyToolbar() *** PRIVATE FUNCTION ***
*
* Destroys the OpenDoors toolbar.
*
* Parameters: hwndToolbar - Handle to previously created toolbar.
*
* pWindowInfo - Pointer to frame window information structure.
*
* Return: void.
*/
static void ODFrameDestroyToolbar(HWND hwndToolbar,
tODFrameWindowInfo *pWindowInfo)
{
ASSERT(hwndToolbar != NULL);
ASSERT(pWindowInfo != NULL);
/* Destroy the time up-down control, and NULL its handle in the frame */
/* window information structure. */
DestroyWindow(pWindowInfo->hwndTimeUpDown);
pWindowInfo->hwndTimeUpDown = NULL;
/* Destroy the time edit control, and NULL its handle in the frame window */
/* information structure. */
DestroyWindow(pWindowInfo->hwndTimeEdit);
pWindowInfo->hwndTimeEdit = NULL;
/* Now, destroy the toolbar itself. */
DestroyWindow(hwndToolbar);
}
/* ----------------------------------------------------------------------------
* ODFrameCreateStatusBar() *** PRIVATE FUNCTION ***
*
* Creates the OpenDoors status bar.
*
* Parameters: hwndParent - Handle to the parent window.
*
* hInstance - Handle to the executable file's module instance.
*
* Return: A handle to the status bar on success, or NULL on failure.
*/
static HWND ODFrameCreateStatusBar(HWND hwndParent, HANDLE hInstance)
{
HWND hwndStatusBar = NULL;
char szStatusText[20];
ASSERT(hwndParent != NULL);
/* Create the status bar window. */
hwndStatusBar = CreateWindowEx(0L, STATUSCLASSNAME, "",
WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
hwndParent, (HMENU)ID_STATUSBAR, hInstance, NULL);
if(hwndStatusBar == NULL)
{
return(NULL);
}
/* Set the size of the status bar parts from the size of the frame */
/* window. */
ODFrameSizeStatusBar(hwndStatusBar);
/* Add the user's name, location and connection info string. */
ODFrameSetMainStatusText(hwndStatusBar);
/* Add the node number string. */
sprintf(szStatusText, "Node %d", od_control.od_node);
SendMessage(hwndStatusBar, SB_SETTEXT, (WPARAM)1, (LPARAM)szStatusText);
return(hwndStatusBar);
}
/* ----------------------------------------------------------------------------
* ODFrameSetMainStatusText() *** PRIVATE FUNCTION ***
*
* Updates the text that is displayed in the main pane of the status bar.
*
* Parameters: hwndStatusBar - Handle to the status bar.
*
* Return: void.
*/
static void ODFrameSetMainStatusText(HWND hwndStatusBar)
{
char szStatusText[160];
ASSERT(hwndStatusBar != NULL);
/* Generate base status bar text, with the user's name, location and */
/* connection information. */
if(od_control.baud == 0)
{
sprintf(szStatusText, "%s of %s in local mode",
od_control.user_name,
od_control.user_location);
}
else
{
sprintf(szStatusText, "%s of %s at %ldbps",
od_control.user_name,
od_control.user_location,
od_control.od_connect_speed);
}
/* If the user has paged the sysop, then include reason for chat if */
/* it is available. */
if(od_control.user_wantchat && strlen(od_control.user_reasonforchat) > 0)
{
strcat(szStatusText, " (Reason for chat: \"");
strcat(szStatusText, od_control.user_reasonforchat);
strcat(szStatusText, "\")");
}
/* Update status bar text in the main status bar pane with the newly */
/* generated string. */
SendMessage(hwndStatusBar, SB_SETTEXT, (WPARAM)0, (LPARAM)szStatusText);
}
/* ----------------------------------------------------------------------------
* ODFrameDestroyStatusBar() *** PRIVATE FUNCTION ***
*
* Destroys the OpenDoors status bar.
*
* Parameters: hwndStatusBar - Handle to previously created status bar.
*
* Return: void.
*/
static void ODFrameDestroyStatusBar(HWND hwndStatusBar)
{
DestroyWindow(hwndStatusBar);
}
/* ----------------------------------------------------------------------------
* ODFrameSizeStatusBar() *** PRIVATE FUNCTION ***
*
* Creates the OpenDoors status bar.
*
* Parameters: hwndStatusBar - Handle to existing status bar window.
*
* Return: void.
*/
static void ODFrameSizeStatusBar(HWND hwndStatusBar)
{
int anWidths[NUM_STATUS_PARTS];
int nStatusWidth;
RECT rcStatusBar;
/* Determine the total width of the status bar. */
GetWindowRect(hwndStatusBar, &rcStatusBar);
nStatusWidth = rcStatusBar.right - rcStatusBar.left;
/* Calculate the width of the parts from the total width. */
anWidths[0] = nStatusWidth - NODE_PART_WIDTH;
anWidths[1] = -1;
/* Update the status bar part settings. */
SendMessage(hwndStatusBar, SB_SETPARTS, NUM_STATUS_PARTS,
(LPARAM)anWidths);
}
/* ----------------------------------------------------------------------------
* ODFrameGetUsedClientAtTop()
*
* Determines height in pixels of the space used at the top of the
* frame window's client area, by the toolbar, etc.
*
* Parameters: hwndFrame - Handle to the OpenDoors frame window.
*
* Return: The height of the used space, in pixels.
*/
INT ODFrameGetUsedClientAtTop(HWND hwndFrame)
{
tODFrameWindowInfo *pWindowInfo;
RECT rcWindow;
pWindowInfo = (tODFrameWindowInfo *)GetWindowLongPtr(hwndFrame, GWLP_USERDATA);
if(!pWindowInfo->bToolbarOn) return(0);
GetWindowRect(pWindowInfo->hwndToolbar, &rcWindow);
return(rcWindow.bottom - rcWindow.top - 2);
}
/* ----------------------------------------------------------------------------
* ODFrameGetUsedClientAtBottom()
*
* Determines height in pixels of the space used at the bottom of the
* frame window's client area, by the status bar, etc.
*
* Parameters: hwndFrame - Handle to the OpenDoors frame window.
*
* Return: The height of the used space, in pixels.
*/
INT ODFrameGetUsedClientAtBottom(HWND hwndFrame)
{
tODFrameWindowInfo *pWindowInfo;
RECT rcWindow;
pWindowInfo = (tODFrameWindowInfo *)GetWindowLongPtr(hwndFrame, GWLP_USERDATA);
if(!pWindowInfo->bStatusBarOn) return(0);
GetWindowRect(pWindowInfo->hwndStatusBar, &rcWindow);
return(rcWindow.bottom - rcWindow.top - 1);
}
/* ----------------------------------------------------------------------------
* ODFrameWindowProc() *** PRIVATE FUNCTION ***
*
* The OpenDoors frame window proceedure.
*
* Parameters: hwnd - Handle to the OpenDoors frame window.
*
* uMsg - Specifies the message.
*
* wParam - Specifies additional message information. The content
* of this parameter depends on the value of the uMsg
* parameter.
*
* lParam - Specifies additional message information. The content
* of this parameter depends on the value of the uMsg
* parameter.
*
* Return: The return value is the result of the message processing and
* depends on the message.
*/
LRESULT CALLBACK ODFrameWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
tODFrameWindowInfo *pWindowInfo;
pWindowInfo = (tODFrameWindowInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
switch(uMsg)
{
case WM_CREATE:
{
/* At window creation time, store a pointer to the window */
/* information structure in window's user data. */
CREATESTRUCT *pCreateStruct = (CREATESTRUCT *)lParam;
pWindowInfo = (tODFrameWindowInfo *)pCreateStruct->lpCreateParams;
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pWindowInfo);
/* Update the enabled and checked states of frame window commands. */
ODFrameUpdateCmdUI();
/* If the client has not provided a help callback function, then */
/* remove the Contents item from the help menu. */
if(od_control.od_help_callback == NULL)
{
RemoveMenu(GetMenu(hwnd), ID_HELP_CONTENTS, MF_BYCOMMAND);
}
if(od_control.od_config_callback == NULL)
{
RemoveMenu(GetMenu(hwnd), ID_DOOR_CONFIG, MF_BYCOMMAND);
}
break;
}
case WM_CLOSE:
/* If door exit has been chosen, confirm with local user. */
if(MessageBox(hwnd,
"You are about to terminate this session and return the user to the BBS.\nDo you wish to proceed?",
od_control.od_prog_name,
MB_ICONQUESTION | MB_YESNO) == IDYES)
{
/* Normal door exit (drop to BBS) is implemented by the */
/* WM_DESTROY handler. */
ODFrameDestroyWindow(hwnd);
}
break;
case WM_DESTROY:
/* If toolbar is on, then it must be destroyed when the frame */
/* window is destroyed. */
if(pWindowInfo->bToolbarOn)
{
ODFrameDestroyToolbar(GetDlgItem(hwnd, ID_TOOLBAR), pWindowInfo);
}
/* If status bar is on, then it must be destroyed when the frame */
/* window is destroyed. */
if(pWindowInfo->bStatusBarOn)
{
ODFrameDestroyStatusBar(GetDlgItem(hwnd, ID_STATUSBAR));
}
/* Now, force OpenDoors to shutdown. */
ODKrnlForceOpenDoorsShutdown(ERRORLEVEL_DROPTOBBS);
/* When the frame window is destroyed, it is the window proc's */
/* responsiblity to deallocate the window information structure. */
free(pWindowInfo);
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)NULL);
/* Reset current frame window handle. */
hwndCurrentFrame = NULL;
break;
case WM_SETFOCUS:
/* Whenver input focus is set to the frame window, pass the input */
/* focus on to the screen window, which fills most of our client */
/* area. */
ODScrnSetFocusToWindow();
break;
case WM_TIMER:
/* If the window flash timer has elapsed, then flash the window. */
FlashWindow(hwnd, TRUE);
break;
case WM_COMMAND:
/* An OpenDoors-defined command has been selected, so switch on */
/* the command ID. */
switch(LOWORD(wParam))
{
case ID_HELP_ABOUT:
/* Display the OpenDoors default about box. */
DialogBox(pWindowInfo->hInstance, MAKEINTRESOURCE(IDD_ABOUT),
hwnd, ODFrameAboutDlgProc);
break;
case ID_HELP_CONTENTS:
/* Call the client's help callback function, if one was */
/* provided. */
if(od_control.od_help_callback != NULL)
{
(*od_control.od_help_callback)();
}
break;
case ID_DOOR_CONFIG:
if(od_control.od_config_callback != NULL)
{
(*od_control.od_config_callback)();
}
break;
case ID_DOOR_EXIT:
/* On request for normal door exit (drop to BBS), just send */
/* a close message to this window. This will prompt to */
/* confirm exit, and then shutdown OpenDoors if appropriate. */
PostMessage(hwnd, WM_CLOSE, 0, 0L);
break;
case ID_DOOR_CHATMODE:
/* If chat mode is currently active, then end it. */
if(od_control.od_chat_active)
{
ODKrnlEndChatMode();
}
/* If chat mode is not currently active, then start it. */
else
{
ODKrnlStartChatThread(TRUE);
}
break;
case ID_DOOR_USERKEYBOARDOFF:
/* If user keyboard off command has been chosen, then toggle */
/* keyboard off mode on or off. */
od_control.od_user_keyboard_on
= !od_control.od_user_keyboard_on;
/* Update the keyboard off menu item and toolbar button. */
CheckMenuItem(GetMenu(hwnd), ID_DOOR_USERKEYBOARDOFF,
MF_BYCOMMAND | (od_control.od_user_keyboard_on
? MF_UNCHECKED : MF_CHECKED));
SendMessage(GetDlgItem(hwnd, ID_TOOLBAR), TB_CHECKBUTTON,
ID_DOOR_USERKEYBOARDOFF,
MAKELONG(!od_control.od_user_keyboard_on, 0));
break;
case ID_DOOR_SYSOPNEXT:
/* If sysop next command has been chosen, then toggle the */
/* sysop next flag on or off. */
od_control.sysop_next = !od_control.sysop_next;
/* Update the sysop next menu item and toolbar button. */
CheckMenuItem(GetMenu(hwnd), ID_DOOR_SYSOPNEXT, MF_BYCOMMAND |
(od_control.sysop_next ? MF_CHECKED : MF_UNCHECKED));
SendMessage(GetDlgItem(hwnd, ID_TOOLBAR), TB_CHECKBUTTON,
ID_DOOR_SYSOPNEXT, MAKELONG(od_control.sysop_next, 0));
break;
case ID_DOOR_HANGUP:
/* If hangup command has been chosen, then confirm with the */
/* local user. */
if(MessageBox(hwnd,
"You are about to disconnect this user. Do you wish to proceed?",
od_control.od_prog_name,
MB_ICONQUESTION | MB_YESNO) == IDYES)
{
ODKrnlForceOpenDoorsShutdown(ERRORLEVEL_HANGUP);
}
break;
case ID_DOOR_LOCKOUT:
/* If lockout command has been chosen, the confirm with the */
/* local user. */
if(MessageBox(hwnd,
"You are about to lock out this user. Do you wish to proceed?",
od_control.od_prog_name,
MB_ICONQUESTION | MB_YESNO) == IDYES)
{
/* Set the user's access security level to 0. */
od_control.user_security = 0;
ODKrnlForceOpenDoorsShutdown(ERRORLEVEL_HANGUP);
}
break;
case ID_VIEW_TOOL_BAR:
{
HKEY hOpenDoorsKey;
/* If toolbar on/off command has been chosen ... */
if(pWindowInfo->bToolbarOn)
{
/* If the toolbar is on, then turn it off. */
ODFrameDestroyToolbar(GetDlgItem(hwnd, ID_TOOLBAR),
pWindowInfo);
pWindowInfo->bToolbarOn = FALSE;
CheckMenuItem(GetMenu(hwnd), ID_VIEW_TOOL_BAR,
MF_BYCOMMAND | MF_UNCHECKED);
}
else
{
/* If the toolbar is off, then turn it on. */
pWindowInfo->hwndToolbar = ODFrameCreateToolbar(hwnd,
pWindowInfo->hInstance, pWindowInfo);
pWindowInfo->bToolbarOn = TRUE;
CheckMenuItem(GetMenu(hwnd), ID_VIEW_TOOL_BAR,
MF_BYCOMMAND | MF_CHECKED);
ODFrameUpdateCmdUI();
}
/* Adjust window sizes accordingly. */
ODScrnAdjustWindows();
/* Update the toolbar setting in the registry. */
RegCreateKey(HKEY_CURRENT_USER, "Software\\Pirie\\OpenDoors",
&hOpenDoorsKey);
RegSetValueEx(hOpenDoorsKey, "ToolBarOn", 0, REG_DWORD,
(LPBYTE)&pWindowInfo->bToolbarOn,
sizeof(pWindowInfo->bToolbarOn));
RegCloseKey(hOpenDoorsKey);
break;
}
case ID_VIEW_STAT_BAR:
{
HKEY hOpenDoorsKey;
/* If the status bar on/off command has been chosen ... */
if(pWindowInfo->bStatusBarOn)
{
/* If the status bar is on, then turn it off. */
pWindowInfo->bStatusBarOn = FALSE;
CheckMenuItem(GetMenu(hwnd), ID_VIEW_STAT_BAR,
MF_BYCOMMAND | MF_UNCHECKED);
ODFrameDestroyStatusBar(GetDlgItem(hwnd, ID_STATUSBAR));
}
else
{
/* If the status bar is off, then turn it on. */
pWindowInfo->bStatusBarOn = TRUE;
CheckMenuItem(GetMenu(hwnd), ID_VIEW_STAT_BAR,
MF_BYCOMMAND | MF_CHECKED);
pWindowInfo->hwndStatusBar =
ODFrameCreateStatusBar(hwnd, pWindowInfo->hInstance);
}
/* Adjust window sizes accordingly. */
ODScrnAdjustWindows();
/* Update the status bar setting in the registry. */
RegCreateKey(HKEY_CURRENT_USER, "Software\\Pirie\\OpenDoors",
&hOpenDoorsKey);
RegSetValueEx(hOpenDoorsKey, "StatusBarOn", 0, REG_DWORD,
(LPBYTE)&pWindowInfo->bStatusBarOn,
sizeof(pWindowInfo->bStatusBarOn));
RegCloseKey(hOpenDoorsKey);
break;
}
case ID_USER_ADDONEMINUTE:
/* If add one minute command has been chosen, then */
/* increment the user's time, up to the maximum allowable */
/* time. */
if(od_control.user_timelimit < MAX_TIME)
{
od_control.user_timelimit++;
ODFrameUpdateTimeLeft(pWindowInfo);
}
break;
case ID_USER_ADDFIVEMINUTES:
/* If add five minutes command has been chosen, then */
/* adjust the user's time accordingly. */
od_control.user_timelimit =
MIN(od_control.user_timelimit + 5, MAX_TIME);
ODFrameUpdateTimeLeft(pWindowInfo);
break;
case ID_USER_SUBTRACTONEMINUTE:
/* If subtract one minute command has been chosen, then */
/* adjust the user's time accordingly. */
if(od_control.user_timelimit > MIN_TIME)
{
od_control.user_timelimit--;
ODFrameUpdateTimeLeft(pWindowInfo);
}
break;
case ID_USER_SUBTRACTFIVEMINUTES:
/* If the subtract five mintues command has been chosen, */
/* then adjust the user's time accordingly. */
od_control.user_timelimit =
MAX(od_control.user_timelimit - 5, MIN_TIME);
ODFrameUpdateTimeLeft(pWindowInfo);
break;
case ID_USER_INACTIVITYTIMER:
/* If the user inactivity timer command has been chosen, */
/* then toggle the timer on or off. */
od_control.od_disable_inactivity =
!od_control.od_disable_inactivity;
CheckMenuItem(GetMenu(hwnd), ID_USER_INACTIVITYTIMER,
MF_BYCOMMAND | (od_control.od_disable_inactivity ?
MF_UNCHECKED : MF_CHECKED));
break;
case ID_TIME_EDIT:
{
/* If the user's time remaining has been directly edited, */
/* then adjust the time limit accordingly. */
if(HIWORD(wParam) == EN_CHANGE)
{
char szTimeText[40];
GetWindowText((HWND)lParam, szTimeText, sizeof(szTimeText));
od_control.user_timelimit = atoi(szTimeText);
/* Do not allow the time limit to fall outside of the */
/* valid range. */
od_control.user_timelimit =
MAX(MIN_TIME, od_control.user_timelimit);
od_control.user_timelimit =
MIN(MAX_TIME, od_control.user_timelimit);
/* Update the position of the up-down control. */
SendMessage(pWindowInfo->hwndTimeUpDown, UDM_SETPOS, 0,
(LPARAM)MAKELONG(od_control.user_timelimit, 0));
}
}
default:
return(TRUE);
}
return(FALSE);
case WM_NOTIFY:
/* A control parent notification message has been sent. */
switch(((LPNMHDR)lParam)->code)
{
case TTN_NEEDTEXT:
{
/* This is the message from the tool tip control, requesting */
/* the appropriate string to display for the current toolbar */
/* item. */
LPTOOLTIPTEXT lpToolTipText = (LPTOOLTIPTEXT)lParam;