This file is indexed.

/usr/include/cwidget/widgets/subtree.h is in libcwidget-dev 0.5.17-4+b1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
// subtree.h  (this is -*-c++-*-)
//
//  Copyright 1999-2003, 2005 Daniel Burrows
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; see the file COPYING.  If not, write to
//  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
//  Boston, MA 02111-1307, USA.
//
//  Subtrees for trees.

#ifndef SUBTREE_H
#define SUBTREE_H

#include <list>
#include "treeitem.h"
#include "tree.h"

#include <cwidget/config/keybindings.h>

namespace cwidget
{
  namespace widgets
  {
    template<class childtype, class default_sorter=tag_sort_policy>
    class subtree:virtual public treeitem
    // A tree-item which can contain other tree items.  Still abstract -- the
    // display routines have to be filled in, and you may want to add more behavior
    // on keypresses -- but we're getting there :)
    {
    protected:

      typedef std::list<childtype *> child_list;
      typedef typename std::list<childtype *>::iterator child_iterator;

      class levelref:public tree_levelref
      {
	child_iterator realitem;

	child_list *parent_list;
      public:
	levelref(const levelref &x)
	  :tree_levelref(x), realitem(x.realitem), parent_list(x.parent_list) {}
	levelref(const child_iterator &_realitem, child_list *_parent_list)
	  :realitem(_realitem), parent_list(_parent_list)
	{
	}

	treeitem *get_item() {eassert(realitem!=parent_list->end()); return *realitem;}
	virtual void advance_next() {++realitem;}
	virtual void return_prev() {--realitem;}
	bool is_begin() {return realitem==parent_list->begin();}
	bool is_end() {return realitem==parent_list->end();}
	levelref *clone() const {return new levelref(*this);}
      };

    private:
      bool expanded;

      child_list children;

    protected:
      child_iterator get_children_begin() {return children.begin();}
      child_iterator get_children_end() {return children.end();}

    public:
      typedef treeiterator iterator;
      typedef default_sorter default_sort;

      subtree(bool _expanded):treeitem(),expanded(_expanded) {}

      bool get_expanded() {return expanded;}

      void expand() {expanded=true;}

      void expand_all()
      {
	expanded=true;
	for(child_iterator i=children.begin(); i!=children.end(); i++)
	  (*i)->expand_all();
      }

      void collapse_all()
      {
	expanded=false;
	for(child_iterator i=children.begin(); i!=children.end(); i++)
	  (*i)->collapse_all();
      }

      void paint(tree *win, int y, bool hierarchical,
		 const std::wstring &str, int depth_shift=2)
      {
	int width, height;
	int basex=hierarchical?depth_shift*get_depth():0;
	win->getmaxyx(height,width);

	win->move(y,0);

	int x=0;
	while(x<basex && x<width)
	  {
	    win->add_wch(L' ');
	    x+=wcwidth(L' ');
	  }

	if(basex>width)
	  return;

	const wchar_t *ws;
	if(hierarchical)
	  ws=get_expanded()?L"--\\ ":L"--- ";
	else
	  ws=L"-> ";

	while(*ws!=0 && x<width)
	  {
	    win->add_wch(*ws);
	    x+=wcwidth(*ws);
	    ++ws;
	  }

	if(x>=width)
	  return;

	size_t i=0;
	while(i<str.size() && x<width)
	  {
	    wchar_t ch=str[i];

	    win->add_wch(ch);
	    x+=wcwidth(ch);
	    ++i;
	  }

	while(x<width)
	  {
	    win->add_wch(L' ');
	    x+=wcwidth(L' ');
	  }
      }

      void set_depth(int _depth)
      {
	for(child_iterator i=children.begin(); i!=children.end(); i++)
	  (*i)->set_depth(_depth+1);

	treeitem::set_depth(_depth);
      }

      void add_child(childtype *newchild)
      {
	newchild->set_depth(get_depth()+1);

	children.push_back(newchild);
      }

      // Adds a new child item at an unspecified location -- you should call sort()
      // after adding children or the tree will have an undetermined order.  (yes,
      // you can deduce the real order.  Don't.)
      void sort(sortpolicy &sort_method)
      {
	for(child_iterator i=children.begin(); i!=children.end(); i++)
	  (*i)->sort(sort_method);

	children.sort(sortpolicy_wrapper(sort_method));
      }

      void sort()
      {
	default_sort sorter;
	sort(sorter);
      }

      virtual bool dispatch_key(const config::key &k, tree *owner)
      {
	if(tree::bindings->key_matches(k, "ToggleExpanded"))
	  {
	    expanded=!expanded;
	    return true;
	  }
	else if(tree::bindings->key_matches(k, "ExpandTree"))
	  {
	    if(!expanded)
	      {
		expanded=true;
		return true;
	      }
	    else
	      return false;
	  }
	else if(tree::bindings->key_matches(k, "CollapseTree"))
	  {
	    if(expanded)
	      {
		expanded=false;
		return true;
	      } else
	      return false;
	  }
	else if(tree::bindings->key_matches(k, "ExpandAll"))
	  {
	    expand_all();
	    return true;
	  }
	else if(tree::bindings->key_matches(k, "CollapseAll"))
	  {
	    collapse_all();
	    return true;
	  }
	return false;
      }
      // The default action is to expand or shrink the tree when Enter is pressed.
      // FIXME: should I use '+' and '-' here?  That would appear to conflict with
      // the other keybindings I need.  Hm.

      virtual void dispatch_mouse(short id, int x, mmask_t bstate, tree *owner)
      {
	if(bstate & (BUTTON1_DOUBLE_CLICKED | BUTTON2_DOUBLE_CLICKED |
		     BUTTON3_DOUBLE_CLICKED | BUTTON4_DOUBLE_CLICKED |
		     BUTTON1_TRIPLE_CLICKED | BUTTON2_TRIPLE_CLICKED |
		     BUTTON3_TRIPLE_CLICKED | BUTTON4_TRIPLE_CLICKED))
	  expanded=!expanded;
      }

      virtual levelref *begin() {return new levelref(children.begin(), &children);}
      virtual levelref *end() {return new levelref(children.end(), &children);}

      bool has_visible_children() {return expanded && children.size()>0;}
      bool has_children() {return children.size()>0;}

      virtual ~subtree()
      {
	child_iterator i,j;
	for(i=children.begin(); i!=children.end(); i=j)
	  {
	    j=i;
	    j++;
	    delete *i;
	  }
      }
    };

    class subtree_generic:public subtree<treeitem>
    {
    public:
      subtree_generic(int _expanded):subtree<treeitem>(_expanded) {}
    };
  }
}

#endif