rtf cut&paste works now, html export fixed

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4788 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Karsten Ballüder
1999-12-01 18:05:54 +00:00
parent 1193d8fa93
commit 371ee4026e
8 changed files with 125 additions and 67 deletions

View File

@@ -2,9 +2,6 @@
BUGS BUGS
===================================================================== =====================================================================
- dmalloc shows duplicate deletion after merging two lines and
deleting the second half
- word wrap for objects with lots of non-space needs to search in positive - word wrap for objects with lots of non-space needs to search in positive
direction if begin of first object is reached direction if begin of first object is reached
@@ -13,26 +10,14 @@ TODO
- use printsetup margins - use printsetup margins
- merge RecalulateXXX and Layout() into one
- UNDO!! - UNDO!!
- replacement of llist in window - replacement of llist in window
Improve speed! (See layout problem below!)
- wxlwindow needs to shrink scrollbar range when window contents get removed
- When selecting with the mouse, scroll window if pointer is outside.
- The import of a private data object does not work yet, we need to get
the objects back from the string.
- update rectangle (needs support in wxllist and wxWindows) - update rectangle (needs support in wxllist and wxWindows)
--> needs a bit of fixing still --> needs a bit of fixing still
some code bits are commented out in wxlwindow.cpp some code bits are commented out in wxlwindow.cpp
offset handling seems a bit dodgy, white shadow to top/left of cursor offset handling seems a bit dodgy, white shadow to top/left of cursor
- DragNDrop - add wxHTML parser to import HTML
- Update docs, do full rtf/html editing. - add some kind of callback for objects with userdata
- Verify/fix html export. - use wxTempFile to get rid of temporary image files

View File

