source: trunk/Lucide/SOURCE/gui/findDlg.cpp @ 150

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

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

File size: 6.8 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
40#include "globals.h"
41#include "findDlg.h"
42#include "Lucide_res.h"
43#include "luutils.h"
44#include "messages.h"
45
46#define MAXSEARCHLENGTH 100
47
48FindDlg::FindDlg( HWND hWndFrame )
49{
50    hFrame        = hWndFrame;
51    searchString  = newstrdup( "" );
52    caseSensitive = false;
53}
54
55FindDlg::~FindDlg()
56{
57    delete searchString;
58}
59
60ULONG FindDlg::showDialog()
61{
62    return WinDlgBox( HWND_DESKTOP, hFrame, findDlgProc,
63                      _hmod, IDD_FIND, this );
64}
65
66
67
68MRESULT EXPENTRY FindDlg::findDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
69{
70    // This is a static method, so we don't know which instantiation we're
71    // dealing with. But we can get a pseudo-this from the parameter to
72    // WM_INITDLG, which we therafter store with the window and retrieve
73    // as follows:
74    FindDlg *_this = (FindDlg *)WinQueryWindowULong( hwnd, QWL_USER );
75
76    switch (msg)
77    {
78
79        // Dialog has just been created
80        case WM_INITDLG:
81        {
82            // Save the mp2 into our user data so that subsequent calls have
83            // access to the parent C++ object
84            WinSetWindowULong( hwnd, QWL_USER, (ULONG)mp2 );
85            _this = (FindDlg *)mp2;
86            localizeDialog( hwnd );
87            centerWindow( _this->hFrame, hwnd );
88
89            WinSendDlgItemMsg( hwnd, IDC_FINDFIELD, EM_SETTEXTLIMIT,
90                               MPFROMSHORT( MAXSEARCHLENGTH ), MPVOID );
91            WinSetDlgItemText( hwnd, IDC_FINDFIELD, _this->searchString );
92            WinCheckButton( hwnd, IDC_FINDMATCHCASE, _this->caseSensitive );
93
94            return (MRESULT)FALSE;
95        }
96
97        case WM_COMMAND:
98            switch (SHORT1FROMMP(mp1))
99            {
100                case DID_OK:
101                    {
102                        char buf[ MAXSEARCHLENGTH + 1 ];
103                        WinQueryDlgItemText( hwnd, IDC_FINDFIELD, sizeof( buf ), buf );
104                        delete _this->searchString;
105                        _this->searchString = newstrdup( buf );
106                        _this->caseSensitive = WinQueryButtonCheckstate( hwnd, IDC_FINDMATCHCASE );
107                        WinDismissDlg( hwnd, DID_OK );
108                    }
109                    return (MRESULT)FALSE;
110
111                case DID_CANCEL:
112                    WinDismissDlg( hwnd, DID_CANCEL );
113                    return (MRESULT)FALSE;
114            };
115            return (MRESULT)FALSE;
116    }
117    return WinDefDlgProc( hwnd, msg, mp1, mp2 );
118}
119
120
121//
122// ------------------ GotoDlg ---------------------
123//
124
125GotoDlg::GotoDlg( HWND hWndFrame, long _pages, long _curpage )
126{
127    hFrame  = hWndFrame;
128    page    = -1;
129    pages   = _pages;
130    curpage = _curpage;
131}
132
133GotoDlg::~GotoDlg()
134{
135}
136
137ULONG GotoDlg::showDialog()
138{
139    return WinDlgBox( HWND_DESKTOP, hFrame, gotoDlgProc,
140                      _hmod, IDD_GOTOPAGE, this );
141}
142
143
144
145MRESULT EXPENTRY GotoDlg::gotoDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
146{
147    // This is a static method, so we don't know which instantiation we're
148    // dealing with. But we can get a pseudo-this from the parameter to
149    // WM_INITDLG, which we therafter store with the window and retrieve
150    // as follows:
151    GotoDlg *_this = (GotoDlg *)WinQueryWindowULong( hwnd, QWL_USER );
152
153    switch (msg)
154    {
155
156        // Dialog has just been created
157        case WM_INITDLG:
158        {
159            // Save the mp2 into our user data so that subsequent calls have
160            // access to the parent C++ object
161            WinSetWindowULong( hwnd, QWL_USER, (ULONG)mp2 );
162            _this = (GotoDlg *)mp2;
163            localizeDialog( hwnd );
164            centerWindow( _this->hFrame, hwnd );
165
166            WinSendDlgItemMsg( hwnd, IDC_PAGE, SPBM_SETLIMITS,
167                               MPFROMLONG( _this->pages ), MPFROMLONG( 1 ) );
168            WinSendDlgItemMsg( hwnd, IDC_PAGE, SPBM_SETCURRENTVALUE,
169                               MPFROMLONG( _this->curpage ), MPVOID );
170            char *pgfrm = newstrdupL( GTP_OF );
171            char pgnum[ 32 ];
172            snprintf( pgnum, sizeof( pgnum ), pgfrm, _this->pages );
173            delete pgfrm;
174            WinSetDlgItemText( hwnd, IDC_PAGES, pgnum );
175            return (MRESULT)FALSE;
176        }
177
178        case WM_COMMAND:
179            switch (SHORT1FROMMP(mp1))
180            {
181                case DID_OK:
182                    {
183                        LONG spbmValue = 0;
184                        BOOL rc = (BOOL)WinSendDlgItemMsg( hwnd, IDC_PAGE, SPBM_QUERYVALUE,
185                                            MPFROMP( &spbmValue ),
186                                            MPFROM2SHORT( 0, SPBQ_UPDATEIFVALID ) );
187
188                        if ( rc && ( spbmValue > 0 ) ) {
189                            _this->page = spbmValue;
190                        }
191                        WinDismissDlg( hwnd, DID_OK );
192                    }
193                    return (MRESULT)FALSE;
194
195                case DID_CANCEL:
196                    WinDismissDlg( hwnd, DID_CANCEL );
197                    return (MRESULT)FALSE;
198            };
199            return (MRESULT)FALSE;
200    }
201    return WinDefDlgProc( hwnd, msg, mp1, mp2 );
202}
203
Note: See TracBrowser for help on using the repository browser.