Menu

[r130]: / src / xmlctrl.h  Maximize  Restore  History

Download this file

212 lines (199 with data), 6.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
* Copyright 2005-2007 Gerald Schmidt.
*
* This file is part of Xml Copy Editor.
*
* Xml Copy Editor is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* Xml Copy Editor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xml Copy Editor; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef XML_CTRL_H
#define XML_CTRL_H
#define DEFAULT_XML_DECLARATION L"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
#define DEFAULT_XML_DECLARATION_UTF8 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
#include <wx/wx.h>
#include <wx/stc/stc.h>
#include <string>
#include <set>
#include <map>
#include "validationthread.h"
struct XmlCtrlProperties
{
bool completion;
bool fold;
bool number;
bool currentLine;
bool whitespaceVisible;
bool wrap;
bool indentLines;
bool protectHiddenElements;
bool toggleLineBackground;
bool insertCloseTag;
bool deleteWholeTag;
bool validateAsYouType;
bool highlightSyntax;
int zoom, colorScheme;
wxString font;
};
enum VisibilityStates
{
SHOW_TAGS,
HIDE_ATTRIBUTES,
HIDE_TAGS
};
enum ColorSchemes
{
COLOR_SCHEME_DEFAULT,
COLOR_SCHEME_DEFAULT_BACKGROUND,
COLOR_SCHEME_REDUCED_GLARE,
COLOR_SCHEME_REDUCED_GLARE_BACKGROUND,
COLOR_SCHEME_NONE
};
enum TagTypes
{
TAG_TYPE_OPEN,
TAG_TYPE_CLOSE,
TAG_TYPE_EMPTY,
TAG_TYPE_OTHER,
TAG_TYPE_ERROR
};
enum BackgroundStates
{
BACKGROUND_STATE_NORMAL,
BACKGROUND_STATE_LIGHT
};
enum XmlFileTypes
{
FILE_TYPE_XML,
FILE_TYPE_DTD,
FILE_TYPE_CSS,
FILE_TYPE_PHP,
FILE_TYPE_RNC,
FILE_TYPE_BINARY
};
class XmlCtrl: public wxStyledTextCtrl
{
public:
XmlCtrl (
wxWindow *parent,
XmlCtrlProperties propertiesParameter,
bool *protectTagsParameter,
int visibilityStateParameter = SHOW_TAGS,
int typeParameter = FILE_TYPE_XML,
wxWindowID id = wxID_ANY,
const char *buffer = NULL,
size_t bufferLen = 0,
const std::string& catalogPath = "",
const std::string& catalogUtilityPath = "",
const std::string& basePath = "",
const std::string& auxPath = "",
const wxPoint &position = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0 );
~XmlCtrl();
int getType();
int getParentCloseAngleBracket ( int pos, int range = USHRT_MAX * 4 );
void applyProperties (
XmlCtrlProperties propertiesParameter,
bool zoomOnly = false );
void applyVisibilityState ( int state = SHOW_TAGS );
void updatePromptMaps();
void updatePromptMaps ( const char *buffer, size_t bufferLen );
void adjustCursor();
void adjustSelection();
void foldAll();
void unfoldAll();
void toggleFold();
bool insertChild ( const wxString& child );
bool insertSibling ( const wxString& sibling, const wxString& parent );
bool insertEntity ( const wxString& entity );
bool getGrammarFound();
void setErrorIndicator ( int line, int column );
void clearErrorIndicators ( int maxLine = 0 );
wxString getParent();
wxString getLastElementName ( int pos );
std::set<wxString> getChildren ( const wxString& parent );
std::set<std::string> getEntitySet();
std::set<std::string> getAttributes ( const wxString& parent );
std::string getElementStructure ( const wxString& parent );
bool canInsertAt ( int pos );
int getTagStartPos ( int pos );
void toggleLineBackground();
bool backgroundValidate ( );
bool backgroundValidate (
const char *buffer,
const char *system,
size_t bufferLen );
std::string myGetTextRaw(); // alternative to faulty stc implementation
bool getValidationRequired();
void setValidationRequired ( bool b );
private:
// the following are used for background validation
ValidationThread *validationThread;
bool validationStarted,
validationFinished,
validationSuccess;
bool *validationReleasePtr;
std::pair<int, int> validationPosition;
std::string validationMessage;
int type;
bool *protectTags;
bool validationRequired, grammarFound;
int visibilityState;
int controlState;
int currentMaxLine;
int lineBackgroundState;
wxColour baseBackground, alternateBackground;
std::map<std::string, std::map<std::string, std::set<std::string> > >
attributeMap;
std::map<std::string, std::set<std::string> > requiredAttributeMap;
std::map<std::string, std::set<std::string> > elementMap;
std::set<std::string> entitySet;
std::map<std::string, std::string> elementStructureMap;
std::string catalogPath, catalogUtilityPath, basePath, auxPath;
XmlCtrlProperties properties;
wxString getLastAttributeName ( int pos );
int getAttributeStartPos ( int pos );
int getAttributeSectionEndPos ( int pos, int range = USHRT_MAX );
int getTagType ( int pos );
int getLexerStyleAt ( int pos );
bool isCloseTag ( int pos );
bool canMoveLeftAt ( int pos );
bool canMoveRightAt ( int pos );
wxString getOpenTag ( const wxString& element );
void handleOpenAngleBracket ( wxKeyEvent& event );
void handleCloseAngleBracket ( wxKeyEvent& event );
void handleEquals ( wxKeyEvent& event );
void handleSpace ( wxKeyEvent& event );
void handleAmpersand ( wxKeyEvent& event );
void handleForwardSlash ( wxKeyEvent& event );
void handleBackspace ( wxKeyEvent& event );
void handleDelete ( wxKeyEvent& event );
void OnMarginClick ( wxStyledTextEvent& event );
void OnChar ( wxKeyEvent& event );
void OnIdle ( wxIdleEvent& event );
void OnKeyPressed ( wxKeyEvent& event );
void OnMouseLeftDown ( wxMouseEvent& event );
void OnMouseLeftUp ( wxMouseEvent& event );
void OnMouseRightUp ( wxMouseEvent& event );
void OnMiddleDown ( wxMouseEvent& event );
void insertNewLine();
void adjustNoColumnWidth();
void adjustPosRight();
void adjustPosLeft();
void setColorScheme ( int scheme );
void expandFoldsToLevel ( int level, bool expand );
void protectHeadLine();
DECLARE_NO_COPY_CLASS ( XmlCtrl )
DECLARE_EVENT_TABLE()
};
#endif
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.