@@ -18,6 +18,7 @@
#include "wxLayout.h" #include "wxLayout.h"
#include <wx/textfile.h> #include <wx/textfile.h>
#include <wx/image.h>
#include <iostream.h> #include <iostream.h>
@@ -40,7 +41,7 @@ enum ids
ID_PRINT_SETUP, ID_PAGE_SETUP, ID_PREVIEW, ID_PRINT_PS, ID_PRINT_SETUP, ID_PAGE_SETUP, ID_PREVIEW, ID_PRINT_PS,
ID_PRINT_SETUP_PS, ID_PAGE_SETUP_PS,ID_PREVIEW_PS, ID_PRINT_SETUP_PS, ID_PAGE_SETUP_PS,ID_PREVIEW_PS,
ID_WRAP, ID_NOWRAP, ID_PASTE, ID_COPY, ID_CUT, ID_WRAP, ID_NOWRAP, ID_PASTE, ID_COPY, ID_CUT,
ID_PASTE_PRIMARY, ID_COPY_PRIMARY, ID_PASTE_PRIMARY,
ID_FIND, ID_FIND,
ID_WXLAYOUT_DEBUG, ID_QUIT, ID_CLICK, ID_HTML, ID_TEXT, ID_WXLAYOUT_DEBUG, ID_QUIT, ID_CLICK, ID_HTML, ID_TEXT,
ID_TEST, ID_LINEBREAKS_TEST, ID_LONG_TEST, ID_URL_TEST ID_TEST, ID_LINEBREAKS_TEST, ID_LONG_TEST, ID_URL_TEST
@@ -105,10 +106,11 @@ MyFrame::MyFrame(void) :
edit_menu->AppendSeparator(); edit_menu->AppendSeparator();
edit_menu->Append(ID_COPY, "&Copy", "Copy text to clipboard."); edit_menu->Append(ID_COPY, "&Copy", "Copy text to clipboard.");
edit_menu->Append(ID_CUT, "Cu&t", "Cut text to clipboard."); edit_menu->Append(ID_CUT, "Cu&t", "Cut text to clipboard.");
#ifdef __WXGTK__
edit_menu->Append(ID_PASTE,"&Paste", "Paste text from clipboard."); edit_menu->Append(ID_PASTE,"&Paste", "Paste text from clipboard.");
#endif #ifdef __WXGTK__
edit_menu->Append(ID_COPY_PRIMARY, "C&opy primary", "Copy text to primary selecton.");
edit_menu->Append(ID_PASTE_PRIMARY,"&Paste primary", "Paste text from primary selection."); edit_menu->Append(ID_PASTE_PRIMARY,"&Paste primary", "Paste text from primary selection.");
#endif
edit_menu->Append(ID_FIND, "&Find", "Find text."); edit_menu->Append(ID_FIND, "&Find", "Find text.");
menu_bar->Append(edit_menu, "&Edit" ); menu_bar->Append(edit_menu, "&Edit" );
@@ -283,17 +285,23 @@ void MyFrame::OnCommand( wxCommandEvent &event )
cerr << "Received click event." << endl; cerr << "Received click event." << endl;
break; break;
case ID_PASTE: case ID_PASTE:
m_lwin->Paste(); m_lwin->Paste(TRUE);
m_lwin->Refresh(FALSE); m_lwin->Refresh(FALSE);
break; break;
#ifdef __WXGTK__ #ifdef __WXGTK__
case ID_PASTE_PRIMARY: case ID_PASTE_PRIMARY:
m_lwin->Paste(TRUE); // text only from primary:
m_lwin->Paste(FALSE, TRUE);
m_lwin->Refresh(FALSE);
break;
case ID_COPY_PRIMARY:
// copy text-only to primary selection:
m_lwin->Copy(FALSE,FALSE,TRUE);
m_lwin->Refresh(FALSE); m_lwin->Refresh(FALSE);
break; break;
#endif #endif
case ID_COPY: case ID_COPY:
m_lwin->Copy(); m_lwin->Copy(TRUE,TRUE,FALSE);
m_lwin->Refresh(FALSE); m_lwin->Refresh(FALSE);
break; break;
case ID_CUT: case ID_CUT:
@@ -311,13 +319,14 @@ void MyFrame::OnCommand( wxCommandEvent &event )
wxLayoutExportObject *export0; wxLayoutExportObject *export0;
wxLayoutExportStatus status(m_lwin->GetLayoutList()); wxLayoutExportStatus status(m_lwin->GetLayoutList());
cout << "<HTML>" << endl;
while((export0 = wxLayoutExport( &status, while((export0 = wxLayoutExport( &status,
WXLO_EXPORT_AS_HTML)) != NULL) WXLO_EXPORT_AS_HTML)) != NULL)
{ {
if(export0->type == WXLO_EXPORT_HTML) if(export0->type == WXLO_EXPORT_HTML)
cout << *(export0->content.text); cout << *(export0->content.text);
else else
cout << "<!--UNKNOWN OBJECT>"; ; // ignore itcout << "<!--UNKNOWN OBJECT>";
delete export0; delete export0;
} }
} }
@@ -506,6 +515,7 @@ MyApp::MyApp(void) :
bool MyApp::OnInit(void) bool MyApp::OnInit(void)
{ {
wxFrame *frame = new MyFrame(); wxFrame *frame = new MyFrame();
wxInitAllImageHandlers();
frame->Show( TRUE ); frame->Show( TRUE );
// wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/"); // wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");
return TRUE; return TRUE;

View File

@@ -448,6 +448,8 @@ wxLayoutObjectIcon::Copy(void)
wxLayoutObjectIcon::wxLayoutObjectIcon(wxBitmap *icon) wxLayoutObjectIcon::wxLayoutObjectIcon(wxBitmap *icon)
{ {
m_Icon = icon; m_Icon = icon;
if(! m_Icon)
m_Icon = new wxIcon;
} }
void void
@@ -524,12 +526,19 @@ wxLayoutObjectCmd::wxLayoutObjectCmd(int family, int size, int style, int
m_StyleInfo = new wxLayoutStyleInfo(family, size,style,weight,underline,fg,bg); m_StyleInfo = new wxLayoutStyleInfo(family, size,style,weight,underline,fg,bg);
} }
wxLayoutObjectCmd::wxLayoutObjectCmd(const wxLayoutStyleInfo &si)
{
m_StyleInfo = new wxLayoutStyleInfo;
*m_StyleInfo = si;
}
wxLayoutObject * wxLayoutObject *
wxLayoutObjectCmd::Copy(void) wxLayoutObjectCmd::Copy(void)
{ {
wxLayoutObjectCmd *obj = new wxLayoutObjectCmd( wxLayoutObjectCmd *obj = new wxLayoutObjectCmd(
m_StyleInfo->size,
m_StyleInfo->family, m_StyleInfo->family,
m_StyleInfo->size,
m_StyleInfo->style, m_StyleInfo->style,
m_StyleInfo->weight, m_StyleInfo->weight,
m_StyleInfo->underline, m_StyleInfo->underline,
@@ -545,8 +554,8 @@ void
wxLayoutObjectCmd::Write(wxString &ostr) wxLayoutObjectCmd::Write(wxString &ostr)
{ {
ostr << WXLO_TYPE_CMD << '\n' ostr << WXLO_TYPE_CMD << '\n'
<< m_StyleInfo->size << '\n'
<< m_StyleInfo->family << '\n' << m_StyleInfo->family << '\n'
<< m_StyleInfo->size << '\n'
<< m_StyleInfo->style << '\n' << m_StyleInfo->style << '\n'
<< m_StyleInfo->weight << '\n' << m_StyleInfo->weight << '\n'
<< m_StyleInfo->underline << '\n' << m_StyleInfo->underline << '\n'
@@ -573,10 +582,10 @@ wxLayoutObjectCmd::Read(wxString &istr)
wxString tmp; wxString tmp;
ReadString(tmp, istr); ReadString(tmp, istr);
sscanf(tmp.c_str(),"%d", &obj->m_StyleInfo->size);
ReadString(tmp, istr);
sscanf(tmp.c_str(),"%d", &obj->m_StyleInfo->family); sscanf(tmp.c_str(),"%d", &obj->m_StyleInfo->family);
ReadString(tmp, istr); ReadString(tmp, istr);
sscanf(tmp.c_str(),"%d", &obj->m_StyleInfo->size);
ReadString(tmp, istr);
sscanf(tmp.c_str(),"%d", &obj->m_StyleInfo->style); sscanf(tmp.c_str(),"%d", &obj->m_StyleInfo->style);
ReadString(tmp, istr); ReadString(tmp, istr);
sscanf(tmp.c_str(),"%d", &obj->m_StyleInfo->weight); sscanf(tmp.c_str(),"%d", &obj->m_StyleInfo->weight);
@@ -1571,12 +1580,20 @@ wxLayoutList::InternalClear(void)
void void
wxLayoutList::Read(wxString &istr) wxLayoutList::Read(wxString &istr)
{ {
/* In order to handle input of formatted string "nicely", we need
to restore our current font settings after the string. So first
of all, we create a StyleInfo structure with our current
settings. */
wxLayoutStyleInfo current_si = GetStyleInfo();
while(istr.Length()) while(istr.Length())
{ {
wxLayoutObject *obj = wxLayoutObject::Read(istr); wxLayoutObject *obj = wxLayoutObject::Read(istr);
if(obj) if(obj)
Insert(obj); Insert(obj);
} }
/* Now we use the current_si to restore our last font settings: */
Insert(new wxLayoutObjectCmd(current_si));
} }
@@ -2891,11 +2908,13 @@ wxLayoutList::ApplyStyle(wxLayoutStyleInfo const &si, wxDC &dc)
if(si.m_fg_valid) if(si.m_fg_valid)
{ {
m_CurrentStyleInfo.m_fg = si.m_fg; m_CurrentStyleInfo.m_fg = si.m_fg;
m_CurrentStyleInfo.m_fg_valid = true;
dc.SetTextForeground(m_CurrentStyleInfo.m_fg); dc.SetTextForeground(m_CurrentStyleInfo.m_fg);
} }
if(si.m_bg_valid) if(si.m_bg_valid)
{ {
m_CurrentStyleInfo.m_bg = si.m_bg; m_CurrentStyleInfo.m_bg = si.m_bg;
m_CurrentStyleInfo.m_bg_valid = true;
dc.SetTextBackground(m_CurrentStyleInfo.m_bg); dc.SetTextBackground(m_CurrentStyleInfo.m_bg);
} }
} }

View File

@@ -421,6 +421,7 @@ public:
int underline = -1, int underline = -1,
wxColour *fg = NULL, wxColour *fg = NULL,
wxColour *bg = NULL); wxColour *bg = NULL);
wxLayoutObjectCmd(const wxLayoutStyleInfo &si);
~wxLayoutObjectCmd(); ~wxLayoutObjectCmd();
/** Stores the current style in the styleinfo structure */ /** Stores the current style in the styleinfo structure */
wxLayoutStyleInfo * GetStyle(void) const; wxLayoutStyleInfo * GetStyle(void) const;

View File

@@ -73,7 +73,8 @@ void wxLayoutImportText(wxLayoutList *list, wxString const &str)
static static
wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd, wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
wxLayoutStyleInfo *styleInfo) wxLayoutStyleInfo *styleInfo,
bool firstTime)
{ {
static char buffer[20]; static char buffer[20];
wxString html; wxString html;
@@ -128,7 +129,7 @@ wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
html +=">"; html +=">";
if(styleInfo != NULL) if(styleInfo != NULL && ! firstTime)
html ="</font>"+html; // terminate any previous font command html ="</font>"+html; // terminate any previous font command
if((si->weight == wxBOLD) && ( (!styleInfo) || (styleInfo->weight != wxBOLD))) if((si->weight == wxBOLD) && ( (!styleInfo) || (styleInfo->weight != wxBOLD)))
@@ -164,6 +165,7 @@ wxLayoutExportStatus::wxLayoutExportStatus(wxLayoutList *list)
m_si = list->GetDefaultStyleInfo(); m_si = list->GetDefaultStyleInfo();
m_line = list->GetFirstLine(); m_line = list->GetFirstLine();
m_iterator = m_line->GetFirstObject(); m_iterator = m_line->GetFirstObject();
m_FirstTime = TRUE;
} }
@@ -220,7 +222,7 @@ wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
{ {
while(status->m_iterator == NULLIT) while(status->m_iterator == NULLIT)
{ {
if(flags & WXLO_EXPORT_AS_HTML) if(mode & WXLO_EXPORT_AS_HTML)
*str += "<br>"; *str += "<br>";
if(flags & WXLO_EXPORT_WITH_CRLF) if(flags & WXLO_EXPORT_WITH_CRLF)
*str += "\r\n"; *str += "\r\n";
@@ -245,15 +247,16 @@ wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
break; break;
case WXLO_TYPE_CMD: case WXLO_TYPE_CMD:
if(mode == WXLO_EXPORT_AS_HTML) if(mode == WXLO_EXPORT_AS_HTML)
*str += wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd const *str += wxLayoutExportCmdAsHTML(
*)*status->m_iterator, & status->m_si); *(wxLayoutObjectCmd const *)*status->m_iterator,
& status->m_si, status->m_FirstTime);
status->m_FirstTime = FALSE;
break; break;
default: // ignore icons default: // ignore icons
; ;
} }
status->m_iterator++; status->m_iterator++;
} }
exp->type = (mode == WXLO_EXPORT_AS_HTML) exp->type = (mode == WXLO_EXPORT_AS_HTML)
? WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT; ? WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT;
exp->content.text = str; exp->content.text = str;

