From: Stalkern 2 Reply-To: stalkern2 at tin.it To: lablgtk at kaba.or.jp Subject: GTK1.2 clist column sort: hints for beginners Date: Thu, 29 May 2003 14:21:37 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200305291421.37032.stalkern2 at tin.it> I post this here in case somebody may save some time with this issue To create a clist with a basic callback for cell and a callback for sorting on titles, you can use something like this: let callback_sort_cListColumn (aCList: string GList.clist) colNum () = let () = aCList #set_sort ~auto:true ~dir:`ASCENDING (*`DESCENDING*) ~column:colNum () in let () = aCList #sort () in () in let create_cList aViewPort aScrolledWindow aCListTitlesL = ( let thisCList = GList.clist ~titles:aCListTitlesL ~shadow_type:`OUT ~packing:aScrolledWindow#add () (*~packing:tabsViewer#patTabViewport#add does not allow keeping titles at the same place when scrolling the rest*) in let _ = thisCList#connect#select_row ~callback: (fun ~row ~column ~event -> let text = thisCList#cell_text row column in Printf.printf "You selected row %d. More specifically you clicked in column %d, and the text in this cell is %s\n\n" row column text; flush Pervasives.stdout ) in let _ = thisCList#set_titles_active true in let allColsNum = thisCList #columns in let _ = for n = 0 to allColsNum do ignore (thisCList #connect #click_column ~callback: (fun n -> (callback_sort_cListColumn thisCList n ()))) done in thisCList ) Please notice that the callback is not connected to a title object, but to a click_column signal of the clist. Who wants to have ASCENDING sort alternate to DESCENDING sort, can as usual store the current behaviour of that column header in a ref value. One thing more: if the signal were named click_title, people could find it out before... but actually one can put a generic widget (e.g. a pixmap image) at the place of the title, by using code like: let clistVbox = GPack.vbox ~spacing:0 ~homogeneous:false () in let clistCol1Pixmap = GMisc.pixmap (GDraw.pixmap_from_xpm ~file:"pixmaps/littepixmap.xpm" ()) ~packing:(clistVbox#pack ~padding:0 ~fill:true ~expand:true) ~xalign:0.5 ~yalign:0.5 ~xpad:0 ~ypad:0 () in let clistCol1Label = GMisc.label ~text: "Col 1" ~packing:(clistVbox#pack ~padding:0 ~fill:false ~expand:false) ~xalign:0.5 ~yalign:0.5 ~xpad:0 ~ypad:0 ~line_wrap:false () in let _ = testClist#set_column ~widget:(clistVbox#coerce) 1 in ();; Ciao Ernesto PS inspiration came from http://misha.host.ge/public/programming/gtk-tutorial.20000721/html/sec-workingwithtitles.html