]>
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"
29 #include "wx/imaglist.h"
30 #include "wx/listctrl.h"
34 #define ART_CLIENT(id) \
35 choice->Append(#id, (void*)id);
36 #define ART_ICON(id) \
39 wxIcon icon = wxArtProvider::GetIcon(id, client, size); \
41 ind = images->Add(icon); \
44 list->InsertItem(index, #id, ind); \
45 list->SetItemData(index, (long)id); \
49 // ----------------------------------------------------------------------------
50 // Functions to fill-in all supported art IDs
51 // ----------------------------------------------------------------------------
53 static void FillClients(wxChoice
*choice
)
55 ART_CLIENT(wxART_OTHER
)
56 ART_CLIENT(wxART_TOOLBAR
)
57 ART_CLIENT(wxART_MENU
)
58 ART_CLIENT(wxART_FRAME_ICON
)
59 ART_CLIENT(wxART_CMN_DIALOG
)
60 ART_CLIENT(wxART_HELP_BROWSER
)
61 ART_CLIENT(wxART_MESSAGE_BOX
)
64 static void FillBitmaps(wxImageList
*images
, wxListCtrl
*list
,
66 const wxArtClient
& client
, const wxSize
& size
)
69 ART_ICON(wxART_QUESTION
)
70 ART_ICON(wxART_WARNING
)
71 ART_ICON(wxART_INFORMATION
)
72 ART_ICON(wxART_ADD_BOOKMARK
)
73 ART_ICON(wxART_DEL_BOOKMARK
)
74 ART_ICON(wxART_HELP_SIDE_PANEL
)
75 ART_ICON(wxART_HELP_SETTINGS
)
76 ART_ICON(wxART_HELP_BOOK
)
77 ART_ICON(wxART_HELP_FOLDER
)
78 ART_ICON(wxART_HELP_PAGE
)
79 ART_ICON(wxART_GO_BACK
)
80 ART_ICON(wxART_GO_FORWARD
)
82 ART_ICON(wxART_GO_DOWN
)
83 ART_ICON(wxART_GO_TO_PARENT
)
84 ART_ICON(wxART_GO_HOME
)
85 ART_ICON(wxART_FILE_OPEN
)
89 ART_ICON(wxART_REPORT_VIEW
)
90 ART_ICON(wxART_LIST_VIEW
)
91 ART_ICON(wxART_NEW_DIR
)
92 ART_ICON(wxART_FOLDER
)
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
)
101 // ----------------------------------------------------------------------------
102 // Browser implementation
103 // ----------------------------------------------------------------------------
107 BEGIN_EVENT_TABLE(wxArtBrowserDialog
, wxDialog
)
108 EVT_LIST_ITEM_SELECTED(-1, wxArtBrowserDialog::OnSelectItem
)
109 EVT_CHOICE(-1, wxArtBrowserDialog::OnChooseClient
)
112 wxArtBrowserDialog::wxArtBrowserDialog(wxWindow
*parent
)
113 : wxDialog(parent
, -1, _T("Art resources browser"),
114 wxDefaultPosition
, wxDefaultSize
,
115 wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
)
117 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
120 wxChoice
*choice
= new wxChoice(this, -1);
123 subsizer
= new wxBoxSizer(wxHORIZONTAL
);
124 subsizer
->Add(new wxStaticText(this, -1, _T("Client:")), 0, wxALIGN_CENTER_VERTICAL
);
125 subsizer
->Add(choice
, 1, wxLEFT
, 5);
126 sizer
->Add(subsizer
, 0, wxALL
| wxEXPAND
, 10);
128 subsizer
= new wxBoxSizer(wxHORIZONTAL
);
130 m_list
= new wxListCtrl(this, -1, wxDefaultPosition
, wxSize(250, 300),
131 wxLC_REPORT
| wxSUNKEN_BORDER
);
132 m_list
->InsertColumn(0, _T("wxArtID"));
133 subsizer
->Add(m_list
, 1, wxEXPAND
| wxRIGHT
, 10);
135 wxSizer
*subsub
= new wxBoxSizer(wxVERTICAL
);
136 m_canvas
= new wxStaticBitmap(this, -1, wxBitmap(null_xpm
));
137 subsub
->Add(m_canvas
);
138 subsub
->Add(100, 100);
139 subsizer
->Add(subsub
);
141 sizer
->Add(subsizer
, 1, wxEXPAND
| wxLEFT
|wxRIGHT
, 10);
143 wxButton
*ok
= new wxButton(this, wxID_OK
, _T("Close"));
145 sizer
->Add(ok
, 0, wxALIGN_RIGHT
| wxALL
, 10);
151 choice
->SetSelection(6/*wxART_MESSAGE_BOX*/);
152 SetArtClient(wxART_MESSAGE_BOX
);
156 void wxArtBrowserDialog::SetArtClient(const wxArtClient
& client
)
160 wxImageList
*img
= new wxImageList(16, 16);
161 img
->Add(wxIcon(null_xpm
));
164 m_list
->DeleteAllItems();
165 FillBitmaps(img
, m_list
, index
, client
, wxSize(16, 16));
166 m_list
->AssignImageList(img
, wxIMAGE_LIST_SMALL
);
167 m_list
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
172 void wxArtBrowserDialog::OnSelectItem(wxListEvent
&event
)
174 const wxChar
*data
= (const wxChar
*)event
.GetData();
175 wxBitmap bmp
= wxArtProvider::GetBitmap(data
, m_client
);
176 m_canvas
->SetBitmap(bmp
);
177 m_canvas
->SetSize(bmp
.GetWidth(), bmp
.GetHeight());
180 void wxArtBrowserDialog::OnChooseClient(wxCommandEvent
&event
)
182 const wxChar
*data
= (const wxChar
*)event
.GetClientData();