Strange behaviour of combobox-gadget

Just starting out? Need help? Post your questions and find answers here.
Angelo
User
User
Posts: 10
Joined: Tue Jul 09, 2013 10:23 am
Location: Berlin

Strange behaviour of combobox-gadget

Post by Angelo »

Using PB 5.40 the attached code is working fine.
For example:
1. When I type 'An', then 'Andrew' is displayed.
2. The following cursor down action leads to 'Anna'.
3. Finally, typing of the letter 'c' results in 'Carol'.
Great - everything is okay!

But using PB 5.50 or PB 5.60 instead produces a strange behaviour:
Steps 1. and 2. will show the same results as above. So far, so good. But step 3 - i. e. typing of 'c' - doesn't result in 'Carol'.

So, why this difference between 5.40 and 5.50/5.60? Is it because of unicode compilation?

Code: Select all

Declare ComboboxAutoComplete(WindowID, Message, wParam, lParam)

#window = 0
#combo = 0

Global index_auto ;will be changed in ComboxAutoComplete procedure

OpenWindow(#Window, 0, 0, 400, 200, "Combobox with AutoComplete",  #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)

ComboBoxGadget(#combo, 40, 40, 260, #Null, #PB_ComboBox_Editable | #CBS_NOINTEGRALHEIGHT)
MoveWindow_(GadgetID(#combo),GadgetX(#combo),GadgetY(#combo),GadgetWidth(#combo), 22, #True)

      AddGadgetItem(#combo, -1, "Albert")
      AddGadgetItem(#combo, -1, "Alexander")
      AddGadgetItem(#combo, -1, "Andrew")
      AddGadgetItem(#combo, -1, "Anna")
      AddGadgetItem(#combo, -1, "Bernie")
      AddGadgetItem(#combo, -1, "Bridget")
      AddGadgetItem(#combo, -1, "Carol")
      AddGadgetItem(#combo, -1, "Clair")   
   
SetActiveGadget(#combo)      
      
SetWindowCallback(@ComboboxAutoComplete())


Repeat
   
   event = WaitWindowEvent() 

   If event = #PB_Event_CloseWindow
      quit = #True
   EndIf


   If event = #PB_Event_Gadget      
      If EventGadget() = #combo
         
         If GetAsyncKeyState_(#VK_DOWN)
            ind = index_auto + 1
            SetGadgetState(#combo, ind)
            index_auto = ind
         EndIf
         If GetAsyncKeyState_(#VK_UP)
            ind = index_auto - 1
            If ind < 0
               ind = 0
            EndIf
            SetGadgetState(#combo, ind)
            index_auto = ind
         EndIf
         
      EndIf      
   EndIf         
      
Until quit = #True


Procedure ComboboxAutoComplete(WindowID, Message, wParam, lParam)

Protected result.l

Protected comboWert.s, comboLang.l, comboStart.l, parameter.l, start.l, ende.l
Static comboIndex.l 
                    
result = #PB_ProcessPureBasicEvents
 
Select Message
   ;Case #WM_PAINT
    Case #WM_COMMAND
      Select lParam
         Case GadgetID(#combo)
            Select (wParam >> 16 & $FFFF)
               Case #CBN_EDITUPDATE
                  If GetAsyncKeyState_(#VK_BACK) Or GetAsyncKeyState_(#VK_DELETE)
                     comboWert = GetGadgetText(#combo)
                     If comboIndex >= 0 
                        combowert = Left(comboWert, Len(combowert)-1)
                     EndIf
                  Else
                     comboWert = GetGadgetText(#combo)
                  EndIf
                     ;
                     comboIndex = SendMessage_(lParam, #CB_FINDSTRING, -1, @comboWert)
                     comboStart = Len(comboWert) ;length of typed text
                     If combostart = 0
                        SetGadgetText(#combo, "")
                     EndIf
                     ;
                     If comboIndex >= 0 ;there is a match
                        SendMessage_(lParam, #CB_SETCURSEL, comboIndex, 0)
                        comboLang = Len(GetGadgetText(#combo)) 
                        parameter = (comboLang << 16 & $FFFFFFFF) + comboStart
                        SendMessage_(lParam, #CB_SETEDITSEL, 0, parameter)
                        index_auto = GetGadgetState(#combo)
                     EndIf
            EndSelect
      EndSelect
EndSelect

ProcedureReturn result

EndProcedure
Last edited by Angelo on Tue Jul 04, 2017 12:27 pm, edited 1 time in total.
PB 5.60 - Windows 10
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Re: Strange bevaviour of combobox-gadget

Post by kpeters58 »

Hmm - this may be a philosophical question: Why would you expect the 'old' behavior? The current mode of operation is exactly what is commonly expected:

You type 'A' , get your first 'A' name, add an 'n', get what you expect (as you now had requested 'An'); then you add a 'c' which initiates a search for 'Anc' - clearly this should NOT find 'Carol'. For that, you'd have to erase the 'An' first and then type 'c'.....

Way more disconcerting is the fact that the combobox dropdown functionality seems to be broken; i.e., it is impossible to get a list of all present names by clicking on the dropdown arrow symbol.

Unless, of course, I somehow misinterpreted your post.
PB 5.73 on Windows 10 & OS X High Sierra
Angelo
User
User
Posts: 10
Joined: Tue Jul 09, 2013 10:23 am
Location: Berlin

Re: Strange bevaviour of combobox-gadget

Post by Angelo »

Hi KPeters, I should mention the following:
The combobox dropdown functionality is not broken, it is intentionally turned off by the code.
When you type 'An', then 'Andrew' is displayed and highlighted. So, I would expect the highlighted 'Andrew' to be replaced by C (the same procedure as in text editors), which itself will be "autocompleted" to 'Carol'. That's normal for me and is achieved by using PB 5.40.
PB 5.60 - Windows 10
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Strange bevaviour of combobox-gadget

Post by Dude »

kpeters58 wrote:Unless, of course, I somehow misinterpreted your post.
You have. He's asking why the behavior is different when the exact same code is compiled with 5.40 compared to 5.50/5.60.
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Re: Strange behaviour of combobox-gadget

Post by kpeters58 »

Ahh, I see that I overlooked the line stating that you used the cursor down key....

That does select the entire entry and the next keypress should replace your current search criteria as it apparently has in earlier PB versions. It seems that somehow the first key event after the cursor down gets "swallowed" - the 2nd 'c' press then does the trick.

Might be a new bug?
PB 5.73 on Windows 10 & OS X High Sierra
Angelo
User
User
Posts: 10
Joined: Tue Jul 09, 2013 10:23 am
Location: Berlin

Re: Strange behaviour of combobox-gadget

Post by Angelo »

I assume. It seems that the combobox gadget doesn't work correctly anymore starting with PB 5.50.
PB 5.60 - Windows 10
Post Reply