OSDN Git Service

Fix bugs process protection.
[ffftp/ffftp.git] / bookmark.c
1 /*=============================================================================\r
2 *\r
3 *                                                               ブックマーク\r
4 *\r
5 ===============================================================================\r
6 / Copyright (C) 1997-2007 Sota. All rights reserved.\r
7 /\r
8 / Redistribution and use in source and binary forms, with or without \r
9 / modification, are permitted provided that the following conditions \r
10 / are met:\r
11 /\r
12 /  1. Redistributions of source code must retain the above copyright \r
13 /     notice, this list of conditions and the following disclaimer.\r
14 /  2. Redistributions in binary form must reproduce the above copyright \r
15 /     notice, this list of conditions and the following disclaimer in the \r
16 /     documentation and/or other materials provided with the distribution.\r
17 /\r
18 / THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR \r
19 / IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES \r
20 / OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \r
21 / IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, \r
22 / INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, \r
23 / BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
24 / USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
25 / ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
26 / (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF \r
27 / THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
28 /============================================================================*/\r
29 \r
30 // UTF-8対応\r
31 //#define WINVER 0x400\r
32 \r
33 #define STRICT\r
34 #include <windows.h>\r
35 #include <stdio.h>\r
36 #include <stdlib.h>\r
37 #include <string.h>\r
38 #include <mbstring.h>\r
39 #include <malloc.h>\r
40 #include <windowsx.h>\r
41 #include <commctrl.h>\r
42 \r
43 #include "common.h"\r
44 #include "resource.h"\r
45 \r
46 #include <htmlhelp.h>\r
47 #include "helpid.h"\r
48 \r
49 // UTF-8対応\r
50 #undef __MBSWRAPPER_H__\r
51 #include "mbswrapper.h"\r
52 \r
53 \r
54 /*===== プロトタイプ =====*/\r
55 \r
56 static int AddBookMark(char *Path);\r
57 static int GetBothPath(char *Str, char **Path1, char **Path2);\r
58 static BOOL CALLBACK EditBookMarkProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
59 static BOOL CALLBACK BookMarkEditCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
60 \r
61 /*===== 外部参照 =====*/\r
62 \r
63 extern HWND hHelpWin;\r
64 \r
65 /* 設定値 */\r
66 extern HFONT ListFont;          /* リストボックスのフォント */\r
67 extern SIZE BmarkDlgSize;\r
68 \r
69 \r
70 \r
71 /*----- ブックマークをクリアする ----------------------------------------------\r
72 *\r
73 *       Parameter\r
74 *               なし\r
75 *\r
76 *       Return Value\r
77 *               なし\r
78 *----------------------------------------------------------------------------*/\r
79 \r
80 void ClearBookMark(void)\r
81 {\r
82         HMENU hMenu;\r
83 \r
84         hMenu = GetSubMenu(GetMenu(GetMainHwnd()), BMARK_SUB_MENU);\r
85         while(GetMenuItemCount(hMenu) > DEFAULT_BMARK_ITEM)\r
86                 DeleteMenu(hMenu, DEFAULT_BMARK_ITEM, MF_BYPOSITION);\r
87         return;\r
88 }\r
89 \r
90 \r
91 /*----- カレントディレクトリをブックマークに追加 ------------------------------\r
92 *\r
93 *       Parameter\r
94 *               int Win : ウインドウ番号 (WIN_xxx)\r
95 *\r
96 *       Return Value\r
97 *               なし\r
98 *----------------------------------------------------------------------------*/\r
99 \r
100 void AddCurDirToBookMark(int Win)\r
101 {\r
102         char Buf[BMARK_MARK_LEN + FMAX_PATH * 2 + BMARK_SEP_LEN + 1];\r
103 \r
104         if(Win == WIN_LOCAL)\r
105         {\r
106                 strcpy(Buf, BMARK_MARK_LOCAL);\r
107                 AskLocalCurDir(Buf + BMARK_MARK_LEN, FMAX_PATH);\r
108         }\r
109         else if(Win == WIN_REMOTE)\r
110         {\r
111                 strcpy(Buf, BMARK_MARK_REMOTE);\r
112                 AskRemoteCurDir(Buf + BMARK_MARK_LEN, FMAX_PATH);\r
113         }\r
114         else\r
115         {\r
116                 strcpy(Buf, BMARK_MARK_BOTH);\r
117                 AskLocalCurDir(Buf + BMARK_MARK_LEN, FMAX_PATH);\r
118                 strcat(Buf, BMARK_SEP);\r
119                 AskRemoteCurDir(Buf + strlen(Buf), FMAX_PATH);\r
120         }\r
121         AddBookMark(Buf);\r
122         return;\r
123 }\r
124 \r
125 \r
126 /*----- ブックマークにパスを登録する ------------------------------------------\r
127 *\r
128 *       Parameter\r
129 *               char *Path : パス名\r
130 *\r
131 *       Return Value\r
132 *               int ステータス\r
133 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
134 *----------------------------------------------------------------------------*/\r
135 \r
136 static int AddBookMark(char *Path)\r
137 {\r
138         HMENU hMenu;\r
139         int MarkID;\r
140         int Sts;\r
141 \r
142         Sts = FFFTP_FAIL;\r
143         hMenu = GetSubMenu(GetMenu(GetMainHwnd()), BMARK_SUB_MENU);\r
144         MarkID = (GetMenuItemCount(hMenu) - DEFAULT_BMARK_ITEM) + MENU_BMARK_TOP;\r
145         if(AppendMenu(hMenu, MF_STRING, MarkID, Path) == TRUE)\r
146                 Sts = FFFTP_SUCCESS;\r
147         return(Sts);\r
148 }\r
149 \r
150 \r
151 /*----- 指定のIDを持つブックマークのパスを返す --------------------------------\r
152 *\r
153 *       Parameter\r
154 *               int MarkID : ID\r
155 *               char *Local : ローカル側のパスを返すバッファ\r
156 *               char *Remote : リモート側のパスを返すバッファ\r
157 *               int Max : バッファのサイズ\r
158 *\r
159 *       Return Value\r
160 *               int ステータス (BMARK_TYPE_xxx)\r
161 *----------------------------------------------------------------------------*/\r
162 \r
163 int AskBookMarkText(int MarkID, char *Local, char *Remote, int Max)\r
164 {\r
165         HMENU hMenu;\r
166         MENUITEMINFO mInfo;\r
167         int Sts;\r
168         char Tmp[BMARK_MARK_LEN + FMAX_PATH * 2 + BMARK_SEP_LEN + 1];\r
169         char *Path1;\r
170         char *Path2;\r
171         int Num;\r
172 \r
173         memset(Local, NUL, Max);\r
174         memset(Remote, NUL, Max);\r
175 \r
176         Sts = BMARK_TYPE_NONE;\r
177         hMenu = GetSubMenu(GetMenu(GetMainHwnd()), BMARK_SUB_MENU);\r
178 \r
179         mInfo.cbSize = sizeof(MENUITEMINFO);\r
180         mInfo.fMask = MIIM_TYPE;\r
181         mInfo.dwTypeData = Tmp;\r
182         mInfo.cch = BMARK_MARK_LEN + FMAX_PATH * 2 + BMARK_SEP_LEN;\r
183         if(GetMenuItemInfo(hMenu, MarkID, FALSE, &mInfo) == TRUE)\r
184         {\r
185                 Num = GetBothPath(Tmp, &Path1, &Path2);\r
186                 if(strncmp(Tmp, BMARK_MARK_LOCAL, BMARK_MARK_LEN) == 0)\r
187                 {\r
188                         Sts = BMARK_TYPE_LOCAL;\r
189                         strncpy(Local, Path1, Max-1);\r
190                 }\r
191                 else if(strncmp(Tmp, BMARK_MARK_REMOTE, BMARK_MARK_LEN) == 0)\r
192                 {\r
193                         Sts = BMARK_TYPE_REMOTE;\r
194                         strncpy(Remote, Path1, Max-1);\r
195                 }\r
196                 else if(strncmp(Tmp, BMARK_MARK_BOTH, BMARK_MARK_LEN) == 0)\r
197                 {\r
198                         if(Num == 2)\r
199                         {\r
200                                 strncpy(Local, Path1, Max-1);\r
201                                 strncpy(Remote, Path2, Max-1);\r
202                                 Sts = BMARK_TYPE_BOTH;\r
203                         }\r
204                 }\r
205         }\r
206         return(Sts);\r
207 }\r
208 \r
209 \r
210 /*----- ブックマークの文字列から2つのパスを取り出す --------------------------\r
211 *\r
212 *       Parameter\r
213 *               char *Str : 文字列\r
214 *               char **Local : ローカル側のパスの先頭を返すワーク\r
215 *               char **Remote : リモート側のパスの先頭を返すワーク\r
216 *\r
217 *       Return Value\r
218 *               int パスの個数 (1 or 2)\r
219 *\r
220 *       Note\r
221 *               Strの内容を書き換える\r
222 *----------------------------------------------------------------------------*/\r
223 \r
224 static int GetBothPath(char *Str, char **Path1, char **Path2)\r
225 {\r
226         char *Pos;\r
227         int Ret;\r
228 \r
229         Ret = 1;\r
230         *Path1 = Str + BMARK_MARK_LEN;\r
231 \r
232         Pos = _mbsstr(Str, BMARK_SEP);\r
233         if(Pos != NULL)\r
234         {\r
235                 Ret = 2;\r
236                 *Pos = NUL;\r
237                 *Path2 = Pos + BMARK_SEP_LEN;\r
238         }\r
239         return(Ret);\r
240 }\r
241 \r
242 \r
243 /*----- ブックマークを接続中のホストリストに保存する --------------------------\r
244 *\r
245 *       Parameter\r
246 *               なし\r
247 *\r
248 *       Return Value\r
249 *               なし\r
250 *----------------------------------------------------------------------------*/\r
251 \r
252 void SaveBookMark(void)\r
253 {\r
254         HMENU hMenu;\r
255         MENUITEMINFO mInfo;\r
256         int i;\r
257         int Cnt;\r
258         char *Buf;\r
259         char *Pos;\r
260         int Len;\r
261         char Tmp[BMARK_MARK_LEN + FMAX_PATH * 2 + BMARK_SEP_LEN + 1];\r
262         int CurHost;\r
263 \r
264         if(AskConnecting() == YES)\r
265         {\r
266                 if((CurHost = AskCurrentHost()) != HOSTNUM_NOENTRY)\r
267                 {\r
268                         if((Buf = malloc(BOOKMARK_SIZE)) != NULL)\r
269                         {\r
270                                 hMenu = GetSubMenu(GetMenu(GetMainHwnd()), BMARK_SUB_MENU);\r
271 \r
272                                 Pos = Buf;\r
273                                 Len = 0;\r
274                                 Cnt = GetMenuItemCount(hMenu);\r
275                                 for(i = DEFAULT_BMARK_ITEM; i < Cnt; i++)\r
276                                 {\r
277                                         mInfo.cbSize = sizeof(MENUITEMINFO);\r
278                                         mInfo.fMask = MIIM_TYPE;\r
279                                         mInfo.dwTypeData = Tmp;\r
280                                         mInfo.cch = FMAX_PATH;\r
281                                         if(GetMenuItemInfo(hMenu, i, TRUE, &mInfo) == TRUE)\r
282                                         {\r
283                                                 if(Len + strlen(Tmp) + 2 <= BOOKMARK_SIZE)\r
284                                                 {\r
285                                                         strcpy(Pos, Tmp);\r
286                                                         Pos += strlen(Tmp) + 1;\r
287                                                         Len += strlen(Tmp) + 1;\r
288                                                 }\r
289                                         }\r
290                                 }\r
291 \r
292                                 if(Pos == Buf)\r
293                                 {\r
294                                         memset(Buf, NUL, 2);\r
295                                         Len = 2;\r
296                                 }\r
297                                 else\r
298                                 {\r
299                                         *Pos = NUL;\r
300                                         Len++;\r
301                                 }\r
302 \r
303                                 SetHostBookMark(CurHost, Buf, Len);\r
304 \r
305                                 free(Buf);\r
306                         }\r
307                 }\r
308         }\r
309         return;\r
310 }\r
311 \r
312 \r
313 /*----- ホストリストからブックマークを読み込む --------------------------------\r
314 *\r
315 *       Parameter\r
316 *               なし\r
317 *\r
318 *       Return Value\r
319 *               なし\r
320 *----------------------------------------------------------------------------*/\r
321 \r
322 void LoadBookMark(void)\r
323 {\r
324         char *Buf;\r
325         char *Pos;\r
326         int CurHost;\r
327         char Tmp[FMAX_PATH + BMARK_MARK_LEN + 1];\r
328 \r
329         if(AskConnecting() == YES)\r
330         {\r
331                 if((CurHost = AskCurrentHost()) != HOSTNUM_NOENTRY)\r
332                 {\r
333                         if((Buf = AskHostBookMark(CurHost)) != NULL)\r
334                         {\r
335                                 ClearBookMark();\r
336                                 Pos = Buf;\r
337                                 while(*Pos != NUL)\r
338                                 {\r
339                                         /* 旧フォーマットのための処理 */\r
340                                         /* (パスに"L"や"H"がついてない物) */\r
341                                         if((strncmp(Pos, BMARK_MARK_LOCAL, BMARK_MARK_LEN) != 0) &&\r
342                                            (strncmp(Pos, BMARK_MARK_REMOTE, BMARK_MARK_LEN) != 0) &&\r
343                                            (strncmp(Pos, BMARK_MARK_BOTH, BMARK_MARK_LEN) != 0))\r
344                                         {\r
345                                                 strcpy(Tmp, BMARK_MARK_REMOTE);\r
346                                                 strcat(Tmp, Pos);\r
347                                                 AddBookMark(Tmp);\r
348                                         }\r
349                                         else\r
350                                                 AddBookMark(Pos);\r
351 \r
352                                         Pos += strlen(Pos) + 1;\r
353                                 }\r
354                         }\r
355                 }\r
356         }\r
357         return;\r
358 }\r
359 \r
360 \r
361 /*----- ブックマーク編集ウインドウ --------------------------------------------\r
362 *\r
363 *       Parameter\r
364 *               なし\r
365 *\r
366 *       Return Value\r
367 *               ステータス (YES=実行/NO=取消)\r
368 *----------------------------------------------------------------------------*/\r
369 \r
370 int EditBookMark(void)\r
371 {\r
372         int Sts;\r
373 \r
374         Sts = DialogBox(GetFtpInst(), MAKEINTRESOURCE(bmark_dlg), GetMainHwnd(), EditBookMarkProc);\r
375         return(Sts);\r
376 }\r
377 \r
378 \r
379 /*----- ブックマーク編集ウインドウのコールバック ------------------------------\r
380 *\r
381 *       Parameter\r
382 *               HWND hDlg : ウインドウハンドル\r
383 *               UINT message : メッセージ番号\r
384 *               WPARAM wParam : メッセージの WPARAM 引数\r
385 *               LPARAM lParam : メッセージの LPARAM 引数\r
386 *\r
387 *       Return Value\r
388 *               BOOL TRUE/FALSE\r
389 *----------------------------------------------------------------------------*/\r
390 \r
391 static BOOL CALLBACK EditBookMarkProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
392 {\r
393         HMENU hMenu;\r
394         MENUITEMINFO mInfo;\r
395         int Cur;\r
396         int Max;\r
397         char Tmp[BMARK_MARK_LEN + FMAX_PATH * 2 + BMARK_SEP_LEN + 1];\r
398 \r
399         static DIALOGSIZE DlgSize = {\r
400                 { BMARK_NEW, BMARK_SET, BMARK_DEL, BMARK_DOWN, BMARK_UP, IDHELP, BMARK_SIZEGRIP, -1 },\r
401                 { IDOK, BMARK_JUMP, BMARK_SIZEGRIP, -1 },\r
402                 { BMARK_LIST, -1 },\r
403                 { 0, 0 },\r
404                 { 0, 0 }\r
405         };\r
406 \r
407         switch (message)\r
408         {\r
409                 case WM_INITDIALOG :\r
410                         if(ListFont != NULL)\r
411                                 SendDlgItemMessage(hDlg, BMARK_LIST, WM_SETFONT, (WPARAM)ListFont, MAKELPARAM(TRUE, 0));\r
412 \r
413                         hMenu = GetSubMenu(GetMenu(GetMainHwnd()), BMARK_SUB_MENU);\r
414                         Max = GetMenuItemCount(hMenu);\r
415                         for(Cur = DEFAULT_BMARK_ITEM; Cur < Max; Cur++)\r
416                         {\r
417                                 mInfo.cbSize = sizeof(MENUITEMINFO);\r
418                                 mInfo.fMask = MIIM_TYPE;\r
419                                 mInfo.dwTypeData = Tmp;\r
420                                 mInfo.cch = FMAX_PATH;\r
421                                 if(GetMenuItemInfo(hMenu, Cur, TRUE, &mInfo) == TRUE)\r
422                                         SendDlgItemMessage(hDlg, BMARK_LIST, LB_ADDSTRING, 0, (LPARAM)Tmp);\r
423                         }\r
424                         DlgSizeInit(hDlg, &DlgSize, &BmarkDlgSize);\r
425                     return(TRUE);\r
426 \r
427                 case WM_COMMAND :\r
428                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
429                         {\r
430                                 case BMARK_JUMP :\r
431                                         if((Cur = SendDlgItemMessage(hDlg, BMARK_LIST, LB_GETCURSEL, 0, 0)) != LB_ERR)\r
432                                                 PostMessage(GetMainHwnd(), WM_COMMAND, MAKEWPARAM(Cur+MENU_BMARK_TOP, 0), 0);\r
433                                         /* ここに break はない */\r
434 \r
435                                 case IDCANCEL :\r
436                                 case IDOK :\r
437                                         ClearBookMark();\r
438                                         Max = SendDlgItemMessage(hDlg, BMARK_LIST, LB_GETCOUNT, 0, 0);\r
439                                         for(Cur = 0; Cur < Max; Cur++)\r
440                                         {\r
441                                                 SendDlgItemMessage(hDlg, BMARK_LIST, LB_GETTEXT, Cur, (LPARAM)Tmp);\r
442                                                 AddBookMark(Tmp);\r
443                                         }\r
444                                         AskDlgSize(hDlg, &DlgSize, &BmarkDlgSize);\r
445                                         EndDialog(hDlg, YES);\r
446                                         break;\r
447 \r
448                                 case BMARK_SET :\r
449                                         if((Cur = SendDlgItemMessage(hDlg, BMARK_LIST, LB_GETCURSEL, 0, 0)) != LB_ERR)\r
450                                         {\r
451                                                 SendDlgItemMessage(hDlg, BMARK_LIST, LB_GETTEXT, Cur, (LPARAM)Tmp);\r
452                                                 if(DialogBoxParam(GetFtpInst(), MAKEINTRESOURCE(bmark_edit_dlg), hDlg, BookMarkEditCallBack, (LPARAM)Tmp) == YES)\r
453                                                 {\r
454                                                         SendDlgItemMessage(hDlg, BMARK_LIST, LB_DELETESTRING, Cur, 0);\r
455                                                         SendDlgItemMessage(hDlg, BMARK_LIST, LB_INSERTSTRING, Cur, (LPARAM)Tmp);\r
456                                                         SendDlgItemMessage(hDlg, BMARK_LIST, LB_SETCURSEL, Cur, 0);\r
457                                                 }\r
458                                         }\r
459                                         break;\r
460 \r
461                                 case BMARK_NEW :\r
462                                         strcpy(Tmp, "");\r
463                                         if(DialogBoxParam(GetFtpInst(), MAKEINTRESOURCE(bmark_edit_dlg), hDlg, BookMarkEditCallBack, (LPARAM)Tmp) == YES)\r
464                                         {\r
465                                                 SendDlgItemMessage(hDlg, BMARK_LIST, LB_ADDSTRING, 0, (LPARAM)Tmp);\r
466                                                 Cur = SendDlgItemMessage(hDlg, BMARK_LIST, LB_GETCOUNT, 0, 0) - 1;\r
467                                                 SendDlgItemMessage(hDlg, BMARK_LIST, LB_SETCURSEL, Cur, 0);\r
468                                         }\r
469                                         break;\r
470 \r
471                                 case BMARK_DEL :\r
472                                         if((Cur = SendDlgItemMessage(hDlg, BMARK_LIST, LB_GETCURSEL, 0, 0)) != LB_ERR)\r
473                                         {\r
474                                                 SendDlgItemMessage(hDlg, BMARK_LIST, LB_DELETESTRING, Cur, 0);\r
475                                                 if(Cur >= SendDlgItemMessage(hDlg, BMARK_LIST, LB_GETCOUNT, 0, 0))\r
476                                                         Cur = max1(0, SendDlgItemMessage(hDlg, BMARK_LIST, LB_GETCOUNT, 0, 0)-1);\r
477                                                 if(SendDlgItemMessage(hDlg, BMARK_LIST, LB_GETCOUNT, 0, 0) > 0)\r
478                                                         SendDlgItemMessage(hDlg, BMARK_LIST, LB_SETCURSEL, Cur, 0);\r
479                                         }\r
480                                         break;\r
481 \r
482                                 case BMARK_UP :\r
483                                         if((Cur = SendDlgItemMessage(hDlg, BMARK_LIST, LB_GETCURSEL, 0, 0)) != LB_ERR)\r
484                                         {\r
485                                                 if(Cur > 0)\r
486                                                 {\r
487                                                         SendDlgItemMessage(hDlg, BMARK_LIST, LB_GETTEXT, Cur, (LPARAM)Tmp);\r
488                                                         SendDlgItemMessage(hDlg, BMARK_LIST, LB_DELETESTRING, Cur, 0);\r
489                                                         SendDlgItemMessage(hDlg, BMARK_LIST, LB_INSERTSTRING, --Cur, (LPARAM)Tmp);\r
490                                                         SendDlgItemMessage(hDlg, BMARK_LIST, LB_SETCURSEL, Cur, 0);\r
491                                                 }\r
492                                         }\r
493                                         break;\r
494 \r
495                                 case BMARK_DOWN :\r
496                                         if((Cur = SendDlgItemMessage(hDlg, BMARK_LIST, LB_GETCURSEL, 0, 0)) != LB_ERR)\r
497                                         {\r
498                                                 if(Cur < SendDlgItemMessage(hDlg, BMARK_LIST, LB_GETCOUNT, 0, 0)-1)\r
499                                                 {\r
500                                                         SendDlgItemMessage(hDlg, BMARK_LIST, LB_GETTEXT, Cur, (LPARAM)Tmp);\r
501                                                         SendDlgItemMessage(hDlg, BMARK_LIST, LB_DELETESTRING, Cur, 0);\r
502                                                         SendDlgItemMessage(hDlg, BMARK_LIST, LB_INSERTSTRING, ++Cur, (LPARAM)Tmp);\r
503                                                         SendDlgItemMessage(hDlg, BMARK_LIST, LB_SETCURSEL, Cur, 0);\r
504                                                 }\r
505                                         }\r
506                                         break;\r
507 \r
508                                 case IDHELP :\r
509                                         hHelpWin = HtmlHelp(NULL, AskHelpFilePath(), HH_HELP_CONTEXT, IDH_HELP_TOPIC_0000019);\r
510                                         break;\r
511                         }\r
512                         return(TRUE);\r
513 \r
514                 case WM_SIZING :\r
515                         DlgSizeChange(hDlg, &DlgSize, (RECT *)lParam, (int)wParam);\r
516                     return(TRUE);\r
517 \r
518         }\r
519     return(FALSE);\r
520 }\r
521 \r
522 \r
523 /*----- ブックマーク入力ダイアログのコールバック ------------------------------\r
524 *\r
525 *       Parameter\r
526 *               HWND hDlg : ウインドウハンドル\r
527 *               UINT message : メッセージ番号\r
528 *               WPARAM wParam : メッセージの WPARAM 引数\r
529 *               LPARAM lParam : メッセージの LPARAM 引数\r
530 *\r
531 *       Return Value\r
532 *               BOOL TRUE/FALSE\r
533 *----------------------------------------------------------------------------*/\r
534 \r
535 static BOOL CALLBACK BookMarkEditCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
536 {\r
537         static char *Str;\r
538         char *Path1;\r
539         char *Path2;\r
540         char Local[FMAX_PATH+1];\r
541         char Remote[FMAX_PATH+1];\r
542         int Num;\r
543 \r
544         switch (iMessage)\r
545         {\r
546                 case WM_INITDIALOG :\r
547                         Str = (char *)lParam;\r
548                         SendDlgItemMessage(hDlg, BEDIT_LOCAL, EM_LIMITTEXT, FMAX_PATH-1, 0);\r
549                         SendDlgItemMessage(hDlg, BEDIT_REMOTE, EM_LIMITTEXT, FMAX_PATH-1, 0);\r
550                         if(strlen(Str) > BMARK_MARK_LEN)\r
551                         {\r
552                                 Num = GetBothPath(Str, &Path1, &Path2);\r
553                                 if(strncmp(Str, BMARK_MARK_LOCAL, BMARK_MARK_LEN) == 0)\r
554                                         SendDlgItemMessage(hDlg, BEDIT_LOCAL, WM_SETTEXT, 0, (LPARAM)Path1);\r
555                                 else if(strncmp(Str, BMARK_MARK_REMOTE, BMARK_MARK_LEN) == 0)\r
556                                 {\r
557                                         SendDlgItemMessage(hDlg, BEDIT_REMOTE, WM_SETTEXT, 0, (LPARAM)Path1);\r
558                                         /* ホスト側にカーソルを移動しておく */\r
559                                         SetFocus(GetDlgItem(hDlg, BEDIT_REMOTE));\r
560                                         SendDlgItemMessage(hDlg, BEDIT_REMOTE, EM_SETSEL, 0, -1);\r
561                                         return(FALSE);\r
562                                 }\r
563                                 else if((strncmp(Str, BMARK_MARK_BOTH, BMARK_MARK_LEN) == 0) && (Num == 2))\r
564                                 {\r
565                                         SendDlgItemMessage(hDlg, BEDIT_LOCAL, WM_SETTEXT, 0, (LPARAM)Path1);\r
566                                         SendDlgItemMessage(hDlg, BEDIT_REMOTE, WM_SETTEXT, 0, (LPARAM)Path2);\r
567                                 }\r
568                         }\r
569                         return(TRUE);\r
570 \r
571                 case WM_COMMAND :\r
572                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
573                         {\r
574                                 case IDOK :\r
575                                         SendDlgItemMessage(hDlg, BEDIT_LOCAL, WM_GETTEXT, FMAX_PATH+1, (LPARAM)Local);\r
576                                         SendDlgItemMessage(hDlg, BEDIT_REMOTE, WM_GETTEXT, FMAX_PATH+1, (LPARAM)Remote);\r
577                                         if(strlen(Local) > 0)\r
578                                         {\r
579                                                 if(strlen(Remote) > 0)\r
580                                                 {\r
581                                                         /* 両方 */\r
582                                                         strcpy(Str, BMARK_MARK_BOTH);\r
583                                                         strcat(Str, Local);\r
584                                                         strcat(Str, BMARK_SEP);\r
585                                                         strcat(Str, Remote);\r
586                                                 }\r
587                                                 else\r
588                                                 {\r
589                                                         /* ローカルのみ */\r
590                                                         strcpy(Str, BMARK_MARK_LOCAL);\r
591                                                         strcat(Str, Local);\r
592                                                 }\r
593                                                 EndDialog(hDlg, YES);\r
594                                         }\r
595                                         else if(strlen(Remote) > 0)\r
596                                         {\r
597                                                 /* ホストのみ */\r
598                                                 strcpy(Str, BMARK_MARK_REMOTE);\r
599                                                 strcat(Str, Remote);\r
600                                                 EndDialog(hDlg, YES);\r
601                                         }\r
602                                         else\r
603                                                 EndDialog(hDlg, NO);\r
604                                         break;\r
605 \r
606                                 case IDCANCEL :\r
607                                         EndDialog(hDlg, NO);\r
608                                         break;\r
609                         }\r
610             return(TRUE);\r
611         }\r
612         return(FALSE);\r
613 }\r
614 \r
615 \r