source: trunk/Lucide/SOURCE/gui/progressDlg.cpp @ 94

Last change on this file since 94 was 61, checked in by Eugene Romanenko, 15 years ago

interface changes as per Heiko Nitzsche suggestions, compatibility changes

File size: 8.3 KB
Line 
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 "luutils.h"
43#include "progressDlg.h"
44#include "Lucide_res.h"
45#include "messages.h"
46
47#define TID_PAINT   1
48
49
50ProgressDlg::ProgressDlg( HWND hWndFrame )
51{
52    hFrame      = hWndFrame;
53    text        = newstrdup( "" );
54    threadFn    = NULL;
55    threadData  = NULL;
56    fn          = NULL;
57    data        = NULL;
58    pOldBarProc = NULL;
59    hpsBuffer   = NULLHANDLE;
60    hdcBuffer   = NULLHANDLE;
61    startPos    = 0;
62}
63
64ProgressDlg::~ProgressDlg()
65{
66    delete text;
67}
68
69void ProgressDlg::show( progressThreadFn _threadFn, void *_threadData )
70{
71    threadFn = _threadFn;
72    threadData = _threadData;
73    WinDlgBox( HWND_DESKTOP, hFrame, progressDlgProc,
74               NULLHANDLE, IDD_PROGRESS, this );
75}
76
77void ProgressDlg::hide()
78{
79    if ( hDialog != NULLHANDLE ) {
80        WinPostMsg( hDialog, WM_COMMAND, MPFROMSHORT( DID_OK ), (MPARAM)0 );
81    }
82}
83
84void ProgressDlg::setBreakFunc( progressBrkFn _fn, void *_data )
85{
86    fn   = _fn;
87    data = _data;
88}
89
90void ProgressDlg::setText( const char *_text )
91{
92    delete text;
93    text = newstrdup( _text );
94    if ( hDialog != NULLHANDLE ) {
95        WinSetDlgItemText( hDialog, IDC_PTEXT, text );
96    }
97}
98
99MRESULT EXPENTRY ProgressDlg::progressDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
100{
101    // This is a static method, so we don't know which instantiation we're
102    // dealing with. But we can get a pseudo-this from the parameter to
103    // WM_INITDLG, which we therafter store with the window and retrieve
104    // as follows:
105    ProgressDlg *_this = (ProgressDlg *)WinQueryWindowULong( hwnd, QWL_USER );
106
107    switch (msg)
108    {
109
110        // Dialog has just been created
111        case WM_INITDLG:
112        {
113            // Save the mp2 into our user data so that subsequent calls have
114            // access to the parent C++ object
115            WinSetWindowULong( hwnd, QWL_USER, (ULONG)mp2 );
116            _this = (ProgressDlg *)mp2;
117            localizeDialog( hwnd );
118            centerWindow( _this->hFrame, hwnd );
119
120            _this->hDialog = hwnd;
121            WinSetDlgItemText( hwnd, IDC_PTEXT, _this->text );
122            WinEnableControl( hwnd, DID_CANCEL, _this->fn != NULL );
123
124            _this->startPos = 0;
125            HWND hBar = WinWindowFromID( hwnd, IDC_PBAR );
126            HAB hBarHab = WinQueryAnchorBlock( hBar );
127
128            if ( ( _this->hpsBuffer != NULLHANDLE ) &&
129                 ( _this->hdcBuffer != NULLHANDLE ) ) {
130                DestroyGraphicsBuffer( _this->hpsBuffer, _this->hdcBuffer );
131                _this->hpsBuffer = _this->hdcBuffer = NULLHANDLE;
132            }
133
134            RECTL rcl;
135            WinQueryWindowRect( hBar, &rcl );
136            HPS hps = WinGetPS( hBar );
137            CreateGraphicsBuffer( hBarHab, &rcl, hps, &_this->hpsBuffer, &_this->hdcBuffer );
138            WinReleasePS( hps );
139
140            WinSetWindowULong( hBar, QWL_USER, (ULONG)_this );
141            _this->pOldBarProc = WinSubclassWindow( hBar, progressBarProc );
142            WinStartTimer( hBarHab, hBar, TID_PAINT, 1 );
143           
144            _beginthread( _this->threadFn, NULL, 262144, _this->threadData );
145
146            return (MRESULT)FALSE;
147        }
148
149        case WM_DESTROY:
150        {
151            _this->hDialog = NULLHANDLE;
152            if ( ( _this->hpsBuffer != NULLHANDLE ) &&
153                 ( _this->hdcBuffer != NULLHANDLE ) ) {
154                DestroyGraphicsBuffer( _this->hpsBuffer, _this->hdcBuffer );
155                _this->hpsBuffer = _this->hdcBuffer = NULLHANDLE;
156            }
157        }
158        break;
159
160        case WM_COMMAND:
161            switch (SHORT1FROMMP(mp1))
162            {
163                case DID_OK:
164                    WinDismissDlg( hwnd, DID_OK );
165                    return (MRESULT)FALSE;
166
167                case DID_CANCEL:
168                    WinEnableControl( hwnd, DID_CANCEL, FALSE );
169                    if ( _this->fn != NULL ) {
170                        _this->fn( _this->data );
171                    }
172                    return (MRESULT)FALSE;
173            };
174            return (MRESULT)FALSE;
175    }
176    return WinDefDlgProc( hwnd, msg, mp1, mp2 );
177}
178
179#define SHAPE_LEN   30
180
181MRESULT EXPENTRY ProgressDlg::progressBarProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
182{
183    ProgressDlg *_this = (ProgressDlg *)WinQueryWindowULong( hwnd, QWL_USER );
184
185    switch ( msg )
186    {
187        case WM_PAINT:
188            _this->wmPaintBar( hwnd );
189            return (MRESULT)FALSE;
190
191        case WM_TIMER:
192            if ( SHORT1FROMMP( mp1 ) == TID_PAINT )
193            {
194                WinInvalidateRect( hwnd, NULL, FALSE );
195                _this->startPos += 3;
196                if ( _this->startPos > ( ( SHAPE_LEN * 2 ) - 1 ) ) {
197                    _this->startPos = 0;
198                }
199            }
200            break;
201    }
202    return _this->pOldBarProc( hwnd, msg, mp1, mp2 );
203}
204
205void ProgressDlg::drawShape( HPS hps, PRECTL r )
206{
207    POINTL ptlStart, ptlEnd;
208    ptlStart.x = r->xLeft;      // x coordinate, lower-left corner of box
209    ptlStart.y = r->yBottom;    // y coordinate, lower-left corner of box
210    ptlEnd.x   = r->xRight;     // x coordinate, upper-right corner of box
211    ptlEnd.y   = r->yTop;       // y coordinate, upper-right corner of box
212    GpiMove( hps, &ptlStart );
213    GpiBox( hps, DRO_FILL, &ptlEnd, 0, 0 ); // Draw sheared box
214}
215
216void ProgressDlg::wmPaintBar( HWND hwnd )
217{
218    RECTL rcl;
219    HPS hps = WinBeginPaint( hwnd, 0, NULL );
220    WinQueryWindowRect( hwnd, &rcl );
221
222    // 161,192,224
223    LONG lclr1 = ( 161 << 16 ) | ( 192 << 8 ) | 224;
224    LONG lclr2 = ( 121 << 16 ) | ( 144 << 8 ) | 168;
225    LONG ltabl[ 2 ] = { lclr1, lclr2 };
226    GpiCreateLogColorTable( hpsBuffer, 0, LCOLF_CONSECRGB, 100, 2, ltabl );
227    WinFillRect( hpsBuffer, &rcl, 100 );
228    GpiSetColor( hpsBuffer, 101 );
229
230    MATRIXLF matlfTransform;
231    matlfTransform.fxM11 = MAKEFIXED( 1, 0 );
232    matlfTransform.fxM12 = MAKEFIXED( 0, 0 );
233    matlfTransform.lM13  = 0;
234    matlfTransform.fxM21 = MAKEFIXED( 0, 65536 / 2 );  // Shear factor .5
235    matlfTransform.fxM22 = MAKEFIXED( 1, 0 );
236    matlfTransform.lM23  = 0;
237    matlfTransform.lM31  = 0;               // Translate 0 units right
238    matlfTransform.lM32  = 0;
239    matlfTransform.lM33  = 1;
240    GpiSetDefaultViewMatrix( hpsBuffer, 9, &matlfTransform, TRANSFORM_REPLACE );
241
242    LONG xPos = startPos - ( SHAPE_LEN * 2 );
243    for ( ; xPos < rcl.xRight; xPos += ( SHAPE_LEN * 2 ) )
244    {
245        RECTL r = { xPos, rcl.yBottom, xPos + SHAPE_LEN, rcl.yTop - 1 };
246        drawShape( hpsBuffer, &r );
247    }
248
249    BlitGraphicsBuffer( hps, hpsBuffer, &rcl );
250    WinEndPaint( hps );
251}
252
Note: See TracBrowser for help on using the repository browser.