]> git.saurik.com Git - wxWidgets.git/blame - samples/artprov/artbrows.cpp
refresh the dialog children forcefully even if wxCLIP_CHILDREN was specified
[wxWidgets.git] / samples / artprov / artbrows.cpp
CommitLineData
ccb42cc5
VS
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 license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "artbrows.h"
14#endif
15
16// For compilers that support precompilation, includes "wx/wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #include "wx/listctrl.h"
26 #include "wx/choice.h"
27#endif
28
29#include "wx/sizer.h"
30#include "wx/imaglist.h"
31
32#include "artbrows.h"
33
34#define ART_CLIENT(id) \
35 choice->Append(#id, (void*)id);
36#define ART_ICON(id) \
37 { \
38 int ind; \
39 wxIcon icon = wxArtProvider::GetIcon(id, client, size); \
40 if ( icon.Ok() ) \
41 ind = images->Add(icon); \
42 else \
43 ind = 0; \
44 list->InsertItem(index, #id, ind); \
45 list->SetItemData(index, (long)id); \
46 index++; \
47 }
48
49// ----------------------------------------------------------------------------
50// Functions to fill-in all supported art IDs
51// ----------------------------------------------------------------------------
52
53static void FillClients(wxChoice *choice)
54{
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)
62}
63
64static void FillBitmaps(wxImageList *images, wxListCtrl *list,
65 int& index,
66 const wxArtClient& client, const wxSize& size)
67{
68 ART_ICON(wxART_ERROR)
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)
81 ART_ICON(wxART_GO_UP)
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)
86 ART_ICON(wxART_PRINT)
87 ART_ICON(wxART_HELP)
88 ART_ICON(wxART_TIP)
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)
98}
99
100
101// ----------------------------------------------------------------------------
102// Browser implementation
103// ----------------------------------------------------------------------------
104
105#include "null.xpm"
106
107BEGIN_EVENT_TABLE(wxArtBrowserDialog, wxDialog)
108 EVT_LIST_ITEM_SELECTED(-1, wxArtBrowserDialog::OnSelectItem)
109 EVT_CHOICE(-1, wxArtBrowserDialog::OnChooseClient)
110END_EVENT_TABLE()
111
112wxArtBrowserDialog::wxArtBrowserDialog(wxWindow *parent)
113 : wxDialog(parent, -1, _T("Art resources browser"),
114 wxDefaultPosition, wxDefaultSize,
115 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
116{
117 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
118 wxSizer *subsizer;
119
120 wxChoice *choice = new wxChoice(this, -1);
121 FillClients(choice);
122
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);
127
128 subsizer = new wxBoxSizer(wxHORIZONTAL);
129
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);
134
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);
140
141 sizer->Add(subsizer, 1, wxEXPAND | wxLEFT|wxRIGHT, 10);
142
143 wxButton *ok = new wxButton(this, wxID_OK, _T("Close"));
144 ok->SetDefault();
145 sizer->Add(ok, 0, wxALIGN_RIGHT | wxALL, 10);
146
147 SetSizer(sizer);
148 SetAutoLayout(TRUE);
149 sizer->Fit(this);
150
151 choice->SetSelection(6/*wxART_MESSAGE_BOX*/);
152 SetArtClient(wxART_MESSAGE_BOX);
153}
154
155
156void wxArtBrowserDialog::SetArtClient(const wxArtClient& client)
157{
158 wxBusyCursor bcur;
159
160 wxImageList *img = new wxImageList(16, 16);
161 img->Add(wxIcon(null_xpm));
162 int index = 0;
163
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);
168
169 m_client = client;
170}
171
172void wxArtBrowserDialog::OnSelectItem(wxListEvent &event)
173{
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());
178}
179
180void wxArtBrowserDialog::OnChooseClient(wxCommandEvent &event)
181{
182 const wxChar *data = (const wxChar*)event.GetClientData();
183 SetArtClient(data);
184}