SyntaxBomb - Indie Coders

Languages & Coding => BlitzMax / BlitzMax NG => MaxGUI => Topic started by: hackball on May 17, 2020, 20:32:06

Title: Make a GadgetItem in a listbox visible?
Post by: hackball on May 17, 2020, 20:32:06
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. ???
Title: Re: Make a GadgetItem in a listbox visible?
Post by: Henri on May 18, 2020, 00:12:36
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
Title: Re: Make a GadgetItem in a listbox visible?
Post by: hackball on May 18, 2020, 20:06:10
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.
Title: Re: Make a GadgetItem in a listbox visible?
Post by: Henri on May 18, 2020, 21:57:34
You mean that the scrollbars wont appear?

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

-Henri
Title: Re: Make a GadgetItem in a listbox visible?
Post by: hackball on May 19, 2020, 20:25:32
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
Title: Re: Make a GadgetItem in a listbox visible?
Post by: Henri on May 19, 2020, 22:42:31
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
Title: Re: Make a GadgetItem in a listbox visible?
Post by: hackball on May 20, 2020, 20:15:16
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?
Title: Re: Make a GadgetItem in a listbox visible?
Post by: wombats on May 20, 2020, 22:56:01
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).
Title: Re: Make a GadgetItem in a listbox visible?
Post by: Henri on May 21, 2020, 09:01:08
Good find there wombats. I always struggle with macs sense I don't have one :-)

-Henri
Title: Re: Make a GadgetItem in a listbox visible?
Post by: hackball on May 21, 2020, 11:17:10
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
Title: Re: Make a GadgetItem in a listbox visible?
Post by: wombats on May 21, 2020, 12:10:47
Oh, are you not using BlitzMax NG? That's what I use.
Title: Re: Make a GadgetItem in a listbox visible?
Post by: hackball on May 21, 2020, 14:02:04
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.
Title: Re: Make a GadgetItem in a listbox visible?
Post by: wombats on May 21, 2020, 14:25:29
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?
Title: Re: Make a GadgetItem in a listbox visible?
Post by: hackball on May 21, 2020, 17:31:38
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. ???
Title: Re: Make a GadgetItem in a listbox visible?
Post by: Henri on May 21, 2020, 19:07:11
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
Title: Re: Make a GadgetItem in a listbox visible?
Post by: hackball on May 21, 2020, 23:28:18
I am still running Mac OS X, not macOS, because of the limitations.I can test my apps on Mojave, HighSierra if i want, but for now i keep my 10.9 Mavericks. It looks better.
Title: Re: Make a GadgetItem in a listbox visible?
Post by: wombats on May 21, 2020, 23:45:37
What limitations are present in macOS? I can only think of lack of 32-bit support (which is why I can't help with BlitzMax 151).
Title: Re: Make a GadgetItem in a listbox visible?
Post by: hackball on May 21, 2020, 23:53:13
Yes, 32bit support and you can never go back. I think it is really bad to "upgrade" to a major OS version every year and potentially cut off all bondings some artificial unknown time (days, months...) later.It is still OS 10, right. Every followup is just a revision, it must not break compatibility. That was the rule before. Nowadays they push an update and two years later none of your Apps are working anymore, maybe sooner, who knows?
Title: Re: Make a GadgetItem in a listbox visible?
Post by: Henri on May 22, 2020, 00:13:57
It is possible that if you have an older version OS then you probably have older version of Xcode developments tools installed. If you update them you might get the module building working. Also, you might be missing Xcode command line tools as well.

If you try then please backup your Blitzmax/mod folder first so if anything goes wrong you can always revert back.

If you destroy anything else in the process then I can't be held responsible :-)

-Henri