[f17e6dc6] | 1 | // |
---|
| 2 | // aventreectrl.cc |
---|
| 3 | // |
---|
| 4 | // Tree control used for the survey tree. |
---|
| 5 | // |
---|
| 6 | // Copyright (C) 2001, Mark R. Shinwell. |
---|
[672459c] | 7 | // Copyright (C) 2001-2003,2005,2006,2016,2018 Olly Betts |
---|
[887c26e] | 8 | // Copyright (C) 2005 Martin Green |
---|
[f17e6dc6] | 9 | // |
---|
| 10 | // This program is free software; you can redistribute it and/or modify |
---|
| 11 | // it under the terms of the GNU General Public License as published by |
---|
| 12 | // the Free Software Foundation; either version 2 of the License, or |
---|
| 13 | // (at your option) any later version. |
---|
| 14 | // |
---|
| 15 | // This program is distributed in the hope that it will be useful, |
---|
| 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 18 | // GNU General Public License for more details. |
---|
| 19 | // |
---|
| 20 | // You should have received a copy of the GNU General Public License |
---|
| 21 | // along with this program; if not, write to the Free Software |
---|
[ecbc6c18] | 22 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
[f17e6dc6] | 23 | // |
---|
| 24 | |
---|
[cbfa50d] | 25 | #ifdef HAVE_CONFIG_H |
---|
| 26 | #include <config.h> |
---|
| 27 | #endif |
---|
| 28 | |
---|
[f17e6dc6] | 29 | #include "aventreectrl.h" |
---|
| 30 | #include "mainfrm.h" |
---|
| 31 | |
---|
[17a38ded] | 32 | #include <stack> |
---|
| 33 | |
---|
| 34 | using namespace std; |
---|
| 35 | |
---|
[44e007d] | 36 | // STATE_BLANK is used for stations which are siblings of surveys which have |
---|
| 37 | // select checkboxes. |
---|
| 38 | enum { STATE_BLANK = 0, STATE_OFF, STATE_ON }; |
---|
[672459c] | 39 | |
---|
| 40 | /* XPM */ |
---|
[44e007d] | 41 | static const char *blank_xpm[] = { |
---|
| 42 | /* columns rows colors chars-per-pixel */ |
---|
| 43 | "15 15 1 1", |
---|
| 44 | " c None", |
---|
| 45 | /* pixels */ |
---|
| 46 | " ", |
---|
| 47 | " ", |
---|
| 48 | " ", |
---|
| 49 | " ", |
---|
| 50 | " ", |
---|
| 51 | " ", |
---|
| 52 | " ", |
---|
| 53 | " ", |
---|
| 54 | " ", |
---|
| 55 | " ", |
---|
| 56 | " ", |
---|
| 57 | " ", |
---|
| 58 | " ", |
---|
| 59 | " ", |
---|
| 60 | " " |
---|
| 61 | }; |
---|
| 62 | |
---|
| 63 | /* XPM */ |
---|
| 64 | static const char *off_xpm[] = { |
---|
[672459c] | 65 | /* columns rows colors chars-per-pixel */ |
---|
[c78d5b4] | 66 | "15 15 2 1", |
---|
| 67 | ". c #000000", |
---|
[672459c] | 68 | " c None", |
---|
| 69 | /* pixels */ |
---|
| 70 | " ", |
---|
| 71 | " ", |
---|
[c78d5b4] | 72 | " ............ ", |
---|
| 73 | " . . ", |
---|
| 74 | " . . ", |
---|
| 75 | " . . ", |
---|
| 76 | " . . ", |
---|
| 77 | " . . ", |
---|
| 78 | " . . ", |
---|
| 79 | " . . ", |
---|
| 80 | " . . ", |
---|
| 81 | " . . ", |
---|
| 82 | " . . ", |
---|
| 83 | " ............ ", |
---|
[672459c] | 84 | " " |
---|
| 85 | }; |
---|
| 86 | |
---|
| 87 | /* XPM */ |
---|
[44e007d] | 88 | static const char *on_xpm[] = { |
---|
[672459c] | 89 | /* columns rows colors chars-per-pixel */ |
---|
[c78d5b4] | 90 | "15 15 3 1", |
---|
| 91 | ". c #000000", |
---|
[672459c] | 92 | "X c #007F28", |
---|
| 93 | " c None", |
---|
| 94 | /* pixels */ |
---|
| 95 | " ", |
---|
[c78d5b4] | 96 | " ", |
---|
| 97 | " ............XX", |
---|
| 98 | " . XXX", |
---|
| 99 | " . XXXX", |
---|
| 100 | " . XXXX ", |
---|
| 101 | " . XXXX ", |
---|
| 102 | " . XXXX. ", |
---|
| 103 | " . XX XXXX . ", |
---|
| 104 | " . XXXXXXX . ", |
---|
| 105 | " . XXXXX . ", |
---|
| 106 | " . XXX . ", |
---|
| 107 | " . X . ", |
---|
| 108 | " ............ ", |
---|
[672459c] | 109 | " " |
---|
| 110 | }; |
---|
| 111 | |
---|
[f17e6dc6] | 112 | BEGIN_EVENT_TABLE(AvenTreeCtrl, wxTreeCtrl) |
---|
| 113 | EVT_MOTION(AvenTreeCtrl::OnMouseMove) |
---|
[887c26e] | 114 | EVT_LEAVE_WINDOW(AvenTreeCtrl::OnLeaveWindow) |
---|
[f17e6dc6] | 115 | EVT_TREE_SEL_CHANGED(-1, AvenTreeCtrl::OnSelChanged) |
---|
[44ed489] | 116 | EVT_TREE_ITEM_ACTIVATED(-1, AvenTreeCtrl::OnItemActivated) |
---|
[5901b62] | 117 | EVT_CHAR(AvenTreeCtrl::OnKeyPress) |
---|
[5e0b9f9d] | 118 | EVT_TREE_ITEM_MENU(-1, AvenTreeCtrl::OnMenu) |
---|
[d5fd4f4] | 119 | EVT_MENU(menu_SURVEY_SHOW_ALL, AvenTreeCtrl::OnRestrict) |
---|
[5e0b9f9d] | 120 | EVT_MENU(menu_SURVEY_RESTRICT, AvenTreeCtrl::OnRestrict) |
---|
[672459c] | 121 | EVT_MENU(menu_SURVEY_HIDE, AvenTreeCtrl::OnHide) |
---|
| 122 | EVT_MENU(menu_SURVEY_SHOW, AvenTreeCtrl::OnShow) |
---|
| 123 | EVT_MENU(menu_SURVEY_HIDE_SIBLINGS, AvenTreeCtrl::OnHideSiblings) |
---|
| 124 | EVT_TREE_STATE_IMAGE_CLICK(-1, AvenTreeCtrl::OnStateClick) |
---|
[f17e6dc6] | 125 | END_EVENT_TABLE() |
---|
| 126 | |
---|
| 127 | AvenTreeCtrl::AvenTreeCtrl(MainFrm* parent, wxWindow* window_parent) : |
---|
[84f1ed1] | 128 | wxTreeCtrl(window_parent, -1), |
---|
[b623b3e] | 129 | m_Parent(parent), |
---|
[b4fe9fb] | 130 | m_Enabled(false), |
---|
[3eddcaf4] | 131 | m_LastItem(), |
---|
[efb30c4] | 132 | m_BackgroundColour(), |
---|
[5e0b9f9d] | 133 | m_SelValid(false), |
---|
| 134 | menu_data(NULL) |
---|
[f17e6dc6] | 135 | { |
---|
[672459c] | 136 | wxImageList* img_list = new wxImageList(15, 15, 2); |
---|
[44e007d] | 137 | img_list->Add(wxBitmap(blank_xpm)); |
---|
| 138 | img_list->Add(wxBitmap(off_xpm)); |
---|
| 139 | img_list->Add(wxBitmap(on_xpm)); |
---|
[672459c] | 140 | AssignStateImageList(img_list); |
---|
[f17e6dc6] | 141 | } |
---|
| 142 | |
---|
[17a38ded] | 143 | void AvenTreeCtrl::FillTree(const wxString& root_name) |
---|
| 144 | { |
---|
| 145 | Freeze(); |
---|
| 146 | m_Enabled = false; |
---|
| 147 | m_LastItem = wxTreeItemId(); |
---|
| 148 | m_SelValid = false; |
---|
| 149 | DeleteAllItems(); |
---|
| 150 | |
---|
| 151 | const wxChar separator = m_Parent->GetSeparator(); |
---|
| 152 | filter.clear(); |
---|
| 153 | filter.SetSeparator(separator); |
---|
| 154 | |
---|
| 155 | // Create the root of the tree. |
---|
| 156 | wxTreeItemId treeroot = AddRoot(root_name); |
---|
| 157 | |
---|
| 158 | // Fill the tree of stations and prefixes. |
---|
| 159 | stack<wxTreeItemId> previous_ids; |
---|
| 160 | wxString current_prefix; |
---|
| 161 | wxTreeItemId current_id = treeroot; |
---|
| 162 | |
---|
| 163 | list<LabelInfo*>::const_iterator pos = m_Parent->GetLabels(); |
---|
| 164 | while (pos != m_Parent->GetLabelsEnd()) { |
---|
| 165 | LabelInfo* label = *pos++; |
---|
| 166 | |
---|
| 167 | if (label->IsAnon()) continue; |
---|
| 168 | |
---|
| 169 | // Determine the current prefix. |
---|
| 170 | wxString prefix = label->GetText().BeforeLast(separator); |
---|
| 171 | |
---|
| 172 | // Determine if we're still on the same prefix. |
---|
| 173 | if (prefix == current_prefix) { |
---|
| 174 | // no need to fiddle with branches... |
---|
| 175 | } |
---|
| 176 | // If not, then see if we've descended to a new prefix. |
---|
| 177 | else if (prefix.length() > current_prefix.length() && |
---|
| 178 | prefix.StartsWith(current_prefix) && |
---|
| 179 | (prefix[current_prefix.length()] == separator || |
---|
| 180 | current_prefix.empty())) { |
---|
| 181 | // We have, so start as many new branches as required. |
---|
| 182 | int current_prefix_length = current_prefix.length(); |
---|
| 183 | current_prefix = prefix; |
---|
| 184 | size_t next_dot = current_prefix_length; |
---|
| 185 | if (!next_dot) --next_dot; |
---|
| 186 | do { |
---|
| 187 | size_t prev_dot = next_dot + 1; |
---|
| 188 | |
---|
| 189 | // Extract the next bit of prefix. |
---|
| 190 | next_dot = prefix.find(separator, prev_dot + 1); |
---|
| 191 | |
---|
| 192 | wxString bit = prefix.substr(prev_dot, next_dot - prev_dot); |
---|
| 193 | assert(!bit.empty()); |
---|
| 194 | |
---|
| 195 | // Add the current tree ID to the stack. |
---|
| 196 | previous_ids.push(current_id); |
---|
| 197 | |
---|
| 198 | // Append the new item to the tree and set this as the current branch. |
---|
| 199 | current_id = AppendItem(current_id, bit); |
---|
| 200 | SetItemData(current_id, new TreeData(prefix.substr(0, next_dot))); |
---|
| 201 | } while (next_dot != wxString::npos); |
---|
| 202 | } |
---|
| 203 | // Otherwise, we must have moved up, and possibly then down again. |
---|
| 204 | else { |
---|
| 205 | size_t count = 0; |
---|
| 206 | bool ascent_only = (prefix.length() < current_prefix.length() && |
---|
| 207 | current_prefix.StartsWith(prefix) && |
---|
| 208 | (current_prefix[prefix.length()] == separator || |
---|
| 209 | prefix.empty())); |
---|
| 210 | if (!ascent_only) { |
---|
| 211 | // Find out how much of the current prefix and the new prefix |
---|
| 212 | // are the same. |
---|
| 213 | // Note that we require a match of a whole number of parts |
---|
| 214 | // between dots! |
---|
| 215 | size_t n = min(prefix.length(), current_prefix.length()); |
---|
| 216 | size_t i; |
---|
| 217 | for (i = 0; i < n && prefix[i] == current_prefix[i]; ++i) { |
---|
| 218 | if (prefix[i] == separator) count = i + 1; |
---|
| 219 | } |
---|
| 220 | } else { |
---|
| 221 | count = prefix.length() + 1; |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | // Extract the part of the current prefix after the bit (if any) |
---|
| 225 | // which has matched. |
---|
| 226 | // This gives the prefixes to ascend over. |
---|
| 227 | wxString prefixes_ascended = current_prefix.substr(count); |
---|
| 228 | |
---|
| 229 | // Count the number of prefixes to ascend over. |
---|
| 230 | int num_prefixes = prefixes_ascended.Freq(separator); |
---|
| 231 | |
---|
| 232 | // Reverse up over these prefixes. |
---|
| 233 | for (int i = 1; i <= num_prefixes; i++) { |
---|
| 234 | previous_ids.pop(); |
---|
| 235 | } |
---|
| 236 | current_id = previous_ids.top(); |
---|
| 237 | previous_ids.pop(); |
---|
| 238 | |
---|
| 239 | if (!ascent_only) { |
---|
| 240 | // Add branches for this new part. |
---|
| 241 | size_t next_dot = count - 1; |
---|
| 242 | do { |
---|
| 243 | size_t prev_dot = next_dot + 1; |
---|
| 244 | |
---|
| 245 | // Extract the next bit of prefix. |
---|
| 246 | next_dot = prefix.find(separator, prev_dot + 1); |
---|
| 247 | |
---|
| 248 | wxString bit = prefix.substr(prev_dot, next_dot - prev_dot); |
---|
| 249 | assert(!bit.empty()); |
---|
| 250 | |
---|
| 251 | // Add the current tree ID to the stack. |
---|
| 252 | previous_ids.push(current_id); |
---|
| 253 | |
---|
| 254 | // Append the new item to the tree and set this as the current branch. |
---|
| 255 | current_id = AppendItem(current_id, bit); |
---|
| 256 | SetItemData(current_id, new TreeData(prefix.substr(0, next_dot))); |
---|
| 257 | } while (next_dot != wxString::npos); |
---|
| 258 | } |
---|
| 259 | |
---|
| 260 | current_prefix = prefix; |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | // Now add the leaf. |
---|
| 264 | wxString bit = label->GetText().AfterLast(separator); |
---|
| 265 | assert(!bit.empty()); |
---|
| 266 | wxTreeItemId id = AppendItem(current_id, bit); |
---|
| 267 | SetItemData(id, new TreeData(label)); |
---|
| 268 | label->tree_id = id; |
---|
| 269 | // Set the colour for an item in the survey tree. |
---|
| 270 | if (label->IsEntrance()) { |
---|
| 271 | // Entrances are green (like entrance blobs). |
---|
| 272 | SetItemTextColour(id, wxColour(0, 255, 40)); |
---|
| 273 | } else if (label->IsSurface()) { |
---|
| 274 | // Surface stations are dark green. |
---|
| 275 | SetItemTextColour(id, wxColour(49, 158, 79)); |
---|
| 276 | } |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | Expand(treeroot); |
---|
| 280 | m_Enabled = true; |
---|
| 281 | Thaw(); |
---|
| 282 | } |
---|
| 283 | |
---|
[9e8e1d6] | 284 | constexpr auto TREE_MASK = wxTREE_HITTEST_ONITEMLABEL | |
---|
| 285 | wxTREE_HITTEST_ONITEMRIGHT | |
---|
| 286 | wxTREE_HITTEST_ONITEMSTATEICON; |
---|
[97dd0d2] | 287 | |
---|
[f17e6dc6] | 288 | void AvenTreeCtrl::OnMouseMove(wxMouseEvent& event) |
---|
| 289 | { |
---|
[0ae40fa] | 290 | if (!m_Enabled || m_Parent->Animating()) |
---|
| 291 | return; |
---|
| 292 | |
---|
| 293 | int flags; |
---|
| 294 | wxTreeItemId pos = HitTest(event.GetPosition(), flags); |
---|
| 295 | if (!(flags & TREE_MASK)) { |
---|
| 296 | pos = wxTreeItemId(); |
---|
| 297 | } |
---|
| 298 | if (pos == m_LastItem) return; |
---|
| 299 | if (pos.IsOk()) { |
---|
| 300 | m_Parent->DisplayTreeInfo(GetItemData(pos)); |
---|
| 301 | } else { |
---|
| 302 | m_Parent->DisplayTreeInfo(); |
---|
[f17e6dc6] | 303 | } |
---|
| 304 | } |
---|
| 305 | |
---|
[570d62c3] | 306 | void AvenTreeCtrl::SetHere(wxTreeItemId pos) |
---|
| 307 | { |
---|
| 308 | if (pos == m_LastItem) return; |
---|
| 309 | |
---|
| 310 | if (m_LastItem.IsOk()) { |
---|
| 311 | SetItemBackgroundColour(m_LastItem, m_BackgroundColour); |
---|
| 312 | } |
---|
| 313 | if (pos.IsOk()) { |
---|
| 314 | m_BackgroundColour = GetItemBackgroundColour(pos); |
---|
| 315 | SetItemBackgroundColour(pos, wxColour(180, 180, 180)); |
---|
| 316 | } |
---|
| 317 | m_LastItem = pos; |
---|
| 318 | } |
---|
| 319 | |
---|
[887c26e] | 320 | void AvenTreeCtrl::OnLeaveWindow(wxMouseEvent&) |
---|
| 321 | { |
---|
| 322 | if (m_LastItem.IsOk()) { |
---|
| 323 | SetItemBackgroundColour(m_LastItem, m_BackgroundColour); |
---|
| 324 | m_LastItem = wxTreeItemId(); |
---|
| 325 | } |
---|
[381ae6e] | 326 | m_Parent->DisplayTreeInfo(); |
---|
[887c26e] | 327 | } |
---|
| 328 | |
---|
[5dae1ba] | 329 | void AvenTreeCtrl::OnSelChanged(wxTreeEvent&) |
---|
[f17e6dc6] | 330 | { |
---|
[b623b3e] | 331 | m_SelValid = true; |
---|
[f17e6dc6] | 332 | } |
---|
| 333 | |
---|
[44ed489] | 334 | void AvenTreeCtrl::OnItemActivated(wxTreeEvent& e) |
---|
| 335 | { |
---|
[4dc54fa] | 336 | if (!m_Enabled) return; |
---|
| 337 | |
---|
| 338 | m_Parent->TreeItemSelected(GetItemData(e.GetItem())); |
---|
[44ed489] | 339 | } |
---|
| 340 | |
---|
[5e0b9f9d] | 341 | void AvenTreeCtrl::OnMenu(wxTreeEvent& e) |
---|
| 342 | { |
---|
[0ae40fa] | 343 | if (!m_Enabled) return; |
---|
| 344 | |
---|
| 345 | const TreeData* data = static_cast<const TreeData*>(GetItemData(e.GetItem())); |
---|
| 346 | menu_data = data; |
---|
| 347 | menu_item = e.GetItem(); |
---|
| 348 | if (!data) { |
---|
| 349 | // Root: |
---|
| 350 | wxMenu menu; |
---|
| 351 | /* TRANSLATORS: In aven's survey tree, right-clicking on the root |
---|
| 352 | * gives a pop-up menu and this is an option (but only enabled if |
---|
| 353 | * the view is restricted to a subsurvey). It reloads the current |
---|
| 354 | * survey file with the who survey visible. |
---|
| 355 | */ |
---|
| 356 | menu.Append(menu_SURVEY_SHOW_ALL, wmsg(/*Show all*/245)); |
---|
| 357 | if (m_Parent->GetSurvey().empty()) |
---|
| 358 | menu.Enable(menu_SURVEY_SHOW_ALL, false); |
---|
| 359 | PopupMenu(&menu); |
---|
| 360 | } else if (data->GetLabel()) { |
---|
| 361 | // Station: name is data->GetLabel()->GetText() |
---|
| 362 | } else { |
---|
| 363 | // Survey: |
---|
| 364 | wxMenu menu; |
---|
| 365 | /* TRANSLATORS: In aven's survey tree, right-clicking on a survey |
---|
| 366 | * name gives a pop-up menu and this is an option. It reloads the |
---|
| 367 | * current survey file with the view restricted to the survey |
---|
| 368 | * clicked upon. |
---|
| 369 | */ |
---|
| 370 | menu.Append(menu_SURVEY_RESTRICT, wmsg(/*Hide others*/246)); |
---|
| 371 | menu.AppendSeparator(); |
---|
[699c65f] | 372 | //menu.Append(menu_SURVEY_HIDE, wmsg(/*&Hide*/407)); |
---|
[0ae40fa] | 373 | menu.Append(menu_SURVEY_SHOW, wmsg(/*&Show*/409)); |
---|
[699c65f] | 374 | //menu.Append(menu_SURVEY_HIDE_SIBLINGS, wmsg(/*Hide si&blings*/388)); |
---|
[0ae40fa] | 375 | switch (GetItemState(menu_item)) { |
---|
[44e007d] | 376 | case STATE_ON: // Currently shown. |
---|
[0ae40fa] | 377 | menu.Enable(menu_SURVEY_SHOW, false); |
---|
| 378 | break; |
---|
[672459c] | 379 | #if 0 |
---|
[0ae40fa] | 380 | case STATE_HIDDEN: // Currently hidden. |
---|
| 381 | menu.Enable(menu_SURVEY_RESTRICT, false); |
---|
| 382 | menu.Enable(menu_SURVEY_HIDE, false); |
---|
| 383 | menu.Enable(menu_SURVEY_HIDE_SIBLINGS, false); |
---|
| 384 | break; |
---|
[44e007d] | 385 | case STATE_OFF: |
---|
[0ae40fa] | 386 | menu.Enable(menu_SURVEY_HIDE, false); |
---|
| 387 | menu.Enable(menu_SURVEY_HIDE_SIBLINGS, false); |
---|
| 388 | break; |
---|
[38ba3b6] | 389 | #endif |
---|
[5e0b9f9d] | 390 | } |
---|
[0ae40fa] | 391 | PopupMenu(&menu); |
---|
[5e0b9f9d] | 392 | } |
---|
[0ae40fa] | 393 | menu_data = NULL; |
---|
| 394 | e.Skip(); |
---|
[5e0b9f9d] | 395 | } |
---|
| 396 | |
---|
[570d62c3] | 397 | bool AvenTreeCtrl::GetSelectionData(wxTreeItemData** data) const |
---|
[f17e6dc6] | 398 | { |
---|
| 399 | assert(m_Enabled); |
---|
[26fac5a] | 400 | assert(data); |
---|
[b623b3e] | 401 | |
---|
| 402 | if (!m_SelValid) { |
---|
[421b7d2] | 403 | return false; |
---|
[b623b3e] | 404 | } |
---|
[421b7d2] | 405 | |
---|
[f17e6dc6] | 406 | wxTreeItemId id = GetSelection(); |
---|
| 407 | if (id.IsOk()) { |
---|
[421b7d2] | 408 | *data = GetItemData(id); |
---|
[f17e6dc6] | 409 | } |
---|
| 410 | |
---|
[2d9ed8ad] | 411 | return id.IsOk() && *data; |
---|
[f17e6dc6] | 412 | } |
---|
[b623b3e] | 413 | |
---|
| 414 | void AvenTreeCtrl::UnselectAll() |
---|
| 415 | { |
---|
| 416 | m_SelValid = false; |
---|
| 417 | wxTreeCtrl::UnselectAll(); |
---|
| 418 | } |
---|
| 419 | |
---|
[5901b62] | 420 | void AvenTreeCtrl::OnKeyPress(wxKeyEvent &e) |
---|
| 421 | { |
---|
[a6e8d45] | 422 | switch (e.GetKeyCode()) { |
---|
[26fac5a] | 423 | case WXK_ESCAPE: |
---|
| 424 | m_Parent->ClearTreeSelection(); |
---|
| 425 | break; |
---|
| 426 | case WXK_RETURN: { |
---|
| 427 | wxTreeItemId id = GetSelection(); |
---|
| 428 | if (id.IsOk()) { |
---|
| 429 | if (ItemHasChildren(id)) { |
---|
| 430 | // If on a branch, expand/contract it. |
---|
| 431 | if (IsExpanded(id)) { |
---|
| 432 | Collapse(id); |
---|
| 433 | } else { |
---|
| 434 | Expand(id); |
---|
| 435 | } |
---|
| 436 | } else { |
---|
[672459c] | 437 | // If on a station, centre on it by selecting it twice. |
---|
| 438 | m_Parent->TreeItemSelected(GetItemData(id)); |
---|
| 439 | m_Parent->TreeItemSelected(GetItemData(id)); |
---|
[26fac5a] | 440 | } |
---|
| 441 | } |
---|
| 442 | break; |
---|
| 443 | } |
---|
| 444 | case WXK_LEFT: case WXK_RIGHT: case WXK_UP: case WXK_DOWN: |
---|
| 445 | case WXK_HOME: case WXK_END: case WXK_PAGEUP: case WXK_PAGEDOWN: |
---|
| 446 | e.Skip(); |
---|
| 447 | break; |
---|
| 448 | default: |
---|
| 449 | // Pass key event to MainFrm which will pass to GfxCore which will |
---|
| 450 | // pass to GUIControl. |
---|
| 451 | m_Parent->OnKeyPress(e); |
---|
| 452 | break; |
---|
[5901b62] | 453 | } |
---|
| 454 | } |
---|
[5e0b9f9d] | 455 | |
---|
[5dae1ba] | 456 | void AvenTreeCtrl::OnRestrict(wxCommandEvent&) |
---|
[5e0b9f9d] | 457 | { |
---|
[d5fd4f4] | 458 | m_Parent->RestrictTo(menu_data ? menu_data->GetSurvey() : wxString()); |
---|
[672459c] | 459 | } |
---|
| 460 | |
---|
[5dae1ba] | 461 | void AvenTreeCtrl::OnHide(wxCommandEvent&) |
---|
[672459c] | 462 | { |
---|
| 463 | // Shouldn't be available for the root item. |
---|
| 464 | wxASSERT(menu_data); |
---|
| 465 | // Hide should be disabled unless the item is explicitly shown. |
---|
[44e007d] | 466 | wxASSERT(GetItemState(menu_item) == STATE_ON); |
---|
| 467 | SetItemState(menu_item, STATE_OFF); |
---|
[1a46879] | 468 | filter.remove(menu_data->GetSurvey()); |
---|
[672459c] | 469 | #if 0 |
---|
| 470 | Freeze(); |
---|
| 471 | // Show siblings if not already shown or hidden. |
---|
| 472 | wxTreeItemId i = menu_item; |
---|
| 473 | while ((i = GetPrevSibling(i)).IsOk()) { |
---|
| 474 | if (GetItemState(i) == wxTREE_ITEMSTATE_NONE) |
---|
| 475 | SetItemState(i, 1); |
---|
| 476 | } |
---|
| 477 | i = menu_item; |
---|
| 478 | while ((i = GetNextSibling(i)).IsOk()) { |
---|
| 479 | if (GetItemState(i) == wxTREE_ITEMSTATE_NONE) |
---|
| 480 | SetItemState(i, 1); |
---|
| 481 | } |
---|
| 482 | Thaw(); |
---|
| 483 | #endif |
---|
| 484 | m_Parent->ForceFullRedraw(); |
---|
| 485 | } |
---|
| 486 | |
---|
[5dae1ba] | 487 | void AvenTreeCtrl::OnShow(wxCommandEvent&) |
---|
[672459c] | 488 | { |
---|
| 489 | // Shouldn't be available for the root item. |
---|
| 490 | wxASSERT(menu_data); |
---|
[44e007d] | 491 | auto old_state = GetItemState(menu_item); |
---|
[672459c] | 492 | // Show should be disabled for an explicitly shown item. |
---|
[44e007d] | 493 | wxASSERT(old_state != STATE_ON); |
---|
[672459c] | 494 | Freeze(); |
---|
[44e007d] | 495 | SetItemState(menu_item, STATE_ON); |
---|
[1a46879] | 496 | filter.add(menu_data->GetSurvey()); |
---|
[44e007d] | 497 | if (old_state == wxTREE_ITEMSTATE_NONE) { |
---|
| 498 | // Hide siblings if not already shown or hidden. |
---|
| 499 | wxTreeItemId i = menu_item; |
---|
| 500 | while ((i = GetPrevSibling(i)).IsOk()) { |
---|
| 501 | if (GetItemState(i) == wxTREE_ITEMSTATE_NONE) { |
---|
| 502 | const TreeData* data = static_cast<const TreeData*>(GetItemData(i)); |
---|
| 503 | SetItemState(i, data->IsStation() ? STATE_BLANK : STATE_OFF); |
---|
| 504 | } |
---|
| 505 | } |
---|
| 506 | i = menu_item; |
---|
| 507 | while ((i = GetNextSibling(i)).IsOk()) { |
---|
| 508 | if (GetItemState(i) == wxTREE_ITEMSTATE_NONE) { |
---|
| 509 | const TreeData* data = static_cast<const TreeData*>(GetItemData(i)); |
---|
| 510 | SetItemState(i, data->IsStation() ? STATE_BLANK : STATE_OFF); |
---|
| 511 | } |
---|
| 512 | } |
---|
[672459c] | 513 | } |
---|
| 514 | Thaw(); |
---|
| 515 | m_Parent->ForceFullRedraw(); |
---|
| 516 | } |
---|
| 517 | |
---|
[5dae1ba] | 518 | void AvenTreeCtrl::OnHideSiblings(wxCommandEvent&) |
---|
[672459c] | 519 | { |
---|
| 520 | // Shouldn't be available for the root item. |
---|
| 521 | wxASSERT(menu_data); |
---|
| 522 | Freeze(); |
---|
[44e007d] | 523 | SetItemState(menu_item, STATE_ON); |
---|
[1a46879] | 524 | filter.add(menu_data->GetSurvey()); |
---|
[672459c] | 525 | |
---|
| 526 | wxTreeItemId i = menu_item; |
---|
| 527 | while ((i = GetPrevSibling(i)).IsOk()) { |
---|
| 528 | const TreeData* data = static_cast<const TreeData*>(GetItemData(i)); |
---|
[1a46879] | 529 | filter.remove(data->GetSurvey()); |
---|
[44e007d] | 530 | SetItemState(i, data->IsStation() ? STATE_BLANK : STATE_OFF); |
---|
[672459c] | 531 | } |
---|
| 532 | i = menu_item; |
---|
| 533 | while ((i = GetNextSibling(i)).IsOk()) { |
---|
| 534 | const TreeData* data = static_cast<const TreeData*>(GetItemData(i)); |
---|
[1a46879] | 535 | filter.remove(data->GetSurvey()); |
---|
[44e007d] | 536 | SetItemState(i, data->IsStation() ? STATE_BLANK : STATE_OFF); |
---|
[672459c] | 537 | } |
---|
| 538 | Thaw(); |
---|
| 539 | m_Parent->ForceFullRedraw(); |
---|
| 540 | } |
---|
| 541 | |
---|
| 542 | void AvenTreeCtrl::OnStateClick(wxTreeEvent& e) |
---|
| 543 | { |
---|
| 544 | auto item = e.GetItem(); |
---|
| 545 | const TreeData* data = static_cast<const TreeData*>(GetItemData(item)); |
---|
[44e007d] | 546 | switch (GetItemState(item)) { |
---|
| 547 | case STATE_BLANK: |
---|
| 548 | // Click on blank state icon for a station - let the tree handle |
---|
| 549 | // this in the same way as a click on the label. |
---|
| 550 | return; |
---|
| 551 | case STATE_ON: |
---|
| 552 | filter.remove(data->GetSurvey()); |
---|
| 553 | SetItemState(item, STATE_OFF); |
---|
| 554 | break; |
---|
| 555 | case STATE_OFF: |
---|
| 556 | filter.add(data->GetSurvey()); |
---|
| 557 | SetItemState(item, STATE_ON); |
---|
| 558 | break; |
---|
[672459c] | 559 | } |
---|
[5e0b9f9d] | 560 | e.Skip(); |
---|
[672459c] | 561 | m_Parent->ForceFullRedraw(); |
---|
| 562 | } |
---|