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