blob: 5ac203ff644fbe4235cfb42e1bc9bb5e31727c32 (
plain)
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
|
//
// Node Tree code for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2025 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
// https://www.fltk.org/COPYING.php
//
// Please see the following page on how to report bugs and issues:
//
// https://www.fltk.org/bugs.php
//
#include "nodes/Tree.h"
#include "Project.h"
Tree::Iterator::Iterator(Node *t, bool only_selected)
: type_(t)
, only_selected_(only_selected)
{
if (t) {
if (only_selected_) {
if (!type_->selected) {
operator++();
}
}
}
}
Tree::Iterator &Tree::Iterator::operator++() {
if (only_selected_) {
do {
type_ = type_->next;
} while (type_ && !type_->selected);
} else {
type_ = type_->next;
}
return *this;
}
Tree::WIterator::WIterator(Node *t, bool only_selected)
: type_(t)
, only_selected_(only_selected)
{
if (t) {
if (only_selected_) {
if (!type_->selected || !type_->is_widget()) {
operator++();
}
} else {
if (!type_->is_widget()) {
operator++();
}
}
}
}
Tree::WIterator& Tree::WIterator::operator++() {
if (only_selected_) {
do {
type_ = type_->next;
} while (type_ && (!type_->selected || !type_->is_widget()));
} else {
do {
type_ = type_->next;
} while (type_ && !type_->is_widget());
}
return *this;
}
Tree::Tree(Project &proj)
: proj_(proj)
{ (void)proj_; }
/** Find a node by its unique id.
Every node in a type tree has an id that is unique for the current project.
Walk the tree and return the node with this uid.
\param[in] uid any number between 0 and 65535
\return the node with this uid, or 0 if not found
*/
Node *Tree::find_by_uid(unsigned short uid) {
for (Node *tp: all_nodes()) {
if (tp->get_uid() == uid) return tp;
}
return 0;
}
/** Find a node by using the codeview text positions.
\param[in] text_type 0=source file, 1=header, 2=.fl project file
\param[in] crsr cursor position in text
\return the node we found or 0
*/
Node *Tree::find_in_text(int text_type, int crsr) {
for (Node *node: all_nodes()) {
switch (text_type) {
case 0:
if (crsr >= node->code1_start && crsr < node->code1_end) return node;
if (crsr >= node->code2_start && crsr < node->code2_end) return node;
if (crsr >= node->code_static_start && crsr < node->code_static_end) return node;
break;
case 1:
if (crsr >= node->header1_start && crsr < node->header1_end) return node;
if (crsr >= node->header2_start && crsr < node->header2_end) return node;
if (crsr >= node->header_static_start && crsr < node->header_static_end) return node;
break;
case 2:
if (crsr >= node->proj1_start && crsr < node->proj1_end) return node;
if (crsr >= node->proj2_start && crsr < node->proj2_end) return node;
break;
}
}
return 0;
}
|