📄 newtoolbar.c
字号:
end:
ReleaseDC (hdc);
new_item->next = NULL;
if (ntb_data->tail == NULL) {
ntb_data->head = ntb_data->tail = new_item;
}
else {
ntb_data->tail->next = new_item;
ntb_data->tail = new_item;
}
ntb_data->nr_items++;
}
static void recalc_items (HWND hwnd, NTBCTRLDATA* ntb_data)
{
HDC hdc;
PNTBITEM item, prev = NULL;
hdc = GetClientDC (hwnd);
item = ntb_data->head;
if(!( ntb_data->style & NTBS_VERTICAL ))
{
while (item) {
//horizontal
if (prev == NULL )
{
item->rc_item.top = MARGIN_VERT;
item->rc_item.left = MARGIN_HORZ;
}
else if ( (item->flags & NTBIF_TYPEMASK ) == NTBIF_NEWLINE )
{
item->rc_item.top = prev->rc_item.bottom + GAP_ITEM_ITEM_VERT;
item->rc_item.left = MARGIN_HORZ;
item->rc_item.bottom = item->rc_item.top;
item->rc_item.right = item->rc_item.left;
goto end;
}
else
{
if ( (prev->flags & NTBIF_TYPEMASK) == NTBIF_NEWLINE )
item->rc_item.left = MARGIN_HORZ;
else
item->rc_item.left = prev->rc_item.right + GAP_ITEM_ITEM_HORZ;
item->rc_item.top = prev->rc_item.top;
}
switch (item->flags & NTBIF_TYPEMASK) {
case NTBIF_PUSHBUTTON:
case NTBIF_CHECKBUTTON:
case NTBIF_HOTSPOTBUTTON:
if (ntb_data->style & NTBS_WITHTEXT) {
if (ntb_data->style & NTBS_TEXTRIGHT) {
SIZE sz_text;
GetTextExtent (hdc, item->text, -1, &sz_text);
item->rc_item.bottom
= item->rc_item.top + ntb_data->h_cell + 1;
item->rc_text.left = item->rc_item.left + ntb_data->w_cell + GAP_BMP_TEXT_HORZ + 1;
item->rc_text.right = item->rc_text.left + sz_text.cx;
item->rc_text.top = item->rc_item.top;
item->rc_text.bottom = item->rc_item.bottom;
item->rc_item.right = item->rc_text.right + GAP_BMP_TEXT_HORZ + 1;
}
else {
item->rc_item.right = item->rc_item.left + ntb_data->w_cell + 1;
item->rc_text.left = item->rc_item.left;
item->rc_text.right = item->rc_item.right;
item->rc_text.top
= item->rc_item.top + ntb_data->h_cell + GAP_BMP_TEXT_VERT;
item->rc_text.bottom = item->rc_text.top + GetFontHeight (hdc);
item->rc_item.bottom = item->rc_text.bottom + 1;
}
}
else {
item->rc_item.right = item->rc_item.left + ntb_data->w_cell + 1;
item->rc_item.bottom = item->rc_item.top + ntb_data->h_cell + 1;
}
break;
case NTBIF_SEPARATOR:
default:
if (ntb_data->style & NTBS_DRAWSEPARATOR)
item->rc_item.right = item->rc_item.left + WIDTH_SEPARATOR;
else
item->rc_item.right = item->rc_item.left + WIDTH_SEPARATOR * 2;
item->rc_item.bottom = item->rc_item.top + ntb_data->h_cell;
break;
}
prev = item;
item = item->next;
}
}
else
{
//vertical
while (item) {
if (prev == NULL )
{
item->rc_item.top = MARGIN_V_VERT;
item->rc_item.left = MARGIN_V_HORZ;
}
else if ( (item->flags & NTBIF_TYPEMASK ) == NTBIF_NEWLINE )
{
item->rc_item.left = prev->rc_item.right + GAP_ITEM_ITEM_HORZ;
item->rc_item.top = MARGIN_V_VERT;
item->rc_item.bottom = item->rc_item.top;
item->rc_item.right = item->rc_item.left;
goto end;
}
else
{
if ( (prev->flags & NTBIF_TYPEMASK) == NTBIF_NEWLINE )
item->rc_item.top = MARGIN_V_VERT;
else
item->rc_item.top = prev->rc_item.bottom + GAP_ITEM_ITEM_VERT;
item->rc_item.left = prev->rc_item.left;
}
switch (item->flags & NTBIF_TYPEMASK) {
case NTBIF_PUSHBUTTON:
case NTBIF_CHECKBUTTON:
case NTBIF_HOTSPOTBUTTON:
if (ntb_data->style & NTBS_WITHTEXT) {
if (ntb_data->style & NTBS_TEXTRIGHT) {
SIZE sz_text;
GetTextExtent (hdc, item->text, -1, &sz_text);
item->rc_item.bottom
= item->rc_item.top + ntb_data->h_cell + 1;
item->rc_text.left = item->rc_item.left + ntb_data->w_cell + GAP_BMP_TEXT_HORZ + 1;
item->rc_text.right = item->rc_text.left + sz_text.cx;
item->rc_text.top = item->rc_item.top;
item->rc_text.bottom = item->rc_item.bottom;
item->rc_item.right = item->rc_text.right + GAP_BMP_TEXT_HORZ + 1;
}
else {
item->rc_item.right = item->rc_item.left + ntb_data->w_cell + 1;
item->rc_text.left = item->rc_item.left;
item->rc_text.right = item->rc_item.right;
item->rc_text.top
= item->rc_item.top + ntb_data->h_cell + GAP_BMP_TEXT_VERT;
item->rc_text.bottom = item->rc_text.top + GetFontHeight (hdc);
item->rc_item.bottom = item->rc_text.bottom + 1;
}
}
else {
item->rc_item.right = item->rc_item.left + ntb_data->w_cell + 1;
item->rc_item.bottom = item->rc_item.top + ntb_data->h_cell + 1;
}
break;
case NTBIF_SEPARATOR:
default:
if (ntb_data->style & NTBS_DRAWSEPARATOR)
item->rc_item.bottom = item->rc_item.top + WIDTH_SEPARATOR;
else
item->rc_item.bottom = item->rc_item.top + WIDTH_SEPARATOR * 2;
item->rc_item.right = item->rc_item.left + ntb_data->w_cell;
break;
}
prev = item;
item = item->next;
}
}
end:
ReleaseDC (hdc);
}
/*===========================================================================*/
static int NewToolbarCtrlProc (HWND hwnd, int message, WPARAM wParam, LPARAM lParam)
{
PCONTROL myself;
PNTBCTRLDATA ntb_data;
myself = Control (hwnd);
ntb_data = (PNTBCTRLDATA) myself->dwAddData2;
switch (message) {
case MSG_CREATE:
{
NTBINFO* data = (NTBINFO*)myself->dwAddData;
ntb_data = (NTBCTRLDATA*) calloc (1, sizeof (NTBCTRLDATA));
if (ntb_data == NULL)
return -1;
ntb_data->head = NULL;
ntb_data->style = myself->dwStyle;
ntb_data->image = data->image;
ntb_data->nr_cells = data->nr_cells;
ntb_data->nr_cols = data->nr_cols;
if (data->nr_cols == 0)
ntb_data->nr_cols = 4;
ntb_data->w_cell = data->w_cell;
if (data->w_cell == 0)
ntb_data->w_cell = data->image->bmWidth / ntb_data->nr_cols;
ntb_data->h_cell = data->h_cell;
if (data->h_cell == 0)
ntb_data->h_cell = data->image->bmHeight / ntb_data->nr_cells;
ntb_data->nr_items = 0;
ntb_data->sel_item = NULL;
myself->dwAddData2 = (DWORD)ntb_data;
break;
}
case MSG_DESTROY:
{
NTBITEM *item, *tmp;
item = ntb_data->head;
while (item) {
tmp = item->next;
free (item);
item = tmp;
}
free (ntb_data);
break;
}
case MSG_FONTCHANGED:
{
RECT rc;
recalc_items (hwnd, ntb_data);
GetWindowRect (hwnd, &rc);
MoveWindow (hwnd, rc.left, rc.top, RECTW(rc), RECTH(rc), TRUE);
break;
}
case MSG_NCPAINT:
return 0;
case MSG_SIZECHANGING:
{
const RECT* rcExpect = (const RECT*)wParam;
RECT* rcResult = (RECT*)lParam;
if ( ! (ntb_data->style & NTBS_VERTICAL ) )
{
// as horizontal
rcResult->left = rcExpect->left;
rcResult->top = rcExpect->top;
rcResult->right = rcExpect->right;
if (ntb_data->style & NTBS_MULTLINE )
{
rcResult->bottom = rcExpect->bottom;
}
else if (ntb_data->style & NTBS_WITHTEXT) {
rcResult->bottom = rcExpect->top + ntb_data->h_cell + MARGIN_VERT * 2;
if (!(ntb_data->style & NTBS_TEXTRIGHT))
rcResult->bottom += GetWindowFont (hwnd)->size + GAP_BMP_TEXT_VERT;
}
else
rcResult->bottom = rcExpect->top + ntb_data->h_cell + MARGIN_VERT * 2;
}
else
{
// as vertical ;
rcResult->left = rcExpect->left;
rcResult->top = rcExpect->top;
rcResult->bottom = rcExpect->bottom;
if (ntb_data->style & NTBS_WITHTEXT || ntb_data->style & NTBS_MULTLINE ) {
rcResult->right = rcExpect->right;
}
else
rcResult->right = rcExpect->left + ntb_data->w_cell + MARGIN_V_HORZ * 2;
}
return 0;
}
case NTBM_ADDITEM:
{
NTBITEMINFO* item_info = NULL;
NTBITEM* new_item;
item_info = (NTBITEMINFO*) lParam;
if (!(new_item = (NTBITEM*)calloc (1, sizeof (NTBITEM))))
return NTB_ERR;
new_item->flags = item_info->flags;
new_item->id = item_info->id;
new_item->bmp_cell = item_info->bmp_cell;
if (item_info->text)
strncpy (new_item->text, item_info->text, NTB_TEXT_LEN);
else
new_item->text [0] = '\0';
if (item_info->tip)
strncpy (new_item->tip, item_info->tip, NTB_TIP_LEN);
else
new_item->tip [0] = '\0';
new_item->rc_hotspot = item_info->rc_hotspot;
new_item->hotspot_proc = item_info->hotspot_proc;
new_item->add_data = item_info->add_data;
append_new_item (hwnd, ntb_data, new_item);
InvalidateRect (hwnd, &new_item->rc_item, TRUE);
return 0;
}
break;
case NTBM_GETITEM:
{
int id = wParam;
PNTBITEMINFO item_info = (PNTBITEMINFO) lParam;
NTBITEM* item = NULL;
if (!item_info)
return NTB_ERR;
item = ntb_data->head;
while (item) {
if (id == item->id) {
if (item_info->which & MTB_WHICH_FLAGS)
item_info->flags = item->flags;
if (item_info->which & MTB_WHICH_ID)
item_info->id = item->id;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -