KiCad PCB EDA Suite
bitmap.cpp
Go to the documentation of this file.
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 
25 
26 #include <wx/image.h>
27 #include <wx/bitmap.h>
28 #include <wx/mstream.h>
29 #include <wx/menu.h>
30 #include <wx/menuitem.h>
31 
32 #include <common.h>
33 #include <bitmaps.h>
34 #include <pgm_base.h>
35 
36 wxBitmap KiBitmap( BITMAP_DEF aBitmap )
37 {
38  wxMemoryInputStream is( aBitmap->png, aBitmap->byteCount );
39  wxImage image( is, wxBITMAP_TYPE_PNG );
40  wxBitmap bitmap( image );
41 
42  return bitmap;
43 }
44 
45 
46 wxBitmap* KiBitmapNew( BITMAP_DEF aBitmap )
47 {
48  wxMemoryInputStream is( aBitmap->png, aBitmap->byteCount );
49  wxImage image( is, wxBITMAP_TYPE_PNG );
50  wxBitmap* bitmap = new wxBitmap( image );
51 
52  return bitmap;
53 }
54 
55 wxMenuItem* AddMenuItem( wxMenu* aMenu, int aId, const wxString& aText,
56  const wxBitmap& aImage, wxItemKind aType = wxITEM_NORMAL )
57 {
58  wxMenuItem* item;
59 
60  item = new wxMenuItem( aMenu, aId, aText, wxEmptyString, aType );
61 
62  // Retrieve the global applicaton show icon option:
63  bool useImagesInMenus = Pgm().GetUseIconsInMenus();
64 
65  if( useImagesInMenus )
66  {
67  if( aType == wxITEM_CHECK )
68  {
69  #if defined( __WINDOWS__ )
70  item->SetBitmaps( KiBitmap( checked_ok_xpm ), aImage );
71  // A workaround to a strange bug on Windows, wx Widgets 3.0:
72  // size of bitmaps is not taken in account for wxITEM_CHECK menu
73  // unless we call SetFont
74  item->SetFont(*wxNORMAL_FONT);
75  #endif
76  }
77  else
78  item->SetBitmap( aImage );
79  }
80 
81  aMenu->Append( item );
82 
83  return item;
84 }
85 
86 wxMenuItem* AddMenuItem( wxMenu* aMenu, int aId, const wxString& aText,
87  const wxString& aHelpText, const wxBitmap& aImage,
88  wxItemKind aType = wxITEM_NORMAL )
89 {
90  wxMenuItem* item;
91 
92  item = new wxMenuItem( aMenu, aId, aText, aHelpText, aType );
93 
94  // Retrieve the global applicaton show icon option:
95  bool useImagesInMenus = Pgm().GetUseIconsInMenus();
96 
97  if( useImagesInMenus )
98  {
99  if( aType == wxITEM_CHECK )
100  {
101  #if defined( __WINDOWS__ )
102  item->SetBitmaps( KiBitmap( checked_ok_xpm ), aImage );
103  // A workaround to a strange bug on Windows, wx Widgets 3.0:
104  // size of bitmaps is not taken in account for wxITEM_CHECK menu
105  // unless we call SetFont
106  item->SetFont(*wxNORMAL_FONT);
107  #endif
108  }
109  else
110  item->SetBitmap( aImage );
111  }
112 
113  aMenu->Append( item );
114 
115  return item;
116 }
117 
118 wxMenuItem* AddMenuItem( wxMenu* aMenu, wxMenu* aSubMenu, int aId,
119  const wxString& aText, const wxBitmap& aImage )
120 {
121  wxMenuItem* item;
122 
123  item = new wxMenuItem( aMenu, aId, aText );
124  item->SetSubMenu( aSubMenu );
125 
126  // Retrieve the global applicaton show icon option:
127  bool useImagesInMenus = Pgm().GetUseIconsInMenus();
128 
129  if( useImagesInMenus )
130  item->SetBitmap( aImage );
131 
132  aMenu->Append( item );
133 
134  return item;
135 };
136 
137 
138 wxMenuItem* AddMenuItem( wxMenu* aMenu, wxMenu* aSubMenu, int aId,
139  const wxString& aText, const wxString& aHelpText,
140  const wxBitmap& aImage )
141 {
142  wxMenuItem* item;
143 
144  item = new wxMenuItem( aMenu, aId, aText, aHelpText );
145  item->SetSubMenu( aSubMenu );
146 
147  // Retrieve the global applicaton show icon option:
148  bool useImagesInMenus = Pgm().GetUseIconsInMenus();
149 
150  if( useImagesInMenus )
151  item->SetBitmap( aImage );
152 
153  aMenu->Append( item );
154 
155  return item;
156 };
PNG memory record (file in memory).
Definition: bitmap_types.h:38
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:55
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
const unsigned char * png
Definition: bitmap_types.h:40
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
wxBitmap * KiBitmapNew(BITMAP_DEF aBitmap)
Function KiBitmapNew allocates a wxBitmap on heap from a memory record, held in a BITMAP_DEF...
Definition: bitmap.cpp:46
bool GetUseIconsInMenus()
Definition: pgm_base.h:328
see class PGM_BASE
The common library.