📄 tlmisc.c
字号:
//: TreeList memory allocation and miscellaneous routines
//
// $Id: TLMisc.c,v 1.15 1998/08/13 23:18:59 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", "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));
}
else return NULL;
}
//----------------------------------------------------|
// Private memory deallocation routine
void TLFree (void* p) {
if (p) free (p);
}
//----------------------------------------------------|
// Return next item
TLTreeItem* NextItem (TLTreeItem* p) {
if (p->nextItem) return p->nextItem;
if (p->parentItem) return (NextItem (p->parentItem));
return NULL;
}
//----------------------------------------------------|
// Return item below the specified one
TLTreeItem* DownItem (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 = NextItem (p->parentItem);
if (p2) return (p2);
}
}
return p;
}
//----------------------------------------------------|
// Return last child item of the specified item
TLTreeItem* LastItem (TLTreeItem* p) {
if (p->childItem && (p->state & TLIS_EXPANDED)) {
p = p->childItem;
while (p->nextItem) p = p->nextItem;
return (LastItem (p));
}
return p;
}
//----------------------------------------------------|
// Return item above the specified one
TLTreeItem* UpItem (TLTreeItem* p, BOOL bShift) {
if (bShift) {
if (p->prevItem) p = p->prevItem;
}
else {
if (p->prevItem) return LastItem (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 = DownItem (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);
}
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 = UpItem (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);
}
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 = DownItem (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);
}
else if (!bControl) {
TLDeselectTree (pWD, pWD->rootItem, NULL);
pWD->firstSelectItem = p;
pWD->iNumberSelected = 1;
pWD->focusItem->state |= TLIS_SELECTED;
pWD->nmTreeList.flags |= TLC_BYKEYBOARD;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -