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

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

replaced toolbar bitmaps

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