Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing Line Spacing in ListBox
#1
Hi Gintaras,
I am loving 2.3.3.0 - stable and love being able to preload complex dialogs in the background flag 128 and bringing them forward immediately with act - huge difference for user!!!!
Quick question (I think): I want to increase the font on my listbox but when it gets more than 10 bold in Arial, the lines start clipping. How can I increase the line spacing as well?

Function SeriesPicker_MR_Brain_MonB
Code:
Copy      Help
,,__Font-- f
,,f.Create("Arial" 10 1)
,,f.SetDialogFont(hDlg "9")

I found this on the web but don't know how to convert it to QM:

http://social.msdn.microsoft.com/Forums ... 19939092a/

Thanks!!!,
Stuart


ps - I also am loving: DT_ChangeMouseControlSize and
this little bit of code from listbox tooltips is flexibile for a lot of other cool interactions I am using with LB's
Function SeriesPicker_MR_Brain_MonB
Code:
Copy      Help
,case WM_SETCURSOR
,,if GetDlgCtrlID(wParam)=9
,,,SendMessage id(9 hDlg) LB_SELITEMRANGE 0 100;;deselects all in  LB
,,,POINT p; xm p wParam 1
,,,_i=SendMessage(wParam LB_ITEMFROMPOINT 0 MakeInt(p.x p.y))
,,,out _i
,,,LB_SelectItem id(9 hDlg) _i 1;err

I use it in conjunction with WaitforKeyOrMouse also for a right click Drag-Pulldown release detector:

Function PickerDlg
Code:
Copy      Help
,case WM_SETCURSOR
,,if GetDlgCtrlID(wParam)=9
,,,SendMessage id(9 hDlg) LB_SELITEMRANGE 0 100;;deselects all in  LB
,,,POINT p; xm p wParam 1
,,,_i=SendMessage(wParam LB_ITEMFROMPOINT 0 MakeInt(p.x p.y))
,,,out _i
,,,LB_SelectItem id(9 hDlg) _i 1;err
,,,int+ SelectedLbSeries = _i
,,,mac "RtCliCkReleaseTest"


Function RtCliCkReleaseTest
Code:
Copy      Help
if WaitForKeyOrMouse(1) = 517;;RMB up
,lef





