📄 skin.c
字号:
/* first, should we KILLFOCUS form hilighted item? */ /* if hilight exist, and mouse moves out of it, kill focus from it */ if ( skin->hilighted && !(item && (item->id == skin->hilighted->id)) ){ ITEM_MSG_PROC (skin->hilighted, SKIN_MSG_KILLFOCUS, 0, 0); set_item_hilighted (skin->hilighted, FALSE); skin->hilighted = NULL; } /* second, should we SETFOCUS on current item? (item isn't hilighted) */ if ( item && item_enable (item) ){ /* hilighted it */ skin->hilighted = item; set_item_hilighted (item, TRUE); ITEM_MSG_PROC (item, SKIN_MSG_SETFOCUS, 0, 0); /* show tool tip here */ show_item_hint (hwnd, skin, item, x, y); } } else{ /* item is being DRAGED. skin->hilighted must be non-null */ ITEM_MSG_PROC (skin->hilighted, SKIN_MSG_MOUSEDRAG, x, y); }}#define ITEM_OPS(skin,op) \{ \ int i; \ skin_item_t* item; \ item = skin->items; \ for (i = 0; i < skin->nr_items; i++, item++) { \ if ( item->ops && item->ops->op ) \ item->ops->op (item); \ } \} static int SkinWndProc (HWND hwnd, int message, WPARAM wParam, LPARAM lParam){ int x, y, result = MSG_CB_GOON; skin_head_t *skin = NULL; if (message == MSG_NCCREATE) SetWindowAdditionalData2 (hwnd, GetWindowAdditionalData(hwnd)); skin = (skin_head_t*) GetWindowAdditionalData2 (hwnd); /* msg_cb */ if ( skin && skin->msg_cb ){ skin->msg_cb (hwnd, message, wParam, lParam, &result); } switch (result){ case MSG_CB_GOON: /* continue */ switch (message) { case MSG_CREATE: skin->hwnd = hwnd; ITEM_OPS(skin,on_create); break; case MSG_DESTROY: ITEM_OPS(skin,on_destroy); break; case MSG_ERASEBKGND: { /* draw skin window background */ HDC hdc = (HDC)wParam; const RECT* clip = (const RECT*) lParam; BOOL fGetDC = FALSE; RECT rcTemp; if (hdc == 0) { hdc = GetClientDC (hwnd); fGetDC = TRUE; } if (clip) { rcTemp = *clip; ScreenToClient (hwnd, &rcTemp.left, &rcTemp.top); ScreenToClient (hwnd, &rcTemp.right, &rcTemp.bottom); IncludeClipRect (hdc, &rcTemp); } FillBoxWithBitmap (hdc, 0, 0, 0, 0, &skin->bmps[skin->bk_bmp_index]); if (fGetDC) ReleaseDC (hdc); return 0; } case MSG_PAINT: on_paint (hwnd, skin); break; case MSG_MOUSEMOVE: x = LOSWORD (lParam); y = HISWORD (lParam); on_mousemove (hwnd, skin, x, y); break; case MSG_LBUTTONDOWN: x = LOSWORD (lParam); y = HISWORD (lParam); on_lbuttondown (hwnd, skin, x, y); break; case MSG_LBUTTONUP: x = LOSWORD (lParam); y = HISWORD (lParam); ScreenToClient (hwnd, &x, &y); on_lbuttonup (hwnd, skin, x, y); break; case MSG_CLOSE: DestroyAllControls (hwnd); DestroyMainWindow (hwnd); if (GetHosting(hwnd) == HWND_DESKTOP) PostQuitMessage (hwnd); else MainWindowCleanup (hwnd); return 0; } case MSG_CB_DEF_GOON: /* continue default only */ if (IsControl(hwnd)) return DefaultControlProc (hwnd, message, wParam, lParam); return DefaultMainWinProc (hwnd, message, wParam, lParam); break; case MSG_CB_STOP: /* stop proc */ default: /* error if here */ return 0; }}HWND create_skin_control (skin_head_t* skin, HWND parent, int id, int x, int y, int w, int h){ skin->hwnd = CreateWindow ( CTRL_SKIN, NULL, WS_VISIBLE | WS_CHILD, id, x, y, w, h, parent, (DWORD)skin); return skin->hwnd;}HWND create_skin_main_window (skin_head_t* skin, HWND hosting, int x, int y, int w, int h, BOOL modal){ MSG Msg; MAINWINCREATE CreateInfo; CreateInfo.dwStyle = WS_VISIBLE; CreateInfo.dwExStyle = 0; CreateInfo.spCaption = "Main Window with Skin"; CreateInfo.hMenu = 0; CreateInfo.hCursor = GetSystemCursor (IDC_ARROW); CreateInfo.hIcon = 0; CreateInfo.lx = x; CreateInfo.ty = y; CreateInfo.rx = w; CreateInfo.by = h; CreateInfo.hHosting = hosting; CreateInfo.iBkColor = PIXEL_lightwhite; CreateInfo.dwAddData = (DWORD)skin; CreateInfo.MainWindowProc = SkinWndProc; skin->hwnd = CreateMainWindow (&CreateInfo); if (skin->hwnd == HWND_INVALID) return HWND_INVALID; ShowWindow (skin->hwnd, SW_SHOWNORMAL); /* modal window */ if ( modal ) { if (hosting) EnableWindow (hosting, FALSE); while( GetMessage (&Msg, skin->hwnd) ) { TranslateMessage (&Msg); DispatchMessage (&Msg); } DestroyMainWindow (skin->hwnd); ThrowAwayMessages (skin->hwnd); MainWindowThreadCleanup (skin->hwnd); if (hosting) { EnableWindow (hosting, TRUE); ShowWindow (hosting, SW_SHOWNORMAL); SetActiveWindow (hosting); } } return skin->hwnd;}void destroy_skin_window (HWND hwnd){ if (IsControl(hwnd)) DestroyWindow (hwnd); else SendNotifyMessage (hwnd, MSG_CLOSE, 0, 0);}skin_head_t* set_window_skin (HWND hwnd, skin_head_t *new_skin){ skin_head_t *old_skin = (skin_head_t*) GetWindowAdditionalData2 (hwnd); if (!new_skin || !old_skin || old_skin == new_skin) return NULL; new_skin->hwnd = hwnd; old_skin->hwnd = 0; SetWindowAdditionalData2 (hwnd, (DWORD)new_skin); InvalidateRect (hwnd, NULL, FALSE); return old_skin;}skin_head_t* get_window_skin (HWND hwnd){ return (skin_head_t*) GetWindowAdditionalData2 (hwnd);}skin_item_t* skin_get_item (skin_head_t* skin, int id){ int i; skin_item_t* item = skin->items; for ( i = 0 ; i < skin->nr_items ; i++, item++ ) { if ( item->id == id ) return item; } return NULL;}/* ------------------------- operation interfaces -------------------------- */#define CHECK_OPS(func, error) \ skin_item_t *item = skin_get_item (skin, id); \ if (!item || !item->ops || !item->ops->func) \ return error; const char* skin_get_item_label (skin_head_t* skin, int id){ CHECK_OPS(get_value, NULL); return (const char*)( item->ops->get_value (item) );}BOOL skin_set_item_label (skin_head_t* skin, int id, const char* label){ BOOL ret; CHECK_OPS(set_value, FALSE); ret = (BOOL)( item->ops->set_value (item, (DWORD)label) ); //refresh_item (item); return ret;}DWORD skin_get_item_status ( skin_head_t* skin, int id ){ return get_item_status ( skin_get_item (skin, id) );}DWORD skin_set_item_status ( skin_head_t* skin, int id, DWORD status ){ skin_item_t *item = skin_get_item (skin, id); DWORD old_status = get_item_status (item); if ( old_status ){ item->style |= status; refresh_item (item); } return old_status; }DWORD skin_show_item (skin_head_t* skin, int id, BOOL show){ skin_item_t *item = skin_get_item (skin, id); set_item_visible ( item, show ); return get_item_status ( item );}DWORD skin_enable_item (skin_head_t* skin, int id, BOOL enable){ skin_item_t *item = skin_get_item (skin, id); set_item_disabled( item, !enable ); return get_item_status ( item );}skin_item_t* skin_get_hilited_item (skin_head_t* skin){ return skin->hilighted;}skin_item_t* skin_set_hilited_item (skin_head_t* skin, int id){ skin_item_t *old_hilighted = skin->hilighted; skin->hilighted = skin_get_item (skin, id); return old_hilighted;}BOOL skin_get_check_status (skin_head_t* skin, int id){ return item_clicked ( skin_get_item (skin, id) );}DWORD skin_set_check_status (skin_head_t* skin, int id, BOOL check){ set_item_clicked ( skin_get_item (skin, id), check ); return skin_get_item_status (skin, id);}int skin_get_thumb_pos (skin_head_t* skin, int id){ CHECK_OPS(get_value, -1); return (int) (item->ops->get_value (item) ) ;}BOOL skin_set_thumb_pos (skin_head_t* skin, int id, int pos){ BOOL ret; CHECK_OPS(set_value, FALSE); ret = (BOOL) (item->ops->set_value (item, pos) ); refresh_item (item); return ret; }BOOL skin_get_slider_info (skin_head_t* skin, int id, sie_slider_t* sie){ skin_item_t *item = skin_get_item (skin, id); si_nrmslider_t* slider = (si_nrmslider_t*) item->type_data; memcpy ( sie, &slider->slider_info, sizeof(sie_slider_t)); return TRUE;}BOOL skin_set_slider_info (skin_head_t* skin, int id, const sie_slider_t* sie){ skin_item_t *item = skin_get_item (skin, id); si_nrmslider_t* slider = (si_nrmslider_t*) item->type_data; memcpy ( &slider->slider_info, sie, sizeof(sie_slider_t)); return TRUE;}int skin_scale_slider_pos (const sie_slider_t* org, int new_min, int new_max){ return (.5 + new_min + 1. * (new_max - new_min) * (org->cur_pos - org->min_pos) / (org->max_pos - org->min_pos) );}HWND skin_get_control_hwnd (skin_head_t* skin, int id){ skin_item_t *item = skin_get_item (skin, id); if ( (item->style & SI_TYPE_MASK) == SI_TYPE_CONTROL ) return item->ops->get_value(item); return HWND_INVALID;}BOOL RegisterSkinControl (void){ WNDCLASS SkinClass; SkinClass.spClassName = CTRL_SKIN; SkinClass.dwStyle = 0; SkinClass.dwExStyle = 0; SkinClass.hCursor = GetSystemCursor (IDC_ARROW); SkinClass.iBkColor = COLOR_lightwhite; SkinClass.WinProc = SkinWndProc; SkinClass.dwAddData = 0; return RegisterWindowClass (&SkinClass);}void SkinControlCleanup (void){ UnregisterWindowClass (CTRL_SKIN);}#endif /* _EXT_SKIN */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -