Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Syntax Edit
  New Posts New Posts RSS Feed - CXTPSyntaxEditCtrl selection highlight
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTPSyntaxEditCtrl selection highlight

 Post Reply Post Reply
Author
Message
robin_l View Drop Down
Senior Member
Senior Member


Joined: 15 October 2006
Status: Offline
Points: 117
Post Options Post Options   Thanks (0) Thanks(0)   Quote robin_l Quote  Post ReplyReply Direct Link To This Post Topic: CXTPSyntaxEditCtrl selection highlight
    Posted: 27 August 2009 at 11:52am
The default for the CXTPSyntaxEditCtrl control is that any selected text retains the selection highlight irrespective of whether the control has focus. This means that the controls behave similar to edit controls created with the ES_NOHIDESEL style. This means that if multiple CXTPSyntaxEditCtrls are present within a dialog it is hard to know which (if any) has focus.
 
For example, I'm currently working on the following page which has 4 syntax edit controls:
 
 
It is possible that I've missed it, but ss there any way to have the selection hidden when the control does not have focus? This would be a more "standard" behaviour for an edit control.
 
Thanks,
 
Robin
Product: Xtreme ToolkitPro 2009 (13.4.1)
Platform: Windows 7 Ultimate(64bit)
Language: Visual Studio 2010 (C++)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 28 August 2009 at 12:25am
There is flag - BOOL CXTPSyntaxEditCtrl::m_bFocused - you can analyze it and make something like change control border style or color
 
Because your proposal does not covered the cases where each control have no selection - how you identify which one is active?
Back to Top
robin_l View Drop Down
Senior Member
Senior Member


Joined: 15 October 2006
Status: Offline
Points: 117
Post Options Post Options   Thanks (0) Thanks(0)   Quote robin_l Quote  Post ReplyReply Direct Link To This Post Posted: 28 August 2009 at 7:12am
If they were "normal" edit controls then the selection highlight would only be visible when the control had focus (unless created with the ES_NOHIDESEL style, which is not the default). Visual Studio has two different colors for highlighted text: vivid blue when the editor has focus, dull blue when it has not.
 
Would it be possible to put something into CXTPSyntaxEditPaintManager to only paint the selection highlight if the control had focus? (and force a repaint on gain/loss of focus). Or, if you want it to resemble the Visual Studio editor, to have different highlight selection colors for the focused and non-focused states....
Product: Xtreme ToolkitPro 2009 (13.4.1)
Platform: Windows 7 Ultimate(64bit)
Language: Visual Studio 2010 (C++)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 28 August 2009 at 10:22am
Make sense if I will have some extra time. But even this way not indicate you which of Syntax controls is active Now - right?
Back to Top
robin_l View Drop Down
Senior Member
Senior Member


Joined: 15 October 2006
Status: Offline
Points: 117
Post Options Post Options   Thanks (0) Thanks(0)   Quote robin_l Quote  Post ReplyReply Direct Link To This Post Posted: 28 August 2009 at 10:51am
Well it does if the selected control is the only one with the highlighted selection.
 
But possibly it is better to mimic the way that Visual Studio does things, which is to have a differently coloured selection when the editor has the focus than when it does not.
 
As far as I can see, the only bits involved are in XTPSyntaxEditPaintManager.cpp, where the selection highlight color is set by the code:

pDC->SetTextColor((i%2) ? crText : crHiliteText);

pDC->SetBkColor((i%2) ? crBack : crHiliteBack);

It should be possible to change the highlight color depending on whether the control has focus. Perhaps something like:

pDC->SetTextColor((i%2) ? crText : ((pEditCtrl->GetFocus()==pEditCtrl)?FOCUSED_HILITE_TEXT:crHiliteText));

pDC->SetBkColor((i%2) ? crBack : ((pEditCtrl->GetFocus()==pEditCtrl)?FOCUSED_HILITE_BACK:crHiliteBack));

If you used the system text highlight colors then you would get the same effect as Visual Studio, as the current syntax control selection highlights appear to be the same as the non-focused Visual Studio colors.
 
You would also need to add handlers for WM_SETFOCUS and WM_KILLFOCUS that invalidated the control so that it was redrawn correctly.
Product: Xtreme ToolkitPro 2009 (13.4.1)
Platform: Windows 7 Ultimate(64bit)
Language: Visual Studio 2010 (C++)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 28 August 2009 at 10:56am
Right - this is not difficult.
See next post - we already have active and not active color combination.
Used in CXTPSyntaxEditPaintManager::DrawLineTextEx
with defaults:

m_clrValues.crHiliteText.SetStandardValue(::GetSysColor(COLOR_HIGHLIGHTTEXT));

m_clrValues.crHiliteBack.SetStandardValue(::GetSysColor(COLOR_HIGHLIGHT));

m_clrValues.crInactiveHiliteText.SetStandardValue(::GetSysColor(COLOR_INACTIVECAPTIONTEXT));

m_clrValues.crInactiveHiliteBack.SetStandardValue(::GetSysColor(COLOR_INACTIVECAPTION));

And function to switch:

if (!pEditCtrl->IsActive()) {

if (crHiliteBack == m_clrValues.crHiliteBack.GetStandardColor())

crHiliteBack = m_clrValues.crInactiveHiliteBack;

if (crHiliteText == m_clrValues.crHiliteText.GetStandardColor())

crHiliteText = m_clrValues.crInactiveHiliteText; }

So find why it does not covered your expectation - please debug your mutli-controls case with attention to this switch
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 28 August 2009 at 9:55pm

