]>
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 license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "artbrows.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
25 #include "wx/choice.h"
28 #include "wx/listctrl.h"
30 #include "wx/imaglist.h"
31 #include "wx/listctrl.h"
35 #define ART_CLIENT(id) \
36 choice->Append(_T(#id), (void*)id);
37 #define ART_ICON(id) \
40 wxIcon icon = wxArtProvider::GetIcon(id, client, size); \
42 ind = images->Add(icon); \
45 list->InsertItem(index, _T(#id), ind); \
46 list->SetItemData(index, (long)id); \
50 // ----------------------------------------------------------------------------
51 // Functions to fill-in all supported art IDs
52 // ----------------------------------------------------------------------------
54 static void FillClients(wxChoice
*choice
)
56 ART_CLIENT(wxART_OTHER
)
57 ART_CLIENT(wxART_TOOLBAR
)
58 ART_CLIENT(wxART_MENU
)
59 ART_CLIENT(wxART_FRAME_ICON
)
60 ART_CLIENT(wxART_CMN_DIALOG
)
61 ART_CLIENT(wxART_HELP_BROWSER
)
62 ART_CLIENT(wxART_MESSAGE_BOX
)
65 static void FillBitmaps(wxImageList
*images
, wxListCtrl
*list
,
67 const wxArtClient
& client
, const wxSize
& size
)
70 ART_ICON(wxART_QUESTION
)
71 ART_ICON(wxART_WARNING
)
72 ART_ICON(wxART_INFORMATION
)
73 ART_ICON(wxART_ADD_BOOKMARK
)
74 ART_ICON(wxART_DEL_BOOKMARK
)
75 ART_ICON(wxART_HELP_SIDE_PANEL
)
76 ART_ICON(wxART_HELP_SETTINGS
)
77 ART_ICON(wxART_HELP_BOOK
)
78 ART_ICON(wxART_HELP_FOLDER
)
79 ART_ICON(wxART_HELP_PAGE
)
80 ART_ICON(wxART_GO_BACK
)
81 ART_ICON(wxART_GO_FORWARD
)
83 ART_ICON(wxART_GO_DOWN
)
84 ART_ICON(wxART_GO_TO_PARENT
)
85 ART_ICON(wxART_GO_HOME
)
86 ART_ICON(wxART_FILE_OPEN
)
90 ART_ICON(wxART_REPORT_VIEW
)
91 ART_ICON(wxART_LIST_VIEW
)
92 ART_ICON(wxART_NEW_DIR
)
93 ART_ICON(wxART_FOLDER
)
94 ART_ICON(wxART_GO_DIR_UP
)
95 ART_ICON(wxART_EXECUTABLE_FILE
)
96 ART_ICON(wxART_NORMAL_FILE
)
97 ART_ICON(wxART_TICK_MARK
)
98 ART_ICON(wxART_CROSS_MARK
)
99 ART_ICON(wxART_MISSING_IMAGE
)
103 // ----------------------------------------------------------------------------
104 // Browser implementation
105 // ----------------------------------------------------------------------------
109 BEGIN_EVENT_TABLE(wxArtBrowserDialog
, wxDialog
)
110 EVT_LIST_ITEM_SELECTED(-1, wxArtBrowserDialog::OnSelectItem
)
111 EVT_CHOICE(-1, wxArtBrowserDialog::OnChooseClient
)
114 wxArtBrowserDialog::wxArtBrowserDialog(wxWindow
*parent
)
115 : wxDialog(parent
, -1, _T("Art resources browser"),
116 wxDefaultPosition
, wxDefaultSize
,
117 wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
)
119 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
122 wxChoice
*choice
= new wxChoice(this, -1);
125 subsizer
= new wxBoxSizer(wxHORIZONTAL
);
126 subsizer
->Add(new wxStaticText(this, -1, _T("Client:")), 0, wxALIGN_CENTER_VERTICAL
);
127 subsizer
->Add(choice
, 1, wxLEFT
, 5);
128 sizer
->Add(subsizer
, 0, wxALL
| wxEXPAND
, 10);
130 subsizer
= new wxBoxSizer(wxHORIZONTAL
);
132 m_list
= new wxListCtrl(this, -1, wxDefaultPosition
, wxSize(250, 300),
133 wxLC_REPORT
| wxSUNKEN_BORDER
);
134 m_list
->InsertColumn(0, _T("wxArtID"));
135 subsizer
->Add(m_list
, 1, wxEXPAND
| wxRIGHT
, 10);
137 wxSizer
*subsub
= new wxBoxSizer(wxVERTICAL
);
138 m_canvas
= new wxStaticBitmap(this, -1, wxBitmap(null_xpm
));
139 subsub
->Add(m_canvas
);
140 subsub
->Add(100, 100);
141 subsizer
->Add(subsub
);
143 sizer
->Add(subsizer
, 1, wxEXPAND
| wxLEFT
|wxRIGHT
, 10);
145 wxButton
*ok
= new wxButton(this, wxID_OK
, _T("Close"));
147 sizer
->Add(ok
, 0, wxALIGN_RIGHT
| wxALL
, 10);
153 choice
->SetSelection(6/*wxART_MESSAGE_BOX*/);
154 SetArtClient(wxART_MESSAGE_BOX
);
158 void wxArtBrowserDialog::SetArtClient(const wxArtClient
& client
)
162 wxImageList
*img
= new wxImageList(16, 16);
163 img
->Add(wxIcon(null_xpm
));
166 m_list
->DeleteAllItems();
167 FillBitmaps(img
, m_list
, index
, client
, wxSize(16, 16));
168 m_list
->AssignImageList(img
, wxIMAGE_LIST_SMALL
);
169 m_list
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
174 void wxArtBrowserDialog::OnSelectItem(wxListEvent
&event
)
176 const wxChar
*data
= (const wxChar
*)event
.GetData();
177 wxBitmap bmp
= wxArtProvider::GetBitmap(data
, m_client
);
178 m_canvas
->SetBitmap(bmp
);
179 m_canvas
->SetSize(bmp
.GetWidth(), bmp
.GetHeight());
182 void wxArtBrowserDialog::OnChooseClient(wxCommandEvent
&event
)
184 const wxChar
*data
= (const wxChar
*)event
.GetClientData();