source: trunk/Lucide/SOURCE/gui/toolbar.cpp @ 89

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

UI improvements, started print dialog

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