source: trunk/Lucide/gui/toolbar.cpp @ 460

Last change on this file since 460 was 460, checked in by Silvan Scherrer, 11 years ago

small changes

File size: 12.8 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#include "os2all.h"
36
37#include <stdio.h>
38#include <string.h>
39#include <string>
40
41#include "tb_spl.h"
42
43#include "lucide.h"
44#include "Lucide_res.h"
45#include "luutils.h"
46#include "messages.h"
47
48
49PFNWP pOldTbProc; // Old toolbar window proc
50PFNWP pOldZeProc; // Old zoom entryfield window proc
51
52
53// Toolbar window proc
54static MRESULT EXPENTRY tbProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
55{
56    switch ( msg )
57    {
58        case WM_CONTROL:
59            {
60                SHORT controlId = SHORT1FROMMP( mp1 );
61                SHORT notifyCode = SHORT2FROMMP( mp1 );
62
63                if ( ( controlId == TBID_PAGENUM ) && ( notifyCode == EN_CHANGE )
64                     && !Lucide::dontSwitchPage )
65                {
66                        char szText[256];
67                        LONG newPage = 0;
68                        ULONG retLen = 0;
69                        retLen = WinQueryDlgItemText( hwnd, TBID_PAGENUM, sizeof(szText),
70                                            szText );
71
72                        if ( retLen > 0) {
73                                newPage = atol(szText);
74                                if (newPage > 0) {
75                                    Lucide::goToPage(newPage - 1);
76                                }
77                        }
78                }
79
80                if ( ( controlId == TBID_PAGENUM ) && ( notifyCode == EN_SETFOCUS )
81                     && !Lucide::dontSwitchPage )
82                {
83                // highlight the text
84                WinSendDlgItemMsg( hwnd, TBID_PAGENUM, EM_SETSEL,
85                                      MPFROM2SHORT(0, 256), NULL);
86                }
87
88                if ( ( controlId == TBID_ZOOM ) && ( notifyCode == CBN_ENTER ) )
89                {
90                    bool shortValueOk = false;
91                    SHORT sResult = 0;
92                    if ( WinQueryDlgItemShort( hwnd, TBID_ZOOM, &sResult, FALSE ) )
93                    {
94                        if ( ( sResult > 0 ) && ( sResult < 1600 ) ) {
95                            shortValueOk = true;
96                            Lucide::focusDocview();
97                            Lucide::setZoom( (double)sResult / 100.0 );
98                        }
99                    }
100
101                    if ( !shortValueOk )
102                    {
103                        SHORT rc = SHORT1FROMMR( WinSendDlgItemMsg( hwnd, TBID_ZOOM, LM_QUERYSELECTION,
104                                                                    MPFROMSHORT( LIT_CURSOR ), MPVOID ) );
105                        if ( rc != LIT_NONE )
106                        {
107                            double z = convZoom( rc );
108                            if ( z >= -2 ) {
109                                Lucide::focusDocview();
110                                Lucide::setZoom( z );
111                            }
112                        }
113                    }
114                }
115            }
116            break;
117    }
118    return pOldTbProc( hwnd, msg, mp1, mp2 );
119}
120
121static char savedZeText[ 255 ] = "";
122// Zoom entryfield window proc
123static MRESULT EXPENTRY zeProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
124{
125    char tmp[ 255 ] = "";
126
127    switch ( msg )
128    {
129
130        // clear field on click
131        case WM_BUTTON1CLICK:
132        {
133            WinQueryWindowText( hwnd, sizeof( tmp ), tmp );
134            if ( strlen( tmp ) > 0 ) {
135                strcpy( savedZeText, tmp );
136            }
137            WinSetWindowText( hwnd, "" );
138        }
139        break;
140
141        // restore text if empty when losing focus
142        case WM_SETFOCUS:
143        {
144            if ( !SHORT1FROMMP( mp2 ) )
145            {
146                WinQueryWindowText( hwnd, sizeof( tmp ), tmp );
147                if ( strlen( tmp ) == 0 ) {
148                    WinSetWindowText( hwnd, savedZeText );
149                }
150            }
151        }
152        break;
153
154    }
155    return pOldZeProc( hwnd, msg, mp1, mp2 );
156}
157
158
159HWND createToolbar( HWND hwnd )
160{
161    HWND hToolBar = WinCreateWindow( hwnd, WC_ER_TOOLBAR, "",
162                                WS_VISIBLE, 0, 0, 0, 0, hwnd, HWND_TOP,
163                                0, NULL, NULL );
164    pOldTbProc = WinSubclassWindow( hToolBar, tbProc );
165
166    // used for different purposes
167    char pgnum[ 32 ];
168    HPS hps;
169
170    AddBtnStruct bs;
171
172    bs.cmd = CM_OPEN;
173    bs.bubbleText = newstrdupL( TBHINT_OPEN );
174    bs.bubbleRes = 0;
175    bs.bubbleHmod = NULLHANDLE;
176    bs.pictRes = IDB_OPEN;
177    bs.pictHmod = _hmod;
178    bs.menuRes = 0;
179    bs.menuHmod = NULLHANDLE;
180    bs.checked = FALSE;
181    bs.enabled = TRUE;
182    WinSendMsg( hToolBar, TBM_ADDBUTTON, (MPARAM)&bs, MPVOID );
183
184    bs.cmd = CM_PRINT;
185    bs.bubbleText = newstrdupL( TBHINT_PRINT );
186    bs.bubbleRes = 0;
187    bs.bubbleHmod = NULLHANDLE;
188    bs.pictRes = IDB_PRINT;
189    bs.pictHmod = _hmod;
190    bs.menuRes = 0;
191    bs.menuHmod = NULLHANDLE;
192    bs.checked = FALSE;
193    bs.enabled = TRUE;
194    WinSendMsg( hToolBar, TBM_ADDBUTTON, (MPARAM)&bs, MPVOID );
195
196    WinSendMsg( hToolBar, TBM_ADDSEPARATOR, MPVOID, MPVOID );
197
198    bs.cmd = CM_NAVPANE;
199    bs.bubbleText = newstrdupL( TBHINT_SHOW_NAV_PANE );
200    bs.bubbleRes = 0;
201    bs.bubbleHmod = NULLHANDLE;
202    bs.pictRes = IDB_NAVPANE;
203    bs.pictHmod = _hmod;
204    bs.menuRes = 0;
205    bs.menuHmod = NULLHANDLE;
206    bs.checked = FALSE;
207    bs.enabled = TRUE;
208    WinSendMsg( hToolBar, TBM_ADDBUTTON, (MPARAM)&bs, MPVOID );
209
210    WinSendMsg( hToolBar, TBM_ADDSEPARATOR, MPVOID, MPVOID );
211
212    bs.cmd = CM_FIRSTPAGE;
213    bs.bubbleText = newstrdupL( TBHINT_FIRST_PAGE );
214    bs.bubbleRes = 0;
215    bs.bubbleHmod = NULLHANDLE;
216    bs.pictRes = IDB_FIRSTPAGE;
217    bs.pictHmod = _hmod;
218    bs.menuRes = 0;
219    bs.menuHmod = NULLHANDLE;
220    bs.checked = FALSE;
221    bs.enabled = TRUE;
222    WinSendMsg( hToolBar, TBM_ADDBUTTON, (MPARAM)&bs, MPVOID );
223
224    bs.cmd = CM_PREVPAGE;
225    bs.bubbleText = newstrdupL( TBHINT_PREV_PAGE );
226    bs.bubbleRes = 0;
227    bs.bubbleHmod = NULLHANDLE;
228    bs.pictRes = IDB_PREVPAGE;
229    bs.pictHmod = _hmod;
230    bs.menuRes = 0;
231    bs.menuHmod = NULLHANDLE;
232    bs.checked = FALSE;
233    bs.enabled = TRUE;
234    WinSendMsg( hToolBar, TBM_ADDBUTTON, (MPARAM)&bs, MPVOID );
235
236    // pages text
237    AddCtrlStruct cs;
238    cs.ctrlHandle = WinCreateWindow( hToolBar, WC_ENTRYFIELD, NULL,
239                                     WS_VISIBLE|ES_CENTER|ES_MARGIN|ES_AUTOSCROLL,
240                                     0,0,0,0, hToolBar, HWND_TOP, TBID_PAGENUM, NULL, NULL );
241    WinSetPresParam( cs.ctrlHandle, PP_FONTNAMESIZE, deffontlen, deffont );
242    // calculate the width
243    snprintf( pgnum, sizeof( pgnum ), "%d", 99999 );
244    hps = WinGetPS( cs.ctrlHandle );
245    cs.cx = getStringPixSize( hps, pgnum ) + 4;
246    WinReleasePS( hps );
247
248    cs.cy = 2;
249    cs.bubbleText = NULL;
250    WinSendMsg( hToolBar, TBM_ADDCONTROL, (MPARAM)&cs, MPVOID );
251
252    cs.ctrlHandle = WinCreateWindow( hToolBar, WC_STATIC, NULL,
253                                     WS_VISIBLE | SS_TEXT | DT_CENTER | DT_VCENTER,
254                                     0,0,0,0, hToolBar, HWND_TOP, TBID_OFPAGES, NULL, NULL );
255    WinSetPresParam( cs.ctrlHandle, PP_FONTNAMESIZE, deffontlen, deffont );
256    ULONG syscmenu = SYSCLR_MENU;
257    WinSetPresParam( cs.ctrlHandle, PP_BACKGROUNDCOLORINDEX, sizeof( ULONG ), &syscmenu );
258    char *pgfrm = newstrdupL( TB_PAGENUM );
259    snprintf( pgnum, sizeof( pgnum ), pgfrm, 99999 );
260    delete pgfrm;
261    hps = WinGetPS( cs.ctrlHandle );
262    cs.cx = getStringPixSize( hps, pgnum );
263    WinReleasePS( hps );
264    cs.cy = 0;
265    cs.bubbleText = NULL;
266    WinSendMsg( hToolBar, TBM_ADDCONTROL, (MPARAM)&cs, MPVOID );
267
268    bs.cmd = CM_NEXTPAGE;
269    bs.bubbleText = newstrdupL( TBHINT_NEXT_PAGE );
270    bs.bubbleRes = 0;
271    bs.bubbleHmod = NULLHANDLE;
272    bs.pictRes = IDB_NEXTPAGE;
273    bs.pictHmod = _hmod;
274    bs.menuRes = 0;
275    bs.menuHmod = NULLHANDLE;
276    bs.checked = FALSE;
277    bs.enabled = TRUE;
278    WinSendMsg( hToolBar, TBM_ADDBUTTON, (MPARAM)&bs, MPVOID );
279
280    bs.cmd = CM_LASTPAGE;
281    bs.bubbleText = newstrdupL( TBHINT_LAST_PAGE );
282    bs.bubbleRes = 0;
283    bs.bubbleHmod = NULLHANDLE;
284    bs.pictRes = IDB_LASTPAGE;
285    bs.pictHmod = _hmod;
286    bs.menuRes = 0;
287    bs.menuHmod = NULLHANDLE;
288    bs.checked = FALSE;
289    bs.enabled = TRUE;
290    WinSendMsg( hToolBar, TBM_ADDBUTTON, (MPARAM)&bs, MPVOID );
291
292    WinSendMsg( hToolBar, TBM_ADDSEPARATOR, MPVOID, MPVOID );
293
294    bs.cmd = CM_ACTSIZE;
295    bs.bubbleText = newstrdupL( TBHINT_ACTUAL_SIZE );
296    bs.bubbleRes = 0;
297    bs.bubbleHmod = NULLHANDLE;
298    bs.pictRes = IDB_100PERC;
299    bs.pictHmod = _hmod;
300    bs.menuRes = 0;
301    bs.menuHmod = NULLHANDLE;
302    bs.checked = FALSE;
303    bs.enabled = TRUE;
304    WinSendMsg( hToolBar, TBM_ADDBUTTON, (MPARAM)&bs, MPVOID );
305
306    bs.cmd = CM_FITWINDOW;
307    bs.bubbleText = newstrdupL( TBHINT_FIT_WINDOW );
308    bs.bubbleRes = 0;
309    bs.bubbleHmod = NULLHANDLE;
310    bs.pictRes = IDB_FITPAGE;
311    bs.pictHmod = _hmod;
312    bs.menuRes = 0;
313    bs.menuHmod = NULLHANDLE;
314    bs.checked = FALSE;
315    bs.enabled = TRUE;
316    WinSendMsg( hToolBar, TBM_ADDBUTTON, (MPARAM)&bs, MPVOID );
317
318    bs.cmd = CM_FITWIDTH;
319    bs.bubbleText = newstrdupL( TBHINT_FIT_WIDTH );
320    bs.bubbleRes = 0;
321    bs.bubbleHmod = NULLHANDLE;
322    bs.pictRes = IDB_FITWIDTH;
323    bs.pictHmod = _hmod;
324    bs.menuRes = 0;
325    bs.menuHmod = NULLHANDLE;
326    bs.checked = FALSE;
327    bs.enabled = TRUE;
328    WinSendMsg( hToolBar, TBM_ADDBUTTON, (MPARAM)&bs, MPVOID );
329
330    cs.ctrlHandle = WinCreateWindow( hToolBar, WC_COMBOBOX, NULL,
331                                     WS_VISIBLE | CBS_DROPDOWN,
332                                     0,0,0,0, hToolBar, HWND_TOP, TBID_ZOOM, NULL, NULL );
333    WinSetPresParam( cs.ctrlHandle, PP_FONTNAMESIZE, deffontlen, deffont );
334    std::string actsizetext = getLocalizedString( TBHINT_ACTUAL_SIZE );
335    cs.cx = setZoomValues( cs.ctrlHandle ) +
336                ( WinQuerySysValue( HWND_DESKTOP, SV_CXVSCROLL ) * 2 );
337    cs.cy = -200;
338    cs.bubbleText = NULL;
339    pOldZeProc = WinSubclassWindow( WinWindowFromID( cs.ctrlHandle, CBID_EDIT ), zeProc );
340    WinSendMsg( hToolBar, TBM_ADDCONTROL, (MPARAM)&cs, MPVOID );
341
342    WinSendMsg( hToolBar, TBM_ADDSEPARATOR, MPVOID, MPVOID );
343
344    bs.cmd = CM_FIND;
345    bs.bubbleText = newstrdupL( TBHINT_FIND );
346    bs.bubbleRes = 0;
347    bs.bubbleHmod = NULLHANDLE;
348    bs.pictRes = IDB_FIND;
349    bs.pictHmod = _hmod;
350    bs.menuRes = 0;
351    bs.menuHmod = NULLHANDLE;
352    bs.checked = FALSE;
353    bs.enabled = TRUE;
354    WinSendMsg( hToolBar, TBM_ADDBUTTON, (MPARAM)&bs, MPVOID );
355
356    bs.cmd = CM_FINDAGAIN;
357    bs.bubbleText = newstrdupL( TBHINT_FINDAGAIN );
358    bs.bubbleRes = 0;
359    bs.bubbleHmod = NULLHANDLE;
360    bs.pictRes = IDB_FINDAGAIN;
361    bs.pictHmod = _hmod;
362    bs.menuRes = 0;
363    bs.menuHmod = NULLHANDLE;
364    bs.checked = FALSE;
365    bs.enabled = TRUE;
366    WinSendMsg( hToolBar, TBM_ADDBUTTON, (MPARAM)&bs, MPVOID );
367
368    WinSendMsg( hToolBar, TBM_ADDSEPARATOR, MPVOID, MPVOID );
369
370    bs.cmd = CM_ZOOM_IN_OUT;
371    bs.bubbleText = newstrdupL( TBHINT_ZOOM_IN_OUT );
372    bs.bubbleRes = 0;
373    bs.bubbleHmod = NULLHANDLE;
374    bs.pictRes = IDB_MGLASS;
375    bs.pictHmod = _hmod;
376    bs.menuRes = 0;
377    bs.menuHmod = NULLHANDLE;
378    bs.checked = FALSE;
379    bs.enabled = TRUE;
380    WinSendMsg( hToolBar, TBM_ADDBUTTON, (MPARAM)&bs, MPVOID );
381
382    return hToolBar;
383}
Note: See TracBrowser for help on using the repository browser.