source: trunk/Lucide/gui/findDlg.cpp @ 450

Last change on this file since 450 was 450, checked in by Silvan Scherrer, 11 years ago

fixes ticket:190

File size: 7.3 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 <stdio.h>
38
39#include "globals.h"
40#include "findDlg.h"
41#include "Lucide_res.h"
42#include "luutils.h"
43#include "messages.h"
44
45#define MAXSEARCHLENGTH 100
46
47FindDlg::FindDlg( HWND hWndFrame )
48{
49    hFrame        = hWndFrame;
50    searchString  = newstrdup( "" );
51    caseSensitive = false;
52    findBack = 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            WinSendDlgItemMsg( hwnd, IDC_FINDFIELD, EM_SETSEL, MPFROM2SHORT( 0, MAXSEARCHLENGTH ), MPVOID );
93            WinCheckButton( hwnd, IDC_FINDMATCHCASE, _this->caseSensitive );
94            WinCheckButton( hwnd, IDC_FINDBACK, _this->findBack );
95
96
97            return (MRESULT)FALSE;
98        }
99
100        case WM_COMMAND:
101            switch (SHORT1FROMMP(mp1))
102            {
103                case DID_OK:
104                    {
105                        char buf[ MAXSEARCHLENGTH + 1 ];
106                        WinQueryDlgItemText( hwnd, IDC_FINDFIELD, sizeof( buf ), buf );
107                        delete _this->searchString;
108                        _this->searchString = newstrdup( buf );
109                        _this->caseSensitive = WinQueryButtonCheckstate( hwnd, IDC_FINDMATCHCASE );
110                        _this->findBack = WinQueryButtonCheckstate( hwnd, IDC_FINDBACK );
111                        WinDismissDlg( hwnd, DID_OK );
112                    }
113                    return (MRESULT)FALSE;
114
115                case DID_CANCEL:
116                    WinDismissDlg( hwnd, DID_CANCEL );
117                    return (MRESULT)FALSE;
118            };
119            return (MRESULT)FALSE;
120    }
121    return WinDefDlgProc( hwnd, msg, mp1, mp2 );
122}
123
124
125//
126// ------------------ GotoDlg ---------------------
127//
128
129GotoDlg::GotoDlg( HWND hWndFrame, long _pages, long _curpage )
130{
131    hFrame  = hWndFrame;
132    page    = -1;
133    pages   = _pages;
134    curpage = _curpage;
135}
136
137GotoDlg::~GotoDlg()
138{
139}
140
141ULONG GotoDlg::showDialog()
142{
143    return WinDlgBox( HWND_DESKTOP, hFrame, gotoDlgProc,
144                      _hmod, IDD_GOTOPAGE, this );
145}
146
147
148
149MRESULT EXPENTRY GotoDlg::gotoDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
150{
151    // This is a static method, so we don't know which instantiation we're
152    // dealing with. But we can get a pseudo-this from the parameter to
153    // WM_INITDLG, which we therafter store with the window and retrieve
154    // as follows:
155    GotoDlg *_this = (GotoDlg *)WinQueryWindowULong( hwnd, QWL_USER );
156
157    switch (msg)
158    {
159
160        // Dialog has just been created
161        case WM_INITDLG:
162        {
163            // Save the mp2 into our user data so that subsequent calls have
164            // access to the parent C++ object
165            WinSetWindowULong( hwnd, QWL_USER, (ULONG)mp2 );
166            _this = (GotoDlg *)mp2;
167            localizeDialog( hwnd );
168            centerWindow( _this->hFrame, hwnd );
169
170            WinSendDlgItemMsg( hwnd, IDC_PAGE, SPBM_SETLIMITS,
171                               MPFROMLONG( _this->pages ), MPFROMLONG( 1 ) );
172            WinSendDlgItemMsg( hwnd, IDC_PAGE, SPBM_SETCURRENTVALUE,
173                               MPFROMLONG( _this->curpage ), MPVOID );
174            char *pgfrm = newstrdupL( GTP_OF );
175            char pgnum[ 32 ];
176            snprintf( pgnum, sizeof( pgnum ), pgfrm, _this->pages );
177            delete pgfrm;
178            WinSetDlgItemText( hwnd, IDC_PAGES, pgnum );
179            return (MRESULT)FALSE;
180        }
181
182        case WM_CONTROL:
183        // @todo highlight the text in the spinbutton (should work but looks like its not)
184        WinSendDlgItemMsg( hwnd, IDC_PAGE, EM_SETSEL,
185                                      MPFROM2SHORT(0, 256), NULL);
186        return (MRESULT)FALSE;
187
188        case WM_COMMAND:
189            switch (SHORT1FROMMP(mp1))
190            {
191                case DID_OK:
192                    {
193                        LONG spbmValue = 0;
194                        BOOL rc = (BOOL)WinSendDlgItemMsg( hwnd, IDC_PAGE, SPBM_QUERYVALUE,
195                                            MPFROMP( &spbmValue ),
196                                            MPFROM2SHORT( 0, SPBQ_UPDATEIFVALID ) );
197
198                        if ( rc && ( spbmValue > 0 ) ) {
199                            _this->page = spbmValue;
200                        }
201                        WinDismissDlg( hwnd, DID_OK );
202                    }
203                    return (MRESULT)FALSE;
204
205                case DID_CANCEL:
206                    WinDismissDlg( hwnd, DID_CANCEL );
207                    return (MRESULT)FALSE;
208            };
209            return (MRESULT)FALSE;
210    }
211    return WinDefDlgProc( hwnd, msg, mp1, mp2 );
212}
213
Note: See TracBrowser for help on using the repository browser.