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 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
|
/*
* This file is part of gtkD.
*
* gtkD is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* gtkD 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with gtkD; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
*/
module TestTreeView;
private import gtk.ScrolledWindow;
private import gtk.TreeView;
private import gtk.TreePath;
private import gtk.TreeViewColumn;
private import gtk.TreeIter;
private import gtk.TreeStore;
private import gtk.TreeModel;
//private import ddi.Pixbuf;
private import gtk.TreeSelection;
private import gtk.CellRendererText;
private import gtk.Image;
//private import ddi.Pixbuf;
private import gtk.TreeNode;
private import std.stdio;
/* Don't copy this bad example; inline RGB data is always a better
* idea than inline XPMs.
*/
static string[] book_closed_xpm = [
"16 16 6 1",
" c None s None",
". c black",
"X c red",
"o c yellow",
"O c #808080",
"# c white",
" ",
" .. ",
" ..XX. ",
" ..XXXXX. ",
" ..XXXXXXXX. ",
".ooXXXXXXXXX. ",
"..ooXXXXXXXXX. ",
".X.ooXXXXXXXXX. ",
".XX.ooXXXXXX.. ",
" .XX.ooXXX..#O ",
" .XX.oo..##OO. ",
" .XX..##OO.. ",
" .X.#OO.. ",
" ..O.. ",
" .. ",
" "
];
/**
* This tests the GtkD tree widget
* \todo report bug to ng: nested class with same name of other class was not used<br>
* test if this works:<br>
* class A {}<br>
* class B { <br>
* class A{} <br>
* method (){ new A;}<br>
* }<br>
*/
class TestTreeView : ScrolledWindow
{
Image image;
//Pixbuf pixbuf;
enum columns
{
//gtkDObject = GtkDType.PIXBUF,
gtkDObject = GType.STRING,
gtkObject = GType.STRING,
desc = GType.STRING,
percentDone = GType.STRING,
author = GType.STRING
}
this()
{
super(null,null);
TreeView treeView = setup();
addWithViewport(treeView);
treeView.addOnRowActivated(&rowActivatedCallback);
treeView.addOnMoveCursor(&moveCursorCallBack);
}
void rowActivatedCallback(TreePath path, TreeViewColumn column, TreeView treeView)
{
writefln("rowActivateCallback for %X",treeView);
writefln("rowActivateCallback for path %s",path.toString());
}
bool moveCursorCallBack(GtkMovementStep step, int direction, TreeView treeView)
{
writefln("moveCursorCallBack for %X",treeView);
writefln("moveCursorCallBack row = %d",direction);
return false;
}
TreeIter [12] h;
int stack = 0;
void push(TreeIter ti)
{
h[stack++]=ti;
}
TreeIter peek()
{
if ( stack == 0)
{
return null;
}
return h[stack-1];
}
TreeIter pop()
{
if ( stack == 0)
{
return null;
}
return h[--stack];
}
class HTreeNode : TreeNode
{
string gtkDL;
string gtk;
string desc;
int percent;
string author;
//TestTreeView ttv;
this(string gtkDL,string gtk,string desc,int percent)//, TestTreeView ttv)
{
this.gtkDL = gtkDL;
this.gtk = gtk;
this.desc = desc;
this.percent = percent;
this.author = "Ant";
//this.ttv = ttv;
}
//Pixbuf getNodePixbuf(int colum)
//{
// return pixbuf;
//}
int columnCount()
{
return 5;
}
string getNodeValue(int column)
{
string value;
switch (column)
{
//case 0: value = pixbuf; break;
case 0: value = gtkDL; break;
case 1: value = gtk; break;
case 2: value = desc; break;
case 3:
switch(percent)
{
case -1: value = "uggly: won't get in"; break;
case 0: value = "unknown"; break;
case 1: value = "not yet";break;
case 98: value = "Almost"; break;
case 99: value = "AGAIG"; break;
case 100: value = "Complete"; break;
default:value = "%"; break;
}
break;
case 4: value = author; break;
default: value = "N/A"; break;
}
return value;
}
}
TreeView setup()
{
class TTreeStore : TreeStore
{
this()
{
//this.nCols = nCols;
static GType [5] columns = [
//GtkDType.PIXBUF,
GType.STRING,
GType.STRING,
GType.STRING,
GType.STRING,
GType.STRING];
super(columns);
}
}
TTreeStore testTreeStore = new TTreeStore();
TreeView treeView = new TreeView(testTreeStore);
treeView.setRulesHint(true);
TreeSelection ts = treeView.getSelection();
ts.setMode(SelectionMode.MULTIPLE);
//TreeViewColumn column = new TreeViewColumn("GtkDObject",new CellRendererPixbuf(),"GdkPixbuf", 0);
TreeViewColumn column = new TreeViewColumn("GtkDObject",new CellRendererText(),"text", 0);
treeView.appendColumn(column);
column.setResizable(true);
column.setReorderable(true);
column.setSortColumnId(0);
column.setSortIndicator(true);
//pixbuf = new Pixbuf(book_closed_xpm);
//image = new Image(pixbuf);
//column.setWidget(image);
column = new TreeViewColumn("GtkObject",new CellRendererText(),"text", 1);
treeView.appendColumn(column);
column.setResizable(true);
column.setReorderable(true);
column.setSortColumnId(1);
column.setSortIndicator(true);
column = new TreeViewColumn("Desc",new CellRendererText(),"text", 2);
treeView.appendColumn(column);
column.setResizable(true);
column.setReorderable(true);
column.setSortColumnId(2);
column.setSortIndicator(true);
column = new TreeViewColumn("Complete",new CellRendererText(),"text", 3);
treeView.appendColumn(column);
column.setResizable(true);
column.setReorderable(true);
column.setSortColumnId(3);
column.setSortIndicator(true);
column = new TreeViewColumn("Author",new CellRendererText(),"text", 4);
treeView.appendColumn(column);
column.setResizable(true);
column.setReorderable(true);
column.setSortColumnId(4);
column.setSortIndicator(true);
TreeIter iter;
TreeIter iterTop = testTreeStore.createIter(null);
TreeIter peekIter(bool pushIt)
{
TreeIter iter = testTreeStore.append(peek());
if ( pushIt )
{
push(iter);
}
return iter;
}
TreeIter popIter(bool pushIt)
{
TreeIter iter = testTreeStore.append(pop());
if ( pushIt )
{
push(iter);
}
return iter;
}
push(iterTop);
testTreeStore.set(iterTop, new HTreeNode("ObjectG","GObject","Parent of the main GtkD objects",90));
testTreeStore.set(peekIter(true), new HTreeNode("ObjectGtk","GtkObject","The main gtk object",100));
testTreeStore.set(peekIter(true), new HTreeNode("Misc","GtkMisc","Comon for Most widgets",100));
testTreeStore.set(peekIter(true), new HTreeNode("Label","GtkLabel","Display only widget",100));
testTreeStore.set(popIter(false), new HTreeNode("AccelLabel","GtkAccelLabel","A label with a thing",1));
testTreeStore.set(peekIter(false), new HTreeNode("Arrow","GtkArrow","A standard arrow",100));
testTreeStore.set(popIter(false), new HTreeNode("Image","GtkImage","A image",100));
testTreeStore.set(peekIter(true), new HTreeNode("Container","GtkContainer","Comon for all widgets that can contain other widgets",90));
testTreeStore.set(peekIter(false), new HTreeNode("Bin","GtkBin","Comon for many widgets",90));
testTreeStore.set(peekIter(false), new HTreeNode("Alignment","GtkAlignment","Aligns a widget in a larger area",100));
testTreeStore.set(peekIter(true), new HTreeNode("Frame","GtkFrame","",100));
testTreeStore.set(popIter(false), new HTreeNode("AspectFrame","GtkAspectFrame","",100));
testTreeStore.set(peekIter(true), new HTreeNode("Button","GtkButton","",90));
testTreeStore.set(peekIter(true), new HTreeNode("ToggleButton","GtkToggleButton","",0));
testTreeStore.set(peekIter(false), new HTreeNode("CheckButton","GtkCheckButton","",0));
testTreeStore.set(popIter(false), new HTreeNode("RadioButton","GtkRadioButton","",0));
testTreeStore.set(popIter(false), new HTreeNode("OptionMenu","GtkOptionMenu","",0));
testTreeStore.set(peekIter(true), new HTreeNode("Item","GtkItem","",0));
testTreeStore.set(peekIter(true), new HTreeNode("MenuItem","GtkMenuItem","",0));
testTreeStore.set(peekIter(true), new HTreeNode("CheckMenuItem","GtkCheckMenuItem","",0));
testTreeStore.set(popIter(false), new HTreeNode("RadioMenuItem","GtkRadioMenuItem","",0));
testTreeStore.set(peekIter(false), new HTreeNode("ImageMenuItem","GtkImageMenuItem","",0));
testTreeStore.set(peekIter(false), new HTreeNode("SeparatorMenuItem","GtkSeparatorMenuItem","",0));
testTreeStore.set(popIter(false), new HTreeNode("TearoffMenuItem","GtkTearoffMenuItem","",0));
testTreeStore.set(peekIter(true), new HTreeNode("Window","GtkWindow","",0));
testTreeStore.set(peekIter(true), new HTreeNode("Dialog","GtkDialog","",0));
testTreeStore.set(peekIter(false), new HTreeNode("ColorSelectionDialog","GtkColorSelectionDialog","",0));
testTreeStore.set(peekIter(false), new HTreeNode("FileSelection","GtkFileSelection","",0));
testTreeStore.set(peekIter(false), new HTreeNode("FontSelectionDialog","GtkFontSelectionDialog","",0));
testTreeStore.set(peekIter(false), new HTreeNode("InputDialog","GtkInputDialog","",0));
testTreeStore.set(popIter(false), new HTreeNode("MessageDialog","GtkMessageDialog","",0));
testTreeStore.set(popIter(false), new HTreeNode("Plug","GtkPlug","",0));
testTreeStore.set(peekIter(false), new HTreeNode("EventBox","GtkEventBox","",0));
testTreeStore.set(peekIter(false), new HTreeNode("HandleBox","GtkHandleBox","",0));
testTreeStore.set(peekIter(false), new HTreeNode("ScrolledWindow","GtkScrolledWindow","",0));
testTreeStore.set(popIter(false), new HTreeNode("Viewport","GtkViewport","",0));
testTreeStore.set(peekIter(true), new HTreeNode("Box","GtkBox","",0));
testTreeStore.set(peekIter(true), new HTreeNode("ButtonBox","GtkButtonBox","",0));
testTreeStore.set(peekIter(false), new HTreeNode("HButtonBox","GtkHButtonBox","",0));
testTreeStore.set(popIter(false), new HTreeNode("VButtonBox","GtkVButtonBox","",0));
testTreeStore.set(peekIter(true), new HTreeNode("VBox","GtkVBox","",100));
testTreeStore.set(peekIter(false), new HTreeNode("ColorSelection","GtkColorSelection","",100));
testTreeStore.set(peekIter(false), new HTreeNode("FontSelection","GtkFontSelection","",100));
testTreeStore.set(popIter(false), new HTreeNode("GammaCurve","GtkGammaCurve","",0));
testTreeStore.set(popIter(true), new HTreeNode("HBox","GtkHBox","",100));
testTreeStore.set(peekIter(false), new HTreeNode("Combo","GtkCombo","",0));
testTreeStore.set(popIter(false), new HTreeNode("Statusbar","GtkStatusbar","",0));
testTreeStore.set(peekIter(false), new HTreeNode("Fixed","GtkFixed","",0));
testTreeStore.set(peekIter(true), new HTreeNode("Paned","GtkPaned","",0));
testTreeStore.set(peekIter(false), new HTreeNode("HPaned","GtkHPaned","",0));
testTreeStore.set(popIter(false), new HTreeNode("VPaned","GtkVPaned","",0));
testTreeStore.set(peekIter(false), new HTreeNode("Layout","GtkLayout","",0));
testTreeStore.set(peekIter(true), new HTreeNode("MenuShell","GtkMenuShell","",0));
testTreeStore.set(peekIter(false), new HTreeNode("MenuBar","GtkMenuBar","",0));
testTreeStore.set(popIter(false), new HTreeNode("Menu","GtkMenu","",0));
testTreeStore.set(peekIter(false), new HTreeNode("Notebook","GtkNotebook","",0));
testTreeStore.set(peekIter(false), new HTreeNode("Socket","GtkSocket","",0));
testTreeStore.set(peekIter(false), new HTreeNode("Table","GtkTable","",0));
testTreeStore.set(peekIter(false), new HTreeNode("TextView","GtkTextView","",0));
testTreeStore.set(peekIter(false), new HTreeNode("Toolbar","GtkToolbar","",0));
testTreeStore.set(popIter(false), new HTreeNode("TreeView","GtkTreeView","",0));
testTreeStore.set(peekIter(false), new HTreeNode("Calendar","GtkCalendar","",0));
testTreeStore.set(peekIter(true), new HTreeNode("DrawingArea","GtkDrawingArea","",0));
testTreeStore.set(popIter(false), new HTreeNode("Curve","GtkCurve","",0));
testTreeStore.set(peekIter(true), new HTreeNode("Editable","GtkEditable","",0));
testTreeStore.set(peekIter(true), new HTreeNode("Entry","GtkEntry","",0));
testTreeStore.set(popIter(false), new HTreeNode("SpinButton","GtkSpinButton","",0));
pop();
testTreeStore.set(peekIter(true), new HTreeNode("Ruler","GtkRuler","",0));
testTreeStore.set(peekIter(false), new HTreeNode("HRuler","GtkHRuler","",0));
testTreeStore.set(popIter(false), new HTreeNode("VRuler","GtkVRuler","",0));
testTreeStore.set(peekIter(true), new HTreeNode("Range","GtkRange","",0));
testTreeStore.set(peekIter(true), new HTreeNode("Scale","GtkScale","",0));
testTreeStore.set(peekIter(true), new HTreeNode("HScale","GtkHScale","",0));
testTreeStore.set(popIter(false), new HTreeNode("VScale","GtkVScale","",0));
testTreeStore.set(popIter(true), new HTreeNode("Scrollbar","GtkScrollbar","",0));
testTreeStore.set(peekIter(false), new HTreeNode("HScrollbar","GtkHScrollbar","",0));
testTreeStore.set(popIter(false), new HTreeNode("VScrollbar","GtkVScrollbar","",0));
pop();
testTreeStore.set(peekIter(true), new HTreeNode("Separator","GtkSeparator","",0));
testTreeStore.set(peekIter(false), new HTreeNode("HSeparator","GtkHSeparator","",0));
testTreeStore.set(popIter(false), new HTreeNode("VSeparator","GtkVSeparator","",0));
testTreeStore.set(peekIter(false), new HTreeNode("Invisible","GtkInvisible","",0));
testTreeStore.set(peekIter(false), new HTreeNode("Preview","GtkPreview","",0));
testTreeStore.set(popIter(false), new HTreeNode("ProgressBar","GtkProgressBar","",0));
testTreeStore.set(peekIter(false), new HTreeNode("Adjustment","GtkAdjustment","Values for the range widget (scroolbars, spin buttons...)",0));
testTreeStore.set(peekIter(true), new HTreeNode("CellRenderer","GtkCellRenderer","",0));
testTreeStore.set(peekIter(false), new HTreeNode("CellRendererPixbuf","GtkCellRendererPixbuf","",0));
testTreeStore.set(peekIter(false), new HTreeNode("CellRendererText","GtkCellRendererText","",0));
testTreeStore.set(popIter(false), new HTreeNode("CellRendererToggle","GtkCellRendererToggle","",0));
testTreeStore.set(peekIter(false), new HTreeNode("ItemFactory","GtkItemFactory","",1));
testTreeStore.set(peekIter(false), new HTreeNode("Tooltips","GtkTooltips","",0));
testTreeStore.set(popIter(false), new HTreeNode("TreeViewColumn","GtkTreeViewColumn","",0));
push(iterTop);
testTreeStore.set(peekIter(false), new HTreeNode("ListG","GList","a double linked list used to comboBox and stuf",0));
return treeView;
}
}
|