~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/plugins/contrib/wxSmithContribItems/wxthings/wxscustombutton.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* This file is part of wxSmithContribItems plugin for Code::Blocks Studio
 
3
* Copyright (C) 2007  Bartlomiej Swiecki
 
4
*
 
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.
 
9
*
 
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.
 
14
*
 
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
 
18
*
 
19
* $Revision: 4564 $
 
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 $
 
22
*/
 
23
 
 
24
#include "wxscustombutton.h"
 
25
 
 
26
#include <wx/things/toggle.h>
 
27
 
 
28
namespace
 
29
{
 
30
    #include "wxcustombutton16.xpm"
 
31
    #include "wxcustombutton32.xpm"
 
32
 
 
33
    wxsRegisterItem<wxsCustomButton> Reg(
 
34
        _T("wxCustomButton"),
 
35
        wxsTWidget,
 
36
        _T("wxWindows"),
 
37
        _T("Bruce Phillips, John Labenski"),
 
38
        _T("jlabenski@gmail.com"),
 
39
        _T("http://wxcode.sourceforge.net/showcomp.php?name=wxThings"),
 
40
        _T("Contrib"),
 
41
        50,
 
42
        _T("Button"),
 
43
        wxsCPP,
 
44
        1, 0,
 
45
        wxBitmap(wxcustombutton32_xpm),
 
46
        wxBitmap(wxcustombutton16_xpm),
 
47
        false);
 
48
 
 
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)
 
52
        WXS_EV_DEFAULTS()
 
53
    WXS_EV_END()
 
54
 
 
55
 
 
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 };
 
58
 
 
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 };
 
61
}
 
62
 
 
63
wxsCustomButton::wxsCustomButton(wxsItemResData* Data):
 
64
    wxsWidget(
 
65
        Data,
 
66
        &Reg.Info,
 
67
        wxsCustomButtonEvents,
 
68
        NULL)
 
69
{
 
70
    m_Type = wxCUSTBUT_BUTTON;
 
71
    m_Flat = false;
 
72
    m_Label = _("Label");
 
73
    m_LabelPosition = wxCUSTBUT_BOTTOM;
 
74
}
 
75
 
 
76
wxsCustomButton::~wxsCustomButton()
 
77
{
 
78
}
 
79
 
 
80
void wxsCustomButton::OnBuildCreatingCode()
 
