| 1 | /* GuiList.cpp |
| 2 | * |
| 3 | * Copyright (C) 1993-2020,2022,2024,2025 Paul Boersma, 2013 Tom Naughton |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | * See the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include "GuiP.h"cxx . . $ `<file>/sys/GuiP.h`/ |
| 20 | |
| 21 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (GuiList, GuiControl, 0); |
| 22 | |
| 23 | #if motifcxx . . $ `sys/Gui.h:34:10`! |
| 24 | #define iam_list \ |
| 25 | Melder_assert (widget -> widgetClass == xmListWidgetClass); \ |
| 26 | GuiList me = (GuiList) widget -> userData |
| 27 | #endif |
| 28 | |
| 29 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 30 | static void _GuiGtkList_destroyCallbackcxx . . $ _GuiGtkList_destroyCallback(5d22bdacc48458e8). (gpointer void_me) { |
| 31 | iamcxx . . $ `melder/melder.h:50:9`! (GuiList); |
| 32 | forgetcxx . . $ `sys/Thing.h:158:9`! (me); |
| 33 | } |
| 34 | static void _GuiGtkList_selectionChangedCallbackcxx . . $ _GuiGtkList_selectionChangedCallback(5a8d033d0ef50495). (GtkTreeSelection *sel, gpointer void_me) { |
| 35 | iamcxx . . $ `melder/melder.h:50:9`! (GuiList); |
| 36 | if (mycxx . . $ `melder/melder.h:44:9`! d_selectionChangedCallbackcxx . . $ structGuiList#d_selectionChangedCallback. && ! mycxx . . $ `melder/melder.h:44:9`! d_blockValueChangedCallbackscxx . . $ structGuiControl#d_blockValueChangedCallbacks.) { |
| 37 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"Selection changed."); |
| 38 | struct structGuiList_SelectionChangedEventcxx . . $ structGuiList_SelectionChangedEvent# event { me }; |
| 39 | mycxx . . $ `melder/melder.h:44:9`! d_selectionChangedCallbackcxx . . $ structGuiList#d_selectionChangedCallback. (cxx . . $ MelderCallback#`operator()`(e7ade0e2880b4e44).mycxx . . $ `melder/melder.h:44:9`! d_selectionChangedBosscxx . . $ structGuiList#d_selectionChangedBoss., & event); |
| 40 | } |
| 41 | } |
| 42 | #elif motif |
| 43 | void _GuiWinList_destroy (GuiObject widget) { |
| 44 | iam_list; |
| 45 | DestroyWindow (widget -> window); |
| 46 | forget (me); // NOTE: my widget is not destroyed here |
| 47 | } |
| 48 | void _GuiWinList_map (GuiObject widget) { |
| 49 | iam_list; |
| 50 | ShowWindow (widget -> window, SW_SHOW); |
| 51 | } |
| 52 | void _GuiWinList_handleClick (GuiObject widget) { |
| 53 | iam_list; |
| 54 | if (my d_selectionChangedCallback) { |
| 55 | struct structGuiList_SelectionChangedEvent event { me }; |
| 56 | my d_selectionChangedCallback (my d_selectionChangedBoss, & event); |
| 57 | } |
| 58 | } |
| 59 | #elif cocoa |
| 60 | @implementation GuiCocoaList { |
| 61 | GuiList userData; |
| 62 | @public NSMutableArray *contents; |
| 63 | @public NSTableView *tableView; |
| 64 | } |
| 65 | |
| 66 | /* |
| 67 | * Override NSObject methods. |
| 68 | */ |
| 69 | - (void) dealloc { |
| 70 | [self -> contents release]; |
| 71 | GuiThing me = self -> userData; |
| 72 | forget (me); |
| 73 | trace (U"deleting a list"); |
| 74 | [super dealloc]; |
| 75 | } |
| 76 | |
| 77 | /* |
| 78 | * Override NSView methods. |
| 79 | */ |
| 80 | - (id) initWithFrame: (NSRect) frameRect { |
| 81 | self = [super initWithFrame: frameRect]; |
| 82 | if (self) { |
| 83 | self -> tableView = [[NSTableView alloc] initWithFrame: frameRect]; |
| 84 | trace (U"Retain count of table view after creation: ", [self -> tableView retainCount]); // probably 1 |
| 85 | NSTableColumn *tableColumn = [[NSTableColumn alloc] initWithIdentifier: @"list"]; |
| 86 | tableColumn. width = frameRect. size. width; |
| 87 | [tableColumn setEditable: NO]; |
| 88 | [self -> tableView addTableColumn: tableColumn]; |
| 89 | trace (U"Retain count of table view after adding one column: ", [self -> tableView retainCount]); // probably 1 |
| 90 | |
| 91 | self -> tableView. delegate = self; |
| 92 | self -> tableView. dataSource = self; |
| 93 | self -> tableView. allowsEmptySelection = YES; |
| 94 | self -> tableView. headerView = nil; |
| 95 | self -> tableView. target = self; |
| 96 | self -> tableView. action = @selector (_GuiCocoaList_clicked:); |
| 97 | |
| 98 | NSScrollView *scrollView = [[NSScrollView alloc] initWithFrame: frameRect]; |
| 99 | [scrollView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; |
| 100 | [scrollView setBorderType: NSBezelBorder]; |
| 101 | trace (U"Retain count of table view before setting as document view: ", [self -> tableView retainCount]); // probably 1 |
| 102 | [scrollView setDocumentView: self -> tableView]; // this retains the table view |
| 103 | trace (U"Retain count of table view after setting as document view: ", [self -> tableView retainCount]); // probably 3 |
| 104 | [scrollView setHasVerticalScroller: YES]; |
| 105 | //[scrollView setHasHorizontalScroller: YES]; |
| 106 | |
| 107 | trace (U"Retain count of scroll view before adding as subview: ", [scrollView retainCount]); // probably 1 |
| 108 | [self addSubview: scrollView]; // this retains the scroll view |
| 109 | trace (U"Retain count of scroll view after adding as subview: ", [scrollView retainCount]); // probably 3 |
| 110 | |
| 111 | trace (U"Retain count of scroll view before release: ", [scrollView retainCount]); // probably 3 |
| 112 | [scrollView release]; // compensates for alloc |
| 113 | trace (U"Retain count of table view before release: ", [self -> tableView retainCount]); // probably 3 |
| 114 | [self -> tableView release]; // compensates for alloc |
| 115 | |
| 116 | self -> contents = [[NSMutableArray alloc] init]; |
| 117 | } |
| 118 | return self; |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | Implement GuiCocoaAny protocol. |
| 123 | */ |
| 124 | - (GuiThing) getUserData { |
| 125 | return self -> userData; |
| 126 | } |
| 127 | - (void) setUserData: (GuiThing) newUserData { |
| 128 | Melder_assert (newUserData == nullptr || Thing_isa (newUserData, classGuiList)); |
| 129 | self -> userData = static_cast <GuiList> (newUserData); |
| 130 | } |
| 131 | |
| 132 | /* |
| 133 | Implement GuiCocoaList methods. |
| 134 | */ |
| 135 | - (IBAction) _GuiCocoaList_clicked: (id) sender { |
| 136 | /* |
| 137 | This method probably shouldn't do anything, |
| 138 | because tableViewSelectionDidChange will already have been called at this point. |
| 139 | */ |
| 140 | (void) sender; |
| 141 | trace (U"enter"); |
| 142 | GuiList me = self -> userData; |
| 143 | if (me && my d_selectionChangedCallback) { |
| 144 | //struct structGuiList_SelectionChangedEvent event { me }; |
| 145 | //my d_selectionChangedCallback (my d_selectionChangedBoss, & event); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /* |
| 150 | Override TableViewDataSource methods. |
| 151 | */ |
| 152 | - (NSInteger) numberOfRowsInTableView: (NSTableView *) aTableView { |
| 153 | (void) aTableView; |
| 154 | return uinteger_to_integer_a ([self -> contents count]); |
| 155 | } |
| 156 | - (id) tableView: (NSTableView *) aTableView objectValueForTableColumn: (NSTableColumn *) aTableColumn row: (NSInteger) row { |
| 157 | (void) aTableColumn; |
| 158 | (void) aTableView; |
| 159 | return [self -> contents objectAtIndex: integer_to_uinteger_a (row)]; |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | Override TableViewDelegate methods. |
| 164 | */ |
| 165 | - (void) tableViewSelectionDidChange: (NSNotification *) notification { |
| 166 | /* |
| 167 | * This is invoked when the user clicks in the table or uses the arrow keys. |
| 168 | */ |
| 169 | (void) notification; |
| 170 | trace (U"enter"); |
| 171 | GuiList me = self -> userData; |
| 172 | if (me && my d_selectionChangedCallback && ! my d_blockValueChangedCallbacks) { |
| 173 | struct structGuiList_SelectionChangedEvent event { me }; |
| 174 | my d_selectionChangedCallback (my d_selectionChangedBoss, & event); |
| 175 | } |
| 176 | } |
| 177 | @end |
| 178 | #endif |
| 179 | |
| 180 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 181 | enumcxx . . $ $anonymous_type_e55159b6e1225f14_0# { |
| 182 | COLUMN_STRINGcxx . . $ COLUMN_STRING., |
| 183 | N_COLUMNScxx . . $ N_COLUMNS. |
| 184 | }; |
| 185 | #endif |
| 186 | |
| 187 | GuiListcxx . . $ GuiList# GuiList_createcxx . . $ GuiList_create(88aee17cb4a88a62). (GuiFormcxx . . $ GuiForm# parent, int left, int right, int top, int bottom, bool allowMultipleSelection, conststring32cxx . . $ conststring32# header) { |
| 188 | autoGuiListcxx . . $ autoGuiList# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (GuiList); |
| 189 | mycxx . . $ `melder/melder.h:44:9`! d_shellcxx . . $ structGuiThing#d_shell. = parent -> d_shellcxx . . $ structGuiThing#d_shell.; |
| 190 | mycxx . . $ `melder/melder.h:44:9`! d_parentcxx . . $ structGuiThing#d_parent. = parent; |
| 191 | mycxx . . $ `melder/melder.h:44:9`! d_allowMultipleSelectioncxx . . $ structGuiList#d_allowMultipleSelection. = allowMultipleSelection; |
| 192 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 193 | GtkCellRenderer *renderer = nullptr; |
| 194 | GtkTreeViewColumn *col = nullptr; |
| 195 | GtkTreeSelection *sel = nullptr; |
| 196 | GtkListStore *liststore = nullptr; |
| 197 | |
| 198 | liststore = gtk_list_store_new (1, G_TYPE_STRINGcxx . . $ `<external>/9567554376676449156/gtype.h:165:9`!); // 1 column, of type String (this is a vararg list) |
| 199 | GuiObjectcxx . . $ GuiObject# scrolled = gtk_scrolled_window_new (nullptr, nullptr); |
| 200 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOWcxx . . $ `<external>/15242555379300173687/gtkscrolledwindow.h:38:9`! (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
| 201 | mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget. = gtk_tree_view_new_with_model (GTK_TREE_MODELcxx . . $ `<external>/3374684074160863771/gtktreemodel.h:31:9`! (liststore)); |
| 202 | gtk_tree_view_set_headers_visible (GTK_TREE_VIEWcxx . . $ `<external>/10416157116008001206/gtktreeview.h:55:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), false); |
| 203 | gtk_container_add (GTK_CONTAINERcxx . . $ `<external>/462093496598485868/gtkcontainer.h:38:9`! (scrolled), GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)); |
| 204 | gtk_widget_show (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (scrolled)); // BUG |
| 205 | gtk_tree_view_set_rubber_banding (GTK_TREE_VIEWcxx . . $ `<external>/10416157116008001206/gtktreeview.h:55:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), allowMultipleSelection ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_SINGLE); |
| 206 | g_object_unref (liststore); // Destroys the widget after the list is destroyed |
| 207 | |
| 208 | _GuiObject_setUserDatacxx . . $ _GuiObject_setUserData(6c58c5e2437d25a2). (mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget., me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 209 | _GuiObject_setUserDatacxx . . $ _GuiObject_setUserData(6c58c5e2437d25a2). (scrolled, me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); // for resizing |
| 210 | |
| 211 | renderer = gtk_cell_renderer_text_new (); |
| 212 | col = gtk_tree_view_column_new (); |
| 213 | gtk_tree_view_column_pack_start (col, renderer, true); |
| 214 | gtk_tree_view_column_add_attribute (col, renderer, "text", 0); // zeroeth column |
| 215 | if (header) { |
| 216 | //gtk_tree_view_column_set_title (col, Melder_peek32to8 (header)); |
| 217 | } |
| 218 | gtk_tree_view_append_column (GTK_TREE_VIEWcxx . . $ `<external>/10416157116008001206/gtktreeview.h:55:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), col); |
| 219 | |
| 220 | g_object_set_data_full (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), "guiList", me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), (GDestroyNotify) _GuiGtkList_destroyCallbackcxx . . $ _GuiGtkList_destroyCallback(5d22bdacc48458e8).); |
| 221 | |
| 222 | sel = gtk_tree_view_get_selection (GTK_TREE_VIEWcxx . . $ `<external>/10416157116008001206/gtktreeview.h:55:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)); |
| 223 | if (allowMultipleSelection) { |
| 224 | gtk_tree_selection_set_mode (sel, GTK_SELECTION_MULTIPLE); |
| 225 | } else { |
| 226 | gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE); |
| 227 | } |
| 228 | mycxx . . $ `melder/melder.h:44:9`! v_positionInFormcxx . . $ structGuiControl#v_positionInForm(6e76d3e0dab57625). (scrolled, left, right, top, bottom, parent); |
| 229 | g_signal_connectcxx . . $ `<external>/15952772511652638895/gsignal.h:548:9`! (sel, "changed", G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (_GuiGtkList_selectionChangedCallback), me.get()); |
| 230 | #elif motif |
| 231 | my d_widget = _Gui_initializeWidget (xmListWidgetClass, parent -> d_widget, U"list"); |
| 232 | _GuiObject_setUserData (my d_widget, me.get()); |
| 233 | my d_widget -> window = CreateWindowEx (0, L"listbox", L"list", |
| 234 | WS_CHILD | WS_BORDER | WS_VSCROLL | LBS_NOTIFY | WS_CLIPSIBLINGS | |
| 235 | ( allowMultipleSelection ? LBS_EXTENDEDSEL : 0 ), |
| 236 | my d_widget -> x, my d_widget -> y, my d_widget -> width, my d_widget -> height, |
| 237 | my d_widget -> parent -> window, nullptr, theGui.instance, nullptr); |
| 238 | SetWindowLongPtr (my d_widget -> window, GWLP_USERDATA, (LONG_PTR) my d_widget); |
| 239 | SetWindowFont (my d_widget -> window, theWinGuiNormalLabelFont (), false); |
| 240 | /*if (MEMBER (my parent, ScrolledWindow)) { |
| 241 | XtDestroyWidget (my d_widget -> parent -> motiff.scrolledWindow.horizontalBar); |
| 242 | my d_widget -> parent -> motiff.scrolledWindow.horizontalBar = nullptr; |
| 243 | XtDestroyWidget (my d_widget -> parent -> motiff.scrolledWindow.verticalBar); |
| 244 | my d_widget -> parent -> motiff.scrolledWindow.verticalBar = nullptr; |
| 245 | }*/ |
| 246 | my v_positionInForm (my d_widget, left, right, top, bottom, parent); |
| 247 | #elif cocoa |
| 248 | (void) header; |
| 249 | GuiCocoaList *list = [[GuiCocoaList alloc] init]; |
| 250 | my d_widget = (GuiObject) list; |
| 251 | my v_positionInForm (my d_widget, left, right, top, bottom, parent); |
| 252 | [list -> tableView setAllowsMultipleSelection: allowMultipleSelection]; |
| 253 | [list setUserData: me.get()]; |
| 254 | #endif |
| 255 | return me.releaseToAmbiguousOwnercxx . . $ autoSomeThing#releaseToAmbiguousOwner(258ee1c9e0a18a5c).(); |
| 256 | } |
| 257 | |
| 258 | GuiListcxx . . $ GuiList# GuiList_createShowncxx . . $ GuiList_createShown(88aee17cb4a88a62). (GuiFormcxx . . $ GuiForm# parent, int left, int right, int top, int bottom, bool allowMultipleSelection, conststring32cxx . . $ conststring32# header) { |
| 259 | GuiListcxx . . $ GuiList# me = GuiList_createcxx . . $ GuiList_create(88aee17cb4a88a62). (parent, left, right, top, bottom, allowMultipleSelection, header); |
| 260 | GuiThing_showcxx . . $ GuiThing_show(20e88c25f0ba841). (me); |
| 261 | return me; |
| 262 | } |
| 263 | |
| 264 | void GuiList_deleteAllItemscxx . . $ GuiList_deleteAllItems(bb293b59cc37ad76). (GuiListcxx . . $ GuiList# me) { |
| 265 | GuiControlBlockValueChangedCallbackscxx . . $ GuiControlBlockValueChangedCallbacks# blockcxx . . $ GuiControlBlockValueChangedCallbacks#GuiControlBlockValueChangedCallbacks(1363d6663f95c9c7). (me); |
| 266 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 267 | GtkListStore *list_store = GTK_LIST_STOREcxx . . $ `<external>/814451646052299711/gtkliststore.h:34:9`! (gtk_tree_view_get_model (GTK_TREE_VIEWcxx . . $ `<external>/10416157116008001206/gtktreeview.h:55:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget))); |
| 268 | gtk_list_store_clear (list_store); |
| 269 | #elif motif |
| 270 | ListBox_ResetContent (my d_widget -> window); |
| 271 | #elif cocoa |
| 272 | GuiCocoaList *list = (GuiCocoaList *) my d_widget; |
| 273 | [list -> contents removeAllObjects]; |
| 274 | [list -> tableView reloadData]; |
| 275 | #endif |
| 276 | } |
| 277 | |
| 278 | void GuiList_deleteItemcxx . . $ GuiList_deleteItem(f9b5f8b1da8fd2dd). (GuiListcxx . . $ GuiList# me, integercxx . . $ integer# position) { |
| 279 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (position >= 1); // so that we can subtract 1 even if the result has to be unsigned |
| 280 | GuiControlBlockValueChangedCallbackscxx . . $ GuiControlBlockValueChangedCallbacks# blockcxx . . $ GuiControlBlockValueChangedCallbacks#GuiControlBlockValueChangedCallbacks(1363d6663f95c9c7). (me); |
| 281 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 282 | GtkTreeIter iter; |
| 283 | GtkTreeModel *tree_model = gtk_tree_view_get_model (GTK_TREE_VIEWcxx . . $ `<external>/10416157116008001206/gtktreeview.h:55:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)); |
| 284 | if (gtk_tree_model_iter_nth_child (tree_model, & iter, nullptr, (gint) (position - 1))) |
| 285 | gtk_list_store_remove (GTK_LIST_STOREcxx . . $ `<external>/814451646052299711/gtkliststore.h:34:9`! (tree_model), & iter); |
| 286 | #elif motif |
| 287 | ListBox_DeleteString (my d_widget -> window, position - 1); |
| 288 | #elif cocoa |
| 289 | GuiCocoaList *list = (GuiCocoaList *) my d_widget; |
| 290 | [list -> contents removeObjectAtIndex: (NSUInteger) (position - 1)]; |
| 291 | [list -> tableView reloadData]; |
| 292 | #endif |
| 293 | } |
| 294 | |
| 295 | void GuiList_deselectAllItemscxx . . $ GuiList_deselectAllItems(bb293b59cc37ad76). (GuiListcxx . . $ GuiList# me) { |
| 296 | GuiControlBlockValueChangedCallbackscxx . . $ GuiControlBlockValueChangedCallbacks# blockcxx . . $ GuiControlBlockValueChangedCallbacks#GuiControlBlockValueChangedCallbacks(1363d6663f95c9c7). (me); |
| 297 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 298 | GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEWcxx . . $ `<external>/10416157116008001206/gtktreeview.h:55:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)); |
| 299 | gtk_tree_selection_unselect_all (selection); |
| 300 | #elif motif |
| 301 | ListBox_SetSel (my d_widget -> window, False, -1); |
| 302 | #elif cocoa |
| 303 | GuiCocoaList *list = (GuiCocoaList *) my d_widget; |
| 304 | [list -> tableView deselectAll: nil]; |
| 305 | #endif |
| 306 | } |
| 307 | |
| 308 | void GuiList_deselectItemcxx . . $ GuiList_deselectItem(f9b5f8b1da8fd2dd). (GuiListcxx . . $ GuiList# me, integercxx . . $ integer# position) { |
| 309 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (position >= 1); // so that we can subtract 1 even if the result has to be unsigned |
| 310 | GuiControlBlockValueChangedCallbackscxx . . $ GuiControlBlockValueChangedCallbacks# blockcxx . . $ GuiControlBlockValueChangedCallbacks#GuiControlBlockValueChangedCallbacks(1363d6663f95c9c7). (me); |
| 311 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 312 | GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEWcxx . . $ `<external>/10416157116008001206/gtktreeview.h:55:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)); |
| 313 | GtkTreeIter iter; |
| 314 | GtkTreeModel *tree_model = gtk_tree_view_get_model (GTK_TREE_VIEWcxx . . $ `<external>/10416157116008001206/gtktreeview.h:55:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)); |
| 315 | if (gtk_tree_model_iter_nth_child (tree_model, & iter, nullptr, (gint) (position - 1))) |
| 316 | gtk_tree_selection_unselect_iter (selection, & iter); |
| 317 | #elif motif |
| 318 | ListBox_SetSel (my d_widget -> window, False, position - 1); |
| 319 | #elif cocoa |
| 320 | GuiCocoaList *list = (GuiCocoaList *) my d_widget; |
| 321 | [list -> tableView deselectRow: position - 1]; |
| 322 | #endif |
| 323 | } |
| 324 | |
| 325 | autoINTVECcxx . . $ autoINTVEC# GuiList_getSelectedPositionscxx . . $ GuiList_getSelectedPositions(21bc371a31941fa7). (GuiListcxx . . $ GuiList# me) { |
| 326 | autoINTVECcxx . . $ autoINTVEC# selectedPositionscxx . . $ autovector#autovector(49f6e7a06ebc5aa8).; |
| 327 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 328 | GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEWcxx . . $ `<external>/10416157116008001206/gtktreeview.h:55:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)); |
| 329 | GtkListStore *list_store = GTK_LIST_STOREcxx . . $ `<external>/814451646052299711/gtkliststore.h:34:9`! (gtk_tree_view_get_model (GTK_TREE_VIEWcxx . . $ `<external>/10416157116008001206/gtktreeview.h:55:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget))); |
| 330 | int n = gtk_tree_selection_count_selected_rows (selection); |
| 331 | if (n > 0) { |
| 332 | GList *list = gtk_tree_selection_get_selected_rows (selection, (GtkTreeModel **) & list_store); |
| 333 | integercxx . . $ integer# ipos = 1; |
| 334 | selectedPositions =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). zero_INTVECcxx . . $ zero_INTVEC(dab5d3ef28d6a25). (n); |
| 335 | for (GList *l = g_list_first (list); l != nullptr; l = g_list_nextcxx . . $ `<external>/15348682223309100921/glist.h:175:9`! (l)) { |
| 336 | gint *index = gtk_tree_path_get_indices ((GtkTreePath *) l -> datacxx . . $ _GList#data.); |
| 337 | selectedPositions [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ipos] = index [0] + 1; |
| 338 | ipos ++; |
| 339 | } |
| 340 | g_list_foreach (list, (GFunc) gtk_tree_path_free, nullptr); |
| 341 | g_list_free (list); |
| 342 | } |
| 343 | return selectedPositionscxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 344 | #elif motif |
| 345 | int n = ListBox_GetSelCount (my d_widget -> window), *indices; |
| 346 | if (n == 0) |
| 347 | return selectedPositions; |
| 348 | if (n == -1) { // single selection |
| 349 | int selection = ListBox_GetCurSel (my d_widget -> window); |
| 350 | if (selection == -1) |
| 351 | return selectedPositions; |
| 352 | n = 1; |
| 353 | indices = Melder_calloc_f (int, n); |
| 354 | indices [0] = selection; |
| 355 | } else { |
| 356 | indices = Melder_calloc_f (int, n); |
| 357 | ListBox_GetSelItems (my d_widget -> window, n, indices); |
| 358 | } |
| 359 | selectedPositions = zero_INTVEC (n); |
| 360 | for (integer ipos = 1; ipos <= n; ipos ++) |
| 361 | selectedPositions [ipos] = indices [ipos - 1] + 1; // convert from zero-based list of zero-based indices |
| 362 | Melder_free (indices); |
| 363 | #elif cocoa |
| 364 | GuiCocoaList *list = (GuiCocoaList *) my d_widget; |
| 365 | NSIndexSet *indexSet = [list -> tableView selectedRowIndexes]; |
| 366 | selectedPositions = zero_INTVEC (uinteger_to_integer_a ([indexSet count])); |
| 367 | NSUInteger currentIndex = [indexSet firstIndex]; |
| 368 | integer ipos = 0; |
| 369 | while (currentIndex != NSNotFound) { |
| 370 | selectedPositions [++ ipos] = uinteger_to_integer_a (currentIndex + 1); |
| 371 | currentIndex = [indexSet indexGreaterThanIndex: currentIndex]; |
| 372 | } |
| 373 | Melder_assert (ipos == selectedPositions.size); |
| 374 | #endif |
| 375 | return selectedPositionscxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 376 | } |
| 377 | |
| 378 | integercxx . . $ integer# GuiList_getBottomPositioncxx . . $ GuiList_getBottomPosition(699f1c5434bb2ea9). (GuiListcxx . . $ GuiList# me) { |
| 379 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 380 | GtkTreePath *path; |
| 381 | integercxx . . $ integer# position = 1; |
| 382 | if (gtk_tree_view_get_visible_range (GTK_TREE_VIEWcxx . . $ `<external>/10416157116008001206/gtktreeview.h:55:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), nullptr, & path)) { |
| 383 | int *indices = gtk_tree_path_get_indices (path); |
| 384 | position = indices ? indices[0] + 1 : 1; |
| 385 | gtk_tree_path_free (path); // also frees indices !! |
| 386 | } |
| 387 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"bottom: ", position); |
| 388 | return position; |
| 389 | #elif motif |
| 390 | integer bottom = ListBox_GetTopIndex (my d_widget -> window) + my d_widget -> height / ListBox_GetItemHeight (my d_widget -> window, 0); |
| 391 | if (bottom < 1) bottom = 1; |
| 392 | integer n = ListBox_GetCount (my d_widget -> window); |
| 393 | if (bottom > n) bottom = n; |
| 394 | return bottom; |
| 395 | #elif cocoa |
| 396 | (void) me; |
| 397 | return 1; // TODO |
| 398 | #else |
| 399 | return 0; |
| 400 | #endif |
| 401 | } |
| 402 | |
| 403 | integercxx . . $ integer# GuiList_getNumberOfItemscxx . . $ GuiList_getNumberOfItems(699f1c5434bb2ea9). (GuiListcxx . . $ GuiList# me) { |
| 404 | integercxx . . $ integer# numberOfItems = 0; |
| 405 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 406 | GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEWcxx . . $ `<external>/10416157116008001206/gtktreeview.h:55:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)); |
| 407 | numberOfItems = gtk_tree_model_iter_n_children (model, nullptr); |
| 408 | #elif motif |
| 409 | numberOfItems = ListBox_GetCount (my d_widget -> window); |
| 410 | #elif cocoa |
| 411 | GuiCocoaList *list = (GuiCocoaList *) my d_widget; |
| 412 | numberOfItems = uinteger_to_integer_a ([list -> contents count]); |
| 413 | #endif |
| 414 | return numberOfItems; |
| 415 | } |
| 416 | |
| 417 | integercxx . . $ integer# GuiList_getTopPositioncxx . . $ GuiList_getTopPosition(699f1c5434bb2ea9). (GuiListcxx . . $ GuiList# me) { |
| 418 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 419 | GtkTreePath *path; |
| 420 | integercxx . . $ integer# position = 1; |
| 421 | if (gtk_tree_view_get_visible_range (GTK_TREE_VIEWcxx . . $ `<external>/10416157116008001206/gtktreeview.h:55:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), & path, nullptr)) { |
| 422 | int *indices = gtk_tree_path_get_indices (path); |
| 423 | position = indices ? indices[0] + 1 : 1; |
| 424 | gtk_tree_path_free (path); // also frees indices !! |
| 425 | } |
| 426 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"top: ", position); |
| 427 | return position; |
| 428 | #elif motif |
| 429 | integer top = ListBox_GetTopIndex (my d_widget -> window); |
| 430 | if (top < 1) top = 1; |
| 431 | integer n = ListBox_GetCount (my d_widget -> window); |
| 432 | if (top > n) top = 0; |
| 433 | return top; |
| 434 | #elif cocoa |
| 435 | (void) me; |
| 436 | return 1; // TODO |
| 437 | #else |
| 438 | return 0; |
| 439 | #endif |
| 440 | } |
| 441 | |
| 442 | void GuiList_insertItemcxx . . $ GuiList_insertItem(896610c612ff86cf). (GuiListcxx . . $ GuiList# me, conststring32cxx . . $ conststring32# itemText /* cattable */, integercxx . . $ integer# position_base1) { |
| 443 | bool explicitlyInsertAtEnd = ( position_base1 <= 0 ); |
| 444 | GuiControlBlockValueChangedCallbackscxx . . $ GuiControlBlockValueChangedCallbacks# blockcxx . . $ GuiControlBlockValueChangedCallbacks#GuiControlBlockValueChangedCallbacks(1363d6663f95c9c7). (me); |
| 445 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 446 | GtkListStore *list_store = GTK_LIST_STOREcxx . . $ `<external>/814451646052299711/gtkliststore.h:34:9`! (gtk_tree_view_get_model (GTK_TREE_VIEWcxx . . $ `<external>/10416157116008001206/gtktreeview.h:55:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget))); |
| 447 | gtk_list_store_insert_with_values (list_store, nullptr, explicitlyInsertAtEnd ? 1000000000 : (gint) position_base1 - 1, COLUMN_STRINGcxx . . $ COLUMN_STRING., Melder_peek32to8 (itemText), -1); |
| 448 | #elif motif |
| 449 | HWND nativeList = my d_widget -> window; |
| 450 | conststringW nativeItemText = Melder_peek32toW (itemText); |
| 451 | if (explicitlyInsertAtEnd) { |
| 452 | ListBox_AddString (nativeList, nativeItemText); |
| 453 | } else { |
| 454 | int nativePosition_base0 = position_base1 - 1; |
| 455 | ListBox_InsertString (nativeList, nativePosition_base0, nativeItemText); |
| 456 | } |
| 457 | #elif cocoa |
| 458 | GuiCocoaList *nativeList = (GuiCocoaList *) my d_widget; |
| 459 | NSString *nativeItemText = [[NSString alloc] initWithUTF8String: Melder_peek32to8 (itemText)]; |
| 460 | if (explicitlyInsertAtEnd) { |
| 461 | [nativeList -> contents addObject: nativeItemText]; |
| 462 | } else { |
| 463 | NSUInteger nativePosition_base0 = (uinteger) position_base1 - 1; |
| 464 | [nativeList -> contents insertObject: nativeItemText atIndex: nativePosition_base0]; |
| 465 | } |
| 466 | [nativeItemText release]; |
| 467 | [nativeList -> tableView reloadData]; |
| 468 | #endif |
| 469 | } |
| 470 | |
| 471 | void GuiList_replaceItemcxx . . $ GuiList_replaceItem(896610c612ff86cf). (GuiListcxx . . $ GuiList# me, conststring32cxx . . $ conststring32# itemText, integercxx . . $ integer# position) { |
| 472 | GuiControlBlockValueChangedCallbackscxx . . $ GuiControlBlockValueChangedCallbacks# blockcxx . . $ GuiControlBlockValueChangedCallbacks#GuiControlBlockValueChangedCallbacks(1363d6663f95c9c7). (me); |
| 473 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 474 | GtkTreeIter iter; |
| 475 | GtkTreeModel *tree_model = gtk_tree_view_get_model (GTK_TREE_VIEWcxx . . $ `<external>/10416157116008001206/gtktreeview.h:55:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)); |
| 476 | if (gtk_tree_model_iter_nth_child (tree_model, & iter, nullptr, (gint) (position - 1))) |
| 477 | gtk_list_store_set (GTK_LIST_STOREcxx . . $ `<external>/814451646052299711/gtkliststore.h:34:9`! (tree_model), & iter, COLUMN_STRINGcxx . . $ COLUMN_STRING., Melder_peek32to8 (itemText), -1); |
| 478 | #elif motif |
| 479 | integer nativePosition = position - 1; // convert from 1-based to zero-based |
| 480 | ListBox_DeleteString (my d_widget -> window, nativePosition); |
| 481 | ListBox_InsertString (my d_widget -> window, nativePosition, Melder_peek32toW (itemText)); |
| 482 | #elif cocoa |
| 483 | GuiCocoaList *list = (GuiCocoaList *) my d_widget; |
| 484 | NSString *nsString = [[NSString alloc] initWithUTF8String: Melder_peek32to8 (itemText)]; |
| 485 | [list -> contents replaceObjectAtIndex: integer_to_uinteger_a (position - 1) withObject: nsString]; |
| 486 | [nsString release]; |
| 487 | [list -> tableView reloadData]; |
| 488 | #endif |
| 489 | } |
| 490 | |
| 491 | void GuiList_selectItemcxx . . $ GuiList_selectItem(f9b5f8b1da8fd2dd). (GuiListcxx . . $ GuiList# me, integercxx . . $ integer# position) { |
| 492 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (position >= 1); // so that we can subtract 1 even if the result has to be unsigned |
| 493 | GuiControlBlockValueChangedCallbackscxx . . $ GuiControlBlockValueChangedCallbacks# blockcxx . . $ GuiControlBlockValueChangedCallbacks#GuiControlBlockValueChangedCallbacks(1363d6663f95c9c7). (me); |
| 494 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 495 | GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEWcxx . . $ `<external>/10416157116008001206/gtktreeview.h:55:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)); |
| 496 | GtkTreePath *path = gtk_tree_path_new_from_indices ((gint) position - 1, -1 /* terminator */); |
| 497 | gtk_tree_selection_select_path (selection, path); |
| 498 | gtk_tree_path_free (path); |
| 499 | #elif motif |
| 500 | if (! my d_allowMultipleSelection) { |
| 501 | ListBox_SetCurSel (my d_widget -> window, position - 1); |
| 502 | } else { |
| 503 | ListBox_SetSel (my d_widget -> window, True, position - 1); |
| 504 | } |
| 505 | #elif cocoa |
| 506 | NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndex: NSUInteger (position - 1)]; |
| 507 | GuiCocoaList *list = (GuiCocoaList *) my d_widget; |
| 508 | [list -> tableView selectRowIndexes: indexSet byExtendingSelection: my d_allowMultipleSelection]; |
| 509 | [indexSet release]; |
| 510 | #endif |
| 511 | } |
| 512 | |
| 513 | void GuiList_setSelectionChangedCallbackcxx . . $ GuiList_setSelectionChangedCallback(4a4684c95b017ef2). (GuiListcxx . . $ GuiList# me, GuiList_SelectionChangedCallbackcxx . . $ GuiList_SelectionChangedCallback# callback, Thingcxx . . $ Thing# boss) { |
| 514 | mycxx . . $ `melder/melder.h:44:9`! d_selectionChangedCallbackcxx . . $ structGuiList#d_selectionChangedCallback. =cxx . . $ MelderCallback#`operator=`(2a50312b410f5f0c). callback; |
| 515 | mycxx . . $ `melder/melder.h:44:9`! d_selectionChangedBosscxx . . $ structGuiList#d_selectionChangedBoss. = boss; |
| 516 | } |
| 517 | |
| 518 | void GuiList_setDoubleClickCallbackcxx . . $ GuiList_setDoubleClickCallback(1ef636283ce6f16). (GuiListcxx . . $ GuiList# me, GuiList_DoubleClickCallbackcxx . . $ GuiList_DoubleClickCallback# callback, Thingcxx . . $ Thing# boss) { |
| 519 | mycxx . . $ `melder/melder.h:44:9`! d_doubleClickCallbackcxx . . $ structGuiList#d_doubleClickCallback. =cxx . . $ MelderCallback#`operator=`(451b7ddabcb369ee). callback; |
| 520 | mycxx . . $ `melder/melder.h:44:9`! d_doubleClickBosscxx . . $ structGuiList#d_doubleClickBoss. = boss; |
| 521 | } |
| 522 | |
| 523 | void GuiList_setScrollCallbackcxx . . $ GuiList_setScrollCallback(89a218c210a2f369). (GuiListcxx . . $ GuiList# me, GuiList_ScrollCallbackcxx . . $ GuiList_ScrollCallback# callback, Thingcxx . . $ Thing# boss) { |
| 524 | mycxx . . $ `melder/melder.h:44:9`! d_scrollCallbackcxx . . $ structGuiList#d_scrollCallback. =cxx . . $ MelderCallback#`operator=`(d6cf1bbd622798eb). callback; |
| 525 | mycxx . . $ `melder/melder.h:44:9`! d_scrollBosscxx . . $ structGuiList#d_scrollBoss. = boss; |
| 526 | } |
| 527 | |
| 528 | void GuiList_setTopPositioncxx . . $ GuiList_setTopPosition(f9b5f8b1da8fd2dd). (GuiListcxx . . $ GuiList# me, integercxx . . $ integer# topPosition) { |
| 529 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"Set top position ", topPosition); |
| 530 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 531 | // GtkListStore *list_store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (my md_widget))); |
| 532 | GtkTreePath *path = gtk_tree_path_new_from_indices ((gint) topPosition, -1 /* terminator */); // BUG? |
| 533 | gtk_tree_view_scroll_to_cell (GTK_TREE_VIEWcxx . . $ `<external>/10416157116008001206/gtktreeview.h:55:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), path, nullptr, false, 0.0, 0.0); |
| 534 | gtk_tree_path_free (path); |
| 535 | #elif motif |
| 536 | ListBox_SetTopIndex (my d_widget -> window, topPosition - 1); |
| 537 | #elif cocoa |
| 538 | (void) me; |
| 539 | // TODO: implement |
| 540 | #endif |
| 541 | } |
| 542 | |
| 543 | /* End of file GuiList.cpp */ |