XML with StyledTextControl Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
letij
Earned a small fee
Earned a small fee
Posts: 18
Joined: Mon Jun 16, 2008 10:36 am

XML with StyledTextControl

Post by letij » Thu Jun 19, 2008 11:15 am

Hello!

I want to include a simple XML editor in my application and the StyledTextControl seems to be just right for this purpose, but I can't find any tutorials on how to use it.

How do I activated Folding?
How do I define syntax highlighting with a property file?
The first characters are "" before the root node. What's wrong?
Last edited by letij on Thu Jun 19, 2008 12:59 pm, edited 1 time in total.

letij
Earned a small fee
Earned a small fee
Posts: 18
Joined: Mon Jun 16, 2008 10:36 am

Post by letij » Thu Jun 19, 2008 12:45 pm

Edit: Got the hardcoded syntax highlighting working already
use StyleSetXXX( wx.stc.STC_H_YYY, <style> ) methods
the STC_H_ constants define the XML tokens

Edit: A lot of infos seems to be pack in the file "wxPython Docs and Demos/demo/StyledTextCtrl_2.py"

NinjaNL
Moderator
Moderator
Posts: 899
Joined: Sun Oct 03, 2004 10:33 am
Location: Oosterwolde, Netherlands

Post by NinjaNL » Thu Jun 19, 2008 2:49 pm

letij wrote:Edit: Got the hardcoded syntax highlighting working already
use StyleSetXXX( wx.stc.STC_H_YYY, <style> ) methods
the STC_H_ constants define the XML tokens

Edit: A lot of infos seems to be pack in the file "wxPython Docs and Demos/demo/StyledTextCtrl_2.py"
Lots of information here:

http://www.yellowbrain.com/stc/index.html
Follow the development of my screenplay authoring program at http://wxscreenplaywriter.blogspot.com/

letij
Earned a small fee
Earned a small fee
Posts: 18
Joined: Mon Jun 16, 2008 10:36 am

Post by letij » Fri Jun 20, 2008 9:13 am

I still can't get the issue with the "" characters resolved. Notepad++ says that my document is "ANSI" while after I save it with the StyledTextControl it is "UTF-8". Is there a way to convert the document to UTF-8 right away?

> Lots of information here:
> http://www.yellowbrain.com/stc/index.html

I know, but it's only an API documentation, no tutorial. Thanks anyway!

geralds
I live to help wx-kind
I live to help wx-kind
Posts: 186
Joined: Tue Nov 01, 2005 9:22 am
Contact:

Post by geralds » Tue Jun 24, 2008 11:13 am

What you see at the start of your file is the UTF-8 byte order mark.

(I know it's redundant as UTF-8 consists of chains of single-byte units, but some processors _require_ a UTF-8 BOM which is why many editors offer to put it in.)

One way of handling this is to strip out the byte order mark before passing it to wxStyledTextCtrl.

In the following docBuffer is of type char *, docBufferLen is unsigned and isUtf8 is bool.

Code: Select all

// adjust for UTF-8 BOM
if ( docBuffer &&
        ( unsigned char ) docBuffer[0] == 0xEF &&
        ( unsigned char ) docBuffer[1] == 0xBB &&
        ( unsigned char ) docBuffer[2] == 0xBF )
{
    docBuffer += 3;
    docBufferLen -= 3;
    isUtf8 = true;
}

An example of a syntax highlighting property is the stedit component.

I derived from wxStyledTextCtrl for my XML editor and there are some issues: the lexer has serious bugs (e.g. embedded DTDs aren't highlighted correctly) and the Scintilla component is rather out of date. (Can't wait for wxW 2.8.8! Until it's released I can't use the update that's been in the source tree since November last year - it's easy on Windows but the Linux port relies on centrally maintained libraries...)

-Gerald

Post Reply