1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #include "status/status.hh"
|
---|
10 |
|
---|
11 | i4_status_create_function_type i4_stat_fun=0;
|
---|
12 |
|
---|
13 | void i4_set_status_create_function(i4_status_create_function_type fun)
|
---|
14 | {
|
---|
15 | i4_stat_fun=fun;
|
---|
16 | }
|
---|
17 |
|
---|
18 | i4_idle_class *i4_idle_class::first=0;
|
---|
19 |
|
---|
20 |
|
---|
21 | i4_idle_class::i4_idle_class()
|
---|
22 | {
|
---|
23 | next=first;
|
---|
24 | first=this;
|
---|
25 | }
|
---|
26 |
|
---|
27 | i4_idle_class::~i4_idle_class()
|
---|
28 | {
|
---|
29 | if (first==this)
|
---|
30 | first=first->next;
|
---|
31 | else
|
---|
32 | {
|
---|
33 | i4_idle_class *p=first;
|
---|
34 | for (;p->next && p->next!=this; p=p->next);
|
---|
35 | p->next=next;
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 | #ifdef _WINDOWS
|
---|
42 | #include <windows.h>
|
---|
43 | #include <commctrl.h>
|
---|
44 | #include "main/win_main.hh"
|
---|
45 | #include "string/string.hh"
|
---|
46 | #include "time/time.hh"
|
---|
47 |
|
---|
48 | enum {MAX_UPDATES=50};
|
---|
49 |
|
---|
50 | static int stat_y=40;
|
---|
51 |
|
---|
52 | class win32_status_class : public i4_status_class
|
---|
53 | {
|
---|
54 | public:
|
---|
55 | HWND hwndPB; // handle of progress bar
|
---|
56 | i4_time_class start_time;
|
---|
57 | int last_p;
|
---|
58 | i4_bool win_created;
|
---|
59 | i4_str *description;
|
---|
60 |
|
---|
61 | virtual i4_bool update(float percent)
|
---|
62 | {
|
---|
63 | i4_time_class now;
|
---|
64 | if (now.milli_diff(start_time)>500)
|
---|
65 | {
|
---|
66 | start_time.get();
|
---|
67 |
|
---|
68 | if (!win_created)
|
---|
69 | {
|
---|
70 | InitCommonControls();
|
---|
71 |
|
---|
72 | char buf[100];
|
---|
73 | i4_os_string(*description, buf, 100);
|
---|
74 |
|
---|
75 | hwndPB = CreateWindowEx(0, PROGRESS_CLASS, buf,
|
---|
76 | WS_BORDER | WS_VISIBLE, 50, stat_y,
|
---|
77 | 500, 40,
|
---|
78 | 0, (HMENU) 0, i4_win32_instance, NULL);
|
---|
79 |
|
---|
80 |
|
---|
81 | // Set the range and increment of the progress bar.
|
---|
82 | SendMessage(hwndPB, PBM_SETRANGE, 0, MAKELPARAM(0, MAX_UPDATES));
|
---|
83 | SendMessage(hwndPB, PBM_SETSTEP, (WPARAM) 1, 0);
|
---|
84 | win_created=i4_T;
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | if (win_created)
|
---|
89 | {
|
---|
90 | int p=percent*MAX_UPDATES;
|
---|
91 | while (last_p!=p)
|
---|
92 | {
|
---|
93 | last_p++;
|
---|
94 | SendMessage(hwndPB, PBM_STEPIT, 0, 0);
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | return i4_T;
|
---|
99 | }
|
---|
100 |
|
---|
101 | win32_status_class(const i4_const_str &d)
|
---|
102 | {
|
---|
103 | description=new i4_str(d);
|
---|
104 | win_created=i4_F;
|
---|
105 | last_p=0;
|
---|
106 | stat_y+=60;
|
---|
107 | }
|
---|
108 |
|
---|
109 | virtual ~win32_status_class()
|
---|
110 | {
|
---|
111 | delete description;
|
---|
112 |
|
---|
113 | if (win_created)
|
---|
114 | {
|
---|
115 | while (last_p!=MAX_UPDATES)
|
---|
116 | {
|
---|
117 | last_p++;
|
---|
118 | SendMessage(hwndPB, PBM_STEPIT, 0, 0);
|
---|
119 | }
|
---|
120 |
|
---|
121 | DestroyWindow(hwndPB);
|
---|
122 | }
|
---|
123 |
|
---|
124 | stat_y-=60;
|
---|
125 |
|
---|
126 | }
|
---|
127 | };
|
---|
128 |
|
---|
129 |
|
---|
130 |
|
---|
131 | // this is operating system dependant
|
---|
132 | i4_status_class *i4_create_status(const i4_const_str &description, int flags)
|
---|
133 | {
|
---|
134 | if (i4_stat_fun)
|
---|
135 | return i4_stat_fun(description, flags);
|
---|
136 | else
|
---|
137 | {
|
---|
138 | return new win32_status_class(description);
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 |
|
---|
143 | #else
|
---|
144 |
|
---|
145 |
|
---|
146 | class i4_null_status_class : public i4_status_class
|
---|
147 | {
|
---|
148 | public:
|
---|
149 | i4_bool update(float percent)
|
---|
150 | {
|
---|
151 | for (i4_idle_class *p=i4_idle_class::first; p;p=p->next)
|
---|
152 | p->idle();
|
---|
153 | return i4_T;
|
---|
154 | }
|
---|
155 | };
|
---|
156 |
|
---|
157 |
|
---|
158 | i4_status_class *i4_create_status(const i4_const_str &description, int flags)
|
---|
159 | {
|
---|
160 | if (i4_stat_fun)
|
---|
161 | return i4_stat_fun(description, flags);
|
---|
162 | else
|
---|
163 | return new i4_null_status_class;
|
---|
164 | }
|
---|
165 |
|
---|
166 |
|
---|
167 |
|
---|
168 | #endif
|
---|