Unnamed Fossil Project

Check-in [9640fda380]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:new code for treeview insert
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:9640fda380ba2f9bd89e38e109bcc884f040c8b9
User & Date: arnulf 2013-09-17 19:42:45
Context
2013-09-18
19:40
fixes and new code for treeview insert check-in: 422deb7b94 user: arnulf tags: trunk
2013-09-17
19:42
new code for treeview insert check-in: 9640fda380 user: arnulf tags: trunk
2013-09-15
19:37
new code and fixes for treeview check-in: 36c7c055cc user: arnulf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to library/ntkTTreeview.tcl.

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
...
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
...
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
....
1118
1119
1120
1121
1122
1123
1124
1125












































































































































1126
1127
1128
1129
1130
1131




























































1132
1133
1134
1135
1136
1137
1138
....
1214
1215
1216
1217
1218
1219
1220
1221









1222
    public method TreeviewDetachCommand {args} 
    public method TreeviewDragCommand {args} 
    public method TreeviewExistsCommand {args} 
    public method TreeviewFocusCommand {args} 
    public method TreeviewHeadingCommand {args} 
    public method TreeviewIdentifyCommand {args} 
    public method TreeviewIndexCommand {args} 




    public method TreeviewInsertCommand {args} 
    public method TreeviewItemCommand {args} 
    public method TreeviewMoveCommand {args} 
    public method TreeviewNextCommand {args} 
    public method TreeviewParentCommand {args} 
    public method TreeviewPrevCommand {args} 
    public method TreeviewSeeCommand {args} 
    public method TreeviewSelectionCommand {args} 
    public method TreeviewSetCommand {args} 
    public method TreeviewTagCommand {args}
    public method TreeviewXViewCommand {args}
    public method TreeviewYViewCommand {args}


}

#================================ constructor ============================
#     
#=========================================================================

::itcl::body treeview::constructor {args} {
................................................................................
    set columns [cget -columns]
    if {$columns eq ""} {
        set nCols 0
    } else {
        set nCols [llength $columns]
    }
    if {$nCols > 0} {
        foreach columName $columns {
            dict lappend tree columnNames $columnName
            InitColumn column
            dict set column idObj $columnName
            dict lappend columns $column
#            Tk_InitOptions((tv->tree.columns + i), tv->tree.columnOptionTable, tv->core.tkwin);
#            Tk_InitOptions((tv->tree.columns + i), tv->tree.headingOptionTable, tv->core.tkwin);
        }
    }
    return 0
}

................................................................................

