aswang  1.0
TreeView.cpp
Go to the documentation of this file.
00001 /*
00002         Copyright 2003 Joseph Alvis
00003 
00004     This file is part of Aswang.
00005 
00006     Aswang is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU Lesser General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 
00011     Aswang is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU Lesser General Public License for more details.
00015 
00016     You should have received a copy of the GNU Lesser General Public License
00017     along with Aswang.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 #include "TreeView.h"
00021 
00022 using namespace aswang;
00023 
00024 HTREEITEM TreeView::AddTextItem(const AswangStr &text,HTREEITEM treeParent,HTREEITEM insertAfter) {
00025         if(hWnd!=NULL) {
00026                 TVINSERTSTRUCT tvis;
00027                 tvis.hInsertAfter=insertAfter;
00028                 tvis.hParent=treeParent;
00029                 tvis.itemex.mask = TVIF_TEXT;
00030                 tvis.itemex.pszText = (_TCHAR *)text.c_str();
00031                 return (HTREEITEM)SendMessage(hWnd,TVM_INSERTITEM,0,(LPARAM)&tvis);
00032         }
00033         return NULL;
00034 }
00035 
00036 AswangStr TreeView::GetItemText(HTREEITEM item) {
00037         AswangStr retstr;
00038         if(hWnd!=NULL) {
00039                 unsigned long i;
00040                 for(i=100;i<1024;i*=2) {
00041                         _TCHAR *buf = new _TCHAR[i];
00042                         TVITEMEX tex;
00043                         buf[0]=0;
00044                         tex.hItem = item;
00045                         tex.pszText = buf;
00046                         tex.cchTextMax = i;
00047                         tex.mask = TVIF_TEXT;
00048                         SendMessage(hWnd,TVM_GETITEM,0,(LPARAM)&tex);
00049                         retstr=buf;
00050                         delete buf;
00051                         if(retstr.length()<i-1)
00052                                 break;
00053                 }
00054         }
00055         return retstr;
00056 }
00057 
00058 void TreeView::DeleteItem(HTREEITEM item) {
00059         if(hWnd!=NULL)
00060                 SendMessage(hWnd,TVM_DELETEITEM,0,(LPARAM)item);
00061 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines