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

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

'Go to page' dialog, some play with djvu plugin.

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