Author Topic: Highlight disappears when using mouse drag scroll with right key  (Read 8058 times)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Highlight disappears when using mouse drag scroll with right key
« Reply #15 on: September 07, 2018, 11:55:01 pm »
You're missing frames. Type bt in the debugger console to see the real reason why this has happened.
But if your source code is the same as mine - there is either updateui or paint event causing this. :(
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Highlight disappears when using mouse drag scroll with right key
« Reply #16 on: September 08, 2018, 12:03:56 am »
Ok... found something:
in sdk/wxsintilla/src/scintillawx.cpp:1071
Code
void ScintillaWX::DoRightButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt) {
    if (!PointInSelection(pt)) {
        CancelModes();
        SetEmptySelection(PositionFromLocation(pt));
    }

    RightButtonDownWithModifiers(pt, curTime, ModifierFlags(shift, ctrl, alt));
}
the selection is set to empty...

this seems to be a bug, but why does it work on linux? For me there should be a DoRightButtonUp...

[EDIT:]
This was introduced in the update to 3.7.2: https://github.com/wxWidgets/wxWidgets/pull/409/commits/2da2b9339663e5df2eaf03eaa444953d4425ca0a#diff-dea3c61f771e11ad01faf0c2c35da760
« Last Edit: September 08, 2018, 12:56:06 am by BlueHazzard »

Offline New Pagodi

  • Multiple posting newcomer
  • *
  • Posts: 41
Re: Highlight disappears when using mouse drag scroll with right key
« Reply #17 on: September 08, 2018, 01:26:32 am »
I'm pretty sure I did this.  To the best of my recollection, the right mouse stuff was added in order to be able to handle the new MARGIN_RIGHT_CLICK notification that was added between whatever the previous version of Scintilla was and 3.72.

I think that function was basically adapted for the wx Platform from the windows platform code included with the Scintilla source
(ScintillaWin.cxx lines 1421-1433) and looks like this:

Code
sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
...
case WM_RBUTTONDOWN: {
::SetFocus(MainHWND());
Point pt = Point::FromLong(static_cast<long>(lParam));
if (!PointInSelection(pt)) {
CancelModes();
SetEmptySelection(PositionFromLocation(Point::FromLong(static_cast<long>(lParam))));
}

RightButtonDownWithModifiers(pt, ::GetMessageTime(), ModifierFlags((wParam & MK_SHIFT) != 0,
      (wParam & MK_CONTROL) != 0,
      Platform::IsKeyDown(VK_MENU)));
}
break;

The code for the GTK+ platform is similar (ScintillaGTK.cxx lines 1703-1724)

Code
		
