Beispiel #1
0
static void NSISCALL SetParentState(HWND hwTree, HTREEITEM hItem)
{
  TVITEM tvItem;
  int iState = 0, iItrState, *iFlags;

  HTREEITEM hParent = TreeView_GetParent(hwTree, hItem);
  if (!hParent)
    return;

  hItem = TreeView_GetChild(hwTree, hParent);

  tvItem.mask = TVIF_STATE | TVIF_PARAM;
  tvItem.stateMask = TVIS_STATEIMAGEMASK;

  while (hItem) {
    tvItem.hItem = hItem;
    TreeView_GetItem(hwTree, &tvItem);
    iItrState = tvItem.state >> 12;
    iState |= iItrState % 3 ? iItrState % 3 : 3;
    hItem = TreeView_GetNextSibling(hwTree, hItem);
  }

  tvItem.hItem = hParent;
  TreeView_GetItem(hwTree, &tvItem);

  iFlags = &(g_sections[tvItem.lParam].flags);
  *iFlags &= ~(SF_SELECTED|SF_PSELECTED);

  if (iState == 2)
    *iFlags |= SF_SELECTED;
  if (iState == 3)
    *iFlags |= SF_PSELECTED;

  tvItem.state = INDEXTOSTATEIMAGEMASK(iState);
  TreeView_SetItem(hwTree, &tvItem);

  SetParentState(hwTree, hParent);
}
Beispiel #2
0
void    IDeleteRecurse( HWND tree, HTREEITEM item )
{
    while( item != nil )
    {
        HTREEITEM   child = TreeView_GetChild( tree, item );
        if( child != nil )
            IDeleteRecurse( tree, child );

        TVITEM  itemInfo;
        itemInfo.mask = TVIF_PARAM | TVIF_HANDLE;
        itemInfo.hItem = item;
        TreeView_GetItem( tree, &itemInfo );
        plKeyInfo *keyInfo = (plKeyInfo *)itemInfo.lParam;
        if( keyInfo != nil )
        {
            delete keyInfo;
            itemInfo.lParam = 0;
            TreeView_SetItem( tree, &itemInfo );
        }

        item = TreeView_GetNextSibling( tree, item );
    }
}
Beispiel #3
0
void AddTreeViewNodes(HWND hWndDlg, PageHash key, HTREEITEM root)
{
	if (root) {
		TCHAR title[2048] = {0};

		TVITEM item = {0};
		item.mask = TVIF_TEXT;
		item.hItem = root;
		item.pszText = title;
		item.cchTextMax = _countof(title);

		if (TreeView_GetItem(hWndDlg, &item))
			if (mir_tstrlen(title) > 0)
				AddFilterString(key, title);

		HTREEITEM child = root;
		while (child) {
			child = TreeView_GetNextItem(hWndDlg, child, TVGN_CHILD);
			AddTreeViewNodes(hWndDlg, key, child);
		}

		AddTreeViewNodes(hWndDlg, key, TreeView_GetNextSibling(hWndDlg, root));
	}
}
static BOOL TreeView_SetTree(HWND hwnd, TV_ITEM* root)
{
    BOOL result = FALSE;
    HTREEITEM childItem; 
    TV_ITEM tv_item = *root;

    do
    {
        result = TreeView_SetItem(hwnd, &tv_item);

        childItem = TreeView_GetChild(hwnd, tv_item.hItem);

        if(result && childItem)
        {
            TV_ITEM child_tv_item = tv_item;

            child_tv_item.hItem = childItem;
            result = TreeView_SetTree(hwnd, &child_tv_item);
        }

    }while(result && (tv_item.hItem = TreeView_GetNextSibling(hwnd, tv_item.hItem)));
    
    return result;
}
Beispiel #5
0
void RemoveFromOptions(int id)
{
	if (OptionshWnd) {
		HWND hTree = GetDlgItem(OptionshWnd, IDC_BUTTONORDERTREE);
		TVITEM tvi = { 0 };
		tvi.hItem = TreeView_GetRoot(hTree);
		tvi.mask = TVIF_PARAM | TVIF_HANDLE;

		TopButtonInt* btn;
		while(tvi.hItem != NULL) {
			TreeView_GetItem(hTree, &tvi);
			btn = (TopButtonInt*)tvi.lParam;
			if (btn->id == id) {
			  // delete if was changed
				if (btn->dwFlags & TTBBF_OPTIONAL)
					delete btn;
				TreeView_DeleteItem(hTree,tvi.hItem);
				break;
			}

			tvi.hItem = TreeView_GetNextSibling(hTree, tvi.hItem);
		}
	}
}
Beispiel #6
0
static void
cfgui_free_node(HWND hwtv, HTREEITEM hItem) {
    TVITEMEX iex;
    HTREEITEM hChItem;

    ZeroMemory(&iex, sizeof(iex));

    iex.mask = TVIF_PARAM;
    iex.hItem = hItem;

    if (TreeView_GetItem(hwtv, &iex)) {
        khui_config_node node;

        node = (khui_config_node) iex.lParam;
        khui_cfg_release(node);
    }

    hChItem = TreeView_GetChild(hwtv, hItem);
    while(hChItem) {
        cfgui_free_node(hwtv, hChItem);

        hChItem = TreeView_GetNextSibling(hwtv, hChItem);
    }
}
Beispiel #7
0
void CCList::SelectGroups(HTREEITEM hCurItem, bool bSelected)
{
	// select/deselect all child items
	HTREEITEM hItem = TreeView_GetChild(hTreeView, hCurItem);
	HTREEITEM hLimitItem = GetNextItem(MCLGN_NEXT | MCLGN_ANY | MCLGN_NOTCHILD, hCurItem);
	while (hItem && hItem != hLimitItem) {
		TreeView_SetItemState(hTreeView, hItem, bSelected ? TVIS_SELECTED : 0, TVIS_SELECTED);
		Array_SetItemState(hItem, bSelected);
		hItem = GetNextItem(MCLGN_NEXT | MCLGN_ANY | MCLGN_MULTILEVEL, hItem);
	}
	// select/deselect all parent groups
	hCurItem = TreeView_GetParent(hTreeView, hCurItem);
	if (bSelected) {
		while (hCurItem) { // select until we'll find an unselected item or until we'll reach the root
			hItem = TreeView_GetChild(hTreeView, hCurItem);
			while (hItem) { // walk through all siblings
				if (!(TreeView_GetItemState(hTreeView, hItem, TVIS_SELECTED) & TVIS_SELECTED))
					break;

				hItem = TreeView_GetNextSibling(hTreeView, hItem);
			}
			if (hItem) // means there was at least one unselected item
				break;

			TreeView_SetItemState(hTreeView, hCurItem, TVIS_SELECTED, TVIS_SELECTED);
			Array_SetItemState(hCurItem, true);
			hCurItem = TreeView_GetParent(hTreeView, hCurItem);
		}
	}

	while (hCurItem) { // and deselect all remaining parent groups
		TreeView_SetItemState(hTreeView, hCurItem, 0, TVIS_SELECTED);
		Array_SetItemState(hCurItem, false);
		hCurItem = TreeView_GetParent(hTreeView, hCurItem);
	}
}
Beispiel #8
0
static void SaveTree(HWND hwndDlg)
{
	HWND hTree = GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE);

	TVITEM tvi = { 0 };
	tvi.hItem = TreeView_GetRoot(hTree);
	tvi.stateMask = TVIS_STATEIMAGEMASK;
	tvi.mask = TVIF_PARAM | TVIF_HANDLE | TVIF_STATE;

	LIST<TopButtonInt> tmpList(8);

	while(tvi.hItem != NULL) {
		TreeView_GetItem(hTree, &tvi);

		TopButtonInt* btn = (TopButtonInt*)tvi.lParam;
		Buttons.remove(btn);

		if (TreeView_GetCheckState(hTree,tvi.hItem))
			btn->dwFlags |= TTBBF_VISIBLE;
		else
			btn->dwFlags &= ~TTBBF_VISIBLE;
		btn->dwFlags &= ~TTBBF_OPTIONAL;
		btn->arrangedpos = tmpList.getCount();

		tmpList.insert(btn);
		tvi.hItem = TreeView_GetNextSibling(hTree, tvi.hItem);
	}
	{
		mir_cslock lck(csButtonsHook);
		for (int i=0; i < Buttons.getCount(); i++)
			delete Buttons[i];

		Buttons = tmpList;
	}
	SaveAllButtonsOptions();
}
Beispiel #9
0
LRESULT CALLBACK ParentSubclassProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	CCList *dat = CWndUserData(hWnd).GetCList();
	switch (Msg) {
	case WM_NOTIFY:
		{
			LPNMHDR pnmh = (LPNMHDR)lParam;
			if (pnmh->hwndFrom == dat->hTreeView) {
				switch (pnmh->code) {
				case TVN_ITEMEXPANDED: // just set an appropriate group image
					{
						LPNMTREEVIEW pnmtv = (LPNMTREEVIEW)lParam;
						TVITEM tvItem;
						tvItem.hItem = pnmtv->itemNew.hItem;
						tvItem.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
						tvItem.iImage = tvItem.iSelectedImage = (pnmtv->itemNew.state & TVIS_EXPANDED) ? IMAGE_GROUPOPEN : IMAGE_GROUPSHUT;
						TreeView_SetItem(dat->hTreeView, &tvItem);
					}
					break;
				case TVN_SELCHANGED:
					{
						LPNMTREEVIEW pnmtv = (LPNMTREEVIEW)lParam;
						TREEITEMARRAY OldSelection = dat->SelectedItems;
						for (int i = 0; i < dat->SelectedItems.GetSize(); i++) {
							if (dat->SelectedItems[i] != pnmtv->itemNew.hItem) {
								TreeView_SetItemState(dat->hTreeView, dat->SelectedItems[i], 0, TVIS_SELECTED);
							}
						}
						dat->SelectedItems.RemoveAll();
						if (pnmtv->itemNew.hItem) {
							dat->SelectedItems.AddElem(pnmtv->itemNew.hItem);
							dat->SelectGroups(pnmtv->itemNew.hItem, true);
						}
						NMCLIST nm;
						nm.hdr.code = MCLN_SELCHANGED;
						nm.hdr.hwndFrom = dat->hTreeView;
						nm.hdr.idFrom = GetDlgCtrlID(dat->hTreeView);
						nm.OldSelection = &OldSelection;
						nm.NewSelection = &dat->SelectedItems;
						SendMessage(hWnd, WM_NOTIFY, 0, (LPARAM)&nm);
					}
					break;

				case TVN_DELETEITEM:
					if (dat->Items.GetSize()) { // if Items size = 0, then this TVN_DELETEITEM came after WM_DESTROY, so there is no need to do anything
						LPNMTREEVIEW pnmtv = (LPNMTREEVIEW)lParam;
						TREEITEMARRAY OldSelection = dat->SelectedItems;
						int Index = dat->SelectedItems.Find(pnmtv->itemOld.hItem);
						if (Index != -1)
							dat->SelectedItems.RemoveElem(Index);

						// find an item to pass to SelectGroups()
						HTREEITEM hItem = TreeView_GetNextSibling(dat->hTreeView, pnmtv->itemOld.hItem);
						if (!hItem) {
							hItem = TreeView_GetPrevSibling(dat->hTreeView, pnmtv->itemOld.hItem);
							if (!hItem)
								hItem = TreeView_GetParent(dat->hTreeView, pnmtv->itemOld.hItem);
						}
						if (hItem) // if it wasn't one of the root items
							dat->SelectGroups(hItem, dat->SelectedItems.Find(hItem) != -1);

						NMCLIST nm;
						nm.hdr.code = MCLN_SELCHANGED;
						nm.hdr.hwndFrom = dat->hTreeView;
						nm.hdr.idFrom = GetDlgCtrlID(dat->hTreeView);
						nm.OldSelection = &OldSelection;
						nm.NewSelection = &dat->SelectedItems;
						SendMessage(hWnd, WM_NOTIFY, 0, (LPARAM)&nm);
						dat->Items[pnmtv->itemOld.lParam].hContact = INVALID_CONTACT_ID;
					}
					break;

				case NM_CUSTOMDRAW:
					LPNMTVCUSTOMDRAW lpNMCD = (LPNMTVCUSTOMDRAW)lParam;
					switch (lpNMCD->nmcd.dwDrawStage) {
					case CDDS_PREPAINT: // the control is about to start painting
						return CDRF_NOTIFYITEMDRAW; // instruct the control to return information when it draws items
					case CDDS_ITEMPREPAINT:
						return CDRF_NOTIFYPOSTPAINT;
					case CDDS_ITEMPOSTPAINT:
						RECT rc;
						if (TreeView_GetItemRect(dat->hTreeView, (HTREEITEM)lpNMCD->nmcd.dwItemSpec, &rc, false)) {
							for (int i = 0; i < MAXEXTRAICONS; i++) {
								BYTE nIndex = dat->Items[lpNMCD->nmcd.lItemlParam].ExtraIcons[i];
								if (nIndex != CLC_EXTRAICON_EMPTY) {
									ImageList_DrawEx(dat->ExtraImageList, nIndex, lpNMCD->nmcd.hdc, rc.right - EXTRAICON_XSTEP * (i + 1), rc.top, 0, 0, /*GetSysColor(COLOR_WINDOW)*/CLR_NONE, CLR_NONE, ILD_NORMAL);
								}
							}
						}
						break;
					}
				}
				break;
			}
		}
	}
	return CallWindowProc(dat->OrigParentProc, hWnd, Msg, wParam, lParam);
}
Beispiel #10
0
HTREEITEM CCList::GetNextItem(DWORD Flags, HTREEITEM hItem)
{
	switch (Flags & ~(MCLGN_MULTILEVEL | MCLGN_NOTCHILD | MCLGN_ANY)) {
	case MCLGN_ROOT:
		return TreeView_GetRoot(hTreeView);

	case MCLGN_LAST:
		{
			HTREEITEM hNextItem = TVI_ROOT;
			do {
				hItem = hNextItem;
				hNextItem = TreeView_GetLastChild(hTreeView, hNextItem);
			} while (hNextItem);
			return (hItem == TVI_ROOT) ? nullptr : hItem;
		}

	case MCLGN_CHILD:
		return TreeView_GetChild(hTreeView, hItem);

	case MCLGN_LASTCHILD:
		return TreeView_GetLastChild(hTreeView, hItem);

	case MCLGN_PARENT:
		return TreeView_GetParent(hTreeView, hItem);

	case MCLGN_NEXT:
		do {
			if (Flags & MCLGN_MULTILEVEL) {
				HTREEITEM hNextItem = nullptr;
				if ((Flags & MCLGN_NOTCHILD) != MCLGN_NOTCHILD)
					hNextItem = TreeView_GetChild(hTreeView, hItem);

				if (!hNextItem) {
					hNextItem = TreeView_GetNextSibling(hTreeView, hItem);
					while (!hNextItem) { // move back until we find next sibling of the item or one of its parents
						hItem = TreeView_GetParent(hTreeView, hItem);
						if (!hItem) // means it was the root, there are no items left.
							break; // returns NULL as the next item

						hNextItem = TreeView_GetNextSibling(hTreeView, hItem);
					}
				}
				hItem = hNextItem;
			}
			else hItem = TreeView_GetNextSibling(hTreeView, hItem);
	
			Flags &= ~(MCLGN_NOTCHILD & ~MCLGN_MULTILEVEL); // clear MCLGN_NOTCHILD flag
		}
			while (hItem && !(Flags & GetItemTypeAsCLGNFlag(hItem)));
		return hItem;

	case MCLGN_PREV:
		do {
			if (Flags & MCLGN_MULTILEVEL) {
				HTREEITEM hNextItem = TreeView_GetPrevSibling(hTreeView, hItem);
				if (hNextItem) {
					if ((Flags & MCLGN_NOTCHILD) != MCLGN_NOTCHILD) {
						while (hNextItem) {
							hItem = hNextItem;
							hNextItem = TreeView_GetLastChild(hTreeView, hItem);
						}
					}
					else hItem = hNextItem;
				}
				else hItem = TreeView_GetParent(hTreeView, hItem);
			}
			else hItem = TreeView_GetPrevSibling(hTreeView, hItem);

			Flags &= ~(MCLGN_NOTCHILD & ~MCLGN_MULTILEVEL); // clear MCLGN_NOTCHILD flag
		}
			while (hItem && !(Flags & GetItemTypeAsCLGNFlag(hItem)));
		return hItem;

	default:
		_ASSERT(0);
	}
	return nullptr;
}
Beispiel #11
0
INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam)
{	
	switch(msg){
	case WM_INITDIALOG:{
		DWORD style;
		g_opHdlg=hdlg;
		bOptionsInit=TRUE;
		TranslateDialogDefault(hdlg); 
		if(g_iButtonsCount!=db_get_b(NULL, PLGNAME,"ButtonsCount", 0))
		{
			LOGFONT logFont;
			HFONT hFont;
			bNeedRestart=TRUE;
			EnableWindow(GetDlgItem(hdlg,IDC_BUTTONSLIST),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_BLISTADD),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_BLISTREMOVE),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_MENUTREE),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_MTREEADD),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_MTREEREMOVE),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_RCLICKVALUE),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_BUTTONNAME),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
			EnableWindow(GetDlgItem(hdlg,IDC_MENUNAME),FALSE);	
			ShowWindow(GetDlgItem(hdlg,IDC_WARNING),SW_SHOW);

			hFont = (HFONT)SendDlgItemMessage(hdlg, IDC_WARNING, WM_GETFONT, 0, 0);
			GetObject(hFont, sizeof(logFont), &logFont);
			logFont.lfWeight = FW_BOLD;
			hFont = CreateFontIndirect(&logFont);
			SendDlgItemMessage(hdlg, IDC_WARNING, WM_SETFONT, (WPARAM)hFont, 0);
			break;
		}

		g_iOPButtonsCount=g_iButtonsCount;

		hButtonsList=GetDlgItem(hdlg,IDC_BUTTONSLIST);
		hMenuTree=GetDlgItem(hdlg,IDC_MENUTREE);

		style = GetWindowLongPtr(hButtonsList,GWL_STYLE);
		style |=TVS_NOHSCROLL;
		SetWindowLongPtr(hButtonsList,GWL_STYLE, style);

		style = GetWindowLongPtr(hMenuTree,GWL_STYLE);
		style |=TVS_NOHSCROLL;			
		SetWindowLongPtr(hMenuTree,GWL_STYLE, style);
		BuildButtonsList(hButtonsList);

		if (!TreeView_GetCount(hButtonsList))
			EnableWindow(GetDlgItem(hdlg,IDC_RCLICKVALUE),FALSE);

		mir_subclassWindow( GetDlgItem(hdlg,IDC_BUTTONNAME), EditSubclassProc);
		mir_subclassWindow( GetDlgItem(hdlg,IDC_MENUNAME),   EditSubclassProc);

		EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
		EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE);
		EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
		CheckDlgButton(hdlg,IDC_RAUTOSEND,(g_bRClickAuto=db_get_b(NULL,PLGNAME,"RClickAuto",0)) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hdlg,IDC_LAUTOSEND,(g_bLClickAuto=db_get_b(NULL,PLGNAME,"LClickAuto",0)) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hdlg,IDC_ENABLEQUICKMENU,(g_bQuickMenu=db_get_b(NULL, PLGNAME,"QuickMenu", 1)) ? BST_CHECKED : BST_UNCHECKED);

		bOptionsInit=FALSE;
							 }break;

	case WM_LBUTTONUP:
		if(drag) {
			TVHITTESTINFO hti; 
			HTREEITEM htiAfter=NULL;
			ButtonData* bd=NULL;
			TVITEM tvi;
			RECT rc;
			BYTE height;
			BOOLEAN bAsChild = FALSE;

			TreeView_SetInsertMark(hMenuTree, NULL, 0 );
			ReleaseCapture();
			SetCursor( LoadCursor( NULL, IDC_ARROW ));

			hti.pt.x = ( SHORT )LOWORD( lparam );
			hti.pt.y = ( SHORT )HIWORD( lparam );
			ClientToScreen(hdlg,&hti.pt);
			ScreenToClient(hMenuTree,&hti.pt);
			TreeView_HitTest( hMenuTree, &hti );

			if(TreeView_GetParent(hMenuTree,hti.hItem)&&TreeView_GetChild(hMenuTree,hDragItem))
				break;

			if(TreeView_GetChild(hMenuTree,hti.hItem)&&TreeView_GetChild(hMenuTree,hDragItem))
				break;


			if ( hti.flags & TVHT_ABOVE ) {
				htiAfter = TVI_FIRST;
			}
			else
				if ( hti.flags & ( TVHT_NOWHERE|TVHT_BELOW )) {
					htiAfter = TVI_LAST;
				}
				else
					if ( hti.flags & ( TVHT_ONITEM|TVHT_ONITEMRIGHT )) {
						// check where over the item, the pointer is
						if ( !TreeView_GetItemRect( hMenuTree, hti.hItem, &rc, FALSE )) {
							drag=0;
							break;
						}
						height = ( BYTE )( rc.bottom - rc.top );

						if ( hti.pt.y - ( height / 3 ) < rc.top ) {
							HTREEITEM hItem = hti.hItem;

							if ( !( hti.hItem = TreeView_GetPrevSibling( hMenuTree, hItem )) ) {
								if ( !( hti.hItem = TreeView_GetParent(hMenuTree, hItem )))
									htiAfter = TVI_FIRST;
								else
									bAsChild = TRUE;
							}
						}
						else 
							if ( hti.pt.y + ( height / 3 ) <= rc.bottom ) {
								bAsChild = TRUE;
							}
					}	


					if(TreeView_GetChild(hMenuTree,hDragItem)&&bAsChild)
						break;


					if(hti.hItem){
						tvi.hItem=hti.hItem;
						tvi.mask=TVIF_PARAM |TVIF_HANDLE;
						TreeView_GetItem(hMenuTree,&tvi);
						if ((bd=(ButtonData*)tvi.lParam)&&(bd->fEntryOpType&QMF_EX_SEPARATOR))
							bAsChild = FALSE;
					}

					if(TreeView_GetParent(hMenuTree,hti.hItem))
						bAsChild = FALSE;


					MoveItem( hDragItem, htiAfter?htiAfter:hti.hItem, bAsChild );
					SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
					drag=0;

		}
		break; 

		///////////////////////////////////
		//From UserInfoEx by DeathAxe
		//
	case WM_MOUSEMOVE:
		{
			if (!drag) break;
			{
				TVHITTESTINFO hti;

				hti.pt.x=(short)LOWORD(lparam);
				hti.pt.y=(short)HIWORD(lparam);
				ClientToScreen(hdlg,&hti.pt);
				ScreenToClient(hMenuTree,&hti.pt);
				TreeView_HitTest(hMenuTree,&hti);
				if ( hti.flags & ( TVHT_ONITEM|TVHT_ONITEMRIGHT )) {
					RECT rc;
					BYTE height;

					if ( TreeView_GetItemRect(hMenuTree, hti.hItem, &rc, FALSE )) {
						height = ( BYTE )( rc.bottom - rc.top );

						if ( hti.pt.y - ( height / 3 ) < rc.top ) {
							SetCursor( LoadCursor( NULL, IDC_ARROW ));
							TreeView_SetInsertMark( hMenuTree, hti.hItem, 0 );
						}
						else
							if ( hti.pt.y + ( height / 3 ) > rc.bottom ) {
								SetCursor( LoadCursor( NULL, IDC_ARROW ));
								TreeView_SetInsertMark( hMenuTree, hti.hItem, 1 );
							}
							else {
								TreeView_SetInsertMark( hMenuTree, NULL, 0 );
								SetCursor( LoadCursor( GetModuleHandle(NULL), MAKEINTRESOURCE( 183 )) );
							}
					}
				}
				else {
					if ( hti.flags & TVHT_ABOVE ) SendMessage( hMenuTree, WM_VSCROLL, MAKEWPARAM( SB_LINEUP, 0 ), 0 );
					if ( hti.flags & TVHT_BELOW ) SendMessage( hMenuTree, WM_VSCROLL, MAKEWPARAM( SB_LINEDOWN, 0 ), 0 );
					TreeView_SetInsertMark( hMenuTree, NULL, 0 );
				}
			}
		}break;
		/////////////
	case WM_DESTROY:
		if (g_varhelpDlg)
			DestroyWindow(g_varhelpDlg);
		g_varhelpDlg=NULL;
		break;

	case WM_NOTIFY:
		switch(((LPNMHDR)lparam)->idFrom)	{
		case 0:
			if (((LPNMHDR)lparam)->code == PSN_APPLY ) {
				if (!bNeedRestart){
					SetMenuEntryProperties(hdlg);
					SaveMenuTree(hdlg); 
				}
				db_set_b(NULL,PLGNAME,"RClickAuto",(BYTE)(g_bRClickAuto=IsDlgButtonChecked(hdlg,IDC_RAUTOSEND)));
				db_set_b(NULL,PLGNAME,"LClickAuto",(BYTE)(g_bLClickAuto=IsDlgButtonChecked(hdlg,IDC_LAUTOSEND)));
				db_set_b(NULL,PLGNAME,"QuickMenu",(BYTE)(g_bQuickMenu=IsDlgButtonChecked(hdlg,IDC_ENABLEQUICKMENU)));
				return 1;
			}
			else if (((LPNMHDR)lparam)->code == PSN_RESET ) {
				if (!bNeedRestart)
					RestoreModuleData(hdlg);
				return 1;
			}
			break; 

		case IDC_MENUTREE:
			switch (((LPNMHDR)lparam)->code){
			case TVN_KEYDOWN:{
				TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*) ((LPNMHDR)lparam);
				if ( pTVKeyDown->wVKey == VK_F2 )
					TreeView_EditLabel(hMenuTree,TreeView_GetSelection(hMenuTree));
				else if ( pTVKeyDown->wVKey == VK_DELETE )
					SendMessage(hdlg,WM_COMMAND,IDC_MTREEREMOVE,0);
								  }break;

			case TVN_BEGINLABELEDIT:
				hwndEdit=TreeView_GetEditControl(hMenuTree);
				mir_subclassWindow(hwndEdit, LabelEditSubclassProc);
				break;

			case TVN_ENDLABELEDIT:
				{
					TVITEM tvi;
					ButtonData* bd=NULL;
					TCHAR strbuf[256];
					TCHAR szLabel[256];

					tvi.pszText = strbuf;
					tvi.cchTextMax = _countof(strbuf);
					tvi.mask=TVIF_TEXT |TVIF_HANDLE|TVIF_PARAM;
					tvi.hItem=TreeView_GetSelection(hMenuTree);
					TreeView_GetItem(hMenuTree,&tvi);

					GetWindowText(hwndEdit, szLabel, _countof(szLabel));
					hwndEdit=NULL;
					if (!mir_tstrlen(szLabel)) break;
					if (bd = (ButtonData*)tvi.lParam){
						if (!mir_tstrcmp(szLabel,_T("---"))) {
							if(TreeView_GetChild(hMenuTree,tvi.hItem))
								break;
							else{
								bd->fEntryOpType=QMF_EX_SEPARATOR;
								EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
								EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
								SetDlgItemText(hdlg, IDC_MENUVALUE, _T(""));
							}
						}
						else {
							bd->fEntryOpType&=~QMF_EX_SEPARATOR;
							EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),TRUE);
							EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),TRUE);
							SetDlgItemText(hdlg, IDC_MENUVALUE, bd->pszOpValue/*?bd->pszOpValue:bd->pszValue*/);
						}

						bd->pszOpName=mir_tstrdup(szLabel);

						tvi.pszText=szLabel;
						TreeView_SetItem(hMenuTree, &tvi);
						SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
					}
				}
				break;

			case NM_KILLFOCUS:
				TreeView_EndEditLabelNow(hButtonsList, 1);
				break;

			case TVN_BEGINDRAG:
				SetCapture(hdlg);
				drag=1;
				hDragItem=((LPNMTREEVIEW)lparam)->itemNew.hItem;
				TreeView_SelectItem(hMenuTree,hDragItem);
				break;

			case TVN_SELCHANGING:
				{
					HTREEITEM hti = TreeView_GetSelection(hMenuTree);
					if (hti==NULL)
						break;

					TVITEM tvi;
					tvi.hItem=hti;
					tvi.mask=TVIF_HANDLE|TVIF_PARAM;
					TreeView_GetItem(hMenuTree,&tvi);
					if (tvi.lParam == 0)
						break;

					ButtonData *bd = ( ButtonData* )tvi.lParam;
					if (bd) {
						TCHAR szValue[256];
						GetDlgItemText(hdlg, IDC_MENUVALUE, szValue, _countof(szValue));
						if(mir_tstrlen(szValue))
						{
							if(bd->pszOpValue&&(bd->pszOpValue!=bd->pszValue))
								mir_free(bd->pszOpValue);
							bd->pszOpValue=mir_tstrdup(szValue);
						}
						bd->bOpInQMenu=IsDlgButtonChecked(hdlg,IDC_INQMENU);
						bd->bIsOpServName=IsDlgButtonChecked(hdlg,IDC_ISSERVNAME);
					}
				}
				break;

			case TVN_SELCHANGED:
				{
					HTREEITEM hti = TreeView_GetSelection(hMenuTree);
					if (hti == NULL)
						break;

					TVITEM tvi;
					tvi.mask=TVIF_HANDLE|TVIF_PARAM;
					tvi.hItem=hti;
					TreeView_GetItem(hMenuTree,&tvi);

					ButtonData *bd = ( ButtonData* )tvi.lParam;
					if (bd) {
						if (!TreeView_GetChild(hMenuTree, tvi.hItem)&&!(bd->fEntryOpType&QMF_EX_SEPARATOR))
						{
							EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),TRUE);
							EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),TRUE);
							EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),TRUE);
							SetDlgItemText(hdlg, IDC_MENUVALUE, bd->pszOpValue/*?bd->pszOpValue:bd->pszValue*/);
						}
						else
						{
							EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
							EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
							if (!(bd->fEntryOpType&QMF_EX_SEPARATOR))
								EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE);
							SetDlgItemText(hdlg, IDC_MENUVALUE, _T(""));
						}
						CheckDlgButton(hdlg,IDC_INQMENU,bd->bOpInQMenu ? BST_CHECKED : BST_UNCHECKED);
						CheckDlgButton(hdlg,IDC_ISSERVNAME,bd->bIsOpServName ? BST_CHECKED : BST_UNCHECKED);
					}
				}
			}
			break;

		case IDC_BUTTONSLIST:
			switch (((LPNMHDR)lparam)->code) {
			case TVN_KEYDOWN:{
				TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*) ((LPNMHDR)lparam);
				if ( pTVKeyDown->wVKey == VK_F2 )
					TreeView_EditLabel(hButtonsList,TreeView_GetSelection(hButtonsList));
				else if ( pTVKeyDown->wVKey == VK_DELETE )
					SendMessage(hdlg,WM_COMMAND,IDC_BLISTREMOVE,0);
								  }break;

			case TVN_BEGINLABELEDIT:
				hwndEdit = TreeView_GetEditControl(hButtonsList);
				mir_subclassWindow(hwndEdit, LabelEditSubclassProc);
				break;

			case TVN_ENDLABELEDIT:
				{
					TVITEM tvi;
					TCHAR strbuf[128];
					TCHAR szLabel[128];

					tvi.pszText = strbuf;
					tvi.cchTextMax = _countof(strbuf);
					tvi.mask=TVIF_TEXT |TVIF_HANDLE|TVIF_PARAM;
					tvi.hItem=TreeView_GetSelection(hButtonsList);
					TreeView_GetItem(hButtonsList,&tvi);

					GetWindowText(hwndEdit, szLabel, _countof(szLabel));
					hwndEdit=NULL;
					if (!mir_tstrlen(szLabel)) break;

					tvi.pszText=szLabel;
					((ListData*)tvi.lParam)->dwOPFlags|=QMF_RENAMED;	

					TreeView_SetItem(hButtonsList, &tvi);
					SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
				}
				break;

			case TVN_SELCHANGING:
				SetMenuEntryProperties(hdlg);
				break;

			case TVN_SELCHANGED:
				{
					HTREEITEM hti = TreeView_GetSelection(hButtonsList);
					if(hti==NULL||!TreeView_GetCount(hButtonsList)) {
						EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
						EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
						EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE);
						EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME2),FALSE);
						SetDlgItemText(hdlg, IDC_MENUVALUE, _T(""));
						break;
					}

					TVITEM tvi;
					tvi.mask=TVIF_HANDLE|TVIF_PARAM;
					tvi.hItem=hti;
					TreeView_GetItem(hButtonsList,&tvi);

					if(tvi.lParam==0) break;

					BuildMenuTree(hMenuTree,(SortedList *)((ListData*)tvi.lParam)->sl);

					SetDlgItemText(hdlg, IDC_MENUVALUE, _T(""));
					EnableWindow(GetDlgItem(hdlg,IDC_RCLICKVALUE),TRUE);
					EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME2),TRUE);
					CheckDlgButton(hdlg,IDC_ISSERVNAME2,((ListData*)tvi.lParam)->bIsOpServName ? BST_CHECKED : BST_UNCHECKED);

					if (((ListData*)tvi.lParam)->ptszOPQValue) 
						SetDlgItemText(hdlg, IDC_RCLICKVALUE, ((ListData*)tvi.lParam)->ptszOPQValue);
					else
						SetDlgItemText(hdlg, IDC_RCLICKVALUE, _T(""));
				}
				break;
			}
			break;
		}
		break;

	case WM_COMMAND:
		switch(LOWORD(wparam)) {
		case IDC_VARHELP:
			if (!g_varhelpDlg)
				g_varhelpDlg=CreateDialog(hinstance,MAKEINTRESOURCE(IDD_HELPDIALOG), 0, HelpDlgProc);
			else
				//ShowWindow(g_varhelpDlg,SW_SHOWDEFAULT);
				SetWindowPos(g_varhelpDlg,0,0,0,0,0,SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE);
			break;
		case IDC_BLISTADD:
			{
				TVINSERTSTRUCT tvis;
				ListData* ld=NULL;
				TCHAR namebuff[MAX_PATH]={'\0'};
				int count=TreeView_GetCount(hButtonsList);
				if (count>10) break;
				if(g_iOPButtonsCount==99){
					MessageBox(NULL, TranslateT("Congratulation!\r\nYou have clicked this button 100 times!\r\nThere was access violation at this point...\r\nAnd now function for freeing resources must be called...\r\nBut no! there's only break :D"), TranslateT("You win!"),MB_OK);
					break;
				}

				ld = (ListData *)mir_alloc(sizeof(ListData));
				ButtonsList[g_iOPButtonsCount++]=ld;

				ld->sl=List_Create(0,1);
				ld->dwOPFlags=QMF_NEW;
				ld->bIsOpServName=0;
				ld->ptszButtonName=NULL;
				ld->ptszOPQValue=NULL;
				ld->ptszQValue=NULL;
				tvis.hParent = NULL;
				tvis.hInsertAfter = TVI_LAST;

				GetDlgItemText(hdlg, IDC_BUTTONNAME, namebuff, _countof(namebuff));

				tvis.item.mask=TVIF_PARAM|TVIF_TEXT;
				tvis.item.pszText=(mir_tstrlen(namebuff))?namebuff:TranslateT("New Button");
				tvis.item.lParam=(LPARAM)ld;
				TreeView_SelectItem(hButtonsList,TreeView_InsertItem(hButtonsList,&tvis));
			}break;

		case IDC_BLISTREMOVE:
			{ 
				TVITEM tvi;
				ListData* ld;

				if (!(tvi.hItem=TreeView_GetSelection(hButtonsList)))
					break;

				tvi.mask=TVIF_HANDLE|TVIF_PARAM;
				TreeView_GetItem(hButtonsList,&tvi);

				ld= (ListData*)tvi.lParam;

				ld->dwOPFlags|=QMF_DELETNEEDED;	

				TreeView_DeleteItem(hButtonsList,tvi.hItem);
				if (!TreeView_GetCount(hButtonsList)) {
					TreeView_DeleteAllItems(hMenuTree);
					EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
					EnableWindow(GetDlgItem(hdlg,IDC_RCLICKVALUE),FALSE);
					EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
					EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE);
					EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME2),FALSE);
					SetDlgItemText(hdlg, IDC_MENUVALUE, _T(""));
					SetDlgItemText(hdlg, IDC_RCLICKVALUE, _T(""));
				}
			}break;

		case IDC_MTREEADD:
			{
				TVINSERTSTRUCT tvis;
				TVITEM tvi;
				ButtonData *bd=NULL;
				SortedList *sl=NULL;
				TCHAR namebuff[MAX_PATH]={'\0'};

				if (!TreeView_GetCount(hButtonsList)) break;
				if (!(tvi.hItem=TreeView_GetSelection(hButtonsList))) break;

				bd = (ButtonData *)mir_alloc(sizeof(ButtonData));
				memset(bd,0,sizeof(ButtonData));

				GetDlgItemText(hdlg, IDC_MENUNAME, namebuff, _countof(namebuff));

				bd->dwOPPos=TreeView_GetCount(hMenuTree)-1;
				bd->pszOpName=mir_tstrlen(namebuff)?mir_tstrdup(namebuff):mir_tstrdup(TranslateT("New Menu Entry"));
				bd->pszOpValue=mir_tstrdup(bd->pszOpName);
				bd->fEntryOpType=!mir_tstrcmp(namebuff,_T("---"))?QMF_EX_SEPARATOR:0;
				bd->dwOPFlags=QMF_NEW;
				bd->pszName=NULL;
				bd->pszValue=NULL;


				tvi.mask=TVIF_HANDLE|TVIF_PARAM;

				TreeView_GetItem(hButtonsList,&tvi);

				sl=((ListData*)tvi.lParam)->sl;

				List_InsertPtr(sl,bd);

				tvis.hParent = NULL;
				tvis.hInsertAfter = TVI_LAST;
				tvis.item.mask=TVIF_PARAM|TVIF_TEXT;
				tvis.item.pszText=bd->pszOpName;
				tvis.item.lParam=(LPARAM)bd;
				TreeView_SelectItem(hMenuTree,TreeView_InsertItem(hMenuTree,&tvis));
			}break;

		case IDC_MTREEREMOVE:
			{
				TVITEM tvi;
				TVINSERTSTRUCT tvis;
				HTREEITEM hti=NULL;
				ButtonData *bd=NULL;
				tvi.mask=TVIF_HANDLE|TVIF_PARAM;
				if (!(tvi.hItem=TreeView_GetSelection(hMenuTree)))
					break;
				TreeView_GetItem(hMenuTree,&tvi);
				hti=tvi.hItem;

				bd= (ButtonData*)tvi.lParam;
				bd->dwOPFlags|=QMF_DELETNEEDED;			

				if(tvi.hItem=TreeView_GetChild(hMenuTree,tvi.hItem)) {
					TCHAR strbuf[128];
					while(tvi.hItem){
						tvis.hInsertAfter=hti;
						tvi.pszText = strbuf;
						tvi.cchTextMax = _countof(strbuf);
						tvi.mask=TVIF_HANDLE|TVIF_PARAM|TVIF_TEXT;

						TreeView_GetItem(hMenuTree,&tvi); 
						tvis.hParent=NULL;
						tvis.item=tvi;
						TreeView_InsertItem(hMenuTree,&tvis);
						tvi.hItem=TreeView_GetNextSibling(hMenuTree,tvi.hItem);
					}
				}

				TreeView_DeleteItem(hMenuTree,hti);
				if (!TreeView_GetCount(hMenuTree)) {
					EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE);
					EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE);
					EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE);
					SetDlgItemText(hdlg, IDC_MENUVALUE, _T(""));
				}
			}break;
		}
		break;

	case WM_CLOSE:
		EndDialog(hdlg,0);
		return 0;
	}
	if (HIWORD(wparam)==BN_CLICKED && GetFocus()==(HWND)lparam)
		SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
	else if ((HIWORD(wparam) == EN_CHANGE)&&(GetFocus()==(HWND)lparam))
		if (!bOptionsInit)	SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);

	return 0;
}
Beispiel #12
0
BOOL
FreeDriveInfoStructures(
    HWND hWnd
    )
