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

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

Improved size of input fields, initially select text in Find dialog (closes #103)

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