]>
git.saurik.com Git - wxWidgets.git/blob - samples/artprov/artbrows.cpp
0fd8a8aae9540d42ba24953a8ef96c8c71dd8f09
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxArtProvider demo - art browser dialog
4 // Author: Vaclav Slavik
8 // Copyright: (c) Vaclav Slavik
9 // Licence: wxWindows license
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(_T(#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, _T(#id), ind); \
42 list->SetItemData(index, (long)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_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
)
61 static void FillBitmaps(wxImageList
*images
, wxListCtrl
*list
,
63 const wxArtClient
& client
, const wxSize
& size
)
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
)
79 ART_ICON(wxART_GO_DOWN
)
80 ART_ICON(wxART_GO_TO_PARENT
)
81 ART_ICON(wxART_GO_HOME
)
82 ART_ICON(wxART_FILE_OPEN
)
86 ART_ICON(wxART_REPORT_VIEW
)
87 ART_ICON(wxART_LIST_VIEW
)
88 ART_ICON(wxART_NEW_DIR
)
89 ART_ICON(wxART_FOLDER
)
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
)
95 ART_ICON(wxART_MISSING_IMAGE
)
96 ART_ICON(wxART_FILE_SAVE
)
97 ART_ICON(wxART_FILE_SAVE_AS
)
100 ART_ICON(wxART_PASTE
)
105 ART_ICON(wxART_FIND_AND_REPLACE
)
110 // ----------------------------------------------------------------------------
111 // Browser implementation
112 // ----------------------------------------------------------------------------
116 BEGIN_EVENT_TABLE(wxArtBrowserDialog
, wxDialog
)
117 EVT_LIST_ITEM_SELECTED(wxID_ANY
, wxArtBrowserDialog::OnSelectItem
)
118 EVT_CHOICE(wxID_ANY
, wxArtBrowserDialog::OnChooseClient
)
121 wxArtBrowserDialog::wxArtBrowserDialog(wxWindow
*parent
)
122 : wxDialog(parent
, wxID_ANY
, _T("Art resources browser"),
123 wxDefaultPosition
, wxDefaultSize
,
124 wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
)
126 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
129 wxChoice
*choice
= new wxChoice(this, wxID_ANY
);
132 subsizer
= new wxBoxSizer(wxHORIZONTAL
);
133 subsizer
->Add(new wxStaticText(this, wxID_ANY
, _T("Client:")), 0, wxALIGN_CENTER_VERTICAL
);
134 subsizer
->Add(choice
, 1, wxLEFT
, 5);
135 sizer
->Add(subsizer
, 0, wxALL
| wxEXPAND
, 10);
137 subsizer
= new wxBoxSizer(wxHORIZONTAL
);
139 m_list
= new wxListCtrl(this, wxID_ANY
, wxDefaultPosition
, wxSize(250, 300),
140 wxLC_REPORT
| wxSUNKEN_BORDER
);
141 m_list
->InsertColumn(0, _T("wxArtID"));
142 subsizer
->Add(m_list
, 1, wxEXPAND
| wxRIGHT
, 10);
144 wxSizer
*subsub
= new wxBoxSizer(wxVERTICAL
);
145 m_text
= new wxStaticText(this, wxID_ANY
, wxT("Size: 333x333"));
148 m_canvas
= new wxStaticBitmap(this, wxID_ANY
, wxBitmap(null_xpm
));
149 subsub
->Add(m_canvas
);
150 subsub
->Add(100, 100);
151 subsizer
->Add(subsub
);
153 sizer
->Add(subsizer
, 1, wxEXPAND
| wxLEFT
|wxRIGHT
, 10);
155 wxButton
*ok
= new wxButton(this, wxID_OK
, _T("Close"));
157 sizer
->Add(ok
, 0, wxALIGN_RIGHT
| wxALL
, 10);
162 choice
->SetSelection(6/*wxART_MESSAGE_BOX*/);
163 SetArtClient(wxART_MESSAGE_BOX
);
167 void wxArtBrowserDialog::SetArtClient(const wxArtClient
& client
)
171 wxImageList
*img
= new wxImageList(16, 16);
172 img
->Add(wxIcon(null_xpm
));
175 long sel
= m_list
->GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_FOCUSED
);
176 if (sel
< 0) sel
= 0;
178 m_list
->DeleteAllItems();
179 FillBitmaps(img
, m_list
, index
, client
, wxSize(16, 16));
180 m_list
->AssignImageList(img
, wxIMAGE_LIST_SMALL
);
181 m_list
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
183 m_list
->SetItemState(sel
, wxLIST_STATE_FOCUSED
, wxLIST_STATE_FOCUSED
);
186 SetArtBitmap((const wxChar
*)m_list
->GetItemData(sel
), m_client
);
189 void wxArtBrowserDialog::OnSelectItem(wxListEvent
&event
)
191 const wxChar
*data
= (const wxChar
*)event
.GetData();
192 SetArtBitmap(data
, m_client
, wxDefaultSize
);
195 void wxArtBrowserDialog::OnChooseClient(wxCommandEvent
&event
)
197 const wxChar
*data
= (const wxChar
*)event
.GetClientData();
201 void wxArtBrowserDialog::SetArtBitmap(const wxArtID
& id
, const wxArtClient
& client
, const wxSize
& size
)
203 wxBitmap bmp
= wxArtProvider::GetBitmap(id
, client
, size
);
204 m_canvas
->SetSize(bmp
.GetWidth(), bmp
.GetHeight());
205 m_canvas
->SetBitmap(bmp
);
206 m_text
->SetLabel(wxString::Format(wxT("Size: %d x %d"), bmp
.GetWidth(), bmp
.GetHeight()));