December 03, 2020, 12:04:45 PM

Author Topic: Make a GadgetItem in a listbox visible?  (Read 1167 times)

Offline hackball

  • Jr. Member
  • **
  • Posts: 37
Make a GadgetItem in a listbox visible?
« on: May 17, 2020, 08:32:06 PM »
This is something i am stumbling about right now:
I have created a listbox and when i add items to it by dropping files or directories onto the window they are added to the bottom of the list by default. What i want is to scroll the list up to make those new items visible.I can select a new item with SelectGadgetItem() (but this does not trigger an event i can work with, unfortunately) but i cannot make it visible.
What do i miss? I had a look into the gadgets.bmx but didn't find a method to do that. ???

Offline Henri

  • Sr. Member
  • ****
  • Posts: 265
Re: Make a GadgetItem in a listbox visible?
« Reply #1 on: May 18, 2020, 12:12:36 AM »
Hi,

there is probably some piece missing from this puzzle but..

What you can do is insert the item at a different place in a list with the InsertGadgetItem if needed (I'm assuming you are catching the window drag&drop event and add item from there). SelectGadgetItem should make the line visible, but that doesn't create an event. Of course, you can create an event with PostEvent at the same location as the inserting/adding part happens (if you really want to..).

EDIT_2:  Code updated

Code: BlitzMax
  1.  
  2. ' DragAndDrop.bmx
  3.  
  4. Import MaxGui.Drivers
  5.  
  6. AppTitle = "DragAndDrop Example"
  7.  
  8. 'Creating GUI elements
  9. Global window:TGadget = CreateWindow( AppTitle, 100, 100, 400, 200, Null, WINDOW_DEFAULT | WINDOW_CENTER | WINDOW_ACCEPTFILES)
  10.  
  11. Local w:Int = ClientWidth(window) / 2
  12. Local h:Int = ClientHeight(window)
  13.  
  14. Global listbox:TGadget = CreateListBox( 0, 0, w, h, window )
  15.         SetGadgetLayout(listbox, EDGE_ALIGNED, EDGE_RELATIVE, EDGE_ALIGNED, EDGE_ALIGNED)
  16.  
  17. Global label:TGadget = CreateLabel("Drop files ..", w, 0, w, 23, window, LABEL_CENTER)
  18.         SetGadgetLayout(label, EDGE_RELATIVE, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_CENTERED)
  19.         SetGadgetColor(label, 200, 200, 200)   
  20.  
  21. While WaitEvent()
  22.        
  23.         Print CurrentEvent.tostring()
  24.        
  25.         Select EventID()
  26.        
  27.         Case EVENT_APPRESUME
  28.        
  29.                 'ActivateGadget(window)
  30.        
  31.         Case EVENT_WINDOWACTIVATE
  32.        
  33.                 'ActivateGadget(window)
  34.        
  35.         Case EVENT_APPSUSPEND
  36.                
  37.                 ActivateGadget(window)
  38.                
  39.         Case EVENT_GADGETACTION
  40.                 Select EventSource()
  41.  
  42.                 Case listbox
  43.                         Local s:String = EventText()
  44.                         If s Then Notify("Opening " + s)
  45.                        
  46.                 EndSelect
  47.         Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE
  48.                 End
  49.                
  50.         Case EVENT_WINDOWACCEPT
  51.                
  52.                 Local s:String = EventText()
  53.                 If s Then
  54.                         Local file:String = StripDir(s)
  55.                        
  56.                         AddGadgetItem listbox, file,,, "", s
  57.                         SelectGadgetItem(listbox, CountGadgetItems(listbox) - 1)
  58.                        
  59.                 EndIf
  60.                
  61.         End Select
  62. Wend
  63.  

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Offline hackball

  • Jr. Member
  • **
  • Posts: 37
Re: Make a GadgetItem in a listbox visible?
« Reply #2 on: May 18, 2020, 08:06:10 PM »
Thanks, i can't get it to work. Is this because while dropping files onto the window the app is in suspended state?
ActivateWindow()/ActivateGadget() do not work either, i tried this:
Code: BlitzMax
  1. Case EVENT_WINDOWACCEPT            'Print "DragnDrop file: "
  2.             Local itm:String = EventText()        
  3.             Select FileType(itm)
  4.                 Case 0; Print "ERR : >"+ itm + "< doesn't exist"
  5.                 Case 1                                                    'its a file
  6.                     ActivateGadget (window)
  7.                     ActivateGadget (listbox)
  8.                     Local fpath:String = ExtractDir(itm)
  9.                     If Right(fpath,1) <>"/" Then fpath :+"/"
  10.                     AddGadgetItem listbox, StripDir(itm), False, -1, fpath
  11.                     SelectGadgetItem (listbox, CountGadgetItems(listbox)-1)
  12.                 Case 2                                                    'its a directory!
  13.                     If Right(itm,1) <>"/" Then itm :+"/"
  14.                     ClearGadgetItems (listbox)            'make this optional later!
  15.                     ScanDirToList (itm, listbox)
  16.             End Select
  17.  
The item(s) gets added, the item gets selected but the listbox and the window stay inactive (Mac OS X), the listbox does not scroll the new items into the visible field.

Offline Henri

  • Sr. Member
  • ****
  • Posts: 265
Re: Make a GadgetItem in a listbox visible?
« Reply #3 on: May 18, 2020, 09:57:34 PM »
You mean that the scrollbars wont appear?

I've changed the example above if you can try that out by adding some files.

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Offline hackball

  • Jr. Member
  • **
  • Posts: 37
Re: Make a GadgetItem in a listbox visible?
« Reply #4 on: May 19, 2020, 08:25:32 PM »
No, doesn't work.
I drop some files or just one, the listbox refreshes and a scrollbar appears, that's okay so far.But, i'd like to activate the window, or, at least scroll the list down to the last entry i just added.pic1
When i click on the window and scrolldown the list, the listbox shows a selected entry, but the listbox gadget has not the focus.pic2
it should look like this, after clicking on the listbox:pic3

Offline Henri

  • Sr. Member
  • ****
  • Posts: 265
Re: Make a GadgetItem in a listbox visible?
« Reply #5 on: May 19, 2020, 10:42:31 PM »
I believe you can't easily grab a focus for a window in any os when your app loses focus, but I tried ActivateGadget in different places,  and did manage to get the selected item to show as selected (at least in Windows).

Code updated above.

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Offline hackball

  • Jr. Member
  • **
  • Posts: 37
Re: Make a GadgetItem in a listbox visible?
« Reply #6 on: May 20, 2020, 08:15:16 PM »
Thanx again. But the main problem still remains unsolved: I cannot get any item outside the visible area into the visible area.I really need an MakeItemVisible or something like that.
Imagine i want to implement a real time search from a list and the list is like 2000 items long; i should be able to jump to view the item #788 so the user can see it.
The ActivateWindow() stuff still don't work on Mac, but this was just a silly idea to force the selected item being shown as if the listbox has the focus. But that does not work either.
I might give TreeView a go, maybe that works differently?

Offline wombats

  • Jr. Member
  • **
  • Posts: 52
Re: Make a GadgetItem in a listbox visible?
« Reply #7 on: May 20, 2020, 10:56:01 PM »
It will work with a TreeView since it uses scrollRowToVisible (a Cocoa command).

If you want to make it work with a ListBox, search for -(void)selectItem:(unsigned)index{ in /mod/maxgui.mod/cocoamaxgui.mod/cocoa.macos.m and add the following after [table selectRowIndexes...:

Code: [Select]
[table scrollRowToVisible:index];
Build modules (Cmd + D).

Offline Henri

  • Sr. Member
  • ****
  • Posts: 265
Re: Make a GadgetItem in a listbox visible?
« Reply #8 on: May 21, 2020, 09:01:08 AM »
Good find there wombats. I always struggle with macs sense I don't have one :-)

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Offline hackball

  • Jr. Member
  • **
  • Posts: 37
Re: Make a GadgetItem in a listbox visible?
« Reply #9 on: May 21, 2020, 11:17:10 AM »
Unfortunatley, it does not work.
And, when building the mods, i get some errors now:
Code: [Select]
Archiving:blitz.debug.macos.x86.a
Compiling:debugger_mt.stdio.bmx
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/BlitzMax151/mod/brl.mod/blitz.mod/.bmx/blitz_gc.c.debug.macos.x86.o has no symbols
Code: [Select]
Compiling:blitz_app.c
clang: error: unknown argument: '-fno-tree-vrp'
Build Error: failed to compile /Applications/BlitzMax151/mod/brl.mod/blitz.mod/blitz_app.c
Process complete

Offline wombats

  • Jr. Member
  • **
  • Posts: 52
Re: Make a GadgetItem in a listbox visible?
« Reply #10 on: May 21, 2020, 12:10:47 PM »
Oh, are you not using BlitzMax NG? That's what I use.

Offline hackball

  • Jr. Member
  • **
  • Posts: 37
Re: Make a GadgetItem in a listbox visible?
« Reply #11 on: May 21, 2020, 02:02:04 PM »
No, i couldn't install it. It fails to build on my machine. So i am stuck with BMax 1.51.But all builds needs to work on 10.6 upto 10.10 at least for my needs. I am not sure BMaxNG can do that even if i could get it to build.

Offline wombats

  • Jr. Member
  • **
  • Posts: 52
Re: Make a GadgetItem in a listbox visible?
« Reply #12 on: May 21, 2020, 02:25:29 PM »
BlitzMax 151 doesn't seem to work on Catalina, so I'm afraid I can't test it.

Do you still get those build errors even without making the change I suggested?

Offline hackball

  • Jr. Member
  • **
  • Posts: 37
Re: Make a GadgetItem in a listbox visible?
« Reply #13 on: May 21, 2020, 05:31:38 PM »
Yes, the build errors still remain.So, by basically try to install and build BMaxNG (and it failed) a few days ago i broke my perfectly fine BMax1.51 environment?This is not a way to go to, guys. ???

Offline Henri

  • Sr. Member
  • ****
  • Posts: 265
Re: Make a GadgetItem in a listbox visible?
« Reply #14 on: May 21, 2020, 07:07:11 PM »
I have no experience on macs, but just to get some more info, what macOS you have ?

Building modules is advanced stuff , and there is always some risk involved, more so if you have no experience in the matter. Of course, if you have never built modules then you have the basic setup and can just download Blitzmax 1.51 again and install it. This should reset everything.

-Henri
- Got 01100011 problems, but the bit ain't 00000001

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal