X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/61a6d4c23a509f1e26d01e9f80e7fd9629cda05d..3da93aae505563c359f58b357e6c79cd117c5320:/samples/richedit/wxlwindow.cpp diff --git a/samples/richedit/wxlwindow.cpp b/samples/richedit/wxlwindow.cpp index 441d5a28cc..0993e2ca99 100644 --- a/samples/richedit/wxlwindow.cpp +++ b/samples/richedit/wxlwindow.cpp @@ -88,8 +88,6 @@ static const int Y_SCROLL_PAGE = 20; -#define wxUSE_PRIVATE_CLIPBOARD_FORMAT 0 - // ---------------------------------------------------------------------------- // event tables // ---------------------------------------------------------------------------- @@ -496,21 +494,18 @@ wxLayoutWindow::OnChar(wxKeyEvent& event) if ( IsDirectionKey(keyCode) ) { // just continue the old selection - if ( m_Selecting ) + if ( m_Selecting && event.ShiftDown() ) + m_llist->ContinueSelection(); + else { + m_llist->DiscardSelection(); + m_Selecting = false; if( event.ShiftDown() ) - m_llist->ContinueSelection(); - else { - m_llist->DiscardSelection(); - m_Selecting = false; + m_Selecting = true; + m_llist->StartSelection(); } } - else if( event.ShiftDown() ) - { - m_Selecting = true; - m_llist->StartSelection(); - } } // If needed, make cursor visible: @@ -567,7 +562,7 @@ wxLayoutWindow::OnChar(wxKeyEvent& event) { case 'c': // this should work even in read-only mode - Copy(); + Copy(TRUE, TRUE); break; case 's': // search Find(""); @@ -631,8 +626,11 @@ wxLayoutWindow::OnChar(wxKeyEvent& event) m_llist->DeleteToEndOfLine(); SetDirty(); break; + case 'c': + Copy(TRUE, TRUE); + break; case 'v': - Paste(); + Paste( TRUE ); break; case 'x': Cut(); @@ -716,8 +714,15 @@ wxLayoutWindow::OnChar(wxKeyEvent& event) ) { if(m_WrapMargin > 0 && isspace(keyCode)) - m_llist->WrapLine(m_WrapMargin); - m_llist->Insert((char)keyCode); + { + bool wrapped = m_llist->WrapLine(m_WrapMargin); + // donĀ“t insert space as first thing in line + // after wrapping: + if(! wrapped || m_llist->GetCursorPos().x != 0) + m_llist->Insert((char)keyCode); + } + else + m_llist->Insert((char)keyCode); SetDirty(); } else @@ -1070,24 +1075,47 @@ wxLayoutWindow::ResizeScrollbars(bool exact) // ---------------------------------------------------------------------------- void -wxLayoutWindow::Paste(bool primary) +wxLayoutWindow::Paste(bool usePrivate, bool primary) { // this only has an effect under X11: - if(primary) wxTheClipboard->UsePrimarySelection(); + wxTheClipboard->UsePrimarySelection(primary); // Read some text if (wxTheClipboard->Open()) { -#if wxUSE_PRIVATE_CLIPBOARD_FORMAT - wxLayoutDataObject wxldo; - if (wxTheClipboard->IsSupported( wxldo.GetFormat() )) + if(usePrivate) { - wxTheClipboard->GetData(wxldo); + wxLayoutDataObject wxldo; + if (wxTheClipboard->IsSupported( wxldo.GetFormat() )) { + if(wxTheClipboard->GetData(wxldo)) + { + wxTheClipboard->Close(); + wxString str = wxldo.GetLayoutData(); + m_llist->Read(str); + SetDirty(); + RequestUpdate(); + return; + } } - //FIXME: missing functionality m_llist->Insert(wxldo.GetList()); } - else -#endif + wxTextDataObject data; + if (wxTheClipboard->IsSupported( data.GetFormat() ) + && wxTheClipboard->GetData(data) ) + { + wxTheClipboard->Close(); + wxString text = data.GetText(); + wxLayoutImportText( m_llist, text); + SetDirty(); + RequestUpdate(); + return; + } + } + // if everything failed we can still try the primary: + wxTheClipboard->Close(); + if(! primary) // not tried before + { + wxTheClipboard->UsePrimarySelection(); + if (wxTheClipboard->Open()) { wxTextDataObject data; if (wxTheClipboard->IsSupported( data.GetFormat() ) @@ -1096,14 +1124,15 @@ wxLayoutWindow::Paste(bool primary) wxString text = data.GetText(); wxLayoutImportText( m_llist, text); SetDirty(); + RequestUpdate(); } + wxTheClipboard->Close(); } - wxTheClipboard->Close(); } } bool -wxLayoutWindow::Copy(bool invalidate) +wxLayoutWindow::Copy(bool invalidate, bool privateFormat, bool primary) { // Calling GetSelection() will automatically do an EndSelection() // on the list, but we need to take a note of it, too: @@ -1113,8 +1142,8 @@ wxLayoutWindow::Copy(bool invalidate) m_llist->EndSelection(); } - wxLayoutDataObject wldo; - wxLayoutList *llist = m_llist->GetSelection(&wldo, invalidate); + wxLayoutDataObject *wldo = new wxLayoutDataObject; + wxLayoutList *llist = m_llist->GetSelection(wldo, invalidate); if(! llist) return FALSE; // Export selection as text: @@ -1139,24 +1168,41 @@ wxLayoutWindow::Copy(bool invalidate) text = text.Mid(0,len-1); } +#if 0 +if(! primary) // always copy as text-only to primary selection + { + wxTheClipboard->UsePrimarySelection(); + if (wxTheClipboard->Open()) + { + wxTextDataObject *data = new wxTextDataObject( text ); + wxTheClipboard->SetData( data ); + wxTheClipboard->Close(); + } + } +#endif + + wxTheClipboard->UsePrimarySelection(primary); if (wxTheClipboard->Open()) { wxTextDataObject *data = new wxTextDataObject( text ); - bool rc = wxTheClipboard->SetData( data ); -#if wxUSE_PRIVATE_CLIPBOARD_FORMAT - rc |= wxTheClipboard->AddData( &wldo ); -#endif + bool rc; + + rc = wxTheClipboard->SetData( data ); + if(privateFormat) + rc |= wxTheClipboard->SetData( wldo ); wxTheClipboard->Close(); return rc; } + else + delete wldo; return FALSE; } bool -wxLayoutWindow::Cut(void) +wxLayoutWindow::Cut(bool privateFormat, bool usePrimary) { - if(Copy(false)) // do not invalidate selection after copy + if(Copy(false, privateFormat, usePrimary)) // do not invalidate selection after copy { m_llist->DeleteSelection(); SetDirty();