Page 1 of 1

Little trouble [solved]

Posted: Fri May 01, 2020 4:30 pm
by ZX80
Hi to all.

Below is the simple code that shows the problem. It does not always occur, but often. This is not critical, but only a cosmetic effect. However, it is annoying. I decided to duplicate mouse actions so that I could select items using the keyboard.

So... run the code several times(F5 in IDE again and again) to catch the problem.

After starting, press the <Tab> key once to shift focus to combo1. Right after that, press <Enter> to expand combo1. Now you can see that selected row is not equal to the first element. The same goes for combo2. Why? Prior to this, on lines # 24 and # 29, I forced the first element to be set as active.

I also tried to fix it with API, but did not give a positive result. How to fix it? Please, help me.

Code: Select all

Procedure.s OpenChildWindow()
  Protected Ret.s = ""
  Protected Exit
  
  Child_Wnd = OpenWindow(0, 0, 0, 300, 200, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  If Child_Wnd
    TextGadget(1, 10, 15, 70, 20, "Str #1:")
    TextGadget(2, 10, 50, 70, 20, "Str #2:")
    
    cb1 = ComboBoxGadget(4, 90, 13, 200, 25)
    cb2 = ComboBoxGadget(5, 90, 48, 200, 25)
    EditorGadget(6, 10, 85, 280, 80, #PB_Editor_ReadOnly)
    
    btn = ButtonGadget(8, 210, 170, 80, 25, "Ok")
    AddKeyboardShortcut(0, #PB_Shortcut_Return, 100)
    SetForegroundWindow_(Child_Wnd)
    
    AddGadgetItem(4, -1, "Alfa")
    AddGadgetItem(4, -1, "Bravo") 
    AddGadgetItem(4, -1, "Charlie")
    AddGadgetItem(4, -1, "Delta")
    AddGadgetItem(4, -1, "Echo")
    AddGadgetItem(4, -1, "Foxtrot")
    SetGadgetState(4, 0)
    
    For i=0 To 15
      AddGadgetItem(5, -1, Str(i))
    Next i
    SetGadgetState(5, 0)
    SetActiveGadget(-1)
    
   Repeat
      Event  = WaitWindowEvent()
      Window = EventWindow()
      
      If Window = 0
        If Event = #PB_Event_CloseWindow
          RemoveKeyboardShortcut(0, #PB_Shortcut_Return)
          Exit = #True
 
        ElseIf Event = #PB_Event_Menu
          Select EventMenu()
            Case 100
              ag = GetActiveGadget()
              If ag = 4
                If SendMessage_(cb1, #CB_GETDROPPEDSTATE, 0, 0)
                  SendMessage_(cb1, #CB_SHOWDROPDOWN, 0, 0)
                Else
                  SendMessage_(cb1, #CB_SHOWDROPDOWN, 1, 0)
                EndIf
              ElseIf ag = 5
                If SendMessage_(cb2, #CB_GETDROPPEDSTATE, 0, 0)
                  SendMessage_(cb2, #CB_SHOWDROPDOWN, 0, 0)
                Else
                  SendMessage_(cb2, #CB_SHOWDROPDOWN, 1, 0)
                EndIf
              EndIf
          EndSelect
          
        ElseIf Event = #PB_Event_Gadget
          Gadget = EventGadget()
          If Gadget = 4
           
          ElseIf Gadget = 5
            
          ElseIf Gadget = 8
            
          EndIf
        EndIf
      EndIf
    Until Exit
    CloseWindow(0)
    ProcedureReturn Ret
  EndIf
EndProcedure

OpenChildWindow()

Re: Little trouble

Posted: Fri May 01, 2020 4:44 pm
by ZX80
I remember that in earlier versions of PB the main loop for the window should have been outside the procedures. And only in the main thread. But I also saw fresh examples where the loop was inside the procedure.
And one cycle for all windows. One event (WaitWindowEvent()). Therefore you can see the following check:

Code: Select all

...
Window = EventWindow()
If Window = 0
...

Re: Little trouble

Posted: Fri May 01, 2020 5:03 pm
by ZX80
I understood!
Forgive me for being stupid. The fact is that every time I start the program, I have to click on the confirmation button in the window from the firewall. It is also located in the center of the screen. It turns out that the mouse cursor is often somewhere in the range of 3-5 items (combo1). And since I open combo1 by pressing a hot key, the mouse cursor remains in place. And therefore, the active element changes in accordance with the position of the cursor. Everything is logical! Sorry for the panic. So you need to remove the cursor above before opening combo by hotkey. Somewhere to the level of the first element.

Re: Little trouble [solved]

Posted: Fri May 01, 2020 6:43 pm
by mk-soft
Windows standard, open combobox.

Key Alt+Down :wink:

Re: Little trouble [solved]

Posted: Fri May 01, 2020 7:32 pm
by IdeasVacuum
Talking to yourself zx80 :mrgreen: (all the best developers do)

Re: Little trouble [solved]

Posted: Sat May 02, 2020 6:50 pm
by ZX80
mk-soft and IdeasVacuum

Thank you very much for your answers. I'm really glad to see you.

mk-soft
Windows standard, open combobox.
Key Alt+Down
Thanks, but I wanted to do this with the <Enter> key. For convenience.
Talking to yourself
Yes, it was thinking out loud. I was looking for a solution. Sorry for several posts in a row.

Unfortunately, I am very far from you (about experience), at the foot of the mountain. So I often look at your codes and tips for other members. If I do something, it will be the invention of a crooked wheel. Yes it is valuable, but often wrong. For this reason, I am here to see how professionals do it. Beautiful and fast codes.

I wasted my time (all day). It was difficult for me to find the reason, because it did not always appear (random). And my biggest mistake is inattention. I didn’t even think about the mouse. Did not pay attention. It turns out in vain. And yes, the eyes need a rest.

Another big barrier is language. I do not want to offend anyone or show disrespect. Sorry for my bad english. I liked the signature of NicTheQuick:
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
I agree with that. As if he says about me. :oops:

OK. Leave the lyric. I will have another question for infratec. The fundamental thing. But I will ask tomorrow. Already very late. And if he asks for something (details), but I do not answer, then it will be bad. I need this, but not for him. Therefore, he may lose interest. And then this issue will remain unresolved. In summary, I try not to bother the professionals. To have a quota for more important and serious issues.

Thanks again.

P.S.
If this helps someone, so as not to step on the rake that I stepped on, then I want to publish my solution here.

Code: Select all

#CCHILDREN_TITLEBAR = 5

Structure TITLEBARINFO
  cbSize.l
  rcTitleBar.RECT
  rgstate.l[#CCHILDREN_TITLEBAR+1]
EndStructure

Global pti.TITLEBARINFO\cbSize = SizeOf(TITLEBARINFO)
Global cur0 = LoadCursor_(0, #IDC_ARROW)


Procedure.s OpenChildWindow()
  Protected Ret.s = ""
  Protected Exit
  
  Child_Wnd = OpenWindow(0, 0, 0, 300, 200, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  If Child_Wnd
    TextGadget(1, 10, 15, 70, 20, "Str #1:")
    TextGadget(2, 10, 50, 70, 20, "Str #2:")
    
    cb1 = ComboBoxGadget(4, 90, 13, 200, 25)
    cb2 = ComboBoxGadget(5, 90, 48, 200, 25)
    EditorGadget(6, 10, 85, 280, 80, #PB_Editor_ReadOnly)
    
    btn = ButtonGadget(8, 210, 170, 80, 25, "Ok")
    AddKeyboardShortcut(0, #PB_Shortcut_Return, 100)
    SetForegroundWindow_(Child_Wnd)
    
    GetTitleBarInfo_(Child_Wnd, pti)
    TitleHeight = pti\rcTitleBar\bottom-pti\rcTitleBar\top
    
    xpos = WindowX(0)
    ypos = WindowY(0)
      
    mx1 = xpos + GadgetX(4, #PB_Gadget_WindowCoordinate) + GadgetWidth(4, #PB_Gadget_ActualSize) - 10
    my1 = ypos + GadgetY(4, #PB_Gadget_WindowCoordinate) + TitleHeight + (GadgetHeight(4, #PB_Gadget_ActualSize)/2)
    mx2 = xpos + GadgetX(5, #PB_Gadget_WindowCoordinate) + GadgetWidth(5, #PB_Gadget_ActualSize) - 10
    my2 = ypos + GadgetY(5, #PB_Gadget_WindowCoordinate) + TitleHeight + (GadgetHeight(5, #PB_Gadget_ActualSize)/2)
    
    AddGadgetItem(4, -1, "Alfa")
    AddGadgetItem(4, -1, "Bravo")
    AddGadgetItem(4, -1, "Charlie")
    AddGadgetItem(4, -1, "Delta")
    AddGadgetItem(4, -1, "Echo")
    AddGadgetItem(4, -1, "Foxtrot")
    SetGadgetState(4, 0)
    
    For i=0 To 15
      AddGadgetItem(5, -1, Str(i))
    Next i
    SetGadgetState(5, 0)
    SetActiveGadget(-1)
    
   Repeat
      Event  = WaitWindowEvent()
      Window = EventWindow()
      
      If Window = 0
        If Event = #PB_Event_CloseWindow
          RemoveKeyboardShortcut(0, #PB_Shortcut_Return)
          DestroyCursor_(cur0)
          Exit = #True
 
        ElseIf Event = #PB_Event_Menu
          Select EventMenu()
            Case 100
              ag = GetActiveGadget()
              If ag = 4
                If SendMessage_(cb1, #CB_GETDROPPEDSTATE, 0, 0)
                  SendMessage_(cb1, #CB_SHOWDROPDOWN, 0, 0)
                Else
                  SetCursor_(cur0)
                  SetCursorPos_(mx1, my1)
                  SendMessage_(cb1, #CB_SHOWDROPDOWN, 1, 0)
                EndIf
              ElseIf ag = 5
                If SendMessage_(cb2, #CB_GETDROPPEDSTATE, 0, 0)
                  SendMessage_(cb2, #CB_SHOWDROPDOWN, 0, 0)
                Else
                  SetCursor_(cur0)
                  SetCursorPos_(mx2, my2)
                  SendMessage_(cb2, #CB_SHOWDROPDOWN, 1, 0)
                EndIf
              EndIf
          EndSelect
          
        ElseIf Event = #PB_Event_Gadget
          Gadget = EventGadget()
          If Gadget = 4
           
          ElseIf Gadget = 5
            
          ElseIf Gadget = 8
            
          EndIf
        EndIf
      EndIf
    Until Exit
    CloseWindow(0)
    ProcedureReturn Ret
  EndIf
EndProcedure

OpenChildWindow()
Good luck!

Re: Little trouble [solved]

Posted: Sun May 03, 2020 1:13 am
by Olliv
@ZX80

Without wanting...* question you, I wish you to try and test a tip I coded here.

This could be interesting for you.
But it is very interesting for me to know if I must adapt the code for such these types of problems.

(*) : 3 dots mean I need Google Translate.

Re: Little trouble [solved]

Posted: Wed May 06, 2020 11:39 am
by ZX80
Olliv

Thanks. Not needed. Sorry.

Re: Little trouble [solved]

Posted: Wed May 06, 2020 9:38 pm
by Olliv
Thank you for having tested !

Re: Little trouble [solved]

Posted: Fri May 08, 2020 11:26 am
by ZX80
Hello everyone!

I did not find one simple thing in the PB IDE. Maybe I'm inattentive?

Essence: In older versions of MS Office in the main menu "File" was item "Properties" (If my memory serves me). Is it possible to add the same thing to PB IDE? So I can see where my source code is located (for active tab). Now I can see only list of recently opened files. And that’s all. This is necessary if several source codes have same names, but are located in different directories. Now I'm looking for file modification time (timestamp in Total Commander). Then I can determine which file was edited (most fresh version).

So... this is a bit uncomfortable.


Thank you for attention.