Menu

[r13158]: / trunk / src / sdk / editarrayorderdlg.cpp  Maximize  Restore  History

Download this file

108 lines (88 with data), 2.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
/*
* This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
* http://www.gnu.org/licenses/lgpl-3.0.html
*
* $Revision$
* $Id$
* $HeadURL$
*/
#include "sdk_precomp.h"
#ifndef CB_PRECOMP
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
#include <wx/button.h>
#include <wx/listbox.h>
#endif
#include "editarrayorderdlg.h" // class's header file
BEGIN_EVENT_TABLE(EditArrayOrderDlg, wxScrollingDialog)
EVT_UPDATE_UI( -1, EditArrayOrderDlg::OnUpdateUI)
EVT_BUTTON(XRCID("btnMoveUp"), EditArrayOrderDlg::OnMoveUp)
EVT_BUTTON(XRCID("btnMoveDown"), EditArrayOrderDlg::OnMoveDown)
END_EVENT_TABLE()
// class constructor
EditArrayOrderDlg::EditArrayOrderDlg(wxWindow* parent, const wxArrayString& array)
: m_Array(array)
{
wxXmlResource::Get()->LoadObject(this, parent, _T("dlgEditArrayOrder"),_T("wxScrollingDialog"));
DoFillList();
XRCCTRL(*this, "wxID_OK", wxButton)->SetDefault();
wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
list->SetFocus();
}
// class destructor
EditArrayOrderDlg::~EditArrayOrderDlg()
{
}
void EditArrayOrderDlg::SetArray(const wxArrayString& array)
{
m_Array = array;
DoFillList();
}
void EditArrayOrderDlg::DoFillList()
{
wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
list->Clear();
for (unsigned int i = 0; i < m_Array.GetCount(); ++i)
list->Append(m_Array[i]);
}
void EditArrayOrderDlg::OnUpdateUI(wxUpdateUIEvent& WXUNUSED(event))
{
wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
XRCCTRL(*this, "btnMoveUp", wxButton)->Enable(list->GetSelection() > 0);
XRCCTRL(*this, "btnMoveDown", wxButton)->Enable(list->GetSelection() >= 0 && list->GetSelection() < (int)list->GetCount() - 1);
}
void EditArrayOrderDlg::OnMoveUp(wxCommandEvent& WXUNUSED(event))
{
wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
int sel = list->GetSelection();
if (sel > 0)
{
wxString tmp = list->GetString(sel);
list->Delete(sel);
list->InsertItems(1, &tmp, sel - 1);
list->SetSelection(sel - 1);
}
}
void EditArrayOrderDlg::OnMoveDown(wxCommandEvent& WXUNUSED(event))
{
wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
int sel = list->GetSelection();
if (sel < (int)list->GetCount() - 1)
{
wxString tmp = list->GetString(sel);
list->Delete(sel);
list->InsertItems(1, &tmp, sel + 1);
list->SetSelection(sel + 1);
}
}
void EditArrayOrderDlg::EndModal(int retCode)
{
if (retCode == wxID_OK)
{
wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
m_Array.Clear();
for (int i = 0; i < (int)list->GetCount(); ++i)
m_Array.Add(list->GetString(i));
}
wxScrollingDialog::EndModal(retCode);
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.