📄 easytab.c
字号:
static int EasyTab_CalculateRowLists(TabGroup group)
{
int error = UIENoError;
ListType rowLists = NULL;
ListType sheetList = NULL;
ListType currSheetList;
Sheet sheet;
int numRows;
int numSheets;
int index;
if (group->rowLists) /* already done */
return 0;
numRows = EasyTab_CalculateNumRows(group);
nullChk( rowLists = ListCreate(sizeof(ListType)));
for (index = 1; index <= numRows; index++)
{
nullChk( sheetList = ListCreate(sizeof(Sheet)));
nullChk( ListInsertItem(rowLists, &sheetList, END_OF_LIST));
sheetList = NULL;
}
numSheets = EasyTab_NumSheets(group);
for (index = 1; index <= numSheets; index++)
{
ListGetItem(group->sheetList, &sheet, index);
if (!sheet->hidden)
{
ListGetItem(rowLists, &currSheetList, sheet->originalRow);
nullChk( ListInsertItem(currSheetList, &sheet, END_OF_LIST));
}
}
EasyTab_FreeRowLists(group);
group->rowLists = rowLists;
EasyTab_MoveActiveRowToEnd(group);
Error:
ListDispose(sheetList); /* will be NULL unless an insertion error occurred */
if (error < 0)
FreeListOfLists(rowLists);
return error;
}
/*************************************************************/
/* Returns NULL if out of memory, the rowsLists returned belong to the group and should not
be disposed by the caller
*/
static ListType EasyTab_GetRowLists(TabGroup group)
{
if (EasyTab_CalculateRowLists(group) >= 0)
return group->rowLists;
else
return NULL;
}
/*************************************************************/
static int EasyTab_NumVisibleTabsOnRow(TabGroup group, int rowIndex)
{
ListType rowLists = EasyTab_GetRowLists(group);
ListType currRowList;
int numRows;
int index;
Sheet firstSheet;
numRows = ListNumItems(rowLists);
for (index = 1; index <= numRows; index++)
{
ListGetItem(rowLists, &currRowList, index);
ListGetItem(currRowList, &firstSheet, 1);
if (firstSheet->originalRow == rowIndex)
{
int sheetIndex;
int numSheets = ListNumItems(currRowList);
Sheet currSheet;
int numVisible = 0;
for (sheetIndex = 1; sheetIndex <= numSheets; sheetIndex++)
{
ListGetItem(currRowList, &currSheet, sheetIndex);
if (!currSheet->hidden)
numVisible++;
}
return numVisible;
}
}
return 0;
}
/*************************************************************/
static int EasyTab_GetSheetDisplayPosition(TabGroup group, Sheet sheet, int *row, int *column)
{
int numRows;
ListType rowLists, currRowList;
int columnIndex, rowIndex;
int found = FALSE;
rowLists = EasyTab_GetRowLists(group);
if (rowLists)
{
numRows = ListNumItems(rowLists);
for (rowIndex = 1; rowIndex <= numRows; rowIndex++)
{
ListGetItem(rowLists, &currRowList, rowIndex);
columnIndex = ListFindItem (currRowList, &sheet, FRONT_OF_LIST, NULL);
if (columnIndex > 0)
{
found = TRUE;
break;
}
}
}
if (!found)
{
columnIndex = 0;
rowIndex = 0;
}
if (column)
*column = columnIndex;
if (row)
*row = rowIndex;
return found;
}
/*************************************************************/
static void EasyTab_MoveActiveRowToEnd(TabGroup group)
{
Sheet activeSheet;
int row;
ListType oldActiveSheetRowList;
ListType newActiveSheetRowList;
ListType rowLists;
int numRows;
/* move list of sheets on the active row to the end of the list of sheet lists so they will draw on the bottom */
rowLists = EasyTab_GetRowLists(group);
if (rowLists)
{
numRows = ListNumItems(rowLists);
activeSheet = EasyTab_GetActive(group);
if (activeSheet)
{
if (!EasyTab_GetSheetDisplayPosition(group, activeSheet, &row, NULL))
Assert(FALSE);
if (row < numRows)
{
ListRemoveItem(rowLists, &newActiveSheetRowList, row);
ListRemoveItem(rowLists, &oldActiveSheetRowList, END_OF_LIST);
ListInsertItem(rowLists, &newActiveSheetRowList, END_OF_LIST);
ListInsertItem(rowLists, &oldActiveSheetRowList, FRONT_OF_LIST);
}
}
}
}
/*************************************************************/
/* minHeight and minWidth are given in relationship to the orientation of of the buttons.
Therefore, if the buttons were on the side, the minWidth would actually be the vertical
space needed by the buttons.
*/
static int EasyTab_CalcMinButtonArea(TabGroup group, int *minHeight, int *minWidth)
{
int error = UIENoError;
int numRows;
int rowIndex;
ListType rowLists;
ListType sheetList;
int numSheets;
int sheetIndex;
Sheet sheet;
int largestRowMinWidth = 0;
int minRowWidth;
Rect minBounds;
int height = 0;
nullChk( rowLists = EasyTab_GetRowLists(group));
numRows = ListNumItems(rowLists);
for (rowIndex = numRows; rowIndex >= 1 ; rowIndex--)
{
ListGetItem(rowLists, &sheetList, rowIndex);
numSheets = ListNumItems(sheetList);
minRowWidth = 0;
for (sheetIndex = 1; sheetIndex <= numSheets; sheetIndex++)
{
ListGetItem(sheetList, &sheet, sheetIndex);
if(sheetIndex == 1)
{
TabButton_GetMinBounds(sheet->tabButton, rowIndex == 1, &minBounds);
height += minBounds.height;
}
TabButton_GetMinBounds(sheet->tabButton, sheetIndex == 1, &minBounds);
minRowWidth += minBounds.width;
}
largestRowMinWidth = Max(largestRowMinWidth, minRowWidth);
}
if (minWidth)
*minWidth = largestRowMinWidth;
if (minHeight)
*minHeight = height;
Error:
return error;
}
/*************************************************************/
/* TabButton positions are calculated relative to the frameRect of the group
(whose top,left is always 0,0 in canvas coordinates).
*/
static int EasyTab_CalculateTabSizes(TabGroup group)
{
int error = UIENoError;
Sheet sheet;
Sheet activeSheet;
TabButton tabButton;
ListType sheetList;
ListType rowLists;
int numRows;
int rowIndex;
int numSheets;
int numSheetsLeft;
int sheetIndex;
Rect minBounds;
Rect buttonBounds;
Rect unionRect;
Rect eraseRect;
int gapSpace; /* number of pixels in row that need to be covered when the buttons are stretch to cover the row */
int availableGapSpace;
int stretchSpace;
Rect relBounds;
int relVOffset, relHOffset;
int minRowWidth, maxRowWidth;
int thisGapSpace;
int thisStretchSpace;
int activeSheetIsLeftMost;
int activeSheetIsRightMost;
if (!group->tabButtonPositionsCalculated)
{
if (!group->sizeHasBeenSet)
EasyTab_AutoSize(group->dialogPanel, group->canvas);
nullChk( rowLists = EasyTab_GetRowLists(group));
numRows = ListNumItems(rowLists);
relVOffset = 0;
switch (group->buttonPosition)
{
case VAL_EASY_TAB_BTNS_ON_TOP:
case VAL_EASY_TAB_BTNS_ON_BOTTOM:
maxRowWidth = group->frameRect.width;
break;
case VAL_EASY_TAB_BTNS_ON_RIGHT:
case VAL_EASY_TAB_BTNS_ON_LEFT:
maxRowWidth = group->frameRect.height;
break;
}
maxRowWidth = maxRowWidth - (TABBUTTON_ACTIVE_EXTRA_LEFT + TABBUTTON_ACTIVE_EXTRA_RIGHT);
RectSet(&unionRect, 0, 0, 0, 0);
activeSheet = EasyTab_GetActive(group);
for (rowIndex = numRows; rowIndex >= 1 ; rowIndex--)
{
ListGetItem(rowLists, &sheetList, rowIndex);
numSheets = ListNumItems(sheetList);
relHOffset = TABBUTTON_ACTIVE_EXTRA_LEFT; /* non-active tab button are inset from the edge */
/* Calculate minRowWidth and find the active sheet position */
minRowWidth = 0;
activeSheetIsLeftMost = FALSE;
activeSheetIsRightMost = FALSE;
for (sheetIndex = 1; sheetIndex <= numSheets; sheetIndex++)
{
ListGetItem(sheetList, &sheet, sheetIndex);
TabButton_GetMinBounds(sheet->tabButton, FALSE, &minBounds);
minRowWidth += minBounds.width;
if (sheet == activeSheet)
{
if (sheetIndex == 1)
activeSheetIsLeftMost = TRUE;
if (sheetIndex == numSheets)
activeSheetIsRightMost = TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -