📄 footer.c
字号:
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <dirent.h>#include <time.h>#include <string.h>#include <sys/time.h>#include <pthread.h>#include <semaphore.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#include "vacs.h"#include "gui.h"#include "footer.h"#include "command.h"/************************** Global Variables ********************************/static HWND sg_hFooterWin = HWND_INVALID;static FOOTERINFO sg_FooterInfo;/********************* Interfaces for external modules ***********************/void SetFooterRowInfo (int row, int num_cols, int *widths, BOOL fUpdate){ int i, x; RECT rcInv; FOOTERINFO* pFooterInfo; if (sg_hFooterWin == HWND_INVALID) return; pFooterInfo = (FOOTERINFO*)GetWindowAdditionalData (sg_hFooterWin); if (pFooterInfo == NULL) return; if (row >= pFooterInfo->num_rows || row < 0) return; pFooterInfo->num_cols_per_row [row] = num_cols; x = 0; for (i = 0; i < num_cols; i++) { pFooterInfo->cell [row][i].l = x; pFooterInfo->cell [row][i].r = x + widths [i]; x += widths [i]; } GetClientRect (sg_hFooterWin, &rcInv); rcInv.top = HEIGHT_ROW * row; rcInv.bottom = rcInv.top + HEIGHT_ROW; InvalidateRect (sg_hFooterWin, &rcInv, FALSE); if (fUpdate) PostMessage (sg_hFooterWin, MSG_PAINT, 0, 0L);}void SetFooterCellInfo (int row, int col, int fc, int bc, const char* text, BOOL fUpdate){ RECT rcInv; FOOTERINFO *pFooterInfo; if (sg_hFooterWin == HWND_INVALID) return; pFooterInfo = (FOOTERINFO*)GetWindowAdditionalData (sg_hFooterWin); if (pFooterInfo == NULL) return; if (row >= pFooterInfo->num_rows || row < 0) return; if (col >= MAX_NUM_COLS || col < 0) return; pFooterInfo->cell[row][col].fc = fc; pFooterInfo->cell[row][col].bc = bc; strncpy (pFooterInfo->cell[row][col].text, text, MAX_LEN_CELL_TEXT); memcpy (&rcInv, &pFooterInfo->cell[row][col], sizeof (RECT)); InvalidateRect (sg_hFooterWin, &rcInv, FALSE); if (fUpdate) PostMessage (sg_hFooterWin, MSG_PAINT, 0, 0L);}void SetFooterCellStyle (int row, int col, DWORD style, BOOL fUpdate){ RECT rcInv; FOOTERINFO *pFooterInfo; if (sg_hFooterWin == HWND_INVALID) return; pFooterInfo = (FOOTERINFO*)GetWindowAdditionalData (sg_hFooterWin); if (pFooterInfo == NULL) return; if (row >= pFooterInfo->num_rows || row < 0) return; if (col >= MAX_NUM_COLS || col < 0) return; pFooterInfo->cell[row][col].style = style; memcpy (&rcInv, &pFooterInfo->cell[row][col], sizeof (RECT)); InvalidateRect (sg_hFooterWin, &rcInv, FALSE); if (fUpdate) PostMessage (sg_hFooterWin, MSG_PAINT, 0, 0L);}/****************************** Window Handling ******************************/static void DrawCell (HDC hdc, CELLINFO* cell){ int fc, bc; SetPenColor (hdc, COLOR_lightgray); Rectangle (hdc, cell->l, cell->t, cell->r, cell->b); fc = cell->fc; bc = cell->bc; switch (cell->style & CS_TYPEMASK) { case CS_INVERT: fc = cell->bc; bc = cell->fc; break; case CS_ALARM: fc = cell->fc; if (cell->style & CS_HILITED) { cell->style &= ~CS_HILITED; bc = cell->bc; } else { cell->style |= CS_HILITED; bc = COLOR_red; } break; case CS_NORMAL: default: break; } SetBrushColor (hdc, bc); FillBox (hdc, cell->l + 1, cell->t + 1, cell->r - cell->l - 1, cell->b - cell->t - 1); SetBkColor (hdc, bc); SetTextColor (hdc, fc); TextOut (hdc, cell->l + 2, cell->t + 2, cell->text);}static void FlushAlarmCell (HWND hWnd){ int i, j; RECT rcInv; FOOTERINFO *pFooterInfo; pFooterInfo = (FOOTERINFO*)GetWindowAdditionalData (hWnd); if (pFooterInfo == NULL) return; for (i = 0; i < pFooterInfo->num_rows; i++) { for (j = 0; j < pFooterInfo->num_cols_per_row [i]; j++) { if ((pFooterInfo->cell[i][j].style & CS_TYPEMASK) == CS_ALARM) { memcpy (&rcInv, &pFooterInfo->cell[i][j], sizeof (RECT)); InvalidateRect (sg_hFooterWin, &rcInv, FALSE); } } }}int FooterHook (void* context, HWND dst_wnd, int message, WPARAM wParam, LPARAM lParam){ if ((message == MSG_KEYUP || message == MSG_SYSKEYUP) && lParam == 0) { switch (wParam) { case SCANCODE_F1 ... SCANCODE_F10: case SCANCODE_F11: case SCANCODE_F12: case SCANCODE_CURSORBLOCKUP: case SCANCODE_CURSORBLOCKLEFT: case SCANCODE_CURSORBLOCKRIGHT: break; default: return HOOK_GOON; } PostMessage ((HWND)context, MSG_HOTKEYPRESSED, wParam, 0); return HOOK_STOP; } return HOOK_GOON;}static char* szLabelPrefix[] ={ "F1\n帮助", "F2\n", "F3\n", "F4\n", "F5\n", "F6\n", "F7\n", "F8\n", "F9\n", "F10\n", "F11\n", "F12\n", "←", "↑", "→"};// ←// →static void FooterSetButtonText (HWND hWnd){ FOOTERINFO* pFooterInfo; BTNMENUITEM* btmi; int id = ID_GROUP_FIRST; int i = 1; int count = 0; char text [MAX_LEN_ITEM_TEXT + 6]; pFooterInfo = (FOOTERINFO*)GetWindowAdditionalData (hWnd); btmi = pFooterInfo->page_first; while (btmi) { strcpy (text, szLabelPrefix [i]); strcat (text, btmi->text); SetDlgItemText (hWnd, id, text); EnableWindow (GetDlgItem (hWnd, id), TRUE); i++; id++; count++; btmi = btmi->next; if (count >= NUM_BUTTONS_PER_PAGE) break; } if (count < NUM_BUTTONS_PER_PAGE) { for (; id < ID_ENTER_BUTTON; i++, id++) { strcpy (text, szLabelPrefix [i]); SetDlgItemText (hWnd, id, text); EnableWindow (GetDlgItem (hWnd, id), FALSE); } } if (pFooterInfo->curr_leader == pFooterInfo->page_first) EnableWindow (GetDlgItem (hWnd, ID_LEFT_BUTTON), FALSE); else EnableWindow (GetDlgItem (hWnd, ID_LEFT_BUTTON), TRUE); if (btmi == NULL) EnableWindow (GetDlgItem (hWnd, ID_RIGHT_BUTTON), FALSE); else EnableWindow (GetDlgItem (hWnd, ID_RIGHT_BUTTON), TRUE); if (pFooterInfo->curr_leader && pFooterInfo->curr_leader->parent) EnableWindow (GetDlgItem (hWnd, ID_UP_BUTTON), TRUE); else EnableWindow (GetDlgItem (hWnd, ID_UP_BUTTON), FALSE);}static BTNMENUITEM* GetCheckedMenuButton (HWND hWnd){ FOOTERINFO* pFooterInfo; BTNMENUITEM* curr_btmi; int id = ID_GROUP_FIRST; int count = 0; pFooterInfo = (FOOTERINFO*)GetWindowAdditionalData (hWnd); curr_btmi = pFooterInfo->page_first; while (curr_btmi) { if (IsDlgButtonChecked (hWnd, id)) return curr_btmi; id++; count++; if (count > NUM_BUTTONS_PER_PAGE) break; curr_btmi = curr_btmi->next; } return NULL;}static void SetEnterButtonText (HWND hWnd){ BTNMENUITEM* curr_btmi = GetCheckedMenuButton (hWnd); char text [MAX_LEN_ITEM_TEXT + 6]; if (!curr_btmi) { strcpy (text, szLabelPrefix [NUM_BUTTONS - 1]); SetDlgItemText (hWnd, ID_ENTER_BUTTON, text); EnableWindow (GetDlgItem (hWnd, ID_ENTER_BUTTON), FALSE); } else if (curr_btmi->child) { strcpy (text, szLabelPrefix [NUM_BUTTONS - 1]); strcat (text, "下一级"); SetDlgItemText (hWnd, ID_ENTER_BUTTON, text); EnableWindow (GetDlgItem (hWnd, ID_ENTER_BUTTON), TRUE); } else { strcpy (text, szLabelPrefix [NUM_BUTTONS - 1]); strcat (text, "确定"); SetDlgItemText (hWnd, ID_ENTER_BUTTON, text); EnableWindow (GetDlgItem (hWnd, ID_ENTER_BUTTON), TRUE); }}static void ResetCheckButton (HWND hWnd){ int id; for (id=ID_GROUP_FIRST; id<ID_GROUP_FIRST + NUM_BUTTONS_PER_PAGE; id++) { if (IsDlgButtonChecked (hWnd, id)) { CheckDlgButton (hWnd, id, 0); break; } } SetDlgItemText (hWnd, ID_ENTER_BUTTON, szLabelPrefix [NUM_BUTTONS - 1]); EnableWindow (GetDlgItem (hWnd, ID_ENTER_BUTTON), FALSE);}static BTNMENUITEM* get_prev_page (BTNMENUITEM* curr_leader, int curr_page_num){ int i = 0; int count; BTNMENUITEM* btmi; if (curr_page_num == 0) return NULL; curr_page_num --; count = curr_page_num*NUM_BUTTONS_PER_PAGE; btmi = curr_leader; while (btmi) { if (i == count) break; i ++; btmi = btmi->next; } return btmi;}static BTNMENUITEM* get_next_page (BTNMENUITEM* page_first){ int count = 0; BTNMENUITEM* btmi; btmi = page_first; while (btmi) { count++; if (count > NUM_BUTTONS_PER_PAGE) break; btmi = btmi->next; } if (count <= NUM_BUTTONS_PER_PAGE) return NULL; return btmi;}static BTNMENUITEM* btm_level_first (FOOTERINFO* pFooterInfo, BTNMENUITEM* btmi){ if (btmi->parent) return btmi->parent->child; return pFooterInfo->first;}static void FooterHandleButtonCommand (HWND hWnd, int id){ FOOTERINFO* pFooterInfo; BTNMENUITEM* curr_btmi; BTNMENUITEM* btmi; pFooterInfo = (FOOTERINFO*)GetWindowAdditionalData (hWnd); switch (id) { case ID_HELP_BUTTON: break; case ID_ENTER_BUTTON: curr_btmi = GetCheckedMenuButton (hWnd); if (!curr_btmi) break; if (curr_btmi->child) { pFooterInfo->curr_leader = curr_btmi->child; pFooterInfo->page_first = curr_btmi->child; pFooterInfo->page_num = 0; FooterSetButtonText (hWnd); ResetCheckButton (hWnd); } else { ButtonCommand (GetHosting (hWnd), hWnd, curr_btmi->id); } break; case ID_UP_BUTTON: if (pFooterInfo->curr_leader->parent) { pFooterInfo->curr_leader = btm_level_first (pFooterInfo, pFooterInfo->curr_leader->parent); pFooterInfo->page_first = pFooterInfo->curr_leader; pFooterInfo->page_num = 0; FooterSetButtonText (hWnd); ResetCheckButton (hWnd); } break; case ID_LEFT_BUTTON: btmi = get_prev_page (pFooterInfo->curr_leader, pFooterInfo->page_num); if (btmi == NULL) break; pFooterInfo->page_first = btmi; pFooterInfo->page_num --; FooterSetButtonText (hWnd); ResetCheckButton (hWnd); break; case ID_RIGHT_BUTTON: btmi = get_next_page (pFooterInfo->page_first); if (btmi == NULL) break; pFooterInfo->page_first = btmi; pFooterInfo->page_num ++; FooterSetButtonText (hWnd); ResetCheckButton (hWnd); break; }}static int FooterWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam){ FOOTERINFO* pFooterInfo; switch (message) { case MSG_CREATE: SetTimer (hWnd, ID_FOOTER_TIMER, 50); RegisterKeyMsgHook ((void*)hWnd, FooterHook); break; case MSG_SHOWWINDOW: if (wParam == SW_SHOWNORMAL) { // show window at the first time FooterSetButtonText (hWnd); ResetCheckButton (hWnd); } break; case MSG_PAINT: { HDC hdc; int i, j; pFooterInfo = (FOOTERINFO*)GetWindowAdditionalData (hWnd); hdc = BeginPaint (hWnd); for (i = 0; i < pFooterInfo->num_rows; i++) { for (j = 0; j < pFooterInfo->num_cols_per_row [i]; j++) { if (RectVisible (hdc, (RECT*)(&pFooterInfo->cell[i][j]))) { DrawCell (hdc, &pFooterInfo->cell[i][j]); } } } EndPaint (hWnd, hdc); return 0; } case MSG_TIMER: if (wParam == ID_FOOTER_TIMER) FlushAlarmCell (hWnd); break; case MSG_HOTKEYPRESSED: switch (wParam) { case SCANCODE_F1: if (IsWindowEnabled (GetDlgItem (hWnd, ID_FIRST_BUTTON))) SendMessage (hWnd, MSG_BUTTONCOMMAND, ID_FIRST_BUTTON, 0); break; case SCANCODE_F12: if (IsWindowEnabled (GetDlgItem (hWnd, ID_FIRST_BUTTON + 11))) SendMessage (hWnd, MSG_BUTTONCOMMAND, ID_FIRST_BUTTON + 11, 0); break; case SCANCODE_F11: if (IsWindowEnabled (GetDlgItem (hWnd, ID_FIRST_BUTTON + 10))) CheckRadioButton (hWnd, 0, 0, ID_FIRST_BUTTON + 10); break; case SCANCODE_F2 ... SCANCODE_F10: if (IsWindowEnabled (GetDlgItem (hWnd, ID_FIRST_BUTTON + (wParam - SCANCODE_F1)))) CheckRadioButton (hWnd, 0, 0, ID_FIRST_BUTTON + (wParam - SCANCODE_F1)); break; case SCANCODE_CURSORBLOCKLEFT: if (IsWindowEnabled (GetDlgItem (hWnd, ID_FIRST_BUTTON + NUM_BUTTONS))) SendMessage (hWnd, MSG_BUTTONCOMMAND, ID_FIRST_BUTTON + NUM_BUTTONS, 0); break; case SCANCODE_CURSORBLOCKUP: if (IsWindowEnabled (GetDlgItem (hWnd, ID_FIRST_BUTTON + NUM_BUTTONS + 1))) SendMessage (hWnd, MSG_BUTTONCOMMAND, ID_FIRST_BUTTON + NUM_BUTTONS + 1, 0); break; case SCANCODE_CURSORBLOCKRIGHT: if (IsWindowEnabled (GetDlgItem (hWnd, ID_FIRST_BUTTON + NUM_BUTTONS + 2))) SendMessage (hWnd, MSG_BUTTONCOMMAND, ID_FIRST_BUTTON + NUM_BUTTONS + 2, 0); break; } SetEnterButtonText (hWnd); break; case MSG_BUTTONCOMMAND: FooterHandleButtonCommand (hWnd, wParam); RegisterKeyMsgHook ((void*)hWnd, FooterHook); break; case MSG_COMMAND: if (wParam == ID_FIRST_BUTTON || wParam >= (ID_FIRST_BUTTON + NUM_BUTTONS - 1)) SendMessage (hWnd, MSG_BUTTONCOMMAND, wParam, 0); else if (wParam > ID_FIRST_BUTTON && wParam < ID_ENTER_BUTTON) SetEnterButtonText (hWnd); break; case MSG_CLOSE: RegisterKeyMsgHook (NULL, NULL); KillTimer (hWnd, ID_FOOTER_TIMER); DestroyMainWindow (hWnd); return 0; } return DefaultMainWinProc (hWnd, message, wParam, lParam);}static CTRLDATA FooterCtrls [NUM_BUTTONS + 3];static DLGTEMPLATE FooterTempl = { WS_THINFRAME | WS_VISIBLE, WS_EX_NONE, 0, 0, 0, 0, "菜单栏", 0, 0, NUM_BUTTONS + 3, FooterCtrls, 0};static void InitCreateInfo(void){ int i; int x, y; x = 0; y = HEIGHT_ROW * NUM_ROWS; for (i = 0; i < NUM_BUTTONS; i++) { FooterCtrls[i].class_name = "button"; FooterCtrls[i].dwStyle = WS_VISIBLE | BS_AUTORADIOBUTTON | BS_PUSHLIKE | BS_MULTLINE | BS_CENTER; FooterCtrls[i].x = x; FooterCtrls[i].y = y; FooterCtrls[i].w = WIDTH_BUTTON; FooterCtrls[i].h = HEIGHT_BUTTON; FooterCtrls[i].id = ID_FIRST_BUTTON + i; FooterCtrls[i].caption = szLabelPrefix [i];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -