Browse Source

Shift click text selection

Josh Engebretson 11 years ago
parent
commit
30dceb247e

+ 47 - 23
Source/Atomic/UI/TBUI.cpp

@@ -49,6 +49,26 @@ namespace Atomic
 
 
 extern const char* UI_CATEGORY;
 extern const char* UI_CATEGORY;
 
 
+static MODIFIER_KEYS GetModifierKeys(int qualifiers, bool superKey)
+{
+    MODIFIER_KEYS code = TB_MODIFIER_NONE;
+    if (qualifiers & QUAL_ALT)	code |= TB_ALT;
+    if (qualifiers & QUAL_CTRL)	code |= TB_CTRL;
+    if (qualifiers & QUAL_SHIFT)	code |= TB_SHIFT;
+    if (superKey)	code |= TB_SUPER;
+    return code;
+}
+
+
+// @return Return the upper case of a ascii charcter. Only for shortcut handling.
+static int toupr_ascii(int ascii)
+{
+    if (ascii >= 'a' && ascii <= 'z')
+        return ascii + 'A' - 'a';
+    return ascii;
+}
+
+
 class TBUIRenderer;
 class TBUIRenderer;
 
 
 class TBUIBitmap : public tb::TBBitmap
 class TBUIBitmap : public tb::TBBitmap
@@ -353,6 +373,18 @@ void TBUI::HandleMouseButtonDown(StringHash eventType, VariantMap& eventData)
     IntVector2 pos;
     IntVector2 pos;
     pos = GetSubsystem<UI>()->GetCursorPosition();
     pos = GetSubsystem<UI>()->GetCursorPosition();
 
 
+    Input* input = GetSubsystem<Input>();
+    int qualifiers = input->GetQualifiers();
+
+#ifdef ATOMIC_PLATFORM_WINDOWS
+    bool superdown = input->GetKeyDown(KEY_LCTRL) || input->GetKeyDown(KEY_RCTRL);
+#else
+    bool superdown = input->GetKeyDown(KEY_LGUI) || input->GetKeyDown(KEY_RGUI);
+#endif
+
+    MODIFIER_KEYS mod = GetModifierKeys(qualifiers, superdown);
+
+
     static double last_time = 0;
     static double last_time = 0;
     static int counter = 1;
     static int counter = 1;
 
 
@@ -366,9 +398,9 @@ void TBUI::HandleMouseButtonDown(StringHash eventType, VariantMap& eventData)
 
 
     last_time = time;
     last_time = time;
     if (button == MOUSEB_RIGHT)
     if (button == MOUSEB_RIGHT)
-        rootWidget_->InvokeRightPointerDown(pos.x_, pos.y_, counter, tb::TB_MODIFIER_NONE);
+        rootWidget_->InvokeRightPointerDown(pos.x_, pos.y_, counter, mod);
     else
     else
-        rootWidget_->InvokePointerDown(pos.x_, pos.y_, counter, tb::TB_MODIFIER_NONE, false);
+        rootWidget_->InvokePointerDown(pos.x_, pos.y_, counter, mod, false);
 
 
 
 
 }
 }
@@ -384,11 +416,22 @@ void TBUI::HandleMouseButtonUp(StringHash eventType, VariantMap& eventData)
 
 
     IntVector2 pos;
     IntVector2 pos;
     pos = GetSubsystem<UI>()->GetCursorPosition();
     pos = GetSubsystem<UI>()->GetCursorPosition();
+    Input* input = GetSubsystem<Input>();
+    int qualifiers = input->GetQualifiers();
+
+#ifdef ATOMIC_PLATFORM_WINDOWS
+    bool superdown = input->GetKeyDown(KEY_LCTRL) || input->GetKeyDown(KEY_RCTRL);
+#else
+    bool superdown = input->GetKeyDown(KEY_LGUI) || input->GetKeyDown(KEY_RGUI);
+#endif
+
+    MODIFIER_KEYS mod = GetModifierKeys(qualifiers, superdown);
+
 
 
     if (button == MOUSEB_RIGHT)
     if (button == MOUSEB_RIGHT)
-        rootWidget_->InvokeRightPointerUp(pos.x_, pos.y_, tb::TB_MODIFIER_NONE);
+        rootWidget_->InvokeRightPointerUp(pos.x_, pos.y_, mod);
     else
     else
-        rootWidget_->InvokePointerUp(pos.x_, pos.y_, tb::TB_MODIFIER_NONE, false);
+        rootWidget_->InvokePointerUp(pos.x_, pos.y_, mod, false);
 }
 }
 
 
 
 
@@ -422,25 +465,6 @@ void TBUI::HandleMouseWheel(StringHash eventType, VariantMap& eventData)
 
 
 }
 }
 
 
-static MODIFIER_KEYS GetModifierKeys(int qualifiers, bool superKey)
-{
-    MODIFIER_KEYS code = TB_MODIFIER_NONE;
-    if (qualifiers & QUAL_ALT)	code |= TB_ALT;
-    if (qualifiers & QUAL_CTRL)	code |= TB_CTRL;
-    if (qualifiers & QUAL_SHIFT)	code |= TB_SHIFT;
-    if (superKey)	code |= TB_SUPER;
-    return code;
-}
-
-
-// @return Return the upper case of a ascii charcter. Only for shortcut handling.
-static int toupr_ascii(int ascii)
-{
-    if (ascii >= 'a' && ascii <= 'z')
-        return ascii + 'A' - 'a';
-    return ascii;
-}
-
 static bool InvokeShortcut(int key, SPECIAL_KEY special_key, MODIFIER_KEYS modifierkeys, bool down)
 static bool InvokeShortcut(int key, SPECIAL_KEY special_key, MODIFIER_KEYS modifierkeys, bool down)
 {
 {
 #ifdef __APPLE__
 #ifdef __APPLE__

+ 2 - 2
Source/ThirdParty/TurboBadger/tb_editfield.cpp

@@ -222,7 +222,7 @@ bool TBEditField::OnEvent(const TBWidgetEvent &ev)
 		TBRect padding_rect = GetPaddingRect();
 		TBRect padding_rect = GetPaddingRect();
 		if (m_style_edit.MouseDown(
 		if (m_style_edit.MouseDown(
 			TBPoint(ev.target_x - padding_rect.x, ev.target_y - padding_rect.y),
 			TBPoint(ev.target_x - padding_rect.x, ev.target_y - padding_rect.y),
-			1, ev.count, TB_MODIFIER_NONE, ev.touch))
+            1, ev.count, ev.modifierkeys, ev.touch))
 		{
 		{
 			// Post a message to start selection scroll
 			// Post a message to start selection scroll
 			PostMessageDelayed(TBIDC("selscroll"), nullptr, SELECTION_SCROLL_DELAY);
 			PostMessageDelayed(TBIDC("selscroll"), nullptr, SELECTION_SCROLL_DELAY);
@@ -238,7 +238,7 @@ bool TBEditField::OnEvent(const TBWidgetEvent &ev)
 	{
 	{
 		TBRect padding_rect = GetPaddingRect();
 		TBRect padding_rect = GetPaddingRect();
 		return m_style_edit.MouseUp(TBPoint(ev.target_x - padding_rect.x, ev.target_y - padding_rect.y),
 		return m_style_edit.MouseUp(TBPoint(ev.target_x - padding_rect.x, ev.target_y - padding_rect.y),
-										1, TB_MODIFIER_NONE, ev.touch);
+                                        1, ev.modifierkeys, ev.touch);
 	}
 	}
 	else if (ev.type == EVENT_TYPE_KEY_DOWN)
 	else if (ev.type == EVENT_TYPE_KEY_DOWN)
 	{
 	{

+ 9 - 4
Source/ThirdParty/TurboBadger/tb_style_edit.cpp

@@ -1944,10 +1944,15 @@ bool TBStyleEdit::MouseDown(const TBPoint &point, int button, int clicks, MODIFI
 	}
 	}
 	else if (packed.selection_on)
 	else if (packed.selection_on)
 	{
 	{
-		//if (modifierkeys & P_SHIFT) // Select to new caretpos
-		//{
-		//}
-		//else // Start selection
+        if (modifierkeys & TB_SHIFT) // Select to new caretpos
+        {
+            mousedown_fragment = nullptr;
+            mousedown_point = TBPoint(point.x + scroll_x, point.y + scroll_y);
+            TBTextOfs old_caret_pos = caret.pos;
+            caret.Place(mousedown_point);
+            selection.SelectToCaret(old_caret_pos.block, old_caret_pos.ofs);
+        }
+        else // Start selection
 		{
 		{
 			mousedown_point = TBPoint(point.x + scroll_x, point.y + scroll_y);
 			mousedown_point = TBPoint(point.x + scroll_x, point.y + scroll_y);
 			selection.SelectNothing();
 			selection.SelectNothing();