2002-04-06 14:55:16 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: artbrows.cpp
|
|
|
|
// Purpose: wxArtProvider demo - art browser dialog
|
|
|
|
// Author: Vaclav Slavik
|
|
|
|
// Modified by:
|
|
|
|
// Created: 2002/04/05
|
|
|
|
// Copyright: (c) Vaclav Slavik
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
2002-04-06 14:55:16 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#include "wx/choice.h"
|
|
|
|
#endif
|
|
|
|
|
2002-05-03 19:43:17 +00:00
|
|
|
#include "wx/listctrl.h"
|
2002-04-06 14:55:16 +00:00
|
|
|
#include "wx/sizer.h"
|
|
|
|
#include "wx/imaglist.h"
|
2002-04-07 17:28:56 +00:00
|
|
|
#include "wx/listctrl.h"
|
2002-04-06 14:55:16 +00:00
|
|
|
|
|
|
|
#include "artbrows.h"
|
|
|
|
|
|
|
|
#define ART_CLIENT(id) \
|
2009-07-23 20:30:22 +00:00
|
|
|
choice->Append(wxT(#id), (void*)id);
|
2002-04-06 14:55:16 +00:00
|
|
|
#define ART_ICON(id) \
|
|
|
|
{ \
|
|
|
|
int ind; \
|
|
|
|
wxIcon icon = wxArtProvider::GetIcon(id, client, size); \
|
2011-05-03 16:29:04 +00:00
|
|
|
if ( icon.IsOk() ) \
|
2002-04-06 14:55:16 +00:00
|
|
|
ind = images->Add(icon); \
|
|
|
|
else \
|
|
|
|
ind = 0; \
|
2009-07-23 20:30:22 +00:00
|
|
|
list->InsertItem(index, wxT(#id), ind); \
|
2010-09-09 22:20:07 +00:00
|
|
|
list->SetItemPtrData(index, wxPtrToUInt(id)); \
|
2002-04-06 14:55:16 +00:00
|
|
|
index++; \
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Functions to fill-in all supported art IDs
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static void FillClients(wxChoice *choice)
|
|
|
|
{
|
|
|
|
ART_CLIENT(wxART_OTHER)
|
2010-12-31 17:38:35 +00:00
|
|
|
ART_CLIENT(wxART_BUTTON)
|
2002-04-06 14:55:16 +00:00
|
|
|
ART_CLIENT(wxART_TOOLBAR)
|
|
|
|
ART_CLIENT(wxART_MENU)
|
|
|
|
ART_CLIENT(wxART_FRAME_ICON)
|
|
|
|
ART_CLIENT(wxART_CMN_DIALOG)
|
|
|
|
ART_CLIENT(wxART_HELP_BROWSER)
|
2010-12-31 17:38:35 +00:00
|
|
|
ART_CLIENT(wxART_MESSAGE_BOX) // Keep this last, it's the initial shown one
|
2002-04-06 14:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void FillBitmaps(wxImageList *images, wxListCtrl *list,
|
|
|
|
int& index,
|
|
|
|
const wxArtClient& client, const wxSize& size)
|
|
|
|
{
|
|
|
|
ART_ICON(wxART_ERROR)
|
|
|
|
ART_ICON(wxART_QUESTION)
|
|
|
|
ART_ICON(wxART_WARNING)
|
|
|
|
ART_ICON(wxART_INFORMATION)
|
|
|
|
ART_ICON(wxART_ADD_BOOKMARK)
|
|
|
|
ART_ICON(wxART_DEL_BOOKMARK)
|
|
|
|
ART_ICON(wxART_HELP_SIDE_PANEL)
|
|
|
|
ART_ICON(wxART_HELP_SETTINGS)
|
|
|
|
ART_ICON(wxART_HELP_BOOK)
|
|
|
|
ART_ICON(wxART_HELP_FOLDER)
|
|
|
|
ART_ICON(wxART_HELP_PAGE)
|
|
|
|
ART_ICON(wxART_GO_BACK)
|
|
|
|
ART_ICON(wxART_GO_FORWARD)
|
|
|
|
ART_ICON(wxART_GO_UP)
|
|
|
|
ART_ICON(wxART_GO_DOWN)
|
|
|
|
ART_ICON(wxART_GO_TO_PARENT)
|
|
|
|
ART_ICON(wxART_GO_HOME)
|
2010-12-31 17:39:01 +00:00
|
|
|
ART_ICON(wxART_GOTO_FIRST)
|
|
|
|
ART_ICON(wxART_GOTO_LAST)
|
2002-04-06 14:55:16 +00:00
|
|
|
ART_ICON(wxART_PRINT)
|
|
|
|
ART_ICON(wxART_HELP)
|
|
|
|
ART_ICON(wxART_TIP)
|
|
|
|
ART_ICON(wxART_REPORT_VIEW)
|
|
|
|
ART_ICON(wxART_LIST_VIEW)
|
|
|
|
ART_ICON(wxART_NEW_DIR)
|
|
|
|
ART_ICON(wxART_FOLDER)
|
2007-03-30 18:50:31 +00:00
|
|
|
ART_ICON(wxART_FOLDER_OPEN);
|
2002-04-06 14:55:16 +00:00
|
|
|
ART_ICON(wxART_GO_DIR_UP)
|
|
|
|
ART_ICON(wxART_EXECUTABLE_FILE)
|
|
|
|
ART_ICON(wxART_NORMAL_FILE)
|
|
|
|
ART_ICON(wxART_TICK_MARK)
|
|
|
|
ART_ICON(wxART_CROSS_MARK)
|
2003-06-24 18:14:37 +00:00
|
|
|
ART_ICON(wxART_MISSING_IMAGE)
|
2007-03-30 18:50:31 +00:00
|
|
|
ART_ICON(wxART_NEW);
|
|
|
|
ART_ICON(wxART_FILE_OPEN)
|
2005-02-19 16:56:13 +00:00
|
|
|
ART_ICON(wxART_FILE_SAVE)
|
|
|
|
ART_ICON(wxART_FILE_SAVE_AS)
|
2007-03-30 18:50:31 +00:00
|
|
|
ART_ICON(wxART_DELETE);
|
2005-02-19 16:56:13 +00:00
|
|
|
ART_ICON(wxART_COPY)
|
|
|
|
ART_ICON(wxART_CUT)
|
|
|
|
ART_ICON(wxART_PASTE)
|
|
|
|
ART_ICON(wxART_UNDO)
|
|
|
|
ART_ICON(wxART_REDO)
|
2010-12-31 17:39:01 +00:00
|
|
|
ART_ICON(wxART_PLUS)
|
|
|
|
ART_ICON(wxART_MINUS)
|
2005-02-19 16:56:13 +00:00
|
|
|
ART_ICON(wxART_QUIT)
|
|
|
|
ART_ICON(wxART_FIND)
|
|
|
|
ART_ICON(wxART_FIND_AND_REPLACE)
|
2015-08-09 14:47:44 +00:00
|
|
|
ART_ICON(wxART_EDIT)
|
2014-10-11 16:30:06 +00:00
|
|
|
ART_ICON(wxART_FULL_SCREEN)
|
2007-03-30 18:50:31 +00:00
|
|
|
ART_ICON(wxART_HARDDISK)
|
|
|
|
ART_ICON(wxART_FLOPPY)
|
|
|
|
ART_ICON(wxART_CDROM)
|
|
|
|
ART_ICON(wxART_REMOVABLE)
|
2002-04-06 14:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Browser implementation
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "null.xpm"
|
|
|
|
|
2014-03-30 07:07:55 +00:00
|
|
|
wxBEGIN_EVENT_TABLE(wxArtBrowserDialog, wxDialog)
|
2004-05-27 17:50:54 +00:00
|
|
|
EVT_LIST_ITEM_SELECTED(wxID_ANY, wxArtBrowserDialog::OnSelectItem)
|
|
|
|
EVT_CHOICE(wxID_ANY, wxArtBrowserDialog::OnChooseClient)
|
2014-03-30 07:07:55 +00:00
|
|
|
wxEND_EVENT_TABLE()
|
2002-04-06 14:55:16 +00:00
|
|
|
|
|
|
|
wxArtBrowserDialog::wxArtBrowserDialog(wxWindow *parent)
|
2009-07-23 20:30:22 +00:00
|
|
|
: wxDialog(parent, wxID_ANY, wxT("Art resources browser"),
|
2004-06-12 23:44:08 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
2002-04-06 14:55:16 +00:00
|
|
|
wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
|
|
|
|
{
|
|
|
|
wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
wxSizer *subsizer;
|
2004-06-12 23:44:08 +00:00
|
|
|
|
2004-05-27 17:50:54 +00:00
|
|
|
wxChoice *choice = new wxChoice(this, wxID_ANY);
|
2002-04-06 14:55:16 +00:00
|
|
|
FillClients(choice);
|
2004-06-12 23:44:08 +00:00
|
|
|
|
2002-04-06 14:55:16 +00:00
|
|
|
subsizer = new wxBoxSizer(wxHORIZONTAL);
|
2009-07-23 20:30:22 +00:00
|
|
|
subsizer->Add(new wxStaticText(this, wxID_ANY, wxT("Client:")), 0, wxALIGN_CENTER_VERTICAL);
|
2002-04-06 14:55:16 +00:00
|
|
|
subsizer->Add(choice, 1, wxLEFT, 5);
|
|
|
|
sizer->Add(subsizer, 0, wxALL | wxEXPAND, 10);
|
|
|
|
|
|
|
|
subsizer = new wxBoxSizer(wxHORIZONTAL);
|
2004-06-12 23:44:08 +00:00
|
|
|
|
2004-05-27 17:50:54 +00:00
|
|
|
m_list = new wxListCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(250, 300),
|
2002-04-06 14:55:16 +00:00
|
|
|
wxLC_REPORT | wxSUNKEN_BORDER);
|
2013-06-29 12:52:34 +00:00
|
|
|
m_list->AppendColumn(wxT("wxArtID"));
|
2002-04-06 14:55:16 +00:00
|
|
|
subsizer->Add(m_list, 1, wxEXPAND | wxRIGHT, 10);
|
2004-06-12 23:44:08 +00:00
|
|
|
|
2002-04-06 14:55:16 +00:00
|
|
|
wxSizer *subsub = new wxBoxSizer(wxVERTICAL);
|
2005-03-12 10:33:00 +00:00
|
|
|
m_text = new wxStaticText(this, wxID_ANY, wxT("Size: 333x333"));
|
|
|
|
subsub->Add(m_text);
|
|
|
|
|
2004-05-27 17:50:54 +00:00
|
|
|
m_canvas = new wxStaticBitmap(this, wxID_ANY, wxBitmap(null_xpm));
|
2002-04-06 14:55:16 +00:00
|
|
|
subsub->Add(m_canvas);
|
|
|
|
subsub->Add(100, 100);
|
|
|
|
subsizer->Add(subsub);
|
|
|
|
|
|
|
|
sizer->Add(subsizer, 1, wxEXPAND | wxLEFT|wxRIGHT, 10);
|
2004-06-12 23:44:08 +00:00
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
wxButton *ok = new wxButton(this, wxID_OK, wxT("Close"));
|
2002-04-06 14:55:16 +00:00
|
|
|
ok->SetDefault();
|
|
|
|
sizer->Add(ok, 0, wxALIGN_RIGHT | wxALL, 10);
|
2004-06-12 23:44:08 +00:00
|
|
|
|
2008-03-15 02:08:02 +00:00
|
|
|
SetSizerAndFit(sizer);
|
2002-04-06 14:55:16 +00:00
|
|
|
|
2010-12-31 17:38:35 +00:00
|
|
|
choice->SetSelection(choice->GetCount() - 1);
|
2002-04-06 14:55:16 +00:00
|
|
|
SetArtClient(wxART_MESSAGE_BOX);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wxArtBrowserDialog::SetArtClient(const wxArtClient& client)
|
|
|
|
{
|
|
|
|
wxBusyCursor bcur;
|
2004-06-12 23:44:08 +00:00
|
|
|
|
2002-04-06 14:55:16 +00:00
|
|
|
wxImageList *img = new wxImageList(16, 16);
|
|
|
|
img->Add(wxIcon(null_xpm));
|
|
|
|
int index = 0;
|
|
|
|
|
2005-03-12 10:33:00 +00:00
|
|
|
long sel = m_list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
|
|
|
|
if (sel < 0) sel = 0;
|
|
|
|
|
2002-04-06 14:55:16 +00:00
|
|
|
m_list->DeleteAllItems();
|
|
|
|
FillBitmaps(img, m_list, index, client, wxSize(16, 16));
|
|
|
|
m_list->AssignImageList(img, wxIMAGE_LIST_SMALL);
|
|
|
|
m_list->SetColumnWidth(0, wxLIST_AUTOSIZE);
|
|
|
|
|
2005-03-12 10:33:00 +00:00
|
|
|
m_list->SetItemState(sel, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
|
|
|
|
|
2002-04-06 14:55:16 +00:00
|
|
|
m_client = client;
|
2010-12-31 17:38:51 +00:00
|
|
|
SetArtBitmap((const char*)m_list->GetItemData(sel), m_client);
|
2002-04-06 14:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wxArtBrowserDialog::OnSelectItem(wxListEvent &event)
|
|
|
|
{
|
2010-12-31 17:38:51 +00:00
|
|
|
const char *data = (const char*)event.GetData();
|
2005-03-12 10:33:00 +00:00
|
|
|
SetArtBitmap(data, m_client, wxDefaultSize);
|
2002-04-06 14:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wxArtBrowserDialog::OnChooseClient(wxCommandEvent &event)
|
|
|
|
{
|
2010-12-31 17:38:51 +00:00
|
|
|
const char *data = (const char*)event.GetClientData();
|
2002-04-06 14:55:16 +00:00
|
|
|
SetArtClient(data);
|
|
|
|
}
|
2005-03-12 10:33:00 +00:00
|
|
|
|
|
|
|
void wxArtBrowserDialog::SetArtBitmap(const wxArtID& id, const wxArtClient& client, const wxSize& size)
|
|
|
|
{
|
|
|
|
wxBitmap bmp = wxArtProvider::GetBitmap(id, client, size);
|
|
|
|
m_canvas->SetSize(bmp.GetWidth(), bmp.GetHeight());
|
|
|
|
m_canvas->SetBitmap(bmp);
|
|
|
|
m_text->SetLabel(wxString::Format(wxT("Size: %d x %d"), bmp.GetWidth(), bmp.GetHeight()));
|
|
|
|
Refresh();
|
|
|
|
}
|