1 /***************************************************************************
3 TextEditor.mcc - Textediting MUI Custom Class
4 Copyright (C) 1997-2000 Allan Odgaard
5 Copyright (C) 2005-2014 TextEditor.mcc Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 TextEditor class Support Site: http://www.sf.net/projects/texteditor-mcc
21 ***************************************************************************/
24 #include <clib/alib_protos.h>
25 #include <proto/utility.h>
31 static void SimpleMarkText(struct InstData
*data
, LONG startx
, struct line_node
*startline
, LONG stopx
, struct line_node
*stopline
)
37 data
->blockinfo
.enabled
= FALSE
;
38 MarkText(data
, data
->blockinfo
.startx
, data
->blockinfo
.startline
, data
->blockinfo
.stopx
, data
->blockinfo
.stopline
);
42 SetCursor(data
, data
->CPos_X
, data
->actualline
, FALSE
);
45 data
->blockinfo
.startline
= startline
;
46 data
->blockinfo
.startx
= startx
;
47 data
->blockinfo
.stopline
= data
->actualline
= stopline
;
48 data
->blockinfo
.stopx
= data
->CPos_X
= stopx
;
49 data
->blockinfo
.enabled
= TRUE
;
51 ScrollIntoDisplay(data
);
52 MarkText(data
, startx
, startline
, stopx
, stopline
);
59 static LONG
Native_strncmp (STRPTR str1
, STRPTR str2
, LONG len
) { return strncmp(str1
, str2
, len
); }
60 static LONG
Utility_strnicmp (STRPTR str1
, STRPTR str2
, LONG len
) { return Strnicmp(str1
, str2
, len
); }
63 IPTR
mSearch(UNUSED
struct IClass
*cl
, Object
*obj
, struct MUIP_TextEditor_Search
*msg
)
65 struct InstData
*data
= INST_DATA(cl
, obj
);
66 STRPTR str
= msg
->SearchString
;
67 LONG len
= strlen(str
), step
= 0;
71 if(len
> 0 && len
<= 120)
74 LONG (*StrCmp
)(STRPTR
, STRPTR
, LONG
);
76 struct line_node
*line
;
78 // if the FromTop flag is set we start the search right from the top
79 if(isFlagSet(msg
->Flags
, MUIF_TextEditor_Search_FromTop
))
82 line
= GetFirstLine(&data
->linelist
);
86 cursor
= data
->CPos_X
;
87 line
= data
->actualline
;
90 memset(map
, len
, 256);
92 // if a casesensitive search is requested we use a different
94 if(isFlagSet(msg
->Flags
, MUIF_TextEditor_Search_CaseSensitive
))
96 StrCmp
= Native_strncmp
;
99 map
[(int)*str
++] = step
--;
103 StrCmp
= Utility_strnicmp
;
106 map
[ToLower(*str
)] = step
;
107 map
[ToUpper(*str
++)] = step
--;
111 if(isFlagSet(msg
->Flags
, MUIF_TextEditor_Search_Backwards
))
113 //D(DBF_STARTUP, "MUIF_TextEditor_Search_Backwards search=%s\n", msg->SearchString);
120 STRPTR contents
= line
->line
.Contents
+ cursor
- lenTmp
+1;
121 STRPTR lower
= line
->line
.Contents
;
123 while(contents
>= lower
)
125 //D(DBF_STARTUP, "MUIF_TextEditor_Search_Backwards previous=%ld, contents=%s\n",line, contents);
126 if(!StrCmp(contents
, msg
->SearchString
, len
))
128 LONG startx
= contents
- line
->line
.Contents
;
130 //D(DBF_STARTUP, "MUIF_TextEditor_Search_Backwards found\n");
132 SimpleMarkText(data
, startx
, line
, startx
+len
, line
);
141 line
= GetPrevLine(line
);
144 cursor
= line
->line
.Length
;
152 STRPTR contents
= line
->line
.Contents
+ cursor
+ len
-1;
153 STRPTR upper
= line
->line
.Contents
+ line
->line
.Length
;
155 while(contents
< upper
)
157 skip
= map
[(int)(*contents
)];
162 if(!StrCmp(contents
, msg
->SearchString
, len
))
164 LONG startx
= contents
- line
->line
.Contents
;
166 SimpleMarkText(data
, startx
, line
, startx
+len
, line
);
177 line
= GetNextLine(line
);
189 IPTR
mReplace(UNUSED
struct IClass
*cl
, Object
*obj
, struct MUIP_TextEditor_Replace
*msg
)
191 struct InstData
*data
= INST_DATA(cl
, obj
);
199 DoMethod(obj
, MUIM_TextEditor_InsertText
, msg
->NewString
, MUIV_TextEditor_InsertText_Cursor
);