[PB 4.60] GetActiveGadget doesn't give the right value ?

Just starting out? Need help? Post your questions and find answers here.
SeaWolf
User
User
Posts: 12
Joined: Mon Mar 15, 2010 6:06 pm
Location: France

[PB 4.60] GetActiveGadget doesn't give the right value ?

Post by SeaWolf »

Hi,

I'm writing a cross-platform program (Windows/Linux), it works as expected in Windows, however in Linux I'm running into some trouble with GetActiveGadget.
This is with PureBasic 4.60 x86 Final, with Arch LInux.

Here is a simplified program to show the trouble :

Code: Select all

Enumeration
    #Window_0
    #ListIcon
    #Menu
    #Rename
    #Remove
EndEnumeration

If OpenWindow(#Window_0, 168, 103, 1024, 508, "Test", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_TitleBar | #PB_Window_SizeGadget)

    ListIconGadget(#ListIcon, 10, 40, 1000, 440, "Folder", 187, #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
    AddGadgetColumn(#ListIcon, 1, "Name", 600)
    AddGadgetColumn(#ListIcon, 2, "Size (MB)", 70)
    AddGadgetColumn(#ListIcon, 3, "Date", 109)
    AddKeyboardShortcut(#Window_0, #PB_Shortcut_F2, #Rename)
    AddKeyboardShortcut(#Window_0, #PB_Shortcut_Delete, #Remove)

    AddGadgetItem(#ListIcon, -1, "folder1" + Chr(10) + "file1" + Chr(10) + "312" + Chr(10) + "06/11/2011 16:54")
    AddGadgetItem(#ListIcon, -1, "folder2" + Chr(10) + "file2" + Chr(10) + "65" + Chr(10) + "10/01/2009 08:33")

    If CreatePopupMenu(#Menu)
        MenuItem(#Rename, "Rename" + Chr(9) + "F2")
        MenuItem(#Remove, "Delete" + Chr(9) + "Del")
    EndIf

   Repeat
            Event = WaitWindowEvent()
    
            Select Event
            Case #PB_Event_Gadget

                Select EventGadget()

                    Case #ListIcon
                        Select EventType()
                            Case #PB_EventType_RightClick
                                DisplayPopupMenu(#Menu, WindowID(#Window_0))
                        EndSelect

                EndSelect
                    
                Case #PB_Event_Menu
    
                    Select EventMenu()
                        Case #Rename
                            Debug(GetActiveGadget())
                            If GetActiveGadget() = #ListIcon And GetGadgetState(#ListIcon) <> -1
                                newName$ = InputRequester("Rename", "Enter the new name (or 'Esc' to cancel) :", GetGadgetItemText(#ListIcon, GetGadgetState(#ListIcon), 1))
                            EndIf
                            
                        Case #Remove
                            Debug(GetActiveGadget())                            
                            If GetActiveGadget() = #ListIcon And GetGadgetState(#ListIcon) <> -1
                                confirm = MessageRequester("Delete", "Delete " + GetGadgetItemText(#ListIcon, GetGadgetState(#ListIcon), 1) + " ?", #PB_MessageRequester_YesNo)
                            EndIf
                                                                                                                
                    EndSelect
    
            EndSelect
    
    Until Event = #PB_Event_CloseWindow
    
EndIf
So, I select a line inside the listicon, and then :
- if I right-click on the line, and then click on "rename" (or "delete") in the popup menu, "debug GetActiveGadget()" shows -1 (that is, no Gadget has the focus) and the rename (or delete) dialog window doesn't appear,
- if I use the shortcuts (F2 or Del key), then debug shows 1 (the listicon has the focus) and the rename/delete dialog window appears as expected.

Is it a bug ? Again, in Windows it works perfectly.
Thanks.

P.S. : besides, I see that the InputRequester and MessageRequester windows are non-modal, while they are modal in Windows. But I think I can find a way around that.
User avatar
idle
Always Here
Always Here
Posts: 5837
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: [PB 4.60] GetActiveGadget doesn't give the right value ?

Post by idle »

Don't know if it's a bug but once you've got the menu displaying it becomes the active gadget
in terms of how gtk sees things. So you will need to track it yourself, I guess.

Code: Select all

Enumeration
    #Window_0
    #ListIcon
    #Menu
    #Rename
    #Remove
EndEnumeration

Define activeGadget

If OpenWindow(#Window_0, 168, 103, 1024, 508, "Test", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_TitleBar | #PB_Window_SizeGadget)

    ListIconGadget(#ListIcon, 10, 40, 1000, 440, "Folder", 187, #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
    AddGadgetColumn(#ListIcon, 1, "Name", 600)
    AddGadgetColumn(#ListIcon, 2, "Size (MB)", 70)
    AddGadgetColumn(#ListIcon, 3, "Date", 109)
    AddKeyboardShortcut(#Window_0, #PB_Shortcut_F2, #Rename)
    AddKeyboardShortcut(#Window_0, #PB_Shortcut_Delete, #Remove)

    AddGadgetItem(#ListIcon, -1, "folder1" + Chr(10) + "file1" + Chr(10) + "312" + Chr(10) + "06/11/2011 16:54")
    AddGadgetItem(#ListIcon, -1, "folder2" + Chr(10) + "file2" + Chr(10) + "65" + Chr(10) + "10/01/2009 08:33")

    If CreatePopupMenu(#Menu)
        MenuItem(#Rename, "Rename" + Chr(9) + "F2")
        MenuItem(#Remove, "Delete" + Chr(9) + "Del")
    EndIf

   Repeat
            Event = WaitWindowEvent()
   
            Select Event
            Case #PB_Event_Gadget

                Select EventGadget()

                    Case #ListIcon
                        Select EventType()
                            Case #PB_EventType_RightClick
                              activeGadget = GetActiveGadget()
                              DisplayPopupMenu(#Menu, WindowID(#Window_0))
                        EndSelect

                EndSelect
                   
                Case #PB_Event_Menu
   
                    Select EventMenu()
                        Case #Rename
                            Debug(GetActiveGadget())
                            If  activeGadget = #ListIcon And GetGadgetState(#ListIcon) <> -1
                                newName$ = InputRequester("Rename", "Enter the new name (or 'Esc' to cancel) :", GetGadgetItemText(#ListIcon, GetGadgetState(#ListIcon), 1))
                            EndIf
                           
                        Case #Remove
                            Debug(GetActiveGadget())                           
                            If  activeGadget = #ListIcon And GetGadgetState(#ListIcon) <> -1
                                confirm = MessageRequester("Delete", "Delete " + GetGadgetItemText(#ListIcon, GetGadgetState(#ListIcon), 1) + " ?", #PB_MessageRequester_YesNo)
                            EndIf
                                                                                                               
                    EndSelect
   
            EndSelect
   
    Until Event = #PB_Event_CloseWindow
   
EndIf
Windows 11, Manjaro, Raspberry Pi OS
Image
SeaWolf
User
User
Posts: 12
Joined: Mon Mar 15, 2010 6:06 pm
Location: France

Re: [PB 4.60] GetActiveGadget doesn't give the right value ?

Post by SeaWolf »

Thanks idle, I get the idea :)
Post Reply