::itcl::body treeview::TreeviewConfigure {recordPtr mask} {
#puts stderr "TreeviewConfigure!$mask!"

    set showFlags [dict get $tree showFlags]
    if {[lsearch $mask columnsChanged] >= 0 || [lsearch $mask allChanged] >= 0} {
        if {[TreeviewInitColumns] != 0} {
            return -code error "Error in TreeviewInitColumns"
        }
        lappend mask dcolumnsChanged
    }
    if {[lsearch $mask dcolumnsChanged] >= 0 || [lsearch $mask allChanged] >= 0} {
        if {[TreeviewInitDisplayColumns] != 0} {
            return -code error "Error in TreeviewInitDisplayColumns"
        }
    }
    if {[lsearch $mask scrollcmdChanged] >= 0 || [lsearch $mask allChanged] >= 0} {
        ScrollbarUpdateRequired [dict get $tree xscrollHandle]
        ScrollbarUpdateRequired [dict get $tree yscrollHandle]
    }
    if {[lsearch $mask showChanged] >= 0 || [lsearch $mask allChanged] >= 0} {
................................................................................
#================================ TreeviewIndexCommand ============================
#     
#=========================================================================

::itcl::body treeview::TreeviewIndexCommand {args} {
puts stderr "TreeviewIndexCommand!$args!"
}













































































































































#================================ TreeviewInsertCommand ============================
#     
#=========================================================================

::itcl::body treeview::TreeviewInsertCommand {args} {
puts stderr "TreeviewInsertCommand!$args!"




























































}

#================================ TreeviewItemCommand ============================
#     
#=========================================================================

::itcl::body treeview::TreeviewItemCommand {args} {
................................................................................
#================================ TreeviewYViewCommand ============================
#     
#=========================================================================

::itcl::body treeview::TreeviewYViewCommand {args} {
puts stderr "TreeviewYViewCommand!$args!"
}










} ; # end namespace ::ntk::classes







>
>
>
>












>
>







 







|



|







 







|





|







 








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 








>
>
>
>
>
>
>
>
>

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
...
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
...
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
....
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
....
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
    public method TreeviewDetachCommand {args} 
    public method TreeviewDragCommand {args} 
    public method TreeviewExistsCommand {args} 
    public method TreeviewFocusCommand {args} 
    public method TreeviewHeadingCommand {args} 
    public method TreeviewIdentifyCommand {args} 
    public method TreeviewIndexCommand {args} 
    private method ConfigureItem {item args}
    private method InsertPosition {parent index}
    private method EndPosition {parent}
    private method FindItem {itemName}
    public method TreeviewInsertCommand {args} 
    public method TreeviewItemCommand {args} 
    public method TreeviewMoveCommand {args} 
    public method TreeviewNextCommand {args} 
    public method TreeviewParentCommand {args} 
    public method TreeviewPrevCommand {args} 
    public method TreeviewSeeCommand {args} 
    public method TreeviewSelectionCommand {args} 
    public method TreeviewSetCommand {args} 
    public method TreeviewTagCommand {args}
    public method TreeviewXViewCommand {args}
    public method TreeviewYViewCommand {args}

    public method insert {args}
}

#================================ constructor ============================
#     
#=========================================================================

::itcl::body treeview::constructor {args} {
................................................................................
    set columns [cget -columns]
    if {$columns eq ""} {
        set nCols 0
    } else {
        set nCols [llength $columns]
    }
    if {$nCols > 0} {
        foreach columnName $columns {
            dict lappend tree columnNames $columnName
            InitColumn column
            dict set column idObj $columnName
            dict lappend tree columns $column
#            Tk_InitOptions((tv->tree.columns + i), tv->tree.columnOptionTable, tv->core.tkwin);
#            Tk_InitOptions((tv->tree.columns + i), tv->tree.headingOptionTable, tv->core.tkwin);
        }
    }
    return 0
}

................................................................................

::itcl::body treeview::TreeviewConfigure {recordPtr mask} {
#puts stderr "TreeviewConfigure!$mask!"

    set showFlags [dict get $tree showFlags]
    if {[lsearch $mask columnsChanged] >= 0 || [lsearch $mask allChanged] >= 0} {
        if {[TreeviewInitColumns] != 0} {
            return -code error "Error in TreeviewConfigure"
        }
        lappend mask dcolumnsChanged
    }
    if {[lsearch $mask dcolumnsChanged] >= 0 || [lsearch $mask allChanged] >= 0} {
        if {[TreeviewInitDisplayColumns] != 0} {
            return -code error "Error in TreeviewConfigure"
        }
    }
    if {[lsearch $mask scrollcmdChanged] >= 0 || [lsearch $mask allChanged] >= 0} {
        ScrollbarUpdateRequired [dict get $tree xscrollHandle]
        ScrollbarUpdateRequired [dict get $tree yscrollHandle]
    }
    if {[lsearch $mask showChanged] >= 0 || [lsearch $mask allChanged] >= 0} {
................................................................................
#================================ TreeviewIndexCommand ============================
#     
#=========================================================================

::itcl::body treeview::TreeviewIndexCommand {args} {
puts stderr "TreeviewIndexCommand!$args!"
}

#================================ ConfigureItem ============================
# ConfigureItem --
#     Set item options.
#=========================================================================

::itcl::body treeview::ConfigureItem {item args} {
puts stderr "ConfigureItem!$args!"
    set newImageSpec ""
    set newTagSet ""

    SetOptions $item $args savedOptions mask]

    # Make sure that -values is a valid list:
 
    if {[dict get $item valuesObj] ne ""} {
#        if (Tcl_ListObjLength(interp, item->valuesObj, &unused) != TCL_OK)
#            goto error;
    }

    # Check -image.
    if {[lsearch $mask itemOptionImageChanged] >= 0 && [dict get $item imageObj] ne ""} {
        set newImageSpec [GetImageSpec [dict get $core tkwin] [dict get $item imageObj]]
        if {$newImageSpec eq ""} {
            return -code error "need newImageSpec"
        }
    }

    # Check -tags.
    # Side effect: may create new tags.
 
    if {[lsearch $mask itemOptionTagsChanged] >= 0} {
        set newTagSet [GetTagSetFromObj [dict get $item tagsObj]]
        if {$newTagSet eq ""} {
            return -code error "need newTagSet"
        }
    }

    # Keep TTK_STATE_OPEN flag in sync with item->openObj.
    # We use both a state flag and a Tcl_Obj* resource so elements
    # can access the value in either way.
 
    if {[dict get $item openObj] ne ""} {
        if {[dict get $item openObj]} {
            dict lappend item state stateOpen
        } else {
            set idx [lsearch [dict get $item state] stateOpen]
            if {$idx >= 0} {
                set lst [lreplace [dict get $item state] $idx $idx]
                dict set item state $lst]
            }
        }
    }

    # All OK.
 
#    Tk_FreeSavedOptions(&savedOptions);
    if {[lsearch $mask itemOptionTagsChanged] >= 0} {
        dict set item tagset $newTagSet
    }
    if {[lsearch $mask itemOptionImageChanged] >= 0} {
        dict set item imagespec $newImageSpec
    }
    RedisplayWidget

#error:
#    Tk_RestoreSavedOptions(&savedOptions)
#    if (newTagSet) { Ttk_FreeTagSet(newTagSet); }
#    if (newImageSpec) { TtkFreeImageSpec(newImageSpec); }
#    return TCL_ERROR;
}

#================================ InsertPosition ============================
# InsertPosition --
#     Locate the previous sibling for [$tree insert].
#
#     Returns a pointer to the item just before the specified index,
#     or 0 if the item is to be inserted at the beginning.
#=========================================================================

::itcl::body treeview::InsertPosition {parent index} {
puts stderr "InsertPosition!$parent!$index!"
    set prev ""
    set next [dict get $parent children]

    while {$next ne "" && $index > 0} {
        incr index -1
        set prev $next
        set next [dict get $prev next]
    }

    return $prev
}

#================================ EndPosition ============================
# EndPosition --
#     Locate the last child of the specified node.
#
#     To avoid quadratic-time behavior in the common cases
#     where the treeview is populated in breadth-first or
#     depth-first order using [$tv insert $parent end ...],
#     we cache the result from the last call to EndPosition()
#     and start the search from there on a cache hit.
#=========================================================================

::itcl::body treeview::EndPosition {parent} {
puts stderr "EndPosition!$parent!"
    set endPtr [dict get $tree endPtr]

    while {$endPtr ne "" && [dict get $endPtr parent] ne $parent} {
        set endPtr [dict get $endPtr parent]
    }
    if {$endPtr eq ""} {
        set endPtr [dict get $parent children]
    }

    if {$endPtr ne ""} {
        while {[dict get $endPtr next]} {
            set endPtr [dict get $endPtr next]
        }
        dict set tree endPtr $endPtr
    }

    return $endPtr
}

#================================ FindItem ============================
#     
#=========================================================================

::itcl::body treeview::FindItem {itemName} {
puts stderr "FindItem!$itemName!"
    if {$itemName eq ""} {
        return $itemName
    }
    if {![dict exists $tree items itemName]} {
        return -code error "Item $itemName not found"
    }
    return $itemName
}

#================================ TreeviewInsertCommand ============================
#     
#=========================================================================

::itcl::body treeview::TreeviewInsertCommand {args} {
puts stderr "TreeviewInsertCommand!$args!"
    # Get parent node:

    set parent [FindItem [lindex $args 0]]
#    if {$parent eq ""} {
#        return -code error "error in FindItem"
#    }

    # Locate previous sibling based on $index:

    if {[lindex $args 1] eq "end"} {
        set sibling [EndPosition $parent]
    } else {
        set index [lindex $args 2]
        if {![string is integer $index]} {
            return -code error "index is not integer"
        }
        set sibling [InsertPosition $parent $index]
    }

puts stderr "sibling!$sibling!"
    # Get node name:
    #     If -id supplied and does not already exist, use that;
    #     Otherwise autogenerate new one.
    set args [lrange $args 3 end]
    if {[llength $args] == 2 && [lindex $args 0] eq "-id"} {
        set itemName [lindex $args 1]

        if {[dict exists $tree items $itemName]} {
            return -code error "Item $itemName already exists"
        }
        dict set tree items $itemName [dict create]
        set args [lrange $args 2 end]
    } else {
        while {1} {
            dict set tree serial [expr {[dict get $tree serial] + 1}]
            set idbuf [format "I%03X" [dict get $tree serial]
            if {![dict exists $tree items $idbuf]} {
                dict set tree items $idbuf [dict create]
                set itemName $idbuf
                break
            }
        }
    }
puts stderr "itemName!$itemName!"

    # Create and configure new item:
 
    set newItem [NewItem]
#    Tk_InitOptions(newItem, tv->tree.itemOptionTable, tv->core.tkwin);
    dict set newItem tagset [GetTagSetFromObj [dict get $tv tagTable]]
    ConfigureItem $newItem $args

    # Store in hash table, link into tree:
 
    dict set tree items $itemName $newItem
    dict set newItem entryPtr itemName
    InsertItem $parent $sibling $newItem
    RedisplayWidget

    return [ItemID $newItem]
}

#================================ TreeviewItemCommand ============================
#     
#=========================================================================

::itcl::body treeview::TreeviewItemCommand {args} {
................................................................................
#================================ TreeviewYViewCommand ============================
#     
#=========================================================================

::itcl::body treeview::TreeviewYViewCommand {args} {
puts stderr "TreeviewYViewCommand!$args!"
}

#================================ insert ============================
#     
#=========================================================================

::itcl::body treeview::insert {args} {
puts stderr "insert!$args!"
    TreeviewInsertCommand {*}$args
}

} ; # end namespace ::ntk::classes

Changes to nt1.tcl.

60
61
62
63
64
65
66
67



68
69
70
71
72
73
74
#set ::l3 [::ntk::label .l3 -text world]
#$::tpw1 add .l2
#$::tpw1 add .l3
#$::tpw1 UpdateLayout
#$::tpw1 SizeChanged "" width height
#::ntk::classes::place::place $::tpw1 30 0

set ::ttv1 [::ntk::treeview .ttv1]



::ntk::classes::place::place $::ttv1 30 0

set ch [read stdin 1]
#$::te1 insert insert "abc"
#$::tcb1 insert insert "abc"
#set ch [read stdin 1]
#$::te1 insert insert "def"







|
>
>
>







60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#set ::l3 [::ntk::label .l3 -text world]
#$::tpw1 add .l2
#$::tpw1 add .l3
#$::tpw1 UpdateLayout
#$::tpw1 SizeChanged "" width height
#::ntk::classes::place::place $::tpw1 30 0

set ::ttv1 [::ntk::treeview .ttv1 -columns [list a b c]]
$::ttv1 insert {} end -id newnode -text "New node"
$::ttv1 insert newnode 0 -id newnode.n1 -text "Foo1"
$::ttv1 insert newnode 0 -id newnode.n2 -text "Foo2"
::ntk::classes::place::place $::ttv1 30 0

set ch [read stdin 1]
#$::te1 insert insert "abc"
#$::tcb1 insert insert "abc"
#set ch [read stdin 1]
#$::te1 insert insert "def"