On wxGTK the Primary Selection is now set when something is selected

in wxSTC, and the middle mouse button will paste from the
PrimarySelection.  Regular Cut/Copy/Paste explicitly uses the normal
clipboard selection.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17797 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2002-11-10 00:53:30 +00:00
parent 58072c4313
commit ee29e26938
6 changed files with 76 additions and 20 deletions

View File

@@ -1942,6 +1942,7 @@ private:
void OnMouseMove(wxMouseEvent& evt); void OnMouseMove(wxMouseEvent& evt);
void OnMouseLeftUp(wxMouseEvent& evt); void OnMouseLeftUp(wxMouseEvent& evt);
void OnMouseRightUp(wxMouseEvent& evt); void OnMouseRightUp(wxMouseEvent& evt);
void OnMouseMiddleUp(wxMouseEvent& evt);
void OnContextMenu(wxContextMenuEvent& evt); void OnContextMenu(wxContextMenuEvent& evt);
void OnMouseWheel(wxMouseEvent& evt); void OnMouseWheel(wxMouseEvent& evt);
void OnChar(wxKeyEvent& evt); void OnChar(wxKeyEvent& evt);

View File

@@ -338,7 +338,7 @@ void ScintillaWX::Copy() {
SelectionText st; SelectionText st;
CopySelectionRange(&st); CopySelectionRange(&st);
if (wxTheClipboard->Open()) { if (wxTheClipboard->Open()) {
wxTheClipboard->UsePrimarySelection(); wxTheClipboard->UsePrimarySelection(FALSE);
wxString text = stc2wx(st.s, st.len); wxString text = stc2wx(st.s, st.len);
wxTheClipboard->SetData(new wxTextDataObject(text)); wxTheClipboard->SetData(new wxTextDataObject(text));
wxTheClipboard->Close(); wxTheClipboard->Close();
@@ -355,7 +355,7 @@ void ScintillaWX::Paste() {
bool gotData = FALSE; bool gotData = FALSE;
if (wxTheClipboard->Open()) { if (wxTheClipboard->Open()) {
wxTheClipboard->UsePrimarySelection(); wxTheClipboard->UsePrimarySelection(FALSE);
gotData = wxTheClipboard->GetData(data); gotData = wxTheClipboard->GetData(data);
wxTheClipboard->Close(); wxTheClipboard->Close();
} }
@@ -380,7 +380,7 @@ bool ScintillaWX::CanPaste() {
wxTheClipboard->Open(); wxTheClipboard->Open();
if (wxTheClipboard->IsOpened()) { if (wxTheClipboard->IsOpened()) {
wxTheClipboard->UsePrimarySelection(); wxTheClipboard->UsePrimarySelection(FALSE);
canPaste = wxTheClipboard->IsSupported(wxUSE_UNICODE ? wxDF_UNICODETEXT : wxDF_TEXT); canPaste = wxTheClipboard->IsSupported(wxUSE_UNICODE ? wxDF_UNICODETEXT : wxDF_TEXT);
if (didOpen) if (didOpen)
wxTheClipboard->Close(); wxTheClipboard->Close();
@@ -405,8 +405,22 @@ void ScintillaWX::AddToPopUp(const char *label, int cmd, bool enabled) {
} }
// This is called by the Editor base class whenever something is selected
void ScintillaWX::ClaimSelection() { void ScintillaWX::ClaimSelection() {
#ifdef __WXGTK__
// Put the selected text in the PRIMARY selection
if (currentPos != anchor) {
SelectionText st;
CopySelectionRange(&st);
if (wxTheClipboard->Open()) {
wxTheClipboard->UsePrimarySelection(TRUE);
wxString text = stc2wx(st.s, st.len);
wxTheClipboard->SetData(new wxTextDataObject(text));
wxTheClipboard->UsePrimarySelection(FALSE);
wxTheClipboard->Close();
}
}
#endif
} }
@@ -547,18 +561,49 @@ void ScintillaWX::DoSysColourChange() {
InvalidateStyleData(); InvalidateStyleData();
} }
void ScintillaWX::DoButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt) { void ScintillaWX::DoLeftButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt) {
ButtonDown(pt, curTime, shift, ctrl, alt); ButtonDown(pt, curTime, shift, ctrl, alt);
} }
void ScintillaWX::DoButtonUp(Point pt, unsigned int curTime, bool ctrl) { void ScintillaWX::DoLeftButtonUp(Point pt, unsigned int curTime, bool ctrl) {
ButtonUp(pt, curTime, ctrl); ButtonUp(pt, curTime, ctrl);
} }
void ScintillaWX::DoButtonMove(Point pt) { void ScintillaWX::DoLeftButtonMove(Point pt) {
ButtonMove(pt); ButtonMove(pt);
} }
void ScintillaWX::DoMiddleButtonUp(Point pt) {
#ifdef __WXGTK__
// Set the current position to the mouse click point and
// then paste in the PRIMARY selection, if any. wxGTK only.
int newPos = PositionFromLocation(pt);
MovePositionTo(newPos, 0, 1);
pdoc->BeginUndoAction();
wxTextDataObject data;
bool gotData = FALSE;
if (wxTheClipboard->Open()) {
wxTheClipboard->UsePrimarySelection(TRUE);
gotData = wxTheClipboard->GetData(data);
wxTheClipboard->UsePrimarySelection(FALSE);
wxTheClipboard->Close();
}
if (gotData) {
wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(data.GetText());
int len = strlen(buf);
pdoc->InsertString(currentPos, buf, len);
SetEmptySelection(currentPos + len);
}
pdoc->EndUndoAction();
NotifyChange();
Redraw();
ShowCaretAtCurrentPosition();
EnsureCaretVisible();
#endif
}
void ScintillaWX::DoAddChar(int key) { void ScintillaWX::DoAddChar(int key) {
#if wxUSE_UNICODE #if wxUSE_UNICODE

View File

@@ -122,9 +122,10 @@ public:
void DoLoseFocus(); void DoLoseFocus();
void DoGainFocus(); void DoGainFocus();
void DoSysColourChange(); void DoSysColourChange();
void DoButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt); void DoLeftButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt);
void DoButtonUp(Point pt, unsigned int curTime, bool ctrl); void DoLeftButtonUp(Point pt, unsigned int curTime, bool ctrl);
void DoButtonMove(Point pt); void DoLeftButtonMove(Point pt);
void DoMiddleButtonUp(Point pt);
void DoMouseWheel(int rotation, int delta, int linesPerAction, int ctrlDown, bool isPageScroll); void DoMouseWheel(int rotation, int delta, int linesPerAction, int ctrlDown, bool isPageScroll);
void DoAddChar(int key); void DoAddChar(int key);
int DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool* consumed); int DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool* consumed);

View File

@@ -90,10 +90,8 @@ BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl)
EVT_SCROLL (wxStyledTextCtrl::OnScroll) EVT_SCROLL (wxStyledTextCtrl::OnScroll)
EVT_SIZE (wxStyledTextCtrl::OnSize) EVT_SIZE (wxStyledTextCtrl::OnSize)
EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown) EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown)
#if defined(__WXMSW__) || defined(__WXMAC__)
// Let Scintilla see the double click as a second click // Let Scintilla see the double click as a second click
EVT_LEFT_DCLICK (wxStyledTextCtrl::OnMouseLeftDown) EVT_LEFT_DCLICK (wxStyledTextCtrl::OnMouseLeftDown)
#endif
EVT_MOTION (wxStyledTextCtrl::OnMouseMove) EVT_MOTION (wxStyledTextCtrl::OnMouseMove)
EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp) EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp)
#if defined(__WXGTK__) || defined(__WXMAC__) #if defined(__WXGTK__) || defined(__WXMAC__)
@@ -102,6 +100,7 @@ BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl)
EVT_CONTEXT_MENU (wxStyledTextCtrl::OnContextMenu) EVT_CONTEXT_MENU (wxStyledTextCtrl::OnContextMenu)
#endif #endif
EVT_MOUSEWHEEL (wxStyledTextCtrl::OnMouseWheel) EVT_MOUSEWHEEL (wxStyledTextCtrl::OnMouseWheel)
EVT_MIDDLE_UP (wxStyledTextCtrl::OnMouseMiddleUp)
EVT_CHAR (wxStyledTextCtrl::OnChar) EVT_CHAR (wxStyledTextCtrl::OnChar)
EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown) EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown)
EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus) EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus)
@@ -1959,18 +1958,18 @@ void wxStyledTextCtrl::OnSize(wxSizeEvent& evt) {
void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent& evt) { void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent& evt) {
SetFocus(); SetFocus();
wxPoint pt = evt.GetPosition(); wxPoint pt = evt.GetPosition();
m_swx->DoButtonDown(Point(pt.x, pt.y), m_stopWatch.Time(), m_swx->DoLeftButtonDown(Point(pt.x, pt.y), m_stopWatch.Time(),
evt.ShiftDown(), evt.ControlDown(), evt.AltDown()); evt.ShiftDown(), evt.ControlDown(), evt.AltDown());
} }
void wxStyledTextCtrl::OnMouseMove(wxMouseEvent& evt) { void wxStyledTextCtrl::OnMouseMove(wxMouseEvent& evt) {
wxPoint pt = evt.GetPosition(); wxPoint pt = evt.GetPosition();
m_swx->DoButtonMove(Point(pt.x, pt.y)); m_swx->DoLeftButtonMove(Point(pt.x, pt.y));
} }
void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent& evt) { void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent& evt) {
wxPoint pt = evt.GetPosition(); wxPoint pt = evt.GetPosition();
m_swx->DoButtonUp(Point(pt.x, pt.y), m_stopWatch.Time(), m_swx->DoLeftButtonUp(Point(pt.x, pt.y), m_stopWatch.Time(),
evt.ControlDown()); evt.ControlDown());
} }
@@ -1981,6 +1980,11 @@ void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent& evt) {
} }
void wxStyledTextCtrl::OnMouseMiddleUp(wxMouseEvent& evt) {
wxPoint pt = evt.GetPosition();
m_swx->DoMiddleButtonUp(Point(pt.x, pt.y));
}
void wxStyledTextCtrl::OnContextMenu(wxContextMenuEvent& evt) { void wxStyledTextCtrl::OnContextMenu(wxContextMenuEvent& evt) {
wxPoint pt = evt.GetPosition(); wxPoint pt = evt.GetPosition();
ScreenToClient(&pt.x, &pt.y); ScreenToClient(&pt.x, &pt.y);

View File

@@ -90,10 +90,8 @@ BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl)
EVT_SCROLL (wxStyledTextCtrl::OnScroll) EVT_SCROLL (wxStyledTextCtrl::OnScroll)
EVT_SIZE (wxStyledTextCtrl::OnSize) EVT_SIZE (wxStyledTextCtrl::OnSize)
EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown) EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown)
#if defined(__WXMSW__) || defined(__WXMAC__)
// Let Scintilla see the double click as a second click // Let Scintilla see the double click as a second click
EVT_LEFT_DCLICK (wxStyledTextCtrl::OnMouseLeftDown) EVT_LEFT_DCLICK (wxStyledTextCtrl::OnMouseLeftDown)
#endif
EVT_MOTION (wxStyledTextCtrl::OnMouseMove) EVT_MOTION (wxStyledTextCtrl::OnMouseMove)
EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp) EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp)
#if defined(__WXGTK__) || defined(__WXMAC__) #if defined(__WXGTK__) || defined(__WXMAC__)
@@ -102,6 +100,7 @@ BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl)
EVT_CONTEXT_MENU (wxStyledTextCtrl::OnContextMenu) EVT_CONTEXT_MENU (wxStyledTextCtrl::OnContextMenu)
#endif #endif
EVT_MOUSEWHEEL (wxStyledTextCtrl::OnMouseWheel) EVT_MOUSEWHEEL (wxStyledTextCtrl::OnMouseWheel)
EVT_MIDDLE_UP (wxStyledTextCtrl::OnMouseMiddleUp)
EVT_CHAR (wxStyledTextCtrl::OnChar) EVT_CHAR (wxStyledTextCtrl::OnChar)
EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown) EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown)
EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus) EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus)
@@ -337,18 +336,18 @@ void wxStyledTextCtrl::OnSize(wxSizeEvent& evt) {
void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent& evt) { void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent& evt) {
SetFocus(); SetFocus();
wxPoint pt = evt.GetPosition(); wxPoint pt = evt.GetPosition();
m_swx->DoButtonDown(Point(pt.x, pt.y), m_stopWatch.Time(), m_swx->DoLeftButtonDown(Point(pt.x, pt.y), m_stopWatch.Time(),
evt.ShiftDown(), evt.ControlDown(), evt.AltDown()); evt.ShiftDown(), evt.ControlDown(), evt.AltDown());
} }
void wxStyledTextCtrl::OnMouseMove(wxMouseEvent& evt) { void wxStyledTextCtrl::OnMouseMove(wxMouseEvent& evt) {
wxPoint pt = evt.GetPosition(); wxPoint pt = evt.GetPosition();
m_swx->DoButtonMove(Point(pt.x, pt.y)); m_swx->DoLeftButtonMove(Point(pt.x, pt.y));
} }
void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent& evt) { void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent& evt) {
wxPoint pt = evt.GetPosition(); wxPoint pt = evt.GetPosition();
m_swx->DoButtonUp(Point(pt.x, pt.y), m_stopWatch.Time(), m_swx->DoLeftButtonUp(Point(pt.x, pt.y), m_stopWatch.Time(),
evt.ControlDown()); evt.ControlDown());
} }
@@ -359,6 +358,11 @@ void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent& evt) {
} }
void wxStyledTextCtrl::OnMouseMiddleUp(wxMouseEvent& evt) {
wxPoint pt = evt.GetPosition();
m_swx->DoMiddleButtonUp(Point(pt.x, pt.y));
}
void wxStyledTextCtrl::OnContextMenu(wxContextMenuEvent& evt) { void wxStyledTextCtrl::OnContextMenu(wxContextMenuEvent& evt) {
wxPoint pt = evt.GetPosition(); wxPoint pt = evt.GetPosition();
ScreenToClient(&pt.x, &pt.y); ScreenToClient(&pt.x, &pt.y);

View File

@@ -184,6 +184,7 @@ private:
void OnMouseMove(wxMouseEvent& evt); void OnMouseMove(wxMouseEvent& evt);
void OnMouseLeftUp(wxMouseEvent& evt); void OnMouseLeftUp(wxMouseEvent& evt);
void OnMouseRightUp(wxMouseEvent& evt); void OnMouseRightUp(wxMouseEvent& evt);
void OnMouseMiddleUp(wxMouseEvent& evt);
void OnContextMenu(wxContextMenuEvent& evt); void OnContextMenu(wxContextMenuEvent& evt);
void OnMouseWheel(wxMouseEvent& evt); void OnMouseWheel(wxMouseEvent& evt);
void OnChar(wxKeyEvent& evt); void OnChar(wxKeyEvent& evt);