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

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

UI improvements, save files, ability to compile plugins with gcc, saveAs for djvu plugin, djvu plugin compiled with gcc, get rid of ddjvuapi.dll

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