]>
Commit | Line | Data |
---|---|---|
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); \ | |
37 | if ( icon.Ok() ) \ | |
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 | ||
50 | static void FillClients(wxChoice *choice) | |
51 | { | |
52 | ART_CLIENT(wxART_OTHER) | |
53 | ART_CLIENT(wxART_TOOLBAR) | |
54 | ART_CLIENT(wxART_MENU) | |
55 | ART_CLIENT(wxART_FRAME_ICON) | |
56 | ART_CLIENT(wxART_CMN_DIALOG) | |
57 | ART_CLIENT(wxART_HELP_BROWSER) | |
58 | ART_CLIENT(wxART_MESSAGE_BOX) | |
59 | } | |
60 | ||
61 | static void FillBitmaps(wxImageList *images, wxListCtrl *list, | |
62 | int& index, | |
63 | const wxArtClient& client, const wxSize& size) | |
64 | { | |
65 | ART_ICON(wxART_ERROR) | |
66 | ART_ICON(wxART_QUESTION) | |
67 | ART_ICON(wxART_WARNING) | |
68 | ART_ICON(wxART_INFORMATION) | |
69 | ART_ICON(wxART_ADD_BOOKMARK) | |
70 | ART_ICON(wxART_DEL_BOOKMARK) | |
71 | ART_ICON(wxART_HELP_SIDE_PANEL) | |
72 | ART_ICON(wxART_HELP_SETTINGS) | |
73 | ART_ICON(wxART_HELP_BOOK) | |
74 | ART_ICON(wxART_HELP_FOLDER) | |
75 | ART_ICON(wxART_HELP_PAGE) | |
76 | ART_ICON(wxART_GO_BACK) | |
77 | ART_ICON(wxART_GO_FORWARD) | |
78 | ART_ICON(wxART_GO_UP) | |
79 | ART_ICON(wxART_GO_DOWN) | |
80 | ART_ICON(wxART_GO_TO_PARENT) | |
81 | ART_ICON(wxART_GO_HOME) | |
ccb42cc5 VS |
82 | ART_ICON(wxART_PRINT) |
83 | ART_ICON(wxART_HELP) | |
84 | ART_ICON(wxART_TIP) | |
85 | ART_ICON(wxART_REPORT_VIEW) | |
86 | ART_ICON(wxART_LIST_VIEW) | |
87 | ART_ICON(wxART_NEW_DIR) | |
88 | ART_ICON(wxART_FOLDER) | |
60f8c22b | 89 | ART_ICON(wxART_FOLDER_OPEN); |
ccb42cc5 VS |
90 | ART_ICON(wxART_GO_DIR_UP) |
91 | ART_ICON(wxART_EXECUTABLE_FILE) | |
92 | ART_ICON(wxART_NORMAL_FILE) | |
93 | ART_ICON(wxART_TICK_MARK) | |
94 | ART_ICON(wxART_CROSS_MARK) | |
e43fcd54 | 95 | ART_ICON(wxART_MISSING_IMAGE) |
60f8c22b VZ |
96 | ART_ICON(wxART_NEW); |
97 | ART_ICON(wxART_FILE_OPEN) | |
50f65637 VZ |
98 | ART_ICON(wxART_FILE_SAVE) |
99 | ART_ICON(wxART_FILE_SAVE_AS) | |
60f8c22b | 100 | ART_ICON(wxART_DELETE); |
50f65637 VZ |
101 | ART_ICON(wxART_COPY) |
102 | ART_ICON(wxART_CUT) | |
103 | ART_ICON(wxART_PASTE) | |
104 | ART_ICON(wxART_UNDO) | |
105 | ART_ICON(wxART_REDO) | |
106 | ART_ICON(wxART_QUIT) | |
107 | ART_ICON(wxART_FIND) | |
108 | ART_ICON(wxART_FIND_AND_REPLACE) | |
60f8c22b VZ |
109 | ART_ICON(wxART_HARDDISK) |
110 | ART_ICON(wxART_FLOPPY) | |
111 | ART_ICON(wxART_CDROM) | |
112 | ART_ICON(wxART_REMOVABLE) | |
ccb42cc5 VS |
113 | } |
114 | ||
115 | ||
116 | // ---------------------------------------------------------------------------- | |
117 | // Browser implementation | |
118 | // ---------------------------------------------------------------------------- | |
119 | ||
120 | #include "null.xpm" | |
121 | ||
122 | BEGIN_EVENT_TABLE(wxArtBrowserDialog, wxDialog) | |
5014bb3a WS |
123 | EVT_LIST_ITEM_SELECTED(wxID_ANY, wxArtBrowserDialog::OnSelectItem) |
124 | EVT_CHOICE(wxID_ANY, wxArtBrowserDialog::OnChooseClient) | |
ccb42cc5 VS |
125 | END_EVENT_TABLE() |
126 | ||
127 | wxArtBrowserDialog::wxArtBrowserDialog(wxWindow *parent) | |
9a83f860 | 128 | : wxDialog(parent, wxID_ANY, wxT("Art resources browser"), |
dabbc6a5 | 129 | wxDefaultPosition, wxDefaultSize, |
ccb42cc5 VS |
130 | wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER) |
131 | { | |
132 | wxSizer *sizer = new wxBoxSizer(wxVERTICAL); | |
133 | wxSizer *subsizer; | |
dabbc6a5 | 134 | |
5014bb3a | 135 | wxChoice *choice = new wxChoice(this, wxID_ANY); |
ccb42cc5 | 136 | FillClients(choice); |
dabbc6a5 | 137 | |
ccb42cc5 | 138 | subsizer = new wxBoxSizer(wxHORIZONTAL); |
9a83f860 | 139 | subsizer->Add(new wxStaticText(this, wxID_ANY, wxT("Client:")), 0, wxALIGN_CENTER_VERTICAL); |
ccb42cc5 VS |
140 | subsizer->Add(choice, 1, wxLEFT, 5); |
141 | sizer->Add(subsizer, 0, wxALL | wxEXPAND, 10); | |
142 | ||
143 | subsizer = new wxBoxSizer(wxHORIZONTAL); | |
dabbc6a5 | 144 | |
5014bb3a | 145 | m_list = new wxListCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(250, 300), |
ccb42cc5 | 146 | wxLC_REPORT | wxSUNKEN_BORDER); |
9a83f860 | 147 | m_list->InsertColumn(0, wxT("wxArtID")); |
ccb42cc5 | 148 | subsizer->Add(m_list, 1, wxEXPAND | wxRIGHT, 10); |
dabbc6a5 | 149 | |
ccb42cc5 | 150 | wxSizer *subsub = new wxBoxSizer(wxVERTICAL); |
e53a95bc RR |
151 | m_text = new wxStaticText(this, wxID_ANY, wxT("Size: 333x333")); |
152 | subsub->Add(m_text); | |
153 | ||
5014bb3a | 154 | m_canvas = new wxStaticBitmap(this, wxID_ANY, wxBitmap(null_xpm)); |
ccb42cc5 VS |
155 | subsub->Add(m_canvas); |
156 | subsub->Add(100, 100); | |
157 | subsizer->Add(subsub); | |
158 | ||
159 | sizer->Add(subsizer, 1, wxEXPAND | wxLEFT|wxRIGHT, 10); | |
dabbc6a5 | 160 | |
9a83f860 | 161 | wxButton *ok = new wxButton(this, wxID_OK, wxT("Close")); |
ccb42cc5 VS |
162 | ok->SetDefault(); |
163 | sizer->Add(ok, 0, wxALIGN_RIGHT | wxALL, 10); | |
dabbc6a5 | 164 | |
92c01615 | 165 | SetSizerAndFit(sizer); |
ccb42cc5 VS |
166 | |
167 | choice->SetSelection(6/*wxART_MESSAGE_BOX*/); | |
168 | SetArtClient(wxART_MESSAGE_BOX); | |
169 | } | |
170 | ||
171 | ||
172 | void wxArtBrowserDialog::SetArtClient(const wxArtClient& client) | |
173 | { | |
174 | wxBusyCursor bcur; | |
dabbc6a5 | 175 | |
ccb42cc5 VS |
176 | wxImageList *img = new wxImageList(16, 16); |
177 | img->Add(wxIcon(null_xpm)); | |
178 | int index = 0; | |
179 | ||
e53a95bc RR |
180 | long sel = m_list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED); |
181 | if (sel < 0) sel = 0; | |
182 | ||
ccb42cc5 VS |
183 | m_list->DeleteAllItems(); |
184 | FillBitmaps(img, m_list, index, client, wxSize(16, 16)); | |
185 | m_list->AssignImageList(img, wxIMAGE_LIST_SMALL); | |
186 | m_list->SetColumnWidth(0, wxLIST_AUTOSIZE); | |
187 | ||
e53a95bc RR |
188 | m_list->SetItemState(sel, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); |
189 | ||
ccb42cc5 | 190 | m_client = client; |
e53a95bc | 191 | SetArtBitmap((const wxChar*)m_list->GetItemData(sel), m_client); |
ccb42cc5 VS |
192 | } |
193 | ||
194 | void wxArtBrowserDialog::OnSelectItem(wxListEvent &event) | |
195 | { | |
196 | const wxChar *data = (const wxChar*)event.GetData(); | |
e53a95bc | 197 | SetArtBitmap(data, m_client, wxDefaultSize); |
ccb42cc5 VS |
198 | } |
199 | ||
200 | void wxArtBrowserDialog::OnChooseClient(wxCommandEvent &event) | |
201 | { | |
202 | const wxChar *data = (const wxChar*)event.GetClientData(); | |
203 | SetArtClient(data); | |
204 | } | |
e53a95bc RR |
205 | |
206 | void wxArtBrowserDialog::SetArtBitmap(const wxArtID& id, const wxArtClient& client, const wxSize& size) | |
207 | { | |
208 | wxBitmap bmp = wxArtProvider::GetBitmap(id, client, size); | |
209 | m_canvas->SetSize(bmp.GetWidth(), bmp.GetHeight()); | |
210 | m_canvas->SetBitmap(bmp); | |
211 | m_text->SetLabel(wxString::Format(wxT("Size: %d x %d"), bmp.GetWidth(), bmp.GetHeight())); | |
212 | Refresh(); | |
213 | } |