Hi,
Sometimes
TREEVIEW_GetItem(hItem, hTreeItemCur, TREEVIEW_GET_FIRST_CHILD);
returns its next sibling instead of 0 when hTreeItemCur hasn't any child..
Sometimes it returns 0, sometimes it returns next sibling.
Is there any solution? Is it a bug or my fault?
I'm using stemwin on stm32f103zet6. (emwin version: 5.26)
I extract the emwin related codes from loops. I explain the problem in detail;
TREEVIEW_ITEM_Handle hTreeItemCur;
TREEVIEW_ITEM_Handle hTreeItemNew;
TREEVIEW_ITEM_Handle hTreeItemTemp;
TREEVIEW_ITEM_Handle hTreeItemPreviousTemp;
//firs operation, add a child to treeview item has only root node item.
hItem = WM_GetDialogItem(hWin_FileWin, GUI_ID_TREEVIEW_0);
hTreeItemCur = TREEVIEW_GetItem(hItem, 0, TREEVIEW_GET_FIRST); //Get Root node item
hTreeItemTemp = TREEVIEW_GetItem(hItem, hTreeItemCur, TREEVIEW_GET_FIRST_CHILD);
// it hasn't any child.hTreeItemTemp = 0
hTreeItemNew = TREEVIEW_ITEM_Create(TREEVIEW_ITEM_TYPE_NODE, "1", 0);
TREEVIEW_AttachItem(hItem, hTreeItemNew, hTreeItemCur, TREEVIEW_INSERT_FIRST_CHILD); TREEVIEW_ITEM_ExpandAll(hTreeItemCur);
WM_Exec();
//second operation, add a new next sibling item to previous node.
hItem = WM_GetDialogItem(hWin_FileWin, GUI_ID_TREEVIEW_0);
hTreeItemCur = TREEVIEW_GetItem(hItem, 0, TREEVIEW_GET_FIRST); //Get Root node item
hTreeItemTemp = TREEVIEW_GetItem(hItem, hTreeItemCur, TREEVIEW_GET_FIRST_CHILD);
// it has a child. ( first child item text = "1" )
hTreeItemPreviousTemp = hTreeItemTemp; //copy handle
hTreeItemTemp = TREEVIEW_GetItem(hItem, hTreeItemTemp, TREEVIEW_GET_NEXT_SIBLING);
// it hasn't next sibling. hTreeItemTemp = 0
hTreeItemNew = TREEVIEW_ITEM_Create(TREEVIEW_ITEM_TYPE_NODE, "2", 0);
TREEVIEW_AttachItem(hItem, hTreeItemNew, hTreeItemPreviousTemp, TREEVIEW_INSERT_BELOW);
//new sibling attached. ( new item text = "2" )
TREEVIEW_ITEM_ExpandAll(hTreeItemCur);WM_Exec();
//there is no problem so far. Now I will add a new child item to first node...
hItem = WM_GetDialogItem(hWin_FileWin, GUI_ID_TREEVIEW_0);
hTreeItemCur = TREEVIEW_GetItem(hItem, 0, TREEVIEW_GET_FIRST); //Get Root node item
hTreeItemTemp = TREEVIEW_GetItem(hItem, hTreeItemCur, TREEVIEW_GET_FIRST_CHILD); //first node item... hTreeItemCur = hTreeItemTemp; hTreeItemTemp = TREEVIEW_GetItem(hItem, hTreeItemCur, TREEVIEW_GET_FIRST_CHILD); /*the problem is at here; first node hasn't child. It should return '0' but it returns second nodes handle (which has item text '2')....*/
hTreeItemNew = TREEVIEW_ITEM_Create(TREEVIEW_ITEM_TYPE_NODE, "1.1", 0);
if(hTreeItemTemp) //if first item node has child, add a new child.
{ TREEVIEW_AttachItem(hItem, hTreeItemNew, hTreeItemTemp, TREEVIEW_INSERT_BELOW); }
else // first node hasn't any child, add first child to first node...
{ TREEVIEW_AttachItem(hItem, hTreeItemNew, hTreeItemCur, TREEVIEW_INSERT_FIRST_CHILD); } TREEVIEW_ITEM_ExpandAll(hTreeItemCur);
WM_Exec();
When I change the sequence of operations there is no probem occur.
first; add first node.
second; add first child to first node.
third; add second node.
but I must generate nodes random sequence. Any Help?
Sometimes
TREEVIEW_GetItem(hItem, hTreeItemCur, TREEVIEW_GET_FIRST_CHILD);
returns its next sibling instead of 0 when hTreeItemCur hasn't any child..
Sometimes it returns 0, sometimes it returns next sibling.
Is there any solution? Is it a bug or my fault?
I'm using stemwin on stm32f103zet6. (emwin version: 5.26)
I extract the emwin related codes from loops. I explain the problem in detail;
TREEVIEW_ITEM_Handle hTreeItemCur;
TREEVIEW_ITEM_Handle hTreeItemNew;
TREEVIEW_ITEM_Handle hTreeItemTemp;
TREEVIEW_ITEM_Handle hTreeItemPreviousTemp;
//firs operation, add a child to treeview item has only root node item.
hItem = WM_GetDialogItem(hWin_FileWin, GUI_ID_TREEVIEW_0);
hTreeItemCur = TREEVIEW_GetItem(hItem, 0, TREEVIEW_GET_FIRST); //Get Root node item
hTreeItemTemp = TREEVIEW_GetItem(hItem, hTreeItemCur, TREEVIEW_GET_FIRST_CHILD);
// it hasn't any child.hTreeItemTemp = 0
hTreeItemNew = TREEVIEW_ITEM_Create(TREEVIEW_ITEM_TYPE_NODE, "1", 0);
TREEVIEW_AttachItem(hItem, hTreeItemNew, hTreeItemCur, TREEVIEW_INSERT_FIRST_CHILD); TREEVIEW_ITEM_ExpandAll(hTreeItemCur);
WM_Exec();
//second operation, add a new next sibling item to previous node.
hItem = WM_GetDialogItem(hWin_FileWin, GUI_ID_TREEVIEW_0);
hTreeItemCur = TREEVIEW_GetItem(hItem, 0, TREEVIEW_GET_FIRST); //Get Root node item
hTreeItemTemp = TREEVIEW_GetItem(hItem, hTreeItemCur, TREEVIEW_GET_FIRST_CHILD);
// it has a child. ( first child item text = "1" )
hTreeItemPreviousTemp = hTreeItemTemp; //copy handle
hTreeItemTemp = TREEVIEW_GetItem(hItem, hTreeItemTemp, TREEVIEW_GET_NEXT_SIBLING);
// it hasn't next sibling. hTreeItemTemp = 0
hTreeItemNew = TREEVIEW_ITEM_Create(TREEVIEW_ITEM_TYPE_NODE, "2", 0);
TREEVIEW_AttachItem(hItem, hTreeItemNew, hTreeItemPreviousTemp, TREEVIEW_INSERT_BELOW);
//new sibling attached. ( new item text = "2" )
TREEVIEW_ITEM_ExpandAll(hTreeItemCur);WM_Exec();
//there is no problem so far. Now I will add a new child item to first node...
hItem = WM_GetDialogItem(hWin_FileWin, GUI_ID_TREEVIEW_0);
hTreeItemCur = TREEVIEW_GetItem(hItem, 0, TREEVIEW_GET_FIRST); //Get Root node item
hTreeItemTemp = TREEVIEW_GetItem(hItem, hTreeItemCur, TREEVIEW_GET_FIRST_CHILD); //first node item... hTreeItemCur = hTreeItemTemp; hTreeItemTemp = TREEVIEW_GetItem(hItem, hTreeItemCur, TREEVIEW_GET_FIRST_CHILD); /*the problem is at here; first node hasn't child. It should return '0' but it returns second nodes handle (which has item text '2')....*/
hTreeItemNew = TREEVIEW_ITEM_Create(TREEVIEW_ITEM_TYPE_NODE, "1.1", 0);
if(hTreeItemTemp) //if first item node has child, add a new child.
{ TREEVIEW_AttachItem(hItem, hTreeItemNew, hTreeItemTemp, TREEVIEW_INSERT_BELOW); }
else // first node hasn't any child, add first child to first node...
{ TREEVIEW_AttachItem(hItem, hTreeItemNew, hTreeItemCur, TREEVIEW_INSERT_FIRST_CHILD); } TREEVIEW_ITEM_ExpandAll(hTreeItemCur);
WM_Exec();
When I change the sequence of operations there is no probem occur.
first; add first node.
second; add first child to first node.
third; add second node.
but I must generate nodes random sequence. Any Help?
The post was edited 2 times, last by ilmete ().