fixes [ 1779152 ] FileDataObject Unicode, [ 1643699 ] DnD File Unicode error

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@48566 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2007-09-05 12:39:06 +00:00
parent 9ffcc41fc4
commit 0e4341c1ec
3 changed files with 70 additions and 35 deletions

View File

@@ -175,6 +175,9 @@ wxGTK:
- Fixed crash in settings when using tooltips->tip_window with GTK+ 2.11.6.
- Fix WX_GL_STEREO attribute handling (Tristan Mehamli)
- Fix wxThread::SetPriority() when the thread is running (Christos Gourdoupis)
- Fixed size problem in wxTaskBarIcon
- Fixed scrolling problem of wxStaticBox (and possibly other control)
- Fixed wxFileDataObject for DnD in UTF8 locales with non-ASCII characters
wxMac:

View File

@@ -25,6 +25,7 @@
#include "wx/clipbrd.h"
#include "wx/colordlg.h"
#include "wx/metafile.h"
#include "wx/file.h"
#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
#include "../sample.xpm"
@@ -206,6 +207,7 @@ public:
void OnSize(wxSizeEvent& event);
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnOpenFile(wxCommandEvent& event);
void OnDrag(wxCommandEvent& event);
void OnDragMoveByDefault(wxCommandEvent& event);
void OnDragMoveAllow(wxCommandEvent& event);
@@ -793,6 +795,7 @@ enum
Menu_DragMoveAllow,
Menu_NewFrame,
Menu_About = 101,
Menu_OpenFile,
Menu_Help,
Menu_Clear,
Menu_Copy,
@@ -812,6 +815,7 @@ enum
BEGIN_EVENT_TABLE(DnDFrame, wxFrame)
EVT_MENU(Menu_Quit, DnDFrame::OnQuit)
EVT_MENU(Menu_About, DnDFrame::OnAbout)
EVT_MENU(Menu_OpenFile, DnDFrame::OnOpenFile)
EVT_MENU(Menu_Drag, DnDFrame::OnDrag)
EVT_MENU(Menu_DragMoveDef, DnDFrame::OnDragMoveByDefault)
EVT_MENU(Menu_DragMoveAllow,DnDFrame::OnDragMoveAllow)
@@ -904,7 +908,7 @@ bool DnDApp::OnInit()
// create the main frame window
DnDFrame *frame = new DnDFrame((wxFrame *) NULL,
_T("Drag-and-Drop/Clipboard wxWidgets Sample"),
10, 100, 650, 340);
10, 100, 750, 540);
// activate it
frame->Show(true);
@@ -940,6 +944,8 @@ DnDFrame::DnDFrame(wxFrame *frame, const wxChar *title, int x, int y, int w, int
file_menu->AppendSeparator();
file_menu->Append(Menu_NewFrame, _T("&New frame\tCtrl-N"));
file_menu->AppendSeparator();
file_menu->Append(Menu_OpenFile, _T("&Open file..."));
file_menu->AppendSeparator();
file_menu->Append(Menu_Quit, _T("E&xit\tCtrl-Q"));
#if wxUSE_LOG
@@ -1007,10 +1013,10 @@ DnDFrame::DnDFrame(wxFrame *frame, const wxChar *title, int x, int y, int w, int
sizer_top->Add(m_ctrlText, 1, wxEXPAND );
wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
sizer->Add(sizer_top, 1, wxEXPAND );
sizer->Add(sizer_top, 2, wxEXPAND );
#if wxUSE_LOG
sizer->Add(m_ctrlLog, 2, wxEXPAND);
sizer->SetItemMinSize(m_ctrlLog, 450, 0);
sizer->Add(m_ctrlLog, 1, wxEXPAND);
sizer->SetItemMinSize(m_ctrlLog, 450, 100);
#endif // wxUSE_LOG
sizer->AddSpacer(50);
@@ -1110,6 +1116,18 @@ void DnDFrame::OnDragMoveAllow(wxCommandEvent& event)
m_moveAllow = event.IsChecked();
}
void DnDFrame::OnOpenFile(wxCommandEvent& WXUNUSED(event))
{
wxFileDialog dialog(this, _T("Open a file"), wxEmptyString, wxEmptyString, _T("Files (*.*)|*.*"), wxFD_MULTIPLE);
if (dialog.ShowModal() == wxID_OK)
{
wxString str;
str.Printf( _T("File opened: %s"), dialog.GetPath().c_str() );
m_ctrlFile->Append( str );
}
}
void DnDFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxMessageBox(_T("Drag-&-Drop Demo\n")
@@ -1490,8 +1508,14 @@ bool DnDFile::OnDropFiles(wxCoord, wxCoord, const wxArrayString& filenames)
wxString str;
str.Printf( _T("%d files dropped"), (int)nFiles);
m_pOwner->Append(str);
for ( size_t n = 0; n < nFiles; n++ ) {
for ( size_t n = 0; n < nFiles; n++ )
{
m_pOwner->Append(filenames[n]);
if (wxFile::Exists(filenames[n]))
m_pOwner->Append(wxT(" This file exists.") );
else
m_pOwner->Append(wxT(" This file doesn't exist.") );
}
return true;

View File

@@ -255,48 +255,56 @@ size_t wxFileDataObject::GetDataSize() const
bool wxFileDataObject::SetData(size_t WXUNUSED(size), const void *buf)
{
// we get data in the text/uri-list format, i.e. as a sequence of URIs
// (filenames prefixed by "file:") delimited by "\r\n". size includes
// the trailing zero (in theory, not for Nautilus in early GNOME
// versions).
m_filenames.Empty();
// we get data in the text/uri-list format, i.e. as a sequence of URIs
// (filenames prefixed by "file:") delimited by "\r\n"
wxString filename;
for ( const char *p = (const char *)buf; ; p++ )
const gchar *nexttemp = (const gchar*) buf;
for ( ; ; )
{
// some broken programs (testdnd GTK+ sample!) omit the trailing
// "\r\n", so check for '\0' explicitly here instead of doing it in
// the loop statement to account for it
if ( (*p == '\r' && *(p+1) == '\n') || !*p )
int len = 0;
const gchar *temp = nexttemp;
for (;;)
{
size_t lenPrefix = 5; // strlen("file:")
if ( filename.Left(lenPrefix).MakeLower() == _T("file:") )
if (temp[len] == 0)
{
// sometimes the syntax is "file:filename", sometimes it's
// URL-like: "file://filename" - deal with both
if ( filename[lenPrefix] == _T('/') &&
filename[lenPrefix + 1] == _T('/') )
if (len > 0)
{
// skip the slashes
lenPrefix += 2;
// if an app omits '\r''\n'
nexttemp = temp+len;
break;
}
AddFile(wxURI::Unescape(filename.c_str() + lenPrefix));
filename.Empty();
return true;
}
else if ( !filename.empty() )
if (temp[len] == '\r')
{
wxLogDebug(_T("Unsupported URI \"%s\" in wxFileDataObject"),
filename.c_str());
if (temp[len+1] == '\n')
nexttemp = temp+len+2;
else
nexttemp = temp+len+1;
break;
}
len++;
}
if ( !*p )
if (len == 0)
break;
// skip '\r'
p++;
}
else
// required to give it a trailing zero
gchar *uri = g_strndup( temp, len );
gchar *fn = g_filename_from_uri( uri, NULL, NULL );
g_free( uri );
if (fn)
{
filename += *p;
AddFile( wxConvFileName->cMB2WX( fn ) );
g_free( fn );
}
}