Codejock Forums Homepage
Forum Home Forum Home > General > Articles and Tutorials
  New Posts New Posts RSS Feed - How to load the Lex Syntax from a resource
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to load the Lex Syntax from a resource

 Post Reply Post Reply
Author
Message
elmue View Drop Down
Groupie
Groupie


Joined: 05 June 2010
Location: Germany
Status: Offline
Points: 24
Post Options Post Options   Thanks (0) Thanks(0)   Quote elmue Quote  Post ReplyReply Direct Link To This Post Topic: How to load the Lex Syntax from a resource
    Posted: 13 June 2010 at 10:25pm
Hello

The samples MDITextEditor and GUI_VisualStudio demonstrate how to use the SyntaxEdit control.
But both load the Lex Syntax and the color theme from files.
At least 3 files are required in the samples:
SyntaxEdit.ini
colorSchema0.ini
_cpp.schclass

I need only one syntax for my project and don't want to fill the disk with unnecessarry files.

As an Xtreme manual does not exist I had to dive deep into the code to find out how to load the syntax from a resource rather than from files.
I will explain this here so others can save the time that I spent in finding out how to do this.

When tracing through the code I found several bugs.
You must first fix these bugs and then recompile the entire library.

Edit the file XTPSyntaxEditLexColorFileReader.cpp:




In the demo GUI_VisualStudio in the constructor CGUI_VisualStudioView() remove the line
________________________________________________

GetEditCtrl().SetConfigFile(CXTPSyntaxEditCtrl::GetModulePath() + _T("EditConfig\\SyntaxEdit.ini"));
________________________________________________

and replace it with the following code:
________________________________________________

CString s_Theme = ";Comment";
CString s_Scheme;
CUtils::GetResource(MAKEINTRESOURCE(IDR_LEXSYNTAX), RT_RCDATA, &s_Scheme);

GetEditCtrl().SetPassedIniSet("[Themes]\r\nDefault\r\n[Schemes]\r\nCPP\r\n");
GetEditCtrl().SetSyntaxAndColorScheme(s_Scheme, s_Theme);

GetEditCtrl().GetPaintManager()->SetLineNumberTextColor(0x999999);

________________________________________________

The function GetResource() loads the Syntax scheme from the resources into a string.

I tried to set a color theme via s_Theme but it does not work. (There are more bugs still in the code)
But this does not matter because all the colors are already defined in the syntax scheme.
The color theme is only needed if you want to override these colors.
_______________

Please note that the "parsing" that is done for the string
"[Themes]\r\nDefault\r\n[Schemes]\r\nCPP\r\n"
is very primitive.
The string must be exactly of the above format.
It MUST end with "\r\n" !
_______________

The scheme name "CPP" is completely meaningless.
_______________

The string s_Theme must not be empty!
_______________

The comment in the code is misleading:
//m_sIniSet = _T("[Schemes]\r\nCPP\r\n[Themes]\r\nDefault\r\nAlternative\r\n");

This comment makes you think that it would be possible to add more than one Theme or more than one Scheme.
But this is not possible. The rest of the code was not designed for that.
___________________

The color of the line numbers must be set separately.

Elmü


Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down



This page was generated in 0.102 seconds.