View File

@@ -59,12 +59,13 @@ struct wxLayoutExportStatus
wxLayoutLine * m_line; wxLayoutLine * m_line;
wxLOiterator m_iterator; wxLOiterator m_iterator;
wxLayoutStyleInfo m_si; wxLayoutStyleInfo m_si;
bool m_FirstTime;
}; };
#ifdef OS_WIN #ifdef OS_WIN
#define WXLO_DEFAULT_EXPORT_MODE WXLO_EXPORT_WITH_CRLF # define WXLO_DEFAULT_EXPORT_MODE WXLO_EXPORT_WITH_CRLF
#else // Unix #else // Unix
#define WXLO_DEFAULT_EXPORT_MODE WXLO_EXPORT_WITH_LF_ONLY # define WXLO_DEFAULT_EXPORT_MODE WXLO_EXPORT_WITH_LF_ONLY
#endif // Win/Unix #endif // Win/Unix
/// import text into a wxLayoutList (including linefeeds): /// import text into a wxLayoutList (including linefeeds):

View File

@@ -88,8 +88,6 @@ static const int Y_SCROLL_PAGE = 20;
#define wxUSE_PRIVATE_CLIPBOARD_FORMAT 0
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// event tables // event tables
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -564,7 +562,7 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
{ {
case 'c': case 'c':
// this should work even in read-only mode // this should work even in read-only mode
Copy(); Copy(TRUE, TRUE);
break; break;
case 's': // search case 's': // search
Find(""); Find("");
@@ -629,11 +627,10 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
SetDirty(); SetDirty();
break; break;
case 'c': case 'c':
Copy(); Copy(TRUE, TRUE);
break; break;
case 'v': case 'v':
// if SHIFT is down, use primary selection Paste( TRUE );
Paste( event.ShiftDown() );
break; break;
case 'x': case 'x':
Cut(); Cut();
@@ -717,8 +714,15 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
) )
{ {
if(m_WrapMargin > 0 && isspace(keyCode)) if(m_WrapMargin > 0 && isspace(keyCode))
m_llist->WrapLine(m_WrapMargin); {
m_llist->Insert((char)keyCode); bool wrapped = m_llist->WrapLine(m_WrapMargin);
// don<6F>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(); SetDirty();
} }
else else
@@ -1071,26 +1075,47 @@ wxLayoutWindow::ResizeScrollbars(bool exact)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void void
wxLayoutWindow::Paste(bool primary) wxLayoutWindow::Paste(bool usePrivate, bool primary)
{ {
// this only has an effect under X11: // this only has an effect under X11:
if(primary) wxTheClipboard->UsePrimarySelection(); wxTheClipboard->UsePrimarySelection(primary);
// Read some text // Read some text
if (wxTheClipboard->Open()) if (wxTheClipboard->Open())
{ {
#if wxUSE_PRIVATE_CLIPBOARD_FORMAT if(usePrivate)
wxLayoutDataObject wxldo;
if (wxTheClipboard->IsSupported( wxldo.GetFormat() ))
{ {
if(wxTheClipboard->GetData(wxldo)) wxLayoutDataObject wxldo;
if (wxTheClipboard->IsSupported( wxldo.GetFormat() ))
{ {
wxString str = wxldo.GetLayoutData(); if(wxTheClipboard->GetData(wxldo))
m_llist->Read(str); {
RequestUpdate(); wxTheClipboard->Close();
wxString str = wxldo.GetLayoutData();
m_llist->Read(str);
SetDirty();
RequestUpdate();
return;
}
} }
} }
else wxTextDataObject data;
#endif 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; wxTextDataObject data;
if (wxTheClipboard->IsSupported( data.GetFormat() ) if (wxTheClipboard->IsSupported( data.GetFormat() )
@@ -1099,14 +1124,15 @@ wxLayoutWindow::Paste(bool primary)
wxString text = data.GetText(); wxString text = data.GetText();
wxLayoutImportText( m_llist, text); wxLayoutImportText( m_llist, text);
SetDirty(); SetDirty();
RequestUpdate();
} }
wxTheClipboard->Close();
} }
wxTheClipboard->Close();
} }
} }
bool bool
wxLayoutWindow::Copy(bool invalidate) wxLayoutWindow::Copy(bool invalidate, bool privateFormat, bool primary)
{ {
// Calling GetSelection() will automatically do an EndSelection() // Calling GetSelection() will automatically do an EndSelection()
// on the list, but we need to take a note of it, too: // on the list, but we need to take a note of it, too:
@@ -1142,15 +1168,28 @@ wxLayoutWindow::Copy(bool invalidate)
text = text.Mid(0,len-1); 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()) if (wxTheClipboard->Open())
{ {
wxTextDataObject *data = new wxTextDataObject( text ); wxTextDataObject *data = new wxTextDataObject( text );
bool rc; bool rc;
rc = wxTheClipboard->SetData( data ); rc = wxTheClipboard->SetData( data );
#if wxUSE_PRIVATE_CLIPBOARD_FORMAT if(privateFormat)
rc |= wxTheClipboard->SetData( wldo ); rc |= wxTheClipboard->SetData( wldo );
#endif
wxTheClipboard->Close(); wxTheClipboard->Close();
return rc; return rc;
} }
@@ -1161,9 +1200,9 @@ wxLayoutWindow::Copy(bool invalidate)
} }
bool 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(); m_llist->DeleteSelection();
SetDirty(); SetDirty();

View File

@@ -95,13 +95,13 @@ public:
m_CursorVisibility = visibility; return v;} m_CursorVisibility = visibility; return v;}
/// Pastes text from clipboard. /// Pastes text from clipboard.
void Paste(bool usePrimarySelection = FALSE); void Paste(bool privateFormat = FALSE, bool usePrimarySelection = FALSE);
/** Copies selection to clipboard. /** Copies selection to clipboard.
@param invalidate used internally, see wxllist.h for details @param invalidate used internally, see wxllist.h for details
*/ */
bool Copy(bool invalidate = true); bool Copy(bool invalidate = true, bool privateFormat = FALSE, bool primary = FALSE);
/// Copies selection to clipboard and deletes it. /// Copies selection to clipboard and deletes it.
bool Cut(void); bool Cut(bool privateFormat = FALSE, bool usePrimary = FALSE);
//@} //@}
/// find string in buffer /// find string in buffer