Make a GadgetItem in a listbox visible?

Started by hackball, May 17, 2020, 20:32:06

Previous topic - Next topic

hackball

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. ???

Henri

#1
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) Select


' DragAndDrop.bmx

Import MaxGui.Drivers

AppTitle = "DragAndDrop Example"

'Creating GUI elements
Global window:TGadget = CreateWindow( AppTitle, 100, 100, 400, 200, Null, WINDOW_DEFAULT | WINDOW_CENTER | WINDOW_ACCEPTFILES)

Local w:Int = ClientWidth(window) / 2
Local h:Int = ClientHeight(window)

Global listbox:TGadget = CreateListBox( 0, 0, w, h, window )
SetGadgetLayout(listbox, EDGE_ALIGNED, EDGE_RELATIVE, EDGE_ALIGNED, EDGE_ALIGNED)

Global label:TGadget = CreateLabel("Drop files ..", w, 0, w, 23, window, LABEL_CENTER)
SetGadgetLayout(label, EDGE_RELATIVE, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_CENTERED)
SetGadgetColor(label, 200, 200, 200)

While WaitEvent()

Print CurrentEvent.tostring()

Select EventID()

Case EVENT_APPRESUME

'ActivateGadget(window)

Case EVENT_WINDOWACTIVATE

'ActivateGadget(window)

Case EVENT_APPSUSPEND

ActivateGadget(window)

Case EVENT_GADGETACTION
Select EventSource()

Case listbox
Local s:String = EventText()
If s Then Notify("Opening " + s)

EndSelect
Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE
End

Case EVENT_WINDOWACCEPT

Local s:String = EventText()
If s Then
Local file:String = StripDir(s)

AddGadgetItem listbox, file,,, "", s
SelectGadgetItem(listbox, CountGadgetItems(listbox) - 1)

EndIf

End Select
Wend


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

hackball

#2
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) Select
Case EVENT_WINDOWACCEPT            'Print "DragnDrop file: "
            Local itm:String = EventText()       
            Select FileType(itm)
                Case 0; Print "ERR : >"+ itm + "< doesn't exist"
                Case 1                                                    'its a file
                    ActivateGadget (window)
                    ActivateGadget (listbox)
                    Local fpath:String = ExtractDir(itm)
                    If Right(fpath,1) <>"/" Then fpath :+"/"
                    AddGadgetItem listbox, StripDir(itm), False, -1, fpath
                    SelectGadgetItem (listbox, CountGadgetItems(listbox)-1)
                Case 2                                                    'its a directory!
                    If Right(itm,1) <>"/" Then itm :+"/"
                    ClearGadgetItems (listbox)            'make this optional later!
                    ScanDirToList (itm, listbox)
            End Select
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.

Henri

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

hackball

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

Henri

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

hackball

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?

wombats

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...:

[table scrollRowToVisible:index];

Build modules (Cmd + D).

Henri

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

hackball

Unfortunatley, it does not work.
And, when building the mods, i get some errors now: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
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

wombats

Oh, are you not using BlitzMax NG? That's what I use.

hackball

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.

wombats

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?

hackball

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. ???

Henri

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