Page 1 of 1

Strange behaviour of combobox-gadget

Posted: Wed Jun 28, 2017 3:16 pm
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

Re: Strange bevaviour of combobox-gadget

Posted: Wed Jun 28, 2017 5:25 pm
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.

Re: Strange bevaviour of combobox-gadget

Posted: Wed Jun 28, 2017 6:35 pm
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.

Re: Strange bevaviour of combobox-gadget

Posted: Thu Jun 29, 2017 12:02 am
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.

Re: Strange behaviour of combobox-gadget

Posted: Tue Jul 04, 2017 9:45 pm
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?

Re: Strange behaviour of combobox-gadget

Posted: Wed Jul 05, 2017 11:57 am
by Angelo
I assume. It seems that the combobox gadget doesn't work correctly anymore starting with PB 5.50.