XML editor mode

<< Click to Display Table of Contents >>

Navigation:  Appendix >

XML editor mode

WPTools 8 supports a special XML editing mode.

 

A loaded XML text will be displayed as:

clip0181

 

 

for this the XMLTAGS reader must be used.

 

  WPRichText1.LoadFromFile( filename , true, 'XMLTAGS-utf8' );

 

and the FormatOptions initialized as follows:

 

 WPRichText1.FormatOptions := WPRichText1.FormatOptions + [wpShowSPANCodes];

 WPRichText1.FormatOptionsEx2 := WPRichText1.FormatOptionsEx2 + [wpfCodeObjectAsXMLTags,wpfCodeObjectCheckParStyles];

 

wpfCodeObjectAsXMLTags creates the tag boxes shown above.

wpfCodeObjectCheckParStyles makes the editor look up paragraph styles which have the same name as the tags which include the text. In this case the paragraph style collection uses the CSS definition

 

         Lemma{font-family:'Courier New';font-weight:bold;color:red}

         Entsprechung{font-family:'Tahoma';font-size:13.00pt;}

 

which was assigned to the editor using:

 

  WPRichText1.LoadCSSheet( css_string );

 

 

... but there is more ...

 

in case You have the WPTools 8 Premium edition, You can also work with XML schemas.

 

from the tags in the XML schema it is possible to create a popup menu with items, which can be inserted at a certain position in the editor.

 

To make this easy the premium edition includes the unit WPXMLSchema which implements the class TWPXMLSchmema.

 

You need to create it like this:

 

procedure TForm1.FormCreate(Sender: TObject);

begin

 Schema := TWPXMLSchmema.Create(Self);

 Schema.OnPopupMenuClick := DoPopupMenuClick;

end;

 

procedure TForm1.FormDestroy(Sender: TObject);

begin

 Schema.Free;

end;

 

DoPopupMenuClick is a method which should handle the click event on one popup menu item.

 

procedure TForm1.DoPopupMenuClick(fMenu: TXMLMenuItem; fXMLSchema: TWPXMLSchmema; fXMLTag: TWPXMLSchemaTag);

var men: TXMLMenuItem;

begin

 men := fMenu.XMLParent;

while men <> nil do

begin

   WPRichText1.InputCode(wpobjCode, men.XMLTag.nameparam, '', [wpinpWrapSelectedText, wpinpNewParagraph, wpinpAutoTabs, wpinpPlaceCursorAfterStart]);

   men := men.XMLParent;

end;

 WPRichText1.InputCode(wpobjCode, fXMLTag.nameparam, '', [wpinpWrapSelectedText, wpinpNewParagraph, wpinpAutoTabs, wpinpPlaceCursorAfterStart]);

 WPRichText1.SetFocus;

end;

 

 

The popup menu object is created on the form and assigned to the WPRichText PopupMenu property. Then in event PopupMenu1Popup this code is placed:

 

var bb: Boolean;

 

procedure TForm1.PopupMenu1Popup(Sender: TObject);

var a: TWPXMLSchemaTag; pt: TPoint;

begin

if not bb then

try

   bb := true;

   PopupMenu1.Items.Clear;

   a := Schema.LocateContext(

     WPRichText1.ActivePar,

     WPRichText1.ActivePosInPar);

  if a <> nil then

     a.FillPopupMenu(PopupMenu1, 0);

   WPRichText1.GetParXYBaselineScreen(WPRichText1.ActivePar,

     WPRichText1.ActivePosInPar, pt.x, pt.y);

   pt := WPRichText1.ClientToScreen(pt);

   PopupMenu1.Popup(PopupMenu1.PopupPoint.X, pt.y + 4);

finally

   bb := false;

end;

end;

 

Of course the menu can be also created a bit differently or other items can be added.

 

In action the popup menu can look like this:

 

1) press the context menu key on the keyboard:

 

clip0183

 

2) select the item and press enter

 

clip0184