CXTPSyntaxEditCtrl selection highlight |
Post Reply |
Author | ||
robin_l
Senior Member Joined: 15 October 2006 Status: Offline Points: 117 |
Post Options
Thanks(0)
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++) |
||
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
|
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?
|
||
robin_l
Senior Member Joined: 15 October 2006 Status: Offline Points: 117 |
Post Options
Thanks(0)
|
|
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++) |
||
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
|
Make sense if I will have some extra time. But even this way not indicate you which of Syntax controls is active Now - right?
|
||
robin_l
Senior Member Joined: 15 October 2006 Status: Offline Points: 117 |
Post Options
Thanks(0)
|
|
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:
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++) |
||
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
|
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 |
||
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
|
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; } |
||
robin_l
Senior Member Joined: 15 October 2006 Status: Offline Points: 117 |
Post Options
Thanks(0)
|
|
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++) |
||
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
|
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.
|
||
robin_l
Senior Member Joined: 15 October 2006 Status: Offline Points: 117 |
Post Options
Thanks(0)
|
|
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++) |
||
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
|
Essentially this is proper behaviour - app should care about such things - control should not dictate it.
|
||
robin_l
Senior Member Joined: 15 October 2006 Status: Offline Points: 117 |
Post Options
Thanks(0)
|
|
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++) |
||
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
|
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
|
||
robin_l
Senior Member Joined: 15 October 2006 Status: Offline Points: 117 |
Post Options
Thanks(0)
|
|
Sounds good! Thanks!
|
||
Product: Xtreme ToolkitPro 2009 (13.4.1)
Platform: Windows 7 Ultimate(64bit) Language: Visual Studio 2010 (C++) |
||
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
|
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 |
||
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |