]> git.saurik.com Git - wxWidgets.git/blame - samples/artprov/artbrows.cpp
added tests for savin PNG images in different formats; don't ask for BMP bpp if not...
[wxWidgets.git] / samples / artprov / artbrows.cpp
CommitLineData
ccb42cc5
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: artbrows.cpp
3// Purpose: wxArtProvider demo - art browser dialog
4// Author: Vaclav Slavik
5// Modified by:
6// Created: 2002/04/05
7// RCS-ID: $Id$
8// Copyright: (c) Vaclav Slavik
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "artbrows.h"
14#endif
15
16// For compilers that support precompilation, includes "wx/wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24 #include "wx/wx.h"
ccb42cc5
VS
25 #include "wx/choice.h"
26#endif
27
f7435c32 28#include "wx/listctrl.h"
ccb42cc5
VS
29#include "wx/sizer.h"
30#include "wx/imaglist.h"
04c4c93f 31#include "wx/listctrl.h"
ccb42cc5
VS
32
33#include "artbrows.h"
34
35#define ART_CLIENT(id) \
9f84eccd 36 choice->Append(_T(#id), (void*)id);
ccb42cc5
VS
37#define ART_ICON(id) \
38 { \
39 int ind; \
40 wxIcon icon = wxArtProvider::GetIcon(id, client, size); \
41 if ( icon.Ok() ) \
42 ind = images->Add(icon); \
43 else \
44 ind = 0; \
9f84eccd 45 list->InsertItem(index, _T(#id), ind); \
ccb42cc5
VS
46 list->SetItemData(index, (long)id); \
47 index++; \
48 }
49
50// ----------------------------------------------------------------------------
51// Functions to fill-in all supported art IDs
52// ----------------------------------------------------------------------------
53
54static void FillClients(wxChoice *choice)
55{
56 ART_CLIENT(wxART_OTHER)
57 ART_CLIENT(wxART_TOOLBAR)
58 ART_CLIENT(wxART_MENU)
59 ART_CLIENT(wxART_FRAME_ICON)
60 ART_CLIENT(wxART_CMN_DIALOG)
61 ART_CLIENT(wxART_HELP_BROWSER)
62 ART_CLIENT(wxART_MESSAGE_BOX)
63}
64
65static void FillBitmaps(wxImageList *images, wxListCtrl *list,
66 int& index,
67 const wxArtClient& client, const wxSize& size)
68{
69 ART_ICON(wxART_ERROR)
70 ART_ICON(wxART_QUESTION)
71 ART_ICON(wxART_WARNING)
72 ART_ICON(wxART_INFORMATION)
73 ART_ICON(wxART_ADD_BOOKMARK)
74 ART_ICON(wxART_DEL_BOOKMARK)
75 ART_ICON(wxART_HELP_SIDE_PANEL)
76 ART_ICON(wxART_HELP_SETTINGS)
77 ART_ICON(wxART_HELP_BOOK)
78 ART_ICON(wxART_HELP_FOLDER)
79 ART_ICON(wxART_HELP_PAGE)
80 ART_ICON(wxART_GO_BACK)
81 ART_ICON(wxART_GO_FORWARD)
82 ART_ICON(wxART_GO_UP)
83 ART_ICON(wxART_GO_DOWN)
84 ART_ICON(wxART_GO_TO_PARENT)
85 ART_ICON(wxART_GO_HOME)
86 ART_ICON(wxART_FILE_OPEN)
87 ART_ICON(wxART_PRINT)
88 ART_ICON(wxART_HELP)
89 ART_ICON(wxART_TIP)
90 ART_ICON(wxART_REPORT_VIEW)
91 ART_ICON(wxART_LIST_VIEW)
92 ART_ICON(wxART_NEW_DIR)
93 ART_ICON(wxART_FOLDER)
94 ART_ICON(wxART_GO_DIR_UP)
95 ART_ICON(wxART_EXECUTABLE_FILE)
96 ART_ICON(wxART_NORMAL_FILE)
97 ART_ICON(wxART_TICK_MARK)
98 ART_ICON(wxART_CROSS_MARK)
e43fcd54 99 ART_ICON(wxART_MISSING_IMAGE)
50f65637
VZ
100 ART_ICON(wxART_FILE_SAVE)
101 ART_ICON(wxART_FILE_SAVE_AS)
102 ART_ICON(wxART_COPY)
103 ART_ICON(wxART_CUT)
104 ART_ICON(wxART_PASTE)
105 ART_ICON(wxART_UNDO)
106 ART_ICON(wxART_REDO)
107 ART_ICON(wxART_QUIT)
108 ART_ICON(wxART_FIND)
109 ART_ICON(wxART_FIND_AND_REPLACE)
110
ccb42cc5
VS
111}
112
113
114// ----------------------------------------------------------------------------
115// Browser implementation
116// ----------------------------------------------------------------------------
117
118#include "null.xpm"
119
120BEGIN_EVENT_TABLE(wxArtBrowserDialog, wxDialog)
5014bb3a
WS
121 EVT_LIST_ITEM_SELECTED(wxID_ANY, wxArtBrowserDialog::OnSelectItem)
122 EVT_CHOICE(wxID_ANY, wxArtBrowserDialog::OnChooseClient)
ccb42cc5
VS
123END_EVENT_TABLE()
124
125wxArtBrowserDialog::wxArtBrowserDialog(wxWindow *parent)
dabbc6a5
DS
126 : wxDialog(parent, wxID_ANY, _T("Art resources browser"),
127 wxDefaultPosition, wxDefaultSize,
ccb42cc5
VS
128 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
129{
130 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
131 wxSizer *subsizer;
dabbc6a5 132
5014bb3a 133 wxChoice *choice = new wxChoice(this, wxID_ANY);
ccb42cc5 134 FillClients(choice);
dabbc6a5 135
ccb42cc5 136 subsizer = new wxBoxSizer(wxHORIZONTAL);
5014bb3a 137 subsizer->Add(new wxStaticText(this, wxID_ANY, _T("Client:")), 0, wxALIGN_CENTER_VERTICAL);
ccb42cc5
VS
138 subsizer->Add(choice, 1, wxLEFT, 5);
139 sizer->Add(subsizer, 0, wxALL | wxEXPAND, 10);
140
141 subsizer = new wxBoxSizer(wxHORIZONTAL);
dabbc6a5 142
5014bb3a 143 m_list = new wxListCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(250, 300),
ccb42cc5
VS
144 wxLC_REPORT | wxSUNKEN_BORDER);
145 m_list->InsertColumn(0, _T("wxArtID"));
146 subsizer->Add(m_list, 1, wxEXPAND | wxRIGHT, 10);
dabbc6a5 147
ccb42cc5 148 wxSizer *subsub = new wxBoxSizer(wxVERTICAL);
5014bb3a 149 m_canvas = new wxStaticBitmap(this, wxID_ANY, wxBitmap(null_xpm));
ccb42cc5
VS
150 subsub->Add(m_canvas);
151 subsub->Add(100, 100);
152 subsizer->Add(subsub);
153
154 sizer->Add(subsizer, 1, wxEXPAND | wxLEFT|wxRIGHT, 10);
dabbc6a5 155
ccb42cc5
VS
156 wxButton *ok = new wxButton(this, wxID_OK, _T("Close"));
157 ok->SetDefault();
158 sizer->Add(ok, 0, wxALIGN_RIGHT | wxALL, 10);
dabbc6a5 159
ccb42cc5 160 SetSizer(sizer);
ccb42cc5
VS
161 sizer->Fit(this);
162
163 choice->SetSelection(6/*wxART_MESSAGE_BOX*/);
164 SetArtClient(wxART_MESSAGE_BOX);
165}
166
167
168void wxArtBrowserDialog::SetArtClient(const wxArtClient& client)
169{
170 wxBusyCursor bcur;
dabbc6a5 171
ccb42cc5
VS
172 wxImageList *img = new wxImageList(16, 16);
173 img->Add(wxIcon(null_xpm));
174 int index = 0;
175
176 m_list->DeleteAllItems();
177 FillBitmaps(img, m_list, index, client, wxSize(16, 16));
178 m_list->AssignImageList(img, wxIMAGE_LIST_SMALL);
179 m_list->SetColumnWidth(0, wxLIST_AUTOSIZE);
180
181 m_client = client;
182}
183
184void wxArtBrowserDialog::OnSelectItem(wxListEvent &event)
185{
186 const wxChar *data = (const wxChar*)event.GetData();
187 wxBitmap bmp = wxArtProvider::GetBitmap(data, m_client);
188 m_canvas->SetBitmap(bmp);
189 m_canvas->SetSize(bmp.GetWidth(), bmp.GetHeight());
190}
191
192void wxArtBrowserDialog::OnChooseClient(wxCommandEvent &event)
193{
194 const wxChar *data = (const wxChar*)event.GetClientData();
195 SetArtClient(data);
196}