1 /*-----------------------------------------------------------------------------
3 *-----------------------------------------------------------------------------
4 * Copyright (c) 2004-2005 Kazuo Ishii <k-ishii@wb4.so-net.ne.jp>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 *---------------------------------------------------------------------------*/
25 BOOL init_options(ckOpt& opt);
27 static void __write_console_input(LPCWSTR str, DWORD length)
29 if(!str || !length) return;
31 INPUT_RECORD *p, *buf;
33 p = buf = new INPUT_RECORD[ length ];
35 for( ; i < length ; i++, p++) {
36 p->EventType = KEY_EVENT;
37 p->Event.KeyEvent.bKeyDown = TRUE;
38 p->Event.KeyEvent.wRepeatCount = 1;
39 p->Event.KeyEvent.wVirtualKeyCode = 0;
40 p->Event.KeyEvent.wVirtualScanCode = 0;
41 p->Event.KeyEvent.uChar.UnicodeChar = 0;
42 p->Event.KeyEvent.dwControlKeyState = 0;
48 p->Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
51 p->Event.KeyEvent.uChar.UnicodeChar = *str++;
55 WriteConsoleInput(gStdIn, buf, length, &length);
60 void onPasteFromClipboard(HWND hWnd)
66 if(! IsClipboardFormatAvailable(CF_UNICODETEXT))
68 if(!OpenClipboard(hWnd)) {
70 if(!OpenClipboard(hWnd))
73 hMem = GetClipboardData(CF_UNICODETEXT);
76 if(result && !(ptr = (wchar_t*)GlobalLock(hMem)))
79 __write_console_input(ptr, (DWORD)wcslen(ptr));
86 void onDropFile(HDROP hDrop)
89 wchar_t wbuf[MAX_PATH+32];
92 nb = DragQueryFile(hDrop, (DWORD)-1, NULL, 0);
93 for(i = 0 ; i < nb ; i++) {
94 len = DragQueryFile(hDrop, i, NULL, 0);
95 if(len < 1 || len > MAX_PATH)
98 if(! DragQueryFile(hDrop, i, wp, MAX_PATH))
101 while(*wp > 0x20) wp++;
105 wp[0] = wp[len++] = L'\"';
112 __write_console_input(wp, len);
118 BOOL CALLBACK AboutDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
123 HWND hEdit = GetDlgItem(hWnd, IDC_EDIT1);
125 L"This program is free software; you can redistribute it and/or\r\n"
126 L"modify it under the terms of the GNU General Public License\r\n"
127 L"as published by the Free Software Foundation; either version 2\r\n"
128 L"of the License, or (at your option) any later version.\r\n"
130 L"This program is distributed in the hope that it will be useful,\r\n"
131 L"but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n"
132 L"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r\n"
133 L"See the GNU General Public License for more details.\r\n"
135 L"You should have received a copy of the GNU General Public License\r\n"
136 L"along with this program; if not, write to the Free Software Foundation, Inc.,\r\n"
137 L" 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA."
153 void sysmenu_init_subconfig(HWND hWnd, HMENU hMenu);
155 void sysmenu_init(HWND hWnd)
158 HMENU hMenu = GetSystemMenu(hWnd, FALSE);
160 memset(&mii, 0, sizeof(mii));
161 mii.cbSize = sizeof(mii);
162 mii.fMask = MIIM_TYPE | MIIM_ID;
164 mii.fType = MFT_STRING;
166 mii.dwTypeData = L"New (&N)";
167 mii.cch = (UINT) wcslen(mii.dwTypeData);
168 InsertMenuItem(hMenu, SC_CLOSE, FALSE, &mii);
170 sysmenu_init_subconfig(hWnd, hMenu);
172 mii.fType = MFT_SEPARATOR;
176 InsertMenuItem(hMenu, SC_CLOSE, FALSE, &mii);
178 mii.fType = MFT_STRING;
180 mii.dwTypeData = L"About (&A)";
181 mii.cch = (UINT) wcslen(mii.dwTypeData);
182 InsertMenuItem(hMenu, SC_CLOSE, FALSE, &mii);
184 mii.fType = MFT_SEPARATOR;
188 InsertMenuItem(hMenu, SC_CLOSE, FALSE, &mii);
191 void get_directory_path(wchar_t *path)
194 GetModuleFileName(NULL, path, MAX_PATH);
195 c = wcsrchr(path, L'\\');
199 void sysmenu_init_subconfig(HWND hWnd, HMENU hMenu)
202 HMENU hSubMenu = CreatePopupMenu();
204 memset(&mii, 0, sizeof(mii));
205 mii.cbSize = sizeof(mii);
206 mii.fMask = MIIM_TYPE | MIIM_ID;
208 wchar_t path[MAX_PATH+1];
209 get_directory_path(path);
210 wcscat_s(path, L"\\*.cfg");
213 memset(&fd, 0, sizeof(fd));
214 HANDLE hFile = FindFirstFile(path, &fd);
215 //MessageBox(hWnd, path, L"", MB_OK);
217 if (hFile != INVALID_HANDLE_VALUE)
221 mii.fType = MFT_STRING;
222 mii.wID = IDM_CONFIG_SELECT_1 + i;
223 mii.dwTypeData = fd.cFileName;
224 mii.cch = (UINT) wcslen(mii.dwTypeData);
225 InsertMenuItem(hSubMenu, 0, TRUE, &mii);
226 if(FindNextFile(hFile, &fd) == 0) { break; }
231 mii.fMask |= MIIM_SUBMENU;
232 mii.fType = MFT_STRING;
233 mii.wID = IDM_CONFIG_SELECT;
234 mii.hSubMenu = hSubMenu;
235 mii.dwTypeData = L"Config (&O)";
236 mii.cch = (UINT) wcslen(mii.dwTypeData);
237 InsertMenuItem(hMenu, SC_CLOSE, FALSE, &mii);
240 void reloadConfig(wchar_t *path)
242 char filepath[MAX_PATH+1];
243 wcstombs(filepath, path, MAX_PATH);
246 opt.setFile(filepath);
250 BOOL onConfigMenuCommand(HWND hWnd, DWORD id)
252 wchar_t path[MAX_PATH+1];
253 get_directory_path(path);
256 memset(&mii, 0, sizeof(mii));
257 mii.cbSize = sizeof(mii);
258 mii.fMask = MIIM_TYPE | MIIM_ID;
259 mii.fType = MFT_STRING;
261 HMENU hMenu = GetSystemMenu(hWnd, FALSE);
262 if (GetMenuItemInfo(hMenu, id, 0, &mii))
264 wchar_t sz[MAX_PATH+1], filepath[MAX_PATH+1];
267 GetMenuItemInfo(hMenu, id, 0, &mii);
268 wsprintf(filepath, L"%s\\%s", path, sz);
269 /* need to open file and update config here */
270 MessageBox(hWnd, filepath, L"", MB_OK);
271 reloadConfig(filepath);
278 BOOL onSysCommand(HWND hWnd, DWORD id)
282 DialogBox(GetModuleHandle(NULL),
283 MAKEINTRESOURCE(IDD_DIALOG1),
291 if(IDM_CONFIG_SELECT < id && id <= IDM_CONFIG_SELECT_MAX) {
292 return onConfigMenuCommand(hWnd, id);