source: branches/kmk/Lucide/gui/toolbar.cpp @ 334

Last change on this file since 334 was 334, checked in by dmik, 11 years ago

branches/kmk: Renamed private os2.h to os2all.h to avoid the clash with the toolkit one.

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