WideStudio Logo
WideStudio
Programming Guide
WideStudio Index
Table of contents


A lista em árvore



Ajustando os itens pelo método

Use o método addItem para adicinar itens à lista cuja propriedade WSNtype é WS_TREE, utilizando uma string e uma posição. Se a posição é omitida, adicione-a ao final da lista. O programa a seguir é um exemplo de adição de item à lista. A diferença da lista são os itens, aqueles com vírgulas. Também é possível ajustar o próximo valor mínimo da lista de itens com o método setItemValue. Os argumentos são posição do item, o tipo com o valor WS_INDENT_LEVEL, e o nível de identação. Se omitido, o valor default é 0.

  setItemValue(pos,WS_INDENT_LEVEL,level);
pos = 0,1,2,...,-1(last one)
level = 0(top),1,2,3...

[a lista em árvore]

O programa a seguir é um exemplo de adição de item à lista.
#include <WScom.h>
#include <WSCfunctionList.h>
#include <WSCbase.h>
//----------------------------------------------------------
//Function for the event procedure
//----------------------------------------------------------
#include <WSCtreeList.h>
extern WSCtreeList* newlist_001;
void btnep1(WSCbase* object){
//Delete all the items of the list.
newlist_001->delAll();
//Add an item to the last of the list.
newlist_001->addItem("item1");
newlist_001->setItemValue(-1,WS_INDENT_LEVEL,0);
newlist_001->addItem("item2");
newlist_001->setItemValue(-1,WS_INDENT_LEVEL,1);
newlist_001->addItem("item3");
newlist_001->setItemValue(-1,WS_INDENT_LEVEL,2);
newlist_001->addItem("item4");
newlist_001->setItemValue(-1,WS_INDENT_LEVEL,3);
newlist_001->addItem("item5");
newlist_001->setItemValue(-1,WS_INDENT_LEVEL,0);
newlist_001->addItem("item6");
newlist_001->setItemValue(-1,WS_INDENT_LEVEL,1);

//Add an item to the specified position of the list.
newlist_001->updateList();
}
static WSCfunctionRegister op("btnep1",(void*)btnep1);

O ponto a realçar em lista tipo árvore, é que não há qualquer relação entre os itens em si, ficando sua posição indicada exclusivamente pela sua posição na identação. Portanto, deletar o item de um nível superior não fará desaparecer um item seguinte abaixo. A diferença do nível superior é somente de "+1". Se maior, então é ajustado automaticamente para "+1".


Ajustando os itens pela propriedade

A propriedade  WSNdata pode ser usada pra ajustar os itens da lista, se comparativamente em menor número de itens. Neste caso, ajuste a propriedade WSNdataSource em WS_DATA_SOURCE_NONE, e então ajuste os itens marcados com uma vírgula. Agora, ajuste a propriedade WSNdata para cada item.

  Format:(the property WSNuseIcon is True)
icon_filename,indent_level,1=open/0=close,the string\n...
Format:(the property WSNuseIcon is False)
indent_level,1=open/0=close,the string\n...
Se o ícone é omitido, então a propriedade WSNuseIcon assume valor True, e o valor de WSNiconPixmap é usado para o ícone.
#include <WScom.h>
#include <WSCfunctionList.h>
#include <WSCbase.h>
//----------------------------------------------------------
//Function for the event procedure
//----------------------------------------------------------
#include <WSCtreeList.h>
extern WSCtreeList* newlist_001;
void btnep1(WSCbase* object){
//Delete all the items of the list.
newlist_001->delAll();
//Set the items of the list by the property
newlist_001->setProperty(WSNdataSource,WS_DATA_SOURCE_NONE);
newlist_001->setProperty(WSNdata,",0,1,item1\n,1,1,item2\n,2,1,item3");

static WSCfunctionRegister op("btnep1",(void*)btnep1);


Ajustando os itens diretamente a partir do arquivo de diretório

É possível ajustar os itens a partir do diretório de arquivos. Nestes casos, primeiro ajuste a propriedade WSNdataSource em WS_DATA_SOURCE_FILE, e depois a propriedade WNSdataSourceName com o nome do arquivo, como mostrado no programa a seguir:

#include <WScom.h>
#include <WSCfunctionList.h>
#include <WSCbase.h>
//----------------------------------------------------------
//Function for the event procedure
//----------------------------------------------------------
#include <WSCtreeList.h>
extern WSCtreeList* newlist_001;
void btnep1(WSCbase* object){
//Delete all the items of the list
newlist_001->delAll();
//Set the items from file directly
newlist_001->setProperty(WSNdataSource,WS_DATA_SOURCE_FILE);
newlist_001->setProperty(WSNdataSourceName,"data.txt");
}
static WSCfunctionRegister op("btnep1",(void*)btnep1);

//data.txt contains...
$(WSDIR)/sys/pixmaps/bi16.xpm,0,1,item1
1,1,item2
2,1,item3
3,1,item4
$(WSDIR)/sys/pixmaps/bi16.xpm,0,1,item5
1,1,item6
2,1,item7
3,1,item8



Ajustando os itens a partir de outra instância

É possível ajustar os itens a partir de outra instância pela propriedade de destino da fonte de dado. Para isso, ajuste a propriedade WSNdataSource de WS_DATA_SOURCE_INSTANCE, e depois ajuste a propriedade WSNdataSourceName com o nome da instância. No exemplo a seguir, a instância WSCtextField é referenciada pelo propriedade WSNdataSourceName, e depois ajusta os dados da lista.

#include <WScom.h>
#include <WSCfunctionList.h>
#include <WSCbase.h>
//----------------------------------------------------------
//Function for the event procedure
//----------------------------------------------------------
#include <WSCtreeList.h>
extern WSCtreeList* newlist_001;
void btnep1(WSCbase* object){
//Delete all the items of the list
newlist_001->delAll();
//Set the items from the other instances
newlist_001->setProperty(WSNdataSource,WS_DATA_SOURCE_INSTANCE);
newlist_001->setProperty(WSNdataSourceName,"newtext_000");
}
static WSCfunctionRegister op("btnep1",(void*)btnep1);


Document Release 3.80 for WideStudio ver 3.80, Jan 2005


WideStudio documents index | Table of contents

Copyright(C) WideStudio Development Team, 1999-2005 Last modified: Jan 05, 2005