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

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

made spinbutton wider ticket:198

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