2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:43:35 +00:00
|
|
|
// Refer to the license.txt file included.
|
2009-03-20 19:12:04 +00:00
|
|
|
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <string>
|
2015-12-19 10:34:01 +00:00
|
|
|
#include <wx/app.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/bitmap.h>
|
2015-12-19 10:34:01 +00:00
|
|
|
#include <wx/gdicmn.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/image.h>
|
2014-07-25 01:46:46 +00:00
|
|
|
#include <wx/msgdlg.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/mstream.h>
|
2014-08-16 04:16:14 +00:00
|
|
|
#include <wx/toolbar.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/utils.h>
|
2009-03-20 19:12:04 +00:00
|
|
|
|
2015-12-19 10:34:01 +00:00
|
|
|
#include "Common/CommonPaths.h"
|
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DolphinWX/WxUtils.h"
|
2013-02-28 04:37:38 +00:00
|
|
|
|
2013-09-25 07:05:36 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#import <AppKit/AppKit.h>
|
|
|
|
#endif
|
|
|
|
|
2014-03-12 19:33:41 +00:00
|
|
|
namespace WxUtils
|
|
|
|
{
|
2009-03-20 19:12:04 +00:00
|
|
|
// Launch a file according to its mime type
|
2014-03-12 19:33:41 +00:00
|
|
|
void Launch(const std::string& filename)
|
2009-03-20 19:12:04 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (!::wxLaunchDefaultBrowser(StrToWxStr(filename)))
|
|
|
|
{
|
|
|
|
// WARN_LOG
|
|
|
|
}
|
2009-03-20 19:12:04 +00:00
|
|
|
}
|
2009-02-24 19:31:32 +00:00
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
// Launch an file explorer window on a certain path
|
2014-03-12 19:33:41 +00:00
|
|
|
void Explore(const std::string& path)
|
2009-03-20 19:12:04 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
wxString wxPath = StrToWxStr(path);
|
2013-10-09 20:18:33 +00:00
|
|
|
#ifndef _WIN32
|
2016-06-24 08:43:46 +00:00
|
|
|
// Default to file
|
|
|
|
if (!wxPath.Contains("://"))
|
|
|
|
{
|
|
|
|
wxPath = "file://" + wxPath;
|
|
|
|
}
|
2013-10-09 20:18:33 +00:00
|
|
|
#endif
|
2009-03-20 19:12:04 +00:00
|
|
|
|
2011-04-17 21:39:58 +00:00
|
|
|
#ifdef __WXGTK__
|
2016-06-24 08:43:46 +00:00
|
|
|
wxPath.Replace(" ", "\\ ");
|
2011-04-17 21:39:58 +00:00
|
|
|
#endif
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (!::wxLaunchDefaultBrowser(wxPath))
|
|
|
|
{
|
|
|
|
// WARN_LOG
|
|
|
|
}
|
2009-08-07 08:52:04 +00:00
|
|
|
}
|
|
|
|
|
2014-07-25 01:46:46 +00:00
|
|
|
void ShowErrorDialog(const wxString& error_msg)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
wxMessageBox(error_msg, _("Error"), wxOK | wxICON_ERROR);
|
2014-07-25 01:46:46 +00:00
|
|
|
}
|
|
|
|
|
2016-01-19 23:46:10 +00:00
|
|
|
wxBitmap LoadResourceBitmap(const std::string& name, const wxSize& padded_size)
|
2015-12-19 10:34:01 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
const std::string path_base = File::GetSysDirectory() + RESOURCES_DIR + DIR_SEP + name;
|
|
|
|
std::string path = path_base + ".png";
|
|
|
|
double scale_factor = 1.0;
|
2016-01-19 23:46:10 +00:00
|
|
|
#ifdef __APPLE__
|
2016-06-24 08:43:46 +00:00
|
|
|
if (wxTheApp->GetTopWindow()->GetContentScaleFactor() >= 2)
|
|
|
|
{
|
|
|
|
const std::string path_2x = path_base + "@2x.png";
|
|
|
|
if (File::Exists(path_2x))
|
|
|
|
{
|
|
|
|
path = path_2x;
|
|
|
|
scale_factor = 2.0;
|
|
|
|
}
|
|
|
|
}
|
2015-12-19 10:34:01 +00:00
|
|
|
#endif
|
2016-06-24 08:43:46 +00:00
|
|
|
wxImage image(StrToWxStr(path), wxBITMAP_TYPE_PNG);
|
|
|
|
|
|
|
|
if (padded_size != wxSize())
|
|
|
|
{
|
|
|
|
// Add padding if necessary (or crop, but images aren't supposed to be large enough to require
|
|
|
|
// that).
|
|
|
|
// The image will be left-aligned and vertically centered.
|
|
|
|
const wxSize scaled_padded_size = padded_size * scale_factor;
|
|
|
|
image.Resize(scaled_padded_size,
|
|
|
|
wxPoint(0, (scaled_padded_size.GetHeight() - image.GetHeight()) / 2));
|
|
|
|
}
|
2016-01-19 23:46:10 +00:00
|
|
|
|
2015-12-19 10:34:01 +00:00
|
|
|
#ifdef __APPLE__
|
2016-06-24 08:43:46 +00:00
|
|
|
return wxBitmap(image, -1, scale_factor);
|
2015-12-19 10:34:01 +00:00
|
|
|
#else
|
2016-06-24 08:43:46 +00:00
|
|
|
return wxBitmap(image);
|
2015-12-19 10:34:01 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-08-16 04:16:14 +00:00
|
|
|
wxBitmap CreateDisabledButtonBitmap(const wxBitmap& original)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
wxImage image = original.ConvertToImage();
|
|
|
|
return wxBitmap(image.ConvertToDisabled(240));
|
2014-08-16 04:16:14 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
void AddToolbarButton(wxToolBar* toolbar, int toolID, const wxString& label, const wxBitmap& bitmap,
|
|
|
|
const wxString& shortHelp)
|
2014-08-16 04:16:14 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// 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);
|
2014-08-16 04:16:14 +00:00
|
|
|
}
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
} // namespace
|
2013-02-28 04:37:38 +00:00
|
|
|
|
|
|
|
std::string WxStrToStr(const wxString& str)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return str.ToUTF8().data();
|
2013-02-28 04:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxString StrToWxStr(const std::string& str)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// return wxString::FromUTF8Unchecked(str.c_str());
|
|
|
|
return wxString::FromUTF8(str.c_str());
|
2013-02-28 04:37:38 +00:00
|
|
|
}
|