81
{
 
82
    switch ( GetLanguage() )
 
83
    {
 
84
        case wxsCPP:
 
85
        {
 
86
            AddHeader(_T("<wx/things/toggle.h>"),GetInfo().ClassName);
 
87
            AddHeader(_T("<wx/tglbtn.h>"),_T(""),hfLocal);
 
88
 
 
89
            wxString Style;
 
90
            for ( int i=0; TypeNames[i]; i++ )
 
91
            {
 
92
                if ( TypeValues[i] == m_Type )
 
93
                {
 
94
                    Style = TypeNames[i];
 
95
                    break;
 
96
                }
 
97
            }
 
98
 
 
99
            for ( int i=0; LabelPositionNames[i]; i++ )
 
100
            {
 
101
                if ( m_LabelPosition == LabelPositionValues[i] )
 
102
                {
 
103
                    if ( !Style.IsEmpty() )
 
104
                    {
 
105
                        Style.Append(_T('|'));
 
106
                    }
 
107
                    Style.Append(LabelPositionNames[i]);
 
108
                    break;
 
109
                }
 
110
            }
 
111
 
 
112
            if ( m_Flat )
 
113
            {
 
114
                if ( !Style.IsEmpty() )
 
115
                {
 
116
                    Style.Append(_T('|'));
 
117
                }
 
118
                Style.Append(_T("wxCUSTBUT_FLAT"));
 
119
            }
 
120
 
 
121
            if ( Style.IsEmpty() )
 
122
            {
 
123
                Style = _T("0");
 
124
            }
 
125
 
 
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());
 
127
 
 
128
            if ( !m_BitmapSelected.IsEmpty() )
 
129
            {
 
130
                Codef(_T("%ASetBitmapSelected(%i);\n"),&m_BitmapSelected,wxART_OTHER);
 
131
            }
 
132
 
 
133
            if ( !m_BitmapFocused.IsEmpty() )
 
134
            {
 
135
                Codef(_T("%ASetBitmapFocus(%i);\n"),&m_BitmapFocused,wxART_OTHER);
 
136
            }
 
137
 
 
138
            if ( !m_BitmapDisabled.IsEmpty() )
 
139
            {
 
140
                Codef(_T("%ASetBitmapDisabled(%i);\n"),&m_BitmapDisabled,wxART_OTHER);
 
141
            }
 
142
            else if ( !m_Bitmap.IsEmpty() )
 
143
            {
 
144
                // Use internal function to generate bitmap dithered with background colour
 
145
                Codef(_T("%ASetBitmapDisabled(%ACreateBitmapDisabled(%AGetBitmapLabel()));\n"));
 
146
            }
 
147
 
 
148
            if ( !m_Margins.IsDefault )
 
149
            {
 
150
                Codef(_T("%ASetMargins(%z);\n"),&m_Margins);
 
151
            }
 
152
 
 
153
            if ( !m_LabelMargins.IsDefault )
 
154
            {
 
155
                Codef(_T("%ASetLabelMargin(%z);\n"),&m_LabelMargins);
 
156
            }
 
157
 
 
158
            if ( !m_BitmapMargins.IsDefault )
 
159
            {
 
160
                Codef(_T("%ASetBitmapMargin(%z);\n"),&m_BitmapMargins);
 
161
            }
 
162
 
 
163
            break;
 
164
        }
 
165
 
 
166
        default:
 
167
            wxsCodeMarks::Unknown(_T("wxsCustomButton::OnBuildCreatingCode"),GetLanguage());
 
168
    }
 
169
}
 
170
 
 
171
wxObject* wxsCustomButton::OnBuildPreview(wxWindow* Parent,long Flags)
 
172
{
 
173
    wxCustomButton* Button = new wxCustomButton(
 
174
        Parent,
 
175
        GetId(),
 
176
        m_Label,
 
177
        m_Bitmap.GetPreview(wxDefaultSize),
 
178
        Pos(Parent),
 
179
        Size(Parent),
 
180
        m_Type | m_LabelPosition | (m_Flat?wxCUSTBUT_FLAT:0) );
 
181
 
 
182
    if ( !m_BitmapSelected.IsEmpty() )
 
183
    {
 
184
        Button->SetBitmapSelected(m_BitmapSelected.GetPreview(wxDefaultSize));
 
185
    }
 
186
 
 
187
    if ( !m_BitmapFocused.IsEmpty() )
 
188
    {
 
189
        Button->SetBitmapFocus(m_BitmapFocused.GetPreview(wxDefaultSize));
 
190
    }
 
191
 
 
192
    if ( !m_BitmapDisabled.IsEmpty() )
 
193
    {
 
194
        Button->SetBitmapDisabled(m_BitmapDisabled.GetPreview(wxDefaultSize));
 
195
    }
 
196
    else if ( !m_Bitmap.IsEmpty() )
 
197
    {
 
198
        Button->SetBitmapDisabled(Button->CreateBitmapDisabled(Button->GetBitmapLabel()));
 
199
    }
 
200
 
 
201
    if ( !m_Margins.IsDefault )
 
202
    {
 
203
        Button->SetMargins(m_Margins.GetSize(Parent));
 
204
    }
 
205
 
 
206
    if ( !m_LabelMargins.IsDefault )
 
207
    {
 
208
        Button->SetLabelMargin(m_LabelMargins.GetSize(Parent));
 
209
    }
 
210
 
 
211
    if ( !m_BitmapMargins.IsDefault )
 
212
    {
 
213
        Button->SetBitmapMargin(m_BitmapMargins.GetSize(Parent));
 
214
    }
 
215
 
 
216
    return Button;
 
217
}
 
218
 
 
219
void wxsCustomButton::OnEnumWidgetProperties(long Flags)
 
220
{
 
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"));
 
232
}