thanks again!
#2
Line height should be automatic.
On my PC this works without vertical clipping.
Function Dialog95
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str lb3
lb3="Aaaaaaaaaaaa[]Yyyyyyyyyyy"
if(!ShowDialog("Dialog95" &Dialog95 &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 ListBox 0x54230101 0x200 6 8 96 48 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030300 "*" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,__Font-- f
,f.Create("Arial" 20 1)
,f.SetDialogFont(hDlg "3")
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#3
thanks for responding: I see now that the reason I am getting the conflict is because I have the LBS_HASSTRINGS styles set to allow CB_ItemColor to work. When I turn this off, the clipping is gone but the color is lost.
Anyway solution?
Thanks, Stuart
#4
Add this code in CB_ItemColor after sel message:
Code:
Copy      Help
,case WM_MEASUREITEM
,if(wParam=ctrlId)
,,MEASUREITEMSTRUCT& mi=+lParam
,,int hlb=id(ctrlId hDlg 1)
,,int ih=GetProp(hlb "lbItemHeight")
,,if !ih
,,,int dc=GetDC(hlb); int of=SelectObject(dc SendMessage(hlb WM_GETFONT 0 0))
,,,RECT _r; DrawText dc "J" 1 &_r DT_CALCRECT; ih=_r.bottom
,,,SetProp hlb "lbItemHeight" ih
,,,SelectObject dc of; ReleaseDC hlb dc
,,mi.itemHeight=ih+4
,

Remove style LBS_OWNERDRAWFIXED and add LBS_OWNERDRAWVARIABLE.

Add items in dialog procedure, not before ShowDialog. Example:
Function Dialog95
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str lb3
;lb3="yellow background[]blue text"
if(!ShowDialog("Dialog95" &Dialog95 &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 ListBox 0x54230161 0x200 6 8 96 48 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030300 "*" "" ""

ret
;messages

CB_ItemColor hDlg message wParam lParam 3 &SampleCbItemColorProc

sel message
,case WM_INITDIALOG
,;create and set font
,__Font-- f
,f.Create("Arial" 12 1)
,f.SetDialogFont(hDlg "3")
,;add items
,int hlb=id(3 hDlg)
,LB_Add hlb "yellow background"
,LB_Add hlb "blue text"
,,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#5
I am in awe!!!!! Thanks so much. Incredible as always, Gintaras!!
S
#6
This works great when I specify the size within the dialog but if I use an external LB filling function in which I change the font size depending on the # of items, I just get a change in height but not a change in font size. Maybe something to do with the scope of the font variable -/-- ?
Still playing around with it.
Stuart
#7
Add this in CB_ItemColor:
Code:
Copy      Help
,case WM_APP+140
,RemoveProp id(ctrlId hDlg 1) "lbItemHeight"
,

When need to change item height:
1. Create/set font of new height.
2. Send WM_APP+140 message to hDlg. It resets font size caching.
3. Delete all items and add again.

Example:
Function Dialog95
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str lb3
;lb3="yellow background[]blue text"
if(!ShowDialog("Dialog95" &Dialog95 &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 ListBox 0x54230161 0x200 6 8 96 48 ""
;4 Button 0x54032000 0x0 8 74 70 12 "Change height"
;END DIALOG
;DIALOG EDITOR: "" 0x2030300 "*" "" ""

ret
;messages

CB_ItemColor hDlg message wParam lParam 3 &SampleCbItemColorProc

sel message
,case WM_INITDIALOG
,;create and set font
,__Font-- f
,f.Create("Arial" 12 1)
,f.SetDialogFont(hDlg "3")
,;add items
,int hlb=id(3 hDlg)
,LB_Add hlb "yellow background"
,LB_Add hlb "blue text"
,,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 4
,f.Create("Arial" 18 1)
,f.SetDialogFont(hDlg "3")
,SendMessage hDlg WM_APP+140 0 0
,hlb=id(3 hDlg)
,SendMessage hlb LB_RESETCONTENT 0 0
,LB_Add hlb "yellow background"
,LB_Add hlb "blue text"
,
,case IDCANCEL
ret 1
#8
oh that's so great!!
thanks again,.

S
#9
thanks again for helping me on this.
I can't seem to make it work in the way my functions are set up.
I am trying to do the font change from a separate function.
It doesn't seem to work. I keep on getting the right line spacing but not the font size. I think it may have to do with the scope of the font variable (--) but not sure.
Are there any such issues that you could think explain this?
Thanks,
Stuart
#10
How with __Font+ ?
#11
some weird behaviors that may help in finding a solution:
the separate function that refills the LB after changing the font, etc - it will sometimes work once after being triggered by the calling dialog, and then on subsequent times fails to set the font size. If I manually click on the LB-setting function, it does change the font but as soon as a series is selected via code below from calling dialog (see below), it immediately reverts back to a small font (leaving wider spacing intact).

I hope this helps!
Stuart

Function SeriesPicker_MR_Brain_MonA
Code:
Copy      Help
,case WM_SETCURSOR
,,if GetDlgCtrlID(wParam)=9
,,,SendMessage id(9 hDlg) LB_SELITEMRANGE 0 100;;deselects all in  LB
,,,POINT p; xm p wParam 1
,,,_i=SendMessage(wParam LB_ITEMFROMPOINT 0 MakeInt(p.x p.y))
,,,out _i
,,,LB_SelectItem id(9 hDlg) _i 0;err
#12
changed scope of font variable from -- to +
All works perfectly now!!! Thanks Stuart
#13
I would use __Font--. If need to change font from other thread, use SendMessage WM_APP+X. In dialog procedure add case WM_APP+X, and change font there.

Function Dialog95
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str lb3
;lb3="yellow background[]blue text"
if(!ShowDialog("Dialog95" &Dialog95 &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 ListBox 0x54230161 0x200 6 8 96 48 ""
;4 Button 0x54032000 0x0 8 74 70 12 "Change height"
;END DIALOG
;DIALOG EDITOR: "" 0x2030300 "*" "" ""

ret
;messages

CB_ItemColor hDlg message wParam lParam 3 &SampleCbItemColorProc

sel message
,case WM_INITDIALOG
,;create and set font
,__Font-- f
,f.Create("Arial" 12 1)
,f.SetDialogFont(hDlg "3")
,;add items
,int hlb=id(3 hDlg)
,LB_Add hlb "yellow background"
,LB_Add hlb "blue text"
,
,case WM_APP+5
,goto g1
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 4
,;g1
,f.Create("Arial" 18 1)
,f.SetDialogFont(hDlg "3")
,SendMessage hDlg WM_APP+140 0 0
,hlb=id(3 hDlg)
,SendMessage hlb LB_RESETCONTENT 0 0
,LB_Add hlb "yellow background"
,LB_Add hlb "blue text"
,
,case IDCANCEL
ret 1

other thread
Macro Macro1543
Code:
Copy      Help
SendMessage win("Dialog") WM_APP+5 0 0


Forum Jump:


Users browsing this thread: 1 Guest(s)