/*++

Routine Description:

    Walks the tree in the tree view window, freeing DRIVE_INFO objects.

Arguments:

    hWnd - tab window handle

Return Value:

    BOOL    true if successful
--*/

{
   HWND hWndTree = GetDlgItem(hWnd, IDC_TV_DRIVE_LIST);
   TV_ITEM tvi;
   TV_ITEM tviChild;
   LPDRIVE_INFO lpdi;

   tvi.mask = tviChild.mask = TVIF_HANDLE | TVIF_PARAM;

   tvi.hItem = TreeView_GetRoot( hWndTree );
   tvi.hItem = TreeView_GetChild( hWndTree, tvi.hItem);

   //
   // Walk the TreeView, freeing memory associated with the tvis.item.lParam
   //

   while( tvi.hItem ){

      if ( TreeView_GetItem(hWndTree, &tvi) ){

         //
         // If we have found a pointer to a DRIVE_INFO, free it
         //

         lpdi = (LPDRIVE_INFO) tvi.lParam;

         if( ( lpdi != NULL ) && ( CheckSignature( lpdi ) ) ){

             FreeObject( lpdi );

         }

      }

      //
      // Check the children as well
      //

      tviChild.hItem = TreeView_GetChild( hWndTree, tvi.hItem);

      while( tviChild.hItem ) {

         if ( TreeView_GetItem(hWndTree, &tviChild) ){

            //
            // If we have found a pointer to a DRIVE_INFO, free it
            //

            lpdi = (LPDRIVE_INFO) tviChild.lParam;

            if( ( lpdi != NULL ) && ( CheckSignature( lpdi ) ) ){

               FreeObject( lpdi );

            }
         }

         tviChild.hItem = TreeView_GetNextSibling(hWndTree, tviChild.hItem);

      }

      //
      // Get next tree item
      //

      tvi.hItem = TreeView_GetNextSibling(hWndTree, tvi.hItem);

   }

   return(TRUE);

}
BOOL addInfoToListView(HTREEITEM hParent)
{
	HIMAGELIST himl1 = ListView_GetImageList(hwndListView, LVSIL_SMALL);
	HIMAGELIST himl2 = ListView_GetImageList(hwndListView, LVSIL_NORMAL);

	SHFILEINFO psfi;
	LV_ITEM		lvItem;		// Cau truc mo ta 1 Item cua ListView
	int			nItem;
	TVITEM		kq;
	TCHAR		szText[PATHFILE_MAX_LEN];
	int			index = 0; // index cua item cua ListView
	HTREEITEM	hItem;
	// Tao gia tri ban dau cho thu muc hien hanh
	HienHanh.iFolderCount = 0; // So thu muc con co trong thu muc hien hanh
	HienHanh.iKichThuoc = 0;
	HienHanh.iFileCount = 0;
	// Xoa noi dung cu cua ListView
	ListView_DeleteAllItems(hwndListView);

	for (int i = 0; i < ImageList_GetImageCount(himl1); ++i)
	{
		DestroyIcon(ImageList_GetIcon(himl1, i, 0));
		DestroyIcon(ImageList_GetIcon(himl2, i, 0));
	}
	ImageList_RemoveAll(himl1);
	ImageList_RemoveAll(himl2);

	// Khoi tao cac gia tri cho item
	lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
	kq.mask = TVIF_TEXT | TVIF_PARAM;
	kq.pszText = szText;
	kq.cchTextMax = PATHFILE_MAX_LEN;
	// Them thu muc vao ListView
	if (hItem = TreeView_GetChild(hwndTreeView, hParent))
	{
		do
		{
			kq.hItem = hItem;
			TreeView_GetItem(hwndTreeView, &kq);
			
			SHGetFileInfo((TCHAR*) kq.lParam, 0, &psfi, sizeof ( SHFILEINFO ), SHGFI_ICON 
				| SHGFI_SMALLICON);
			ImageList_AddIcon(himl1, psfi.hIcon);	
			
			SHGetFileInfo((TCHAR*) kq.lParam, 0, &psfi, sizeof ( SHFILEINFO ), SHGFI_ICON 
				| SHGFI_LARGEICON);
			ImageList_AddIcon(himl2, psfi.hIcon);	

			lvItem.pszText = szText;
			lvItem.iItem = index;
			lvItem.iImage = ImageList_GetImageCount(himl1) - 1;
			lvItem.iSubItem = 0;
			
			// Field lParam duoc dung trong ham so sanh (pfnCompare) khi can sort item
			// Truong hop nay, ta nen luu lai index cua item
			lvItem.lParam = index;  
			// Chen item vao ListView
			nItem = ListView_InsertItem(hwndListView, &lvItem);
			if(nItem == -1)	
				return FALSE;
	
			// Them thong tin cua cac cot con lai (Col #1, #2, #3) cho item 
//			GetDriveType
			WIN32_FIND_DATA FindFileData;
			TCHAR temp[PATHFILE_MAX_LEN];
			
			// Lay duong dan cua thu muc
			wcscpy_s(temp, (TCHAR*) kq.lParam);
			temp[wcslen(temp) - 1] = '\0';
			
			if (wcslen(temp) == 2 && temp[1] == ':') // O dia
			{
				// Thong tin cua o dia
			}
			else
			{
				HANDLE hFind = FindFirstFile(temp, &FindFileData);
				if (hFind == INVALID_HANDLE_VALUE) 
				{
					int t = GetLastError();
					if (t == 21 // O CD, Floppy disk chua co dia
					  || t == 2) // Khong tim thay file nao, tuc o dia rong
					  continue;
					// Loi chua xac dinh
					ErrorExit(_T("\"addInfoToListView() FindFirstFile\""));
				}
				
				TCHAR szItemText[LISTVIEW_ITEM_MAX_LEN];
				// Con tro ham
				ham f[3] = {GetSize,
							GetAttribute,
							GetDateModified};

				++HienHanh.iFolderCount;
				TCHAR *temp1;
				for(int c = 0; c < 3; c++)
				{
					temp1 = f[c](&FindFileData);
					wcscpy_s(szItemText, temp1);
					
					LV_ITEM		lvsItem;	
					lvsItem.mask = LVIF_TEXT;// | LVIF_IMAGE;
					lvsItem.iItem=nItem;
					lvsItem.iSubItem=c + 1;
					lvsItem.pszText=szItemText;
				//	lvsItem.iImage=2;
					ListView_SetItem(hwndListView,&lvsItem);
					delete []temp1;
				}
				FindClose(hFind);
			}
			++index;
		}	
		while (hItem = TreeView_GetNextSibling(hwndTreeView, hItem));
	}
	// Them file vao ListView
	kq.mask = TVIF_PARAM;
	kq.hItem = hParent;
	TreeView_GetItem(hwndTreeView, &kq);
	HienHanh.iFileCount = LV_ThemFie((TCHAR*) kq.lParam, index); 

	CapNhatStatusBar();
	return TRUE;
}
Beispiel #14
0
// adds these folders to the treeview
void ResetTreeViewFolders(void)
{
	HWND hTreeView = GetTreeView();
	int i;
	TVITEM tvi;
	TVINSERTSTRUCT	tvs;

	HTREEITEM shti; // for current child branches

	// currently "cached" parent
	HTREEITEM hti_parent = NULL;
	int index_parent = -1;			

	TreeView_DeleteAllItems(hTreeView);

	//dprintf("Adding folders to tree ui indices %i to %i",start_index,end_index);

	tvs.hInsertAfter = TVI_SORT;

	for (i=0;i<numFolders;i++)
	{
		LPTREEFOLDER lpFolder = treeFolders[i];

		if (lpFolder->m_nParent == -1)
		{
			if (lpFolder->m_nFolderId < MAX_FOLDERS)
			{
				// it's a built in folder, let's see if we should show it
				if (GetShowFolder(lpFolder->m_nFolderId) == FALSE)
				{
					continue;
				}
			}

			tvi.mask	= TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
			tvs.hParent = TVI_ROOT;
			tvi.pszText = lpFolder->m_lpTitle;
			tvi.lParam	= (LPARAM)lpFolder;
			tvi.iImage	= GetTreeViewIconIndex(lpFolder->m_nIconId);
			tvi.iSelectedImage = 0;

#if defined(__GNUC__) /* bug in commctrl.h */
			tvs.item = tvi;
#else
			tvs.DUMMYUNIONNAME.item = tvi;
#endif

			// Add root branch
			hti_parent = TreeView_InsertItem(hTreeView, &tvs);

			continue;
		}

		// not a top level branch, so look for parent
		if (treeFolders[i]->m_nParent != index_parent)
		{
			
			hti_parent = TreeView_GetRoot(hTreeView);
			while (1)
			{
				if (hti_parent == NULL)
				{
					// couldn't find parent folder, so it's a built-in but
					// not shown folder
					break;
				}

				tvi.hItem = hti_parent;
				tvi.mask = TVIF_PARAM;
				TreeView_GetItem(hTreeView,&tvi);
				if (((LPTREEFOLDER)tvi.lParam) == treeFolders[treeFolders[i]->m_nParent])
					break;

				hti_parent = TreeView_GetNextSibling(hTreeView,hti_parent);
			}

			// if parent is not shown, then don't show the child either obviously!
			if (hti_parent == NULL)
				continue;

			index_parent = treeFolders[i]->m_nParent;
		}

		tvi.mask	= TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
		tvs.hParent = hti_parent;
		tvi.iImage	= GetTreeViewIconIndex(treeFolders[i]->m_nIconId);
		tvi.iSelectedImage = 0;
		tvi.pszText = treeFolders[i]->m_lpTitle;
		tvi.lParam	= (LPARAM)treeFolders[i];
		
#if defined(__GNUC__) /* bug in commctrl.h */
		tvs.item = tvi;
#else
		tvs.DUMMYUNIONNAME.item = tvi;
#endif
		// Add it to this tree branch
		shti = TreeView_InsertItem(hTreeView, &tvs);

	}
}
Beispiel #15
0
INT_PTR CALLBACK CFileGroups::DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
// 	OutputDebugString("%s(%08X, %s, %08X, %08X)", __FUNCTION__, hwndDlg,
// 		GetMessageName(uMsg), wParam, lParam);
	static filegroups_t *pfile_groups(0);
	static HWND hwndTVCtrl, hwndEditCtrl;
	OPENFILENAME ofn;
	TVINSERTSTRUCT tvis;
	TVITEMEX tvi;
	HTREEITEM hti, hParent, hGroup, hChild, hSel;
	char text[MAX_PATH], drive[_MAX_DRIVE], dir[_MAX_DIR], path[QMAXPATH], ext[_MAX_EXT];
	BOOL hasSelection;
	switch (uMsg) {
		case WM_INITDIALOG: {
			_ASSERTE(lParam != 0);
			if (lParam == 0) {
				EndDialog(hwndDlg, IDCANCEL);
				return FALSE;
			}
			pfile_groups = reinterpret_cast<filegroups_t *>(lParam);
			hwndTVCtrl = GetDlgItem(hwndDlg, IDC_GROUPVWR);
			_ASSERTE(hwndTVCtrl != 0);
			if (hwndTVCtrl == NULL) {
				EndDialog(hwndDlg, IDCANCEL);
				return FALSE;
			}
			hwndEditCtrl = NULL;
			for (filegroups_t::const_iterator i = pfile_groups->begin(); i != pfile_groups->end(); ++i) {
				tvis.hParent = TVI_ROOT;
				tvis.hInsertAfter = TVI_SORT;
				tvis.itemex.mask = TVIF_STATE | TVIF_TEXT;
				tvis.itemex.state = 0; //TVIS_EXPANDED;
				tvis.itemex.stateMask = 0;
				tvis.itemex.pszText = const_cast<LPTSTR>(i->first.c_str());
				hParent = TreeView_InsertItem(hwndTVCtrl, &tvis);
				_ASSERTE(hParent != NULL);
				if (hParent == NULL) continue;
				for (filegroups_t::mapped_type::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
					tvis.hParent = hParent;
					tvis.hInsertAfter = TVI_SORT;
					tvis.itemex.mask = TVIF_TEXT;
					tvis.itemex.pszText = const_cast<LPTSTR>(j->c_str());
					hti = TreeView_InsertItem(hwndTVCtrl, &tvis);
					_ASSERTE(hti != NULL);
				}
				EnableDlgItem(hwndDlg, IDADD, TreeView_GetCount(hwndTVCtrl) > 0);
				EnableDlgItem(hwndDlg, IDREMOVE, TreeView_GetSelection(hwndTVCtrl) != 0);
			}
			static const tooltip_item_t tooltips[] = {
				IDC_GROUPVWR, "You can edit group names or filenames inplace by left clicking or pressing F2 on selected item",
			};
			HWND hwndTT(CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
				WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP | TTS_BALLOON, CW_USEDEFAULT, CW_USEDEFAULT,
				CW_USEDEFAULT, CW_USEDEFAULT, hwndDlg, NULL, hInstance, NULL));
			SetWindowPos(hwndTT, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
			SendMessage(hwndTT, TTM_SETMAXTIPWIDTH, 0, static_cast<LPARAM>(400));
			SendMessage(hwndTT, TTM_SETDELAYTIME, static_cast<WPARAM>(TTDT_AUTOPOP), static_cast<LPARAM>(20000));
			TOOLINFO tt;
			memset(&tt, 0, sizeof tt);
			tt.cbSize = sizeof tt;
			tt.uFlags = TTF_SUBCLASS | TTF_IDISHWND | TTF_TRANSPARENT;
			tt.hwnd = hwndDlg;
			tt.hinst = hInstance;
			for (UINT j = 0; j < qnumber(tooltips); ++j) {
				tt.uId = reinterpret_cast<UINT_PTR>(GetDlgItem(hwndDlg, tooltips[j].uID));
				tt.lpszText = const_cast<LPTSTR>(tooltips[j].lpText);
				SendMessage(hwndTT, TTM_ADDTOOL, 0, reinterpret_cast<LPARAM>(&tt));
			}
			return TRUE;
		}
		case WM_CLOSE:
			EndDialog(hwndDlg, LOWORD(wParam));
			return TRUE;
		case WM_COMMAND:
			//if (hwndEditCtrl != NULL) return FALSE;
			switch (HIWORD(wParam)) {
				case BN_CLICKED:
					switch (LOWORD(wParam)) {
						case IDOK:
							if (hwndEditCtrl != NULL) {
								TreeView_EndEditLabelNow(hwndTVCtrl, FALSE);
								SetWindowLong(hwndDlg, DWL_MSGRESULT, TRUE);
								return TRUE;
							}
							_ASSERTE(pfile_groups != 0);
							pfile_groups->clear();
							for (hGroup = TreeView_GetRoot(hwndTVCtrl);
								hGroup != NULL; hGroup = TreeView_GetNextSibling(hwndTVCtrl, hGroup)) {
								tvi.mask = TVIF_HANDLE | TVIF_TEXT;
								tvi.hItem = hGroup;
								tvi.pszText = text;
								tvi.cchTextMax = sizeof text;
								if (TreeView_GetItem(hwndTVCtrl, &tvi)) {
									filegroups_t::iterator i(pfile_groups->insert(pfile_groups->begin(),
										filegroups_t::value_type(text, filegroups_t::mapped_type())));
									_ASSERTE(i != pfile_groups->end());
									filegroups_t::mapped_type *
										pcurrentset(i != pfile_groups->end() ? &i->second : 0);
									if (pcurrentset != 0)
										for (hChild = TreeView_GetChild(hwndTVCtrl, hGroup);
											hChild != NULL; hChild = TreeView_GetNextSibling(hwndTVCtrl, hChild)) {
											tvi.mask = TVIF_HANDLE | TVIF_TEXT;
											tvi.hItem = hChild;
											tvi.pszText = text;
											tvi.cchTextMax = sizeof text;
											if (TreeView_GetItem(hwndTVCtrl, &tvi)) {
												/*if (qfileexist(text)) */pcurrentset->insert(text);
											}
#ifdef _DEBUG
											else
												_RPTF3(_CRT_ERROR, "%s(%08X, WM_COMMAND, ...): TreeView_GetItem(%08X, ...) returned NULL\n",
													__FUNCTION__, hwndDlg, hwndTVCtrl);
#endif // _DEBUG
										}
								}
#ifdef _DEBUG
								else
									_RPTF3(_CRT_ERROR, "%s(%08X, WM_COMMAND, ...): TreeView_GetItem(%08X, ...) returned NULL\n",
										__FUNCTION__, hwndDlg, hwndTVCtrl);
#endif // _DEBUG
							}
						case IDCANCEL:
							if (hwndEditCtrl != NULL)
								TreeView_EndEditLabelNow(hwndTVCtrl, TRUE);
							else
								EndDialog(hwndDlg, LOWORD(wParam));
							SetWindowLong(hwndDlg, DWL_MSGRESULT, 0);
							return TRUE;
						case IDADD: {
							hSel = TreeView_GetSelection(hwndTVCtrl);
							if (hSel == NULL) hSel = TreeView_GetRoot(hwndTVCtrl);
							if (hSel != NULL) {
								hGroup = TreeView_GetParent(hwndTVCtrl, hSel);
								if (hGroup == NULL) hGroup = hSel;
								memset(&ofn, 0, sizeof ofn);
								ofn.lStructSize = sizeof ofn;
								ofn.hInstance = hInstance;
								ofn.hwndOwner = hwndDlg;
								ofn.lpstrTitle = CFileGroups::lpstrTitle;
								boost::scoped_array<char> FileName(new char[0x10000]);
								if (!FileName) {
									_RPTF2(_CRT_ERROR, "%s(...): failed to allocate new string of size 0x%X\n",
										__FUNCTION__, 0x10000);
									SetWindowLong(hwndDlg, DWL_MSGRESULT, 0);
									throw std::bad_alloc(); //break;
								}
								FileName[0] = 0;
								ofn.lpstrFile = FileName.get();
								ofn.nMaxFile = 0x10000;
								ofn.Flags = OFN_ENABLESIZING | OFN_EXPLORER | OFN_FORCESHOWHIDDEN |
									OFN_LONGNAMES | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST |
									OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT;
								ofn.lpstrFilter = CFileGroups::lpstrFilter;
								ofn.nFilterIndex = CFileGroups::nFilterIndex;
								ofn.lpstrDefExt = CFileGroups::lpstrDefExt;
								get_input_file_path(CPY(path));
								_splitpath(path, drive, dir, 0, 0);
								_makepath(path, drive, dir, 0, 0);
								ofn.lpstrInitialDir = path;
								ofn.nMaxFile = 0x10000;
								if (GetOpenFileName(&ofn))
									if (ofn.nFileOffset > strlen(ofn.lpstrFile))
										while (*(ofn.lpstrFile + ofn.nFileOffset)) {
											AddFile(hwndTVCtrl, hGroup, _sprintf("%s\\%s",
												ofn.lpstrFile, ofn.lpstrFile + ofn.nFileOffset).c_str());
											ofn.nFileOffset += strlen(ofn.lpstrFile + ofn.nFileOffset) + 1;
										}
									else
										AddFile(hwndTVCtrl, hGroup, ofn.lpstrFile);
								EnableDlgItem(hwndDlg, IDADD, TRUE);
								EnableDlgItem(hwndDlg, IDREMOVE, TreeView_GetSelection(hwndTVCtrl) != 0);
							}
							SetWindowLong(hwndDlg, DWL_MSGRESULT, 0);
							return TRUE;
						}
						case IDADDGROUP: {
							char *newgroup(askstr(HIST_IDENT, NULL, "New group name"));
							if (newgroup != 0 && strlen(newgroup) > 0) {
								if (strlen(newgroup) >= MAX_PATH) newgroup[MAX_PATH - 1] = 0;
								for (hGroup = TreeView_GetRoot(hwndTVCtrl);
									hGroup != NULL; hGroup = TreeView_GetNextSibling(hwndTVCtrl, hGroup)) {
									tvi.mask = TVIF_HANDLE | TVIF_TEXT;
									tvi.hItem = hGroup;
									tvi.pszText = text;
									tvi.cchTextMax = sizeof text;
									if (TreeView_GetItem(hwndTVCtrl, &tvi)) {
										if (strcmp(newgroup, text) == 0) {
											warning("Group with this name already exists");
											SetWindowLong(hwndDlg, DWL_MSGRESULT, 0);
											return FALSE;
										}
									}
#ifdef _DEBUG
									else
										_RPTF3(_CRT_ERROR, "%s(%08X, WM_COMMAND, ...): TreeView_GetItem(%08X, ...) returned NULL\n",
											__FUNCTION__, hwndDlg, hwndTVCtrl);
#endif // _DEBUG
								}
								tvis.hParent = TVI_ROOT;
								tvis.hInsertAfter = TVI_SORT;
								tvis.itemex.mask = TVIF_STATE | TVIF_TEXT;
								tvis.itemex.state = TVIS_EXPANDED;
								tvis.itemex.stateMask = 0;
								tvis.itemex.pszText = newgroup;
								hti = TreeView_InsertItem(hwndTVCtrl, &tvis);
								_ASSERTE(hti != NULL);
								if (hti != NULL) {
									TreeView_SelectItem(hwndTVCtrl, hti);
									TreeView_Expand(hwndTVCtrl, hti, TVE_EXPAND);
									EnableDlgItem(hwndDlg, IDADD, TRUE);
									EnableDlgItem(hwndDlg, IDREMOVE, TRUE);
								}
							}
							SetWindowLong(hwndDlg, DWL_MSGRESULT, 0);
							return TRUE;
						}
						case IDREMOVE:
							if ((hSel = TreeView_GetSelection(hwndTVCtrl)) != NULL) {
								if ((hParent = TreeView_GetParent(hwndTVCtrl, hSel)) == NULL
									&& TreeView_GetChild(hwndTVCtrl, hSel) != NULL) { // is group
									std::string msg("Are you sure to delete group '");
									tvi.mask = TVIF_HANDLE | TVIF_TEXT;
									tvi.hItem = hSel;
									tvi.pszText = text;
									tvi.cchTextMax = sizeof text;
									if (TreeView_GetItem(hwndTVCtrl, &tvi)) msg.append(text);
									msg.append("' and all it's files?");
									if (MessageBox(hwndDlg, msg.c_str(), "libnames matching",
										MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON1) == IDYES)
										TreeView_DeleteItem(hwndTVCtrl, hSel);
								} else  // is file or group has no files - delete without confirmation
									TreeView_DeleteItem(hwndTVCtrl, hSel);
								if (TreeView_GetCount(hwndTVCtrl) <= 0)
									EnableDlgItem(hwndDlg, IDADD, FALSE);
								EnableDlgItem(hwndDlg, IDREMOVE, TreeView_GetSelection(hwndTVCtrl) != NULL);
							}
							SetWindowLong(hwndDlg, DWL_MSGRESULT, 0);
							return TRUE;
					}
					break;
			}
			break;
		case WM_NOTIFY:
			_ASSERTE(lParam != NULL);
			if (lParam != NULL) {
//  				OutputDebugString("%s(%08X, WM_NOTIFY, ...): hwndFrom=%08X idFrom=%u code=0x%X",
//  					__FUNCTION__, hwndDlg, reinterpret_cast<LPNMHDR>(lParam)->hwndFrom, reinterpret_cast<LPNMHDR>(lParam)->idFrom,
// 					reinterpret_cast<LPNMHDR>(lParam)->code);
				switch (reinterpret_cast<LPNMHDR>(lParam)->idFrom) {
					case IDC_GROUPVWR:
						switch (reinterpret_cast<LPNMHDR>(lParam)->code) {
							case TVN_KEYDOWN:
								switch (reinterpret_cast<LPNMTVKEYDOWN>(lParam)->wVKey) {
									case VK_F2:
										if ((hSel = TreeView_GetSelection(hwndTVCtrl)) != NULL)
											TreeView_EditLabel(hwndTVCtrl, hSel);
										SetWindowLong(hwndDlg, DWL_MSGRESULT, TRUE);
										return TRUE;
									case VK_INSERT:
										SendMessage(hwndDlg, WM_COMMAND,
											(hSel = TreeView_GetSelection(hwndTVCtrl)) != NULL
											&& TreeView_GetParent(hwndTVCtrl, hSel) != NULL ?
											MAKELONG(IDADD, BN_CLICKED) : MAKELONG(IDADDGROUP, BN_CLICKED),
											reinterpret_cast<LPARAM>(hwndTVCtrl));
										SetWindowLong(hwndDlg, DWL_MSGRESULT, TRUE);
										return TRUE;
									case VK_DELETE:
										SendMessage(hwndDlg, WM_COMMAND, MAKELONG(IDREMOVE, BN_CLICKED),
											reinterpret_cast<LPARAM>(hwndTVCtrl));
										SetWindowLong(hwndDlg, DWL_MSGRESULT, TRUE);
										return TRUE;
								}
								break;
							case TVN_BEGINLABELEDIT: {
								if ((hSel = TreeView_GetSelection(hwndTVCtrl)) != NULL
									&& TreeView_GetParent(hwndTVCtrl, hSel) != NULL) {
									tvi.mask = TVIF_HANDLE | TVIF_TEXT;
									tvi.hItem = hSel;
									tvi.pszText = text;
									tvi.cchTextMax = sizeof text;
									if (TreeView_GetItem(hwndTVCtrl, &tvi)) {
										memset(&ofn, 0, sizeof ofn);
										ofn.lStructSize = sizeof ofn;
										ofn.lpstrFile = text;
										ofn.nMaxFile = sizeof text;
										_splitpath(text, drive, dir, 0, ext);
										_makepath(path, drive, dir, 0, 0);
										ofn.lpstrInitialDir = path;
										ofn.hwndOwner = hwndDlg;
										ofn.hInstance = hInstance;
										ofn.Flags = OFN_ENABLESIZING | OFN_EXPLORER | OFN_FORCESHOWHIDDEN |
											OFN_LONGNAMES | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST |
											OFN_HIDEREADONLY;
										ofn.lpstrTitle = "Change file's location";
										ofn.lpstrFilter = "all files\0*.*\0";
										ofn.nFilterIndex = 1;
										ofn.lpstrDefExt = ext;
										if (GetOpenFileName(&ofn)) {
											tvi.mask = TVIF_HANDLE | TVIF_TEXT;
											TreeView_SetItem(hwndTVCtrl, &tvi);
										}
										SetWindowLong(hwndDlg, DWL_MSGRESULT, TRUE);
										return TRUE;
									}
#ifdef _DEBUG
									else
										_RPTF2(_CRT_WARN, "%s(...): TreeView_GetItem(%08X, ...) returned NULL",
											__FUNCTION__, hwndTVCtrl);
#endif // _DEBUG
								}
								hwndEditCtrl = TreeView_GetEditControl(hwndTVCtrl);
								_ASSERTE(hwndEditCtrl != NULL);
								SendMessage(hwndEditCtrl, EM_LIMITTEXT, MAX_PATH - 1, 0);
								SetWindowLong(hwndDlg, DWL_MSGRESULT, FALSE);
								return TRUE;
							}
							case TVN_ENDLABELEDIT:
								hwndEditCtrl = NULL;
								SetWindowLong(hwndDlg, DWL_MSGRESULT,
									reinterpret_cast<LPNMTVDISPINFO>(lParam)->item.pszText != NULL
									&& strlen(reinterpret_cast<LPNMTVDISPINFO>(lParam)->item.pszText) > 0
									&& strlen(reinterpret_cast<LPNMTVDISPINFO>(lParam)->item.pszText) < MAX_PATH);
								return TRUE;
							case TVN_SELCHANGED:
								EnableDlgItem(hwndDlg, IDREMOVE, TreeView_GetSelection(hwndTVCtrl) != 0);
								return TRUE;
							//case WM_LBUTTONDBLCLCK:
							//	break;
						} // switch code
						break;
				} // switch idFrom
			} // lParam != NULL
			break;
	} // main switch
	return 0;
}
Beispiel #16
0
INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HWND hTree = GetDlgItem(hwndDlg, IDC_FILTER);

	switch (msg) {
	case WM_INITDIALOG:
	{
		TranslateDialogDefault(hwndDlg);
		bInitializing = true;
		fill_filter();

		SetWindowLongPtr(hTree, GWL_STYLE, GetWindowLongPtr(hTree, GWL_STYLE) | TVS_NOHSCROLL);

		HIMAGELIST himlButtonIcons = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32 | ILC_MASK, 2, 2);
		TreeView_SetImageList(hTree, himlButtonIcons, TVSIL_NORMAL);
		TreeView_DeleteAllItems(hTree);

		for (int i = 2; i < nII; i++) { // we don`t need it IGNORE_ALL and IGNORE_MESSAGE
			TVINSERTSTRUCT tvis = { 0 };
			int index = ImageList_AddIcon(himlButtonIcons, LoadSkinnedIcon(ii[i].icon));
			tvis.hParent = NULL;
			tvis.hInsertAfter = TVI_LAST;
			tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_STATE;
			tvis.item.lParam = (LPARAM)(ii[i].type);
			tvis.item.pszText = TranslateTS(ii[i].name);
			tvis.item.iImage = tvis.item.iSelectedImage = index;
			HTREEITEM hti = TreeView_InsertItem(hTree, &tvis);
			TreeView_SetCheckState(hTree, hti, checkState(ii[i].type));
		}

		CheckDlgButton(hwndDlg, IDC_IGNORE_IGNOREALL, bUseMirandaSettings ? BST_CHECKED : BST_UNCHECKED);
		EnableWindow(GetDlgItem(hwndDlg, IDC_FILTER), !bUseMirandaSettings);
		bInitializing = false;
	}
	return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_IGNORE_IGNOREALL:
			EnableWindow(GetDlgItem(hwndDlg, IDC_FILTER), BST_UNCHECKED == IsDlgButtonChecked(hwndDlg, IDC_IGNORE_IGNOREALL));
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;
		}
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->idFrom) {
		case 0:
			switch (((LPNMHDR)lParam)->code) {
			case PSN_APPLY:
			{
				DWORD flags = 0;
				TVITEM tvi;
				tvi.mask = TVIF_HANDLE | TBIF_LPARAM;
				HWND hTree = GetDlgItem(hwndDlg, IDC_FILTER);
				tvi.hItem = TreeView_GetRoot(hTree); //check ignore all
				while (tvi.hItem) {
					TreeView_GetItem(hTree, &tvi);
					if (TreeView_GetCheckState(hTree, tvi.hItem)) flags |= 1 << (tvi.lParam - 1);
					tvi.hItem = TreeView_GetNextSibling(hTree, tvi.hItem);
				}
				db_set_dw(NULL, MODULENAME, "Filter", flags);

				bUseMirandaSettings = IsDlgButtonChecked(hwndDlg, IDC_IGNORE_IGNOREALL) ? 1 : 0;
				db_set_b(NULL, MODULENAME, "UseMirandaSettings", bUseMirandaSettings);

				fill_filter();
			}
			}
		case IDC_FILTER:
			if (((LPNMHDR)lParam)->code == NM_CLICK)
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;
		}
	}
	return FALSE;
}
Beispiel #17
0
VOID
FilterCheckChildren(
	IN HWND hWnd,
	IN PFILTER_CONTEXT Context,
	IN PFILTER_NODE Node,
	IN HWND hWndTree,
	IN HTREEITEM Parent,
	IN BOOLEAN Check
	)
{
	HTREEITEM Handle;
	TVITEMEX Item = {0};
	TVITEMEX ParentItem = {0};
	ULONG Unchecked, Checked;
	WCHAR Buffer[MAX_PATH];

	Handle = TreeView_GetChild(hWndTree, Parent);

	Checked = INDEXTOSTATEIMAGEMASK(CHECKED);
	Unchecked = INDEXTOSTATEIMAGEMASK(UNCHECKED);

	while (Handle != NULL) {
		
		Item.mask = TVIF_STATE | TVIF_TEXT;
		Item.stateMask = TVIS_STATEIMAGEMASK ;
		Item.hItem = Handle;
		Item.pszText = Buffer;
		Item.cchTextMax = MAX_PATH;

		TreeView_GetItem(hWndTree, &Item);

		if (Check) {

			if (Item.state & Unchecked) {

				Item.state = Checked;
				TreeView_SetItemState(hWndTree, Handle, Item.state, TVIS_STATEIMAGEMASK);

				//
				// N.B. TreeView_SetItemState will incur a TVN_ITEMCHANGED notification
				// for VISTA and above systems, however, we need explicitly insert item
				// here for Windows XP/ SERVER 2003.
				//

				if (!BspIsVistaAbove()) {

					//
					// Insert item
					//

					FilterInsertListItem(hWnd, hWndTree, Node,
						               Handle, Buffer, TRUE);

					Node->NumberOfSelected += 1;
					Context->NumberOfSelected += 1;

					StringCchPrintf(Buffer, MAX_PATH, FILTER_SELECT_STRING, 
									Context->NumberOfSelected);
					SetWindowText(GetDlgItem(hWnd, IDC_STATIC), Buffer);
				}
			}
		} 
		else {
			if (Item.state & Checked) {
				
				Item.state = Unchecked;
				TreeView_SetItemState(hWndTree, Handle, Item.state, TVIS_STATEIMAGEMASK);

				if (!BspIsVistaAbove()) {

					//
					// Delete item
					//

					FilterInsertListItem(hWnd, hWndTree, Node,
						               Handle, Buffer, FALSE);

					Node->NumberOfSelected -= 1;
					Context->NumberOfSelected -= 1;

					StringCchPrintf(Buffer, MAX_PATH, FILTER_SELECT_STRING, 
									Context->NumberOfSelected);
					SetWindowText(GetDlgItem(hWnd, IDC_STATIC), Buffer);
				}
			}
		}
	
		Handle = TreeView_GetNextSibling(hWndTree, Handle);
	}

	return;
}
Beispiel #18
0
ULONG
FilterScanSelection(
	IN PDIALOG_OBJECT Object,
	OUT PLIST_ENTRY DllListHead
	)
{
	HWND hWndTree;
	HTREEITEM DllItem;
	HTREEITEM ApiItem;
	TVITEMEX Item = {0};
	ULONG ApiNumber;
	PFILTER_NODE Node;
	PBTR_FILTER BtrFilter;
	PCSP_FILTER CspFilter;
	ULONG IsChecked;
	ULONG DllCount;
	BTR_BITMAP Bitmap;

	DllCount = 0;
	InitializeListHead(DllListHead);

	hWndTree = GetDlgItem(Object->hWnd, IDC_TREE_FILTER);
	DllItem = TreeView_GetChild(hWndTree, TVI_ROOT);

	while (DllItem != NULL) {
		
		RtlZeroMemory(&Item, sizeof(Item));
		Item.mask = TVIF_PARAM;
		Item.hItem = DllItem;
		TreeView_GetItem(hWndTree, &Item);

		Node = (PFILTER_NODE)Item.lParam;

		if (!Node->NumberOfSelected) {
			DllItem = TreeView_GetNextSibling(hWndTree, DllItem);
			continue;
		}

		CspFilter = (PCSP_FILTER)SdkMalloc(sizeof(CSP_FILTER));
		RtlZeroMemory(CspFilter, sizeof(CSP_FILTER));

		BtrFilter = Node->Filter;
		CspFilter->Count = 0;
		CspFilter->FilterGuid = BtrFilter->FilterGuid;
		StringCchCopy(CspFilter->FilterName, MAX_PATH, BtrFilter->FilterName);

		BtrInitializeBitMap(&Bitmap, CspFilter->Bits, BtrFilter->ProbesCount);

		//
		// Get first child of DllItem
		//

		ApiNumber = 0;
		ApiItem = TreeView_GetChild(hWndTree, DllItem);

		while (ApiItem != NULL) {

			IsChecked = TreeView_GetCheckState(hWndTree, ApiItem);

			if (IsChecked == 1) {
				BtrSetBit(&Bitmap, ApiNumber);
				CspFilter->Count += 1;
			}

			ApiNumber += 1;
			ApiItem = TreeView_GetNextSibling(hWndTree, ApiItem);
		}
	
		ASSERT(CspFilter->Count == Node->NumberOfSelected);
		InsertTailList(DllListHead, &CspFilter->ListEntry);
		DllCount += 1;

		DllItem = TreeView_GetNextSibling(hWndTree, DllItem);
	}

	return DllCount;
}
Beispiel #19
0
VOID
FilterBuildCommand(
	IN PDIALOG_OBJECT Object
	)
{
	HWND hWndTree;
	HTREEITEM DllItem;
	HTREEITEM ApiItem;
	TVITEMEX Item = {0};
	ULONG Unchecked, Checked;
	ULONG ApiNumber;
	struct _MSP_USER_COMMAND* Command;
	struct _BTR_USER_COMMAND* BtrCommand;
	ULONG Length;
	PLIST_ENTRY ListEntry;
	ULONG Number;
	PFILTER_CONTEXT Context;
	PFILTER_NODE Node;
	PBTR_FILTER Filter;
	LIST_ENTRY FilterList;
	ULONG BitNumber;

	Context = SdkGetContext(Object, FILTER_CONTEXT);
	hWndTree = GetDlgItem(Object->hWnd, IDC_TREE_FILTER);
	DllItem = TreeView_GetChild(hWndTree, TVI_ROOT);

	Checked = INDEXTOSTATEIMAGEMASK(CHECKED);
	Unchecked = INDEXTOSTATEIMAGEMASK(UNCHECKED);
	
	InitializeListHead(&FilterList);

	while (DllItem != NULL) {
		
		RtlZeroMemory(&Item, sizeof(Item));
		Item.mask = TVIF_PARAM;
		Item.hItem = DllItem;
		TreeView_GetItem(hWndTree, &Item);

		Node = (PFILTER_NODE)Item.lParam;
		Filter = Node->Filter;

		//
		// Get first child of DllItem
		//

		ApiItem = TreeView_GetChild(hWndTree, DllItem);
		ApiNumber = 0;

		while (ApiItem != NULL) {

			ULONG IsChecked;

			RtlZeroMemory(&Item, sizeof(Item));
			Item.mask = TVIF_PARAM;
			Item.hItem = ApiItem;
			TreeView_GetItem(hWndTree, &Item);

			IsChecked = TreeView_GetCheckState(hWndTree, ApiItem);

			if ((IsChecked == 0 && Item.lParam != 0) || 
				(IsChecked == 1 && Item.lParam == 0)) {

				BtrSetBit(&Node->BitMap, ApiNumber);
				Node->Count += 1;
			} 
			
			ApiNumber += 1;
			ApiItem = TreeView_GetNextSibling(hWndTree, ApiItem);
		}
	
		if (Node->Count != 0) {
			InsertTailList(&FilterList, &Node->ListEntry);
		} else {
			SdkFree(Node);
		}

		DllItem = TreeView_GetNextSibling(hWndTree, DllItem);
	}

	//
	// Copy scanned result into MSP_USER_COMMAND's command list
	//

	Command = NULL;

	if (IsListEmpty(&FilterList) != TRUE) {

		Command = (PMSP_USER_COMMAND)SdkMalloc(sizeof(MSP_USER_COMMAND));
		RtlZeroMemory(Command, sizeof(MSP_USER_COMMAND));
		Command->CommandType = CommandProbe;
		Command->ProcessId = Context->Process->ProcessId;
		Command->Type = PROBE_FILTER;
		Command->Status = 0;
		Command->CommandCount = 0;
		Command->CommandLength = 0;
		Command->FailureCount = 0;

		InitializeListHead(&Command->CommandList);
		InitializeListHead(&Command->FailureList);

		Command->Callback = NULL;
		Command->CallbackContext = NULL;
	}

	while (IsListEmpty(&FilterList) != TRUE) {
	
		ListEntry = RemoveHeadList(&FilterList);
		Node = CONTAINING_RECORD(ListEntry, FILTER_NODE, ListEntry);	

		Length = FIELD_OFFSET(BTR_USER_COMMAND, Probe[Node->Count]);
		BtrCommand = (PBTR_USER_COMMAND)SdkMalloc(Length);
		BtrCommand->Length = Length;
		BtrCommand->Type = PROBE_FILTER;
		BtrCommand->Count = Node->Count;

		Filter = Node->Filter;
		StringCchCopyW(BtrCommand->DllName, MAX_PATH, Filter->FilterFullPath);
	
		BitNumber = 0;

		for(Number = 0; Number < Node->Count; Number += 1) {

			BOOLEAN Activate;

			BitNumber = BtrFindFirstSetBit(&Node->BitMap, BitNumber);
			Activate = BtrTestBit(&Filter->BitMap, BitNumber);

			BtrCommand->Probe[Number].Activate = !Activate;
			BtrCommand->Probe[Number].Number = BitNumber;

			BitNumber += 1;
		}

		InsertTailList(&Command->CommandList, &BtrCommand->ListEntry);
		Command->CommandCount += 1;
		Command->CommandLength += BtrCommand->Length;

		SdkFree(Node);
	}

	Context->Command = Command;
}
Beispiel #20
0
INT_PTR CALLBACK ProtoDlgProc(HWND hwnd, UINT msg, WPARAM, LPARAM lParam)
{
	HWND hwndProto = GetDlgItem(hwnd, IDC_PROTO);

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwnd);

		SetWindowLongPtr(hwndProto, GWL_STYLE, GetWindowLongPtr(hwndProto, GWL_STYLE) | TVS_NOHSCROLL);
		{
			HIMAGELIST himlCheckBoxes = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32 | ILC_MASK, 2, 2);
			HICON Icon;
			Icon = (HICON)Skin_LoadIcon(SKINICON_OTHER_NOTICK);
			ImageList_AddIcon(himlCheckBoxes, Icon);
			IcoLib_ReleaseIcon(Icon);
			Icon = (HICON)Skin_LoadIcon(SKINICON_OTHER_TICK);
			ImageList_AddIcon(himlCheckBoxes, Icon);
			IcoLib_ReleaseIcon(Icon);

			TreeView_SetImageList(hwndProto, himlCheckBoxes, TVSIL_NORMAL);
		}

		FillTree(hwndProto);
		return TRUE;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->idFrom) {
		case 0:
			if (((LPNMHDR)lParam)->code == PSN_APPLY) {

				std::ostringstream out;

				TVITEM tvi;
				tvi.hItem = TreeView_GetRoot(hwndProto);
				tvi.mask = TVIF_PARAM | TVIF_HANDLE;

				while (tvi.hItem != NULL) {
					TreeView_GetItem(hwndProto, &tvi);

					if (tvi.lParam != 0) {
						ProtocolData* ppd = (ProtocolData*)tvi.lParam;
						if (ppd->enabled && ppd->show)
							out << ppd->RealName << " ";
					}

					tvi.hItem = TreeView_GetNextSibling(hwndProto, tvi.hItem);
				}

				plSets->DisabledProtoList = out.str();
			}
			break;

		case IDC_PROTO:
			switch (((LPNMHDR)lParam)->code) {
			case TVN_DELETEITEM:
				{
					NMTREEVIEWA * pnmtv = (NMTREEVIEWA *)lParam;
					if (pnmtv && pnmtv->itemOld.lParam)
						mir_free((ProtocolData*)pnmtv->itemOld.lParam);
				}
				break;

			case NM_CLICK:
				TVHITTESTINFO hti;
				hti.pt.x = (short)LOWORD(GetMessagePos());
				hti.pt.y = (short)HIWORD(GetMessagePos());
				ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt);
				if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti)) {
					if (hti.flags & TVHT_ONITEMICON) {
						TVITEMA tvi;
						tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
						tvi.hItem = hti.hItem;
						TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);

						ProtocolData *pData = (ProtocolData*)tvi.lParam;
						if (pData->enabled) {
							tvi.iImage = tvi.iSelectedImage = !tvi.iImage;
							pData->show = tvi.iImage;
							TreeView_SetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
							SendMessage(GetParent(hwnd), PSM_CHANGED, (WPARAM)hwnd, 0);
						}
					}
				}
			}
			break;
		}
		break;
	}
	return FALSE;
}
static LRESULT CALLBACK ToolBar_OptDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
{
	static HIMAGELIST himlButtonIcons=NULL;
	static BOOL dragging=FALSE;
	static HANDLE hDragItem=NULL;
	switch (msg)
	{
	case WM_DESTROY:
		ImageList_Destroy(himlButtonIcons);
		break;
	case WM_INITDIALOG:
		{
			HWND hTree=GetDlgItem(hwndDlg,IDC_BTNORDER);
			TranslateDialogDefault(hwndDlg);
			SetWindowLong(hTree,GWL_STYLE,GetWindowLong(hTree,GWL_STYLE)|TVS_NOHSCROLL);
			{					
				himlButtonIcons=ImageList_Create(GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),ILC_COLOR32|ILC_MASK,2,2);
				TreeView_SetImageList(hTree,himlButtonIcons,TVSIL_NORMAL);
			}
			TreeView_DeleteAllItems(hTree);
			tblock;
			
			qsort(tbdat.listOfButtons->items,tbdat.listOfButtons->realCount,sizeof(MTB_BUTTONINFO *),sttSortButtons);
			{				
				int i=0;
				for (i=0; i<tbdat.listOfButtons->realCount; i++)
				{
					TVINSERTSTRUCT tvis={0};
					HTREEITEM hti;
					MTB_BUTTONINFO * mtbi = (MTB_BUTTONINFO*) tbdat.listOfButtons->items[i];
					TCHAR * szTempName=mir_a2t(mtbi->szButtonName);
					HICON hIcon = (HICON)CallService(MS_SKIN2_GETICONBYHANDLE, 0, (LPARAM)mtbi->hPrimaryIconHandle);
					int index = ImageList_AddIcon(himlButtonIcons, hIcon);
					CallService(MS_SKIN2_RELEASEICON, (WPARAM)hIcon, 0);
					tvis.hParent=NULL;
					tvis.hInsertAfter=TVI_LAST;
					tvis.item.mask=TVIF_PARAM|TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_STATE;	
					tvis.item.lParam=(LPARAM)(mtbi);
					tvis.item.pszText=TranslateTS(szTempName);
					tvis.item.iImage=tvis.item.iSelectedImage=index;
					hti=TreeView_InsertItem(hTree,&tvis);
					TreeView_SetCheckState(hTree, hti, mtbi->bVisible );
					mir_free(szTempName);
				}				
			}
			tbunlock;

			SendDlgItemMessage(hwndDlg,IDC_SPIN_W,UDM_SETRANGE,0,MAKELONG(50,10));
			SendDlgItemMessage(hwndDlg,IDC_SPIN_W,UDM_SETPOS,0,MAKELONG(ModernGetSettingByte(NULL, "ModernToolBar", "option_Bar0_BtnWidth",  SETTINGS_BARBTNWIDTH_DEFAULT),0));

			SendDlgItemMessage(hwndDlg,IDC_SPIN_H,UDM_SETRANGE,0,MAKELONG(50,10));
			SendDlgItemMessage(hwndDlg,IDC_SPIN_H,UDM_SETPOS,0,MAKELONG(ModernGetSettingByte(NULL, "ModernToolBar", "option_Bar0_BtnHeight", SETTINGS_BARBTNHEIGHT_DEFAULT),0));

			SendDlgItemMessage(hwndDlg,IDC_SPIN_S,UDM_SETRANGE,0,MAKELONG(20,0));
			SendDlgItemMessage(hwndDlg,IDC_SPIN_S,UDM_SETPOS,0,MAKELONG(ModernGetSettingByte(NULL, "ModernToolBar", "option_Bar0_BtnSpace",  SETTINGS_BARBTNSPACE_DEFAULT),0));

			CheckDlgButton(hwndDlg, IDC_CHECK_AUTOSIZE, ModernGetSettingByte(NULL, "ModernToolBar", "option_Bar0_Autosize", SETTINGS_BARAUTOSIZE_DEFAULT) ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hwndDlg, IDC_CHECK_MULTILINE, ModernGetSettingByte(NULL,"ModernToolBar", "option_Bar0_Multiline", SETTINGS_BARMULTILINE_DEFAULT) ? BST_CHECKED : BST_UNCHECKED);

			CheckDlgButton(hwndDlg, IDC_TBSHOW, ModernGetSettingByte(NULL,"CLUI","ShowButtonBar",SETTINGS_SHOWBUTTONBAR_DEFAULT) ? BST_CHECKED : BST_UNCHECKED);
			{
				int i;
				BOOL en=IsDlgButtonChecked(hwndDlg,IDC_TBSHOW);
				for (i=0; i<SIZEOF(ControlIDS); i++)
					EnableWindow(GetDlgItem(hwndDlg,ControlIDS[i]), en);
			}
			return TRUE;
		}

	case WM_NOTIFY:
		{
			switch(((LPNMHDR)lParam)->idFrom) 
			{		
			case 0: 
				{
					switch (((LPNMHDR)lParam)->code)
					{
					case PSN_APPLY:
						{
							int order=100;
							HWND hTree=GetDlgItem(hwndDlg,IDC_BTNORDER);
							int count=TreeView_GetCount(hTree);
							HTREEITEM hItem;
							sttDeleteOrderSettings();
							hItem=TreeView_GetRoot(hTree);
							do
							{
								TVITEM tvi={0};
								MTB_BUTTONINFO *mtbi;
								tvi.mask=TBIF_LPARAM|TVIF_HANDLE;
								tvi.hItem=hItem;
								TreeView_GetItem(hTree, &tvi);
								mtbi=(MTB_BUTTONINFO *)tvi.lParam;
								if (mtbi)
								{
									char szTempSetting[200];
									mir_snprintf(szTempSetting, SIZEOF(szTempSetting), "order_%s", mtbi->szButtonID);
									ModernWriteSettingDword(NULL, "ModernToolBar", szTempSetting, order);
									order+=10;
									mir_snprintf(szTempSetting, SIZEOF(szTempSetting), "visible_%s", mtbi->szButtonID);
									ModernWriteSettingByte(NULL, "ModernToolBar", szTempSetting, TreeView_GetCheckState(hTree,hItem));
								}
								hItem=TreeView_GetNextSibling(hTree,hItem);
							} while (hItem!=NULL);
							ModernWriteSettingByte(NULL,"CLUI","ShowButtonBar",(BYTE)IsDlgButtonChecked(hwndDlg,IDC_TBSHOW));
							ModernWriteSettingByte(NULL,"ModernToolBar","option_Bar0_BtnWidth", (BYTE)SendDlgItemMessage(hwndDlg,IDC_SPIN_W,UDM_GETPOS,0,0));
							ModernWriteSettingByte(NULL,"ModernToolBar","option_Bar0_BtnHeight",(BYTE)SendDlgItemMessage(hwndDlg,IDC_SPIN_H,UDM_GETPOS,0,0));
							ModernWriteSettingByte(NULL,"ModernToolBar","option_Bar0_BtnSpace", (BYTE)SendDlgItemMessage(hwndDlg,IDC_SPIN_S,UDM_GETPOS,0,0));
							ModernWriteSettingByte(NULL, "ModernToolBar", "option_Bar0_Autosize", (BYTE)IsDlgButtonChecked(hwndDlg,IDC_CHECK_AUTOSIZE));
							ModernWriteSettingByte(NULL,"ModernToolBar", "option_Bar0_Multiline", (BYTE)IsDlgButtonChecked(hwndDlg,IDC_CHECK_MULTILINE));
							
							sttReloadButtons();
							return TRUE;
						}
					}
					break;
				}
			case IDC_BTNORDER:
				{
					switch (((LPNMHDR)lParam)->code) 
					{
					case TVN_BEGINDRAGA:
					case TVN_BEGINDRAGW:
						SetCapture(hwndDlg);
						dragging=TRUE;
						hDragItem=((LPNMTREEVIEWA)lParam)->itemNew.hItem;
						TreeView_SelectItem(GetDlgItem(hwndDlg,IDC_BTNORDER),hDragItem);
						break;
					case NM_CLICK:
						{						
							TVHITTESTINFO hti;
							hti.pt.x=(short)LOWORD(GetMessagePos());
							hti.pt.y=(short)HIWORD(GetMessagePos());
							ScreenToClient(((LPNMHDR)lParam)->hwndFrom,&hti.pt);
							if(TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom,&hti))
								if(hti.flags&TVHT_ONITEMSTATEICON) 
									SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);
						};
					}
					break;
				}
			} 
			break;
		}
	case WM_MOUSEMOVE:
		{
			if(!dragging) break;
			{	
				TVHITTESTINFO hti;
				hti.pt.x=(short)LOWORD(lParam);
				hti.pt.y=(short)HIWORD(lParam);
				ClientToScreen(hwndDlg,&hti.pt);
				ScreenToClient(GetDlgItem(hwndDlg,IDC_BTNORDER),&hti.pt);
				TreeView_HitTest(GetDlgItem(hwndDlg,IDC_BTNORDER),&hti);
				if(hti.flags&(TVHT_ONITEM|TVHT_ONITEMRIGHT))
				{
					HTREEITEM it=hti.hItem;
					hti.pt.y-=TreeView_GetItemHeight(GetDlgItem(hwndDlg,IDC_BTNORDER))/2;
					TreeView_HitTest(GetDlgItem(hwndDlg,IDC_BTNORDER),&hti);
					if (!(hti.flags&TVHT_ABOVE))
						TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_BTNORDER),hti.hItem,1);
					else 
						TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_BTNORDER),it,0);
				}
				else 
				{
					if(hti.flags&TVHT_ABOVE) SendDlgItemMessage(hwndDlg,IDC_BTNORDER,WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),0);
					if(hti.flags&TVHT_BELOW) SendDlgItemMessage(hwndDlg,IDC_BTNORDER,WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),0);
					TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_BTNORDER),NULL,0);
				}
			}	
		}
		break;
	case WM_LBUTTONUP:
		{
			if(!dragging) break;
			TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_BTNORDER),NULL,0);
			dragging=0;
			ReleaseCapture();
			{	
				TVHITTESTINFO hti;
				TVITEM tvi;
				hti.pt.x=(short)LOWORD(lParam);
				hti.pt.y=(short)HIWORD(lParam);
				ClientToScreen(hwndDlg,&hti.pt);
				ScreenToClient(GetDlgItem(hwndDlg,IDC_BTNORDER),&hti.pt);
				hti.pt.y-=TreeView_GetItemHeight(GetDlgItem(hwndDlg,IDC_BTNORDER))/2;
				TreeView_HitTest(GetDlgItem(hwndDlg,IDC_BTNORDER),&hti);
				if(hDragItem==hti.hItem) break;
				if (hti.flags&TVHT_ABOVE) hti.hItem=TVI_FIRST;
				tvi.mask=TVIF_HANDLE|TVIF_PARAM;
				tvi.hItem=(HTREEITEM)hDragItem;
				TreeView_GetItem(GetDlgItem(hwndDlg,IDC_BTNORDER),&tvi);
				if(hti.flags&(TVHT_ONITEM|TVHT_ONITEMRIGHT)||(hti.hItem==TVI_FIRST)) 
				{
					TVINSERTSTRUCT tvis;
					TCHAR name[128];
					tvis.item.mask=TVIF_HANDLE|TVIF_PARAM|TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_STATE;
					tvis.item.stateMask=0xFFFFFFFF;
					tvis.item.pszText=name;
					tvis.item.cchTextMax=sizeof(name);
					tvis.item.hItem=(HTREEITEM)hDragItem;
					//tvis.item.iImage=tvis.item.iSelectedImage=((MTB_BUTTONINFO *)tvi.lParam)->bVisible;				
					TreeView_GetItem(GetDlgItem(hwndDlg,IDC_BTNORDER),&tvis.item);				
					TreeView_DeleteItem(GetDlgItem(hwndDlg,IDC_BTNORDER),hDragItem);
					tvis.hParent=NULL;
					tvis.hInsertAfter=hti.hItem;
					TreeView_SelectItem(GetDlgItem(hwndDlg,IDC_BTNORDER),TreeView_InsertItem(GetDlgItem(hwndDlg,IDC_BTNORDER),&tvis));
					SendMessage((GetParent(hwndDlg)), PSM_CHANGED, (WPARAM)hwndDlg, 0);
				}
			}
		}
		break; 
	case WM_COMMAND:
		if (LOWORD(wParam)==IDC_TBSHOW) {
			{
				int i;
				BOOL en=IsDlgButtonChecked(hwndDlg,IDC_TBSHOW);
				for (i=0; i<SIZEOF(ControlIDS); i++)
					EnableWindow(GetDlgItem(hwndDlg,ControlIDS[i]), en);
			}
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);
		} else if ( (LOWORD(wParam)==IDC_TEXT_W || 
					 LOWORD(wParam)==IDC_TEXT_H ||
					 LOWORD(wParam)==IDC_TEXT_S ) 
					&& HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0; // dont make apply enabled during buddy set crap 
		SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);
		break;
	}
	return FALSE;
}
Beispiel #22
0
HTREEITEM TreeCtrl::GetSiblingNext(HTREEITEM item) {
    HTREEITEM res = TreeView_GetNextSibling(this->hwnd, item);
    return res;
}
Beispiel #23
0
static void
cfgui_sync_node(cfgui_wnd_data * d,
                HWND hwtv,
                khui_config_node c,
                HTREEITEM hItem) {
    khui_config_node child;
    HTREEITEM hChild;
    struct cfgui_child_info * childinfo = NULL;
    khm_size n_childinfo = 0;
    khm_size nc_childinfo = 0;
    khm_size i;

    /* first, get the list of children from the treeview control */
    for (hChild = TreeView_GetChild(hwtv, hItem);
         hChild;
         hChild = TreeView_GetNextSibling(hwtv, hChild)) {

        if (n_childinfo >= nc_childinfo) {
            nc_childinfo = UBOUNDSS(n_childinfo + 1,
                                    CI_ALLOC_INCR, CI_ALLOC_INCR);
#ifdef DEBUG
            assert(nc_childinfo > n_childinfo);
#endif
            childinfo = PREALLOC(childinfo,
                                 sizeof(*childinfo) * nc_childinfo);
#ifdef DEBUG
            assert(childinfo);
#endif
        }

        ZeroMemory(&childinfo[n_childinfo],
                   sizeof(childinfo[n_childinfo]));

        childinfo[n_childinfo].hItem = hChild;
        childinfo[n_childinfo].checked = FALSE;
        n_childinfo++;
    }

    /* now, go through the list of actual nodes and make sure they
       match up */
    child = NULL;
    for (khui_cfg_get_first_child(c, &child);
         child;
         khui_cfg_get_next_release(&child)) {

        hChild = (HTREEITEM) khui_cfg_get_param(child);

        for (i=0; i < n_childinfo; i++) {
            if (childinfo[i].hItem == hChild)
                break;
        }

        if (i < n_childinfo) {
            childinfo[i].checked = TRUE;
        } else {
            /* add it to the list, so we can create the node in the
               tree view control later. */
            if (n_childinfo >= nc_childinfo) {
                nc_childinfo = UBOUNDSS(n_childinfo + 1,
                                        CI_ALLOC_INCR, CI_ALLOC_INCR);
#ifdef DEBUG
                assert(nc_childinfo > n_childinfo);
#endif
                childinfo = PREALLOC(childinfo,
                                     sizeof(*childinfo) * nc_childinfo);
#ifdef DEBUG
                assert(childinfo);
#endif
            }

            ZeroMemory(&childinfo[n_childinfo],
                       sizeof(childinfo[n_childinfo]));

            childinfo[n_childinfo].node = child;
            khui_cfg_hold(child);
            n_childinfo++;
        }
    }

    /* by this point, the childinfo list contains items of the
       following forms:

       1. childinfo[i].hItem != NULL && childinfo[i].checked == TRUE

          Corresponds to a tree view item that has a matching
          configuration node.  Nothing to do here.

       2. childinfo[i].hItem != NULL && childinfo[i].checked == FALSE

          Corresponds to a tree view item that has no matching
          configuration node.  These should be removed.

       3. childinfo[i].hItem == NULL && childinfo[i].node != NULL

          Corresponds to a configuration node that has no matching
          tree view item.  These nodes should be added.
    */

    /* first do the removals */
    for (i=0; i < n_childinfo; i++) {
        if (childinfo[i].hItem == NULL)
            break;              /* nothing more to see from this point
                                   on */
        if (!childinfo[i].checked) {
            /* remove! */
            cfgui_remove_item(hwtv, childinfo[i].hItem);
        }
    }

    /* continue from where the previous loop left off */
    for (; i < n_childinfo; i++) {
#ifdef DEBUG
        assert(childinfo[i].hItem == NULL);
        assert(childinfo[i].node != NULL);
#endif

        cfgui_add_node(d, hwtv, childinfo[i].node, c, FALSE);

        khui_cfg_release(childinfo[i].node);
        childinfo[i].node = NULL;
    }

    if (childinfo)
        PFREE(childinfo);

    /* finally recurse through to the next level */
    for (hChild = TreeView_GetChild(hwtv, hItem);
         hChild;
         hChild = TreeView_GetNextSibling(hwtv, hChild)) {

        TVITEMEX itemex;

        ZeroMemory(&itemex, sizeof(itemex));

        itemex.mask = TVIF_PARAM;
        itemex.hItem = hChild;

        TreeView_GetItem(hwtv, &itemex);

        if (itemex.lParam) {
            child = (khui_config_node) itemex.lParam;

            cfgui_sync_node(d, hwtv, child, hChild);
        }
    }
}
Beispiel #24
0
static INT_PTR CALLBACK ContactOpts(HWND hwndDlg, UINT msg, WPARAM, LPARAM lParam)
{	struct ContactOptionsData *dat;

	dat=(struct ContactOptionsData*)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
	switch (msg)
	{
		case WM_INITDIALOG:
		{	TranslateDialogDefault(hwndDlg);
			dat=(struct ContactOptionsData*)mir_alloc(sizeof(struct ContactOptionsData));
			SetWindowLongPtr(hwndDlg,GWLP_USERDATA,(LONG_PTR)dat);
			dat->dragging=0;
			SetWindowLongPtr(GetDlgItem(hwndDlg,IDC_NAMEORDER),GWL_STYLE,GetWindowLongPtr(GetDlgItem(hwndDlg,IDC_NAMEORDER),GWL_STYLE)|TVS_NOHSCROLL);
			{	TVINSERTSTRUCT tvis;
				int i;
				tvis.hParent = NULL;
				tvis.hInsertAfter = TVI_LAST;
				tvis.item.mask = TVIF_TEXT|TVIF_PARAM;
				for(i=0; i < SIZEOF(nameOrderDescr); i++ ) {
					tvis.item.lParam = nameOrder[i];
					tvis.item.pszText = TranslateTS( nameOrderDescr[ nameOrder[i]] );
					TreeView_InsertItem( GetDlgItem(hwndDlg,IDC_NAMEORDER), &tvis );
			}	}
			return TRUE;
		}
		case WM_NOTIFY:
			switch (((LPNMHDR)lParam)->idFrom) {
				case 0:
					if (((LPNMHDR)lParam)->code == PSN_APPLY)
					{	DBCONTACTWRITESETTING cws;
						TVITEM tvi;
						int i;
						cws.szModule = "Contact";
						cws.szSetting = "NameOrder";
						cws.value.type = DBVT_BLOB;
						cws.value.cpbVal = SIZEOF(nameOrderDescr);
						cws.value.pbVal = nameOrder;
						tvi.hItem = TreeView_GetRoot(GetDlgItem(hwndDlg,IDC_NAMEORDER));
						i=0;
						while( tvi.hItem != NULL ) {
							tvi.mask = TVIF_PARAM | TVIF_HANDLE;
							TreeView_GetItem( GetDlgItem(hwndDlg,IDC_NAMEORDER), &tvi );
							nameOrder[i++] = (BYTE)tvi.lParam;
							tvi.hItem = TreeView_GetNextSibling(GetDlgItem(hwndDlg,IDC_NAMEORDER),tvi.hItem);
						}
						CallService(MS_DB_CONTACT_WRITESETTING,(WPARAM)(HANDLE)NULL,(LPARAM)&cws);
						CallService(MS_CLIST_INVALIDATEDISPLAYNAME,(WPARAM)INVALID_HANDLE_VALUE,0);
					}
					break;
				case IDC_NAMEORDER:
					if (((LPNMHDR)lParam)->code == TVN_BEGINDRAGA) {
						LPNMTREEVIEWA notify = (LPNMTREEVIEWA)lParam;
						if ( notify->itemNew.lParam==0 || notify->itemNew.lParam == SIZEOF(nameOrderDescr)-1 )
							break;
						SetCapture(hwndDlg);
						dat->dragging=1;
						dat->hDragItem=((LPNMTREEVIEW)lParam)->itemNew.hItem;
						TreeView_SelectItem(GetDlgItem(hwndDlg,IDC_NAMEORDER),dat->hDragItem);
					}
					break;
			}
			break;
		case WM_MOUSEMOVE:
			if(!dat->dragging) break;
			{	TVHITTESTINFO hti;
				hti.pt.x=(short)LOWORD(lParam);
				hti.pt.y=(short)HIWORD(lParam);
				ClientToScreen(hwndDlg,&hti.pt);
				ScreenToClient(GetDlgItem(hwndDlg,IDC_NAMEORDER),&hti.pt);
				TreeView_HitTest(GetDlgItem(hwndDlg,IDC_NAMEORDER),&hti);
				if(hti.flags&(TVHT_ONITEM|TVHT_ONITEMRIGHT)) {
					hti.pt.y-=TreeView_GetItemHeight(GetDlgItem(hwndDlg,IDC_NAMEORDER))/2;
					TreeView_HitTest(GetDlgItem(hwndDlg,IDC_NAMEORDER),&hti);
					TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_NAMEORDER),hti.hItem,1);
				}
				else {
					if(hti.flags&TVHT_ABOVE) SendDlgItemMessage(hwndDlg,IDC_NAMEORDER,WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),0);
					if(hti.flags&TVHT_BELOW) SendDlgItemMessage(hwndDlg,IDC_NAMEORDER,WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),0);
					TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_NAMEORDER),NULL,0);
				}
			}
			break;
		case WM_LBUTTONUP:
			if(!dat->dragging) break;
			TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_NAMEORDER),NULL,0);
			dat->dragging=0;
			ReleaseCapture();
			{	TVHITTESTINFO hti;
				TVITEM tvi;
				hti.pt.x=(short)LOWORD(lParam);
				hti.pt.y=(short)HIWORD(lParam);
				ClientToScreen(hwndDlg,&hti.pt);
				ScreenToClient(GetDlgItem(hwndDlg,IDC_NAMEORDER),&hti.pt);
				hti.pt.y-=TreeView_GetItemHeight(GetDlgItem(hwndDlg,IDC_NAMEORDER))/2;
				TreeView_HitTest(GetDlgItem(hwndDlg,IDC_NAMEORDER),&hti);
				if(dat->hDragItem==hti.hItem) break;
				tvi.mask=TVIF_HANDLE|TVIF_PARAM;
				tvi.hItem=hti.hItem;
				TreeView_GetItem(GetDlgItem(hwndDlg,IDC_NAMEORDER),&tvi);
				if(tvi.lParam == SIZEOF(nameOrderDescr)-1) break;
				if(hti.flags&(TVHT_ONITEM|TVHT_ONITEMRIGHT)) {
					TVINSERTSTRUCT tvis;
					TCHAR name[128];
					tvis.item.mask=TVIF_HANDLE|TVIF_PARAM|TVIF_TEXT|TVIF_PARAM;
					tvis.item.stateMask=0xFFFFFFFF;
					tvis.item.pszText=name;
					tvis.item.cchTextMax=SIZEOF(name);
					tvis.item.hItem=dat->hDragItem;
					TreeView_GetItem(GetDlgItem(hwndDlg,IDC_NAMEORDER),&tvis.item);
					TreeView_DeleteItem(GetDlgItem(hwndDlg,IDC_NAMEORDER),dat->hDragItem);
					tvis.hParent=NULL;
					tvis.hInsertAfter=hti.hItem;
					TreeView_SelectItem(GetDlgItem(hwndDlg,IDC_NAMEORDER),TreeView_InsertItem(GetDlgItem(hwndDlg,IDC_NAMEORDER),&tvis));
					SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				}
			}
			break;
		case WM_DESTROY:
			mir_free(dat);
			break;
	}
	return FALSE;
}
Beispiel #25
0
static void RebuildPageTree(HWND hdlg, OptionsDlgData *dat)
{
	BOOL bRemoveFocusFromFilter = FALSE;
	HINSTANCE FilterInst = NULL;

	LPARAM oldSel = SendDlgItemMessage(hdlg, IDC_KEYWORD_FILTER, CB_GETEDITSEL, 0, 0);
	GetDlgItemText(hdlg, IDC_KEYWORD_FILTER, dat->szFilterString, SIZEOF(dat->szFilterString));

	//if filter string is set to all modules then make the filter string empty (this will return all modules)
	if (_tcscmp(dat->szFilterString, TranslateT(ALL_MODULES_FILTER)) == 0) {
		dat->szFilterString[0] = 0;
		bRemoveFocusFromFilter = TRUE;
	}
	//if filter string is set to core modules replace it with the name of the executable (this will return all core modules)
	else if (_tcscmp(dat->szFilterString, TranslateT(CORE_MODULES_FILTER)) == 0) {
		//replace string with process name - that will show core settings
		TCHAR szFileName[300];
		GetModuleFileName(NULL, szFileName, SIZEOF(szFileName));
		TCHAR *pos = _tcsrchr(szFileName, _T('\\'));
		if (pos)
			pos++;
		else
			pos = szFileName;

		_tcsncpy(dat->szFilterString, pos, SIZEOF(dat->szFilterString));
	}
	else {
		int sel = SendMessage(GetDlgItem(hdlg, IDC_KEYWORD_FILTER), (UINT)CB_GETCURSEL, 0, 0);
		if (sel != -1) {
			HINSTANCE hinst = (HINSTANCE)SendMessage(GetDlgItem(hdlg, IDC_KEYWORD_FILTER), (UINT)CB_GETITEMDATA, sel, 0);
			TCHAR szFileName[300];
			GetModuleFileName(hinst, szFileName, SIZEOF(szFileName));
			TCHAR *pos = _tcsrchr(szFileName, _T('\\'));
			if (pos) pos++;
			else pos = szFileName;
			_tcsncpy(dat->szFilterString, pos, SIZEOF(dat->szFilterString));
		}
	}

	_tcslwr_locale(dat->szFilterString); //all strings are stored as lowercase ... make sure filter string is lowercase too

	HWND hwndTree = GetDlgItem(hdlg, IDC_PAGETREE);
	SendMessage(hwndTree, WM_SETREDRAW, FALSE, 0);

	HWND oldWnd = NULL;
	HWND oldTab = NULL;

	OptionsPageData *opd = dat->getCurrent();
	if (opd != NULL) {
		oldWnd = opd->hwnd;
		if (opd->insideTab)
			oldTab = GetDlgItem(hdlg, IDC_TAB);
	}

	dat->hCurrentPage = NULL;

	TreeView_SelectItem(hwndTree, NULL);
	TreeView_DeleteAllItems(hwndTree);

	TVINSERTSTRUCT tvis;
	tvis.hParent = NULL;
	tvis.hInsertAfter = TVI_SORT;
	tvis.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
	tvis.item.state = tvis.item.stateMask = TVIS_EXPANDED;
	for (int i = 0; i < dat->arOpd.getCount(); i++) {
		static TCHAR *fullTitle = NULL;
		mir_free(fullTitle); fullTitle = NULL;
		if (!CheckPageShow(hdlg, dat, i))
			continue;

		opd = dat->arOpd[i];
		TCHAR *ptszGroup = TranslateTH(opd->hLangpack, opd->ptszGroup);
		TCHAR *ptszTitle = opd->getString(opd->ptszTitle);
		TCHAR *ptszTab = TranslateTH(opd->hLangpack, opd->ptszTab);

		tvis.hParent = NULL;
		if (FilterInst != NULL) {
			size_t sz = ptszGroup ? _tcslen(ptszGroup) + 1 : 0;
			if (sz) sz += 3;
			sz += ptszTitle ? _tcslen(ptszTitle) + 1 : 0;
			fullTitle = (TCHAR*)mir_alloc(sz*sizeof(TCHAR));
			mir_sntprintf(fullTitle, sz, (ptszGroup && ptszTitle) ? _T("%s - %s") : _T("%s%s"),
				ptszGroup ? ptszGroup : _T(""),
				ptszTitle ? ptszTitle : _T(""));
		}
		TCHAR *useTitle = fullTitle ? fullTitle : ptszTitle;
		if (ptszGroup != NULL && FilterInst == NULL) {
			tvis.hParent = FindNamedTreeItemAtRoot(hwndTree, ptszGroup);
			if (tvis.hParent == NULL) {
				tvis.item.lParam = -1;
				tvis.item.pszText = ptszGroup;
				tvis.hParent = TreeView_InsertItem(hwndTree, &tvis);
			}
		}
		else {
			TVITEM tvi;
			tvi.hItem = FindNamedTreeItemAtRoot(hwndTree, useTitle);
			if (tvi.hItem != NULL) {
				if (i == dat->currentPage) dat->hCurrentPage = tvi.hItem;
				tvi.mask = TVIF_PARAM;
				TreeView_GetItem(hwndTree, &tvi);
				if (tvi.lParam == -1) {
					tvi.lParam = i;
					TreeView_SetItem(hwndTree, &tvi);
					continue;
				}
			}
		}

		if (ptszTab != NULL) {
			HTREEITEM hItem;
			if (tvis.hParent == NULL)
				hItem = FindNamedTreeItemAtRoot(hwndTree, useTitle);
			else
				hItem = FindNamedTreeItemAtChildren(hwndTree, tvis.hParent, useTitle);
			if (hItem != NULL) {
				if (i == dat->currentPage) {
					TVITEM tvi;
					tvi.hItem = hItem;
					tvi.mask = TVIF_PARAM;
					tvi.lParam = dat->currentPage;
					TreeView_SetItem(hwndTree, &tvi);
					dat->hCurrentPage = hItem;
				}
				continue;
			}
		}

		tvis.item.pszText = useTitle;
		tvis.item.lParam = i;
		opd->hTreeItem = TreeView_InsertItem(hwndTree, &tvis);
		if (i == dat->currentPage)
			dat->hCurrentPage = opd->hTreeItem;

		if (fullTitle) mir_free(fullTitle);
		fullTitle = NULL;
	}

	char str[128];
	TVITEMA tvi;
	tvi.mask = TVIF_TEXT | TVIF_STATE;
	tvi.pszText = str;
	tvi.cchTextMax = SIZEOF(str);
	tvi.hItem = TreeView_GetRoot(hwndTree);
	while (tvi.hItem != NULL) {
		if (SendMessageA(hwndTree, TVM_GETITEMA, 0, (LPARAM)&tvi)) {
			char buf[130];
			mir_snprintf(buf, SIZEOF(buf), "%s%s", OPTSTATE_PREFIX, str);
			if (!db_get_b(NULL, "Options", buf, 1))
				TreeView_Expand(hwndTree, tvi.hItem, TVE_COLLAPSE);
		}
		tvi.hItem = TreeView_GetNextSibling(hwndTree, tvi.hItem);
	}

	if (dat->hCurrentPage == NULL) {
		dat->hCurrentPage = TreeView_GetRoot(hwndTree);
		dat->currentPage = -1;
	}
	TreeView_SelectItem(hwndTree, dat->hCurrentPage);

	if (oldWnd) {
		opd = dat->getCurrent();
		if (opd && oldWnd != opd->hwnd) {
			ShowWindow(oldWnd, SW_HIDE);
			if (oldTab && (opd == NULL || !opd->insideTab))
				ShowWindow(oldTab, SW_HIDE);
		}
	}

	if (dat->szFilterString[0] == 0) // Clear the keyword combo box
		SetWindowText(GetDlgItem(hdlg, IDC_KEYWORD_FILTER), _T(""));
	if (!bRemoveFocusFromFilter)
		SetFocus(GetDlgItem(hdlg, IDC_KEYWORD_FILTER)); //set the focus back to the combo box

	SendDlgItemMessage(hdlg, IDC_KEYWORD_FILTER, CB_SETEDITSEL, 0, oldSel); //but don't select any of the text

	SendMessage(hwndTree, WM_SETREDRAW, TRUE, 0);
	TreeView_EnsureVisible(hwndTree, dat->hCurrentPage);
}
Beispiel #26
0
static BOOL BrsFolder_OnSetExpanded(browse_info *info, LPVOID selection,
    BOOL is_str, HTREEITEM *pItem)
{
    LPITEMIDLIST pidlSelection = (LPITEMIDLIST)selection;
    LPCITEMIDLIST pidlCurrent, pidlRoot;
    TVITEMEXW item;
    BOOL bResult = FALSE;

    /* If 'selection' is a string, convert to a Shell ID List. */
    if (is_str) {
        IShellFolder *psfDesktop;
        HRESULT hr;

        hr = SHGetDesktopFolder(&psfDesktop);
        if (FAILED(hr))
            goto done;

        hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL,
                     (LPOLESTR)selection, NULL, &pidlSelection, NULL);
        IShellFolder_Release(psfDesktop);
        if (FAILED(hr))
            goto done;
    }

    /* Move pidlCurrent behind the SHITEMIDs in pidlSelection, which are the root of
     * the sub-tree currently displayed. */
    pidlRoot = info->lpBrowseInfo->pidlRoot;
    pidlCurrent = pidlSelection;
    while (!_ILIsEmpty(pidlRoot) && _ILIsEqualSimple(pidlRoot, pidlCurrent)) {
        pidlRoot = ILGetNext(pidlRoot);
        pidlCurrent = ILGetNext(pidlCurrent);
    }

    /* The given ID List is not part of the SHBrowseForFolder's current sub-tree. */
    if (!_ILIsEmpty(pidlRoot))
        goto done;

    /* Initialize item to point to the first child of the root folder. */
    memset(&item, 0, sizeof(item));
    item.mask = TVIF_PARAM;
    item.hItem = TreeView_GetRoot(info->hwndTreeView);
    if (item.hItem)
        item.hItem = TreeView_GetChild(info->hwndTreeView, item.hItem);

    /* Walk the tree along the nodes corresponding to the remaining ITEMIDLIST */
    while (item.hItem && !_ILIsEmpty(pidlCurrent)) {
        LPTV_ITEMDATA pItemData;

        SendMessageW(info->hwndTreeView, TVM_GETITEMW, 0, (LPARAM)&item);
        pItemData = (LPTV_ITEMDATA)item.lParam;

        if (_ILIsEqualSimple(pItemData->lpi, pidlCurrent)) {
            pidlCurrent = ILGetNext(pidlCurrent);
            if (!_ILIsEmpty(pidlCurrent)) {
                /* Only expand current node and move on to it's first child,
                 * if we didn't already reach the last SHITEMID */
                SendMessageW(info->hwndTreeView, TVM_EXPAND, TVE_EXPAND, (LPARAM)item.hItem);
                item.hItem = TreeView_GetChild(info->hwndTreeView, item.hItem);
            }
        } else {
            item.hItem = TreeView_GetNextSibling(info->hwndTreeView, item.hItem);
        }
    }

    if (_ILIsEmpty(pidlCurrent) && item.hItem)
        bResult = TRUE;

