?? mwmparse.y
字號:
%{/** * * $Id: mwmparse.y,v 1.1 2004/08/28 19:27:39 dannybackx Exp $ * * Copyright (C) 1995 Free Software Foundation, Inc. * Copyright (C) 1995-2002 LessTif Development Team * * This file is part of the GNU LessTif Library. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * **/#include "LTconfig.h"#include <stdlib.h>#include <stdarg.h>#include <stdio.h>#include <string.h>#ifdef HAVE_FCNTL_H#include <fcntl.h>#endif#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#ifdef HAVE_SYS_TYPES_H#include <sys/types.h>#endif#ifdef HAVE_SYS_STAT_H#include <sys/stat.h>#else#error "you lose (I don't know how to fix this)"#endif#include <X11/Xfuncs.h>#include <Xm/Xm.h>#include <Xm/MwmUtil.h>#include "mwm.h"extern int yydebug;extern int yylex(void);static int num_items;static MenuRoot *cur_menu;static ScreenInfo *pscr;static Boolean skip_test;static Boolean button_bind_match;static Boolean button_bind_found;static Boolean key_bind_match;static Boolean key_bind_found;/* * this must be here for the parser */static int lineno;%}%token ALT_TOK APP_TOK BACK_TOK BORDER_TOK BTN1_CLICK2_TOK BTN1_CLICK_TOK BTN1_DOWN_TOK BTN1_UP_TOK BTN2_CLICK2_TOK BTN2_CLICK_TOK BTN2_DOWN_TOK BTN2_UP_TOK BTN3_CLICK2_TOK BTN3_CLICK_TOK BTN3_DOWN_TOK BTN3_UP_TOK BTN4_CLICK2_TOK BTN4_CLICK_TOK BTN4_DOWN_TOK BTN4_UP_TOK BTN5_CLICK2_TOK BTN5_CLICK_TOK BTN5_DOWN_TOK BTN5_UP_TOK BUTTONS_TOK CTRL_TOK FBEEP_TOK FCIRCLE_DOWN_TOK FCIRCLE_UP_TOK FEXEC_TOK FFOCUS_COLOR_TOK FFOCUS_KEY_TOK FKILL_TOK FLOWER_TOK FMAXIMIZE_TOK FMENU_TOK FMINIMIZE_TOK FMOVE_TOK FNEXT_CMAP_TOK FNEXT_KEY_TOK FNOP_TOK FNORMALIZE_TOK FNORMANDRAISE_TOK FPACK_ICONS_TOK FPASS_KEYS_TOK FPOST_WMENU_TOK FPREV_CMAP_TOK FPREV_KEY_TOK FQUIT_MWM_TOK FRAISE_LOWER_TOK FRAISE_TOK FRAME_TOK FREE_FAMILY_TOK FREFRESH_TOK FREFRESH_WIN_TOK FRESIZE_TOK FRESTART_TOK FRESTOREANDRAISE_TOK FRESTORE_TOK FSCREEN_TOK FSEND_MSG_TOK FSEPARATOR_TOK FSET_BEHAVIOR_TOK FTITLE_TOK FWINDOWLIST_TOK FDESK_TOK FTOGGLE_PAGE_TOK FGOTO_PAGE_TOK ICON_TOK KEY_TOK KEYS_TOK LOCK_TOK MENU_TOK MENUB_TOK MINIMIZEB_TOK MAXIMIZEB_TOK MOD1_TOK MOD2_TOK MOD3_TOK MOD4_TOK MOD5_TOK NEXT_TOK PREV_TOK ROOT_TOK SHIFT_TOK TITLE_TOK TRANSIENT_TOK WINDOW_TOK WITHIN_TOK STRING_TOK%type <string> STRING_TOK%type <number> FCIRCLE_DOWN_TOK FCIRCLE_UP_TOK FEXEC_TOK FFOCUS_COLOR_TOK FFOCUS_KEY_TOK FKILL_TOK FLOWER_TOK FMAXIMIZE_TOK FMENU_TOK FMINIMIZE_TOK FMOVE_TOK FNEXT_CMAP_TOK FNEXT_KEY_TOK FNOP_TOK FNORMALIZE_TOK FNORMANDRAISE_TOK FPACK_ICONS_TOK FPASS_KEYS_TOK FPOST_WMENU_TOK FPREV_CMAP_TOK FPREV_KEY_TOK FQUIT_MWM_TOK FRAISE_LOWER_TOK FRAISE_TOK FRAME_TOK FREE_FAMILY_TOK FREFRESH_TOK FREFRESH_WIN_TOK FRESIZE_TOK FRESTART_TOK FRESTOREANDRAISE_TOK FRESTORE_TOK FSCREEN_TOK FSEND_MSG_TOK FSEPARATOR_TOK FSET_BEHAVIOR_TOK FTITLE_TOK ICON_TOK%type <string> bitmap_file string%type <label> label%type <number> context object%type <function> function%type <modifiers> modifier_name modifier_list%type <hotkey> key%union { char *string; int number; KeySym key; struct { int func; char *arg; } function; struct { int type; char *string; } label; long modifiers; struct { int button; int event; int count; int modifiers; } button; struct { int modifiers; KeySym key; } hotkey;};%%res_file: res_file binding |;binding: button_bindings | key_bindings | menu_bindings;button_bindings: BUTTONS_TOK string { if (!skip_test) { if (button_bind_found == False) { if (strcmp($2, pscr->button_bindings) == 0) button_bind_match = True; else button_bind_match = False; } else if (strcmp($2, pscr->button_bindings) == 0) { yyerror("Ignoring duplicate button bindings"); button_bind_match = False; } else button_bind_match = False; } else button_bind_match = True; } '{' button_list '}';button_list: button_list button_binding | error { yyerror("Invalid button binding"); yyerrok; yyclearin; } |;button_binding: button context function { int contexts = $<number>2; int mods, func; MenuItem *mi = NULL; MouseButton *temp = NULL, *ptr; if (!button_bind_match) break; mods = $<button>1.modifiers; if ((contexts & C_WINDOW) && (((mods == 0) || mods == AnyModifier))) { pscr->buttons2grab &= ~($<button>1.button); } func = $<function>3.func; if ((func == F_EXEC) || (func == F_RESTART) || (func == F_CIRCULATE_UP) || (func == F_CIRCULATE_DOWN) || (func == F_WARP)) { mi = (MenuItem *)XtMalloc(sizeof(MenuItem)); mi->next = (MenuItem *) NULL; mi->prev = (MenuItem *) NULL; if ((func == F_EXEC) || (func == F_RESTART)) { mi->item = XtNewString("DOIT"); mi->action = $<function>3.arg; } else { mi->item = XtNewString("DONT DOIT"); mi->action = $<function>3.arg; } mi->item2 = ""; mi->state = 0; mi->func = func; mi->strlen = strlen(mi->item); mi->strlen2 = 0; mi->val1 = 0; mi->val2 = 0; mi->val1_unit = 1; mi->val2_unit = 1; } temp = pscr->buttons; pscr->buttons = (MouseButton *)XtMalloc(sizeof(MouseButton)); pscr->buttons->func = func; if (func == F_POPUP) pscr->buttons->menu = (MenuRoot *)$<function>3.arg; else if (func == F_W_POPUP) pscr->buttons->menu = (MenuRoot *)DEFAULT_WIN_MENU_NAME; else pscr->buttons->menu = NULL; pscr->buttons->item = mi; pscr->buttons->button = ffs($<button>1.button) - 8; pscr->buttons->context = contexts; pscr->buttons->modifier = mods; pscr->buttons->mask = $<button>1.event; pscr->buttons->count = $<button>1.count; pscr->buttons->val1 = 0; pscr->buttons->val2 = 0; pscr->buttons->val1_unit = pscr->d_width; pscr->buttons->val2_unit = pscr->d_height; /* if duplicate, skip second */ for (ptr = temp; ptr != NULL; ptr = ptr->next) { /* If everything is the same except for having func's F_POPUP and F_WINDOWLIST, the second is a duplicate */ if (((ptr->func == F_POPUP || ptr->func == F_WINDOWLIST) && (pscr->buttons->func == F_POPUP || pscr->buttons->func == F_WINDOWLIST)) && ptr->modifier == pscr->buttons->modifier && ptr->mask == pscr->buttons->mask && ptr->count == pscr->buttons->count && ptr->context == pscr->buttons->context && ptr->button == pscr->buttons->button) { XtFree((char *)pscr->buttons); pscr->buttons = temp; break; } if (ptr->func == pscr->buttons->func && ptr->modifier == pscr->buttons->modifier && ptr->mask == pscr->buttons->mask && ptr->count == pscr->buttons->count && ptr->button == pscr->buttons->button) { ptr->context |= pscr->buttons->context; XtFree((char *)pscr->buttons); pscr->buttons = temp; break; } } if (ptr == NULL) pscr->buttons->next = temp; };key_bindings: KEYS_TOK string { if (!skip_test) { if (key_bind_found == False) { if (strcmp($2, pscr->key_bindings) == 0) key_bind_match = True; else key_bind_match = False; } else if (strcmp($2, pscr->key_bindings) == 0) { yyerror("Ignoring duplicate key bindings"); key_bind_match = False; } else key_bind_match = False; } else key_bind_match = True; } '{' key_list '}';key_list: key_list key_binding | error { yyerror("Invalid key binding"); yyerrok; yyclearin; } |;key_binding: key context function { FuncKey *tmp = NULL; KeySym keysym; KeyCode keycode; int i, min, max; int func, contexts; char *ptr; if (!key_bind_match) break; ptr = $<function>3.arg; func = $<function>3.func; contexts = $<number>2; /* * Don't let a 0 keycode go through, since that * means AnyKey to the XGrabKey call in GrabKeys(). */ keysym = $<hotkey>1.key; if (keysym == 0) break; if ((keycode = XKeysymToKeycode(dpy, $<hotkey>1.key)) == 0) break; XDisplayKeycodes(dpy, &min, &max); for (i = min; i <= max; i++) { if (XKeycodeToKeysym(dpy, i, 0) == keysym) { tmp = (FuncKey *)XtMalloc(sizeof(FuncKey)); tmp->next = pscr->keys; pscr->keys = tmp; tmp->name = "HOTKEY"; tmp->keycode = i; tmp->cont = contexts; tmp->mods = $<hotkey>1.modifiers; tmp->func = func; if (func == F_W_POPUP) tmp->action = DEFAULT_WIN_MENU_NAME; else tmp->action = ptr; tmp->val1 = 0; tmp->val2 = 0; tmp->val1_unit = pscr->d_width; tmp->val2_unit = pscr->d_height; tmp->menu = NULL; } } };menu_bindings: MENU_TOK string { num_items = 0; cur_menu = MENU_Create($<string>2); } '{' item_list '}' { MENU_Add(pscr, cur_menu); };item_list: item_list item_binding | error { yyerror("Invalid menu item"); yyerrok; yyclearin; } |;item_binding: label mnemonic accelerator function { MenuItem *tmp; int width, width2; FuncKey *tmpk = NULL; KeySym keysym; KeyCode keycode; int i, min, max; int func, contexts; char *ptr, *acc; tmp = (MenuItem *)XtCalloc(1, sizeof(MenuItem)); if (cur_menu->first == NULL) { cur_menu->first = tmp; tmp->prev = NULL; tmp->next = NULL; } else { cur_menu->last->next = tmp; tmp->prev = cur_menu->last; } cur_menu->last = tmp; cur_menu->items++; if ($<function>4.func == F_NOP) tmp->item = ""; else tmp->item = $<label>1.string; tmp->item2 = ""; MENU_FindHotKey(tmp, $<key>2); if (strcmp(tmp->item, "no-label") == 0) tmp->strlen = 0; else tmp->strlen = strlen(tmp->item); tmp->action = $<function>4.arg; tmp->next = NULL; tmp->state = 0; tmp->func = $<function>4.func; tmp->val1 = 0; tmp->val2 = 0; tmp->val1_unit = pscr->d_width; tmp->val2_unit = pscr->d_height; width = XTextWidth(pscr->components[MWM_MENU].font, tmp->item, tmp->strlen); if (tmp->func == F_POPUP) width += 15; if (width <= 0) width = 1; if (width > cur_menu->width) cur_menu->width = width; ptr = $<function>4.arg; func = $<function>4.func; contexts = C_WINDOW|C_ICON|C_FRAME|C_TITLE|C_LALL|C_RALL; /* * Don't let a 0 keycode go through, since that * means AnyKey to the XGrabKey call in GrabKeys(). */ keysym = $<hotkey>3.key; if (keysym == 0) break; if ((keycode = XKeysymToKeycode(dpy, $<hotkey>3.key)) == 0) break; acc = MENU_AcceleratorString(pscr, $<hotkey>3.key, $<hotkey>3.modifiers); if (strlen(acc)) { tmp->item2 = XtNewString(acc); tmp->strlen2 = strlen(acc); width2 = XTextWidth(pscr->components[MWM_MENU].font, tmp->item2, tmp->strlen2); if (width2 > cur_menu->width2) cur_menu->width2 = width2; } XDisplayKeycodes(dpy, &min, &max); for (i = min; i <= max; i++) { if (XKeycodeToKeysym(dpy, i, 0) == keysym) { tmpk = (FuncKey *)XtMalloc(sizeof(FuncKey)); tmpk->next = pscr->keys; pscr->keys = tmpk; tmpk->name = "HOTKEY"; tmpk->keycode = i; tmpk->cont = contexts; tmpk->mods = $<hotkey>3.modifiers; tmpk->func = func; tmpk->action = ptr; tmpk->val1 = 0; tmpk->val2 = 0; tmpk->val1_unit = pscr->d_width; tmpk->val2_unit = pscr->d_height; tmpk->menu = NULL; } } };accelerator: key { $<hotkey>$ = $<hotkey>1; } | { $<hotkey>$.modifiers = 0; $<hotkey>$.key = 0; };context: context '|' object { $<number>$ = $1 | $3; } | object { $<number>$ = $1; };object: ROOT_TOK { $<number>$ = C_ROOT; } | ICON_TOK { $<number>$ = C_ICON; } | MENUB_TOK { $<number>$ = C_MENUB; } | MINIMIZEB_TOK { $<number>$ = C_MINIMIZEB; } | MAXIMIZEB_TOK { $<number>$ = C_MAXIMIZEB; } | WINDOW_TOK { $<number>$ = C_WINDOW|C_FRAME|C_TITLE|C_LALL|C_RALL|C_ICON; } | TITLE_TOK { $<number>$ = C_TITLE; } | FRAME_TOK { $<number>$ = C_FRAME|C_TITLE|C_LALL|C_RALL; } | BORDER_TOK { $<number>$ = C_FRAME; } | APP_TOK { $<number>$ = C_WINDOW; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -