📄 tlmisc.c
字号:
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
TLmisc.c - memory allocation and miscellaneous routines
$Id: TLMisc.c,v 1.5 2002/09/30 14:28:42 pbj Exp $
____________________________________________________________________________*/
#include "TLintern.h"
#include <malloc.h>
#include <memory.h>
// _______________________________________________
//
// Private memory allocation routine
void*
TLAlloc (
long size)
{
void* p;
p = malloc (size);
if (!p)
MessageBox (NULL,
"Memory allocation failure", "TreeList Error", MB_OK);
else
memset (p, 0, size);
return p;
}
// _______________________________________________
//
// Private memory reallocation routine
void*
TLReAlloc (
void* p,
long size)
{
if (p)
free (p);
return (TLAlloc (size));
}
// _______________________________________________
//
// Private memory deallocation routine
void
TLFree (
void* p)
{
if (p)
free (p);
}
// _______________________________________________
//
// Return next item
static TLTreeItem*
sNextItem (
TLTreeItem* p)
{
if (p->nextItem)
return p->nextItem;
if (p->parentItem)
return (sNextItem (p->parentItem));
return NULL;
}
// _______________________________________________
//
// Return item below the specified one
static TLTreeItem*
sDownItem (
TLTreeItem* p,
BOOL bShift)
{
TLTreeItem *p2;
if (bShift)
{
if (p->nextItem)
p = p->nextItem;
}
else
{
if (p->childItem && (p->state & TLIS_EXPANDED))
return p->childItem;
if (p->nextItem)
return p->nextItem;
if (p->parentItem)
{
p2 = sNextItem (p->parentItem);
if (p2)
return (p2);
}
}
return p;
}
// _______________________________________________
//
// Return last child item of the specified item
static TLTreeItem*
sLastItem (
TLTreeItem* p)
{
if (p->childItem && (p->state & TLIS_EXPANDED))
{
p = p->childItem;
while (p->nextItem)
p = p->nextItem;
return (sLastItem (p));
}
return p;
}
// _______________________________________________
//
// Return item above the specified one
static TLTreeItem*
sUpItem (TLTreeItem* p, BOOL bShift)
{
if (bShift)
{
if (p->prevItem)
p = p->prevItem;
}
else
{
if (p->prevItem)
return sLastItem (p->prevItem);
if (p->parentItem)
return p->parentItem;
}
return p;
}
// _______________________________________________
//
// Process keyboard character
BOOL
TLKeyboardChar (
TLWndData* pWD,
WPARAM ch,
LPARAM lP)
{
TLTreeItem* p;
INT iCurrentRow, iFinalRow;
BOOL bShift, bControl;
if (pWD->style & TLS_SINGLESELECT)
{
bShift = FALSE;
bControl = FALSE;
}
else
{
bControl = FALSE;
bShift = FALSE;
if (GetKeyState (VK_SHIFT) & 0x8000)
bShift = TRUE;
else if (GetKeyState (VK_CONTROL) & 0x8000)
bControl = TRUE;
}
pWD->nmTreeList.flags = 0;
if (ch == VK_ESCAPE)
{
if (pWD->bDragging && (pWD->style & TLS_INTERNALDRAG))
{
TLEndDrag (pWD, MAKELPARAM (-1, -1));
pWD->bDragging = FALSE;
InvalidateRect (pWD->hWnd, &pWD->tlInval, TRUE);
}
}
if (pWD->focusItem)
{
switch (ch) {
case VK_DOWN :
p = sDownItem (pWD->focusItem, bShift);
/// if (p != pWD->focusItem)
{
pWD->focusItem->state &= ~TLIS_FOCUSED;
TLInvalidateItem (pWD, pWD->focusItem);
pWD->focusItem = p;
if (!bControl)
{
TLDeselectTree (pWD, pWD->rootItem, NULL);
if (!pWD->firstSelectItem)
pWD->firstSelectItem = p;
if (!bShift)
{
pWD->iNumberSelected = 1;
pWD->firstSelectItem = p;
}
else
{
pWD->iNumberSelected = 0;
TLSelectRange (pWD, pWD->rootItem, p, NULL);
}
pWD->focusItem->state |= TLIS_SELECTED;
pWD->nmTreeList.flags |= TLC_BYKEYBOARD;
}
pWD->focusItem->state |= TLIS_FOCUSED;
TLInvalidateItem (pWD, pWD->focusItem);
if (TLSelectAutoScroll (pWD, pWD->focusItem))
InvalidateRect (pWD->hWnd, &pWD->tlInval, TRUE);
}
break;
case VK_UP :
p = sUpItem (pWD->focusItem, bShift);
/// if (p != pWD->focusItem)
{
pWD->focusItem->state &= ~TLIS_FOCUSED;
TLInvalidateItem (pWD, pWD->focusItem);
pWD->focusItem = p;
if (!bControl)
{
TLDeselectTree (pWD, pWD->rootItem, NULL);
if (!pWD->firstSelectItem)
pWD->firstSelectItem = p;
if (!bShift)
{
pWD->iNumberSelected = 1;
pWD->firstSelectItem = p;
}
else
{
pWD->iNumberSelected = 0;
TLSelectRange (pWD, pWD->rootItem, p, NULL);
}
pWD->focusItem->state |= TLIS_SELECTED;
pWD->nmTreeList.flags |= TLC_BYKEYBOARD;
}
pWD->focusItem->state |= TLIS_FOCUSED;
TLInvalidateItem (pWD, pWD->focusItem);
if (TLSelectAutoScroll (pWD, pWD->focusItem))
InvalidateRect (pWD->hWnd, &pWD->tlInval, TRUE);
}
break;
case VK_LEFT :
case VK_SUBTRACT :
if (!bShift)
{
if (pWD->focusItem->state & TLIS_EXPANDED)
{
p = pWD->focusItem;
if (!bControl)
{
TLDeselectTree (pWD, pWD->rootItem, p);
pWD->iNumberSelected = 1;
p->state |= TLIS_SELECTED;
pWD->nmTreeList.flags |= TLC_BYKEYBOARD;
}
p->state &= ~TLIS_EXPANDED;
InvalidateRect (pWD->hWnd, &pWD->tlInval, TRUE);
}
else
{
if (ch != VK_SUBTRACT)
{
if (pWD->focusItem->parentItem)
{
pWD->focusItem->state &= ~TLIS_FOCUSED;
TLInvalidateItem (pWD, pWD->focusItem);
p = pWD->focusItem->parentItem;
pWD->focusItem = p;
if (!bControl)
{
TLDeselectTree (pWD, pWD->rootItem, NULL);
pWD->firstSelectItem = p;
pWD->iNumberSelected = 1;
p->state |= TLIS_SELECTED;
pWD->nmTreeList.flags |= TLC_BYKEYBOARD;
}
p->state |= TLIS_FOCUSED;
TLInvalidateItem (pWD, p);
if (TLSelectAutoScroll (pWD, p))
{
InvalidateRect (pWD->hWnd, &pWD->tlInval,
TRUE);
}
}
}
}
}
break;
case VK_RIGHT :
case VK_RETURN :
case VK_ADD :
if (!bShift)
{
if (pWD->focusItem->childItem)
{
if (pWD->focusItem->state & TLIS_EXPANDED)
{
if (ch != VK_ADD)
{
pWD->focusItem->state &= ~TLIS_FOCUSED;
TLInvalidateItem (pWD, pWD->focusItem);
p = pWD->focusItem->childItem;
pWD->focusItem = p;
if (!bControl)
{
TLDeselectTree (pWD, pWD->rootItem, NULL);
pWD->firstSelectItem = p;
pWD->iNumberSelected = 1;
p->state |= TLIS_SELECTED;
pWD->nmTreeList.flags |= TLC_BYKEYBOARD;
}
p->state |= TLIS_FOCUSED;
TLInvalidateItem (pWD, p);
if (TLSelectAutoScroll (pWD, p))
{
InvalidateRect (pWD->hWnd, &pWD->tlInval,
TRUE);
}
}
}
else
{
p = pWD->focusItem;
if (!bControl)
{
TLDeselectTree (pWD, pWD->rootItem, p);
pWD->iNumberSelected = 1;
p->state |= TLIS_SELECTED;
pWD->nmTreeList.flags |= TLC_BYKEYBOARD;
}
p->state |= TLIS_EXPANDED;
InvalidateRect (pWD->hWnd, &pWD->tlInval, TRUE);
TLExpandAutoScroll (pWD, pWD->focusItem);
}
}
}
break;
case VK_NEXT :
iCurrentRow = 0;
TLGetRow (pWD->rootItem, pWD->focusItem, &iCurrentRow);
if (iCurrentRow >= (pWD->iFirstRow + pWD->iMaxRows -1))
iFinalRow = iCurrentRow + pWD->iMaxRows -1;
else
iFinalRow = pWD->iFirstRow + pWD->iMaxRows -1;
if (iFinalRow > pWD->iExpandedRows)
iFinalRow = pWD->iExpandedRows;
p = pWD->focusItem;
while (iCurrentRow < iFinalRow)
{
p = sDownItem (p, bShift);
iCurrentRow++;
}
if (p != pWD->focusItem)
{
pWD->focusItem->state &= ~TLIS_FOCUSED;
TLInvalidateItem (pWD, pWD->focusItem);
pWD->focusItem = p;
if (bShift)
{
TLDeselectTree (pWD, pWD->rootItem, NULL);
if (!pWD->firstSelectItem) pWD->firstSelectItem = p;
pWD->iNumberSelected = 0;
TLSelectRange (pWD, pWD->rootItem, p, NULL);
}
else if (!bControl)
{
TLDeselectTree (pWD, pWD->rootItem, NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -