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