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:
parent
1193d8fa93
commit
371ee4026e
@ -2,9 +2,6 @@
|
||||
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
|
||||
direction if begin of first object is reached
|
||||
|
||||
@ -13,26 +10,14 @@ TODO
|
||||
|
||||
- use printsetup margins
|
||||
|
||||
- merge RecalulateXXX and Layout() into one
|
||||
|
||||
- UNDO!!
|
||||
- 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)
|
||||
--> needs a bit of fixing still
|
||||
some code bits are commented out in wxlwindow.cpp
|
||||
offset handling seems a bit dodgy, white shadow to top/left of cursor
|
||||
|
||||
- DragNDrop
|
||||
- Update docs, do full rtf/html editing.
|
||||
- Verify/fix html export.
|
||||
- add wxHTML parser to import HTML
|
||||
- add some kind of callback for objects with userdata
|
||||
- use wxTempFile to get rid of temporary image files
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "wxLayout.h"
|
||||
#include <wx/textfile.h>
|
||||
#include <wx/image.h>
|
||||
|
||||
#include <iostream.h>
|
||||
|
||||
@ -40,7 +41,7 @@ enum ids
|
||||
ID_PRINT_SETUP, ID_PAGE_SETUP, ID_PREVIEW, ID_PRINT_PS,
|
||||
ID_PRINT_SETUP_PS, ID_PAGE_SETUP_PS,ID_PREVIEW_PS,
|
||||
ID_WRAP, ID_NOWRAP, ID_PASTE, ID_COPY, ID_CUT,
|
||||
ID_PASTE_PRIMARY,
|
||||
ID_COPY_PRIMARY, ID_PASTE_PRIMARY,
|
||||
ID_FIND,
|
||||
ID_WXLAYOUT_DEBUG, ID_QUIT, ID_CLICK, ID_HTML, ID_TEXT,
|
||||
ID_TEST, ID_LINEBREAKS_TEST, ID_LONG_TEST, ID_URL_TEST
|
||||
@ -105,10 +106,11 @@ MyFrame::MyFrame(void) :
|
||||
edit_menu->AppendSeparator();
|
||||
edit_menu->Append(ID_COPY, "&Copy", "Copy 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.");
|
||||
#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.");
|
||||
#endif
|
||||
edit_menu->Append(ID_FIND, "&Find", "Find text.");
|
||||
menu_bar->Append(edit_menu, "&Edit" );
|
||||
|
||||
@ -283,17 +285,23 @@ void MyFrame::OnCommand( wxCommandEvent &event )
|
||||
cerr << "Received click event." << endl;
|
||||
break;
|
||||
case ID_PASTE:
|
||||
m_lwin->Paste();
|
||||
m_lwin->Paste(TRUE);
|
||||
m_lwin->Refresh(FALSE);
|
||||
break;
|
||||
#ifdef __WXGTK__
|
||||
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);
|
||||
break;
|
||||
#endif
|
||||
case ID_COPY:
|
||||
m_lwin->Copy();
|
||||
m_lwin->Copy(TRUE,TRUE,FALSE);
|
||||
m_lwin->Refresh(FALSE);
|
||||
break;
|
||||
case ID_CUT:
|
||||
@ -311,13 +319,14 @@ void MyFrame::OnCommand( wxCommandEvent &event )
|
||||
wxLayoutExportObject *export0;
|
||||
wxLayoutExportStatus status(m_lwin->GetLayoutList());
|
||||
|
||||
cout << "<HTML>" << endl;
|
||||
while((export0 = wxLayoutExport( &status,
|
||||
WXLO_EXPORT_AS_HTML)) != NULL)
|
||||
{
|
||||
if(export0->type == WXLO_EXPORT_HTML)
|
||||
cout << *(export0->content.text);
|
||||
else
|
||||
cout << "<!--UNKNOWN OBJECT>";
|
||||
; // ignore itcout << "<!--UNKNOWN OBJECT>";
|
||||
delete export0;
|
||||
}
|
||||
}
|
||||
@ -506,6 +515,7 @@ MyApp::MyApp(void) :
|
||||
bool MyApp::OnInit(void)
|
||||
{
|
||||
wxFrame *frame = new MyFrame();
|
||||
wxInitAllImageHandlers();
|
||||
frame->Show( TRUE );
|
||||
// wxSetAFMPath("/usr/local/src/wxWindows/misc/afm/");
|
||||
return TRUE;
|
||||
|
@ -448,6 +448,8 @@ wxLayoutObjectIcon::Copy(void)
|
||||
wxLayoutObjectIcon::wxLayoutObjectIcon(wxBitmap *icon)
|
||||
{
|
||||
m_Icon = icon;
|
||||
if(! m_Icon)
|
||||
m_Icon = new wxIcon;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
wxLayoutObjectCmd::wxLayoutObjectCmd(const wxLayoutStyleInfo &si)
|
||||
|
||||
{
|
||||
m_StyleInfo = new wxLayoutStyleInfo;
|
||||
*m_StyleInfo = si;
|
||||
}
|
||||
|
||||
wxLayoutObject *
|
||||
wxLayoutObjectCmd::Copy(void)
|
||||
{
|
||||
wxLayoutObjectCmd *obj = new wxLayoutObjectCmd(
|
||||
m_StyleInfo->size,
|
||||
m_StyleInfo->family,
|
||||
m_StyleInfo->size,
|
||||
m_StyleInfo->style,
|
||||
m_StyleInfo->weight,
|
||||
m_StyleInfo->underline,
|
||||
@ -545,8 +554,8 @@ void
|
||||
wxLayoutObjectCmd::Write(wxString &ostr)
|
||||
{
|
||||
ostr << WXLO_TYPE_CMD << '\n'
|
||||
<< m_StyleInfo->size << '\n'
|
||||
<< m_StyleInfo->family << '\n'
|
||||
<< m_StyleInfo->size << '\n'
|
||||
<< m_StyleInfo->style << '\n'
|
||||
<< m_StyleInfo->weight << '\n'
|
||||
<< m_StyleInfo->underline << '\n'
|
||||
@ -573,10 +582,10 @@ wxLayoutObjectCmd::Read(wxString &istr)
|
||||
|
||||
wxString tmp;
|
||||
ReadString(tmp, istr);
|
||||
sscanf(tmp.c_str(),"%d", &obj->m_StyleInfo->size);
|
||||
ReadString(tmp, istr);
|
||||
sscanf(tmp.c_str(),"%d", &obj->m_StyleInfo->family);
|
||||
ReadString(tmp, istr);
|
||||
sscanf(tmp.c_str(),"%d", &obj->m_StyleInfo->size);
|
||||
ReadString(tmp, istr);
|
||||
sscanf(tmp.c_str(),"%d", &obj->m_StyleInfo->style);
|
||||
ReadString(tmp, istr);
|
||||
sscanf(tmp.c_str(),"%d", &obj->m_StyleInfo->weight);
|
||||
@ -1571,12 +1580,20 @@ wxLayoutList::InternalClear(void)
|
||||
void
|
||||
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())
|
||||
{
|
||||
wxLayoutObject *obj = wxLayoutObject::Read(istr);
|
||||
if(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)
|
||||
{
|
||||
m_CurrentStyleInfo.m_fg = si.m_fg;
|
||||
m_CurrentStyleInfo.m_fg_valid = true;
|
||||
dc.SetTextForeground(m_CurrentStyleInfo.m_fg);
|
||||
}
|
||||
if(si.m_bg_valid)
|
||||
{
|
||||
m_CurrentStyleInfo.m_bg = si.m_bg;
|
||||
m_CurrentStyleInfo.m_bg_valid = true;
|
||||
dc.SetTextBackground(m_CurrentStyleInfo.m_bg);
|
||||
}
|
||||
}
|
||||
|
@ -421,6 +421,7 @@ public:
|
||||
int underline = -1,
|
||||
wxColour *fg = NULL,
|
||||
wxColour *bg = NULL);
|
||||
wxLayoutObjectCmd(const wxLayoutStyleInfo &si);
|
||||
~wxLayoutObjectCmd();
|
||||
/** Stores the current style in the styleinfo structure */
|
||||
wxLayoutStyleInfo * GetStyle(void) const;
|
||||
|
@ -73,7 +73,8 @@ void wxLayoutImportText(wxLayoutList *list, wxString const &str)
|
||||
|
||||
static
|
||||
wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
|
||||
wxLayoutStyleInfo *styleInfo)
|
||||
wxLayoutStyleInfo *styleInfo,
|
||||
bool firstTime)
|
||||
{
|
||||
static char buffer[20];
|
||||
wxString html;
|
||||
@ -128,7 +129,7 @@ wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
|
||||
|
||||
html +=">";
|
||||
|
||||
if(styleInfo != NULL)
|
||||
if(styleInfo != NULL && ! firstTime)
|
||||
html ="</font>"+html; // terminate any previous font command
|
||||
|
||||
if((si->weight == wxBOLD) && ( (!styleInfo) || (styleInfo->weight != wxBOLD)))
|
||||
@ -164,6 +165,7 @@ wxLayoutExportStatus::wxLayoutExportStatus(wxLayoutList *list)
|
||||
m_si = list->GetDefaultStyleInfo();
|
||||
m_line = list->GetFirstLine();
|
||||
m_iterator = m_line->GetFirstObject();
|
||||
m_FirstTime = TRUE;
|
||||
}
|
||||
|
||||
|
||||
@ -220,7 +222,7 @@ wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
|
||||
{
|
||||
while(status->m_iterator == NULLIT)
|
||||
{
|
||||
if(flags & WXLO_EXPORT_AS_HTML)
|
||||
if(mode & WXLO_EXPORT_AS_HTML)
|
||||
*str += "<br>";
|
||||
if(flags & WXLO_EXPORT_WITH_CRLF)
|
||||
*str += "\r\n";
|
||||
@ -245,15 +247,16 @@ wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
|
||||
break;
|
||||
case WXLO_TYPE_CMD:
|
||||
if(mode == WXLO_EXPORT_AS_HTML)
|
||||
*str += wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd const
|
||||
*)*status->m_iterator, & status->m_si);
|
||||
*str += wxLayoutExportCmdAsHTML(
|
||||
*(wxLayoutObjectCmd const *)*status->m_iterator,
|
||||
& status->m_si, status->m_FirstTime);
|
||||
status->m_FirstTime = FALSE;
|
||||
break;
|
||||
default: // ignore icons
|
||||
;
|
||||
}
|
||||
status->m_iterator++;
|
||||
}
|
||||
|
||||
exp->type = (mode == WXLO_EXPORT_AS_HTML)
|
||||
? WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT;
|
||||
exp->content.text = str;
|
||||
|
@ -59,12 +59,13 @@ struct wxLayoutExportStatus
|
||||
wxLayoutLine * m_line;
|
||||
wxLOiterator m_iterator;
|
||||
wxLayoutStyleInfo m_si;
|
||||
bool m_FirstTime;
|
||||
};
|
||||
|
||||
#ifdef OS_WIN
|
||||
#define WXLO_DEFAULT_EXPORT_MODE WXLO_EXPORT_WITH_CRLF
|
||||
# define WXLO_DEFAULT_EXPORT_MODE WXLO_EXPORT_WITH_CRLF
|
||||
#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
|
||||
|
||||
/// import text into a wxLayoutList (including linefeeds):
|
||||
|
@ -88,8 +88,6 @@ static const int Y_SCROLL_PAGE = 20;
|
||||
|
||||
|
||||
|
||||
#define wxUSE_PRIVATE_CLIPBOARD_FORMAT 0
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// event tables
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -564,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("");
|
||||
@ -629,11 +627,10 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
|
||||
SetDirty();
|
||||
break;
|
||||
case 'c':
|
||||
Copy();
|
||||
Copy(TRUE, TRUE);
|
||||
break;
|
||||
case 'v':
|
||||
// if SHIFT is down, use primary selection
|
||||
Paste( event.ShiftDown() );
|
||||
Paste( TRUE );
|
||||
break;
|
||||
case 'x':
|
||||
Cut();
|
||||
@ -717,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
|
||||
@ -1071,26 +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)
|
||||
{
|
||||
if(wxTheClipboard->GetData(wxldo))
|
||||
wxLayoutDataObject wxldo;
|
||||
if (wxTheClipboard->IsSupported( wxldo.GetFormat() ))
|
||||
{
|
||||
wxString str = wxldo.GetLayoutData();
|
||||
m_llist->Read(str);
|
||||
RequestUpdate();
|
||||
if(wxTheClipboard->GetData(wxldo))
|
||||
{
|
||||
wxTheClipboard->Close();
|
||||
wxString str = wxldo.GetLayoutData();
|
||||
m_llist->Read(str);
|
||||
SetDirty();
|
||||
RequestUpdate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
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() )
|
||||
@ -1099,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:
|
||||
@ -1142,15 +1168,28 @@ 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;
|
||||
|
||||
rc = wxTheClipboard->SetData( data );
|
||||
#if wxUSE_PRIVATE_CLIPBOARD_FORMAT
|
||||
rc |= wxTheClipboard->SetData( wldo );
|
||||
#endif
|
||||
rc = wxTheClipboard->SetData( data );
|
||||
if(privateFormat)
|
||||
rc |= wxTheClipboard->SetData( wldo );
|
||||
wxTheClipboard->Close();
|
||||
return rc;
|
||||
}
|
||||
@ -1161,9 +1200,9 @@ wxLayoutWindow::Copy(bool invalidate)
|
||||
}
|
||||
|
||||
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();
|
||||
|
@ -95,13 +95,13 @@ public:
|
||||
m_CursorVisibility = visibility; return v;}
|
||||
|
||||
/// Pastes text from clipboard.
|
||||
void Paste(bool usePrimarySelection = FALSE);
|
||||
void Paste(bool privateFormat = FALSE, bool usePrimarySelection = FALSE);
|
||||
/** Copies selection to clipboard.
|
||||
@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.
|
||||
bool Cut(void);
|
||||
bool Cut(bool privateFormat = FALSE, bool usePrimary = FALSE);
|
||||
//@}
|
||||
|
||||
/// find string in buffer
|
||||
|
Loading…
Reference in New Issue
Block a user