2 #include "ValueListCtrl.h"
7 enum {VALUEMODIFY
=200, VALUEDELETE
, VALUERENAME
};
9 BEGIN_EVENT_TABLE(ValueListCtrl
, wxListCtrl
)
10 EVT_RIGHT_DOWN(ValueListCtrl::OnRightDown
)
11 EVT_MENU(VALUEMODIFY
, ValueListCtrl::OnModify
)
12 EVT_MENU(VALUEDELETE
, ValueListCtrl::OnDelete
)
13 EVT_MENU(VALUERENAME
, ValueListCtrl::OnRename
)
17 ValueListCtrl::ValueListCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
, const wxString
& name
)
18 : wxListCtrl(parent
, id
, pos
, size
, style
| wxLC_REPORT
| wxLC_SINGLE_SEL
, validator
, name
)
20 InsertColumn(0, "Name");
21 InsertColumn(1, "Type");
22 InsertColumn(2, "Data");
25 ValueListCtrl::~ValueListCtrl()
29 void ValueListCtrl::DisplaySection(const ACE_Configuration_Section_Key
& Key
)
33 m_pConfig
= MainFrame::Instance()->GetpConfig();
36 ACE_Configuration::VALUETYPE Type
;
37 ACE_TString StringValue
;
39 while(!m_pConfig
->enumerate_values(Key
, Index
, Name
, Type
))
41 int Row
= InsertItem(0, Name
.fast_rep());
44 case ACE_Configuration::STRING
:
45 SetItem(Row
, 1, "String");
46 m_pConfig
->get_string_value(Key
, Name
.fast_rep(), StringValue
);
47 SetItem(Row
, 2, StringValue
.fast_rep());
49 case ACE_Configuration::INTEGER
:
51 SetItem(Row
, 1, "Integer");
52 m_pConfig
->get_integer_value(Key
, Name
.fast_rep(), UINTValue
);
54 Text
.sprintf("%d", UINTValue
);
55 SetItem(Row
, 2, Text
);
58 case ACE_Configuration::BINARY
:
59 SetItem(Row
, 1, "Binary");
62 SetItemData(Row
, Type
);
67 long ValueListCtrl::GetSelectedItem()
69 return GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
72 void ValueListCtrl::SelectItem(long ItemID
)
74 // XXX Something isn't right here... When I use a mask it doesn't work at
75 // all someone explain..
76 long State
= wxLIST_STATE_SELECTED
| wxLIST_STATE_FOCUSED
;
77 SetItemState(ItemID
, State
, State
);
80 void ValueListCtrl::OnRightDown(wxMouseEvent
& event
)
82 int Flags
= wxLIST_HITTEST_ONITEM
;
83 long ItemID
= HitTest(wxPoint(event
.m_x
, event
.m_y
), Flags
);
90 wxMenu
* pMenu
= new wxMenu
;
91 pMenu
->Append(VALUEMODIFY
, "Modify");
92 pMenu
->AppendSeparator();
93 pMenu
->Append(VALUEDELETE
, "Delete");
94 pMenu
->Append(VALUERENAME
, "Rename");
95 PopupMenu(pMenu
, event
.m_x
, event
.m_y
);
99 void ValueListCtrl::OnModify(wxCommandEvent
& event
)
101 long Item
= GetSelectedItem();
107 ACE_Configuration::VALUETYPE Type
= (ACE_Configuration::VALUETYPE
)GetItemData(Item
);
108 wxString Name
= GetItemText(Item
);
112 case ACE_Configuration::STRING
:
115 m_pConfig
->get_string_value(m_Key
, Name
, Value
);
116 wxString
ValueText(Value
.fast_rep());
117 ValueDlg
Dlg(this, Name
, ValueText
);
118 if(Dlg
.ShowModal() != wxID_OK
)
123 Value
= (const char*)Dlg
.GetStringValue();
124 m_pConfig
->set_string_value(m_Key
, Name
, Value
);
127 case ACE_Configuration::INTEGER
:
130 m_pConfig
->get_integer_value(m_Key
, Name
, Value
);
131 ValueDlg
Dlg(this, Name
, Value
);
132 if(Dlg
.ShowModal() != wxID_OK
)
137 Value
= Dlg
.GetUINTValue();
138 m_pConfig
->set_integer_value(m_Key
, Name
, Value
);
141 case ACE_Configuration::BINARY
:
143 wxMessageBox("Binary modification not supported (why don't you implement it?)");
148 DisplaySection(m_Key
);
151 void ValueListCtrl::OnDelete(wxCommandEvent
& event
)
153 wxMessageDialog
Dlg(this, "Are you sure you want to delete this value?", "Confirm Value Delete", wxYES_NO
| wxICON_EXCLAMATION
);
154 if(Dlg
.ShowModal() != wxID_YES
)
158 long Item
= GetSelectedItem();
163 wxString Text
= GetItemText(Item
);
164 m_pConfig
->remove_value(m_Key
, Text
);
168 void ValueListCtrl::OnRename(wxCommandEvent
& event
)
170 long Item
= GetSelectedItem();
176 ACE_Configuration::VALUETYPE Type
= (ACE_Configuration::VALUETYPE
)GetItemData(Item
);
177 wxString Name
= GetItemText(Item
);
179 Message
.sprintf("Enter new name for '%s'", Name
);
180 wxTextEntryDialog
Dlg(this, Message
, "Please enter text", Name
);
181 if(Dlg
.ShowModal() != wxID_OK
)
185 wxString NewName
= Dlg
.GetValue();
191 // XXX Check to see if an entry with this new name already exists
195 case ACE_Configuration::STRING
:
198 m_pConfig
->get_string_value(m_Key
, Name
, Value
);
199 m_pConfig
->set_string_value(m_Key
, NewName
, Value
);
202 case ACE_Configuration::INTEGER
:
205 m_pConfig
->get_integer_value(m_Key
, Name
, Value
);
206 m_pConfig
->set_integer_value(m_Key
, NewName
, Value
);
209 case ACE_Configuration::BINARY
:
211 wxMessageBox("Rename binary not supported (Why don't you implement it?)");
215 m_pConfig
->remove_value(m_Key
, Name
);
216 DisplaySection(m_Key
);
219 void ValueListCtrl::ChangeConfig(ACE_Configuration
* pConfig
)
222 DisplaySection(pConfig
->root_section());