Posts: 135
Threads: 33
Joined: Aug 2009
Hi Gintaras and all QM fellows!
I'm using the grid for showing data from several arrays. They have different sizes so I wonder how to change dialog/grid size at run time? Bigger with more rows&columns and smaller with less r&c.
Posts: 135
Threads: 33
Joined: Aug 2009
Something more elegant than:
Macro Macro262
str xx=
;BEGIN DIALOG
;0 "" 0x10C80A44 0x100 0 0 400 300 "Data"
;3 QM_Grid 0x54030000 0x0 0 0 XXX YYY ""
;...
str dd=xx
dd.findreplace("XXX" "309")
dd.findreplace("YYY" "250")
if(!ShowDialog(dd 0 &controls 0 2)) ret
Posts: 12,090
Threads: 142
Joined: Dec 2002
Macro Macro2105
int w=309
int h=250
str dd=
F
;BEGIN DIALOG
;0 "" 0x10C80A44 0x100 0 0 400 300 "Data"
;3 QM_Grid 0x54030000 0x0 0 0 {w} {h} ""
;...
if(!ShowDialog(dd 0 &controls 0 2)) ret
However then cannot edit in dialog editor.
Better use regular expression.
Function Dialog127
\Dialog_Editor
int w=309
int h=250
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;3 QM_Grid 0x56031041 0x200 8 8 96 48 "0x0,0,0,0,0x0[]A,,,[]B,,,"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2030507 "*" "" "" ""
if(dd.replacerx("^(3 \w+ \w+ \w+ \w+ \w+) \d+ \d+" F"$1 {w} {h}" 4|8)<=0) end "rx failed"
str controls = "3"
str qmg3x
if(!ShowDialog(dd 0 &controls)) ret
Or in dialog procedure (smart dialog) resize under case WM_INITDIALOG.
In dialog definition are used dialog units - depends on font size. In dialog procedure would need to use pixels.
Posts: 135
Threads: 33
Joined: Aug 2009
Thanks for your help.
The dialog function always uses the parameters: hDlg message wParam lParam
since ShowDialog: ShowDialog(dd &DynamicGrid
In order to pass coordinates x,y to my grid I used wParam lParam
but how to pass different CSV (data arrays)?
Example:
DynamicGrid 0 0 200 105 CSV1
And another question, please: ColumnsAdd is for column labels, is there any command for row labels? I used the trick of column=0
Regards.
Function DynamicGrid
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
int Dlgw Dlgh Gridw Gridh OKx OKy Cancelx Cancely
Dlgw=wParam
Dlgh=lParam
Gridw=Dlgw+1
Gridh=Dlgh-21
OKx=Dlgw/2-55
OKy=Gridh+2
Cancelx=Dlgw/2-5
Cancely=Gridh+2
str dd=
F
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 {Dlgw} {Dlgh} "Stats in detail"
;3 QM_Grid 0x54030000 0x0 0 0 {Gridw} {Gridh} ""
;1 Button 0x54030001 0x4 {OKx} {OKy} 48 14 "OK"
;2 Button 0x54030000 0x4 {Cancelx} {Cancely} 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2030202 "" "" ""
if(!ShowDialog(dd &DynamicGrid 0 0 0 0 0 0 0 0 "")) ret
ret
;messages
DlgGrid g.Init(hDlg 3)
sel message
,case WM_INITDIALOG
,g.GridStyleSet(GRID.QG_NOEDIT)
,g.ColumnsAdd("[]A[]B[]C[]D" 1)
,g.ColumnsWidthAdjust(5);; n columns=5
,
,_s=
,;A,1,2,3,88
,;B,4,5,6,89
,;C,7,8,9,99
,;D,10,11,12,6.77
,g.FromCsv(_s ",")
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
ret 1
Macro Use DynamicGrid
DynamicGrid 0 0 200 105
DynamicGrid 0 0 351 135
DynamicGrid 0 0 651 235
Posts: 12,090
Threads: 142
Joined: Dec 2002
Macro Macro2109
_s=
;A,1,2,3,88
;B,4,5,6,89
;C,7,8,9,99
;D,10,11,12,6.77
DynamicGrid 200 105 _s
Function DynamicGrid
;/Dialog_Editor
function Dlgw Dlgh $gridCSV
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 200 119 "Stats in detail"
;3 QM_Grid 0x54030000 0x0 0 0 200 94 "0x10,0,0,0,0x0[]'' '',,,[]A,,,[]B,,,[]C,,,[]D,,,"
;1 Button 0x54030001 0x0 98 102 48 14 "OK"
;2 Button 0x54030000 0x0 150 102 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2030507 "" "" "" ""
DialogDefinitionReplace 2 dd 0 Dlgw Dlgh
DialogDefinitionReplace 2 dd 3 Dlgw+1 Dlgh-21
DialogDefinitionReplace 1 dd 1 Dlgw/2-55 Dlgh-19
DialogDefinitionReplace 1 dd 2 Dlgw/2-5 Dlgh-19
str controls = "3"
str qmg3x
qmg3x=gridCSV
if(!ShowDialog(dd &DynamicGrid_dialog &controls)) ret
Function DynamicGrid_dialog
;/
function# hDlg message wParam lParam
if(hDlg) goto messages
ret
;messages
DlgGrid g.Init(hDlg 3)
sel message
,case WM_INITDIALOG
,g.ColumnsWidthAdjust(5);; n columns=5
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
ret 1
Function DialogDefinitionReplace
;/
function what str&dd ctrlID v1 v2 ;;what: 0 style/exstyle, 1 x/y, 2 width/height
;Replaces two numeric values in dialog definition string.
;dd - variable containing dialog definition (BEGIN DIALOG...END DIALOG).
;ctrlID - control id, or 0 for dialog. It's the first number in a line.
;v1, v2 - new values. Coordinates are in dialog units.
str rx
sel what
,case 0 rx=F"^({ctrlID} .+?) 0x\w+ \w+"
,case 1 rx=F"^({ctrlID} .+? 0x\w+ \w+) \d+ \d+"
,case 2 rx=F"^({ctrlID} .+? 0x\w+ \w+ \w+ \w+) \d+ \d+"
,case else end ERR_BADARG
if(dd.replacerx(rx F"$1 {v1} {v2}" 4|8)<=0) end ERR_FAILED
QM grid control does not have row labels. Use first column, like now. In editable grid can make first column read-only.
Posts: 135
Threads: 33
Joined: Aug 2009
Thank you! Very useful code.
Tuning a little more...
Macro Array to Grid
ARRAY(str) a.create(7 5)
int i j
for i 0 a.len
,for j 0 a.len(1)
,,a[j i].from(i " " j)
;
ICsv x=CreateCsv(1)
x.FromArray(a)
x.ToString(_s)
lpstr ColumnLabels="a,b bbb,c is other,d,e,f,g"
lpstr RowLabels="A aaa,B label,C,D,E,F"
lpstr GridHeader="My own stats"
_s.ToGrid(500 100 ColumnLabels RowLabels GridHeader);; ColumnLabels RowLabels GridHeader are optional
Macro Use DynamicGrid_labels
_s=
;aa,ab,ac,ad,ae,af
;ba,bb,bc,bd,be,bf
;ca,cb,cc,cd,ce,cf
;da,db,dc,dd,de,df
;ea,eb,ec,ed,ee,ef
lpstr ColumnLabels="col0 is 1st col,col1,col2,col3,col4,col5"
lpstr RowLabels="row0,row1,row2 is not bad,row3,row4"
lpstr GridHeader="This is a demo"
_s.ToGrid(500 100 ColumnLabels RowLabels GridHeader);; ColumnLabels RowLabels GridHeader are optional
Member function str.ToGrid
/Dialog_Editor
function Dlgw Dlgh [$ColumnLabels] [$RowLabels] [$GridHeader]
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 200 119 ""
;3 QM_Grid 0x54030000 0x0 0 0 200 94 ""
;1 Button 0x54030001 0x0 98 102 48 14 "OK"
;2 Button 0x54030000 0x0 150 102 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2030507 "" "" "" ""
DialogDefinitionReplace2 2 dd 0 Dlgw Dlgh
DialogDefinitionReplace2 2 dd 3 Dlgw+1 Dlgh-21
DialogDefinitionReplace2 1 dd 1 Dlgw/2-55 Dlgh-19
DialogDefinitionReplace2 1 dd 2 Dlgw/2-5 Dlgh-19
DialogDefinitionReplace2 3 dd 0 Dlgw Dlgh GridHeader
ICsv+ x._create
x.FromString(this)
x.InsertColumn(0)
for _i 0 x.RowCount
,_s.gett(RowLabels _i ",")
,x.Cell(_i 0)=_s
str sColumnLabels=ColumnLabels
if empty(ColumnLabels)
,sColumnLabels.all(x.ColumnCount 2 13);; 13: ASCII Carriage return
else sColumnLabels.findreplace("," "[]");sColumnLabels.from("[]" sColumnLabels)
str+ g_ColumnLabels=sColumnLabels
if(!ShowDialog(dd &DynamicGrid_dialog2)) ret
Function DialogDefinitionReplace2
;/
function what str&dd ctrlID v1 v2 [$GridHeader];;what: 0 style/exstyle, 1 x/y, 2 width/height, 3 text
;Replaces two numeric values in dialog definition string.
;dd - variable containing dialog definition (BEGIN DIALOG...END DIALOG).
;ctrlID - control id, or 0 for dialog. It's the first number in a line.
;v1, v2 - new values. Coordinates are in dialog units.
str rx
sel what
,case 0 rx=F"^({ctrlID} .+?) 0x\w+ \w+"
,case 1 rx=F"^({ctrlID} .+? 0x\w+ \w+) \d+ \d+"
,case 2 rx=F"^({ctrlID} .+? 0x\w+ \w+ \w+ \w+) \d+ \d+"
,case 3 dd.replacerx(F"^({ctrlID} .+? 0x\w+ \w+ \w+ \w+ \d+ \d+)" F"$1 ''{GridHeader}''" 8);ret
,case else end ERR_BADARG
if(dd.replacerx(rx F"$1 {v1} {v2}" 4|8)<=0) end ERR_FAILED
Function DynamicGrid_dialog2
;/
function# hDlg message wParam lParam
if(hDlg) goto messages
ret
;messages
DlgGrid g.Init(hDlg 3)
sel message
,case WM_INITDIALOG
,g.ColumnsAdd(g_ColumnLabels 1)
,g.FromICsv(x)
,g.ColumnsWidthAdjust(x.ColumnCount);; num columns
,__Font-- f
,int hlv=id(3 hDlg)
,f.Create("" 8)
,f.SetDialogFont(hDlg "3")
,f.SetDialogFontColor(hDlg 0xff0000 "3")
,;SendMessage hlv LVM_SETTEXTBKCOLOR 0 0xe0ffff
,;SendMessage hlv LVM_SETBKCOLOR 0 0xe0ffff
,;DT_SetBackgroundColor(hDlg 0 0x8000);; green
,;function hDlg flags color [color2] ;;flags: 1 horizontal gradient, 2 vertical gradient
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
ret 1
;messages3
NMLVCUSTOMDRAW* cd=+lParam
sel cd.nmcd.dwDrawStage
,case CDDS_PREPAINT _i=CDRF_NOTIFYITEMDRAW ;;yes, notify me to draw items
,case CDDS_ITEMPREPAINT
,if(cd.nmcd.dwItemSpec&1) cd.clrTextBk=0xFAFCCF;; light blue ; indent this line = NO row colors
,case else _i=0
ret DT_Ret(hDlg _i)
Posts: 135
Threads: 33
Joined: Aug 2009
I changed some stuff and looks fine! xD
Please, any info about how to change the background color of a specific cell?
Posts: 12,090
Threads: 142
Joined: Dec 2002
Did you try CDRF_NOTIFYSUBITEMDRAW?
Posts: 12,090
Threads: 142
Joined: Dec 2002
sel cd.nmcd.dwDrawStage
,case CDDS_PREPAINT _i=CDRF_NOTIFYITEMDRAW ;;yes, notify me to draw items
,case CDDS_ITEMPREPAINT _i=CDRF_NOTIFYSUBITEMDRAW ;;draw subitems
,case CDDS_ITEMPREPAINT|CDDS_SUBITEM
,if(cd.nmcd.dwItemSpec&1) cd.clrTextBk=0xFAFCCF;; light blue ; indent this line = NO row colors
,else if(cd.iSubItem&1) cd.clrTextBk=0xa0f0ff
,else cd.clrTextBk=0xffffff
|