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

Last change on this file since 460 was 460, checked in by Silvan Scherrer, 15 years ago

small changes

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