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

Last change on this file since 367 was 367, checked in by dmik, 11 years ago

Merged bramches/kmk (r294:365) to trunk.

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#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}
53
54FindDlg::~FindDlg()
55{
56    delete searchString;
57}
58
59ULONG FindDlg::showDialog()
60{
61    return WinDlgBox( HWND_DESKTOP, hFrame, findDlgProc,
62                      _hmod, IDD_FIND, this );
63}
64
65
66
67MRESULT EXPENTRY FindDlg::findDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
68{
69    // This is a static method, so we don't know which instantiation we're
70    // dealing with. But we can get a pseudo-this from the parameter to
71    // WM_INITDLG, which we therafter store with the window and retrieve
72    // as follows:
73    FindDlg *_this = (FindDlg *)WinQueryWindowULong( hwnd, QWL_USER );
74
75    switch (msg)
76    {
77
78        // Dialog has just been created
79        case WM_INITDLG:
80        {
81            // Save the mp2 into our user data so that subsequent calls have
82            // access to the parent C++ object
83            WinSetWindowULong( hwnd, QWL_USER, (ULONG)mp2 );
84            _this = (FindDlg *)mp2;
85            localizeDialog( hwnd );
86            centerWindow( _this->hFrame, hwnd );
87
88            WinSendDlgItemMsg( hwnd, IDC_FINDFIELD, EM_SETTEXTLIMIT,
89                               MPFROMSHORT( MAXSEARCHLENGTH ), MPVOID );
90            WinSetDlgItemText( hwnd, IDC_FINDFIELD, _this->searchString );
91            WinSendDlgItemMsg( hwnd, IDC_FINDFIELD, EM_SETSEL, MPFROM2SHORT( 0, MAXSEARCHLENGTH ), MPVOID );
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.