<commit_before>/*----------------------------------------------------------------------------*/
/*  menu.c                                                                    */
/*----------------------------------------------------------------------------*/
/*  copyright         : (C) 2002 by <NAME>                               */
/*                      VISC Software & Security Consultant Company           */
/*                      Hall 3, Quang Trung Software City                     */
/*                      Tan Chanh Hiep Ward, District 12,                     */
/*                      Ho Chi Minh city, VIETNAM                             */
/*  website           : http://www.visc-network.com                           */
/*  email             : <EMAIL>                                  */
/*  last modify       : Tue, 13 Aug 2002 03:14:07 +0700                       */
/*----------------------------------------------------------------------------*/
/*                                                                            */
/*   This program is free software; you can redistribute it and/or modify     */
/*   it under the terms of the GNU General Public License as published by     */
/*   the Free Software Foundation; either version 2 of the License, or        */
/*   (at your option) any later version.                                      */
/*                                                                            */
/*----------------------------------------------------------------------------*/
#include "data.h"
#include "flash.h"
#include "event.h"
#include "mainwin.h"
#include "systray.h"
#include "menu.h"
/*----------------------------------------------------------------------------*/
#ifdef VK_CHECK_SPELLING
#define DOCK_MSG_IDX	3
#else
#define DOCK_MSG_IDX	2
#endif
/*----------------------------------------------------------------------------*/
typedef struct vk_menu_item {
	int x, y;
	char *name;
	int type;
	int *vptr;
	int value;
	int length;
	int width;
	struct vk_menu_item *next;
	struct vk_menu *menu;
} vk_menu_item;
/*----------------------------------------------------------------------------*/
typedef struct vk_menu {
	int x, y;
	int w, h;
	int tx, ty;
	char *name;
	int sidex;
	vk_menu_item *sitem;
	vk_menu_item *items;

	Window win;
	GC gc;
} vk_menu;
/*----------------------------------------------------------------------------*/
#define MENU_PADDING	4
/*----------------------------------------------------------------------------*/
static char *vk_dock_message[][2] = {
	{"Docking to systray", "Undocking"},
	{"Đặt vào khay", "Gỡ khỏi khay"}
};
/*----------------------------------------------------------------------------*/
vk_menu_item vk_menu_data[][25] =
{
	{
	{ 0, 0, "About",				-2 },
	{ 0, 0, "Miscellaneous",		 0 },
#ifdef VK_CHECK_SPELLING
	{ 0, 0, "Check spelling",		 7, &vk_spelling, 1 },
#endif
	{ 0, 0, NULL,					 8, NULL },
	{ 0, 0, "Set hotkey",			 5, NULL },
	{ 0, 0, "Set interface font",	 6, NULL },
	{ 0, 0, "Input method",			 0 },
	{ 0, 0, "Off",					 1, &vk_method, VKM_OFF },
	{ 0, 0, "Vni",					 1, &vk_method, VKM_VNI },
	{ 0, 0, "Telex",				 1, &vk_method, VKM_TELEX },
	{ 0, 0, "Viqr",					 1, &vk_method, VKM_VIQR },
	{ 0, 0, "Charset",				 0 },
	{ 0, 0, "Unicode",				 3, &vk_charset, VKC_UTF8 },
	{ 0, 0, "Tcvn3",				 3, &vk_charset, VKC_TCVN },
	{ 0, 0, "Vni",					 3, &vk_charset, VKC_VNI },
	{ 0, 0, "Viqr",					 3, &vk_charset, VKC_VIQR },
	{ 0, 0, "Viscii",				 3, &vk_charset, VKC_VISCII },
	{ 0, 0, "Vps",					 3, &vk_charset, VKC_VPS },
	{ 0, 0, "Interface",			 0 },
	{ 0, 0, "English",				 4, &vk_interface, VK_ENGLISH },
	{ 0, 0, "Vietnamese",			 4, &vk_interface, VK_VIETNAMESE },
	{ 0, 0, "Exit",					-1 },
	{ 0, 0, NULL,					 0 }
	},
	{
	{ 0, 0, "Thông tin",			-2 },
	{ 0, 0, "<NAME>",			 0 },
#ifdef VK_CHECK_SPELLING
	{ 0, 0, "Kiểm tra từ",			 7, &vk_spelling, 1 },
#endif
	{ 0, 0, NULL,					 8, NULL },
	{ 0, 0, "Chọn phím bật/tắt",	 5, NULL },
	{ 0, 0, "Chọn font giao diện",	 6, NULL },
	{ 0, 0, "Kiểu gõ",				 0 },
	{ 0, 0, "Tắt",					 1, &vk_method, VKM_OFF },
	{ 0, 0, "Vni",					 1, &vk_method, VKM_VNI },
	{ 0, 0, "Telex",				 1, &vk_method, VKM_TELEX },
	{ 0, 0, "Viqr",					 1, &vk_method, VKM_VIQR },
	{ 0, 0, "Bảng mã",				 0 },
	{ 0, 0, "Unicode",				 3, &vk_charset, VKC_UTF8 },
	{ 0, 0, "Tcvn3",				 3, &vk_charset, VKC_TCVN },
	{ 0, 0, "Vni",					 3, &vk_charset, VKC_VNI },
	{ 0, 0, "Viqr",					 3, &vk_charset, VKC_VIQR },
	{ 0, 0, "Viscii",				 3, &vk_charset, VKC_VISCII },
	{ 0, 0, "Vps",					 3, &vk_charset, VKC_VPS },
	{ 0, 0, "Giao diện",			 0 },
	{ 0, 0, "Tiếng Anh",			 4, &vk_interface, VK_ENGLISH },
	{ 0, 0, "Tiếng Việt",			 4, &vk_interface, VK_VIETNAMESE },
	{ 0, 0, "Thoát",				-1 },
	{ 0, 0, NULL,					 0 }
	}
};
/*----------------------------------------------------------------------------*/
vk_menu menu = {
	0, 0, 0, 0, 0, 0,
	"xvnkb  "VERSION,
	0, NULL, NULL,
	0, 0
};
/*----------------------------------------------------------------------------*/
extern void VKDrawIcon();
extern void VKIconLoadInterface();
extern void VKCreateFlash();
extern void VKDestroyFlash();
extern void VKShowHotkeyWindow();
extern void VKDrawHotkeyWindow();
/*----------------------------------------------------------------------------*/
void MenuProcess(XEvent *event, void *data);
/*----------------------------------------------------------------------------*/
void CreateMenuWindow(vk_menu *m, int w, int h)
{
	m->w = w + 36;
	m->h = h * (vk_text_height + 4) + MENU_PADDING;
	m->tx = 12;
	m->ty = vk_font->ascent + 4;
	m->win = XCreateWindow(display, root,
					m->x, m->y, m->w, m->h, 0,
					DefaultDepth(display, screen), InputOutput, visual,
					vk_attribmask, &vk_attrib);
	XSelectInput(display, m->win, MAIN_EVENT_MASKS);

	m->gc = XCreateGC(display, m->win, 0, 0);
	XDefineCursor(display, m->win, vk_hand);
#ifndef USE_XFT
	XSetFont(display, m->gc, vk_font->fid);
#endif
	VKRegisterEvent(m->win, MenuProcess, m);
}
/*----------------------------------------------------------------------------*/
void CalculateItemWidth(vk_menu_item *current, vk_menu_item *item)
{
	char *s = item->name;
#ifdef USE_XFT
	XGlyphInfo fi;
	XftTextExtentsUtf8(display, vk_font, s, item->length = strlen(s), &fi);
#else<commit_msg>Cleanup<commit_after>/*----------------------------------------------------------------------------*/
/*  menu.c                                                                    */
/*----------------------------------------------------------------------------*/
/*  copyright         : (C) 2002 by <NAME>                               */
/*                      VISC Software & Security Consultant Company           */
/*                      Hall 3, Quang Trung Software City                     */
/*                      Tan Chanh Hiep Ward, District 12,                     */
/*                      Ho Chi Minh city, VIETNAM                             */
/*  website           : http://www.visc-network.com                           */
/*  email             : <EMAIL>                                  */
/*  last modify       : Tue, 13 Aug 2002 03:14:07 +0700                       */
/*----------------------------------------------------------------------------*/
/*                                                                            */
/*   This program is free software; you can redistribute it and/or modify     */
/*   it under the terms of the GNU General Public License as published by     */
/*   the Free Software Foundation; either version 2 of the License, or        */
/*   (at your option) any later version.                                      */
/*                                                                            */
/*----------------------------------------------------------------------------*/
#include "data.h"
#include "flash.h"
#include "event.h"
#include "mainwin.h"
#include "systray.h"
#include "menu.h"
/*----------------------------------------------------------------------------*/
#ifdef VK_CHECK_SPELLING
#define DOCK_MSG_IDX	3
#else
#define DOCK_MSG_IDX	2
#endif
/*----------------------------------------------------------------------------*/
typedef struct vk_menu_item {
	int x, y;
	char *name;
	int type;
	int *vptr;
	int value;
	int length;
	int width;
	struct vk_menu_item *next;
	struct vk_menu *menu;
} vk_menu_item;
/*----------------------------------------------------------------------------*/
typedef struct vk_menu {
	int x, y;
	int w, h;
	int tx, ty;
	char *name;
	int sidex;
	vk_menu_item *sitem;
	vk_menu_item *items;

	Window win;
	GC gc;
} vk_menu;
/*----------------------------------------------------------------------------*/
#define MENU_PADDING	4
/*----------------------------------------------------------------------------*/
static char *vk_dock_message[][2] = {
	{"Docking to systray", "Undocking"},
	{"Đặt vào khay", "Gỡ khỏi khay"}
};
/*----------------------------------------------------------------------------*/
vk_menu_item vk_menu_data[][25] =
{
	{
	{ 0, 0, "About",				-2 },
	{ 0, 0, "Miscellaneous",		 0 },
#ifdef VK_CHECK_SPELLING
	{ 0, 0, "Check spelling",		 7, &vk_spelling, 1 },
#endif
	{ 0, 0, NULL,					 8, NULL },
	{ 0, 0, "Set hotkey",			 5, NULL },
	{ 0, 0, "Set interface font",	 6, NULL },
	{ 0, 0, "Input method",			 0 },
	{ 0, 0, "Off",					 1, &vk_method, VKM_OFF },
	{ 0, 0, "Vni",					 1, &vk_method, VKM_VNI },
	{ 0, 0, "Telex",				 1, &vk_method, VKM_TELEX },
	{ 0, 0, "Viqr",					 1, &vk_method, VKM_VIQR },
	{ 0, 0, "Charset",				 0 },
	{ 0, 0, "Unicode",				 3, &vk_charset, VKC_UTF8 },
	{ 0, 0, "Tcvn3",				 3, &vk_charset, VKC_TCVN },
	{ 0, 0, "Vni",					 3, &vk_charset, VKC_VNI },
	{ 0, 0, "Viqr",					 3, &vk_charset, VKC_VIQR },
	{ 0, 0, "Viscii",				 3, &vk_charset, VKC_VISCII },
	{ 0, 0, "Vps",					 3, &vk_charset, VKC_VPS },
	{ 0, 0, "Interface",			 0 },
	{ 0, 0, "English",				 4, &vk_interface, VK_ENGLISH },
	{ 0, 0, "Vietnamese",			 4, &vk_interface, VK_VIETNAMESE },
	{ 0, 0, "Exit",					-1 },
	{ 0, 0, NULL,					 0 }
	},
	{
	{ 0, 0, "Thông tin",			-2 },
	{ 0, 0, "Linh tinh",			 0 },
#ifdef VK_CHECK_SPELLING
	{ 0, 0, "Kiểm tra từ",			 7, &vk_spelling, 1 },
#endif
	{ 0, 0, NULL,					 8, NULL },
	{ 0, 0, "Chọn phím bật/tắt",	 5, NULL },
	{ 0, 0, "Chọn font giao diện",	 6, NULL },
	{ 0, 0, "Kiểu gõ",				 0 },
	{ 0, 0, "Tắt",					 1, &vk_method, VKM_OFF },
	{ 0, 0, "Vni",					 1, &vk_method, VKM_VNI },
	{ 0, 0, "Telex",				 1, &vk_method, VKM_TELEX },
	{ 0, 0, "Viqr",					 1, &vk_method, VKM_VIQR },
	{ 0, 0, "Bảng mã",				 0 },
	{ 0, 0, "Unicode",				 3, &vk_charset, VKC_UTF8 },
	{ 0, 0, "Tcvn3",				 3, &vk_charset, VKC_TCVN },
	{ 0, 0, "Vni",					 3, &vk_charset, VKC_VNI },
	{ 0, 0, "Viqr",					 3, &vk_charset, VKC_VIQR },
	{ 0, 0, "Viscii",				 3, &vk_charset, VKC_VISCII },
	{ 0, 0, "Vps",					 3, &vk_charset, VKC_VPS },
	{ 0, 0, "Giao diện",			 0 },
	{ 0, 0, "Tiếng Anh",			 4, &vk_interface, VK_ENGLISH },
	{ 0, 0, "Tiếng Việt",			 4, &vk_interface, VK_VIETNAMESE },
	{ 0, 0, "Thoát",				-1 },
	{ 0, 0, NULL,					 0 }
	}
};
/*----------------------------------------------------------------------------*/
vk_menu menu = {
	0, 0, 0, 0, 0, 0,
	"xvnkb  "VERSION,
	0, NULL, NULL,
	0, 0
};
/*----------------------------------------------------------------------------*/
extern void VKDrawIcon();
extern void VKIconLoadInterface();
extern void VKCreateFlash();
extern void VKDestroyFlash();
extern void VKShowHotkeyWindow();
extern void VKDrawHotkeyWindow();
/*----------------------------------------------------------------------------*/
void MenuProcess(XEvent *event, void *data);
/*----------------------------------------------------------------------------*/
void CreateMenuWindow(vk_menu *m, int w, int h)
{
	m->w = w + 36;
	m->h = h * (vk_text_height + 4) + MENU_PADDING;
	m->tx = 12;
	m->ty = vk_text_ascent + 4;
	m->win = XCreateWindow(display, root,
					m->x, m->y, m->w, m->h, 0,
					DefaultDepth(display, screen), InputOutput, visual,
					vk_attribmask, &vk_attrib);
	XSelectInput(display, m->win, MAIN_EVENT_MASKS);

	m->gc = XCreateGC(display, m->win, 0, 0);
	XDefineCursor(display, m->win, vk_hand);
#ifndef USE_XFT
	XSetFont(display, m->gc, vk_font->fid);
#endif
	VKRegisterEvent(m->win, MenuProcess, m);
}
/*----------------------------------------------------------------------------*/
void CalculateItemWidth(vk_menu_item *current, vk_menu_item *item)
{
	char *s = item->name;
#ifdef USE_XFT
	XGlyphInfo fi;
	XftTextExtentsUtf8(display, vk_font, s, item->length = strlen(s), &fi);
#else
{'fraction_non_alphanumeric': 0.3228950311551366, 'fraction_numerical': 0.030835596740693402, 'mean_word_length': 1.2114467408585055, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6279181', 'n_tokens_mistral': 5049, 'n_tokens_neox': 4214, 'n_words': 1098}