You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
4.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2011 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright (C) 2017 KiCad Developers, see change_log.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <wx/image.h>
  25. #include <wx/bitmap.h>
  26. #include <wx/mstream.h>
  27. #include <wx/menu.h>
  28. #include <wx/menuitem.h>
  29. #include <common.h>
  30. #include <bitmaps.h>
  31. #include <pgm_base.h>
  32. wxBitmap KiBitmap( BITMAP_DEF aBitmap )
  33. {
  34. wxMemoryInputStream is( aBitmap->png, aBitmap->byteCount );
  35. wxImage image( is, wxBITMAP_TYPE_PNG );
  36. wxBitmap bitmap( image );
  37. return bitmap;
  38. }
  39. wxBitmap* KiBitmapNew( BITMAP_DEF aBitmap )
  40. {
  41. wxMemoryInputStream is( aBitmap->png, aBitmap->byteCount );
  42. wxImage image( is, wxBITMAP_TYPE_PNG );
  43. wxBitmap* bitmap = new wxBitmap( image );
  44. return bitmap;
  45. }
  46. wxMenuItem* AddMenuItem( wxMenu* aMenu, int aId, const wxString& aText,
  47. const wxBitmap& aImage, wxItemKind aType = wxITEM_NORMAL )
  48. {
  49. wxMenuItem* item;
  50. item = new wxMenuItem( aMenu, aId, aText, wxEmptyString, aType );
  51. // Retrieve the global applicaton show icon option:
  52. bool useImagesInMenus = Pgm().GetUseIconsInMenus();
  53. if( useImagesInMenus )
  54. {
  55. if( aType == wxITEM_CHECK )
  56. {
  57. #if defined( __WINDOWS__ )
  58. item->SetBitmaps( KiBitmap( checked_ok_xpm ), aImage );
  59. // A workaround to a strange bug on Windows, wx Widgets 3.0:
  60. // size of bitmaps is not taken in account for wxITEM_CHECK menu
  61. // unless we call SetFont
  62. item->SetFont(*wxNORMAL_FONT);
  63. #endif
  64. }
  65. else
  66. item->SetBitmap( aImage );
  67. }
  68. aMenu->Append( item );
  69. return item;
  70. }
  71. wxMenuItem* AddMenuItem( wxMenu* aMenu, int aId, const wxString& aText,
  72. const wxString& aHelpText, const wxBitmap& aImage,
  73. wxItemKind aType = wxITEM_NORMAL )
  74. {
  75. wxMenuItem* item;
  76. item = new wxMenuItem( aMenu, aId, aText, aHelpText, aType );
  77. // Retrieve the global applicaton show icon option:
  78. bool useImagesInMenus = Pgm().GetUseIconsInMenus();
  79. if( useImagesInMenus )
  80. {
  81. if( aType == wxITEM_CHECK )
  82. {
  83. #if defined( __WINDOWS__ )
  84. item->SetBitmaps( KiBitmap( checked_ok_xpm ), aImage );
  85. // A workaround to a strange bug on Windows, wx Widgets 3.0:
  86. // size of bitmaps is not taken in account for wxITEM_CHECK menu
  87. // unless we call SetFont
  88. item->SetFont(*wxNORMAL_FONT);
  89. #endif
  90. }
  91. else
  92. item->SetBitmap( aImage );
  93. }
  94. aMenu->Append( item );
  95. return item;
  96. }
  97. wxMenuItem* AddMenuItem( wxMenu* aMenu, wxMenu* aSubMenu, int aId,
  98. const wxString& aText, const wxBitmap& aImage )
  99. {
  100. wxMenuItem* item;
  101. item = new wxMenuItem( aMenu, aId, aText );
  102. item->SetSubMenu( aSubMenu );
  103. // Retrieve the global applicaton show icon option:
  104. bool useImagesInMenus = Pgm().GetUseIconsInMenus();
  105. if( useImagesInMenus )
  106. item->SetBitmap( aImage );
  107. aMenu->Append( item );
  108. return item;
  109. };
  110. wxMenuItem* AddMenuItem( wxMenu* aMenu, wxMenu* aSubMenu, int aId,
  111. const wxString& aText, const wxString& aHelpText,
  112. const wxBitmap& aImage )
  113. {
  114. wxMenuItem* item;
  115. item = new wxMenuItem( aMenu, aId, aText, aHelpText );
  116. item->SetSubMenu( aSubMenu );
  117. // Retrieve the global applicaton show icon option:
  118. bool useImagesInMenus = Pgm().GetUseIconsInMenus();
  119. if( useImagesInMenus )
  120. item->SetBitmap( aImage );
  121. aMenu->Append( item );
  122. return item;
  123. };