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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
// $Id: ValueListCtrl.cpp 91813 2010-09-17 07:52:52Z johnnyw $
#include "stdafx.h"
#include "ValueListCtrl.h"
#include "MainFrame.h"
#include "ValueDlg.h"
enum {VALUEMODIFY=200, VALUEDELETE, VALUERENAME};
BEGIN_EVENT_TABLE(ValueListCtrl, wxListCtrl)
EVT_RIGHT_DOWN(ValueListCtrl::OnRightDown)
EVT_MENU(VALUEMODIFY, ValueListCtrl::OnModify)
EVT_MENU(VALUEDELETE, ValueListCtrl::OnDelete)
EVT_MENU(VALUERENAME, ValueListCtrl::OnRename)
END_EVENT_TABLE()
ValueListCtrl::ValueListCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name)
: wxListCtrl(parent, id, pos, size, style | wxLC_REPORT | wxLC_SINGLE_SEL, validator, name)
{
InsertColumn(0, "Name");
InsertColumn(1, "Type");
InsertColumn(2, "Data");
}
ValueListCtrl::~ValueListCtrl()
{
}
void ValueListCtrl::DisplaySection(const ACE_Configuration_Section_Key& Key)
{
m_Key = Key;
DeleteAllItems();
m_pConfig = MainFrame::Instance()->GetpConfig();
ACE_TString Name;
int Index = 0;
ACE_Configuration::VALUETYPE Type;
ACE_TString StringValue;
u_int UINTValue;
while(!m_pConfig->enumerate_values(Key, Index, Name, Type))
{
int Row = InsertItem(0, Name.fast_rep());
switch(Type)
{
case ACE_Configuration::STRING:
SetItem(Row, 1, "String");
m_pConfig->get_string_value(Key, Name.fast_rep(), StringValue);
SetItem(Row, 2, StringValue.fast_rep());
break;
case ACE_Configuration::INTEGER:
{
SetItem(Row, 1, "Integer");
m_pConfig->get_integer_value(Key, Name.fast_rep(), UINTValue);
wxString Text;
Text.sprintf("%d", UINTValue);
SetItem(Row, 2, Text);
}
break;
case ACE_Configuration::BINARY:
SetItem(Row, 1, "Binary");
break;
}
SetItemData(Row, Type);
++Index;
}
}
long ValueListCtrl::GetSelectedItem()
{
return GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
}
void ValueListCtrl::SelectItem(long ItemID)
{
// XXX Something isn't right here... When I use a mask it doesn't work at
// all someone explain..
long State = wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED;
SetItemState(ItemID, State, State);
}
void ValueListCtrl::OnRightDown(wxMouseEvent& event)
{
int Flags = wxLIST_HITTEST_ONITEM;
long ItemID = HitTest(wxPoint(event.m_x, event.m_y), Flags);
if(ItemID < 0)
{
return;
}
SelectItem(ItemID);
wxMenu* pMenu = new wxMenu;
pMenu->Append(VALUEMODIFY, "Modify");
pMenu->AppendSeparator();
pMenu->Append(VALUEDELETE, "Delete");
pMenu->Append(VALUERENAME, "Rename");
PopupMenu(pMenu, event.m_x, event.m_y);
delete pMenu;
}
void ValueListCtrl::OnModify(wxCommandEvent& event)
{
long Item = GetSelectedItem();
if(Item == -1)
{
return ;
}
wxListItem ListItem;
ACE_Configuration::VALUETYPE Type = (ACE_Configuration::VALUETYPE)GetItemData(Item);
wxString Name = GetItemText(Item);
switch(Type)
{
case ACE_Configuration::STRING:
{
ACE_TString Value;
m_pConfig->get_string_value(m_Key, Name, Value);
wxString ValueText(Value.fast_rep());
ValueDlg Dlg(this, Name, ValueText);
if(Dlg.ShowModal() != wxID_OK)
{
return;
}
Value = (const char*)Dlg.GetStringValue();
m_pConfig->set_string_value(m_Key, Name, Value);
}
break;
case ACE_Configuration::INTEGER:
{
u_int Value;
m_pConfig->get_integer_value(m_Key, Name, Value);
ValueDlg Dlg(this, Name, Value);
if(Dlg.ShowModal() != wxID_OK)
{
return;
}
Value = Dlg.GetUINTValue();
m_pConfig->set_integer_value(m_Key, Name, Value);
}
break;
case ACE_Configuration::BINARY:
{
wxMessageBox("Binary modification not supported (why don't you implement it?)");
//assert(0);
}
break;
}
DisplaySection(m_Key);
}
void ValueListCtrl::OnDelete(wxCommandEvent& event)
{
wxMessageDialog Dlg(this, "Are you sure you want to delete this value?", "Confirm Value Delete", wxYES_NO | wxICON_EXCLAMATION );
if(Dlg.ShowModal() != wxID_YES)
{
return;
}
long Item = GetSelectedItem();
if(Item == -1)
{
return ;
}
wxString Text = GetItemText(Item);
m_pConfig->remove_value(m_Key, Text);
DeleteItem(Item);
}
void ValueListCtrl::OnRename(wxCommandEvent& event)
{
long Item = GetSelectedItem();
if(Item == -1)
{
return ;
}
wxListItem ListItem;
ACE_Configuration::VALUETYPE Type = (ACE_Configuration::VALUETYPE)GetItemData(Item);
wxString Name = GetItemText(Item);
wxString Message;
Message.sprintf("Enter new name for '%s'", Name);
wxTextEntryDialog Dlg(this, Message, "Please enter text", Name);
if(Dlg.ShowModal() != wxID_OK)
{
return;
}
wxString NewName = Dlg.GetValue();
if(NewName == Name)
{
return;
}
// XXX Check to see if an entry with this new name already exists
switch(Type)
{
case ACE_Configuration::STRING:
{
ACE_TString Value;
m_pConfig->get_string_value(m_Key, Name, Value);
m_pConfig->set_string_value(m_Key, NewName, Value);
}
break;
case ACE_Configuration::INTEGER:
{
u_int Value;
m_pConfig->get_integer_value(m_Key, Name, Value);
m_pConfig->set_integer_value(m_Key, NewName, Value);
}
break;
case ACE_Configuration::BINARY:
{
wxMessageBox("Rename binary not supported (Why don't you implement it?)");
assert(0);
}
}
m_pConfig->remove_value(m_Key, Name);
DisplaySection(m_Key);
}
void ValueListCtrl::ChangeConfig(ACE_Configuration* pConfig)
{
m_pConfig = pConfig;
DisplaySection(pConfig->root_section());
}
|