~ubuntu-branches/ubuntu/oneiric/codeblocks/oneiric

« back to all changes in this revision

Viewing changes to src/plugins/contrib/wxSmith/wxwidgets/defitems/wxstoolbareditor.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 wxSmith plugin for Code::Blocks Studio
 
3
* Copyright (C) 2006-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 3 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, see <http://www.gnu.org/licenses/>.
 
17
*
 
18
* $Revision: 4850 $
 
19
* $Id: wxstoolbareditor.cpp 4850 2008-01-29 21:45:49Z byo $
 
20
* $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/src/plugins/contrib/wxSmith/wxwidgets/defitems/wxstoolbareditor.cpp $
 
21
*/
 
22
 
 
23
#include "wxstoolbareditor.h"
 
24
 
 
25
#include "wxstoolbaritem.h"
 
26
#include "../wxsitemresdata.h"
 
27
#include "../properties/wxsbitmapiconeditordlg.h"
 
28
 
 
29
//(*InternalHeaders(wxsToolBarEditor)
 
30
#include <wx/artprov.h>
 
31
#include <wx/bitmap.h>
 
32
#include <wx/font.h>
 
33
#include <wx/fontenum.h>
 
34
#include <wx/fontmap.h>
 
35
#include <wx/image.h>
 
36
#include <wx/intl.h>
 
37
#include <wx/settings.h>
 
38
#include <wx/string.h>
 
39
//*)
 
40
 
 
41
//(*IdInit(wxsToolBarEditor)
 
42
const long wxsToolBarEditor::ID_LISTBOX1 = wxNewId();
 
43
const long wxsToolBarEditor::ID_RADIOBUTTON1 = wxNewId();
 
44
const long wxsToolBarEditor::ID_RADIOBUTTON2 = wxNewId();
 
45
const long wxsToolBarEditor::ID_RADIOBUTTON3 = wxNewId();
 
46
const long wxsToolBarEditor::ID_RADIOBUTTON4 = wxNewId();
 
47
const long wxsToolBarEditor::ID_STATICLINE1 = wxNewId();
 
48
const long wxsToolBarEditor::ID_STATICTEXT6 = wxNewId();
 
49
const long wxsToolBarEditor::ID_TEXTCTRL4 = wxNewId();
 
50
const long wxsToolBarEditor::ID_STATICTEXT1 = wxNewId();
 
51
const long wxsToolBarEditor::ID_TEXTCTRL1 = wxNewId();
 
52
const long wxsToolBarEditor::ID_STATICTEXT4 = wxNewId();
 
53
const long wxsToolBarEditor::ID_BITMAPBUTTON1 = wxNewId();
 
54
const long wxsToolBarEditor::ID_STATICTEXT5 = wxNewId();
 
55
const long wxsToolBarEditor::ID_BITMAPBUTTON2 = wxNewId();
 
56
const long wxsToolBarEditor::ID_STATICTEXT2 = wxNewId();
 
57
const long wxsToolBarEditor::ID_TEXTCTRL2 = wxNewId();
 
58
const long wxsToolBarEditor::ID_STATICTEXT3 = wxNewId();
 
59
const long wxsToolBarEditor::ID_TEXTCTRL3 = wxNewId();
 
60
const long wxsToolBarEditor::ID_STATICLINE2 = wxNewId();
 
61
const long wxsToolBarEditor::ID_BUTTON3 = wxNewId();
 
62
const long wxsToolBarEditor::ID_BUTTON4 = wxNewId();
 
63
const long wxsToolBarEditor::ID_BUTTON1 = wxNewId();
 
64
const long wxsToolBarEditor::ID_BUTTON2 = wxNewId();
 
65
//*)
 
66
 
 
67
BEGIN_EVENT_TABLE(wxsToolBarEditor,wxPanel)
 
68
        //(*EventTable(wxsToolBarEditor)
 
69
        //*)
 
70
END_EVENT_TABLE()
 
