]>
Commit | Line | Data |
---|---|---|
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 licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
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" | |
21 | #include "wx/choice.h" | |
22 | #endif | |
23 | ||
24 | #include "wx/listctrl.h" | |
25 | #include "wx/sizer.h" | |
26 | #include "wx/imaglist.h" | |
27 | #include "wx/listctrl.h" | |
28 | ||
29 | #include "artbrows.h" | |
30 | ||
31 | #define ART_CLIENT(id) \ | |
32 | choice->Append(wxT(#id), (void*)id); | |
33 | #define ART_ICON(id) \ | |
34 | { \ | |
35 | int ind; \ | |
36 | wxIcon icon = wxArtProvider::GetIcon(id, client, size); \ | |
37 | if ( icon.IsOk() ) \ | |
38 | ind = images->Add(icon); \ | |
39 | else \ | |
40 | ind = 0; \ | |
41 | list->InsertItem(index, wxT(#id), ind); \ | |
42 | list->SetItemPtrData(index, wxPtrToUInt(id)); \ | |
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_BUTTON) | |
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) | |
59 | ART_CLIENT(wxART_MESSAGE_BOX) // Keep this last, it's the initial shown one | |
60 | } | |
61 | ||
62 | static 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) | |
83 | ART_ICON(wxART_GOTO_FIRST) | |
84 | ART_ICON(wxART_GOTO_LAST) | |
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) | |
92 | ART_ICON(wxART_FOLDER_OPEN); | |
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) | |
98 | ART_ICON(wxART_MISSING_IMAGE) | |
99 | ART_ICON(wxART_NEW); | |
100 | ART_ICON(wxART_FILE_OPEN) | |
101 | ART_ICON(wxART_FILE_SAVE) | |
102 | ART_ICON(wxART_FILE_SAVE_AS) | |
103 | ART_ICON(wxART_DELETE); | |
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) | |
109 | ART_ICON(wxART_PLUS) | |
110 | ART_ICON(wxART_MINUS) | |
111 | ART_ICON(wxART_QUIT) | |
112 | ART_ICON(wxART_FIND) | |
113 | ART_ICON(wxART_FIND_AND_REPLACE) | |
114 | ART_ICON(wxART_HARDDISK) | |
115 | ART_ICON(wxART_FLOPPY) | |
116 | ART_ICON(wxART_CDROM) | |
117 | ART_ICON(wxART_REMOVABLE) | |
118 | } | |
119 | ||
120 | ||
121 | // ---------------------------------------------------------------------------- | |
122 | // Browser implementation | |
123 | // ---------------------------------------------------------------------------- | |
124 | ||
125 | #include "null.xpm" | |
126 | ||
127 | BEGIN_EVENT_TABLE(wxArtBrowserDialog, wxDialog) | |
128 | EVT_LIST_ITEM_SELECTED(wxID_ANY, wxArtBrowserDialog::OnSelectItem) | |
129 | EVT_CHOICE(wxID_ANY, wxArtBrowserDialog::OnChooseClient) | |
130 | END_EVENT_TABLE() | |
131 | ||
132 | wxArtBrowserDialog::wxArtBrowserDialog(wxWindow *parent) | |
133 | : wxDialog(parent, wxID_ANY, wxT("Art resources browser"), | |
134 | wxDefaultPosition, wxDefaultSize, | |
135 | wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER) | |
136 | { | |
137 | wxSizer *sizer = new wxBoxSizer(wxVERTICAL); | |
138 | wxSizer *subsizer; | |
139 | ||
140 | wxChoice *choice = new wxChoice(this, wxID_ANY); | |
141 | FillClients(choice); | |
142 | ||
143 | subsizer = new wxBoxSizer(wxHORIZONTAL); | |
144 | subsizer->Add(new wxStaticText(this, wxID_ANY, wxT("Client:")), 0, wxALIGN_CENTER_VERTICAL); | |
145 | subsizer->Add(choice, 1, wxLEFT, 5); | |
146 | sizer->Add(subsizer, 0, wxALL | wxEXPAND, 10); | |
147 | ||
148 | subsizer = new wxBoxSizer(wxHORIZONTAL); | |
149 | ||
150 | m_list = new wxListCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(250, 300), | |
151 | wxLC_REPORT | wxSUNKEN_BORDER); | |
152 | m_list->InsertColumn(0, wxT("wxArtID")); | |
153 | subsizer->Add(m_list, 1, wxEXPAND | wxRIGHT, 10); | |
154 | ||
155 | wxSizer *subsub = new wxBoxSizer(wxVERTICAL); | |
156 | m_text = new wxStaticText(this, wxID_ANY, wxT("Size: 333x333")); | |
157 | subsub->Add(m_text); | |
158 | ||
159 | m_canvas = new wxStaticBitmap(this, wxID_ANY, wxBitmap(null_xpm)); | |
160 | subsub->Add(m_canvas); | |
161 | subsub->Add(100, 100); | |
162 | subsizer->Add(subsub); | |
163 | ||
164 | sizer->Add(subsizer, 1, wxEXPAND | wxLEFT|wxRIGHT, 10); | |
165 | ||
166 | wxButton *ok = new wxButton(this, wxID_OK, wxT("Close")); | |
167 | ok->SetDefault(); | |
168 | sizer->Add(ok, 0, wxALIGN_RIGHT | wxALL, 10); | |
169 | ||
170 | SetSizerAndFit(sizer); | |
171 | ||
172 | choice->SetSelection(choice->GetCount() - 1); | |
173 | SetArtClient(wxART_MESSAGE_BOX); | |
174 | } | |
175 | ||
176 | ||
177 | void wxArtBrowserDialog::SetArtClient(const wxArtClient& client) | |
178 | { | |
179 | wxBusyCursor bcur; | |
180 | ||
181 | wxImageList *img = new wxImageList(16, 16); | |
182 | img->Add(wxIcon(null_xpm)); | |
183 | int index = 0; | |
184 | ||
185 | long sel = m_list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED); | |
186 | if (sel < 0) sel = 0; | |
187 | ||
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 | ||
193 | m_list->SetItemState(sel, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); | |
194 | ||
195 | m_client = client; | |
196 | SetArtBitmap((const char*)m_list->GetItemData(sel), m_client); | |
197 | } | |
198 | ||
199 | void wxArtBrowserDialog::OnSelectItem(wxListEvent &event) | |
200 | { | |
201 | const char *data = (const char*)event.GetData(); | |
202 | SetArtBitmap(data, m_client, wxDefaultSize); | |
203 | } | |
204 | ||
205 | void wxArtBrowserDialog::OnChooseClient(wxCommandEvent &event) | |
206 | { | |
207 | const char *data = (const char*)event.GetClientData(); | |
208 | SetArtClient(data); | |
209 | } | |
210 | ||
211 | void 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 | } |