~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to wless/popfind.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright INRIA */
 
2
/*--------------------------------------------------------
 
3
   POPFIND.C -- Popup Editor Search and Replace Functions
 
4
  --------------------------------------------------------*/
 
5
 
 
6
#include <windows.h>
 
7
#include <commdlg.h>
 
8
#include <string.h>
 
9
#include <stdlib.h> 
 
10
 
 
11
#define MAX_STRING_LEN   256
 
12
 
 
13
static char szFindText [MAX_STRING_LEN] ;
 
14
static char szReplText [MAX_STRING_LEN] ;
 
15
 
 
16
HWND PopFindFindDlg (HWND hwnd)
 
17
     {
 
18
     static FINDREPLACE fr ;       // must be static for modeless dialog!!!
 
19
 
 
20
     fr.lStructSize      = sizeof (FINDREPLACE) ;
 
21
     fr.hwndOwner        = hwnd ;
 
22
     fr.hInstance        = NULL ;
 
23
     fr.Flags            = FR_HIDEUPDOWN | FR_HIDEMATCHCASE | FR_HIDEWHOLEWORD ;
 
24
     fr.lpstrFindWhat    = szFindText ;
 
25
     fr.lpstrReplaceWith = NULL ;
 
26
     fr.wFindWhatLen     = sizeof (szFindText) ;
 
27
     fr.wReplaceWithLen  = 0 ;
 
28
     fr.lCustData        = 0 ;
 
29
     fr.lpfnHook         = NULL ;
 
30
     fr.lpTemplateName   = NULL ;
 
31
 
 
32
     return FindText (&fr) ;
 
33
     }
 
34
 
 
35
HWND PopFindReplaceDlg (HWND hwnd)
 
36
     {
 
37
     static FINDREPLACE fr ;       // must be static for modeless dialog!!!
 
38
 
 
39
     fr.lStructSize      = sizeof (FINDREPLACE) ;
 
40
     fr.hwndOwner        = hwnd ;
 
41
     fr.hInstance        = NULL ;
 
42
     fr.Flags            = FR_HIDEUPDOWN | FR_HIDEMATCHCASE | FR_HIDEWHOLEWORD ;
 
43
     fr.lpstrFindWhat    = szFindText ;
 
44
     fr.lpstrReplaceWith = szReplText ;
 
45
     fr.wFindWhatLen     = sizeof (szFindText) ;
 
46
     fr.wReplaceWithLen  = sizeof (szReplText) ;
 
47
     fr.lCustData        = 0 ;
 
48
     fr.lpfnHook         = NULL ;
 
49
     fr.lpTemplateName   = NULL ;
 
50
 
 
51
     return ReplaceText (&fr) ;
 
52
     }
 
53
 
 
54
BOOL PopFindFindText (HWND hwndEdit, int *piSearchOffset, LPFINDREPLACE pfr)
 
55
     {
 
56
     int   iLength, iPos ;
 
57
     PSTR  pstrDoc, pstrPos ;
 
58
 
 
59
               // Read in the edit document
 
60
 
 
61
     iLength = GetWindowTextLength (hwndEdit) ;
 
62
 
 
63
     if (NULL == (pstrDoc = (PSTR) malloc (iLength + 1)))
 
64
          return FALSE ;
 
65
 
 
66
     GetWindowText (hwndEdit, pstrDoc, iLength + 1) ;
 
67
 
 
68
               // Search the document for the find string
 
69
 
 
70
     pstrPos = strstr (pstrDoc + *piSearchOffset, pfr->lpstrFindWhat) ;
 
71
     free (pstrDoc) ;
 
72
 
 
73
               // Return an error code if the string cannot be found
 
74
 
 
75
     if (pstrPos == NULL)
 
76
          return FALSE ;
 
77
 
 
78
               // Find the position in the document and the new start offset
 
79
 
 
80
     iPos = pstrPos - pstrDoc ;
 
81
     *piSearchOffset = iPos + strlen (pfr->lpstrFindWhat) ;
 
82
 
 
83
               // Select the found text
 
84
 
 
85
     SendMessage (hwndEdit, EM_SETSEL, iPos, *piSearchOffset) ;
 
86
     SendMessage (hwndEdit, EM_SCROLLCARET, 0, 0) ;
 
87
 
 
88
     return TRUE ;
 
89
     }
 
90
 
 
91
BOOL PopFindNextText (HWND hwndEdit, int *piSearchOffset)
 
92
     {
 
93
     FINDREPLACE fr ;
 
94
 
 
95
     fr.lpstrFindWhat = szFindText ;
 
96
 
 
97
     return PopFindFindText (hwndEdit, piSearchOffset, &fr) ;
 
98
     }
 
99
 
 
100
BOOL PopFindReplaceText (HWND hwndEdit, int *piSearchOffset, LPFINDREPLACE pfr)
 
101
     {
 
102
               // Find the text
 
103
 
 
104
     if (!PopFindFindText (hwndEdit, piSearchOffset, pfr))
 
105
          return FALSE ;
 
106
 
 
107
               // Replace it
 
108
 
 
109
     SendMessage (hwndEdit, EM_REPLACESEL, 0, (LPARAM) pfr->lpstrReplaceWith) ;
 
110
 
 
111
     return TRUE ;
 
112
     }
 
113
 
 
114
BOOL PopFindValidFind (void)
 
115
     {
 
116
     return *szFindText != '\0' ;
 
117
     }