-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmlEditFram.h
More file actions
333 lines (304 loc) · 10.4 KB
/
xmlEditFram.h
File metadata and controls
333 lines (304 loc) · 10.4 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/*
Project: XML Editor
Module:
Description:
Author: Martin Gäckler
Address: Hofmannsthalweg 14, A-4030 Linz
Web: https://www.gaeckler.at/
Copyright: (c) 1988-2024 Martin Gäckler
This program 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 3.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
THIS SOFTWARE IS PROVIDED BY Martin Gäckler, Austria, Linz ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
//---------------------------------------------------------------------------
#ifndef xmlEditFramH
#define xmlEditFramH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include <Grids.hpp>
#include <Menus.hpp>
#include <iostream>
#include <fstream>
#include <ActnList.hpp>
#include <gak/string.h>
#include <gak/stringStream.h>
#include <gak/xmlValidator.h>
#include <gak/ChangeManager.h>
#include <gak/directory.h>
//---------------------------------------------------------------------------
class TxmlEditorFrame;
//---------------------------------------------------------------------------
#pragma option -RT-
typedef gak::xml::Document * (*TXmlDocLoad)( const gak::STRING &pathName );
typedef gak::STRING (*TPlainTextLoad)( const gak::STRING &pathName );
typedef gak::STRING (*TSchemaFile4NamespaceCB)( const gak::STRING &nameSpace );
class XmlMySchemaManager : public gak::xml::SchemaManager
{
static TXmlDocLoad xmlDocLoadFunction;
static TSchemaFile4NamespaceCB schemaFile4NamespaceCB;
public:
// XmlMySchemaManager() {} /// TODO check why?
virtual gak::STRING getSchemaFile4Namespace( const gak::STRING &nameSpace );
virtual gak::xml::Document *loadSchemaFile( const gak::STRING &schemaFile );
static void setXmlDocLoadFunction( TXmlDocLoad newFunction )
{
xmlDocLoadFunction = newFunction;
}
static void setSchemaFile4NamespaceCB( TSchemaFile4NamespaceCB newCB )
{
schemaFile4NamespaceCB = newCB;
}
};
class XmlTreeViewer : public gak::DocumentViewer
{
TxmlEditorFrame *theViewer;
public:
XmlTreeViewer( gak::ChangeManager *manager, TxmlEditorFrame *theViewer)
: gak::DocumentViewer( manager )
{
this->theViewer = theViewer;
}
void handlePositionChange( void *document, void *position );
void handleChange( void *document, void *item );
void handleNew( void *document, void *item );
void handleDelete( void *document, void *item );
};
#pragma option -RT.
//---------------------------------------------------------------------------
typedef void (__closure *TStyleChanged)(
const gak::STRING &style, const gak::STRING &stylesheetType
);
typedef void (__closure *TXmlSchemaChanged)( const gak::STRING &schema );
//---------------------------------------------------------------------------
class TxmlEditorFrame : public TFrame
{
__published: // Von der IDE verwaltete Komponenten
TTreeView *XmlTreeView;
TSplitter *Splitter2;
TPanel *Panel1;
TStringGrid *AttributeGrid;
TMemo *ValueMemo;
TPopupMenu *TreeViewPopupMenu;
TMenuItem *ChangePopup;
TMenuItem *N2;
TMenuItem *DeleteChildrenItem;
TMenuItem *N1;
TMenuItem *InsElement;
TMenuItem *InsTextPCDATA;
TMenuItem *InsTextCDATA;
TMenuItem *InsComment;
TMenuItem *ProcInstruction;
TMenuItem *DOCTYPE;
TPopupMenu *AttributePopupMenu;
TSplitter *Splitter1;
TStatusBar *StatusBar;
TMenuItem *insXmlStyleSheet;
TPopupMenu *ValuePopupMenu;
TMenuItem *CreateElement;
TMenuItem *DeleteWithoutChildren;
TMenuItem *N3;
TMenuItem *Expand;
TMenuItem *Collapse;
TMenuItem *CloneElement;
TMenuItem *N4;
TMenuItem *N5;
TMenuItem *ShowStyles;
void __fastcall XmlTreeViewChange(TObject *Sender, TTreeNode *Node);
void __fastcall XmlTreeViewEdited(TObject *Sender, TTreeNode *Node,
AnsiString &S);
void __fastcall XmlTreeViewDragOver(TObject *Sender, TObject *Source,
int X, int Y, TDragState State, bool &Accept);
void __fastcall XmlTreeViewDragDrop(TObject *Sender, TObject *Source,
int X, int Y);
void __fastcall ValueMemoChange(TObject *Sender);
void __fastcall AttributeGridSetEditText(TObject *Sender, int ACol,
int ARow, const AnsiString Value);
void __fastcall AttributeGridKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift);
void __fastcall AttributeGridGetEditText(TObject *Sender, int ACol,
int ARow, AnsiString &Value);
void __fastcall AttributeGridDrawCell(TObject *Sender, int ACol, int ARow,
TRect &Rect, TGridDrawState State);
void __fastcall TreeViewPopupClick(TObject *Sender);
void __fastcall XmlTreeViewContextPopup(TObject *Sender, TPoint &MousePos,
bool &Handled);
void __fastcall ChangePopupClick(TObject *Sender);
void __fastcall AttributePopupClick(TObject *Sender);
void __fastcall AttributeGridContextPopup(TObject *Sender,
TPoint &MousePos, bool &Handled);
void __fastcall XmlTreeViewEditing(TObject *Sender, TTreeNode *Node,
bool &AllowEdit);
void __fastcall XmlTreeViewAdvancedCustomDrawItem(TCustomTreeView *Sender,
TTreeNode *Node, TCustomDrawState State, TCustomDrawStage Stage,
bool &PaintImages, bool &DefaultDraw);
void __fastcall XmlTreeViewKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift);
void __fastcall CreateElementClick(TObject *Sender);
void __fastcall CollapseClick(TObject *Sender);
void __fastcall ExpandClick(TObject *Sender);
void __fastcall ShowStylesClick(TObject *Sender);
private: // Anwender-Deklarationen
bool htmlMode;
gak::xml::Document *theDocument;
gak::STRING filename, schemaFile;
gak::STRING stylesheetFile, stylesheetType;
gak::DocumentViewer *viewerInstance;
static TPlainTextLoad fileLoader;
TStyleChanged styleChangedCB;
TXmlSchemaChanged schemaChangedCB;
XmlMySchemaManager schemaManager;
gak::css::Rules *cssRules;
void addAttributeRow( void )
{
int newIdx = AttributeGrid->RowCount;
AttributeGrid->RowCount++;
AttributeGrid->Cells[0][newIdx] = "";
AttributeGrid->Cells[1][newIdx] = "";
}
void OpenStream(std::istream *theInput, const gak::STRING &fileName);
void setStylesheetFile(
const gak::STRING &stylesheetFile, const gak::STRING &stylesheetType
)
{
this->stylesheetType = stylesheetType;
if( stylesheetFile.isEmpty() )
this->stylesheetFile = stylesheetFile;
else
this->stylesheetFile = makeFullPath( filename, stylesheetFile );
if( styleChangedCB )
styleChangedCB( this->stylesheetFile, stylesheetType );
theDocument->setCssRules( *cssRules );
gak::STRING tmpName = makeFullPath( filename, "editor.css" );
if( fileLoader )
{
gak::STRING css = fileLoader( tmpName );
theDocument->readCssRules( css, false );
}
else if( exists( tmpName ) )
{
std::ifstream istream( tmpName );
theDocument->readCssRules( &istream, false );
}
if( stylesheetType == "text/css" )
{
if( fileLoader )
{
gak::STRING css = fileLoader( stylesheetFile );
theDocument->readCssRules( css, false );
}
else if( exists( stylesheetFile ) )
{
std::ifstream istream( stylesheetFile );
theDocument->readCssRules( &istream, false );
}
}
theDocument->applyCssRules();
}
static gak::STRING getTag( gak::xml::Element *xmlElement );
TTreeNode *addNode( TTreeNode *parentNode, gak::xml::Element *newElement );
void setChanged( void )
{
*viewerInstance = true;
}
bool hasChanged( void ) const
{
return *viewerInstance;
}
public: // Anwender-Deklarationen
bool refreshValue( gak::xml::Element *theItem=NULL );
__fastcall TxmlEditorFrame(TComponent* Owner);
void initShow( void )
{
AttributeGrid->ColWidths[0] = AttributeGrid->Width/3;
AttributeGrid->ColWidths[1] = AttributeGrid->Width - AttributeGrid->ColWidths[0] - 25;
}
void initFrame( gak::ChangeManager *manager, gak::css::Rules *cssRules )
{
doEnterFunction("TxmlEditorFrame::initViewer");
if( viewerInstance )
delete viewerInstance;
viewerInstance = new XmlTreeViewer( manager, this );
this->cssRules = cssRules;
}
void clear( void );
void CreateDoc( void );
void OpenFile( const gak::STRING &fileName )
{
std::ifstream theInput((const char *)fileName);
OpenStream( &theInput, fileName );
}
void setText( const gak::STRING &xmlData, const gak::STRING &fileName )
{
// filename = "";
gak::iSTRINGstream theInput( xmlData );
OpenStream( &theInput, fileName );
}
gak::STRING getText( void )
{
return theDocument->generate( htmlMode ? gak::xml::HTML_MODE : gak::xml::XML_MODE );
}
gak::STRING getSchemaFile( void ) const
{
return schemaFile;
}
gak::STRING getStylesheetFile( gak::STRING *stylesheetType ) const
{
*stylesheetType = this->stylesheetType;
return stylesheetFile;
}
void SaveFile(const gak::STRING &fileName);
void buildTree(TTreeNode *parent, gak::xml::Element *xmlElem );
gak::STRING testDocument( void );
void refreshSchema( void )
{
schemaFile = "";
if( theDocument )
schemaFile = schemaManager.refreshDocument( theDocument, true );
else
schemaManager.clearValidators();
}
void Cut( TWinControl *active );
void Copy( TWinControl *active );
void Paste( TWinControl *active );
gak::xml::Document *getDocument( void ) const
{
return theDocument;
}
void setDocument(gak::xml::Document *newDocument, bool htmlMode );
void setStyleChangedCB( TStyleChanged newCB )
{
styleChangedCB = newCB;
}
void setSchemaChangedCB( TXmlSchemaChanged newCB )
{
schemaChangedCB = newCB;
}
static void setPlainTextLoader( TPlainTextLoad fileLoader )
{
TxmlEditorFrame::fileLoader = fileLoader;
}
void selectXmlElement( gak::xml::Element *theElement );
};
//---------------------------------------------------------------------------
extern PACKAGE TxmlEditorFrame *xmlEditorFrame;
//---------------------------------------------------------------------------
#endif