1
///////////////////////////////////////////////////////////////////////////////
2
// Name: src/common/arttango.cpp
3
// Purpose: art provider using embedded PNG versions of Tango icons
4
// Author: Vadim Zeitlin
6
// Copyright: (c) 2010 Vadim Zeitlin <vadim@wxwidgets.org>
7
// Licence: wxWindows licence
8
///////////////////////////////////////////////////////////////////////////////
10
// ============================================================================
12
// ============================================================================
14
// ----------------------------------------------------------------------------
16
// ----------------------------------------------------------------------------
18
// for compilers that support precompilation, includes "wx.h".
19
#include "wx/wxprec.h"
25
#if wxUSE_ARTPROVIDER_TANGO
32
#include "wx/artprov.h"
34
#include "wx/mstream.h"
36
// ----------------------------------------------------------------------------
38
// ----------------------------------------------------------------------------
40
// All files in art/tango in alphabetical order:
41
#include "../../art/tango/application_x_executable.h"
42
#include "../../art/tango/dialog_error.h"
43
#include "../../art/tango/dialog_information.h"
44
#include "../../art/tango/dialog_warning.h"
45
#include "../../art/tango/document_new.h"
46
#include "../../art/tango/document_open.h"
47
#include "../../art/tango/document_print.h"
48
#include "../../art/tango/document_save.h"
49
#include "../../art/tango/document_save_as.h"
50
#include "../../art/tango/drive_harddisk.h"
51
#include "../../art/tango/drive_optical.h"
52
#include "../../art/tango/drive_removable_media.h"
53
#include "../../art/tango/edit_copy.h"
54
#include "../../art/tango/edit_cut.h"
55
#include "../../art/tango/edit_delete.h"
56
#include "../../art/tango/edit_find.h"
57
#include "../../art/tango/edit_find_replace.h"
58
#include "../../art/tango/edit_paste.h"
59
#include "../../art/tango/edit_redo.h"
60
#include "../../art/tango/edit_undo.h"
61
#include "../../art/tango/folder.h"
62
#include "../../art/tango/folder_new.h"
63
#include "../../art/tango/folder_open.h"
64
#include "../../art/tango/go_down.h"
65
#include "../../art/tango/go_first.h"
66
#include "../../art/tango/go_home.h"
67
#include "../../art/tango/go_last.h"
68
#include "../../art/tango/go_next.h"
69
#include "../../art/tango/go_previous.h"
70
#include "../../art/tango/go_up.h"
71
#include "../../art/tango/image_missing.h"
72
#include "../../art/tango/text_x_generic.h"
73
#include "../../art/tango/list_add.h"
74
#include "../../art/tango/list_remove.h"
76
// ----------------------------------------------------------------------------
78
// ----------------------------------------------------------------------------
83
class wxTangoArtProvider : public wxArtProvider
88
m_imageHandledAdded = false;
92
virtual wxBitmap CreateBitmap(const wxArtID& id,
93
const wxArtClient& client,
97
bool m_imageHandledAdded;
99
wxDECLARE_NO_COPY_CLASS(wxTangoArtProvider);
102
} // anonymous namespace
104
// ============================================================================
106
// ============================================================================
109
wxTangoArtProvider::CreateBitmap(const wxArtID& id,
110
const wxArtClient& client,
111
const wxSize& sizeHint)
113
// Array indexed by the id names with pointers to image data in 16 and 32
114
// pixel sizes as values. The order of the elements in this array is the
115
// same as the definition order in wx/artprov.h. While it's not very
116
// logical, this should make it simpler to add new icons later. Notice that
117
// most elements without Tango equivalents are simply omitted.
119
// To avoid repetition use BITMAP_DATA to only specify the image name once
120
// (this is especially important if we decide to add more image sizes
122
#define BITMAP_ARRAY_NAME(name, size) \
123
name ## _ ## size ## x ## size ## _png
124
#define BITMAP_DATA_FOR_SIZE(name, size) \
125
BITMAP_ARRAY_NAME(name, size), sizeof(BITMAP_ARRAY_NAME(name, size))
126
#define BITMAP_DATA(name) \
127
BITMAP_DATA_FOR_SIZE(name, 16), BITMAP_DATA_FOR_SIZE(name, 24)
129
static const struct BitmapEntry
132
const unsigned char *data16;
134
const unsigned char *data24;
138
// Tango does have bookmark-new but no matching bookmark-delete and
139
// using mismatching icons would be ugly so we don't provide this one
140
// neither, we should add both of them if Tango ever adds the other one.
141
//{ wxART_ADD_BOOKMARK, BITMAP_DATA(bookmark_new)},
142
//{ wxART_DEL_BOOKMARK, BITMAP_DATA() },
144
{ wxART_GO_BACK, BITMAP_DATA(go_previous) },
145
{ wxART_GO_FORWARD, BITMAP_DATA(go_next) },
146
{ wxART_GO_UP, BITMAP_DATA(go_up) },
147
{ wxART_GO_DOWN, BITMAP_DATA(go_down) },
148
// wxART_GO_TO_PARENT doesn't seem to exist in Tango
149
{ wxART_GO_HOME, BITMAP_DATA(go_home) },
150
{ wxART_GOTO_FIRST, BITMAP_DATA(go_first) },
151
{ wxART_GOTO_LAST, BITMAP_DATA(go_last) },
153
{ wxART_FILE_OPEN, BITMAP_DATA(document_open) },
154
{ wxART_FILE_SAVE, BITMAP_DATA(document_save) },
155
{ wxART_FILE_SAVE_AS, BITMAP_DATA(document_save_as) },
156
{ wxART_PRINT, BITMAP_DATA(document_print) },
158
// Should we use help-browser for wxART_HELP?
160
{ wxART_NEW_DIR, BITMAP_DATA(folder_new) },
161
{ wxART_HARDDISK, BITMAP_DATA(drive_harddisk) },
162
// drive-removable-media seems to be better than media-floppy
163
{ wxART_FLOPPY, BITMAP_DATA(drive_removable_media) },
164
{ wxART_CDROM, BITMAP_DATA(drive_optical) },
165
{ wxART_REMOVABLE, BITMAP_DATA(drive_removable_media) },
167
{ wxART_FOLDER, BITMAP_DATA(folder) },
168
{ wxART_FOLDER_OPEN, BITMAP_DATA(folder_open) },
169
// wxART_GO_DIR_UP doesn't seem to exist in Tango
171
{ wxART_EXECUTABLE_FILE, BITMAP_DATA(application_x_executable) },
172
{ wxART_NORMAL_FILE, BITMAP_DATA(text_x_generic) },
174
// There is no dialog-question in Tango so use the information icon
175
// too, this is better for consistency and we do have a precedent for
176
// doing this as Windows Vista/7 does the same thing natively.
177
{ wxART_ERROR, BITMAP_DATA(dialog_error) },
178
{ wxART_QUESTION, BITMAP_DATA(dialog_information) },
179
{ wxART_WARNING, BITMAP_DATA(dialog_warning) },
180
{ wxART_INFORMATION, BITMAP_DATA(dialog_information) },
182
{ wxART_MISSING_IMAGE, BITMAP_DATA(image_missing) },
184
{ wxART_COPY, BITMAP_DATA(edit_copy) },
185
{ wxART_CUT, BITMAP_DATA(edit_cut) },
186
{ wxART_PASTE, BITMAP_DATA(edit_paste) },
187
{ wxART_DELETE, BITMAP_DATA(edit_delete) },
188
{ wxART_NEW, BITMAP_DATA(document_new) },
189
{ wxART_UNDO, BITMAP_DATA(edit_undo) },
190
{ wxART_REDO, BITMAP_DATA(edit_redo) },
192
{ wxART_PLUS, BITMAP_DATA(list_add) },
193
{ wxART_MINUS, BITMAP_DATA(list_remove) },
195
// Surprisingly Tango doesn't seem to have neither wxART_CLOSE nor
196
// wxART_QUIT. We could use system-log-out for the latter but it
197
// doesn't seem quite right.
199
{ wxART_FIND, BITMAP_DATA(edit_find) },
200
{ wxART_FIND_AND_REPLACE, BITMAP_DATA(edit_find_replace) },
203
#undef BITMAP_ARRAY_NAME
204
#undef BITMAP_DATA_FOR_SIZE
207
for ( unsigned n = 0; n < WXSIZEOF(s_allBitmaps); n++ )
209
const BitmapEntry& entry = s_allBitmaps[n];
210
if ( entry.id != id )
213
// This is one of the bitmaps that we have, determine in which size we
218
if ( sizeHint == wxDefaultSize )
220
// Use the normal platform-specific icon size.
221
size = GetNativeSizeHint(client);
223
if ( size == wxDefaultSize )
225
// If we failed to get it, determine the best size more or less
226
// arbitrarily. This definitely won't look good but then it
227
// shouldn't normally happen, all platforms should implement
228
// GetNativeSizeHint() properly.
229
if ( client == wxART_MENU || client == wxART_BUTTON )
230
size = wxSize(16, 16);
232
size = wxSize(24, 24);
235
// We should return the icon of exactly this size so it's more than
239
else // We have a size hint
241
// Use it for determining the version of the icon to return.
244
// But we don't need to return the image of exactly the same size
245
// as the hint, after all it's just that, a hint.
255
// We prefer to downscale the image rather than upscale it if possible
256
// so use the smaller one if we can, otherwise the large one.
257
if ( size.x <= 16 && size.y <= 16 )
258
tangoSize = TangoSize_16;
260
tangoSize = TangoSize_24;
262
const unsigned char *data;
267
wxFAIL_MSG( "Unsupported Tango bitmap size" );
281
wxMemoryInputStream is(data, len);
283
// Before reading the image data from the stream for the first time,
284
// add the handler for PNG images: we do it here and not in, say,
285
// InitTangoProvider() to do it as lately as possible and so to avoid
286
// the asserts about adding an already added handler if the user code
287
// adds the handler itself.
288
if ( !m_imageHandledAdded )
290
// Of course, if the user code did add it already, we have nothing
292
if ( !wxImage::FindHandler(wxBITMAP_TYPE_PNG) )
293
wxImage::AddHandler(new wxPNGHandler);
295
// In any case, no need to do it again.
296
m_imageHandledAdded = true;
299
wxImage image(is, wxBITMAP_TYPE_PNG);
302
// This should normally never happen as all the embedded images are
304
wxLogDebug("Failed to load embedded PNG image for \"%s\"", id);
310
// Notice that this won't do anything if the size is already right.
311
image.Rescale(size.x, size.y, wxIMAGE_QUALITY_HIGH);
317
// Not one of the bitmaps that we support.
322
void wxArtProvider::InitTangoProvider()
324
wxArtProvider::PushBack(new wxTangoArtProvider);
327
#endif // wxUSE_ARTPROVIDER_TANGO