Print Page | Close Window

How to load the Lex Syntax from a resource

Printed From: Codejock Forums
Category: General
Forum Name: Articles and Tutorials
Forum Description: Articles and Tutorials
URL: http://forum.codejock.com/forum_posts.asp?TID=16818
Printed Date: 04 December 2024 at 3:23am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: How to load the Lex Syntax from a resource
Posted By: elmue
Subject: How to load the Lex Syntax from a resource
Date 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ü





Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net