source: trunk/Lucide/gui/settingsDlg.cpp @ 367

Last change on this file since 367 was 367, checked in by dmik, 11 years ago

Merged bramches/kmk (r294:365) to trunk.

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