AFX_INLINE COLORREF CXTPSyntaxEditPaintManager::GetHiliteTextColor() const{ return m_clrValues.crHiliteText; }

AFX_INLINE COLORREF CXTPSyntaxEditPaintManager::GetHiliteBackColor() const { return m_clrValues.crHiliteBack; }

AFX_INLINE COLORREF CXTPSyntaxEditPaintManager::GetInactiveHiliteTextColor() const { return m_clrValues.crInactiveHiliteText; }

AFX_INLINE COLORREF CXTPSyntaxEditPaintManager::GetInactiveHiliteBackColor() const { return m_clrValues.crInactiveHiliteBack; }

Back to Top
robin_l View Drop Down
Senior Member
Senior Member


Joined: 15 October 2006
Status: Offline
Points: 117
Post Options Post Options   Thanks (0) Thanks(0)   Quote robin_l Quote  Post ReplyReply Direct Link To This Post Posted: 29 August 2009 at 9:10am
OK... now I'm beginning to understand! I assumed that as the highlighting was not indicating the focused (active) condition that the code didn't do this. Wrong... it does. What the problem is, however, is that the active state is never being set for a CXTPSyntaxEditCtrl so the selection state is ALWAYS the inactive highlight color. This isn't just a problem of my application--you were good enough to create a small sample app that used the CXTPSyntaxEditCtrl in a dialog--this also shows the same behaviour.
 
The active state is set via the OnActivate function call, but this seems never to happen. I can't detect any WM_ACTIVATE messages going to the control--I'm not even sure that dialog controls receive these. This means that the controls are never in the "active" state.
 
What DOES work, however, is to add message handlers for WM_SETFOCUS and WM_KILLFOCUS, and from these call SetActive(TRUE) and SetActive(FALSE). Perhaps you should add these for the CXTPSyntaxEditCtrl so that the syntax highlighting will work as designed?
Product: Xtreme ToolkitPro 2009 (13.4.1)
Platform: Windows 7 Ultimate(64bit)
Language: Visual Studio 2010 (C++)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 29 August 2009 at 9:51am

I am not sure that you are right - if you put breakpoint inside the CXTPSyntaxEditPaintManager code

if (!pEditCtrl->IsActive()) {...
you will see that it will break. Also flag pEditCtrl->m_bFocused exist and accessable from CXTPSyntaxEditPaintManager.
Back to Top
robin_l View Drop Down
Senior Member
Senior Member


Joined: 15 October 2006
Status: Offline
Points: 117
Post Options Post Options   Thanks (0) Thanks(0)   Quote robin_l Quote  Post ReplyReply Direct Link To This Post Posted: 29 August 2009 at 11:37am
It doesn't do so here. For example, run your "SyntaxEdit On Dialog" sample. This never shows anything but the non-active selection color (on my system at least):
 
 
If the syntax editor is used in a View, then everything is OK. For example, using the SyntaxEdit.MDITextEditor sample from the toolkit:
 
 
This shows the "correct" selection color (and the dull blue color when the application loses focus). It looks as if when the control is used in a dialog then it never receives the WM_ACTIVATE messages, so CXTPSyntaxEditCtrl::OnActivate is never called (though OnMouseActivate is).
 
The View version calls SetActive via a different route, via CXTPSyntaxEditView::OnActivateView, which does get called.
Product: Xtreme ToolkitPro 2009 (13.4.1)
Platform: Windows 7 Ultimate(64bit)
Language: Visual Studio 2010 (C++)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 29 August 2009 at 11:53am
Essentially this is proper behaviour - app should care about such things - control should not dictate it.
Back to Top
robin_l View Drop Down
Senior Member
Senior Member


Joined: 15 October 2006
Status: Offline
Points: 117
Post Options Post Options   Thanks (0) Thanks(0)   Quote robin_l Quote  Post ReplyReply Direct Link To This Post Posted: 29 August 2009 at 12:04pm
I have done now... by subclassing CXTPSyntaxEditCtrl so that WM_SETFOCUS calls SetActive(TRUE) and WM_KILLFOCUS calls SetActive(FALSE). I think it would be useful for other people if this was the default behaviour though.
Product: Xtreme ToolkitPro 2009 (13.4.1)
Platform: Windows 7 Ultimate(64bit)
Language: Visual Studio 2010 (C++)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 29 August 2009 at 12:09pm
We can add special flag CXTPSyntaxEditCtrl::m_bActivateOnFocus - so no need to subclassing - just set TRUE (let's default be FALSE as now - no activation) and expose the flag to ActiveX
Back to Top
robin_l View Drop Down
Senior Member
Senior Member


Joined: 15 October 2006
Status: Offline
Points: 117
Post Options Post Options   Thanks (0) Thanks(0)   Quote robin_l Quote  Post ReplyReply Direct Link To This Post Posted: 29 August 2009 at 12:12pm
Sounds good! Thanks!
Product: Xtreme ToolkitPro 2009 (13.4.1)
Platform: Windows 7 Ultimate(64bit)
Language: Visual Studio 2010 (C++)
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 29 August 2009 at 12:26pm
Done - for MFC and for ActiveX
e.g. in VB sample use
 
With SyntaxEdit1
  .SyntaxSet "[Schemes]" & vbCrLf & "VBS" & vbCrLf & "[Themes]" & vbCrLf & "Default" & vbCrLf & "Alternative" & vbCrLf
  .SyntaxScheme = sScheme2
  .DataManager.FileExt = ".vbs"
  .EnableEditAccelerators = True
  .Text = sText
  .ActivateOnFocus = True
End With
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.359 seconds.