VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/tests/w16gui/popfind.c@ 1

Last change on this file since 1 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38/*--------------------------------------------------------
39 POPFIND.C -- Popup Editor Search and Replace Functions
40 (c) Charles Petzold, 1992
41 --------------------------------------------------------*/
42
43#include <windows.h>
44#include <commdlg.h>
45#include <string.h>
46#define MAX_STRING_LEN 256
47
48static char szFindText [MAX_STRING_LEN] ;
49static char szReplText [MAX_STRING_LEN] ;
50
51HWND PopFindFindDlg (HWND hwnd)
52 {
53 static FINDREPLACE fr ; // must be static for modeless dialog!!!
54
55 fr.lStructSize = sizeof (FINDREPLACE) ;
56 fr.hwndOwner = hwnd ;
57 fr.hInstance = NULL ;
58 fr.Flags = FR_HIDEUPDOWN | FR_HIDEMATCHCASE | FR_HIDEWHOLEWORD ;
59 fr.lpstrFindWhat = szFindText ;
60 fr.lpstrReplaceWith = NULL ;
61 fr.wFindWhatLen = sizeof (szFindText) ;
62 fr.wReplaceWithLen = 0 ;
63 fr.lCustData = 0 ;
64 fr.lpfnHook = NULL ;
65 fr.lpTemplateName = NULL ;
66
67 return FindText (&fr) ;
68 }
69
70HWND PopFindReplaceDlg (HWND hwnd)
71 {
72 static FINDREPLACE fr ; // must be static for modeless dialog!!!
73
74 fr.lStructSize = sizeof (FINDREPLACE) ;
75 fr.hwndOwner = hwnd ;
76 fr.hInstance = NULL ;
77 fr.Flags = FR_HIDEUPDOWN | FR_HIDEMATCHCASE | FR_HIDEWHOLEWORD ;
78 fr.lpstrFindWhat = szFindText ;
79 fr.lpstrReplaceWith = szReplText ;
80 fr.wFindWhatLen = sizeof (szFindText) ;
81 fr.wReplaceWithLen = sizeof (szReplText) ;
82 fr.lCustData = 0 ;
83 fr.lpfnHook = NULL ;
84 fr.lpTemplateName = NULL ;
85
86 return ReplaceText (&fr) ;
87 }
88
89BOOL PopFindFindText (HWND hwndEdit, int *piSearchOffset, LPFINDREPLACE lpfr)
90 {
91 int iPos ;
92 LOCALHANDLE hLocal ;
93 LPSTR lpstrDoc, lpstrPos ;
94
95 // Get a pointer to the edit document
96
97 hLocal = (HWND) SendMessage (hwndEdit, EM_GETHANDLE, 0, 0L) ;
98 lpstrDoc = (LPSTR) LocalLock (hLocal) ;
99
100 // Search the document for the find string
101
102 lpstrPos = _fstrstr (lpstrDoc + *piSearchOffset, lpfr->lpstrFindWhat) ;
103 LocalUnlock (hLocal) ;
104
105 // Return an error code if the string cannot be found
106
107 if (lpstrPos == NULL)
108 return FALSE ;
109
110 // Find the position in the document and the new start offset
111
112 iPos = lpstrPos - lpstrDoc ;
113 *piSearchOffset = iPos + _fstrlen (lpfr->lpstrFindWhat) ;
114
115 // Select the found text
116
117 SendMessage (hwndEdit, EM_SETSEL, 0,
118 MAKELONG (iPos, *piSearchOffset)) ;
119
120 return TRUE ;
121 }
122
123BOOL PopFindNextText (HWND hwndEdit, int *piSearchOffset)
124 {
125 FINDREPLACE fr ;
126
127 fr.lpstrFindWhat = szFindText ;
128
129 return PopFindFindText (hwndEdit, piSearchOffset, &fr) ;
130 }
131
132BOOL PopFindReplaceText (HWND hwndEdit, int *piSearchOffset, LPFINDREPLACE lpfr)
133 {
134 // Find the text
135
136 if (!PopFindFindText (hwndEdit, piSearchOffset, lpfr))
137 return FALSE ;
138
139 // Replace it
140
141 SendMessage (hwndEdit, EM_REPLACESEL, 0, (long) lpfr->lpstrReplaceWith) ;
142
143 return TRUE ;
144 }
145
146BOOL PopFindValidFind (void)
147 {
148 return *szFindText != '\0' ;
149 }
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette