aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2013-08-15 15:13:15 +1000
committerNeil <nyamatongwe@gmail.com>2013-08-15 15:13:15 +1000
commitd396f66bf0bc8d4c777c744efe77ccb5b28b385f (patch)
tree9dc0a355f751c37c953e835ac04a5dee383d6f51
parentc68e1a5ffc74569e4d406e3c904f010390577fcf (diff)
downloadscintilla-mirror-d396f66bf0bc8d4c777c744efe77ccb5b28b385f.tar.gz
Feature: [feature-requests:#1007]. Option to allow mouse selection to
switch to rectangular by pressing Alt after start of gesture. From Neomi.
-rw-r--r--cocoa/ScintillaCocoa.mm35
-rw-r--r--doc/ScintillaDoc.html14
-rw-r--r--doc/ScintillaHistory.html4
-rw-r--r--gtk/ScintillaGTK.cxx5
-rw-r--r--include/Scintilla.h2
-rw-r--r--include/Scintilla.iface6
-rw-r--r--qt/ScintillaEditBase/ScintillaEditBase.cpp15
-rw-r--r--src/Editor.cxx17
-rw-r--r--src/Editor.h2
-rw-r--r--win32/ScintillaWin.cxx5
10 files changed, 85 insertions, 20 deletions
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm
index 34e016d94..5c378c903 100644
--- a/cocoa/ScintillaCocoa.mm
+++ b/cocoa/ScintillaCocoa.mm
@@ -1838,6 +1838,24 @@ static inline UniChar KeyTranslate(UniChar unicodeChar)
//--------------------------------------------------------------------------------------------------
/**
+ * Translate NSEvent modifier flags into SCI_* modifier flags.
+ *
+ * @param modifiers An integer bit set of NSSEvent modifier flags.
+ * @return A set of SCI_* modifier flags.
+ */
+static int TranslateModifierFlags(NSUInteger modifiers)
+{
+ // Signal Control as SCI_META
+ return
+ (((modifiers & NSShiftKeyMask) != 0) ? SCI_SHIFT : 0) |
+ (((modifiers & NSCommandKeyMask) != 0) ? SCI_CTRL : 0) |
+ (((modifiers & NSAlternateKeyMask) != 0) ? SCI_ALT : 0) |
+ (((modifiers & NSControlKeyMask) != 0) ? SCI_META : 0);
+}
+
+//--------------------------------------------------------------------------------------------------
+
+/**
* Main keyboard input handling method. It is called for any key down event, including function keys,
* numeric keypad input and whatnot.
*
@@ -1847,15 +1865,8 @@ static inline UniChar KeyTranslate(UniChar unicodeChar)
bool ScintillaCocoa::KeyboardInput(NSEvent* event)
{
// For now filter out function keys.
- NSUInteger modifiers = [event modifierFlags];
-
NSString* input = [event characters];
- bool control = (modifiers & NSControlKeyMask) != 0;
- bool shift = (modifiers & NSShiftKeyMask) != 0;
- bool command = (modifiers & NSCommandKeyMask) != 0;
- bool alt = (modifiers & NSAlternateKeyMask) != 0;
-
bool handled = false;
// Handle each entry individually. Usually we only have one entry anway.
@@ -1866,13 +1877,7 @@ bool ScintillaCocoa::KeyboardInput(NSEvent* event)
bool consumed = false; // Consumed as command?
- // Signal Control as SCMOD_META
- int modifierKeys =
- (shift ? SCI_SHIFT : 0) |
- (command ? SCI_CTRL : 0) |
- (alt ? SCI_ALT : 0) |
- (control ? SCI_META : 0);
- if (KeyDownWithModifiers(key, modifierKeys, &consumed))
+ if (KeyDownWithModifiers(key, TranslateModifierFlags([event modifierFlags]), &consumed))
handled = true;
if (consumed)
handled = true;
@@ -1977,7 +1982,7 @@ void ScintillaCocoa::MouseMove(NSEvent* event)
{
lastMouseEvent = event;
- ButtonMove(ConvertPoint([event locationInWindow]));
+ ButtonMoveWithModifiers(ConvertPoint([event locationInWindow]), TranslateModifierFlags([event modifierFlags]));
}
//--------------------------------------------------------------------------------------------------
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index 723ddb025..57550bfe6 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -82,7 +82,7 @@
<h1>Scintilla Documentation</h1>
- <p>Last edited 29/June/2013 NH</p>
+ <p>Last edited 14/August/2013 NH</p>
<p>There is <a class="jump" href="Design.html">an overview of the internal design of
Scintilla</a>.<br />
@@ -1167,6 +1167,9 @@ struct Sci_TextToFind {
<a class="message" href="#SCI_CHOOSECARETX">SCI_CHOOSECARETX</a><br />
<a class="message" href="#SCI_MOVESELECTEDLINESUP">SCI_MOVESELECTEDLINESUP</a><br />
<a class="message" href="#SCI_MOVESELECTEDLINESDOWN">SCI_MOVESELECTEDLINESDOWN</a><br />
+ <a class="message" href="#SCI_SETMOUSESELECTIONRECTANGULARSWITCH">SCI_SETMOUSESELECTIONRECTANGULARSWITCH(bool
+ mouseSelectionRectangularSwitch)</a><br />
+ <a class="message" href="#SCI_GETMOUSESELECTIONRECTANGULARSWITCH">SCI_GETMOUSESELECTIONRECTANGULARSWITCH</a><br />
</code>
<p><b id="SCI_GETTEXTLENGTH">SCI_GETTEXTLENGTH</b><br />
@@ -1527,6 +1530,15 @@ struct Sci_TextToFind {
The selection will be automatically extended to the beginning of the selection's first line and the end of the seletion's last line.
If nothing was selected, the line the cursor is currently at will be selected.</p>
+ <p><b id="SCI_SETMOUSESELECTIONRECTANGULARSWITCH">SCI_SETMOUSESELECTIONRECTANGULARSWITCH(bool
+ mouseSelectionRectangularSwitch)</b><br />
+ <b id="SCI_GETMOUSESELECTIONRECTANGULARSWITCH">SCI_GETMOUSESELECTIONRECTANGULARSWITCH</b><br />
+ Enable or disable the ability to switch to rectangular selection mode while making a selection with the mouse.
+ When this option is turned on, mouse selections in stream mode can be switched to rectangular mode by pressing
+ the corresponding modifier key. They then stick to rectangular mode even when the modifier key is released again.
+ When this option is turned off, mouse selections will always stick to the mode the selection was started in. It
+ is off by default.</p>
+
<h2 id="MultipleSelectionAndVirtualSpace">Multiple Selection and Virtual Space</h2>
<code>
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index a041e9e18..098f5dcbe 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -452,6 +452,10 @@
In Unicode mode C1 control characters are represented by their mnemonics.
</li>
<li>
+ Option to allow mouse selection to switch to rectangular by pressing Alt after start of gesture.
+ <a href="http://sourceforge.net/p/scintilla/feature-requests/1007/">Feature #1007.</a>
+ </li>
+ <li>
Bash lexer fixed quoted HereDoc delimiters.
<a href="http://sourceforge.net/p/scintilla/bugs/1500/">Bug #1500</a>.
</li>
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx
index db9e1ea19..25d61d9f2 100644
--- a/gtk/ScintillaGTK.cxx
+++ b/gtk/ScintillaGTK.cxx
@@ -1962,7 +1962,10 @@ gint ScintillaGTK::Motion(GtkWidget *widget, GdkEventMotion *event) {
//Platform::DebugPrintf("Move %x %x %d %c %d %d\n",
// sciThis,event->window,event->time,event->is_hint? 'h' :'.', x, y);
Point pt(x, y);
- sciThis->ButtonMove(pt);
+ int modifiers = ((event->state & GDK_SHIFT_MASK) != 0 ? SCI_SHIFT : 0) |
+ ((event->state & GDK_CONTROL_MASK) != 0 ? SCI_CTRL : 0) |
+ ((event->state & modifierTranslated(sciThis->rectangularSelectionModifier)) != 0 ? SCI_ALT : 0);
+ sciThis->ButtonMoveWithModifiers(pt, modifiers);
} catch (...) {
sciThis->errorStatus = SC_STATUS_FAILURE;
}
diff --git a/include/Scintilla.h b/include/Scintilla.h
index 1a685172b..5bfcfc266 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -801,6 +801,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_ADDUNDOACTION 2560
#define SCI_CHARPOSITIONFROMPOINT 2561
#define SCI_CHARPOSITIONFROMPOINTCLOSE 2562
+#define SCI_SETMOUSESELECTIONRECTANGULARSWITCH 2668
+#define SCI_GETMOUSESELECTIONRECTANGULARSWITCH 2669
#define SCI_SETMULTIPLESELECTION 2563
#define SCI_GETMULTIPLESELECTION 2564
#define SCI_SETADDITIONALSELECTIONTYPING 2565
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index f0b47d519..f7880a035 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -2127,6 +2127,12 @@ fun position CharPositionFromPoint=2561(int x, int y)
# Return INVALID_POSITION if not close to text.
fun position CharPositionFromPointClose=2562(int x, int y)
+# Set whether switching to rectangular mode while selecting with the mouse is allowed.
+set void SetMouseSelectionRectangularSwitch=2668(bool mouseSelectionRectangularSwitch,)
+
+# Whether switching to rectangular mode while selecting with the mouse is allowed.
+get bool GetMouseSelectionRectangularSwitch=2669(,)
+
# Set whether multiple selections can be made
set void SetMultipleSelection=2563(bool multipleSelection,)
diff --git a/qt/ScintillaEditBase/ScintillaEditBase.cpp b/qt/ScintillaEditBase/ScintillaEditBase.cpp
index e5de593a8..37dc888e4 100644
--- a/qt/ScintillaEditBase/ScintillaEditBase.cpp
+++ b/qt/ScintillaEditBase/ScintillaEditBase.cpp
@@ -319,7 +319,20 @@ void ScintillaEditBase::mouseDoubleClickEvent(QMouseEvent *event)
void ScintillaEditBase::mouseMoveEvent(QMouseEvent *event)
{
Point pos = PointFromQPoint(event->pos());
- sqt->ButtonMove(pos);
+
+ bool shift = QApplication::keyboardModifiers() & Qt::ShiftModifier;
+ bool ctrl = QApplication::keyboardModifiers() & Qt::ControlModifier;
+#ifdef Q_WS_X11
+ // On X allow choice of rectangular modifier since most window
+ // managers grab alt + click for moving windows.
+ bool alt = QApplication::keyboardModifiers() & modifierTranslated(sqt->rectangularSelectionModifier);
+#else
+ bool alt = QApplication::keyboardModifiers() & Qt::AltModifier;
+#endif
+
+ int modifiers = (shift ? SCI_SHIFT : 0) | (ctrl ? SCI_CTRL : 0) | (alt ? SCI_ALT : 0);
+
+ sqt->ButtonMoveWithModifiers(pos, modifiers);
}
void ScintillaEditBase::contextMenuEvent(QContextMenuEvent *event)
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 45a88711f..3a30c52a4 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -169,6 +169,7 @@ Editor::Editor() {
endAtLastLine = true;
caretSticky = SC_CARETSTICKY_OFF;
marginOptions = SC_MARGINOPTION_NONE;
+ mouseSelectionRectangularSwitch = false;
multipleSelection = false;
additionalSelectionTyping = false;
multiPasteMode = SC_MULTIPASTE_ONCE;
@@ -6495,7 +6496,7 @@ void Editor::GetHotSpotRange(int &hsStart_, int &hsEnd_) const {
hsEnd_ = hsEnd;
}
-void Editor::ButtonMove(Point pt) {
+void Editor::ButtonMoveWithModifiers(Point pt, int modifiers) {
if ((ptMouseLast.x != pt.x) || (ptMouseLast.y != pt.y)) {
DwellEnd(true);
}
@@ -6529,6 +6530,9 @@ void Editor::ButtonMove(Point pt) {
SetDragPosition(movePos);
} else {
if (selectionType == selChar) {
+ if (sel.selType == Selection::selStream && (modifiers & SCI_ALT) && mouseSelectionRectangularSwitch) {
+ sel.selType = Selection::selRectangle;
+ }
if (sel.IsRectangular()) {
sel.Rectangular() = SelectionRange(movePos, sel.Rectangular().anchor);
SetSelection(movePos, sel.RangeMain().anchor);
@@ -6607,6 +6611,10 @@ void Editor::ButtonMove(Point pt) {
}
}
+void Editor::ButtonMove(Point pt) {
+ ButtonMoveWithModifiers(pt, 0);
+}
+
void Editor::ButtonUp(Point pt, unsigned int curTime, bool ctrl) {
//Platform::DebugPrintf("ButtonUp %d %d\n", HaveMouseCapture(), inDragDrop);
SelectionPosition newPos = SPositionFromLocation(pt, false, false,
@@ -9389,6 +9397,13 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
pdoc->AddUndoAction(wParam, lParam & UNDO_MAY_COALESCE);
break;
+ case SCI_SETMOUSESELECTIONRECTANGULARSWITCH:
+ mouseSelectionRectangularSwitch = wParam != 0;
+ break;
+
+ case SCI_GETMOUSESELECTIONRECTANGULARSWITCH:
+ return mouseSelectionRectangularSwitch;
+
case SCI_SETMULTIPLESELECTION:
multipleSelection = wParam != 0;
InvalidateCaret();
diff --git a/src/Editor.h b/src/Editor.h
index 54358a075..20877b29e 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -219,6 +219,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
bool endAtLastLine;
int caretSticky;
int marginOptions;
+ bool mouseSelectionRectangularSwitch;
bool multipleSelection;
bool additionalSelectionTyping;
int multiPasteMode;
@@ -566,6 +567,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
void DwellEnd(bool mouseMoved);
void MouseLeave();
virtual void ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt);
+ void ButtonMoveWithModifiers(Point pt, int modifiers);
void ButtonMove(Point pt);
void ButtonUp(Point pt, unsigned int curTime, bool ctrl);
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index 216334b17..c3222435e 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -897,7 +897,10 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam
case WM_MOUSEMOVE:
SetTrackMouseLeaveEvent(true);
- ButtonMove(Point::FromLong(lParam));
+ ButtonMoveWithModifiers(Point::FromLong(lParam),
+ ((wParam & MK_SHIFT) != 0 ? SCI_SHIFT : 0) |
+ ((wParam & MK_CONTROL) != 0 ? SCI_CTRL : 0) |
+ (Platform::IsKeyDown(VK_MENU) ? SCI_ALT : 0));
break;
case WM_MOUSELEAVE: