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

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

added settings dialog, asynch opening, fixed many crashes and bugs

File size: 5.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#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
64
65MRESULT EXPENTRY SettingsDlg::settingsDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
66{
67    // This is a static method, so we don't know which instantiation we're
68    // dealing with. But we can get a pseudo-this from the parameter to
69    // WM_INITDLG, which we therafter store with the window and retrieve
70    // as follows:
71    SettingsDlg *_this = (SettingsDlg *)WinQueryWindowULong( hwnd, QWL_USER );
72
73    switch (msg)
74    {
75
76        // Dialog has just been created
77        case WM_INITDLG:
78        {
79            // Save the mp2 into our user data so that subsequent calls have
80            // access to the parent C++ object
81            WinSetWindowULong( hwnd, QWL_USER, (ULONG)mp2 );
82            _this = (SettingsDlg *)mp2;
83            localizeDialog( hwnd );
84            centerWindow( _this->hFrame, hwnd );
85
86            // init
87            HWND hLayout = WinWindowFromID( hwnd, IDC_DEFPGLAYOUT );
88            std::string spage = getLocalizedString( MENU_SINGLE_PAGE );
89            WinSetWindowText( hLayout, spage.c_str() );
90            WinSendMsg( hLayout, LM_INSERTITEM, MPFROMSHORT(LIT_END),
91                        MPFROMP( spage.c_str() ) );
92            WinSendMsg( hLayout, LM_INSERTITEM, MPFROMSHORT(LIT_END),
93                        MPFROMP( getLocalizedString( MENU_CONTINUOUS ).c_str() ) );
94
95            setZoomValues( WinWindowFromID( hwnd, IDC_DEFZOOM ) );
96
97            return (MRESULT)FALSE;
98        }
99
100        case WM_COMMAND:
101            switch (SHORT1FROMMP(mp1))
102            {
103                case DID_OK:
104                    {
105                        SHORT rc = (SHORT)WinSendDlgItemMsg( hwnd, IDC_DEFPGLAYOUT, LM_QUERYSELECTION,
106                                                MPFROMSHORT( LIT_CURSOR ), MPVOID );
107                        if ( rc != LIT_NONE )
108                        {
109                            if ( rc == 0 ) {
110                                _this->settings->layout = SinglePage;
111                            } else if ( rc == 1 ) {
112                                _this->settings->layout = Continuous;
113                            }
114                        }
115
116                        rc = (SHORT)WinSendDlgItemMsg( hwnd, IDC_DEFZOOM, LM_QUERYSELECTION,
117                                                MPFROMSHORT( LIT_CURSOR ), MPVOID );
118                        if ( rc != LIT_NONE )
119                        {
120                            double z = convZoom( rc );
121                            if ( z >= -2 ) {
122                                _this->settings->zoom = z;
123                            }
124                        }
125
126                        _this->settings->save();
127
128                        WinDismissDlg( hwnd, DID_OK );
129                    }
130                    return (MRESULT)FALSE;
131
132                case DID_CANCEL:
133                    WinDismissDlg( hwnd, DID_CANCEL );
134                    return (MRESULT)FALSE;
135            };
136            return (MRESULT)FALSE;
137    }
138    return WinDefDlgProc( hwnd, msg, mp1, mp2 );
139}
140
141
Note: See TracBrowser for help on using the repository browser.