2
* This file is part of wxSmithContribItems plugin for Code::Blocks Studio
3
* Copyright (C) 2007 Bartlomiej Swiecki
5
* wxSmith is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* wxSmith is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with wxSmith; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20
* $Id: wxscustombutton.cpp 4564 2007-10-26 20:33:02Z byo $
21
* $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/src/plugins/contrib/wxSmithContribItems/wxthings/wxscustombutton.cpp $
24
#include "wxscustombutton.h"
26
#include <wx/things/toggle.h>
30
#include "wxcustombutton16.xpm"
31
#include "wxcustombutton32.xpm"
33
wxsRegisterItem<wxsCustomButton> Reg(
37
_T("Bruce Phillips, John Labenski"),
38
_T("jlabenski@gmail.com"),
39
_T("http://wxcode.sourceforge.net/showcomp.php?name=wxThings"),
45
wxBitmap(wxcustombutton32_xpm),
46
wxBitmap(wxcustombutton16_xpm),
49
WXS_EV_BEGIN(wxsCustomButtonEvents)
50
WXS_EVI(EVT_BUTTON,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEvent,Click)
51
WXS_EVI(EVT_TOGGLEBUTTON,wxEVT_COMMAND_TOGGLEBUTTON_CLICKED,wxCommandEvent,Toggle)
56
const long TypeValues[] = { wxCUSTBUT_NOTOGGLE, wxCUSTBUT_BUTTON, wxCUSTBUT_TOGGLE, wxCUSTBUT_BUT_DCLICK_TOG, wxCUSTBUT_TOG_DCLICK_BUT };
57
const wxChar* TypeNames[] = { _T("wxCUSTBUT_NOTOGGLE"), _T("wxCUSTBUT_BUTTON"), _T("wxCUSTBUT_TOGGLE"), _T("wxCUSTBUT_BUT_DCLICK_TOG"), _T("wxCUSTBUT_TOG_DCLICK_BUT"), NULL };
59
const long LabelPositionValues[] = { wxCUSTBUT_LEFT, wxCUSTBUT_RIGHT, wxCUSTBUT_TOP, wxCUSTBUT_BOTTOM };
60
const wxChar* LabelPositionNames[] = { _T("wxCUSTBUT_LEFT"), _T("wxCUSTBUT_RIGHT"), _T("wxCUSTBUT_TOP"), _T("wxCUSTBUT_BOTTOM"), NULL };
63
wxsCustomButton::wxsCustomButton(wxsItemResData* Data):
67
wxsCustomButtonEvents,
70
m_Type = wxCUSTBUT_BUTTON;
73
m_LabelPosition = wxCUSTBUT_BOTTOM;
76
wxsCustomButton::~wxsCustomButton()
80
void wxsCustomButton::OnBuildCreatingCode()
82
switch ( GetLanguage() )
86
AddHeader(_T("<wx/things/toggle.h>"),GetInfo().ClassName);
87
AddHeader(_T("<wx/tglbtn.h>"),_T(""),hfLocal);
90
for ( int i=0; TypeNames[i]; i++ )
92
if ( TypeValues[i] == m_Type )
99
for ( int i=0; LabelPositionNames[i]; i++ )
101
if ( m_LabelPosition == LabelPositionValues[i] )
103
if ( !Style.IsEmpty() )
105
Style.Append(_T('|'));
107
Style.Append(LabelPositionNames[i]);
114
if ( !Style.IsEmpty() )
116
Style.Append(_T('|'));
118
Style.Append(_T("wxCUSTBUT_FLAT"));
121
if ( Style.IsEmpty() )
126
Codef(_T("%C(%W,%I,%t,%i,%P,%S,%s,%V,%N);\n"),m_Label.c_str(),&m_Bitmap,wxART_OTHER,Style.c_str());
128
if ( !m_BitmapSelected.IsEmpty() )
130
Codef(_T("%ASetBitmapSelected(%i);\n"),&m_BitmapSelected,wxART_OTHER);
133
if ( !m_BitmapFocused.IsEmpty() )
135
Codef(_T("%ASetBitmapFocus(%i);\n"),&m_BitmapFocused,wxART_OTHER);
138
if ( !m_BitmapDisabled.IsEmpty() )
140
Codef(_T("%ASetBitmapDisabled(%i);\n"),&m_BitmapDisabled,wxART_OTHER);
142
else if ( !m_Bitmap.IsEmpty() )
144
// Use internal function to generate bitmap dithered with background colour
145
Codef(_T("%ASetBitmapDisabled(%ACreateBitmapDisabled(%AGetBitmapLabel()));\n"));
148
if ( !m_Margins.IsDefault )
150
Codef(_T("%ASetMargins(%z);\n"),&m_Margins);
153
if ( !m_LabelMargins.IsDefault )
155
Codef(_T("%ASetLabelMargin(%z);\n"),&m_LabelMargins);
158
if ( !m_BitmapMargins.IsDefault )
160
Codef(_T("%ASetBitmapMargin(%z);\n"),&m_BitmapMargins);
167
wxsCodeMarks::Unknown(_T("wxsCustomButton::OnBuildCreatingCode"),GetLanguage());
171
wxObject* wxsCustomButton::OnBuildPreview(wxWindow* Parent,long Flags)
173
wxCustomButton* Button = new wxCustomButton(
177
m_Bitmap.GetPreview(wxDefaultSize),
180
m_Type | m_LabelPosition | (m_Flat?wxCUSTBUT_FLAT:0) );
182
if ( !m_BitmapSelected.IsEmpty() )
184
Button->SetBitmapSelected(m_BitmapSelected.GetPreview(wxDefaultSize));
187
if ( !m_BitmapFocused.IsEmpty() )
189
Button->SetBitmapFocus(m_BitmapFocused.GetPreview(wxDefaultSize));
192
if ( !m_BitmapDisabled.IsEmpty() )
194
Button->SetBitmapDisabled(m_BitmapDisabled.GetPreview(wxDefaultSize));
196
else if ( !m_Bitmap.IsEmpty() )
198
Button->SetBitmapDisabled(Button->CreateBitmapDisabled(Button->GetBitmapLabel()));
201
if ( !m_Margins.IsDefault )
203
Button->SetMargins(m_Margins.GetSize(Parent));
206
if ( !m_LabelMargins.IsDefault )
208
Button->SetLabelMargin(m_LabelMargins.GetSize(Parent));
211
if ( !m_BitmapMargins.IsDefault )
213
Button->SetBitmapMargin(m_BitmapMargins.GetSize(Parent));
219
void wxsCustomButton::OnEnumWidgetProperties(long Flags)
221
WXS_ENUM(wxsCustomButton,m_Type,_("Type"),_T("type"),TypeValues,TypeNames,wxCUSTBUT_BUTTON);
222
WXS_BOOL(wxsCustomButton,m_Flat,_("Flat"),_T("flat"),false);
223
WXS_STRING(wxsCustomButton,m_Label,_("Label"),_T("label"),_T(""),false);
224
WXS_ENUM(wxsCustomButton,m_LabelPosition,_("Label position"),_T("label_position"),LabelPositionValues,LabelPositionNames,wxCUSTBUT_BOTTOM);
225
WXS_BITMAP(wxsCustomButton,m_Bitmap,_("Bitmap"),_T("bitmap"),_T("wxART_OTHER"));
226
WXS_BITMAP(wxsCustomButton,m_BitmapSelected,_("Selected bmp"),_T("selected"),_T("wxART_OTHER"));
227
WXS_BITMAP(wxsCustomButton,m_BitmapFocused,_("Focused bmp"),_T("focused"),_T("wxART_OTHER"));
228
WXS_BITMAP(wxsCustomButton,m_BitmapDisabled,_("Disbled bmp"),_T("disabled"),_T("wxART_OTHER"));
229
WXS_SIZE(wxsCustomButton,m_Margins,_("Default margin"),_("Margin width"),_("Margin height"),_("Margin in Dialog Units"),_T("margin"));
230
WXS_SIZE(wxsCustomButton,m_LabelMargins,_("Default label margin"),_("Label marg. width"),_("Label marg. height"),_("Label marg. in Dialog Units"),_T("label_margin"));
231
WXS_SIZE(wxsCustomButton,m_BitmapMargins,_("Default bitmap margin"),_("Bitmap marg. width"),_("Bitmap marg. height"),_("Bitmap marg. in Dialog Units"),_T("bitmap_margin"));