source: trunk/Lucide/SOURCE/gui/settingsDlg.cpp @ 72

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

correctly set initial values for comboboxes in settings dialog

File size: 6.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 <string>
39
40#include "settingsDlg.h"
41#include "lusettings.h"
42#include "luutils.h"
43#include "Lucide_res.h"
44#include "messages.h"
45
46
47SettingsDlg::SettingsDlg( HWND hWndFrame, LuSettings *s )
48{
49    hFrame = hWndFrame;
50    settings = s;
51}
52
53SettingsDlg::~SettingsDlg()
54{
55}
56
57void SettingsDlg::doDialog()
58{
59    WinDlgBox( HWND_DESKTOP, hFrame, settingsDlgProc,
60               NULLHANDLE, IDD_SETTINGS, this );
61    delete this;
62}
63
64static void setZoomCombo( HWND combo, SHORT cbind, double zoom )
65{
66    if ( cbind != -1 )
67    {
68        char buf[ 255 ] = "";
69        WinSendMsg( combo, LM_QUERYITEMTEXT,
70                    MPFROM2SHORT( cbind, sizeof( buf ) ), MPFROMP( buf ) );
71        WinSetWindowText( combo, buf );
72    }
73
74    if ( zoom != 0 )
75    {
76        std::string z = str( zoom * 100.0 ) + "%";
77        WinSetWindowText( combo, z.c_str() );
78    }
79}
80
81MRESULT EXPENTRY SettingsDlg::settingsDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
82{
83    // This is a static method, so we don't know which instantiation we're
84    // dealing with. But we can get a pseudo-this from the parameter to
85    // WM_INITDLG, which we therafter store with the window and retrieve
86    // as follows:
87    SettingsDlg *_this = (SettingsDlg *)WinQueryWindowULong( hwnd, QWL_USER );
88
89    switch (msg)
90    {
91
92        // Dialog has just been created
93        case WM_INITDLG:
94        {
95            // Save the mp2 into our user data so that subsequent calls have
96            // access to the parent C++ object
97            WinSetWindowULong( hwnd, QWL_USER, (ULONG)mp2 );
98            _this = (SettingsDlg *)mp2;
99            localizeDialog( hwnd );
100            centerWindow( _this->hFrame, hwnd );
101
102            // init
103
104            // layout
105            HWND hLayout = WinWindowFromID( hwnd, IDC_DEFPGLAYOUT );
106            std::string spage = getLocalizedString( MENU_SINGLE_PAGE );
107            std::string cont = getLocalizedString( MENU_CONTINUOUS );
108            WinSendMsg( hLayout, LM_INSERTITEM, MPFROMSHORT(LIT_END),
109                        MPFROMP( spage.c_str() ) );
110            WinSendMsg( hLayout, LM_INSERTITEM, MPFROMSHORT(LIT_END),
111                        MPFROMP( cont.c_str() ) );
112            if ( _this->settings->layout == SinglePage ) {
113                WinSetWindowText( hLayout, spage.c_str() );
114            } else if ( _this->settings->layout = Continuous ) {
115                WinSetWindowText( hLayout, cont.c_str() );
116            }
117
118            // zoom
119            HWND zoomCombo = WinWindowFromID( hwnd, IDC_DEFZOOM );
120            setZoomValues( zoomCombo );
121            if ( _this->settings->zoom == -2 ) {
122                setZoomCombo( zoomCombo, 1, 0 );
123            } else if ( _this->settings->zoom == -1 ) {
124                setZoomCombo( zoomCombo, 2, 0 );
125            } else if ( _this->settings->zoom == 1 ) {
126                setZoomCombo( zoomCombo, 0, 0 );
127            } else {
128                setZoomCombo( zoomCombo, -1, _this->settings->zoom );
129            }
130
131            return (MRESULT)FALSE;
132        }
133
134        case WM_COMMAND:
135            switch (SHORT1FROMMP(mp1))
136            {
137                case DID_OK:
138                    {
139                        SHORT rc = (SHORT)WinSendDlgItemMsg( hwnd, IDC_DEFPGLAYOUT, LM_QUERYSELECTION,
140                                                MPFROMSHORT( LIT_CURSOR ), MPVOID );
141                        if ( rc != LIT_NONE )
142                        {
143                            if ( rc == 0 ) {
144                                _this->settings->layout = SinglePage;
145                            } else if ( rc == 1 ) {
146                                _this->settings->layout = Continuous;
147                            }
148                        }
149
150                        rc = (SHORT)WinSendDlgItemMsg( hwnd, IDC_DEFZOOM, LM_QUERYSELECTION,
151                                                MPFROMSHORT( LIT_CURSOR ), MPVOID );
152                        if ( rc != LIT_NONE )
153                        {
154                            double z = convZoom( rc );
155                            if ( z >= -2 ) {
156                                _this->settings->zoom = z;
157                            }
158                        }
159
160                        _this->settings->save();
161
162                        WinDismissDlg( hwnd, DID_OK );
163                    }
164                    return (MRESULT)FALSE;
165
166                case DID_CANCEL:
167                    WinDismissDlg( hwnd, DID_CANCEL );
168                    return (MRESULT)FALSE;
169            };
170            return (MRESULT)FALSE;
171    }
172    return WinDefDlgProc( hwnd, msg, mp1, mp2 );
173}
174
175
Note: See TracBrowser for help on using the repository browser.