done:
    if (pidlSelection && pidlSelection != (LPITEMIDLIST)selection)
        ILFree(pidlSelection);

    if (pItem)
        *pItem = item.hItem;

    return bResult;
}
Beispiel #27
0
HTREEITEM
FindOrAddTreeViewItem ( HWND        hWndTV,
                        LPTV_INSERTSTRUCT lpis
                        )
/*++

Routine Description:

 FindOrAddTreeViewItem: This function will add an item to
                        a TreeView in the right spot. You
                        must specify the parent node of where
                        this item is to be added, and then
                        this function will check to see if a
                        node already exists with this name.
                        If a node with this name already
                        exists, then its handle is returned.
                        If the node does not exist, then the
                        AddTreeViewItem function from
                        above is called to add the item.
                        See how this function is used
                        in the FillTreeView function down
                        below.

Arguments:

    none

Return Value:

    none

--*/

{
  TV_ITEM               tvItem;        // Temporary item
  HTREEITEM             hItem;         // Handle to item
  TCHAR                 szBuffer[512]; // Temporary buffer

  // Get the first child of the passed in parent
  hItem = TreeView_GetChild ( hWndTV, lpis->hParent );

  // Loop through all children, looking for an already existing
  // child.

  while ( hItem )
    {
    tvItem.mask       = TVIF_TEXT;        // We want the text
    tvItem.hItem      = hItem;            // Indicate the item to fetch
    tvItem.pszText    = szBuffer;         // Indicate the buffer
    tvItem.cchTextMax = sizeof(szBuffer); // Indicate buffer's size

    TreeView_GetItem ( hWndTV, &tvItem ); // Get Text

    if (!lstrcmpi (tvItem.pszText, lpis->item.pszText)) // Found it! Just return item
      return hItem;

    // Get the next sibling item in the TreeView, if any.
    hItem = TreeView_GetNextSibling ( hWndTV, hItem );
    }

  // If we made it here, then the item needs to be added
  // onto the end of the list

  return AddTreeViewItem ( hWndTV,        // Handle of TreeView
                           lpis           // pass through the original TV_INSERTSTRUCT
                         );
}
Beispiel #28
0
void TraverseTreebarItems(void)
{
	SetWindowRedraw(Dcx::mIRC.getTreeview(), FALSE);
	TString buf((UINT)MIRC_BUFFER_SIZE_CCH);
	TString res;
	TVITEMEX item;
	ZeroMemory(&item, sizeof(item));
	for (HTREEITEM ptvitem = TreeView_GetRoot(Dcx::mIRC.getTreeview()); ptvitem != NULL; ptvitem = TreeView_GetNextSibling(Dcx::mIRC.getTreeview(), ptvitem)) {
		item.hItem = ptvitem;
		item.pszText = buf.to_chr();
		item.cchTextMax = MIRC_BUFFER_SIZE_CCH;
		item.mask = TVIF_TEXT|TVIF_PARAM;
		if (TreeView_GetItem(Dcx::mIRC.getTreeview(), &item))
		{
			{
				TString tsType;
				DcxDock::getTreebarItemType(tsType, item.lParam);
				Dcx::mIRC.execex("/!set -nu1 %%dcx_%d %s", item.lParam, item.pszText );
				Dcx::mIRC.tsEvalex(res, "$xtreebar_callback(geticons,%s,%%dcx_%d)", tsType.to_chr(), item.lParam);
			}
			item.mask = TVIF_IMAGE|TVIF_SELECTEDIMAGE;
			int i = res.gettok( 1 ).to_int() -1;
			if (i < 0)
				i = 0;
			item.iImage = i;
			i = res.gettok( 2 ).to_int() -1;
			if (i < 0)
				i = 0;
			item.iSelectedImage = i;
			TreeView_SetItem(Dcx::mIRC.getTreeview(), &item);
		}
		TraverseChildren(ptvitem, buf, res, &item);
	}
	SetWindowRedraw(Dcx::mIRC.getTreeview(), TRUE);
}
Beispiel #29
0
HTREEITEM
CDeviceView::RecurseFindDevice(
    _In_ HTREEITEM hParentItem,
    _In_ CNode *Node
    )
{
    HTREEITEM FoundItem;
    HTREEITEM hItem;
    TVITEMW tvItem;
    CNode *FoundNode;

    // Check if this node has any children
    hItem = TreeView_GetChild(m_hTreeView, hParentItem);
    if (hItem == NULL) return NULL;

    // The lParam contains the node pointer data
    tvItem.hItem = hItem;
    tvItem.mask = TVIF_PARAM;
    if (TreeView_GetItem(m_hTreeView, &tvItem) &&
        tvItem.lParam != NULL)
    {
        // check for a matching node
        FoundNode = reinterpret_cast<CNode *>(tvItem.lParam);
        if ((FoundNode->GetNodeType() == Node->GetNodeType()) &&
            (IsEqualGUID(*FoundNode->GetClassGuid(), *Node->GetClassGuid())))
        {
            // check if this is a class node, or a device with matching ID's
            if ((FoundNode->GetNodeType() == ClassNode) ||
                (wcscmp(FoundNode->GetDeviceId(), Node->GetDeviceId()) == 0))
            {
                return hItem;
            }
        }
    }

    // This node may have its own children
    FoundItem = RecurseFindDevice(hItem, Node);
    if (FoundItem) return FoundItem;

    // Loop all the siblings
    for (;;)
    {
        // Get the next item at this level
        hItem = TreeView_GetNextSibling(m_hTreeView, hItem);
        if (hItem == NULL) break;

        // The lParam contains the node pointer data
        tvItem.hItem = hItem;
        tvItem.mask = TVIF_PARAM;
        if (TreeView_GetItem(m_hTreeView, &tvItem))
        {
            // check for a matching class
            FoundNode = reinterpret_cast<CNode *>(tvItem.lParam);
            if ((FoundNode->GetNodeType() == Node->GetNodeType()) &&
                (IsEqualGUID(*FoundNode->GetClassGuid(), *Node->GetClassGuid())))
            {
                // check if this is a class node, or a device with matching ID's
                if ((FoundNode->GetNodeType() == ClassNode) ||
                    (wcscmp(FoundNode->GetDeviceId(), Node->GetDeviceId()) == 0))
                {
                    return hItem;
                }
            }
        }

        // This node may have its own children 
        FoundItem = RecurseFindDevice(hItem, Node);
        if (FoundItem) return FoundItem;
    }

    return hItem;
}
Beispiel #30
0
void TraverseChildren(const HTREEITEM hParent, TString &buf, TString &res, LPTVITEMEX pitem)
{
	ZeroMemory(pitem, sizeof(TVITEMEX));
	for (HTREEITEM ptvitem = TreeView_GetChild(Dcx::mIRC.getTreeview(), hParent); ptvitem != NULL; ptvitem = TreeView_GetNextSibling(Dcx::mIRC.getTreeview(), ptvitem)) {
		pitem->hItem = ptvitem;
		pitem->pszText = buf.to_chr();
		pitem->cchTextMax = MIRC_BUFFER_SIZE_CCH;
		pitem->mask = TVIF_TEXT|TVIF_PARAM;
		if (TreeView_GetItem(Dcx::mIRC.getTreeview(), pitem))
		{
			{
				TString tsType;
				DcxDock::getTreebarItemType(tsType, pitem->lParam);
				Dcx::mIRC.execex("/!set -nu1 %%dcx_%d %s", pitem->lParam, pitem->pszText );
				Dcx::mIRC.tsEvalex(res, "$xtreebar_callback(geticons,%s,%%dcx_%d)", tsType.to_chr(), pitem->lParam);
			}
			pitem->mask = TVIF_IMAGE|TVIF_SELECTEDIMAGE;
			int i = res.gettok( 1 ).to_int() -1;
			if (i < 0)
				i = 0;
			pitem->iImage = i;
			i = res.gettok( 2 ).to_int() -1;
			if (i < 0)
				i = 0;
			pitem->iSelectedImage = i;
			TreeView_SetItem(Dcx::mIRC.getTreeview(), pitem);
		}
		TraverseChildren(ptvitem, buf, res, pitem);
	}
}