acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
tree_base.h
1// Created by camilo on 2025-03-28 22:20 <3ThomasBorregaardSorensen!!
2#pragma once
3
4
5//#pragma once
6
7
8//#include "acme/parallelization/synchronous_lock.h"
9#include "acme/prototype/data/data.h"
10#include "acme/prototype/data/tree_item_base.h"
11
12
13namespace data
14{
15
16
17 class CLASS_DECL_ACME tree_base :
18 virtual public ::data::data,
19 virtual public ::data::tree_item_base
20 {
21 public:
22
23
24 //pointer_array < tree_base > m_treea;
25 //::pointer<tree_item> m_proot;
26 bool m_bFill;
27 index_array m_iaLevelNext;
28
29
30
31
32 tree_base();
33 ~tree_base() override;
34
35
36 virtual ::pointer<::data::tree_item_base> _create_tree_item() = 0;
37
38 void destroy() override;
39
40 virtual void _insert_tree(tree_base * ptree);
41
42 virtual ::i64 increment_reference_count() override
43 {
44 return ::matter::increment_reference_count();
45 }
46
47 virtual ::i64 decrement_reference_count() override
48 {
49 return ::matter::decrement_reference_count();
50 }
51
52
53 virtual void erase_all();
54
55 virtual void update_tree();
56
57 virtual ::collection::count _tree_count() = 0;
58 virtual tree_base * _tree_at(::collection::index iIndex) = 0;
59
60 virtual void predicate_each_tree(const ::function < void(tree_base *) > & callback);
61
62 virtual tree_item_base * _find(const ::item * pitem, ::collection::index * piIndex = nullptr);
63 virtual bool _contains(const ::item * pitem);
64
65 bool _contains(const tree_item_base * pitem) override;
66
67 virtual void _001OnTreeDataChange();
68
69 virtual void _001OnItemExpand(tree_item_base * pitem, const ::action_context & action_context);
70 virtual void _001OnItemCollapse(tree_item_base * pitem, const ::action_context & action_context);
71 virtual void _001OnOpenItem(tree_item_base * pitem, const ::action_context & action_context);
72 virtual void _001OnItemContextMenu(tree_item_base * pitem, const ::action_context & action_context, ::user::element * ptree, const ::i32_point & point);
73
74 void _erase(::data::tree_item_base_ptr_array & itemptra);
75 void _erase(tree_item_base * pitem);
76 void _erase(::item * pitem, ::collection::index i = 0);
77
78
79 //tree_item_base * __previous() override;
80 //tree_item_base * __next() override;
81 //template < typename PRED >
82 //void sort_children(PRED pred)
83 //{
84
85 // tree_sort(this, pred);
86
87 //}
88 //void sort_children(const ::function < bool(const tree_item_base * p1, const tree_item_base * p2) > & functionLess) override;
89
90 virtual tree_item_base * __get_proper_item(::collection::index iIndex, ::collection::index * piLevel, ::collection::index * piCount = nullptr);
91 virtual tree_item_base * _get_proper_item(::collection::index iIndex, ::collection::index * piLevel) override;
92 virtual ::collection::index _get_proper_item_index(tree_item_base * pitemParam, ::collection::index * piLevel, ::collection::index * piCount = nullptr);
93 // virtual ::collection::count get_proper_item_count() override;
94
95 virtual void _update_levels();
96
97 virtual tree_item_base * _get_base_item();
98
99 virtual const tree_item_base * _get_base_item() const;
100
101 virtual tree_item_base * _insert_item(::item * pitemdataNew, enum_relative erelativeNewItem = e_relative_last_child, tree_item_base * pitemRelative = nullptr, bool bVoidTreeDataChangeEvent = false);
102 virtual bool _insert_item(tree_item_base * pitemNew, enum_relative erelativeNewItem = e_relative_last_child, tree_item_base * pitemRelative = nullptr, bool bVoidTreeDataChangeEvent = false);
103
104 virtual ::image::image_list * get_tree_image_list();
105
106 virtual void _001ExpandItem(tree_item_base * pitem, const ::action_context & action_context, bool bExpand = true, bool bRedraw = true, bool bLayout = true);
107 virtual void _001EnsureVisible(tree_item_base * pitem);
108 virtual void _001SelectItem(tree_item_base * pitem);
109
110 virtual void _get_selection(::data::tree_item_base_ptr_array & itemptraSelected) const;
111 virtual bool _is_selected(const tree_item_base * pitem) const;
112 virtual bool _is_selected(const ::item * pitem) const;
113
114 virtual ::collection::count _selection_set(::data::tree_item_base_ptr_array & itemptra);
115 virtual bool _selection_set(tree_item_base * pitem, bool bIfNotInSelection = false, bool bIfParentInSelection = false);
116 virtual bool _selection_set(::item * pitem, bool bIfNotInSelection = false, bool bIfParentInSelection = false);
117 virtual bool _selection_set(::collection::index iIndex, ::item * pitem, bool bIfNotInSelection = false, bool bIfParentInSelection = false);
118
119
120 //void signal(::signal * psignal) override;
121 void handle(::topic * ptopic, ::handler_context * phandlercontext) override;
122
123
124 virtual void on_fill_children() override;
125 //virtual void start_fill_children();
126
127 virtual void on_tree_layout();
128
129 virtual void fill_children();
130
131
132 //virtual void tree_layout(::draw2d::graphics_pointer & pgraphics);
133
134
135 };
136
137 //template < prototype_item ::item * >
138 //tree < ::item * >::tree()
139 //{
140
141 // //defer_create_synchronization();
142
143 // m_bFill = false;
144
145 // //m_proot = allocateø tree_item();
146
147 // //if (m_proot == nullptr)
148 // //{
149
150 // // throw ::exception(error_no_memory);
151
152 // //}
153
154 // this->m_dwState |= ::data::e_tree_item_state_expandable;
155
156 // this->m_dwState |= ::data::e_tree_item_state_expanded;
157
158 // this->m_ptree = this;
159
160 // this->m_pparent = allocateø tree_item();
161
162 //}
163
164 //template < prototype_item ::item * >
165 //tree < ::item * >::~tree()
166 //{
167
168 //}
169
170 //template < prototype_item ::item * >
171 //tree_item_base * tree < ::item * >::find(const ::item * * pitem, ::collection::index * piIndex)
172 //{
173
174 // ::collection::index iIndex;
175
176 // if (pitem == nullptr)
177 // {
178
179 // return nullptr;
180
181 // }
182
183 // if (piIndex == nullptr)
184 // {
185
186 // iIndex = 0;
187
188 // }
189 // else
190 // {
191
192 // iIndex = *piIndex;
193
194 // }
195
196 // ::pointer<::data::tree_item>pitem = this;
197
198 // for (; pitem != nullptr; pitem = pitem->get_item(e_tree_navigation_expanded_forward))
199 // {
200
201 // if (pitem->m_pdataitem == pitem)
202 // {
203
204 // iIndex--;
205
206 // if (iIndex < 0)
207 // {
208
209 // return pitem;
210
211 // }
212
213 // }
214
215 // }
216
217 // if (piIndex != nullptr)
218 // {
219
220 // *piIndex = iIndex;
221
222 // }
223
224 // return nullptr;
225
226 //}
227
228 //template < prototype_item ::item * >
229 //bool tree < ::item * >::contains(const ::item * * pitem)
230 //{
231
232 // return find(pitem) != nullptr;
233
234 //}
235 //template < prototype_item ::item * >
236 //bool tree < ::item * >::contains(const tree_item_base * pitemParam)
237 //{
238
239 // return tree_item::contains(pitemParam);
240
241 // //if (pitemParam == this)
242 // //{
243
244 // // return true;
245
246 // //}
247 // //
248 // //::data::tree_item_base * pitem = this;
249
250 // //for(; pitem != nullptr; pitem = pitem->get_item(e_tree_navigation_expanded_forward))
251 // //{
252
253 // // if (pitem == pitemParam)
254 // // {
255
256 // // return true;
257
258 // // }
259
260 // //}
261
262 // //return false;
263
264 //}
265
266 //template < prototype_item ::item * >
267 //void tree < ::item * >::_001OnTreeDataChange()
268 //{
269
270 // update_levels();
271
272 //}
273
274 //template < prototype_item ::item * >
275 //void tree < ::item * >::erase(::item * * pitem, ::collection::index i)
276 //{
277
278 // tree_item_base * pitem = find(pitem, &i);
279
280 // if (pitem == nullptr)
281 // {
282
283 // return;
284
285 // }
286
287 // return erase(pitem);
288
289 //}
290
291 //template < prototype_item ::item * >
292 //void tree < ::item * >::erase(tree_item_ptr_array<::item *> & itemptra)
293 //{
294
295 // for (::i32 i = 0; i < itemptra.get_count(); i++)
296 // {
297
298 // erase(itemptra[i]);
299
300 // }
301
302 //}
303
304 //template < prototype_item ::item * >
305 //void tree < ::item * >::erase(tree_item_base * pitem)
306 //{
307
308 // if (pitem->m_ptree == this)
309 // {
310
311 // pitem->erase_tree_item();
312
313 // }
314
315 //}
316
317 //template < prototype_item ::item * >
318 //void tree < ::item * >::sort_children(const ::function < bool(const ::data::tree_item_base * p1, const ::data::tree_item_base * p2) > & functionLess)
319 //{
320
321 // this->m_treeitema2.predicate_sort(functionLess);
322
323 // this->m_treeitema2.predicate_each([](auto pitem) {pitem->clear_cache(); });
324
325 //}
326
327 //template < prototype_item ::item * >
328 //::data::tree_item_base * tree < ::item * >::_get_proper_item(::collection::index iIndex, ::collection::index * piLevel, ::collection::index * piCount)
329 //{
330
331 // ::collection::index iCount = 0;
332
333 // if (piLevel)
334 // {
335
336 // *piLevel = 0;
337
338 // }
339
340 // ::pointer<::data::tree_item>pitem = this;
341
342 // while (pitem && iIndex >= 0)
343 // {
344
345 // pitem = pitem->get_proper_next(piLevel);
346
347 // iIndex--;
348
349 // }
350
351 // if (iIndex < 0 && pitem)
352 // {
353
354 // return pitem;
355
356 // }
357
358 // if (piCount != nullptr)
359 // {
360
361 // *piCount = iCount;
362
363 // }
364
365 // return nullptr;
366
367 //}
368
369 //template < prototype_item ::item * >
370 //::data::tree_item_base * tree < ::item * >::get_proper_item(::collection::index iIndex, ::collection::index * piLevel)
371 //{
372
373 // if (piLevel)
374 // {
375
376 // *piLevel = 0;
377
378 // }
379
380 // ::pointer<::data::tree_item>pitem = this;
381
382 // while (pitem && iIndex >= 0)
383 // {
384
385 // pitem = pitem->get_proper_next(piLevel);
386
387 // iIndex--;
388
389 // }
390
391 // if (iIndex < 0 && pitem)
392 // {
393
394 // return pitem;
395
396 // }
397
398 // return nullptr;
399
400 //}
401
402 //template < prototype_item ::item * >
403 //::collection::index tree < ::item * >::get_proper_item_index(::data::tree_item_base * pitemParam, ::collection::index * piLevel, ::collection::index * piCount)
404 //{
405
406 // ::i32 iIndex = 0;
407
408 // ::collection::count iCount = 0;
409
410 // if (piLevel != nullptr)
411 // {
412
413 // *piLevel = 0;
414
415 // }
416
417 // ::pointer<::data::tree_item>pitem = get_base_item();
418
419 // while (pitem != nullptr)
420 // {
421
422 // pitem = pitem->get_proper_next(piLevel);
423
424 // if (pitem == pitemParam)
425 // {
426
427 // if (piCount != nullptr)
428 // {
429
430 // *piCount += iCount;
431
432 // }
433
434 // return iIndex;
435
436 // }
437
438 // iIndex++;
439
440 // iCount++;
441
442 // }
443
444 // if (piCount != nullptr)
445 // {
446
447 // *piCount += iCount;
448
449 // }
450
451 // return -1;
452
453 //}
454
455
458
460
462
464
465 //template < prototype_item ::item * >
466 //::data::tree_item_base * tree < ::item * >::get_base_item()
467 //{
468
469 // return this;
470
471 //}
472
473 //template < prototype_item ::item * >
474 //const ::data::tree_item_base * tree < ::item * >::get_base_item() const
475 //{
476
477 // return this;
478
479 //}
480 //template < prototype_item ::item * >
481
482 //::data::tree_item_base * tree < ::item * >::_____previous()
483 //{
484
485 // return nullptr;
486
487 //}
488
489 //template < prototype_item ::item * >
490 //::data::tree_item_base * tree < ::item * >::_____next()
491 //{
492
493 // return nullptr;
494
495 //}
496
497 //template < prototype_item ::item * >
498 //::data::tree_item_base * tree < ::item * >::insert_item(::item * * pitemdataNew, enum_relative erelativeNewItem, ::data::tree_item_base * pitemRelative, bool bVoidTreeDataChangeEvent)
499 //{
500
501 // if (pitemRelative == nullptr)
502 // {
503
504 // pitemRelative = this;
505
506 // }
507
508 // if (erelativeNewItem == e_relative_replace)
509 // {
510
511 // if (!contains(pitemRelative))
512 // return nullptr;
513
514 // pitemRelative->m_pdataitem = pitemdataNew;
515
516 // return pitemRelative;
517
518 // }
519
520 // ::pointer<::data::tree_item>pitemNew = allocateø tree_item();
521
522 // if (pitemNew == nullptr)
523 // return nullptr;
524
525 // if (!insert_item(pitemNew, erelativeNewItem, pitemRelative, bVoidTreeDataChangeEvent))
526 // {
527
528 // return nullptr;
529
530 // }
531
532 // pitemNew->m_pdataitem = pitemdataNew;
533
534 // return pitemNew;
535
536 //}
537 //template < prototype_item ::item * >
538 //void tree < ::item * >::destroy()
539 //{
540
541 // ::data::data::destroy();
542 // ::data::tree_item::destroy();
543
544 //}
545 //template < prototype_item ::item * >
546 //void tree < ::item * >::on_insert_tree(tree * ptree)
547 //{
548
549 // m_treea.add(ptree);
550
551 //}
552
553 //template < prototype_item ::item * >
554 //bool tree < ::item * >::insert_item(::data::tree_item_base * pitemNew, enum_relative erelativeNewItem, ::data::tree_item_base * pitemRelative, bool bVoidTreeDataChangeEvent)
555 //{
556
557 // ::pointer<tree>ptreeNew = pitemNew;
558
559 // if (ptreeNew)
560 // {
561
562 // on_insert_tree(ptreeNew);
563
564 // }
565
566 // if (pitemRelative == nullptr)
567 // {
568
569 // pitemRelative = this;
570
571 // }
572
573 // _synchronous_lock synchronouslock(this->synchronization(), DEFAULT_SYNCHRONOUS_LOCK_SUFFIX);
574
575 // if (pitemNew == nullptr)
576 // {
577
578 // return false;
579
580 // }
581
582 // if (!contains(pitemRelative))
583 // {
584
585 // return false;
586
587 // }
588
589 // if (erelativeNewItem == e_relative_parent)
590 // {
591
592 // return false;
593
594 // }
595
596 // if (erelativeNewItem == e_relative_last_sibling)
597 // {
598
599 // if (pitemRelative == this)
600 // {
601
602 // erelativeNewItem = e_relative_first_child;
603
604 // }
605
606 // }
607
608 // bool bOk = false;
609
610 // switch (erelativeNewItem)
611 // {
612 // case e_relative_first_child:
613 // {
614
615 // bOk = pitemRelative->insert(erelativeNewItem, pitemNew);
616
617 // }
618 // break;
619 // case e_relative_last_child:
620 // {
621
622 // bOk = pitemRelative->insert(erelativeNewItem, pitemNew);
623
624 // }
625 // break;
626 // case e_relative_previous_sibling:
627 // {
628
629 // bOk = pitemRelative->insert(erelativeNewItem, pitemNew);
630
631 // }
632 // break;
633 // case e_relative_next_sibling:
634 // {
635
636 // bOk = pitemRelative->insert(erelativeNewItem, pitemNew);
637
638 // }
639 // break;
640 // case e_relative_last_sibling:
641 // {
642
643 // bOk = pitemRelative->insert(erelativeNewItem, pitemNew);
644
645 // }
646 // break;
647 // case e_relative_replace:
648 // {
649
650 // pitemNew->m_dwUser = pitemRelative->m_dwUser;
651 // pitemNew->m_dwMetaData = pitemRelative->m_dwMetaData;
652 // pitemNew->m_dwState = pitemRelative->m_dwState;
653 // pitemNew->m_pdataitem = pitemRelative->m_pdataitem;
654
655 // pitemNew->m_iLevel = pitemRelative->m_iLevel;
656
657 // bOk = pitemRelative->insert(erelativeNewItem, pitemNew);
658
659 // }
660 // break;
661
662 // case e_relative_macro_record:
663 // {
664
665 // if (pitemRelative->get_next() != nullptr)
666 // {
667
668 // bOk = insert_item(pitemNew, ::data::e_relative_first_child, pitemRelative);
669
670 // }
671 // else
672 // {
673
674 // bOk = insert_item(pitemNew, ::data::e_relative_last_sibling, pitemRelative);
675
676 // }
677
678 // }
679 // break;
680 // default:
681
682 // throw ::exception(error_not_supported);
683
684 // }
685
686 // pitemNew->m_ptree = this;
687
688 // if (!bVoidTreeDataChangeEvent)
689 // {
690
691 // _001OnTreeDataChange();
692
693 // }
694
695 // return bOk;
696
697 //}
698
699 //template < prototype_item ::item * >
700 //void tree < ::item * >::erase_all()
701 //{
702
703 // this->erase_tree_item_descendants();
704
705 //}
706
707 //template < prototype_item ::item * >
708 //void tree < ::item * >::update_tree()
709 //{
710
711 // _001OnTreeDataChange();
712
713 //}
714
715
717
719
721
724
726
727
729
731
733 //template < prototype_item ::item * >
734 //void tree < ::item * >::update_levels()
735 //{
736
737 // ::collection::index iLevel = -1;
738
739 // ::pointer<tree_item>pitem = get_base_item();
740
741 // while (pitem != nullptr)
742 // {
743
744 // pitem->m_iLevel = iLevel;
745
746 // pitem = pitem->get_child_next_or_parent(&iLevel);
747
748 // }
749
750 //}
751
752 //template < prototype_item ::item * >
753 //void tree < ::item * >::_001ExpandItem(::data::tree_item_base * pitem, const ::action_context & context, bool bExpand, bool bRedraw, bool bLayout)
754 //{
755
756
757 //}
758 //template < prototype_item ::item * >
759 //void tree < ::item * >::_001EnsureVisible(::data::tree_item_base * pitem)
760 //{
761
762
763 //}
764
765 //template < prototype_item ::item * >
766 //void tree < ::item * >::_001SelectItem(::data::tree_item_base * pitem)
767 //{
768
769
770 //}
771 //template < prototype_item ::item * >
772 //void tree < ::item * >::get_selection(::data::tree_item_ptr_array<::item *> & itemptraSelected) const
773 //{
774
775
776 //}
777 //template < prototype_item ::item * >
778
779 //bool tree < ::item * >::is_selected(const ::data::tree_item_base * pitem) const
780 //{
781
782
783 // return false;
784
785 //}
786
787 //template < prototype_item ::item * >
788 //bool tree < ::item * >::is_selected(const ::item * * pitem) const
789 //{
790
791
792 // return false;
793
794 //}
795
796 //template < prototype_item ::item * >
797 //void tree < ::item * >::_001OnItemExpand(::data::tree_item_base * pitem, const ::action_context & context)
798 //{
799
800 // if (pitem->is_expanded())
801 // return;
802
803 // pitem->on_fill_children();
804
805 // if (pitem->get_children_count() > 0)
806 // {
807 // pitem->m_dwState |= ::data::e_tree_item_state_expanded;
808 // pitem->m_dwState |= ::data::e_tree_item_state_expandable;
809 // }
810
811 // /* for (::collection::index i = 0; i < m_treeptra.get_count(); i++)
812 // {
813
814 // m_treeptra[i]._001OnItemExpand(pitem, context);
815
816 // }*/
817
818
819
820
821 //}
822
823 //template < prototype_item ::item * >
824 //void tree < ::item * >::_001OnItemCollapse(::data::tree_item_base * pitem, const ::action_context & context)
825 //{
826
827 // if (!pitem->is_expanded())
828 // return;
829 // if (pitem->get_children_count() > 0)
830 // {
831 // pitem->m_dwState |= ::data::e_tree_item_state_expandable;
832 // }
833 // pitem->m_dwState &= ~::data::e_tree_item_state_expanded;
834 // /*for (::collection::index i = 0; i < m_treeptra.get_count(); i++)
835 // {
836
837 // m_treeptra[i]._001OnItemCollapse(pitem);
838
839 // }*/
840
841 //}
842
843 //template < prototype_item ::item * >
844 //void tree < ::item * >::_001OnOpenItem(::data::tree_item_base * pitem, const ::action_context & context)
845 //{
846
847
848 //}
849
850 //template < prototype_item ::item * >
851 //void tree < ::item * >::_001OnItemContextMenu(::data::tree_item_base * pitem, const ::action_context & context, ::user::element * ptree, const ::i32_point & point)
852 //{
853
854
855 //}
856
857 //template < prototype_item ::item * >
858 //::collection::count tree < ::item * >::selection_set(::data::tree_item_ptr_array<::item *> & itemptra)
859 //{
860
861 // return 0;
862
863 //}
864
865 //template < prototype_item ::item * >
866 //bool tree < ::item * >::selection_set(::data::tree_item_base * pitem, bool bIfNotInSelection, bool bIfParentInSelection)
867 //{
868
869 // return false;
870
871 //}
872
873 //template < prototype_item ::item * >
874 //bool tree < ::item * >::selection_set(::item * * pitem, bool bIfNotInSelection, bool bIfParentInSelection)
875 //{
876
877 // return false;
878
879 //}
880
881 //template < prototype_item ::item * >
882 //bool tree < ::item * >::selection_set(::collection::index iIndex, ::item * * pitem, bool bIfNotInSelection, bool bIfParentInSelection)
883 //{
884
885 // return false;
886
887 //}
888
889 //template < prototype_item ::item * >
890 //::image::image_list * tree < ::item * >::get_image_list() const
891 //{
892
893 // return nullptr;
894
895 //}
896
897
900
902
903 //template < prototype_item ::item * >
904 //void tree < ::item * >::handle(::topic * ptopic, ::handler_context * phandlercontext)
905 //{
906
907 // for (auto & ptree : m_treea)
908 // {
909
910 // ptree->handle(ptopic, phandlercontext);
911
912 // }
913
914 //}
915
916
917
920
922
923
924 //template < prototype_item ::item * >
925 //void tree < ::item * >::on_fill_children()
926 //{
927
928 //}
929
930
933
935
937
940
942
944
946
947 //template < prototype_item ::item * >
948 //void tree < ::item * >::on_tree_layout()
949 //{
950
951 //}
952
953 //template < prototype_item ::item * >
954 //void tree < ::item * >::fill_children()
955 //{
956
957 // try
958 // {
959
960 // on_fill_children();
961
962 // }
963 // catch (...)
964 // {
965
966 // }
967
968
969 // try
970 // {
971
972 // //auto pgraphics = ::draw2d::create_memory_graphics();
973
974 // //tree_layout(pgraphics);
975
976 // on_tree_layout();
977
978 // }
979 // catch (...)
980 // {
981
982 // }
983
984 // m_bFill = false;
985
986 //}
987
988
991
993
994
995
996} // namespace data
997
998//
999//
1000//inline stream & operator <<(stream & s, const ::data::tree & tree);
1001//
1002//inline stream & operator >>(stream & s, ::data::tree & tree);
1003//
1004//
1005
Definition action_context.h:9
Definition tree_item_base.h:1408
Definition tree_item_base.h:18
Definition item.h:93
Definition topic.h:17