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

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

Better solution for #78, move GUI to DLL, executor sets BeginLibPath? and loads GUI DLL (closes #78)

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