71
 
 
72
wxsToolBarEditor::wxsToolBarEditor(wxWindow* parent,wxsToolBar* ToolBar):
 
73
    m_Selected(0),
 
74
    m_ToolBar(ToolBar),
 
75
    m_BlockTextChange(false),
 
76
    m_BlockSelect(false)
 
77
{
 
78
    wxWindowID id = wxID_ANY;
 
79
        //(*Initialize(wxsToolBarEditor)
 
80
        Create(parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("wxPanel"));
 
81
        BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
 
82
        StaticBoxSizer1 = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Content"));
 
83
        m_Content = new wxListBox(this, ID_LISTBOX1, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_LISTBOX1"));
 
84
        StaticBoxSizer1->Add(m_Content, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
85
        BoxSizer1->Add(StaticBoxSizer1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
86
        StaticBoxSizer2 = new wxStaticBoxSizer(wxVERTICAL, this, _("Options"));
 
87
        GridSizer1 = new wxGridSizer(0, 2, 0, 0);
 
88
        m_TypeNormal = new wxRadioButton(this, ID_RADIOBUTTON1, _("Normal"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_RADIOBUTTON1"));
 
89
        m_TypeNormal->Disable();
 
90
        GridSizer1->Add(m_TypeNormal, 1, wxLEFT|wxRIGHT|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
91
        m_TypeSeparator = new wxRadioButton(this, ID_RADIOBUTTON2, _("Separator"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_RADIOBUTTON2"));
 
92
        m_TypeSeparator->Disable();
 
93
        GridSizer1->Add(m_TypeSeparator, 1, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
94
        m_TypeRadio = new wxRadioButton(this, ID_RADIOBUTTON3, _("Radio"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_RADIOBUTTON3"));
 
95
        m_TypeRadio->Disable();
 
96
        GridSizer1->Add(m_TypeRadio, 1, wxLEFT|wxRIGHT|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
97
        m_TypeCheck = new wxRadioButton(this, ID_RADIOBUTTON4, _("Check"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_RADIOBUTTON4"));
 
98
        m_TypeCheck->Disable();
 
99
        GridSizer1->Add(m_TypeCheck, 1, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
100
        StaticBoxSizer2->Add(GridSizer1, 0, wxTOP|wxBOTTOM|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 10);
 
101
        StaticLine1 = new wxStaticLine(this, ID_STATICLINE1, wxDefaultPosition, wxSize(10,-1), wxLI_HORIZONTAL, _T("ID_STATICLINE1"));
 
102
        StaticBoxSizer2->Add(StaticLine1, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
103
        FlexGridSizer1 = new wxFlexGridSizer(0, 2, 0, 0);
 
104
        FlexGridSizer1->AddGrowableCol(1);
 
105
        StaticText6 = new wxStaticText(this, ID_STATICTEXT6, _("Id:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT6"));
 
106
        FlexGridSizer1->Add(StaticText6, 1, wxTOP|wxLEFT|wxRIGHT|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 4);
 
107
        m_Id = new wxTextCtrl(this, ID_TEXTCTRL4, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL4"));
 
108
        FlexGridSizer1->Add(m_Id, 1, wxTOP|wxLEFT|wxRIGHT|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
109
        StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Label:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
 
110
        FlexGridSizer1->Add(StaticText1, 1, wxTOP|wxLEFT|wxRIGHT|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 4);
 
111
        m_Label = new wxTextCtrl(this, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
 
112
        FlexGridSizer1->Add(m_Label, 1, wxTOP|wxLEFT|wxRIGHT|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
113
        StaticText4 = new wxStaticText(this, ID_STATICTEXT4, _("Bitmap:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT4"));
 
114
        FlexGridSizer1->Add(StaticText4, 1, wxTOP|wxLEFT|wxRIGHT|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 4);
 
115
        m_Bitmap = new wxBitmapButton(this, ID_BITMAPBUTTON1, wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_("wxART_FILE_OPEN")),_T("wxART_TOOLBAR")), wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator, _T("ID_BITMAPBUTTON1"));
 
116
        m_Bitmap->SetDefault();
 
117
        FlexGridSizer1->Add(m_Bitmap, 1, wxTOP|wxLEFT|wxRIGHT|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
118
        StaticText5 = new wxStaticText(this, ID_STATICTEXT5, _("Disabled bitmap:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT5"));
 
119
        FlexGridSizer1->Add(StaticText5, 1, wxTOP|wxLEFT|wxRIGHT|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 4);
 
120
        m_Bitmap2 = new wxBitmapButton(this, ID_BITMAPBUTTON2, wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_("wxART_FILE_OPEN")),_T("wxART_BUTTON_C")), wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator, _T("ID_BITMAPBUTTON2"));
 
121
        m_Bitmap2->SetDefault();
 
122
        FlexGridSizer1->Add(m_Bitmap2, 1, wxTOP|wxLEFT|wxRIGHT|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
123
        StaticText2 = new wxStaticText(this, ID_STATICTEXT2, _("Tooltip:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
 
124
        FlexGridSizer1->Add(StaticText2, 1, wxTOP|wxLEFT|wxRIGHT|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 4);
 
125
        m_ToolTip = new wxTextCtrl(this, ID_TEXTCTRL2, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL2"));
 
126
        FlexGridSizer1->Add(m_ToolTip, 1, wxTOP|wxLEFT|wxRIGHT|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
127
        StaticText3 = new wxStaticText(this, ID_STATICTEXT3, _("Help text:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
 
128
        FlexGridSizer1->Add(StaticText3, 1, wxTOP|wxLEFT|wxRIGHT|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 4);
 
129
        m_HelpText = new wxTextCtrl(this, ID_TEXTCTRL3, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL3"));
 
130
        FlexGridSizer1->Add(m_HelpText, 1, wxTOP|wxLEFT|wxRIGHT|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
131
        StaticBoxSizer2->Add(FlexGridSizer1, 0, wxTOP|wxBOTTOM|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 10);
 
132
        StaticLine2 = new wxStaticLine(this, ID_STATICLINE2, wxDefaultPosition, wxSize(10,-1), wxLI_HORIZONTAL, _T("ID_STATICLINE2"));
 
133
        StaticBoxSizer2->Add(StaticLine2, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
134
        BoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
 
135
        Button3 = new wxButton(this, ID_BUTTON3, _("^"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT, wxDefaultValidator, _T("ID_BUTTON3"));
 
136
        BoxSizer3->Add(Button3, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 2);
 
137
        Button4 = new wxButton(this, ID_BUTTON4, _("v"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT, wxDefaultValidator, _T("ID_BUTTON4"));
 
138
        BoxSizer3->Add(Button4, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 2);
 
139
        StaticBoxSizer2->Add(BoxSizer3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
140
        BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
 
141
        Button1 = new wxButton(this, ID_BUTTON1, _("New"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT, wxDefaultValidator, _T("ID_BUTTON1"));
 
142
        BoxSizer2->Add(Button1, 1, wxRIGHT|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
143
        Button2 = new wxButton(this, ID_BUTTON2, _("Delete"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT, wxDefaultValidator, _T("ID_BUTTON2"));
 
144
        BoxSizer2->Add(Button2, 1, wxLEFT|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
145
        StaticBoxSizer2->Add(BoxSizer2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
146
        BoxSizer1->Add(StaticBoxSizer2, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
 
147
        SetSizer(BoxSizer1);
 
148
        BoxSizer1->Fit(this);
 
149
        BoxSizer1->SetSizeHints(this);
 
150
        Connect(ID_LISTBOX1,wxEVT_COMMAND_LISTBOX_SELECTED,(wxObjectEventFunction)&wxsToolBarEditor::Onm_ContentSelect);
 
151
        Connect(ID_RADIOBUTTON1,wxEVT_COMMAND_RADIOBUTTON_SELECTED,(wxObjectEventFunction)&wxsToolBarEditor::OnTypeChanged);
 
152
        Connect(ID_RADIOBUTTON2,wxEVT_COMMAND_RADIOBUTTON_SELECTED,(wxObjectEventFunction)&wxsToolBarEditor::OnTypeChanged);
 
153
        Connect(ID_RADIOBUTTON3,wxEVT_COMMAND_RADIOBUTTON_SELECTED,(wxObjectEventFunction)&wxsToolBarEditor::OnTypeChanged);
 
154
        Connect(ID_RADIOBUTTON4,wxEVT_COMMAND_RADIOBUTTON_SELECTED,(wxObjectEventFunction)&wxsToolBarEditor::OnTypeChanged);
 
155
        Connect(ID_TEXTCTRL1,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&wxsToolBarEditor::Onm_LabelText);
 
156
        Connect(ID_BITMAPBUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxsToolBarEditor::OnBitmapClick);
 
157
        Connect(ID_BITMAPBUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxsToolBarEditor::OnBitmap2Click);
 
158
        Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxsToolBarEditor::OnUpClick);
 
159
        Connect(ID_BUTTON4,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxsToolBarEditor::OnDownClick);
 
160
        Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxsToolBarEditor::OnNewClick);
 
161
        Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxsToolBarEditor::OnDelClick);
 
162
        //*)
 
163
 
 
164
        for ( int i=0; i<m_ToolBar->GetChildCount(); i++ )
 
165
        {
 
166
            wxsItem* Child = m_ToolBar->GetChild(i);
 
167
            if ( Child->GetClassName() == _T("wxToolBarToolBase") )
 
168
            {
 
169
                wxsToolBarItem* Item = (wxsToolBarItem*)Child;
 
170
                ToolBarItem* New = new ToolBarItem;
 
171
                New->m_OriginalPos = -1;
 
172
                New->m_Id = Item->GetIdName();
 
173
                New->m_Label = Item->m_Label;
 
174
                New->m_Bitmap = Item->m_Bitmap;
 
175
                New->m_Bitmap2 = Item->m_Bitmap2;
 
176
                New->m_ToolTip = Item->m_ToolTip;
 
177
                New->m_HelpText = Item->m_HelpText;
 
178
 
 
179
                wxsEvents& Events = Item->GetEvents();
 
180
                if ( Events.GetCount() > 0 ) New->m_Handler1 = Events.GetHandler(0);
 
181
                if ( Events.GetCount() > 1 ) New->m_Handler2 = Events.GetHandler(1);
 
182
 
 
183
                switch ( Item->m_Type )
 
184
                {
 
185
                case wxsToolBarItem::Radio:
 
186
                    New->m_Type = Radio;
 
187
                    break;
 
188
 
 
189
                case wxsToolBarItem::Check:
 
190
                    New->m_Type = Check;
 
191
                    break;
 
192
 
 
193
                case wxsToolBarItem::Separator:
 
194
                    New->m_Type = Separator;
 
195
                    New->m_Id = _T("");
 
196
                    break;
 
197
 
 
198
                    default:
 
199
                    New->m_Type = Normal;
 
200
                    break;
 
201
                }
 
202
 
 
203
                m_Content->Append(GetItemLabel(New),New);
 
204
            }
 
205
            else
 
206
            {
 
207
                ToolBarItem* New = new ToolBarItem;
 
208
                New->m_OriginalPos = i;
 
209
                New->m_Label = Child->GetClassName();
 
210
                if ( Child->GetPropertiesFlags() & flVariable )
 
211
                {
 
212
                    New->m_Label << _T(": ") << Child->GetVarName();
 
213
                }
 
214
                New->m_Type = Control;
 
215
                m_Content->Append(GetItemLabel(New),New);
 
216
            }
 
217
        }
 
218
 
 
219
        if ( m_Content->GetCount() == 0 )
 
220
        {
 
221
            SelectItem(0);
 
222
        }
 
223
        else
 
224
        {
 
225
            m_Content->Select(0);
 
226
            SelectItem((ToolBarItem*)m_Content->GetClientObject(0));
 
227
        }
 
228
}
 
229
 
 
230
wxsToolBarEditor::~wxsToolBarEditor()
 
231
{
 
232
        //(*Destroy(wxsToolBarEditor)
 
233
        //*)
 
234
}
 
235
 
 
236
void wxsToolBarEditor::OnTypeChanged(wxCommandEvent& event)
 
237
{
 
238
    // Saving data
 
239
    ToolBarItem* Selected = m_Selected;
 
240
    SelectItem(0);           // Storing current content
 
241
    SelectItem(Selected);       // Updating screen's content
 
242
}
 
243
 
 
244
namespace
 
245
{
 
246
    typedef wxsItem* wxsItemP;
 
247
}
 
248
 
 
249
void wxsToolBarEditor::ApplyChanges()
 
250
{
 
251
    SelectItem(m_Selected); // Store changes
 
252
 
 
253
    m_ToolBar->GetResourceData()->BeginChange();
 
254
    int NewCount = m_Content->GetCount();
 
255
    if ( NewCount == 0 )
 
256
    {
 
257
        // Simply removing everything from toolbar
 
258
        for ( int i = m_ToolBar->GetChildCount(); i-->0; )
 
259
        {
 
260
            wxsItem* Child = m_ToolBar->GetChild(i);
 
261
            m_ToolBar->UnbindChild(i);
 
262
            delete Child;
 
263
        }
 
264
    }
 
265
 
 
266
    wxsItemP* NewChildrenArray = new wxsItemP[NewCount];
 
267
    wxArrayBool ParentChildrenUsed;
 
268
    ParentChildrenUsed.Add(false,m_ToolBar->GetChildCount());
 
269
 
 
270
    for ( int i=0; i<NewCount; i++ )
 
271
    {
 
272
        ToolBarItem* Item = (ToolBarItem*)m_Content->GetClientData(i);
 
273
        if ( Item->m_Type == Control )
 
274
        {
 
275
            int Index = Item->m_OriginalPos;
 
276
            wxASSERT(ParentChildrenUsed[Index]==false);
 
277
            NewChildrenArray[i] = m_ToolBar->GetChild(Index);
 
278
            ParentChildrenUsed[Index] = true;
 
279
        }
 
280
        else
 
281
        {
 
282
            wxsToolBarItem* New = new wxsToolBarItem(m_ToolBar->GetResourceData(),Item->m_Type==Separator);
 
283
            switch ( Item->m_Type )
 
284
            {
 
285
                case Separator: New->m_Type = wxsToolBarItem::Separator; break;
 
286
                case Radio:     New->m_Type = wxsToolBarItem::Radio; break;
 
287
                case Check:     New->m_Type = wxsToolBarItem::Check; break;
 
288
                default:        New->m_Type = wxsToolBarItem::Normal; break;
 
289
            }
 
290
 
 
291
            if ( Item->m_Type != Separator )
 
292
            {
 
293
                New->SetIdName(Item->m_Id);
 
294
                New->m_Label = Item->m_Label;
 
295
                New->m_Bitmap = Item->m_Bitmap;
 
296
                New->m_Bitmap2 = Item->m_Bitmap2;
 
297
                New->m_ToolTip = Item->m_ToolTip;
 
298
                New->m_HelpText = Item->m_HelpText;
 
299
 
 
300
                wxsEvents& Events = New->GetEvents();
 
301
                if ( Events.GetCount() > 0 ) Events.SetHandler(0,Item->m_Handler1);
 
302
                if ( Events.GetCount() > 1 ) Events.SetHandler(1,Item->m_Handler2);
 
303
            }
 
304
 
 
305
            NewChildrenArray[i] = New;
 
306
        }
 
307
    }
 
308
 
 
309
    // Removing items from toolbar which are not reused
 
310
    for ( int i=m_ToolBar->GetChildCount(); i-->0; )
 
311
    {
 
312
        wxsItem* Child = m_ToolBar->GetChild(i);
 
313
        m_ToolBar->UnbindChild(Child);
 
314
        if ( !ParentChildrenUsed[i] )
 
315
        {
 
316
            delete Child;
 
317
        }
 
318
    }
 
319
 
 
320
    // Adding new items into toolbar
 
321
    for ( int i=0; i<NewCount; i++ )
 
322
    {
 
323
        if ( !m_ToolBar->AddChild(NewChildrenArray[i]) )
 
324
        {
 
325
            delete NewChildrenArray[i];
 
326
        }
 
327
    }
 
328
 
 
329
    delete[] NewChildrenArray;
 
330
    m_ToolBar->GetResourceData()->EndChange();
 
331
}
 
332
 
 
333
wxString wxsToolBarEditor::GetItemLabel(ToolBarItem* Item)
 
334
{
 
335
    if ( Item->m_Type == Separator ) return _T("--------");
 
336
    return Item->m_Label;
 
337
}
 
338
 
 
339
 
 
340
void wxsToolBarEditor::Onm_ContentSelect(wxCommandEvent& event)
 
341
{
 
342
    if ( m_BlockSelect ) return;
 
343
    int Selection = m_Content->GetSelection();
 
344
    if ( Selection == wxNOT_FOUND )
 
345
    {
 
346
        SelectItem(0);
 
347
    }
 
348
    else
 
349
    {
 
350
        SelectItem((ToolBarItem*)m_Content->GetClientObject(Selection));
 
351
    }
 
352
}
 
353
 
 
354
 
 
355
void wxsToolBarEditor::Onm_LabelText(wxCommandEvent& event)
 
356
{
 
357
    if ( m_BlockTextChange ) return;
 
358
    m_BlockSelect = true;
 
359
    if ( m_Selected )
 
360
    {
 
361
        m_Selected->m_Label = m_Label->GetValue();
 
362
        int Selection = m_Content->GetSelection();
 
363
        m_Content->SetString(Selection,GetItemLabel(m_Selected));
 
364
        m_Content->SetSelection(Selection);
 
365
    }
 
366
    m_BlockSelect = false;
 
367
}
 
368
 
 
369
void wxsToolBarEditor::SelectItem(ToolBarItem* Item)
 
370
{
 
371
    m_BlockTextChange = true;
 
372
    if ( m_Selected != 0 )
 
373
    {
 
374
        // Storing current content
 
375
        // If it's control we do not store anything since
 
376
        // can not change anything inside external control
 
377
        if ( m_Selected->m_Type != Control )
 
378
        {
 
379
            m_Selected->m_Type = Normal;
 
380
            if ( m_TypeCheck->GetValue() ) m_Selected->m_Type = Check;
 
381
            if ( m_TypeRadio->GetValue() ) m_Selected->m_Type = Radio;
 
382
            if ( m_TypeSeparator->GetValue() ) m_Selected->m_Type = Separator;
 
383
 
 
384
            m_Selected->m_Id = m_Id->GetValue();
 
385
            m_Selected->m_Label = m_Label->GetValue();
 
386
            m_Selected->m_ToolTip = m_ToolTip->GetValue();
 
387
            m_Selected->m_HelpText = m_HelpText->GetValue();
 
388
        }
 
389
    }
 
390
 
 
391
    if ( m_Selected == Item )
 
392
    {
 
393
        m_BlockTextChange = false;
 
394
        return;
 
395
    }
 
396
    m_Selected = Item;
 
397
 
 
398
    if ( m_Selected )
 
399
    {
 
400
        if ( m_Selected->m_Type == Control )
 
401
        {
 
402
            m_TypeNormal->Disable();
 
403
            m_TypeNormal->SetValue(false);
 
404
            m_TypeCheck->Disable();
 
405
            m_TypeCheck->SetValue(false);
 
406
            m_TypeRadio->Disable();
 
407
            m_TypeRadio->SetValue(false);
 
408
            m_TypeSeparator->Disable();
 
409
            m_TypeSeparator->SetValue(false);
 
410
            m_Id->Disable();
 
411
            m_Id->SetValue(_T(""));
 
412
            m_Label->Disable();
 
413
            m_Label->SetValue(_T(""));
 
414
            m_Bitmap->Disable();
 
415
            m_Bitmap->SetBitmapLabel(wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_("wxART_FILE_OPEN")),_("wxART_TOOLBAR")));
 
416
            m_Bitmap2->Disable();
 
417
            m_Bitmap2->SetBitmapLabel(wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_("wxART_FILE_OPEN")),_("wxART_TOOLBAR")));
 
418
            m_ToolTip->Disable();
 
419
            m_ToolTip->SetValue(_T(""));
 
420
            m_HelpText->Disable();
 
421
            m_HelpText->SetValue(_T(""));
 
422
        }
 
423
        else
 
424
        {
 
425
            bool IsSeparator = m_Selected->m_Type == Separator;
 
426
            m_TypeNormal->Enable();
 
427
            m_TypeNormal->SetValue(m_Selected->m_Type == Normal);
 
428
            m_TypeCheck->Enable();
 
429
            m_TypeCheck->SetValue(m_Selected->m_Type == Check);
 
430
            m_TypeRadio->Enable();
 
431
            m_TypeRadio->SetValue(m_Selected->m_Type == Radio);
 
432
            m_TypeSeparator->Enable();
 
433
            m_TypeSeparator->SetValue(m_Selected->m_Type == Separator);
 
434
            m_Id->Enable(!IsSeparator);
 
435
            m_Id->SetValue(m_Selected->m_Id);
 
436
            m_Label->Enable(!IsSeparator);
 
437
            m_Label->SetValue(m_Selected->m_Label);
 
438
            m_Bitmap->Enable(!IsSeparator);
 
439
            if ( m_Selected->m_Bitmap.IsEmpty() )
 
440
            {
 
441
                m_Bitmap->SetBitmapLabel(wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_FILE_OPEN")),_T("wxART_TOOLBAR")));
 
442
            }
 
443
            else
 
444
            {
 
445
                m_Bitmap->SetBitmapLabel(m_Selected->m_Bitmap.GetPreview(wxDefaultSize,_T("wxART_TOOLBAR")));
 
446
            }
 
447
            m_Bitmap2->Enable(!IsSeparator);
 
448
            if ( m_Selected->m_Bitmap2.IsEmpty() )
 
449
            {
 
450
                m_Bitmap2->SetBitmapLabel(wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_FILE_OPEN")),_T("wxART_TOOLBAR")));
 
451
            }
 
452
            else
 
453
            {
 
454
                m_Bitmap2->SetBitmapLabel(m_Selected->m_Bitmap2.GetPreview(wxDefaultSize,_T("wxART_TOOLBAR")));
 
455
            }
 
456
            m_ToolTip->Enable(!IsSeparator);
 
457
            m_ToolTip->SetValue(m_Selected->m_ToolTip);
 
458
            m_HelpText->Enable(!IsSeparator);
 
459
            m_HelpText->SetValue(m_Selected->m_HelpText);
 
460
        }
 
461
    }
 
462
 
 
463
    m_BlockTextChange = false;
 
464
}
 
465
 
 
466
void wxsToolBarEditor::OnUpClick(wxCommandEvent& event)
 
467
{
 
468
    if ( !m_Selected ) return;
 
469
    SelectItem(m_Selected);
 
470
    int SelIndex = m_Content->GetSelection();
 
471
    if ( SelIndex == wxNOT_FOUND ) return;
 
472
    if ( SelIndex == 0 ) return;
 
473
    // We will delete previous item and put it after this one
 
474
    ToolBarItem* Copy = new ToolBarItem(*((ToolBarItem*)m_Content->GetClientObject(SelIndex-1)));
 
475
    m_Content->Delete(SelIndex-1);
 
476
    m_Content->Insert(GetItemLabel(Copy),SelIndex,Copy);
 
477
}
 
478
 
 
479
void wxsToolBarEditor::OnDownClick(wxCommandEvent& event)
 
480
{
 
481
    if ( !m_Selected ) return;
 
482
    SelectItem(m_Selected);
 
483
    int SelIndex = m_Content->GetSelection();
 
484
    if ( SelIndex == wxNOT_FOUND ) return;
 
485
    if ( SelIndex > (int)m_Content->GetCount()-2  ) return;
 
486
    // We will delete next item and put it before this one
 
487
    ToolBarItem* Copy = new ToolBarItem(*((ToolBarItem*)m_Content->GetClientObject(SelIndex+1)));
 
488
    m_Content->Delete(SelIndex+1);
 
489
    m_Content->Insert(GetItemLabel(Copy),SelIndex,Copy);
 
490
}
 
491
 
 
492
void wxsToolBarEditor::OnNewClick(wxCommandEvent& event)
 
493
{
 
494
    SelectItem(m_Selected);
 
495
    ToolBarItem* New = new ToolBarItem();
 
496
    New->m_Label = _("New item");
 
497
    int SelIndex = m_Content->GetSelection();
 
498
    if ( SelIndex == wxNOT_FOUND )
 
499
    {
 
500
        m_Content->SetSelection(m_Content->Append(GetItemLabel(New),New));
 
501
    }
 
502
    else
 
503
    {
 
504
        m_Content->Insert(GetItemLabel(New),SelIndex+1,New);
 
505
        m_Content->SetSelection(SelIndex+1);
 
506
    }
 
507
    SelectItem(New);
 
508
}
 
509
 
 
510
void wxsToolBarEditor::OnDelClick(wxCommandEvent& event)
 
511
{
 
512
    int Selection = m_Content->GetSelection();
 
513
    if ( Selection == wxNOT_FOUND ) return;
 
514
    if ( cbMessageBox(_("Are you sure to delete this item?"),
 
515
                      _("Deleting wxToolBar item"),
 
516
                      wxYES_NO) == wxID_YES )
 
517
    {
 
518
        m_Content->Delete(Selection);
 
519
        if ( (int)m_Content->GetCount() == Selection ) Selection--;
 
520
        if ( Selection > 0 )
 
521
        {
 
522
            m_Content->SetSelection(Selection);
 
523
            SelectItem((ToolBarItem*)m_Content->GetClientObject(Selection));
 
524
        }
 
525
        else
 
526
        {
 
527
            m_Content->SetSelection(wxNOT_FOUND);
 
528
            SelectItem(0);
 
529
        }
 
530
    }
 
531
}
 
532
 
 
533
void wxsToolBarEditor::OnBitmapClick(wxCommandEvent& event)
 
534
{
 
535
    if ( !m_Selected ) return;
 
536
    ToolBarItem* Selected = m_Selected;
 
537
    SelectItem(Selected);
 
538
    wxsBitmapIconEditorDlg Dlg(this,Selected->m_Bitmap,_T("wxART_TOOLBAR"));
 
539
    Dlg.ShowModal();
 
540
    SelectItem(0);
 
541
    SelectItem(Selected);
 
542
}
 
543
 
 
544
 
 
545
void wxsToolBarEditor::OnBitmap2Click(wxCommandEvent& event)
 
546
{
 
547
    if ( !m_Selected ) return;
 
548
    ToolBarItem* Selected = m_Selected;
 
549
    SelectItem(Selected);
 
550
    wxsBitmapIconEditorDlg Dlg(this,Selected->m_Bitmap2,_T("wxART_TOOLBAR"));
 
551
    Dlg.ShowModal();
 
552
    SelectItem(0);
 
553
    SelectItem(Selected);
 
554
}