2013-04-17 21:43:35 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2009-03-20 13:12:04 -06:00
|
|
|
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <string>
|
|
|
|
#include <wx/bitmap.h>
|
|
|
|
#include <wx/chartype.h>
|
|
|
|
#include <wx/gdicmn.h>
|
|
|
|
#include <wx/image.h>
|
2014-07-24 19:46:46 -06:00
|
|
|
#include <wx/msgdlg.h>
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <wx/mstream.h>
|
2009-02-24 12:31:32 -07:00
|
|
|
#include <wx/string.h>
|
2014-08-15 22:16:14 -06:00
|
|
|
#include <wx/toolbar.h>
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <wx/utils.h>
|
2009-03-20 13:12:04 -06:00
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "DolphinWX/WxUtils.h"
|
2013-02-27 21:37:38 -07:00
|
|
|
|
2013-09-25 01:05:36 -06:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#import <AppKit/AppKit.h>
|
|
|
|
#endif
|
|
|
|
|
2014-03-12 13:33:41 -06:00
|
|
|
namespace WxUtils
|
|
|
|
{
|
2009-02-24 12:31:32 -07:00
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
// Launch a file according to its mime type
|
2014-03-12 13:33:41 -06:00
|
|
|
void Launch(const std::string& filename)
|
2009-03-20 13:12:04 -06:00
|
|
|
{
|
2013-02-27 21:37:38 -07:00
|
|
|
if (! ::wxLaunchDefaultBrowser(StrToWxStr(filename)))
|
2010-01-12 23:34:34 -07:00
|
|
|
{
|
2009-03-20 13:12:04 -06:00
|
|
|
// WARN_LOG
|
2009-02-24 12:31:32 -07:00
|
|
|
}
|
2009-03-20 13:12:04 -06:00
|
|
|
}
|
2009-02-24 12:31:32 -07:00
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
// Launch an file explorer window on a certain path
|
2014-03-12 13:33:41 -06:00
|
|
|
void Explore(const std::string& path)
|
2009-03-20 13:12:04 -06:00
|
|
|
{
|
2013-02-27 21:37:38 -07:00
|
|
|
wxString wxPath = StrToWxStr(path);
|
2013-10-09 14:18:33 -06:00
|
|
|
#ifndef _WIN32
|
2009-03-20 13:12:04 -06:00
|
|
|
// Default to file
|
2014-05-17 11:17:28 -06:00
|
|
|
if (! wxPath.Contains("://"))
|
2010-01-12 23:34:34 -07:00
|
|
|
{
|
2014-05-17 11:17:28 -06:00
|
|
|
wxPath = "file://" + wxPath;
|
2009-03-20 13:12:04 -06:00
|
|
|
}
|
2013-10-09 14:18:33 -06:00
|
|
|
#endif
|
2009-03-20 13:12:04 -06:00
|
|
|
|
2011-04-17 15:39:58 -06:00
|
|
|
#ifdef __WXGTK__
|
2014-05-17 11:17:28 -06:00
|
|
|
wxPath.Replace(" ", "\\ ");
|
2011-04-17 15:39:58 -06:00
|
|
|
#endif
|
|
|
|
|
2010-01-12 23:34:34 -07:00
|
|
|
if (! ::wxLaunchDefaultBrowser(wxPath))
|
2009-08-07 02:52:04 -06:00
|
|
|
{
|
2010-01-12 23:34:34 -07:00
|
|
|
// WARN_LOG
|
2009-08-07 02:52:04 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-24 19:46:46 -06:00
|
|
|
void ShowErrorDialog(const wxString& error_msg)
|
|
|
|
{
|
|
|
|
wxMessageBox(error_msg, _("Error"), wxOK | wxICON_ERROR);
|
|
|
|
}
|
|
|
|
|
2014-02-22 15:36:30 -07:00
|
|
|
wxBitmap _wxGetBitmapFromMemory(const unsigned char* data, int length)
|
|
|
|
{
|
|
|
|
wxMemoryInputStream is(data, length);
|
|
|
|
return(wxBitmap(wxImage(is, wxBITMAP_TYPE_ANY, -1), -1));
|
|
|
|
}
|
|
|
|
|
2014-08-15 22:16:14 -06:00
|
|
|
wxBitmap CreateDisabledButtonBitmap(const wxBitmap& original)
|
|
|
|
{
|
|
|
|
wxImage image = original.ConvertToImage();
|
|
|
|
return wxBitmap(image.ConvertToDisabled(240));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddToolbarButton(wxToolBar* toolbar, int toolID, const wxString& label, const wxBitmap& bitmap, const wxString& shortHelp)
|
|
|
|
{
|
|
|
|
// Must explicitly set the disabled button bitmap because wxWidgets
|
|
|
|
// incorrectly desaturates it instead of lightening it.
|
|
|
|
toolbar->AddTool(toolID, label, bitmap, WxUtils::CreateDisabledButtonBitmap(bitmap), wxITEM_NORMAL, shortHelp);
|
|
|
|
}
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
} // namespace
|
2013-02-27 21:37:38 -07:00
|
|
|
|
|
|
|
std::string WxStrToStr(const wxString& str)
|
|
|
|
{
|
2013-02-28 02:11:10 -07:00
|
|
|
return str.ToUTF8().data();
|
2013-02-27 21:37:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
wxString StrToWxStr(const std::string& str)
|
|
|
|
{
|
2013-02-28 02:11:10 -07:00
|
|
|
//return wxString::FromUTF8Unchecked(str.c_str());
|
2013-02-27 21:37:38 -07:00
|
|
|
return wxString::FromUTF8(str.c_str());
|
|
|
|
}
|