From: <mie...@us...> - 2008-12-24 06:25:33
|
Revision: 3806 http://oorexx.svn.sourceforge.net/oorexx/?rev=3806&view=rev Author: miesfeld Date: 2008-12-24 06:25:26 +0000 (Wed, 24 Dec 2008) Log Message: ----------- Update the TreeControl to use the .ImageList class. Remove usage of deprecated setImages() and removeImages() in the tree-view control sample programs. Modified Paths: -------------- main/trunk/extensions/platform/windows/oodialog/advctrl.cls main/trunk/extensions/platform/windows/oodialog/oovother.cpp main/trunk/extensions/platform/windows/oodialog/oovutil.cpp main/trunk/samples/windows/oodialog/oodtree.rex main/trunk/samples/windows/oodialog/propdemo.rex Modified: main/trunk/extensions/platform/windows/oodialog/advctrl.cls =================================================================== --- main/trunk/extensions/platform/windows/oodialog/advctrl.cls 2008-12-23 23:31:25 UTC (rev 3805) +++ main/trunk/extensions/platform/windows/oodialog/advctrl.cls 2008-12-24 06:25:26 UTC (rev 3806) @@ -87,25 +87,15 @@ return ctrlobj ::method getStaticControl unguarded external "LIBRARY oodialog advCtrl_getStaticControl" -/* -::method GetStaticControl unguarded - arr = Arg(1,"A") - arr[3] = "ST" - forward message "GetControl" Arguments (arr) -*/ +::method getButtonControl unguarded external "LIBRARY oodialog advCtrl_getButtonControl" +::method getTreeControl unguarded external "LIBRARY oodialog advCtrl_getTreeControl" +::method getListControl unguarded external "LIBRARY oodialog advCtrl_getListControl" ::method GetEditControl unguarded arr = Arg(1,"A") arr[3] = "EL" forward message "GetControl" Arguments (arr) -::method getButtonControl unguarded external "LIBRARY oodialog advCtrl_getButtonControl" -/* -::method GetButtonControl unguarded - arr = Arg(1,"A") - arr[3] = "BUT" - forward message "GetControl" Arguments (arr) -*/ ::method GetRadioControl unguarded arr = Arg(1,"A") @@ -137,22 +127,6 @@ arr[3] = "SB" forward message "GetControl" Arguments (arr) -::method GetTreeControl unguarded - arr = Arg(1,"A") - arr[3] = "TC" - forward message "GetControl" Arguments (arr) - -::method getListControl unguarded external "LIBRARY oodialog advCtrl_getListControl" -/* -::method GetListControl unguarded - arr = Arg(1,"A") - arr[3] = "LC" - forward message "GetControl" Arguments (arr) continue - listControl = result - if listControl \== .nil then listControl~lastItem = listControl~items - 1 - return listControl -*/ - ::method GetProgressBar unguarded arr = Arg(1,"A") arr[3] = "PB" @@ -807,6 +781,8 @@ if arg(1, 'O') | hItem = 0 then return -1 return HandleTreeCtrl("SORT", self~Hwnd, hitem, 0) /* recursive not yet supported */ + +-- This method is deprecated, use setImageList() ::method SetImages use arg bmp, cx, cy if arg(1, 'O') then return -1 @@ -814,9 +790,13 @@ if arg(3, 'O') then cy = 0 return HandleTreeCtrl("SETIMG",self~Hwnd, bmp, cx, cy) +-- This method is deprecated, use setImageList() ::method RemoveImages return HandleTreeCtrl("UNSETIMG", self~Hwnd) +::method setImageList external "LIBRARY oodialog tv_setImageList" +::method getImageList external "LIBRARY oodialog tv_getImageList" + ::method HitTest use arg x, y return HandleTreeCtrl("HIT", self~Hwnd, x, y) Modified: main/trunk/extensions/platform/windows/oodialog/oovother.cpp =================================================================== --- main/trunk/extensions/platform/windows/oodialog/oovother.cpp 2008-12-23 23:31:25 UTC (rev 3805) +++ main/trunk/extensions/platform/windows/oodialog/oovother.cpp 2008-12-24 06:25:26 UTC (rev 3806) @@ -3916,6 +3916,11 @@ return advGetControl(context, args, self, "LC"); } +RexxMethod2(RexxObjectPtr, advCtrl_getTreeControl, ARGLIST, args, OSELF, self) +{ + return advGetControl(context, args, self, "TC"); +} + RexxMethod2(RexxObjectPtr, advCtrl_putControl_pvt, RexxObjectPtr, control, OSELF, self) { rxPutInBag(context, control, ADVCTRLCONTROLBAG_ATTRIBUTE); @@ -4159,44 +4164,154 @@ return rxArgCount(context); } +/** + * Sets an object variable value and returns the existing value. With the + * caveat that if the object variable did not have a value set, .nil is + * returned. + * + * @param c The method context we are operating in. + * @param varName The object variable's name. + * @param val The value to set. + * + * @return The previous value of the object variable, if it was set, otherwise + * .nil. + */ +RexxObjectPtr rxSetObjVar(RexxMethodContext *c, CSTRING varName, RexxObjectPtr val) +{ + RexxObjectPtr result = c->GetObjectVariable(varName); + if ( result == NULLOBJECT ) + { + result = c->Nil(); + } + c->SetObjectVariable(varName, val); + return result; +} + + /** - * Methods for the .ListControl. + * Methods for the .TreeControl class. */ -#define LISTCONTROL_CLASS "ListControl" +#define TREECONTROL_CLASS "TreeControl" -#define STATE_ATTRIBUTE "!STATEIMAGELIST" -#define SMALL_ATTRIBUTE "!SMALLIMAGELIST" -#define NORMAL_ATTRIBUTE "!NORMALIMAGELIST" +#define TVSTATE_ATTRIBUTE "TV!STATEIMAGELIST" +#define TVNORMAL_ATTRIBUTE "TV!NORMALIMAGELIST" -CSTRING lvGetAttributeName(uint8_t type) +CSTRING tvGetAttributeName(uint8_t type) { switch ( type ) { - case LVSIL_STATE : - return STATE_ATTRIBUTE; - case LVSIL_SMALL : - return SMALL_ATTRIBUTE; - case LVSIL_NORMAL : + case TVSIL_STATE : + return TVSTATE_ATTRIBUTE; + case TVSIL_NORMAL : default : - return NORMAL_ATTRIBUTE; + return TVNORMAL_ATTRIBUTE; } +} +/** TreeControl::setImageList() + * + * Sets or removes one of a tree-view's image lists. + * + * @param imageList An .ImageList object that references the image list to be + * set, or .nil. If .nil, an existing image list, if any, is + * removed. + * + * @param type [optional] One of the tree-view image list types and + * specifies which image list we are concerned with, normal, + * or state. The default is normal. + * + * @return Returns the exsiting .ImageList object if there is one, or + * .nil if there is not an existing object. + * + */ +RexxMethod3(RexxObjectPtr, tv_setImageList, RexxObjectPtr, imageList, OPTIONAL_uint8_t, type, OSELF, self) +{ + HWND hwnd = rxGetWindowHandle(context, self); + + HIMAGELIST himl = NULL; + + if ( imageList != context->Nil() ) + { + // imageList is not .nil, so it has to be a .ImageList, or error. + himl = rxGetImageList(context, imageList, 1); + if ( himl == NULL ) + { + goto err_out; + } + } + + if ( argumentOmitted(2) ) + { + type = TVSIL_NORMAL; + } + else if ( type != TVSIL_STATE && type != TVSIL_NORMAL ) + { + invalidTypeException(context, 2, "TVSIL_XXX flag"); + goto err_out; + } + + TreeView_SetImageList(hwnd, himl, type); + return rxSetObjVar(context, tvGetAttributeName(type), imageList); + +err_out: + return NULLOBJECT; } -RexxObjectPtr lvSetImages(RexxMethodContext *c, RexxObjectPtr imageList, uint8_t type, OSELF self) + +/** TreeControl::getImageList() + * + * Gets the tree-view's specifed image list. + * + * @param type [optional] Identifies which image list to get, normal, or + * state. Normal is the default. + * + * @return The image list, if it exists, otherwise .nil. + */ +RexxMethod2(RexxObjectPtr, tv_getImageList, OPTIONAL_uint8_t, type, OSELF, self) { - CSTRING varName = lvGetAttributeName(type); + if ( argumentOmitted(1) ) + { + type = TVSIL_NORMAL; + } + else if ( type != TVSIL_STATE && type != TVSIL_NORMAL ) + { + invalidTypeException(context, 2, "TVSIL_XXX flag"); + return NULLOBJECT; + } - RexxObjectPtr result = c->GetObjectVariable(varName); + RexxObjectPtr result = context->GetObjectVariable(tvGetAttributeName(type)); if ( result == NULLOBJECT ) { - result = c->Nil(); + result = context->Nil(); } - c->SetObjectVariable(varName, imageList); - return result; } + + +/** + * Methods for the .ListControl class. + */ +#define LISTCONTROL_CLASS "ListControl" + +#define LVSTATE_ATTRIBUTE "LV!STATEIMAGELIST" +#define LVSMALL_ATTRIBUTE "LV!SMALLIMAGELIST" +#define LVNORMAL_ATTRIBUTE "LV!NORMALIMAGELIST" + +CSTRING lvGetAttributeName(uint8_t type) +{ + switch ( type ) + { + case LVSIL_STATE : + return LVSTATE_ATTRIBUTE; + case LVSIL_SMALL : + return LVSMALL_ATTRIBUTE; + case LVSIL_NORMAL : + default : + return LVNORMAL_ATTRIBUTE; + } +} + /** ListControl::setImageList() * * Sets or removes one of a list-view's image lists. @@ -4216,8 +4331,6 @@ { HWND hwnd = rxGetWindowHandle(context, self); - // If imageList is .nil, then a NULL himl will remove the current image - // list, if any. HIMAGELIST himl = NULL; if ( imageList != context->Nil() ) @@ -4240,12 +4353,9 @@ goto err_out; } - // We ignore the return from ListView_SetImageList() and instead return what - // this ListControl object has at its image list attribute. ListView_SetImageList(hwnd, himl, type); + return rxSetObjVar(context, lvGetAttributeName(type), imageList); - return lvSetImages(context, imageList, type, self); - err_out: return NULLOBJECT; } @@ -4255,7 +4365,7 @@ * Gets the list-view's specifed image list. * * @param type [optional] Identifies which image list to get. Normal, small, - * or state. Normalis the default. + * or state. Normal is the default. * * @return The image list, if it exists, otherwise .nil. */ @@ -4267,7 +4377,7 @@ } else if ( type > LVSIL_STATE ) { - wrongRangeException(context, 2, LVSIL_NORMAL, LVSIL_STATE, type); + wrongRangeException(context, 1, LVSIL_NORMAL, LVSIL_STATE, type); return NULLOBJECT; } @@ -4280,7 +4390,6 @@ } - /** * Methods for the .StaticControl. */ @@ -6214,6 +6323,9 @@ cMap->insert(String2Int::value_type("LVSIL_SMALL", 1)); cMap->insert(String2Int::value_type("LVSIL_STATE", 2)); + cMap->insert(String2Int::value_type("TVSIL_NORMAL", 0)); + cMap->insert(String2Int::value_type("TVSIL_STATE", 2)); + //cMap->insert(String2Int::value_type("", )); return cMap; Modified: main/trunk/extensions/platform/windows/oodialog/oovutil.cpp =================================================================== --- main/trunk/extensions/platform/windows/oodialog/oovutil.cpp 2008-12-23 23:31:25 UTC (rev 3805) +++ main/trunk/extensions/platform/windows/oodialog/oovutil.cpp 2008-12-24 06:25:26 UTC (rev 3806) @@ -2131,9 +2131,13 @@ REXX_METHOD_PROTOTYPE(lv_setImageList); REXX_METHOD_PROTOTYPE(lv_getImageList); +REXX_METHOD_PROTOTYPE(tv_setImageList); +REXX_METHOD_PROTOTYPE(tv_getImageList); + +REXX_METHOD_PROTOTYPE(advCtrl_getStaticControl); REXX_METHOD_PROTOTYPE(advCtrl_getButtonControl); -REXX_METHOD_PROTOTYPE(advCtrl_getStaticControl); REXX_METHOD_PROTOTYPE(advCtrl_getListControl); +REXX_METHOD_PROTOTYPE(advCtrl_getTreeControl); REXX_METHOD_PROTOTYPE(advCtrl_putControl_pvt); REXX_METHOD_PROTOTYPE(pbc_stepIt); @@ -2253,9 +2257,13 @@ REXX_METHOD(lv_setImageList, lv_setImageList), REXX_METHOD(lv_getImageList, lv_getImageList), + REXX_METHOD(tv_setImageList, tv_setImageList), + REXX_METHOD(tv_getImageList, tv_getImageList), + + REXX_METHOD(advCtrl_getStaticControl, advCtrl_getStaticControl), REXX_METHOD(advCtrl_getButtonControl, advCtrl_getButtonControl), - REXX_METHOD(advCtrl_getStaticControl, advCtrl_getStaticControl), REXX_METHOD(advCtrl_getListControl, advCtrl_getListControl), + REXX_METHOD(advCtrl_getTreeControl, advCtrl_getTreeControl), REXX_METHOD(advCtrl_putControl_pvt, advCtrl_putControl_pvt), REXX_METHOD(pbc_stepIt, pbc_stepIt), Modified: main/trunk/samples/windows/oodialog/oodtree.rex =================================================================== --- main/trunk/samples/windows/oodialog/oodtree.rex 2008-12-23 23:31:25 UTC (rev 3805) +++ main/trunk/samples/windows/oodialog/oodtree.rex 2008-12-24 06:25:26 UTC (rev 3806) @@ -1,12 +1,12 @@ /*----------------------------------------------------------------------------*/ /* */ /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */ -/* Copyright (c) 2005-2006 Rexx Language Association. All rights reserved. */ +/* Copyright (c) 2005-2008 Rexx Language Association. All rights reserved. */ /* */ /* This program and the accompanying materials are made available under */ /* the terms of the Common Public License v1.0 which accompanies this */ /* distribution. A copy is also available at the following address: */ -/* http://www.oorexx.org/license.html */ +/* http://www.oorexx.org/license.html */ /* */ /* Redistribution and use in source and binary forms, with or */ /* without modification, are permitted provided that the following */ @@ -148,7 +148,13 @@ end /* Set image list for Tree control IDC_TREE */ - curTree~SetImages(bmpFile,16,12) + image = .Image~getImage(bmpFile) + imageList = .ImageList~create(.Size~new(16, 12), .Image~id(ILC_COLOR8), 5, 2) + if \image~isNull, \imageList~isNull then do + imageList~add(image) + curTree~setImageList(imageList, .Image~id(TVSIL_NORMAL)) + image~release + end /* Read the file containig the tree input data and build the tree */ do while lines(treeFile) Modified: main/trunk/samples/windows/oodialog/propdemo.rex =================================================================== --- main/trunk/samples/windows/oodialog/propdemo.rex 2008-12-23 23:31:25 UTC (rev 3805) +++ main/trunk/samples/windows/oodialog/propdemo.rex 2008-12-24 06:25:26 UTC (rev 3806) @@ -151,13 +151,22 @@ self~ConnectTreeNotify(100,"BeginDrag","DefTreeDragHandler") /* support drag and drop (default behaviour) */ tc = self~GetTreeControl(100) /* category specifier is not required in InitXXX methods */ if tc == .Nil then return - tc~SetImages("bmp\psdemotv.bmp",32,32) /* set images for the items */ + + /* set images for the items */ + image = .Image~getImage("bmp\psdemotv.bmp") + imageList = .ImageList~create(.Size~new(32, 32), .Image~id(ILC_COLOR8), 10, 0) + if \image~isNull, \imageList~isNull then do + imageList~add(image) + tc~setImageList(imageList, .Image~id(TVSIL_NORMAL)) + image~release + end + /* add the tree */ tc~Add("Toys",1) /* this is a root (first argument specified) */ tc~Add(,"Indoor") /* this is a subitem (leading arguments omitted) */ - tc~Add(,,"Boys") - tc~Add(,,,"Cowboys") - tc~Add(,,,"Cars",8) + tc~Add(,,"Boys") -- the last numeric argument in some of the items is + tc~Add(,,,"Cowboys") -- the index for the icon in the image list. Those + tc~Add(,,,"Cars",8) -- items without a number will not display an icon. tc~Add(,,,"Starwars",9) tc~Add(,,"Girls") tc~Add(,,,"Barby") @@ -177,8 +186,8 @@ tc~Add(,,,"Bucket") tc~Add(,,,"Sandbox") tc~Add(,,"Technical") - tc~Add(,,,"Trains") - tc~Add(,,,"Remote controlled") + tc~Add(,,,"Trains",7) + tc~Add(,,,"Remote controlled",8) tc~Add("Office Articles",2) tc~Add(,"Tools") tc~Add(,"Books") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |