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:
@@ -175,6 +175,9 @@ wxGTK:
|
|||||||
- Fixed crash in settings when using tooltips->tip_window with GTK+ 2.11.6.
|
- Fixed crash in settings when using tooltips->tip_window with GTK+ 2.11.6.
|
||||||
- Fix WX_GL_STEREO attribute handling (Tristan Mehamli)
|
- Fix WX_GL_STEREO attribute handling (Tristan Mehamli)
|
||||||
- Fix wxThread::SetPriority() when the thread is running (Christos Gourdoupis)
|
- 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:
|
wxMac:
|
||||||
|
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
#include "wx/clipbrd.h"
|
#include "wx/clipbrd.h"
|
||||||
#include "wx/colordlg.h"
|
#include "wx/colordlg.h"
|
||||||
#include "wx/metafile.h"
|
#include "wx/metafile.h"
|
||||||
|
#include "wx/file.h"
|
||||||
|
|
||||||
#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
|
#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
|
||||||
#include "../sample.xpm"
|
#include "../sample.xpm"
|
||||||
@@ -206,6 +207,7 @@ public:
|
|||||||
void OnSize(wxSizeEvent& event);
|
void OnSize(wxSizeEvent& event);
|
||||||
void OnQuit(wxCommandEvent& event);
|
void OnQuit(wxCommandEvent& event);
|
||||||
void OnAbout(wxCommandEvent& event);
|
void OnAbout(wxCommandEvent& event);
|
||||||
|
void OnOpenFile(wxCommandEvent& event);
|
||||||
void OnDrag(wxCommandEvent& event);
|
void OnDrag(wxCommandEvent& event);
|
||||||
void OnDragMoveByDefault(wxCommandEvent& event);
|
void OnDragMoveByDefault(wxCommandEvent& event);
|
||||||
void OnDragMoveAllow(wxCommandEvent& event);
|
void OnDragMoveAllow(wxCommandEvent& event);
|
||||||
@@ -793,6 +795,7 @@ enum
|
|||||||
Menu_DragMoveAllow,
|
Menu_DragMoveAllow,
|
||||||
Menu_NewFrame,
|
Menu_NewFrame,
|
||||||
Menu_About = 101,
|
Menu_About = 101,
|
||||||
|
Menu_OpenFile,
|
||||||
Menu_Help,
|
Menu_Help,
|
||||||
Menu_Clear,
|
Menu_Clear,
|
||||||
Menu_Copy,
|
Menu_Copy,
|
||||||
@@ -812,6 +815,7 @@ enum
|
|||||||
BEGIN_EVENT_TABLE(DnDFrame, wxFrame)
|
BEGIN_EVENT_TABLE(DnDFrame, wxFrame)
|
||||||
EVT_MENU(Menu_Quit, DnDFrame::OnQuit)
|
EVT_MENU(Menu_Quit, DnDFrame::OnQuit)
|
||||||
EVT_MENU(Menu_About, DnDFrame::OnAbout)
|
EVT_MENU(Menu_About, DnDFrame::OnAbout)
|
||||||
|
EVT_MENU(Menu_OpenFile, DnDFrame::OnOpenFile)
|
||||||
EVT_MENU(Menu_Drag, DnDFrame::OnDrag)
|
EVT_MENU(Menu_Drag, DnDFrame::OnDrag)
|
||||||
EVT_MENU(Menu_DragMoveDef, DnDFrame::OnDragMoveByDefault)
|
EVT_MENU(Menu_DragMoveDef, DnDFrame::OnDragMoveByDefault)
|
||||||
EVT_MENU(Menu_DragMoveAllow,DnDFrame::OnDragMoveAllow)
|
EVT_MENU(Menu_DragMoveAllow,DnDFrame::OnDragMoveAllow)
|
||||||
@@ -904,7 +908,7 @@ bool DnDApp::OnInit()
|
|||||||
// create the main frame window
|
// create the main frame window
|
||||||
DnDFrame *frame = new DnDFrame((wxFrame *) NULL,
|
DnDFrame *frame = new DnDFrame((wxFrame *) NULL,
|
||||||
_T("Drag-and-Drop/Clipboard wxWidgets Sample"),
|
_T("Drag-and-Drop/Clipboard wxWidgets Sample"),
|
||||||
10, 100, 650, 340);
|
10, 100, 750, 540);
|
||||||
|
|
||||||
// activate it
|
// activate it
|
||||||
frame->Show(true);
|
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->AppendSeparator();
|
||||||
file_menu->Append(Menu_NewFrame, _T("&New frame\tCtrl-N"));
|
file_menu->Append(Menu_NewFrame, _T("&New frame\tCtrl-N"));
|
||||||
file_menu->AppendSeparator();
|
file_menu->AppendSeparator();
|
||||||
|
file_menu->Append(Menu_OpenFile, _T("&Open file..."));
|
||||||
|
file_menu->AppendSeparator();
|
||||||
file_menu->Append(Menu_Quit, _T("E&xit\tCtrl-Q"));
|
file_menu->Append(Menu_Quit, _T("E&xit\tCtrl-Q"));
|
||||||
|
|
||||||
#if wxUSE_LOG
|
#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 );
|
sizer_top->Add(m_ctrlText, 1, wxEXPAND );
|
||||||
|
|
||||||
wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
|
wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
|
||||||
sizer->Add(sizer_top, 1, wxEXPAND );
|
sizer->Add(sizer_top, 2, wxEXPAND );
|
||||||
#if wxUSE_LOG
|
#if wxUSE_LOG
|
||||||
sizer->Add(m_ctrlLog, 2, wxEXPAND);
|
sizer->Add(m_ctrlLog, 1, wxEXPAND);
|
||||||
sizer->SetItemMinSize(m_ctrlLog, 450, 0);
|
sizer->SetItemMinSize(m_ctrlLog, 450, 100);
|
||||||
#endif // wxUSE_LOG
|
#endif // wxUSE_LOG
|
||||||
sizer->AddSpacer(50);
|
sizer->AddSpacer(50);
|
||||||
|
|
||||||
@@ -1110,6 +1116,18 @@ void DnDFrame::OnDragMoveAllow(wxCommandEvent& event)
|
|||||||
m_moveAllow = event.IsChecked();
|
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))
|
void DnDFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
wxMessageBox(_T("Drag-&-Drop Demo\n")
|
wxMessageBox(_T("Drag-&-Drop Demo\n")
|
||||||
@@ -1490,8 +1508,14 @@ bool DnDFile::OnDropFiles(wxCoord, wxCoord, const wxArrayString& filenames)
|
|||||||
wxString str;
|
wxString str;
|
||||||
str.Printf( _T("%d files dropped"), (int)nFiles);
|
str.Printf( _T("%d files dropped"), (int)nFiles);
|
||||||
m_pOwner->Append(str);
|
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]);
|
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;
|
return true;
|
||||||
|
@@ -255,48 +255,56 @@ size_t wxFileDataObject::GetDataSize() const
|
|||||||
|
|
||||||
bool wxFileDataObject::SetData(size_t WXUNUSED(size), const void *buf)
|
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();
|
m_filenames.Empty();
|
||||||
|
|
||||||
// we get data in the text/uri-list format, i.e. as a sequence of URIs
|
const gchar *nexttemp = (const gchar*) buf;
|
||||||
// (filenames prefixed by "file:") delimited by "\r\n"
|
for ( ; ; )
|
||||||
wxString filename;
|
|
||||||
for ( const char *p = (const char *)buf; ; p++ )
|
|
||||||
{
|
{
|
||||||
// some broken programs (testdnd GTK+ sample!) omit the trailing
|
int len = 0;
|
||||||
// "\r\n", so check for '\0' explicitly here instead of doing it in
|
const gchar *temp = nexttemp;
|
||||||
// the loop statement to account for it
|
for (;;)
|
||||||
if ( (*p == '\r' && *(p+1) == '\n') || !*p )
|
|
||||||
{
|
{
|
||||||
size_t lenPrefix = 5; // strlen("file:")
|
if (temp[len] == 0)
|
||||||
if ( filename.Left(lenPrefix).MakeLower() == _T("file:") )
|
|
||||||
{
|
{
|
||||||
// sometimes the syntax is "file:filename", sometimes it's
|
if (len > 0)
|
||||||
// URL-like: "file://filename" - deal with both
|
|
||||||
if ( filename[lenPrefix] == _T('/') &&
|
|
||||||
filename[lenPrefix + 1] == _T('/') )
|
|
||||||
{
|
{
|
||||||
// skip the slashes
|
// if an app omits '\r''\n'
|
||||||
lenPrefix += 2;
|
nexttemp = temp+len;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddFile(wxURI::Unescape(filename.c_str() + lenPrefix));
|
return true;
|
||||||
filename.Empty();
|
|
||||||
}
|
}
|
||||||
else if ( !filename.empty() )
|
if (temp[len] == '\r')
|
||||||
{
|
{
|
||||||
wxLogDebug(_T("Unsupported URI \"%s\" in wxFileDataObject"),
|
if (temp[len+1] == '\n')
|
||||||
filename.c_str());
|
nexttemp = temp+len+2;
|
||||||
|
else
|
||||||
|
nexttemp = temp+len+1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !*p )
|
if (len == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// skip '\r'
|
// required to give it a trailing zero
|
||||||
p++;
|
gchar *uri = g_strndup( temp, len );
|
||||||
}
|
|
||||||
else
|
gchar *fn = g_filename_from_uri( uri, NULL, NULL );
|
||||||
|
|
||||||
|
g_free( uri );
|
||||||
|
|
||||||
|
if (fn)
|
||||||
{
|
{
|
||||||
filename += *p;
|
AddFile( wxConvFileName->cMB2WX( fn ) );
|
||||||
|
g_free( fn );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user