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

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

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

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