It is currently Sat Nov 25, 2017 3:02 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: ComboBox Drop-down Height
PostPosted: Fri Jul 14, 2017 1:31 am 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5688
Location: Wales, UK
So, found some code on the forum ( Drop Height ) that does have an effect on the combo drop-down height, but it is not accurate. Also, it does not work at all if the combo item height is set:
Code:
Enumeration
#Win
#Panel
#Scroll
#Container
#Container2
#Combo
EndEnumeration

LoadFont(iFont18.i, "Arial", 18)

If OpenWindow(#Win, 0, 0, 500, 400, "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

       SetWindowColor(#Win, RGB(255,200,255))
        SetGadgetFont(#PB_Default, FontID(iFont18))

          PanelGadget(#Panel, 5, 5, 490, 390)

                  AddGadgetItem(#Panel, 0, "Tab 0")

               ScrollAreaGadget(#Scroll, 5, 5, 470, 360, 600, 500, 20, #PB_ScrollArea_BorderLess)

                         ContainerGadget(#Container, 10, 10, 280, 80)

                                 SetGadgetColor(#Container, #PB_Gadget_BackColor, RGB(150,255,200))

                                 ComboBoxGadget(#Combo, 10, 10, 260, 50) ;, #CBS_NOINTEGRALHEIGHT)
                                   SendMessage_(GadgetID(#Combo), #CB_SETITEMHEIGHT, 0, 50)

                                    ;Max Combo drop-down height measured from Combo Y          ;w   ;h
                                    MoveWindow_(GetWindow_(GadgetID(#Combo), #GW_CHILD), 0, 0, 250, 250, #True)

                                 For a = 0 To 50

                                       AddGadgetItem(#Combo, -1,"ComboBox Item " + Str(a))
                                 Next

                                 SetGadgetState(#Combo, 0)

                         CloseGadgetList()

                         ContainerGadget(#Container2, 10, 100, 280, 240)
                          SetGadgetColor(#Container2, #PB_Gadget_BackColor, RGB(200,255,150))
                         CloseGadgetList()

                  CloseGadgetList()

                  AddGadgetItem(#Panel, 1, "Tab 1")

       CloseGadgetList()

           Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf


Using MoveWindow_ is of course a work-around. Perhaps it worked better on XP than it does on Win7.

Any ideas? I think I may need to go back to PlanB and use a toolwindow-button-ListIcon combination........

Edit: Snippet was missing CloseGadgetList() for the ScrollArea gadget :oops:

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Last edited by IdeasVacuum on Fri Jul 14, 2017 1:57 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: ComboBox Drop-down Height
PostPosted: Fri Jul 14, 2017 12:50 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Jul 21, 2006 4:41 am
Posts: 2336
Location: Berlin, Germany
You forgot to set the style flag:
Code:
#CBS_NOINTEGRALHEIGHT

_________________
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?


Top
 Profile  
Reply with quote  
 Post subject: Re: ComboBox Drop-down Height
PostPosted: Fri Jul 14, 2017 1:38 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5688
Location: Wales, UK
I had already tried that flag - the result is a 1-row drop down, I want to have a drop down where the height max does not take it outside of the parent window, but not unnecessarily short.

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: ComboBox Drop-down Height
PostPosted: Fri Jul 14, 2017 2:07 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5688
Location: Wales, UK
Another issue is that when the height of the combo button is increased, the text is not centered vertically:
Code:
ComboBoxGadget(#Combo, 10, 10, 260, 60)

Image
Too ugly!

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: ComboBox Drop-down Height
PostPosted: Fri Jul 14, 2017 2:33 pm 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 2848
Hi
Code:
Enumeration
#Win
#Panel
#Scroll
#Container
#Container2
#Combo
EndEnumeration

Global Text$,Brush,Brush_2

Text$ = Space(#MAX_PATH)
LoadFont(iFont18.i, "Arial", 18)

Brush = CreateSolidBrush_($FADC72)
Brush_2 = CreateSolidBrush_($99FEFA)

Procedure WndProc(hWnd, uMsg, wParam, lParam)
  Result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_DRAWITEM
      *DRAWITEM.DRAWITEMSTRUCT = lParam       
      If *DRAWITEM\CtlType = #ODT_COMBOBOX
        SetBkMode_(*DRAWITEM\hDC, #TRANSPARENT)
        If *DRAWITEM\ItemState & #ODS_FOCUS
          FillRect_(*DRAWITEM\hDC,*DRAWITEM\rcItem,Brush)
        Else
          FillRect_(*DRAWITEM\hDC,*DRAWITEM\rcItem,Brush_2)
        EndIf
        SendMessage_(*DRAWITEM\hwndItem,#CB_GETLBTEXT,*DRAWITEM\itemID, @Text$)
          SetTextColor_(*DRAWITEM\hDC, $0)
          *DRAWITEM\rcItem\left = 8
          DrawText_(*DRAWITEM\hDC,@Text$,Len(Text$),*DRAWITEM\rcItem,  #DT_SINGLELINE | #DT_VCENTER )
      EndIf 
  EndSelect 
  ProcedureReturn Result
EndProcedure

If OpenWindow(#Win, 0, 0, 500, 400, "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)   
       SetWindowCallback(@WndProc())
       SetWindowColor(#Win, RGB(255,200,255))
        SetGadgetFont(#PB_Default, FontID(iFont18))

          PanelGadget(#Panel, 5, 5, 490, 390)

                  AddGadgetItem(#Panel, 0, "Tab 0")

               ScrollAreaGadget(#Scroll, 5, 5, 480, 390, 600, 500, 20, #PB_ScrollArea_BorderLess)

                ContainerGadget(#Container, 10, 10, 280, 80)

                        SetGadgetColor(#Container, #PB_Gadget_BackColor, RGB(150,255,200))

                        ComboBoxGadget(#Combo, 10, 10, 260, 50,#CBS_OWNERDRAWFIXED|#CBS_HASSTRINGS|#CBS_NOINTEGRALHEIGHT)
                          SendMessage_(GadgetID(#Combo), #CB_SETITEMHEIGHT, 0, 50)
                          dLh = FindWindow_("ComboLBox",0)
                          MoveWindow_(dlh , 0, 0, 250, 250, #True)                       

                        For a = 0 To 50
                              AddGadgetItem(#Combo, -1,"ComboBox Item " + Str(a))
                        Next

                        SetGadgetState(#Combo, 0)                       

                CloseGadgetList()

                ContainerGadget(#Container2, 10, 100, 280, 235)
                 SetGadgetColor(#Container2, #PB_Gadget_BackColor, RGB(200,255,150))
                CloseGadgetList()
                OpenGadgetList(#Panel)
                  AddGadgetItem(#Panel, 1, "Tab 1")

       CloseGadgetList()

  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: ComboBox Drop-down Height
PostPosted: Fri Jul 14, 2017 2:35 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Jul 21, 2006 4:41 am
Posts: 2336
Location: Berlin, Germany
IdeasVacuum wrote:
I had already tried that flag - the result is a 1-row drop down

Which is correct since this returns zero:

Code:
GetWindow_(GadgetID(#Combo), #GW_CHILD)

_________________
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?


Top
 Profile  
Reply with quote  
 Post subject: Re: ComboBox Drop-down Height
PostPosted: Fri Jul 14, 2017 7:14 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5688
Location: Wales, UK
It seems the need for containers within containers can potentially have an adverse affect on standard controls, but this is only witnessed when there are a lot of controls.

Rashad, what you have beautifully coded there is exactly how I want the combos to work and how I have defined a 'hand made' effort. My alternative design is a bit heavy, it needs 4 gadgets and a border-less window, but does not need Win API. I'm trying to keep the use of API to a minimum so that producing code for Android, via Spider Basic, is easier. So, decisions decisions.........

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: ComboBox Drop-down Height
PostPosted: Fri Jul 14, 2017 8:57 pm 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 2848
Hi IdeasVacuum
Next is a hand made combo
The CanvasGadget() is very flexible you can adapt it for your needs
Good luck

Code:
  LoadFont(0,"Tahoma",12)
 
  If OpenWindow(0, 0, 0, 270, 305, "ListViewGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ContainerGadget(0,10,10,250,30,#PB_Container_Flat)
    SetGadgetColor(0,#PB_Gadget_BackColor,$BEFEBC)
      TextGadget(1,5,3,200,20,"ComboBox Item " + Str(1))
      SetGadgetColor(1,#PB_Gadget_BackColor,$BEFEBC)
      SetGadgetFont(1,FontID(0))
      ButtonGadget(2,220,-1,30,30,"Y")
    CloseGadgetList()
    ScrollAreaGadget(5,10,40,250,250,230,500,10,#PB_ScrollArea_Flat)
      CanvasGadget(6,0,0,250,500,#PB_Canvas_Container)
    CloseGadgetList()
    StartDrawing(CanvasOutput(6))
      Box(0,0,250,500,$BBF0FE)
      DrawingFont(FontID(0))
      DrawingMode(#PB_2DDrawing_Transparent )
      DrawText(2,2,"ComboBox Item " + Str(1),$FE2D30)
      DrawText(2,28,"ComboBox Item " + Str(2),$FE2D30)
    StopDrawing()
    HideGadget(5,1)

    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Quit = 1
         
        Case #PB_Event_Gadget
          Select EventGadget()
            Case 2
              Run ! 1
              If Run = 1
                HideGadget(5,0)
              Else
                HideGadget(5,1)
              EndIf
             
            Case 6           
              Select EventType()
                Case #PB_EventType_MouseMove
                    my = GetGadgetAttribute(6, #PB_Canvas_MouseY)
                    If my > 24 And my < 44 And over = 0
                      StartDrawing(CanvasOutput(6))
                        Box(0,24,250,30,$BBF0FE)
                        DrawingMode(#PB_2DDrawing_Transparent )
                        DrawingFont(FontID(0))
                        DrawText(2,28,"ComboBox Item " + Str(2),$FE2D30)
                        DrawingMode(#PB_2DDrawing_AlphaBlend )
                        Box(0,24,250,30,$60FF0000)
                      StopDrawing()
                    Else
                      StartDrawing(CanvasOutput(6))
                        Box(0,24,250,30,$BBF0FE)
                        DrawingMode(#PB_2DDrawing_Transparent )
                        DrawingFont(FontID(0))
                        DrawText(2,28,"ComboBox Item " + Str(2),$FE2D30)
                      StopDrawing()
                    EndIf
                  ;You can know exactly the what item under the cursor even with the scroll bar moved
              EndSelect
          EndSelect
      EndSelect
    Until Quit = 1
  EndIf


Edit : Step forward

_________________
Egypt my love


Last edited by RASHAD on Fri Jul 14, 2017 11:20 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: ComboBox Drop-down Height
PostPosted: Fri Jul 14, 2017 9:54 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5688
Location: Wales, UK
Hi Rashad

That's interesting code but if using a ScrollAreaGadget works, there is no need to use a Canvas, it can host a ListIcon. The reason I use a Window is that you can guarantee it will always be topmost Z level (StickyWindow), whereas I have found using a Container sometimes works, sometimes doesn't when it has to be on top of other gadgets -so to guarantee it is always on top the other gadgets need to be temporarily hidden. If the solution is for just one hand-made combo, either method is good, but for several combos on several tabs, the Window drop-down has an advantage in that it can be recycled.

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: ComboBox Drop-down Height
PostPosted: Fri Jul 14, 2017 10:18 pm 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 2848
I still advice using the CanvasGadget() more than any other Gadget()
It will be more code to use
But
- You can use more than one font per list
- You can justify the text left-center-right
- you can design the height of any row as you like
- And more and more without any Windows API
Just tuck up your sleeve and dive in :mrgreen:

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: ComboBox Drop-down Height
PostPosted: Fri Jul 14, 2017 10:22 pm 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1462
Location: Uttoxeter, UK
@RASHAD,
Very nice example, as usual.
I'll have to take a close look at it.
Thank you for sharing. :D

_________________
DE AA EB


Top
 Profile  
Reply with quote  
 Post subject: Re: ComboBox Drop-down Height
PostPosted: Fri Jul 14, 2017 10:28 pm 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 2848
Hi davido
You just trapped in mate :P
You have to roll up your sleeve and finish the exam. :mrgreen:

Previous post updated

_________________
Egypt my love


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye