From e581b729559003bc4c050e8370699d0f42341d05 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Thu, 17 May 2018 19:42:43 +0200 Subject: [PATCH] Look in multiple paths when searching for resource files of samples When using an out of source build, the files are not in the default wxWidgets directories. Also search in the current directory, parent directory and sample sub-directories. Closes https://trac.wxwidgets.org/ticket/18118 --- samples/drawing/drawing.cpp | 3 ++- samples/html/help/help.cpp | 10 ++++++++-- samples/webview/webview.cpp | 12 +++++++++--- samples/widgets/statbmp.cpp | 8 +++++++- samples/widgets/textctrl.cpp | 1 + 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index a4c6a40a00..563a8b13a1 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -413,7 +413,8 @@ bool MyApp::LoadImages() pathList.Add(wxFileName(argv[0]).GetPath()); pathList.Add(wxT(".")); pathList.Add(wxT("..")); - pathList.Add(wxT("../..")); + pathList.Add(wxT("../drawing")); + pathList.Add(wxT("../../../samples/drawing")); wxString path = pathList.FindValidPath(wxT("pat4.bmp")); if ( !path ) diff --git a/samples/html/help/help.cpp b/samples/html/help/help.cpp index a3746f333a..3833ed2255 100644 --- a/samples/html/help/help.cpp +++ b/samples/html/help/help.cpp @@ -163,10 +163,16 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) help.UseConfig(wxConfig::Get()); bool ret; help.SetTempDir(wxT(".")); - ret = help.AddBook(wxFileName(wxT("helpfiles/testing.hhp"), wxPATH_UNIX)); + + wxPathList pathlist; + pathlist.Add(wxT("./helpfiles")); + pathlist.Add(wxT("../helpfiles")); + pathlist.Add(wxT("../../html/help/helpfiles")); + + ret = help.AddBook(wxFileName(pathlist.FindValidPath(wxT("testing.hhp")), wxPATH_UNIX)); if (! ret) wxMessageBox(wxT("Failed adding book helpfiles/testing.hhp")); - ret = help.AddBook(wxFileName(wxT("helpfiles/another.hhp"), wxPATH_UNIX)); + ret = help.AddBook(wxFileName(pathlist.FindValidPath(wxT("another.hhp")), wxPATH_UNIX)); if (! ret) wxMessageBox(_("Failed adding book helpfiles/another.hhp")); } diff --git a/samples/webview/webview.cpp b/samples/webview/webview.cpp index 362f2bc60b..856169e195 100644 --- a/samples/webview/webview.cpp +++ b/samples/webview/webview.cpp @@ -263,7 +263,7 @@ bool WebApp::OnInit() // Create the memory files wxImage::AddHandler(new wxPNGHandler); - wxMemoryFSHandler::AddFile("logo.png", + wxMemoryFSHandler::AddFile("logo.png", wxBitmap(wxlogo_xpm), wxBITMAP_TYPE_PNG); wxMemoryFSHandler::AddFile("page1.htm", "File System Example" @@ -741,7 +741,13 @@ void WebFrame::OnMode(wxCommandEvent& WXUNUSED(evt)) void WebFrame::OnLoadScheme(wxCommandEvent& WXUNUSED(evt)) { - wxFileName helpfile("../help/doc.zip"); + wxPathList pathlist; + pathlist.Add(wxT(".")); + pathlist.Add(wxT("..")); + pathlist.Add(wxT("../help")); + pathlist.Add(wxT("../../../samples/help")); + + wxFileName helpfile(pathlist.FindValidPath(wxT("doc.zip"))); helpfile.MakeAbsolute(); wxString path = helpfile.GetFullPath(); //Under MSW we need to flip the slashes @@ -1207,7 +1213,7 @@ void WebFrame::OnSelectAll(wxCommandEvent& WXUNUSED(evt)) * Callback invoked when a loading error occurs */ void WebFrame::OnError(wxWebViewEvent& evt) -{ +{ #define WX_ERROR_CASE(type) \ case type: \ category = #type; \ diff --git a/samples/widgets/statbmp.cpp b/samples/widgets/statbmp.cpp index ad100b0df8..08a69c6952 100644 --- a/samples/widgets/statbmp.cpp +++ b/samples/widgets/statbmp.cpp @@ -90,7 +90,13 @@ void StatBmpWidgetsPage::CreateContent() wxString testImage; #if wxUSE_LIBPNG - wxFileName fn("../image/toucan.png"); + wxPathList pathlist; + pathlist.Add(wxT(".")); + pathlist.Add(wxT("..")); + pathlist.Add(wxT("../image")); + pathlist.Add(wxT("../../../samples/image")); + + wxFileName fn(pathlist.FindValidPath(wxT("toucan.png"))); if ( fn.FileExists() ) testImage = fn.GetFullPath(); #endif // wxUSE_LIBPNG diff --git a/samples/widgets/textctrl.cpp b/samples/widgets/textctrl.cpp index d6e2d54f28..c89ba6ca93 100644 --- a/samples/widgets/textctrl.cpp +++ b/samples/widgets/textctrl.cpp @@ -913,6 +913,7 @@ void TextWidgetsPage::OnButtonLoad(wxCommandEvent& WXUNUSED(event)) wxPathList pathlist; pathlist.Add(wxT(".")); pathlist.Add(wxT("..")); + pathlist.Add(wxT("../widgets")); pathlist.Add(wxT("../../../samples/widgets")); wxString filename = pathlist.FindValidPath(wxT("textctrl.cpp"));