Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / ConfigViewer / ValueListCtrl.cpp
blob9a30226ef3b1300df5f7001fefd14839e191beae
1 #include "stdafx.h"
2 #include "ValueListCtrl.h"
3 #include "MainFrame.h"
4 #include "ValueDlg.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)
14 END_EVENT_TABLE()
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)
31 m_Key = Key;
32 DeleteAllItems();
33 m_pConfig = MainFrame::Instance()->GetpConfig();
34 ACE_TString Name;
35 int Index = 0;
36 ACE_Configuration::VALUETYPE Type;
37 ACE_TString StringValue;
38 u_int UINTValue;
39 while(!m_pConfig->enumerate_values(Key, Index, Name, Type))
41 int Row = InsertItem(0, Name.fast_rep());
42 switch(Type)
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());
48 break;
49 case ACE_Configuration::INTEGER:
51 SetItem(Row, 1, "Integer");
52 m_pConfig->get_integer_value(Key, Name.fast_rep(), UINTValue);
53 wxString Text;
54 Text.sprintf("%d", UINTValue);
55 SetItem(Row, 2, Text);
57 break;
58 case ACE_Configuration::BINARY:
59 SetItem(Row, 1, "Binary");
60 break;
62 SetItemData(Row, Type);
63 ++Index;
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);
84 if(ItemID < 0)
86 return;
88 SelectItem(ItemID);
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);
96 delete pMenu;
99 void ValueListCtrl::OnModify(wxCommandEvent& event)
101 long Item = GetSelectedItem();
102 if(Item == -1)
104 return;
106 wxListItem ListItem;
107 ACE_Configuration::VALUETYPE Type = (ACE_Configuration::VALUETYPE)GetItemData(Item);
108 wxString Name = GetItemText(Item);
110 switch(Type)
112 case ACE_Configuration::STRING:
114 ACE_TString Value;
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)
120 return;
123 Value = (const char*)Dlg.GetStringValue();
124 m_pConfig->set_string_value(m_Key, Name, Value);
126 break;
127 case ACE_Configuration::INTEGER:
129 u_int Value;
130 m_pConfig->get_integer_value(m_Key, Name, Value);
131 ValueDlg Dlg(this, Name, Value);
132 if(Dlg.ShowModal() != wxID_OK)
134 return;
137 Value = Dlg.GetUINTValue();
138 m_pConfig->set_integer_value(m_Key, Name, Value);
140 break;
141 case ACE_Configuration::BINARY:
143 wxMessageBox("Binary modification not supported (why don't you implement it?)");
144 //assert(0);
146 break;
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)
156 return;
158 long Item = GetSelectedItem();
159 if(Item == -1)
161 return;
163 wxString Text = GetItemText(Item);
164 m_pConfig->remove_value(m_Key, Text);
165 DeleteItem(Item);
168 void ValueListCtrl::OnRename(wxCommandEvent& event)
170 long Item = GetSelectedItem();
171 if(Item == -1)
173 return;
175 wxListItem ListItem;
176 ACE_Configuration::VALUETYPE Type = (ACE_Configuration::VALUETYPE)GetItemData(Item);
177 wxString Name = GetItemText(Item);
178 wxString Message;
179 Message.sprintf("Enter new name for '%s'", Name);
180 wxTextEntryDialog Dlg(this, Message, "Please enter text", Name);
181 if(Dlg.ShowModal() != wxID_OK)
183 return;
185 wxString NewName = Dlg.GetValue();
186 if(NewName == Name)
188 return;
191 // XXX Check to see if an entry with this new name already exists
193 switch(Type)
195 case ACE_Configuration::STRING:
197 ACE_TString Value;
198 m_pConfig->get_string_value(m_Key, Name, Value);
199 m_pConfig->set_string_value(m_Key, NewName, Value);
201 break;
202 case ACE_Configuration::INTEGER:
204 u_int Value;
205 m_pConfig->get_integer_value(m_Key, Name, Value);
206 m_pConfig->set_integer_value(m_Key, NewName, Value);
208 break;
209 case ACE_Configuration::BINARY:
211 wxMessageBox("Rename binary not supported (Why don't you implement it?)");
212 assert(0);
215 m_pConfig->remove_value(m_Key, Name);
216 DisplaySection(m_Key);
219 void ValueListCtrl::ChangeConfig(ACE_Configuration* pConfig)
221 m_pConfig = pConfig;
222 DisplaySection(pConfig->root_section());