WxUtils.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright 2009 Dolphin Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. #include <string>
  5. #include <wx/bitmap.h>
  6. #include <wx/image.h>
  7. #include <wx/msgdlg.h>
  8. #include <wx/mstream.h>
  9. #include <wx/toolbar.h>
  10. #include <wx/utils.h>
  11. #include "DolphinWX/WxUtils.h"
  12. #ifdef __APPLE__
  13. #import <AppKit/AppKit.h>
  14. #endif
  15. namespace WxUtils
  16. {
  17. // Launch a file according to its mime type
  18. void Launch(const std::string& filename)
  19. {
  20. if (! ::wxLaunchDefaultBrowser(StrToWxStr(filename)))
  21. {
  22. // WARN_LOG
  23. }
  24. }
  25. // Launch an file explorer window on a certain path
  26. void Explore(const std::string& path)
  27. {
  28. wxString wxPath = StrToWxStr(path);
  29. #ifndef _WIN32
  30. // Default to file
  31. if (! wxPath.Contains("://"))
  32. {
  33. wxPath = "file://" + wxPath;
  34. }
  35. #endif
  36. #ifdef __WXGTK__
  37. wxPath.Replace(" ", "\\ ");
  38. #endif
  39. if (! ::wxLaunchDefaultBrowser(wxPath))
  40. {
  41. // WARN_LOG
  42. }
  43. }
  44. void ShowErrorDialog(const wxString& error_msg)
  45. {
  46. wxMessageBox(error_msg, _("Error"), wxOK | wxICON_ERROR);
  47. }
  48. wxBitmap _wxGetBitmapFromMemory(const unsigned char* data, int length)
  49. {
  50. wxMemoryInputStream is(data, length);
  51. return(wxBitmap(wxImage(is, wxBITMAP_TYPE_ANY, -1), -1));
  52. }
  53. wxBitmap CreateDisabledButtonBitmap(const wxBitmap& original)
  54. {
  55. wxImage image = original.ConvertToImage();
  56. return wxBitmap(image.ConvertToDisabled(240));
  57. }
  58. void AddToolbarButton(wxToolBar* toolbar, int toolID, const wxString& label, const wxBitmap& bitmap, const wxString& shortHelp)
  59. {
  60. // Must explicitly set the disabled button bitmap because wxWidgets
  61. // incorrectly desaturates it instead of lightening it.
  62. toolbar->AddTool(toolID, label, bitmap, WxUtils::CreateDisabledButtonBitmap(bitmap), wxITEM_NORMAL, shortHelp);
  63. }
  64. } // namespace
  65. std::string WxStrToStr(const wxString& str)
  66. {
  67. return str.ToUTF8().data();
  68. }
  69. wxString StrToWxStr(const std::string& str)
  70. {
  71. //return wxString::FromUTF8Unchecked(str.c_str());
  72. return wxString::FromUTF8(str.c_str());
  73. }