/* *********************************************************************
This source file is a part of the standard library of Scol
For the latest info, see http://www.scolring.org
Copyright (c) 2014 Stephane Bisaro aka Iri.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt
********************************************************************* */
/*
* Functions for the widget named 'CheckList'
* See http://redmine.scolring.org/projects/tutorials/wiki/Scol_usage
* for more informations
*/
/*! \file checkList.pkg
* \author Scol team
* \version 0.1
* \copyright GNU Lesser General Public License 2.0 or later
* \brief New CheckList widget API
*
* Dependancies :
*
* \image html checklist.png
**/
/*! \struct CheckList
*
* \ingroup _2dos_checklist
*
* \brief Opaque internal structure. You should not call it directly, use
* API instead !
*
**/
struct CheckList = [
cl_oChn : Chn,
cl_oMother : ObjWin,
cl_oWin : ObjWin, // real window if scrolling, otherwise it is nil
cl_oVirtualWin : ObjWin, // where controls are put
cl_oFont : ObjFont,
cl_loCheck : [CheckObject r1],
cl_iCoWidth : I,
cl_iCoHeight : I,
cl_iSpacing : I,
cl_iPosX : I,
cl_iPosY : I,
cl_iWidth : I,
cl_iHeight : I, // displayed
cl_iVirtualHeight : I, // real
cl_iCurId : I,
cl_iScroll : I,
cl_szWinTitle : S,
cl_cbChanged : fun [CheckList I I] I, // callback for check state : parameters are the CL object, the check box ID and the new state
cl_cbSize : fun [CheckList I I] I // callback for the check box resized, parameters are the new width and height
] mkCheckList;;
/*! \struct CheckObject
*
* \ingroup _2dos_checklist
*
* \brief Opaque internal structure. You should not call it directly, use
* API instead !
*
**/
struct CheckObject = [
co_iId : I,
co_iLevel : I, // position in the displayed list (first = 0)
co_oCheck : ObjCheck,
co_oText : ObjText,
co_szTitle : S,
co_iLeft : I, // 1 is left else isRight
co_iFlags : I,
co_iRadio : I,
co_iShow : I
] mkCheckObject;;
proto checklist_resizeVirtualWin = fun [CheckList I I] CheckList;;
var CL_SIZEDEFAULT = 200;;
/*! \brief Constante to create a radio box control
*
* All such sub controls in a CheckList object are dependants : if one is checked,
* all others are unchecked.
*
* \ingroup _2dos_checklist
**/
fun CL_RADIO ()= 0;;
/*! \brief Constante to create a check box control
*
* Several subcontrol can be checked/unchecked in the same time.
*
* \ingroup _2dos_checklist
**/
fun CL_CHECK ()= 1;;
/*! \brief Constante to display a 3d border around the control
*
* \ingroup _2dos_checklist
**/
fun CL_DOWN ()= CH_DOWN;;
fun CL_CENTER ()= 0;; // not used
/*! \brief Constante to add a vertical scroll bar
*
* \ingroup _2dos_checklist
**/
fun CL_SCROLL ()= 1;;
/*! \brief Constante to create a control without scroll bar
*
* \ingroup _2dos_checklist
**/
fun CL_NOSCROLL ()= 0;;
/*! \brief Constante to show the contol
*
* \ingroup _2dos_checklist
**/
fun CL_SHOW ()= WINDOW_UNHIDDEN;;
/*! \brief Constante to hide the control
*
* \ingroup _2dos_checklist
**/
fun CL_HIDE ()= WINDOW_HIDDEN;;
fun checklist_init ()=
mkCheckList [
nil nil nil nil nil
nil
200 20 10
0 0 nil nil nil
0 nil "untitle"
nil nil
];;
fun checklist_init_object ()=
mkCheckObject [
nil nil
nil nil
nil
nil nil nil 1
];;
/* PRIVATE FUNCTIONS */
fun checklist_cbSize (o, u, neww, newh)=
let u -> [cl cbfun uparam] in
exec cbfun with [cl uparam neww newh];;
fun checklist_cbDestroy (o, u)=
let u -> [cl cbfun uparam] in
exec cbfun with [cl uparam];;
fun checklist_cbMove (o, u, newx, newy)=
let u -> [cl cbfun uparam] in
exec cbfun with [cl uparam newx newy];;
fun checklist_cbPaint (o, u)=
let u -> [cl cbfun uparam] in
exec cbfun with [cl uparam];;
fun checklist_cbChanged (o, u, state)=
let u -> [cl co] in
exec cl.cl_cbChanged with [cl co.co_iId state];;
fun checklist_getCoFromId2 (lCo, idCo)=
if lCo == nil then
nil
else
let hd lCo -> co in
if co.co_iId == idCo then
co
else
checklist_getCoFromId2 tl lCo idCo;;
fun checklist_getCoFromId (cl, idCo)=
checklist_getCoFromId2 cl.cl_loCheck idCo;;
fun checklist_getLevel (cl, id)=
let checklist_getCoFromId cl id -> co in
co.co_iLevel;;
fun checklist_count (cl)=
sizelist cl.cl_loCheck;;
fun checklist_getSizeFromCos (cl)=
let checklist_count cl -> nCo in
(nCo * cl.cl_iCoHeight) + ((nCo +1) * cl.cl_iSpacing);;
fun checklist_idExist2 (l, id)=
if l == nil then
0
else
let hd l -> co in
if co.co_iId == id then
1
else
checklist_idExist2 tl l id;;
fun checklist_idExist (cl, id)=
checklist_idExist2 cl.cl_loCheck id;;
fun checklist_getIdFromLevel2 (l, level)=
if l == nil then
nil
else
let hd l -> co in
if level == co.co_iLevel then
co.co_iId
else
checklist_getIdFromLevel2 tl l level;;
fun checklist_getIdFromLevel (cl, level)=
checklist_getIdFromLevel2 cl.cl_loCheck level;;
/*fun checklist_updateSpacingHeight2 (l, ds, dh, dw, allH)=
if l == nil then
allH
else
let hd l -> co in
let _GETcheckPositionSize co.co_oCheck -> [x y w h] in
let y+h+dh+(2*ds) -> a in
(
_POSITIONcheck co.co_oCheck x+ds a+ds w+dw h+dh;
checklist_updateSpacingHeight2 tl l ds dh dw if a > allH then a else allH
);;*/
fun checklist_updateSpacingHeight2 (l, cl)=
if l == nil then
0
else
let hd l -> co in
let (co.co_iLevel * cl.cl_iCoHeight) + ((co.co_iLevel+1) * cl.cl_iSpacing) -> y in
(
_POSITIONcheck co.co_oCheck cl.cl_iSpacing y cl.cl_iCoWidth cl.cl_iCoHeight;
checklist_updateSpacingHeight2 tl l cl
);;
fun checklist_updateSpacingHeight (cl, newSpacing, newHeight, newWidth)=
let cl.cl_iSpacing -> oldSpacing in
let cl.cl_iCoHeight -> oldHeight in
let cl.cl_iCoWidth -> oldWidth in
let newWidth-oldWidth -> dw in
let newSpacing-oldSpacing -> ds in
let newHeight-oldHeight -> dh in
//let checklist_updateSpacingHeight2 cl.cl_loCheck ds dh dw 0 -> allH in
(
set cl.cl_iSpacing = newSpacing;
set cl.cl_iCoHeight = newHeight;
set cl.cl_iCoWidth = newWidth;
checklist_updateSpacingHeight2 cl.cl_loCheck cl;
if (dh != 0) || (ds != 0) || (dw > 0) then
let sizelist cl.cl_loCheck -> n in
(
set cl.cl_iWidth = cl.cl_iWidth+(2*dw);
checklist_resizeVirtualWin cl (n*cl.cl_iCoHeight)+((n+1)*cl.cl_iSpacing) (2*cl.cl_iSpacing)+cl.cl_iCoWidth
)
else
cl
);;
fun checklist_set (cl, id, title, state, shown)=
let checklist_getCoFromId cl id -> co in
if co == nil then
nil
else
(
_SETcheckName co.co_oCheck set co.co_szTitle = title;
if (state == 0) || (state == 1) then
_SETcheck co.co_oCheck state
else
nil;
if (shown == CL_SHOW) || (shown == CL_HIDE) then
(
set co.co_iShow = shown;
_SHOWcheck co.co_oCheck co.co_iShow
)
else
nil;
cl
);;
fun checklist_fontApply (l, cl)=
if l == nil then
cl
else
let hd l -> co in
(
_AFFfontCheck co.co_oCheck cl.cl_oFont;
checklist_fontApply tl l cl
);;
fun checklist_setFont (cl, oFont)=
if oFont != nil then
(
set cl.cl_oFont = oFont;
checklist_fontApply cl.cl_loCheck cl
)
else
nil;;
fun checklist_getTitle (cl, id)=
let checklist_getCoFromId cl id -> co in
if co == nil then
nil
else
co.co_szTitle;;
fun checklist_getState (cl, id)=
let checklist_getCoFromId cl id -> co in
if co == nil then
nil
else
_GETcheck co.co_oCheck;;
fun checklist_getShwon (cl, id)=
let checklist_getCoFromId cl id -> co in
if co == nil then
nil
else
co.co_iShow;;
fun checklist_exchange (cl, id1, id2)=
let checklist_getCoFromId cl id1 -> co1 in
let checklist_getCoFromId cl id2 -> co2 in
if (co1 == nil) || (co2 == nil) then
nil
else
let _GETcheckPositionSize co1.co_oCheck -> [x1 y1 w1 h1] in
let _GETcheckPositionSize co2.co_oCheck -> [x2 y2 w2 h2] in
let co1.co_iLevel -> level1 in
(
_POSITIONcheck co1.co_oCheck x2 y2 w2 h2;
_POSITIONcheck co2.co_oCheck x1 y1 w1 h1;
set co1.co_iLevel = co2.co_iLevel;
set co2.co_iLevel = level1;
cl
);;
fun checklist_getCheckedList2 (l, flag)=
if l == nil then
nil
else
let hd l -> co in
if flag == _GETcheck co.co_oCheck then
[co.co_iId co.co_iLevel] :: checklist_getCheckedList2 tl l flag
else
checklist_getCheckedList2 tl l flag;;
fun checklist_getCheckedList (cl, flag)= // flag : 1 checked, 0 unchecked
checklist_getCheckedList2 cl.cl_loCheck flag;;
/*fun checklist_checkHeightGreater (l, out, yref)=
if l == nil then
out
else
let hd l -> co in
let _GETcheckPositionSize co.co_oCheck -> [_ y _ _] in
if y > yref then
checklist_checkHeightGreater tl l co :: out yref
else
checklist_checkHeightGreater tl l out yref;;*/
fun checklist_checkLevelGreater (l, levelRef)=
if l == nil then
nil
else
let hd l -> co in
if co.co_iLevel >= levelRef then
co :: checklist_checkLevelGreater tl l levelRef
else
checklist_checkLevelGreater tl l levelRef;;
fun checklist_downUpCo (cl, co, dir)=
let _GETcheckPositionSize co.co_oCheck -> [x y w h] in
let if dir then // up
(
set co.co_iLevel = co.co_iLevel+1;
y+cl.cl_iCoHeight+cl.cl_iSpacing
)
else // down
(
set co.co_iLevel = co.co_iLevel-1;
y-cl.cl_iCoHeight-cl.cl_iSpacing
)
-> newy in
_POSITIONcheck co.co_oCheck x newy w h;
//set co.co_iLevel = co.co_iLevel-1;
0;;
/* lorsqu'un co est supprimé, les autres qui étaient à une hateur supérieure
* doivent être descendus d'une hauteur d'un co afin de ne pas laisser
* d'espace vide.
* On ne peut pas se fier à la liste 'cl_loCheck' car les co ont pu être
* déplacés depuis leur création par _EXCHANGEcheckList.
* Il convient ainsi de procéder pour tout co d'une hauteur supérieure à
* une hauteur de référence (la hauteur du co supprimé) et donc de tester
* toute la liste. See checklist_checkHeightGreater above.
*/
fun checklist_downListCo (cl, levelref)=
// let checklist_checkHeightGreater cl.cl_loCheck nil yref -> lCo in
let checklist_checkLevelGreater cl.cl_loCheck levelref -> lCo in
while lCo != nil do
(
checklist_downUpCo cl hd lCo 0;
set lCo = tl lCo
);
cl;;
fun checklist_upListCo (cl, levelref)=
// let checklist_checkHeightGreater cl.cl_loCheck nil yref -> lCo in
let checklist_checkLevelGreater cl.cl_loCheck levelref -> lCo in
while lCo != nil do
(
checklist_downUpCo cl hd lCo 1;
set lCo = tl lCo
);
cl;;
fun checklist_destrpyCo2 (l, co)=
if l == nil then
nil
else
if (co == hd l) then
tl l
else
(hd l) :: checklist_destrpyCo2 tl l co;;
fun checklist_destroyCo (cl, co)=
if co == nil then
nil
else
(
set cl.cl_loCheck = checklist_destrpyCo2 cl.cl_loCheck co;
_DStext co.co_oText;
_DScheck co.co_oCheck;
set co = nil;
0
);;
fun checklist_remove (cl, id)=
let checklist_getCoFromId cl id -> co in
if co == nil then
nil
else
//let _GETcheckPositionSize co.co_oCheck -> [_ y _ _] in
(
checklist_destroyCo cl co;
// checklist_downListCo cl y;
checklist_downListCo cl co.co_iLevel;
let sizelist cl.cl_loCheck -> nCo in
let (nCo*cl.cl_iCoHeight)+((nCo+1)*cl.cl_iSpacing) -> h in
checklist_resizeVirtualWin cl h nil
);;
fun checklist_idList2 (l)=
if l == nil then
nil
else
let hd l -> co in
co.co_iId :: checklist_idList2 tl l;;
fun checklist_idList (cl)=
checklist_idList2 cl.cl_loCheck;;
fun checklist_resizeCo2 (l, cl)=
if l == nil then
cl
else
let hd l -> co in
let _GETcheckPositionSize co.co_oCheck -> [x y w h] in
(
_SIZEcheck co.co_oCheck cl.cl_iCoWidth cl.cl_iCoHeight x y;
checklist_resizeCo2 tl l cl
);;
fun checklist_resizeCo (cl)=
checklist_resizeCo2 cl.cl_loCheck cl;;
fun checklist_size (cl, neww, newh)=
if (neww == nil) || (newh == nil) || (neww < 1) || (newh < 1) then nil
else
(
set cl.cl_iWidth = neww;
set cl.cl_iCoWidth = (cl.cl_iWidth)-2*cl.cl_iSpacing;
set cl.cl_iHeight = newh;
_SIZEwindow cl.cl_oWin cl.cl_iWidth cl.cl_iHeight cl.cl_iPosX cl.cl_iPosY;
checklist_resizeCo cl;
exec cl.cl_cbSize with [cl cl.cl_iCoWidth cl.cl_iCoHeight];
//_SIZEwindow cl.cl_oVirtualWin cl.cl_iWidth cl.cl_iVirtualHeight cl.cl_iPosX cl.cl_iPosY;
cl
);;
fun checklist_move (cl, newx, newy)=
if (newx == nil) || (newy == nil) then nil
else
(
set cl.cl_iPosX = newx;
set cl.cl_iPosY = newy;
_MVwindow cl.cl_oWin cl.cl_iPosX cl.cl_iPosY;
_MVwindow cl.cl_oVirtualWin cl.cl_iPosX cl.cl_iPosY;
cl
);;
fun checklist_resizeVirtualWin (cl, newh, neww)=
set cl.cl_iVirtualHeight = newh;
if neww != nil then
checklist_size cl neww cl.cl_iHeight
else
nil;
let _GETwindowPositionSize cl.cl_oVirtualWin -> [x y _ _] in
_SIZEwindow cl.cl_oVirtualWin cl.cl_iWidth cl.cl_iVirtualHeight x y;
cl;;
fun checklist_destroy (cl)=
_DSwindow cl.cl_oVirtualWin;
set cl.cl_oVirtualWin = nil;
_DSwindow cl.cl_oWin;
set cl.cl_oWin = nil;
set cl = nil;;
fun checklist_setCoId (cl)=
set cl.cl_iCurId = cl.cl_iCurId + 1;;
fun checklist_createScrollWindow (cl)=
_DSwindow cl.cl_oVirtualWin;
_DSwindow cl.cl_oWin;
let _CRscrollWindow
cl.cl_oChn
cl.cl_oMother
cl.cl_iPosX cl.cl_iPosY
cl.cl_iWidth cl.cl_iHeight
cl.cl_iWidth cl.cl_iVirtualHeight
/*if cl.cl_oMother == nil then WN_NORMAL|(if cl.cl_iVirtualHeight >= cl.cl_iHeight then WN_VSCROLL else 0)
else WN_CHILDINSIDE|(if cl.cl_iVirtualHeight >= cl.cl_iHeight then WN_VSCROLL else 0)*/
if cl.cl_oMother == nil then WN_NORMAL|WN_VSCROLL else WN_CHILDINSIDE|WN_VSCROLL
cl.cl_szWinTitle
-> [rWin vWin] in
(
set cl.cl_oVirtualWin = vWin;
set cl.cl_oWin = rWin;
);;
fun checklist_create (chn, mother, width, height, scroll)=
let checklist_init -> cl in
(
set cl.cl_oChn = chn;
set cl.cl_oMother = mother;
set cl.cl_iWidth = if (width == nil) || (width < 1) then CL_SIZEDEFAULT else width;
set cl.cl_iHeight = if (height == nil) || (height < 1) then CL_SIZEDEFAULT else height;
set cl.cl_iCoWidth = cl.cl_iWidth-(2*cl.cl_iSpacing);
set cl.cl_iVirtualHeight = cl.cl_iHeight;
set cl.cl_iScroll = if (scroll == CL_NOSCROLL) || (scroll == CL_SCROLL) then scroll else CL_NOSCROLL;
if cl.cl_iScroll == CL_NOSCROLL then
set cl.cl_oVirtualWin = _CRwindow
cl.cl_oChn
cl.cl_oMother
cl.cl_iPosX cl.cl_iPosY
cl.cl_iWidth cl.cl_iHeight
if cl.cl_oMother == nil then WN_NORMAL else WN_CHILDINSIDE
cl.cl_szWinTitle
else
checklist_createScrollWindow cl;
cl
);;
fun checlist_create_object (cl, isRadio, flags, isLeft, title, pos)= // pos == nil -> APPEND
let checklist_init_object -> co in
let sizelist cl.cl_loCheck -> nCo in
(
set co.co_iId = checklist_setCoId cl;
// set co.co_iLevel = if (pos == nil) || (pos > nCo) || (pos < 0) then nCo else pos;
set pos = if (pos == nil) || (pos > nCo) || (pos < 0) then nCo else pos;
set co.co_iRadio = isRadio;
set co.co_iLeft = isLeft;
set co.co_szTitle = title;
set co.co_iFlags = flags;
//let (nCo*cl.cl_iCoHeight)+((nCo+1)*cl.cl_iSpacing) -> h in
// let (co.co_iLevel*cl.cl_iCoHeight)+((co.co_iLevel+1)*cl.cl_iSpacing) -> h in
let (pos*cl.cl_iCoHeight)+((pos+1)*cl.cl_iSpacing) -> h in
(
set co.co_oCheck = _CRcheck
cl.cl_oChn
cl.cl_oVirtualWin
cl.cl_iSpacing
h
cl.cl_iCoWidth
cl.cl_iCoHeight
flags|CH_TABFOCUS|(if !co.co_iRadio then CH_RADIO else 0)|(if co.co_iLeft then CH_LEFT else 0)
co.co_szTitle;
/*set co.co_oText = _CRtext
cl.cl_oChn
cl.cl_oVirtualWin
cl.cl_iSpacing + 30
h
cl.cl_iCoWidth
cl.cl_iCoHeight
0
co.co_szTitle;*/
//);
if co.co_oCheck != nil then
(
_CBcheck co.co_oCheck @checklist_cbChanged [cl co];
if pos != nil then checklist_upListCo cl pos/*co.co_iLevel*/ else nil;
set co.co_iLevel = pos;
set cl.cl_loCheck = co :: cl.cl_loCheck;
if (checklist_getSizeFromCos cl) > cl.cl_iVirtualHeight then
checklist_resizeVirtualWin cl checklist_getSizeFromCos cl /*h+cl.cl_iSpacing+cl.cl_iCoHeight*/ nil
else
nil;
co.co_iId
)
else
nil
)
);;
/* PUBLIC FUNCTIONS */
/*! \brief Create an empty CheckList object.
*
* A checkList allows to add, remove and modify a list of check boxes.
*
* To (re)define the position from the parent window or the desktop,
* use _MOVEcheckList.
*
* \ingroup _2dos_checklist
* Prototype : fun [Chn ObjWin I I I] CheckList
*
* \param Chn : the channel where the checkList is created
* \param ObjWin : the parent window (can be nil)
* \param I : the width
* \param I : the height
* \param I : define if this object has a vertical scroll bar (CL_SCROLL)
* or not (CL_NOSCROLL).
* This parameter can not be modified after.
*
* \return CheckList : The new CheckList object or nil if an error occurs
* (null channel or bad settings)
*
* \see _MOVEcheckList
* \see _ADDcheckList to add a check control
**/
fun _CRcheckList (chn, parent, width, height, withScroll)=
if chn == nil then nil
else checklist_create chn parent width height withScroll;;
/*! \brief Destroy a CheckList object
*
* All included check controls will be also destroyed.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList] I
*
* \param CheckList : a CheckList object
*
* \return I : always 0
**/
fun _DScheckList (cl)=
checklist_destroy cl;
0;;
/*! \brief Move a CheckList object from its parent window or the desktop
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I I] CheckList
*
* \param CheckList : a CheckList object
* \param I : the new x coordinate. Can not be nil.
* \param I : the new y coordinate. Can not be nil.
*
* \return CheckList : the same CheckList object or nil if an error occurs.
**/
fun _MOVEcheckList (cl, newx, newy)=
checklist_move cl newx newy;;
/*! \brief Resize a CheckList object from its parent window or the desktop
*
* Exactly, it resizes the visible part of the CheckList control (if the
* control has a vertical scroll bar, for example. If not, the function
* resizes the control itself).
*
* All the subcontrols (included check controls) are also resized (in their
* width only).
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I I] CheckList
*
* \param CheckList : a CheckList object
* \param I : the new width >= 1. Can not be nil.
* \param I : the new height >= 1. Can not be nil.
*
* \return CheckList : the same CheckList object or nil if an error occurs.
*
* \see _SETcheckListHeight to define the height of each included subcontrol.
**/
fun _SIZEcheckList (cl, neww, newh)=
checklist_size cl neww newh;;
/*! \brief Append a check box object in a CheckList object.
*
* The subcontrol is unchecked by default.
*
* If the CheckList has not a scroll bar, the new subcontrol could be outside.
* If the CheckList has a scroll bar, its height is automatically updated.
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I I S I] I
*
* \param CheckList : a CheckList object
* \param I : subcontrol style : CL_RADIO or CL_CHECK
* \param I : 1 to display the title a the left side of the box else 0 (default)
* \param S : the title
* \param I : a flag : 0 (nothing) or CL_DOWN
*
* \return I : the subcontrol identifier or nil if an error occurs. This ID
* allows to manage this subcontrol from this API.
*
* \see CL_DOWN
* \see CL_RADIO
* \see CL_CHECK
* \see _SETcheckListState
* \see _GETcheckListIdFromLevel
**/
fun _APPENDcheckList (cl, isRadio, isLeft, szTitle, iflags)=
checlist_create_object cl isRadio iflags isLeft szTitle nil;;
/*! \brief Add a check box object in a CheckList object to a given level.
*
* The subcontrol is unchecked by default.
*
* If the CheckList has not a scroll bar, the new subcontrol could be outside.
* If the CheckList has a scroll bar, its height is automatically updated.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I I S I] I
*
* \param CheckList : a CheckList object
* \param I : the level (the position) in the CheckList control (first = 0)
* \param I : subcontrol style : CL_RADIO or CL_CHECK
* \param I : 1 to display the title a the left side of the box else 0 (default)
* \param S : the title
* \param I : a flag : 0 (nothing) or CL_DOWN
*
* \return I : the identifier of the new subcontrol or nil if an error occurs.
* This ID allows to manage this subcontrol from this API.
*
* \see CL_DOWN
* \see CL_RADIO
* \see CL_CHECK
* \see _SETcheckListState
* \see _GETcheckListIdFromLevel
**/
fun _ADDcheckList (cl, iLevel, isRadio, isLeft, szTitle, iflags)=
checlist_create_object cl isRadio iflags isLeft szTitle iLevel;;
/*! \brief Remove a check box subcontrol in a CheckList object.
*
* Other following subcontrols are automatically moved to replace the empty space.
*
* If the CheckList has a scroll bar, its height is automatically updated.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I] CheckList
*
* \param CheckList : a CheckList object
* \param I : the subcontrol ID to remove
*
* \return CheckList : the same CheckList object or nil if an error occurs.
**/
fun _REMOVEcheckList (cl, iCoId)=
checklist_remove cl iCoId;;
/*! \brief From a level, get the ID of a check box subcontrol in a CheckList object.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I] I
*
* \param CheckList : a CheckList object
* \param I : the subcontrol level. A level is the position in the vertical list.
* The first level is 0 (so the first subcontrol (at the top of the list) is 0).
*
* \return I : the ID or nil if an error occurs (typically, a bad level).
*
* \see _GETcheckListLevel to get the level from the ID.
**/
fun _GETcheckListIdFromLevel (cl, iCoId)=
checklist_getIdFromLevel cl iCoId;;
/*! \brief Set a check box control settings
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I I S I] CheckList
*
* \param CheckList : a CheckList object
* \param I : the subcontrol ID to set
* \param I : 1 to check the subcontrol, 0 to uncheck it (other values are ignored)
* \param S : the title
* \param I : the visibility : CL_SHOW or CL_HIDE (other values are ignored)
*
* \return CheckList : the same CheckList object or nil if an error occurs
* (typically, a bad identifier).
*
* \see CL_SHOW
* \see CL_HIDE
**/
fun _SETcheckList (cl, iCoId, iState, szTitle, iShown)=
checklist_set cl iCoId szTitle iState iShown;;
/*! \brief Set the title of a check box control in a CheckList object.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I S] CheckList
*
* \param CheckList : a CheckList object
* \param I : the subcontrol ID to set
* \param S : the title
*
* \return CheckList : the same CheckList object or nil if an error occurs
* (typically, a bad identifier).
**/
fun _SETcheckListTitle (cl, iCoId, szTitle)=
checklist_set cl iCoId szTitle nil nil;;
/*! \brief Set the state of a check box control in a CheckList object.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I I] CheckList
*
* \param CheckList : a CheckList object
* \param I : the subcontrol ID to set
* \param I : the new state : 1 to check the subcontrol, 0 to uncheck it
* (other values are ignored)
*
* \return CheckList : the same CheckList object or nil if an error occurs
* (typically, a bad identifier).
**/
fun _SETcheckListState (cl, iCoId, iState)=
checklist_set cl iCoId checklist_getTitle cl iCoId iState nil;;
/*! \brief Set the visibility of a check box control in a CheckList object.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I I] CheckList
*
* \param CheckList : a CheckList object
* \param I : the subcontrol ID to set
* \param I : the visibility : CL_SHOW or CL_HIDE (other values are ignored)
*
* \return CheckList : the same CheckList object or nil if an error occurs
* (typically, a bad identifier).
*
* \see CL_SHOW
* \see CL_HIDE
**/
fun _SETcheckListShow (cl, iCoId, iShown)=
checklist_set cl iCoId checklist_getTitle cl iCoId checklist_getState cl iCoId iShown;;
/*! \brief Get the title of a check box control in a CheckList object.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I] S
*
* \param CheckList : a CheckList object
* \param I : the subcontrol ID
*
* \return S : the current title or nil if an error occurs
* (typically, a bad identifier).
**/
fun _GETcheckListTitle (cl, iCoId)=
checklist_getTitle cl iCoId;;
/*! \brief Get the visibility of a check box control in a CheckList object.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I] I
*
* \param CheckList : a CheckList object
* \param I : the subcontrol ID
*
* \return I : the current visibility (CL_SHOW or CL_HIDE) or nil if an error occurs
* (typically, a bad identifier).
**/
fun _GETcheckListShow (cl, iCoId)=
checklist_getShwon cl iCoId;;
/*! \brief Get the current state of a check box control in a CheckList object.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I] I
*
* \param CheckList : a CheckList object
* \param I : the subcontrol ID
*
* \return I : the current state (1 checked, 0 unchecked) or nil if an error occurs
* (typically, a bad identifier).
**/
fun _GETcheckListState (cl, iCoId)=
checklist_getState cl iCoId;;
/*! \brief Exchange the positions of two check box controls in a CheckList object.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I I] CheckList
*
* \param CheckList : a CheckList object
* \param I : the first subcontrol ID
* \param I : the second subcontrol ID
*
* \return CheckList : the same CheckList object or nil if an error occurs
* (typically, a bad identifier).
**/
fun _EXCHANGEcheckList (cl, iCoId1, iCoId2)=
checklist_exchange cl iCoId1 iCoId2;;
/*! \brief Get the list of indentifers of all check box controls in a CheckList object.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList] [I r1]
*
* \param CheckList : a CheckList object
*
* \return [I r1] : the list of identifiers
**/
fun _GETcheckListIds (cl)=
checklist_idList cl;;
/*! \brief Return if an indetifier of a check box controls in a CheckList
* object exists or not.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I] I
*
* \param CheckList : a CheckList object
* \param I : an ID
*
* \return I : 1 if exists else 0
**/
fun _CHECKcheckListId (cl, iCoId)=
checklist_idExist cl iCoId;;
/*! \brief Get the number check box controls in a CheckList object.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList] I
*
* \param CheckList : a CheckList object
*
* \return I : the number of subcontrols
**/
fun _GETcheckListCount (cl)=
checklist_count cl;;
/*! \brief Set the spacing between check box controls in a CheckList object.
*
* If the CheckList control has a scroll bar, its height is automatically updated.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I] CheckList
*
* \param CheckList : a CheckList object
* \param I : the spacing, in pixel
*
* \return CheckList : the same CheckList object or nil if an error occurs
**/
fun _SETcheckListSpacing (cl, iSpacing)=
if (iSpacing == nil) || (iSpacing < 0) then
nil
else
checklist_updateSpacingHeight cl iSpacing cl.cl_iCoHeight cl.cl_iCoWidth;;
/*! \brief Get the current spacing between subcontrols in a CheckList object.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList] I
*
* \param CheckList : a CheckList object
*
* \return I : the current spacing
**/
fun _GETcheckListSpacing (cl)=
cl.cl_iSpacing;;
/*! \brief Set the height of the check box controls in a CheckList object.
*
* If the CheckList control has a scroll bar, its total height is automatically updated.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I] CheckList
*
* \param CheckList : a CheckList object
* \param I : the new height, in pixel
*
* \return CheckList : the same CheckList object or nil if an error occurs
*
* \see _SIZEcheckList to resize the CheckList control itself
**/
fun _SETcheckListHeight (cl, iHeight)=
if (iHeight == nil) || (iHeight < 1) then
nil
else
checklist_updateSpacingHeight cl cl.cl_iSpacing iHeight cl.cl_iCoWidth;;
/*! \brief Get the current subcontrol height in a CheckList object.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList] I
*
* \param CheckList : a CheckList object
*
* \return I : the current height of each subcontrol
**/
fun _GETcheckListHeight (cl, iHeight)=
cl.cl_iCoHeight;;
/*! \brief Set the width of the check box controls in a CheckList object.
*
* The CheckList control is NOT resized if the new width is lesser. It is
* greater than the current CheckList control width, the CheckList control
* is resized. In this case, the new CheckList control width is the new
* subcontrol width + two spacing (at the left and the right).
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I] CheckList
*
* \param CheckList : a CheckList object
* \param I : the new width, in pixel
*
* \return CheckList : the same CheckList object or nil if an error occurs
*
* \see _SIZEcheckList to resize the CheckList control itself
**/
fun _SETcheckListWidth (cl, iWidth)=
if (iWidth == nil) || (iWidth < 1) then
nil
else
checklist_updateSpacingHeight cl cl.cl_iSpacing cl.cl_iCoHeight iWidth;;
/*! \brief Get the current subcontrol width in a CheckList object.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList] I
*
* \param CheckList : a CheckList object
*
* \return I : the current width of each subcontrol
**/
fun _GETcheckListWidth (cl, iHeight)=
cl.cl_iCoWidth;;
/*! \brief Set the font object used in a CheckList object.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList ObjFont] CheckList
*
* \param CheckList : a CheckList object
* \param ObjFont : the new font object
*
* \return CheckList : the same CheckList object or nil if an error occurs
**/
fun _SETcheckListFont (cl, oFont)=
checklist_setFont cl oFont;;
/*! \brief Get the current font object used in a CheckList object.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList] ObjFont
*
* \param CheckList : a CheckList object
*
* \return ObjFont : the current font if _SETcheckListFont has been set
* or the default font if _SETdefaultFont has been previously set or nil
* if the default system font is used.
**/
fun _GETcheckListFont (cl)=
let cl.cl_oFont -> f in
if f == nil then _GETdefaultFont else f;;
/*! \brief Get the current level of a subcontrol in a CheckList object.
*
* A level gives the position of the subcontrol in the CheckList.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList I] ObjFont
*
* \param CheckList : a CheckList object
* \param I : an ID subcontrol
*
* \return I : the current position of the subcontrol (0 is the first subcontrol)
* or nil if an error occurs.
*
* \see _EXCHANGEcheckList to move this position
**/
fun _GETcheckListLevel (cl, iCoId)=
checklist_getLevel cl iCoId;;
/*! \brief Get a list of all checked subcontrols in a CheckList object.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList] [[I I] r1]
*
* \param CheckList : a CheckList object
*
* \return [[I I] r1] : a list of tuples. For each tuple : first is the ID
* subcontrol, second is the level subcontrol. Or nil if an error occurs.
*
* A level gives the position of the subcontrol in the CheckList.
**/
fun _GETcheckListCheckedList (cl)=
checklist_getCheckedList cl 1;;
/*! \brief Get a list of all unchecked subcontrols in a CheckList object.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList] [[I I] r1]
*
* \param CheckList : a CheckList object
*
* \return [[I I] r1] : a list of tuples. For each tuple : first is the ID
* subcontrol, second is the level subcontrol. Or nil if an error occurs.
*
* A level gives the position of the subcontrol in the CheckList.
**/
fun _GETcheckListUncheckedList (cl)=
checklist_getCheckedList cl 0;;
/*! \brief Define the callback to the resize event.
*
* When the CheckList control is resized, the defined reflex will be called.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList fun [CheckList u0 I I] I u0] CheckList
*
* \param CheckList : a CheckList object
* \param fun [CheckList u0 I I] I : the callback. Additional argument are
* the new width and the new height
* \param u0 : an user parameter, at your convenience
*
* \return CheckList : the same CheckList object or nil if an error occurs
**/
fun _CBcheckListSize (cl, cbfun, uparam)=
_CBwinSize cl.cl_oWin @checklist_cbSize [cl cbfun uparam];
cl;;
/*! \brief Define the callback to the resize event.
*
* When the check box subcontrols are resized, the defined reflex will be called.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList fun [CheckList I I] I] CheckList
*
* \param CheckList : a CheckList object
* \param fun [CheckList I I] I : the callback. Additional argument are
* the new width and the new height
*
* To set an 'use parameter', you should add a mkfun3 function ...
*
* \return CheckList : the same CheckList object or nil if an error occurs
**/
fun _CBcheckListSubSize (cl, cbfun)=
set cl.cl_cbSize = cbfun;
cl;;
/*! \brief Define the callback to the move event.
*
* When the CheckList control moves, the defined reflex will be called.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList fun [CheckList u0 I I] I u0] CheckList
*
* \param CheckList : a CheckList object
* \param fun [CheckList u0 I I] I : the callback. Additional argument are
* the new x and y coordinates
* \param u0 : an user parameter, at your convenience
*
* \return CheckList : the same CheckList object or nil if an error occurs
**/
fun _CBcheckListMove (cl, cbfun, uparam)=
_CBwinMove cl.cl_oWin @checklist_cbMove [cl cbfun uparam];
cl;;
/*! \brief Define the callback to the destroy event.
*
* When the CheckList control is destroyed, the defined reflex will be called.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList fun [CheckList u0] I u0] CheckList
*
* \param CheckList : a CheckList object
* \param fun [CheckList u0] I : the callback.
* \param u0 : an user parameter, at your convenience
*
* \return CheckList : the same CheckList object or nil if an error occurs
**/
fun _CBcheckListDestroy (cl, cbfun, uparam)=
_CBwinDestroy cl.cl_oWin @checklist_cbDestroy [cl cbfun uparam];
cl;;
/*! \brief Define the callback to the paint event.
*
* When the CheckList control is painted, the defined reflex will be called.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList fun [CheckList u0] I u0] CheckList
*
* \param CheckList : a CheckList object
* \param fun [CheckList u0] I : the callback.
* \param u0 : an user parameter, at your convenience
*
* \return CheckList : the same CheckList object or nil if an error occurs
**/
fun _CBcheckListPaint (cl, cbfun, uparam)=
_CBwinPaint cl.cl_oWin @checklist_cbPaint [cl cbfun uparam];
cl;;
/*! \brief Define the callback to the state changed event.
*
* When the state of a check box subcontrols changes, the defined reflex
* will be called.
*
* \ingroup _2dos_checklist
* Prototype : fun [CheckList fun [CheckList I I] I] CheckList
*
* \param CheckList : a CheckList object
* \param fun [CheckList I I] I : the callback. Additional argument are
* the ID of subcontrol and its new state
*
* To set an 'use parameter', you should add a mkfun3 function ...
*
* \return CheckList : the same CheckList object or nil if an error occurs
**/
fun _CBcheckListChanged (cl, cbfun)=
set cl.cl_cbChanged = cbfun;
cl;;