1 | /* ***** BEGIN LICENSE BLOCK ***** |
---|
2 | * Version: CDDL 1.0/LGPL 2.1 |
---|
3 | * |
---|
4 | * The contents of this file are subject to the COMMON DEVELOPMENT AND |
---|
5 | * DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use |
---|
6 | * this file except in compliance with the License. You may obtain a copy of |
---|
7 | * the License at http://www.sun.com/cddl/ |
---|
8 | * |
---|
9 | * Software distributed under the License is distributed on an "AS IS" basis, |
---|
10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
---|
11 | * for the specific language governing rights and limitations under the |
---|
12 | * License. |
---|
13 | * |
---|
14 | * The Initial Developer of the Original Code is |
---|
15 | * Eugene Romanenko, netlabs.org. |
---|
16 | * Portions created by the Initial Developer are Copyright (C) 2006 |
---|
17 | * the Initial Developer. All Rights Reserved. |
---|
18 | * |
---|
19 | * Contributor(s): |
---|
20 | * |
---|
21 | * Alternatively, the contents of this file may be used under the terms of |
---|
22 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
---|
23 | * in which case the provisions of the LGPL are applicable instead of those |
---|
24 | * above. If you wish to allow use of your version of this file only under the |
---|
25 | * terms of the LGPL, and not to allow others to use your version of this file |
---|
26 | * under the terms of the CDDL, indicate your decision by deleting the |
---|
27 | * provisions above and replace them with the notice and other provisions |
---|
28 | * required by the LGPL. If you do not delete the provisions above, a recipient |
---|
29 | * may use your version of this file under the terms of any one of the CDDL |
---|
30 | * or the LGPL. |
---|
31 | * |
---|
32 | * ***** END LICENSE BLOCK ***** */ |
---|
33 | |
---|
34 | |
---|
35 | #define INCL_GPI |
---|
36 | #define INCL_WIN |
---|
37 | #include <os2.h> |
---|
38 | |
---|
39 | #include <process.h> |
---|
40 | #include <stdio.h> |
---|
41 | |
---|
42 | #include "globals.h" |
---|
43 | #include "luutils.h" |
---|
44 | #include "progressDlg.h" |
---|
45 | #include "Lucide_res.h" |
---|
46 | #include "messages.h" |
---|
47 | |
---|
48 | #define TID_PAINT 1 |
---|
49 | |
---|
50 | |
---|
51 | ProgressDlg::ProgressDlg( HWND hWndFrame ) |
---|
52 | { |
---|
53 | hFrame = hWndFrame; |
---|
54 | text = newstrdup( "" ); |
---|
55 | threadFn = NULL; |
---|
56 | threadData = NULL; |
---|
57 | fn = NULL; |
---|
58 | data = NULL; |
---|
59 | pOldBarProc = NULL; |
---|
60 | hpsBuffer = NULLHANDLE; |
---|
61 | hdcBuffer = NULLHANDLE; |
---|
62 | startPos = 0; |
---|
63 | } |
---|
64 | |
---|
65 | ProgressDlg::~ProgressDlg() |
---|
66 | { |
---|
67 | delete text; |
---|
68 | } |
---|
69 | |
---|
70 | void ProgressDlg::show( progressThreadFn _threadFn, void *_threadData ) |
---|
71 | { |
---|
72 | threadFn = _threadFn; |
---|
73 | threadData = _threadData; |
---|
74 | WinDlgBox( HWND_DESKTOP, hFrame, progressDlgProc, |
---|
75 | _hmod, IDD_PROGRESS, this ); |
---|
76 | } |
---|
77 | |
---|
78 | void ProgressDlg::hide() |
---|
79 | { |
---|
80 | if ( hDialog != NULLHANDLE ) { |
---|
81 | WinPostMsg( hDialog, WM_COMMAND, MPFROMSHORT( DID_OK ), (MPARAM)0 ); |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | void ProgressDlg::setBreakFunc( progressBrkFn _fn, void *_data ) |
---|
86 | { |
---|
87 | fn = _fn; |
---|
88 | data = _data; |
---|
89 | } |
---|
90 | |
---|
91 | void ProgressDlg::setText( const char *_text ) |
---|
92 | { |
---|
93 | delete text; |
---|
94 | text = newstrdup( _text ); |
---|
95 | if ( hDialog != NULLHANDLE ) { |
---|
96 | WinSetDlgItemText( hDialog, IDC_PTEXT, text ); |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | MRESULT EXPENTRY ProgressDlg::progressDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) |
---|
101 | { |
---|
102 | // This is a static method, so we don't know which instantiation we're |
---|
103 | // dealing with. But we can get a pseudo-this from the parameter to |
---|
104 | // WM_INITDLG, which we therafter store with the window and retrieve |
---|
105 | // as follows: |
---|
106 | ProgressDlg *_this = (ProgressDlg *)WinQueryWindowULong( hwnd, QWL_USER ); |
---|
107 | |
---|
108 | switch (msg) |
---|
109 | { |
---|
110 | |
---|
111 | // Dialog has just been created |
---|
112 | case WM_INITDLG: |
---|
113 | { |
---|
114 | // Save the mp2 into our user data so that subsequent calls have |
---|
115 | // access to the parent C++ object |
---|
116 | WinSetWindowULong( hwnd, QWL_USER, (ULONG)mp2 ); |
---|
117 | _this = (ProgressDlg *)mp2; |
---|
118 | localizeDialog( hwnd ); |
---|
119 | centerWindow( _this->hFrame, hwnd ); |
---|
120 | |
---|
121 | _this->hDialog = hwnd; |
---|
122 | WinSetDlgItemText( hwnd, IDC_PTEXT, _this->text ); |
---|
123 | WinEnableControl( hwnd, DID_CANCEL, _this->fn != NULL ); |
---|
124 | |
---|
125 | _this->startPos = 0; |
---|
126 | HWND hBar = WinWindowFromID( hwnd, IDC_PBAR ); |
---|
127 | HAB hBarHab = WinQueryAnchorBlock( hBar ); |
---|
128 | |
---|
129 | if ( ( _this->hpsBuffer != NULLHANDLE ) && |
---|
130 | ( _this->hdcBuffer != NULLHANDLE ) ) { |
---|
131 | DestroyGraphicsBuffer( _this->hpsBuffer, _this->hdcBuffer ); |
---|
132 | _this->hpsBuffer = _this->hdcBuffer = NULLHANDLE; |
---|
133 | } |
---|
134 | |
---|
135 | RECTL rcl; |
---|
136 | WinQueryWindowRect( hBar, &rcl ); |
---|
137 | HPS hps = WinGetPS( hBar ); |
---|
138 | CreateGraphicsBuffer( hBarHab, &rcl, hps, &_this->hpsBuffer, &_this->hdcBuffer ); |
---|
139 | WinReleasePS( hps ); |
---|
140 | |
---|
141 | WinSetWindowULong( hBar, QWL_USER, (ULONG)_this ); |
---|
142 | _this->pOldBarProc = WinSubclassWindow( hBar, progressBarProc ); |
---|
143 | WinStartTimer( hBarHab, hBar, TID_PAINT, 1 ); |
---|
144 | |
---|
145 | _beginthread( _this->threadFn, NULL, 262144, _this->threadData ); |
---|
146 | |
---|
147 | return (MRESULT)FALSE; |
---|
148 | } |
---|
149 | |
---|
150 | case WM_DESTROY: |
---|
151 | { |
---|
152 | _this->hDialog = NULLHANDLE; |
---|
153 | if ( ( _this->hpsBuffer != NULLHANDLE ) && |
---|
154 | ( _this->hdcBuffer != NULLHANDLE ) ) { |
---|
155 | DestroyGraphicsBuffer( _this->hpsBuffer, _this->hdcBuffer ); |
---|
156 | _this->hpsBuffer = _this->hdcBuffer = NULLHANDLE; |
---|
157 | } |
---|
158 | } |
---|
159 | break; |
---|
160 | |
---|
161 | case WM_COMMAND: |
---|
162 | switch (SHORT1FROMMP(mp1)) |
---|
163 | { |
---|
164 | case DID_OK: |
---|
165 | WinDismissDlg( hwnd, DID_OK ); |
---|
166 | return (MRESULT)FALSE; |
---|
167 | |
---|
168 | case DID_CANCEL: |
---|
169 | WinEnableControl( hwnd, DID_CANCEL, FALSE ); |
---|
170 | if ( _this->fn != NULL ) { |
---|
171 | _this->fn( _this->data ); |
---|
172 | } |
---|
173 | return (MRESULT)FALSE; |
---|
174 | }; |
---|
175 | return (MRESULT)FALSE; |
---|
176 | } |
---|
177 | return WinDefDlgProc( hwnd, msg, mp1, mp2 ); |
---|
178 | } |
---|
179 | |
---|
180 | #define SHAPE_LEN 30 |
---|
181 | |
---|
182 | MRESULT EXPENTRY ProgressDlg::progressBarProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) |
---|
183 | { |
---|
184 | ProgressDlg *_this = (ProgressDlg *)WinQueryWindowULong( hwnd, QWL_USER ); |
---|
185 | |
---|
186 | switch ( msg ) |
---|
187 | { |
---|
188 | case WM_PAINT: |
---|
189 | _this->wmPaintBar( hwnd ); |
---|
190 | return (MRESULT)FALSE; |
---|
191 | |
---|
192 | case WM_TIMER: |
---|
193 | if ( SHORT1FROMMP( mp1 ) == TID_PAINT ) |
---|
194 | { |
---|
195 | WinInvalidateRect( hwnd, NULL, FALSE ); |
---|
196 | _this->startPos += 3; |
---|
197 | if ( _this->startPos > ( ( SHAPE_LEN * 2 ) - 1 ) ) { |
---|
198 | _this->startPos = 0; |
---|
199 | } |
---|
200 | } |
---|
201 | break; |
---|
202 | } |
---|
203 | return _this->pOldBarProc( hwnd, msg, mp1, mp2 ); |
---|
204 | } |
---|
205 | |
---|
206 | void ProgressDlg::drawShape( HPS hps, PRECTL r ) |
---|
207 | { |
---|
208 | POINTL ptlStart, ptlEnd; |
---|
209 | ptlStart.x = r->xLeft; // x coordinate, lower-left corner of box |
---|
210 | ptlStart.y = r->yBottom; // y coordinate, lower-left corner of box |
---|
211 | ptlEnd.x = r->xRight; // x coordinate, upper-right corner of box |
---|
212 | ptlEnd.y = r->yTop; // y coordinate, upper-right corner of box |
---|
213 | GpiMove( hps, &ptlStart ); |
---|
214 | GpiBox( hps, DRO_FILL, &ptlEnd, 0, 0 ); // Draw sheared box |
---|
215 | } |
---|
216 | |
---|
217 | void ProgressDlg::wmPaintBar( HWND hwnd ) |
---|
218 | { |
---|
219 | RECTL rcl; |
---|
220 | HPS hps = WinBeginPaint( hwnd, 0, NULL ); |
---|
221 | WinQueryWindowRect( hwnd, &rcl ); |
---|
222 | |
---|
223 | // 161,192,224 |
---|
224 | LONG lclr1 = ( 161 << 16 ) | ( 192 << 8 ) | 224; |
---|
225 | LONG lclr2 = ( 121 << 16 ) | ( 144 << 8 ) | 168; |
---|
226 | LONG ltabl[ 2 ] = { lclr1, lclr2 }; |
---|
227 | GpiCreateLogColorTable( hpsBuffer, 0, LCOLF_CONSECRGB, 100, 2, ltabl ); |
---|
228 | WinFillRect( hpsBuffer, &rcl, 100 ); |
---|
229 | GpiSetColor( hpsBuffer, 101 ); |
---|
230 | |
---|
231 | MATRIXLF matlfTransform; |
---|
232 | matlfTransform.fxM11 = MAKEFIXED( 1, 0 ); |
---|
233 | matlfTransform.fxM12 = MAKEFIXED( 0, 0 ); |
---|
234 | matlfTransform.lM13 = 0; |
---|
235 | matlfTransform.fxM21 = MAKEFIXED( 0, 65536 / 2 ); // Shear factor .5 |
---|
236 | matlfTransform.fxM22 = MAKEFIXED( 1, 0 ); |
---|
237 | matlfTransform.lM23 = 0; |
---|
238 | matlfTransform.lM31 = 0; // Translate 0 units right |
---|
239 | matlfTransform.lM32 = 0; |
---|
240 | matlfTransform.lM33 = 1; |
---|
241 | GpiSetDefaultViewMatrix( hpsBuffer, 9, &matlfTransform, TRANSFORM_REPLACE ); |
---|
242 | |
---|
243 | LONG xPos = startPos - ( SHAPE_LEN * 2 ); |
---|
244 | for ( ; xPos < rcl.xRight; xPos += ( SHAPE_LEN * 2 ) ) |
---|
245 | { |
---|
246 | RECTL r = { xPos, rcl.yBottom, xPos + SHAPE_LEN, rcl.yTop - 1 }; |
---|
247 | drawShape( hpsBuffer, &r ); |
---|
248 | } |
---|
249 | |
---|
250 | BlitGraphicsBuffer( hps, hpsBuffer, &rcl ); |
---|
251 | WinEndPaint( hps ); |
---|
252 | } |
---|
253 | |
---|