📄 easytab.c
字号:
SetCtrlAttribute(panel, canvas, ATTR_PEN_COLOR, darkShadowColor);
CanvasSetPenPosition(panel, canvas, MakePoint(buttonRight, buttonBottom));
CanvasDrawLineTo(panel, canvas, MakePoint(bounds.left + 2, buttonBottom));
CanvasDrawLineTo(panel, canvas, MakePoint(bounds.left + 1, buttonBottom - 1));
SetCtrlAttribute(panel, canvas, ATTR_PEN_COLOR, shadowColor);
CanvasSetPenPosition(panel, canvas, MakePoint(bounds.left + 2, buttonBottom - 1));
CanvasDrawLineTo(panel, canvas, MakePoint(buttonRight, buttonBottom - 1));
break;
}
if (drawFocus)
{
Rect focusRect;
/* Draw the dotted rectangle which indicates keyboard focus */
switch (group->buttonPosition)
{
case VAL_EASY_TAB_BTNS_ON_TOP:
RectSet(&focusRect, bounds.top + 3, bounds.left + 3, bounds.height - 4, bounds.width - 6);
break;
case VAL_EASY_TAB_BTNS_ON_RIGHT:
RectSet(&focusRect, bounds.top + 3, bounds.left + 1, bounds.height - 6, bounds.width - 5);
break;
case VAL_EASY_TAB_BTNS_ON_LEFT:
RectSet(&focusRect, bounds.top + 3, bounds.left + 3, bounds.height - 7, bounds.width - 5);
break;
case VAL_EASY_TAB_BTNS_ON_BOTTOM:
RectSet(&focusRect, bounds.top + 1, bounds.left + 3, bounds.height - 4, bounds.width - 6);
break;
}
SetCtrlAttribute(panel, canvas, ATTR_PEN_FILL_COLOR, bgColor);
SetCtrlAttribute(group->dialogPanel, group->canvas, ATTR_PEN_PATTERN, checkerPattern);
DrawRectFrameWithFill (group->dialogPanel, group->canvas, focusRect);
SetCtrlAttribute(group->dialogPanel, group->canvas, ATTR_PEN_PATTERN, solidPattern);
}
}
/*************************************************************/
/* Frame a rect, but use interior drawing so pen patterns will apply (this is MS Windows fault!) */
static void DrawRectFrameWithFill(int panel, int canvas, Rect r)
{
Rect fillRect;
RectSet(&fillRect, r.top, r.left, 1, r.width - 1);
CanvasDrawRect (panel, canvas, fillRect, VAL_DRAW_INTERIOR);
RectSet(&fillRect, r.top, r.left, r.height - 1, 1);
CanvasDrawRect (panel, canvas, fillRect, VAL_DRAW_INTERIOR);
RectSet(&fillRect, r.top + r.height - 1, r.left, 1, r.width);
CanvasDrawRect (panel, canvas, fillRect, VAL_DRAW_INTERIOR);
RectSet(&fillRect, r.top, r.left + r.width - 1, r.height, 1);
CanvasDrawRect (panel, canvas, fillRect, VAL_DRAW_INTERIOR);
}
/*************************************************************/
/* returns a Rect with a top and left of zero and a height and width set to the minimum
height and width a tab button can be set to before its label starts to be obscured.
*/
static void TabButton_GetMinBounds(TabButton tabButton, int active, Rect *r)
{
if (active)
RectSet(r, 0, 0, tabButton->minSize.y + TABBUTTON_ACTIVE_EXTRA_TOP ,
tabButton->minSize.x + TABBUTTON_ACTIVE_EXTRA_LEFT + TABBUTTON_ACTIVE_EXTRA_RIGHT);
else
RectSet(r, 0, 0, tabButton->minSize.y, tabButton->minSize.x);
}
/*************************************************************/
/* Sets the "inactive bounds", the button automatically grows when activated.
The caller should call TabButton_GetMinBounds to get the smallest rect
the button can be set to before its label starts to become obscured.
*/
static void TabButton_SetBounds(TabButton tabButton, Rect r)
{
int dt = 0, dl = 0, dh = 0, dw = 0;
tabButton->inactiveBounds = r;
switch (tabButton->sheet->group->buttonPosition)
{
case VAL_EASY_TAB_BTNS_ON_TOP:
dt = 0 - TABBUTTON_ACTIVE_EXTRA_TOP;
dl = 0 - TABBUTTON_ACTIVE_EXTRA_LEFT;
dh = TABBUTTON_ACTIVE_EXTRA_TOP;
dw = TABBUTTON_ACTIVE_EXTRA_LEFT + TABBUTTON_ACTIVE_EXTRA_RIGHT;
break;
case VAL_EASY_TAB_BTNS_ON_BOTTOM:
dt = 0;
dl = 0 - TABBUTTON_ACTIVE_EXTRA_LEFT;
dh = TABBUTTON_ACTIVE_EXTRA_TOP;
dw = TABBUTTON_ACTIVE_EXTRA_LEFT + TABBUTTON_ACTIVE_EXTRA_RIGHT;
break;
case VAL_EASY_TAB_BTNS_ON_RIGHT:
dt = 0 - TABBUTTON_ACTIVE_EXTRA_LEFT;
dl = 0;
dh = TABBUTTON_ACTIVE_EXTRA_LEFT + TABBUTTON_ACTIVE_EXTRA_RIGHT;
dw = TABBUTTON_ACTIVE_EXTRA_TOP;
break;
case VAL_EASY_TAB_BTNS_ON_LEFT:
dt = 0 - TABBUTTON_ACTIVE_EXTRA_LEFT;
dl = 0 - TABBUTTON_ACTIVE_EXTRA_TOP;
dh = TABBUTTON_ACTIVE_EXTRA_LEFT + TABBUTTON_ACTIVE_EXTRA_RIGHT;
dw = TABBUTTON_ACTIVE_EXTRA_TOP;
break;
}
RectSet(&tabButton->activeBounds, r.top + dt, r.left + dl, r.height + dh, r.width + dw);
}
/*************************************************************/
static int Sheet_Create(TabGroup group, int sheetPanel, int row, const char *label, ListType ctrlList, Sheet *sheetToReturn)
{
int error = UIENoError;
Sheet sheet = 0;
int parentPanel;
nullChk( sheet = (Sheet)calloc(sizeof(*sheet), 1));
sheet->signature = SHEET_SIGNATURE;
sheet->panel = sheetPanel;
sheet->originalRow = row;
sheet->group = group;
sheet->hidden = FALSE;
nullChk( sheet->tabButton = TabButton_Create(sheet, label));
sheet->ownsPanel = group->dialogPanel != sheetPanel;
if (sheet->ownsPanel)
{
GetPanelAttribute(sheet->panel, ATTR_PANEL_PARENT, &parentPanel);
if (parentPanel != group->dialogPanel)
errChk( ToolErr_PanelNotAChildOfCorrectPanel);
GetPanelAttribute(sheet->panel, ATTR_WIDTH, &sheet->originalWidth);
GetPanelAttribute(sheet->panel, ATTR_HEIGHT, &sheet->originalHeight);
InstallActivationHooks(sheet->panel, TRUE);
errChk( SetPanelAttribute (sheetPanel, ATTR_PARENT_SHARES_SHORTCUT_KEYS, TRUE));
errChk( SetPanelAttribute(sheetPanel, ATTR_FRAME_STYLE, VAL_HIDDEN_FRAME));
errChk( SetPanelAttribute (sheetPanel, ATTR_TITLEBAR_VISIBLE, 0));
errChk( ChainPanelCallback(sheetPanel, Sheet_PanelCallback, (void *)sheet, "Sheet Panel"));
}
else
SetAttributeForList (sheet->panel, ctrlList, ATTR_VISIBLE, FALSE);
EasyTab_InvalRowLists(group); /* make sure this sheet gets added to the rowLists */
sheet->ctrlList = ctrlList;
Error:
if (error < 0)
{
Sheet_Dispose(sheet);
*sheetToReturn = 0;
}
else
{
*sheetToReturn = sheet;
}
return error;
}
/*************************************************************/
static int IsSheetPanel(int panel)
{
void *callbackData;
return GetChainedPanelCallbackData (panel, "Sheet Panel", &callbackData) >= 0;
}
/*************************************************************/
static void Sheet_Dispose(Sheet sheet)
{
if (sheet)
{
if (sheet->panel > 0)
UnchainPanelCallback(sheet->panel, "Sheet Panel");
if (sheet->ownsPanel)
DiscardPanelNoBOLE(sheet->panel, FALSE);
TabButton_Dispose(sheet->tabButton);
ListDispose(sheet->ctrlList);
free(sheet);
}
}
/*************************************************************/
static void Sheet_Remove(Sheet sheet)
{
if (sheet)
{
if (sheet->panel > 0)
UnchainPanelCallback(sheet->panel, "Sheet Panel");
if (sheet->ownsPanel)
SetPanelAttribute (sheet->panel, ATTR_VISIBLE, 0);
TabButton_Dispose(sheet->tabButton);
ListDispose(sheet->ctrlList);
free(sheet);
}
}
/******************************************************************/
/* invalidate the display of every easy tab control on a panel (does not recurse into child panels) */
static void EasyTab_InvalDisplayForPanel(int panel)
{
int ctrl;
TabGroup group ;
GetPanelAttribute(panel, ATTR_PANEL_FIRST_CTRL, &ctrl);
while (ctrl > 0)
{
if (EasyTab_IdToGroup(panel, ctrl, &group) >= 0)
EasyTab_InvalDisplay(group);
GetCtrlAttribute(panel, ctrl, ATTR_NEXT_CTRL, &ctrl);
}
}
/******************************************************************/
/* This is shared by all the tab controls on a panel */
static int CVICALLBACK EasyTab_PanelCallback (int panel, int event, void *callbackData, int eventData1, int eventData2)
{
int returnVal = FALSE, ctrl, scaleContents;
TabGroup group;
Rect canvasRect;
switch (event)
{
case EVENT_PANEL_SIZE:
GetPanelAttribute (panel, ATTR_SCALE_CONTENTS_ON_RESIZE, &scaleContents);
if (scaleContents)
{
GetPanelAttribute (panel, ATTR_PANEL_FIRST_CTRL, &ctrl);
while (ctrl > 0) {
if (EasyTab_IdToGroup (panel, ctrl, &group) >= 0)
{
GetCtrlAttribute (panel, ctrl, ATTR_TOP, &canvasRect.top);
GetCtrlAttribute (panel, ctrl, ATTR_LEFT, &canvasRect.left);
GetCtrlAttribute (panel, ctrl, ATTR_HEIGHT, &canvasRect.height);
GetCtrlAttribute (panel, ctrl, ATTR_WIDTH, &canvasRect.width);
EasyTab_SetExteriorRect (group, canvasRect);
}
GetCtrlAttribute (panel, ctrl, ATTR_NEXT_CTRL, &ctrl);
}
}
break;
case EVENT_GOT_FOCUS:
case EVENT_LOST_FOCUS:
EasyTab_InvalDisplayForPanel(panel); /* dotted focus rect probably needs to be updated */
break;
case EVENT_KEYPRESS:
if (HandleTabKey(eventData1, &returnVal))
break;
else
if (EasyTab_HandleAcceleratorKey(eventData1, &returnVal))
break;
break;
}
return returnVal;
}
/******************************************************************/
static int CVICALLBACK Sheet_PanelCallback (int panel, int event, void *callbackData, int eventData1, int eventData2)
{
int returnVal = FALSE;
UNUSED(panel);
switch (event)
{
case EVENT_KEYPRESS:
if (HandleTabKey(eventData1, &returnVal))
break;
break;
case EVENT_LOST_FOCUS:
case EVENT_GOT_FOCUS:
returnVal = TRUE;
break;
}
return returnVal;
}
/******************************************************************/
static int CVICALLBACK EasyTab_CanvasCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
TabGroup group = (TabGroup)callbackData;
int returnVal = FALSE;
int locked = FALSE;
if (!group->valid)
return 0;
CmtGetLock(group->lockHandle);
locked = TRUE;
UNUSED(panel);
UNUSED(control);
switch (event)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -