]>
git.saurik.com Git - wxWidgets.git/blob - samples/artprov/artbrows.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxArtProvider demo - art browser dialog
4 // Author: Vaclav Slavik
8 // Copyright: (c) Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/choice.h"
24 #include "wx/listctrl.h"
26 #include "wx/imaglist.h"
27 #include "wx/listctrl.h"
31 #define ART_CLIENT(id) \
32 choice->Append(wxT(#id), (void*)id);
33 #define ART_ICON(id) \
36 wxIcon icon = wxArtProvider::GetIcon(id, client, size); \
38 ind = images->Add(icon); \
41 list->InsertItem(index, wxT(#id), ind); \
42 list->SetItemPtrData(index, wxPtrToUInt(id)); \
46 // ----------------------------------------------------------------------------
47 // Functions to fill-in all supported art IDs
48 // ----------------------------------------------------------------------------
50 static void FillClients(wxChoice
*choice
)
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
62 static void FillBitmaps(wxImageList
*images
, wxListCtrl
*list
,
64 const wxArtClient
& client
, const wxSize
& size
)
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
)
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
)
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
)
100 ART_ICON(wxART_FILE_OPEN
)
101 ART_ICON(wxART_FILE_SAVE
)
102 ART_ICON(wxART_FILE_SAVE_AS
)
103 ART_ICON(wxART_DELETE
);
106 ART_ICON(wxART_PASTE
)
110 ART_ICON(wxART_MINUS
)
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
)
121 // ----------------------------------------------------------------------------
122 // Browser implementation
123 // ----------------------------------------------------------------------------
127 BEGIN_EVENT_TABLE(wxArtBrowserDialog
, wxDialog
)
128 EVT_LIST_ITEM_SELECTED(wxID_ANY
, wxArtBrowserDialog::OnSelectItem
)
129 EVT_CHOICE(wxID_ANY
, wxArtBrowserDialog::OnChooseClient
)
132 wxArtBrowserDialog::wxArtBrowserDialog(wxWindow
*parent
)
133 : wxDialog(parent
, wxID_ANY
, wxT("Art resources browser"),
134 wxDefaultPosition
, wxDefaultSize
,
135 wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
)
137 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
140 wxChoice
*choice
= new wxChoice(this, wxID_ANY
);
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);
148 subsizer
= new wxBoxSizer(wxHORIZONTAL
);
150 m_list
= new wxListCtrl(this, wxID_ANY
, wxDefaultPosition
, wxSize(250, 300),
151 wxLC_REPORT
| wxSUNKEN_BORDER
);
152 m_list
->AppendColumn(wxT("wxArtID"));
153 subsizer
->Add(m_list
, 1, wxEXPAND
| wxRIGHT
, 10);
155 wxSizer
*subsub
= new wxBoxSizer(wxVERTICAL
);
156 m_text
= new wxStaticText(this, wxID_ANY
, wxT("Size: 333x333"));
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
);
164 sizer
->Add(subsizer
, 1, wxEXPAND
| wxLEFT
|wxRIGHT
, 10);
166 wxButton
*ok
= new wxButton(this, wxID_OK
, wxT("Close"));
168 sizer
->Add(ok
, 0, wxALIGN_RIGHT
| wxALL
, 10);
170 SetSizerAndFit(sizer
);
172 choice
->SetSelection(choice
->GetCount() - 1);
173 SetArtClient(wxART_MESSAGE_BOX
);
177 void wxArtBrowserDialog::SetArtClient(const wxArtClient
& client
)
181 wxImageList
*img
= new wxImageList(16, 16);
182 img
->Add(wxIcon(null_xpm
));
185 long sel
= m_list
->GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_FOCUSED
);
186 if (sel
< 0) sel
= 0;
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
);
193 m_list
->SetItemState(sel
, wxLIST_STATE_FOCUSED
, wxLIST_STATE_FOCUSED
);
196 SetArtBitmap((const char*)m_list
->GetItemData(sel
), m_client
);
199 void wxArtBrowserDialog::OnSelectItem(wxListEvent
&event
)
201 const char *data
= (const char*)event
.GetData();
202 SetArtBitmap(data
, m_client
, wxDefaultSize
);
205 void wxArtBrowserDialog::OnChooseClient(wxCommandEvent
&event
)
207 const char *data
= (const char*)event
.GetClientData();
211 void wxArtBrowserDialog::SetArtBitmap(const wxArtID
& id
, const wxArtClient
& client
, const wxSize
& size
)
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()));