]> git.saurik.com Git - wxWidgets.git/blame - samples/artprov/artbrows.cpp
Line endings fixes in bakefile-generated files.
[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
526954c5 9// Licence: wxWindows licence
ccb42cc5
VS
10/////////////////////////////////////////////////////////////////////////////
11
ccb42cc5
VS
12// For compilers that support precompilation, includes "wx/wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
20 #include "wx/wx.h"
ccb42cc5
VS
21 #include "wx/choice.h"
22#endif
23
f7435c32 24#include "wx/listctrl.h"
ccb42cc5
VS
25#include "wx/sizer.h"
26#include "wx/imaglist.h"
04c4c93f 27#include "wx/listctrl.h"
ccb42cc5
VS
28
29#include "artbrows.h"
30
31#define ART_CLIENT(id) \
9a83f860 32 choice->Append(wxT(#id), (void*)id);
ccb42cc5
VS
33#define ART_ICON(id) \
34 { \
35 int ind; \
36 wxIcon icon = wxArtProvider::GetIcon(id, client, size); \
a1b806b9 37 if ( icon.IsOk() ) \
ccb42cc5
VS
38 ind = images->Add(icon); \
39 else \
40 ind = 0; \
9a83f860 41 list->InsertItem(index, wxT(#id), ind); \
ca9fc039 42 list->SetItemPtrData(index, wxPtrToUInt(id)); \
ccb42cc5
VS
43 index++; \
44 }
45
46// ----------------------------------------------------------------------------
47// Functions to fill-in all supported art IDs
48// ----------------------------------------------------------------------------
49
50static void FillClients(wxChoice *choice)
51{
52 ART_CLIENT(wxART_OTHER)
7b898399 53 ART_CLIENT(wxART_BUTTON)
ccb42cc5
VS
54 ART_CLIENT(wxART_TOOLBAR)
55 ART_CLIENT(wxART_MENU)
56 ART_CLIENT(wxART_FRAME_ICON)
57 ART_CLIENT(wxART_CMN_DIALOG)
58 ART_CLIENT(wxART_HELP_BROWSER)
7b898399 59 ART_CLIENT(wxART_MESSAGE_BOX) // Keep this last, it's the initial shown one
ccb42cc5
VS
60}
61
62static void FillBitmaps(wxImageList *images, wxListCtrl *list,
63 int& index,
64 const wxArtClient& client, const wxSize& size)
65{
66 ART_ICON(wxART_ERROR)
67 ART_ICON(wxART_QUESTION)
68 ART_ICON(wxART_WARNING)
69 ART_ICON(wxART_INFORMATION)
70 ART_ICON(wxART_ADD_BOOKMARK)
71 ART_ICON(wxART_DEL_BOOKMARK)
72 ART_ICON(wxART_HELP_SIDE_PANEL)
73 ART_ICON(wxART_HELP_SETTINGS)
74 ART_ICON(wxART_HELP_BOOK)
75 ART_ICON(wxART_HELP_FOLDER)
76 ART_ICON(wxART_HELP_PAGE)
77 ART_ICON(wxART_GO_BACK)
78 ART_ICON(wxART_GO_FORWARD)
79 ART_ICON(wxART_GO_UP)
80 ART_ICON(wxART_GO_DOWN)
81 ART_ICON(wxART_GO_TO_PARENT)
82 ART_ICON(wxART_GO_HOME)
a7cfad3a
VZ
83 ART_ICON(wxART_GOTO_FIRST)
84 ART_ICON(wxART_GOTO_LAST)
ccb42cc5
VS
85 ART_ICON(wxART_PRINT)
86 ART_ICON(wxART_HELP)
87 ART_ICON(wxART_TIP)
88 ART_ICON(wxART_REPORT_VIEW)
89 ART_ICON(wxART_LIST_VIEW)
90 ART_ICON(wxART_NEW_DIR)
91 ART_ICON(wxART_FOLDER)
60f8c22b 92 ART_ICON(wxART_FOLDER_OPEN);
ccb42cc5
VS
93 ART_ICON(wxART_GO_DIR_UP)
94 ART_ICON(wxART_EXECUTABLE_FILE)
95 ART_ICON(wxART_NORMAL_FILE)
96 ART_ICON(wxART_TICK_MARK)
97 ART_ICON(wxART_CROSS_MARK)
e43fcd54 98 ART_ICON(wxART_MISSING_IMAGE)
60f8c22b
VZ
99 ART_ICON(wxART_NEW);
100 ART_ICON(wxART_FILE_OPEN)
50f65637
VZ
101 ART_ICON(wxART_FILE_SAVE)
102 ART_ICON(wxART_FILE_SAVE_AS)
60f8c22b 103 ART_ICON(wxART_DELETE);
50f65637
VZ
104 ART_ICON(wxART_COPY)
105 ART_ICON(wxART_CUT)
106 ART_ICON(wxART_PASTE)
107 ART_ICON(wxART_UNDO)
108 ART_ICON(wxART_REDO)
a7cfad3a
VZ
109 ART_ICON(wxART_PLUS)
110 ART_ICON(wxART_MINUS)
50f65637
VZ
111 ART_ICON(wxART_QUIT)
112 ART_ICON(wxART_FIND)
113 ART_ICON(wxART_FIND_AND_REPLACE)
60f8c22b
VZ
114 ART_ICON(wxART_HARDDISK)
115 ART_ICON(wxART_FLOPPY)
116 ART_ICON(wxART_CDROM)
117 ART_ICON(wxART_REMOVABLE)
ccb42cc5
VS
118}
119
120
121// ----------------------------------------------------------------------------
122// Browser implementation
123// ----------------------------------------------------------------------------
124
125#include "null.xpm"
126
127BEGIN_EVENT_TABLE(wxArtBrowserDialog, wxDialog)
5014bb3a
WS
128 EVT_LIST_ITEM_SELECTED(wxID_ANY, wxArtBrowserDialog::OnSelectItem)
129 EVT_CHOICE(wxID_ANY, wxArtBrowserDialog::OnChooseClient)
ccb42cc5
VS
130END_EVENT_TABLE()
131
132wxArtBrowserDialog::wxArtBrowserDialog(wxWindow *parent)
9a83f860 133 : wxDialog(parent, wxID_ANY, wxT("Art resources browser"),
dabbc6a5 134 wxDefaultPosition, wxDefaultSize,
ccb42cc5
VS
135 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
136{
137 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
138 wxSizer *subsizer;
dabbc6a5 139
5014bb3a 140 wxChoice *choice = new wxChoice(this, wxID_ANY);
ccb42cc5 141 FillClients(choice);
dabbc6a5 142
ccb42cc5 143 subsizer = new wxBoxSizer(wxHORIZONTAL);
9a83f860 144 subsizer->Add(new wxStaticText(this, wxID_ANY, wxT("Client:")), 0, wxALIGN_CENTER_VERTICAL);
ccb42cc5
VS
145 subsizer->Add(choice, 1, wxLEFT, 5);
146 sizer->Add(subsizer, 0, wxALL | wxEXPAND, 10);
147
148 subsizer = new wxBoxSizer(wxHORIZONTAL);
dabbc6a5 149
5014bb3a 150 m_list = new wxListCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(250, 300),
ccb42cc5 151 wxLC_REPORT | wxSUNKEN_BORDER);
9a83f860 152 m_list->InsertColumn(0, wxT("wxArtID"));
ccb42cc5 153 subsizer->Add(m_list, 1, wxEXPAND | wxRIGHT, 10);
dabbc6a5 154
ccb42cc5 155 wxSizer *subsub = new wxBoxSizer(wxVERTICAL);
e53a95bc
RR
156 m_text = new wxStaticText(this, wxID_ANY, wxT("Size: 333x333"));
157 subsub->Add(m_text);
158
5014bb3a 159 m_canvas = new wxStaticBitmap(this, wxID_ANY, wxBitmap(null_xpm));
ccb42cc5
VS
160 subsub->Add(m_canvas);
161 subsub->Add(100, 100);
162 subsizer->Add(subsub);
163
164 sizer->Add(subsizer, 1, wxEXPAND | wxLEFT|wxRIGHT, 10);
dabbc6a5 165
9a83f860 166 wxButton *ok = new wxButton(this, wxID_OK, wxT("Close"));
ccb42cc5
VS
167 ok->SetDefault();
168 sizer->Add(ok, 0, wxALIGN_RIGHT | wxALL, 10);
dabbc6a5 169
92c01615 170 SetSizerAndFit(sizer);
ccb42cc5 171
7b898399 172 choice->SetSelection(choice->GetCount() - 1);
ccb42cc5
VS
173 SetArtClient(wxART_MESSAGE_BOX);
174}
175
176
177void wxArtBrowserDialog::SetArtClient(const wxArtClient& client)
178{
179 wxBusyCursor bcur;
dabbc6a5 180
ccb42cc5
VS
181 wxImageList *img = new wxImageList(16, 16);
182 img->Add(wxIcon(null_xpm));
183 int index = 0;
184
e53a95bc
RR
185 long sel = m_list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
186 if (sel < 0) sel = 0;
187
ccb42cc5
VS
188 m_list->DeleteAllItems();
189 FillBitmaps(img, m_list, index, client, wxSize(16, 16));
190 m_list->AssignImageList(img, wxIMAGE_LIST_SMALL);
191 m_list->SetColumnWidth(0, wxLIST_AUTOSIZE);
192
e53a95bc
RR
193 m_list->SetItemState(sel, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
194
ccb42cc5 195 m_client = client;
19be42b7 196 SetArtBitmap((const char*)m_list->GetItemData(sel), m_client);
ccb42cc5
VS
197}
198
199void wxArtBrowserDialog::OnSelectItem(wxListEvent &event)
200{
19be42b7 201 const char *data = (const char*)event.GetData();
e53a95bc 202 SetArtBitmap(data, m_client, wxDefaultSize);
ccb42cc5
VS
203}
204
205void wxArtBrowserDialog::OnChooseClient(wxCommandEvent &event)
206{
19be42b7 207 const char *data = (const char*)event.GetClientData();
ccb42cc5
VS
208 SetArtClient(data);
209}
e53a95bc
RR
210
211void wxArtBrowserDialog::SetArtBitmap(const wxArtID& id, const wxArtClient& client, const wxSize& size)
212{
213 wxBitmap bmp = wxArtProvider::GetBitmap(id, client, size);
214 m_canvas->SetSize(bmp.GetWidth(), bmp.GetHeight());
215 m_canvas->SetBitmap(bmp);
216 m_text->SetLabel(wxString::Format(wxT("Size: %d x %d"), bmp.GetWidth(), bmp.GetHeight()));
217 Refresh();
218}