dolphin/Source/Core/DolphinWX/WxUtils.cpp

89 lines
1.9 KiB
C++
Raw Normal View History

// Copyright 2009 Dolphin Emulator Project
2015-05-17 23:08:10 +00:00
// Licensed under GPLv2+
// Refer to the license.txt file included.
2014-02-22 22:36:30 +00:00
#include <string>
#include <wx/bitmap.h>
#include <wx/image.h>
#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>
#include "DolphinWX/WxUtils.h"
2013-09-25 07:05:36 +00:00
#ifdef __APPLE__
#import <AppKit/AppKit.h>
#endif
namespace WxUtils
{
// Launch a file according to its mime type
void Launch(const std::string& filename)
{
if (! ::wxLaunchDefaultBrowser(StrToWxStr(filename)))
{
// WARN_LOG
}
}
// Launch an file explorer window on a certain path
void Explore(const std::string& path)
{
wxString wxPath = StrToWxStr(path);
#ifndef _WIN32
// Default to file
if (! wxPath.Contains("://"))
{
wxPath = "file://" + wxPath;
}
#endif
#ifdef __WXGTK__
wxPath.Replace(" ", "\\ ");
#endif
if (! ::wxLaunchDefaultBrowser(wxPath))
{
// WARN_LOG
}
}
void ShowErrorDialog(const wxString& error_msg)
{
wxMessageBox(error_msg, _("Error"), wxOK | wxICON_ERROR);
}
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));
}
2014-08-16 04:16:14 +00: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);
}
} // namespace
std::string WxStrToStr(const wxString& str)
{
2013-02-28 09:11:10 +00:00
return str.ToUTF8().data();
}
wxString StrToWxStr(const std::string& str)
{
2013-02-28 09:11:10 +00:00
//return wxString::FromUTF8Unchecked(str.c_str());
return wxString::FromUTF8(str.c_str());
}