2004-11-21 Casper S. Hornstrup <chorns@users.sourceforge.net>
[reactos.git] / rosapps / calc / stats.c
1 /*
2 * WineCalc (stats.c)
3 *
4 * Copyright 2003 James Briggs
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include <stdio.h> // sprintf
22
23 #include <windows.h>
24
25 #include "stats.h"
26 #include "resource.h"
27 #include "winecalc.h"
28
29 HWND hWndListBox;
30
31 extern CALC calc;
32 extern HWND hWndDlgStats;
33
34 BOOL CALLBACK StatsDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
35 {
36 HDC hdc;
37 PAINTSTRUCT ps;
38
39
40 switch( uMsg ) {
41
42 case WM_INITDIALOG:
43 hWndListBox = CreateWindow(
44 "LISTBOX", // pointer to registered class name
45 "Listbox", // pointer to window name
46 WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER | LBS_NOINTEGRALHEIGHT, // window style
47 6, // horizontal position of window
48 6, // vertical position of window
49 208, // window width
50 66, // window height
51 hDlg, // handle to parent or owner window
52 NULL, // handle to menu or child-window identifier
53 NULL, // handle to application instance
54 NULL // pointer to window-creation data
55 );
56
57 ShowWindow(hWndListBox, SW_SHOW);
58
59 SendMessage (hWndListBox, WM_SETFONT, (UINT)GetStockObject(DEFAULT_GUI_FONT), TRUE);
60
61 // SetFocus(hWndDlgStats);
62
63 return TRUE;
64
65 case WM_COMMAND:
66 switch( LOWORD( wParam ) ) {
67
68 case ID_STATS_RET:
69 SetFocus(GetParent(hDlg));
70 return 0;
71
72 case ID_STATS_LOAD:
73 {
74 int i;
75
76 i = SendMessage(hWndListBox, LB_GETCURSEL, 0, 0);
77 SendMessage(hWndListBox, LB_GETTEXT, i, (LPARAM)calc.buffer);
78 calc_buffer_display(&calc);
79 }
80 return 0;
81
82 case ID_STATS_CD:
83 {
84 int i;
85
86 i = SendMessage(hWndListBox, LB_GETCURSEL, 0, 0);
87 SendMessage(hWndListBox, LB_DELETESTRING, i, 0);
88 InvalidateRect(hDlg,NULL,TRUE);
89 UpdateWindow(hDlg);
90 }
91 return 0;
92
93 case ID_STATS_CAD:
94 SendMessage(hWndListBox, LB_RESETCONTENT, 0, 0);
95 InvalidateRect(hDlg,NULL,TRUE);
96 UpdateWindow(hDlg);
97 return 0;
98 }
99 break;
100
101 case WM_PAINT:
102 {
103 char s[CALC_BUF_SIZE];
104 int lb_count;
105 HFONT hFont;
106 HFONT hFontOrg;
107
108 hdc = BeginPaint( hDlg, &ps );
109 hFont = GetStockObject(DEFAULT_GUI_FONT);
110 hFontOrg = SelectObject(hdc, hFont);
111
112 lb_count = SendMessage(hWndListBox, LB_GETCOUNT, 0, 0);
113 sprintf(s, "n=%d", lb_count);
114
115 SetBkMode(hdc, TRANSPARENT);
116 TextOut(hdc, 98, 121, s, strlen(s));
117 SelectObject(hdc, hFontOrg);
118 EndPaint( hDlg, &ps );
119
120 return 0;
121 }
122 case WM_CLOSE:
123 hWndDlgStats = 0; // invalidate stats dialog
124 SendMessage(GetParent(hDlg), WM_CHAR, '\x13', 1); // disable stats related calculator buttons
125 DestroyWindow( hDlg );
126
127 return 0;
128 }
129 return FALSE;
130 }
131