2013-04-18 03:43:35 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// 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>
|
|
|
|
#include <wx/bitmap.h>
|
|
|
|
#include <wx/chartype.h>
|
|
|
|
#include <wx/gdicmn.h>
|
|
|
|
#include <wx/image.h>
|
|
|
|
#include <wx/mstream.h>
|
2009-02-24 19:31:32 +00:00
|
|
|
#include <wx/string.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/utils.h>
|
2009-03-20 19:12:04 +00:00
|
|
|
|
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
|
|
|
|
|
2009-02-24 19:31:32 +00:00
|
|
|
namespace WxUtils {
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
// Launch a file according to its mime type
|
|
|
|
void Launch(const char *filename)
|
|
|
|
{
|
2013-02-28 04:37:38 +00:00
|
|
|
if (! ::wxLaunchDefaultBrowser(StrToWxStr(filename)))
|
2010-01-13 06:34:34 +00:00
|
|
|
{
|
2009-03-20 19:12:04 +00:00
|
|
|
// WARN_LOG
|
2009-02-24 19:31:32 +00:00
|
|
|
}
|
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
|
|
|
|
void Explore(const char *path)
|
|
|
|
{
|
2013-02-28 04:37:38 +00:00
|
|
|
wxString wxPath = StrToWxStr(path);
|
2013-10-09 20:18:33 +00:00
|
|
|
#ifndef _WIN32
|
2009-03-20 19:12:04 +00:00
|
|
|
// Default to file
|
2010-01-13 06:34:34 +00:00
|
|
|
if (! wxPath.Contains(wxT("://")))
|
|
|
|
{
|
2009-03-20 19:12:04 +00:00
|
|
|
wxPath = wxT("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__
|
|
|
|
wxPath.Replace(wxT(" "), wxT("\\ "));
|
|
|
|
#endif
|
|
|
|
|
2010-01-13 06:34:34 +00:00
|
|
|
if (! ::wxLaunchDefaultBrowser(wxPath))
|
2009-08-07 08:52:04 +00:00
|
|
|
{
|
2010-01-13 06:34:34 +00:00
|
|
|
// WARN_LOG
|
2009-08-07 08:52:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-25 07:05:36 +00:00
|
|
|
double GetCurrentBitmapLogicalScale()
|
|
|
|
{
|
|
|
|
#ifdef __APPLE__
|
|
|
|
// wx doesn't expose this itself, unfortunately.
|
2014-02-27 17:28:00 +00:00
|
|
|
if ([[NSScreen mainScreen] respondsToSelector:@selector(backingScaleFactor)])
|
2013-09-25 07:05:36 +00:00
|
|
|
{
|
2014-02-27 17:28:00 +00:00
|
|
|
return [[NSScreen mainScreen] backingScaleFactor];
|
2013-09-25 07:05:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
2014-02-22 22:36:30 +00:00
|
|
|
wxBitmap _wxGetBitmapFromMemory(const unsigned char* data, int length)
|
|
|
|
{
|
|
|
|
wxMemoryInputStream is(data, length);
|
|
|
|
return(wxBitmap(wxImage(is, wxBITMAP_TYPE_ANY, -1), -1));
|
|
|
|
}
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
} // namespace
|
2013-02-28 04:37:38 +00:00
|
|
|
|
|
|
|
std::string WxStrToStr(const wxString& str)
|
|
|
|
{
|
2013-02-28 09:11:10 +00:00
|
|
|
return str.ToUTF8().data();
|
2013-02-28 04:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxString StrToWxStr(const std::string& str)
|
|
|
|
{
|
2013-02-28 09:11:10 +00:00
|
|
|
//return wxString::FromUTF8Unchecked(str.c_str());
|
2013-02-28 04:37:38 +00:00
|
|
|
return wxString::FromUTF8(str.c_str());
|
|
|
|
}
|