From: Karsten Ballüder Date: Mon, 15 Nov 1999 21:15:25 +0000 (+0000) Subject: private dataformat almost working - minor fixes X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/329e50732b3a203eecd808d91b2191cb630843fd private dataformat almost working - minor fixes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4583 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/samples/richedit/wxllist.cpp b/samples/richedit/wxllist.cpp index 94e81f7d7b..32224783f2 100644 --- a/samples/richedit/wxllist.cpp +++ b/samples/richedit/wxllist.cpp @@ -1568,6 +1568,18 @@ wxLayoutList::InternalClear(void) m_CursorStyleInfo = m_DefaultStyleInfo; } +void +wxLayoutList::Read(wxString &istr) +{ + while(istr.Length()) + { + wxLayoutObject *obj = wxLayoutObject::Read(istr); + if(obj) + Insert(obj); + } +} + + void wxLayoutList::SetFont(int family, int size, int style, int weight, int underline, wxColour *fg, @@ -2352,15 +2364,10 @@ wxLayoutList::Draw(wxDC &dc, } InvalidateUpdateRect(); -#ifdef DEBUG - if ( m_Selection.m_valid ) - { - WXLO_DEBUG(("Selection is %s : %ld,%ld/%ld,%ld", - m_Selection.m_valid ? "valid" : "invalid", - m_Selection.m_CursorA.x, m_Selection.m_CursorA.y, - m_Selection.m_CursorB.x, m_Selection.m_CursorB.y)); - } -#endif + WXLO_DEBUG(("Selection is %s : l%d,%ld/%ld,%ld", + m_Selection.m_valid ? "valid" : "invalid", + m_Selection.m_CursorA.x, m_Selection.m_CursorA.y, + m_Selection.m_CursorB.x, m_Selection.m_CursorB.y)); } wxLayoutObject * @@ -2860,7 +2867,6 @@ wxLayoutList::GetSelection(wxLayoutDataObject *wxlo, bool invalidate) exp->content.object->Write(string); delete exp; } - wxlo->SetLayoutData(string); } return llist; diff --git a/samples/richedit/wxllist.h b/samples/richedit/wxllist.h index 0ff31fb09f..1446ebf3a0 100644 --- a/samples/richedit/wxllist.h +++ b/samples/richedit/wxllist.h @@ -1140,6 +1140,12 @@ public: /// get the line by number wxLayoutLine *GetLine(CoordType index) const; + + /** Reads objects from a string and inserts them. + @param istr stream to read from, will bee changed + */ + void Read(wxString &istr); + private: /// Clear the list. void InternalClear(void); diff --git a/samples/richedit/wxlwindow.cpp b/samples/richedit/wxlwindow.cpp index bade22716d..1fdba74348 100644 --- a/samples/richedit/wxlwindow.cpp +++ b/samples/richedit/wxlwindow.cpp @@ -88,7 +88,7 @@ static const int Y_SCROLL_PAGE = 20; -#define wxUSE_PRIVATE_CLIPBOARD_FORMAT 1 +#define wxUSE_PRIVATE_CLIPBOARD_FORMAT 0 // ---------------------------------------------------------------------------- // event tables @@ -496,21 +496,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: @@ -631,8 +628,12 @@ wxLayoutWindow::OnChar(wxKeyEvent& event) m_llist->DeleteToEndOfLine(); SetDirty(); break; + case 'c': + Copy(); + break; case 'v': - Paste(); + // if SHIFT is down, use primary selection + Paste( event.ShiftDown() ); break; case 'x': Cut(); @@ -1079,11 +1080,14 @@ wxLayoutWindow::Paste(bool primary) { #if wxUSE_PRIVATE_CLIPBOARD_FORMAT wxLayoutDataObject wxldo; - if ( wxTheClipboard->GetData(wxldo) ) + if (wxTheClipboard->IsSupported( wxldo.GetFormat() )) { - //FIXME: missing functionality m_llist->Insert(wxldo.GetList()); - wxLayoutImportText(m_llist, wxldo.GetLayoutData()); - SetDirty(); + if(wxTheClipboard->GetData(wxldo)) + { + wxString str = wxldo.GetLayoutData(); + m_llist->Read(str); + RequestUpdate(); + } } else #endif @@ -1112,20 +1116,10 @@ wxLayoutWindow::Copy(bool invalidate) m_llist->EndSelection(); } -#if wxUSE_PRIVATE_CLIPBOARD_FORMAT - // the data object which holds all different data objects, one for each - // format we support - wxDataObjectComposite *data = new wxDataObjectComposite; -#endif - wxLayoutDataObject *wldo = new wxLayoutDataObject; wxLayoutList *llist = m_llist->GetSelection(wldo, invalidate); if(! llist) - { - delete wldo; - delete data; return FALSE; - } // Export selection as text: wxString text; wxLayoutExportObject *exp; @@ -1138,7 +1132,6 @@ wxLayoutWindow::Copy(bool invalidate) } delete llist; - bool rc; // The exporter always appends a newline, so we chop it off if it // is there: { @@ -1151,19 +1144,20 @@ wxLayoutWindow::Copy(bool invalidate) if (wxTheClipboard->Open()) { + wxTextDataObject *data = new wxTextDataObject( text ); + bool rc; + + rc = wxTheClipboard->SetData( data ); #if wxUSE_PRIVATE_CLIPBOARD_FORMAT - data->Add(wldo, TRUE /* preferred */); - data->Add(new wxTextDataObject(text)); + rc |= wxTheClipboard->SetData( wldo ); #endif - rc = wxTheClipboard->SetData( data ); wxTheClipboard->Close(); + return rc; } else - rc = FALSE; - - delete wldo; - delete data; - return rc; + delete wldo; + + return FALSE; } bool