gint ScintillaGTK::PressThis(GdkEventButton *event) {
....
} else if (event->button == 3) {
if (!PointInSelection(pt))
SetEmptySelection(PositionFromLocation(pt));
if (ShouldDisplayPopup(pt)) {
// PopUp menu
// Convert to screen
int ox = 0;
int oy = 0;
gdk_window_get_origin(PWindow(wMain), &ox, &oy);
ContextMenu(Point(pt.x + ox, pt.y + oy));
} else {
#if PLAT_GTK_MACOSX
bool meta = ctrl;
// GDK reports the Command modifer key as GDK_MOD2_MASK for button events,
// not GDK_META_MASK like in key events.
ctrl = (event->state & GDK_MOD2_MASK) != 0;
#else
bool meta = false;
#endif
RightButtonDownWithModifiers(pt, event->time, ModifierFlags(shift, ctrl, alt, meta));
return FALSE;
}

So I think the code from scintillawx.cpp is an accurate translation of the intended Scintilla behavior to the wx world.  It's just that it was lacking before because no one had handled the right down event prior to updating to 3.72 because nothing else used by wxSTC needed it.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Highlight disappears when using mouse drag scroll with right key
« Reply #18 on: September 08, 2018, 01:40:28 am »
Quote
I'm pretty sure I did this.  To the best of my recollection, the right mouse stuff was added in order to be able to handle the new MARGIN_RIGHT_CLICK notification that was added between whatever the previous version of Scintilla was and 3.72.
i am really not into the Scintilla code. And i don't know what the MARGIN_RIGHT_CLICK  is used for, and if codeblocks uses it. It is quite late now and i wanted to test this so i made this quick and DIRTY patch against the codeblocks code. So far all seems to work as it should.. I can right click without deleting the selection and for this the scrolling works as expected... I can right click and i get all context menus as expected (as far as i was able to test)...

Code
diff --git a/src/sdk/wxscintilla/src/ScintillaWX.cpp b/src/sdk/wxscintilla/src/ScintillaWX.cpp
index 4a56368f1..6ed963fe4 100644
--- a/src/sdk/wxscintilla/src/ScintillaWX.cpp
+++ b/src/sdk/wxscintilla/src/ScintillaWX.cpp
@@ -1069,12 +1069,14 @@ void ScintillaWX::DoLeftButtonDown(Point pt, unsigned int curTime, bool shift, b
 }
 
 void ScintillaWX::DoRightButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt) {
+    RightButtonDownWithModifiers(pt, curTime, ModifierFlags(shift, ctrl, alt));
+}
+
+void ScintillaWX::DoRightButtonUp(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt) {
     if (!PointInSelection(pt)) {
         CancelModes();
         SetEmptySelection(PositionFromLocation(pt));
     }
-
-    RightButtonDownWithModifiers(pt, curTime, ModifierFlags(shift, ctrl, alt));
 }
 
 void ScintillaWX::DoLeftButtonUp(Point pt, unsigned int curTime, bool ctrl) {
diff --git a/src/sdk/wxscintilla/src/ScintillaWX.h b/src/sdk/wxscintilla/src/ScintillaWX.h
index dae8d453d..ff8a1fd5e 100644
--- a/src/sdk/wxscintilla/src/ScintillaWX.h
+++ b/src/sdk/wxscintilla/src/ScintillaWX.h
@@ -173,6 +173,7 @@ public:
     void DoSysColourChange();
     void DoLeftButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt);
     void DoRightButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt);
+    void DoRightButtonUp(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt);
     void DoLeftButtonUp(Point pt, unsigned int curTime, bool ctrl);
     void DoLeftButtonMove(Point pt);
     void DoMiddleButtonUp(Point pt);
diff --git a/src/sdk/wxscintilla/src/wxscintilla.cpp b/src/sdk/wxscintilla/src/wxscintilla.cpp
index 9c86ae0e5..50ae43d6e 100644
--- a/src/sdk/wxscintilla/src/wxscintilla.cpp
+++ b/src/sdk/wxscintilla/src/wxscintilla.cpp
@@ -5305,6 +5305,8 @@ void wxScintilla::OnMouseLeftUp(wxMouseEvent& evt) {
 
 void wxScintilla::OnMouseRightUp(wxMouseEvent& evt) {
     wxPoint pt = evt.GetPosition();
+    m_swx->DoRightButtonUp(Point(pt.x, pt.y), m_stopWatch.Time(),
+                      evt.ShiftDown(), evt.ControlDown(), evt.AltDown());
     m_swx->DoContextMenu(Point(pt.x, pt.y));
 }
 

I really have not looked deep into the code to see what the functions do... so no guarantee for whatever...

Offline Quiss

  • Multiple posting newcomer
  • *
  • Posts: 76
Re: Highlight disappears when using mouse drag scroll with right key
« Reply #19 on: September 10, 2018, 08:26:09 am »
@BlueHazzard

I applied your patch on svn11454. I've been using it since then and it's ok. Thank you.

MARGIN_RIGHT_CLICK event defined in wxscintilla.cpp (line: 131) but never used.

Edit: Ok, there is a commit for DragScroll (svn11455 actually), it fixes the issue without modifying wxscintilla: https://github.com/obfuscated/codeblocks_sf/commit/40e313df4f7ffd7d4bcdb9bdc538e1377c1e2717

That's probably why oBFusCATed can't reproduce the issue in the first place.
« Last Edit: September 10, 2018, 10:07:49 am by Quiss »