OSDN Git Service

forgot to "git add" modified files, so re-commit:
[yamy/yamy.git] / dlgeditsetting.cpp
1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 // dlgeditsetting.cpp
3
4
5 #include "misc.h"
6 #include "mayurc.h"
7 #include "windowstool.h"
8 #include "dlgeditsetting.h"
9 #include "layoutmanager.h"
10 #include <windowsx.h>
11
12
13 ///
14 class DlgEditSetting : public LayoutManager
15 {
16   HWND m_hwndMayuPathName;                      ///
17   HWND m_hwndMayuPath;                          ///
18   HWND m_hwndSymbols;                           ///
19
20   DlgEditSettingData *m_data;                   ///
21
22 public:
23   ///
24   DlgEditSetting(HWND i_hwnd)
25     : LayoutManager(i_hwnd),
26       m_hwndMayuPathName(NULL),
27       m_hwndMayuPath(NULL),
28       m_hwndSymbols(NULL),
29       m_data(NULL)
30   {
31   }
32   
33   /// WM_INITDIALOG
34   BOOL wmInitDialog(HWND /* focus */, LPARAM i_lParam)
35   {
36     m_data = reinterpret_cast<DlgEditSettingData *>(i_lParam);
37     
38     setSmallIcon(m_hwnd, IDI_ICON_mayu);
39     setBigIcon(m_hwnd, IDI_ICON_mayu);
40     
41     CHECK_TRUE( m_hwndMayuPathName
42                 = GetDlgItem(m_hwnd, IDC_EDIT_mayuPathName) );
43     CHECK_TRUE( m_hwndMayuPath = GetDlgItem(m_hwnd, IDC_EDIT_mayuPath) );
44     CHECK_TRUE( m_hwndSymbols = GetDlgItem(m_hwnd, IDC_EDIT_symbols) );
45
46     SetWindowText(m_hwndMayuPathName, m_data->m_name.c_str());
47     SetWindowText(m_hwndMayuPath, m_data->m_filename.c_str());
48     SetWindowText(m_hwndSymbols, m_data->m_symbols.c_str());
49     
50     restrictSmallestSize();
51     
52     // set layout manager
53     typedef LayoutManager LM;
54
55     addItem(GetDlgItem(m_hwnd, IDC_STATIC_mayuPathName));
56     addItem(GetDlgItem(m_hwnd, IDC_EDIT_mayuPathName),
57             LM::ORIGIN_LEFT_EDGE, LM::ORIGIN_TOP_EDGE,
58             LM::ORIGIN_RIGHT_EDGE, LM::ORIGIN_TOP_EDGE);
59     addItem(GetDlgItem(m_hwnd, IDC_STATIC_mayuPathNameComment),
60             LM::ORIGIN_RIGHT_EDGE, LM::ORIGIN_TOP_EDGE,
61             LM::ORIGIN_RIGHT_EDGE, LM::ORIGIN_TOP_EDGE);
62
63     addItem(GetDlgItem(m_hwnd, IDC_STATIC_mayuPath));
64     addItem(GetDlgItem(m_hwnd, IDC_EDIT_mayuPath),
65             LM::ORIGIN_LEFT_EDGE, LM::ORIGIN_TOP_EDGE,
66             LM::ORIGIN_RIGHT_EDGE, LM::ORIGIN_TOP_EDGE);
67     addItem(GetDlgItem(m_hwnd, IDC_BUTTON_browse),
68             LM::ORIGIN_RIGHT_EDGE, LM::ORIGIN_TOP_EDGE,
69             LM::ORIGIN_RIGHT_EDGE, LM::ORIGIN_TOP_EDGE);
70
71     addItem(GetDlgItem(m_hwnd, IDC_STATIC_symbols));
72     addItem(GetDlgItem(m_hwnd, IDC_EDIT_symbols),
73             LM::ORIGIN_LEFT_EDGE, LM::ORIGIN_TOP_EDGE,
74             LM::ORIGIN_RIGHT_EDGE, LM::ORIGIN_TOP_EDGE);
75     addItem(GetDlgItem(m_hwnd, IDC_STATIC_symbolsComment),
76             LM::ORIGIN_RIGHT_EDGE, LM::ORIGIN_TOP_EDGE,
77             LM::ORIGIN_RIGHT_EDGE, LM::ORIGIN_TOP_EDGE);
78     
79     addItem(GetDlgItem(m_hwnd, IDOK),
80             LM::ORIGIN_CENTER, LM::ORIGIN_TOP_EDGE,
81             LM::ORIGIN_CENTER, LM::ORIGIN_TOP_EDGE);
82     addItem(GetDlgItem(m_hwnd, IDCANCEL),
83             LM::ORIGIN_CENTER, LM::ORIGIN_TOP_EDGE,
84             LM::ORIGIN_CENTER, LM::ORIGIN_TOP_EDGE);
85
86     restrictSmallestSize(LM::RESTRICT_BOTH);
87     restrictLargestSize(LM::RESTRICT_VERTICALLY);
88     
89     return TRUE;
90   }
91   
92   /// WM_CLOSE
93   BOOL wmClose()
94   {
95     CHECK_TRUE( EndDialog(m_hwnd, 0) );
96     return TRUE;
97   }
98
99   /// WM_COMMAND
100   BOOL wmCommand(int /* i_notify_code */, int i_id, HWND /* i_hwnd_control */)
101   {
102     _TCHAR buf[GANA_MAX_PATH];
103     switch (i_id)
104     {
105       case IDC_BUTTON_browse:
106       {
107         tstring title = loadString(IDS_openMayu);
108         tstring filter = loadString(IDS_openMayuFilter);
109         for (size_t i = 0; i < filter.size(); ++ i)
110           if (filter[i] == _T('|'))
111             filter[i] = _T('\0');
112
113         _tcscpy(buf, _T(".mayu"));
114         OPENFILENAME of;
115         memset(&of, 0, sizeof(of));
116         of.lStructSize = sizeof(of);
117         of.hwndOwner = m_hwnd;
118         of.lpstrFilter = filter.c_str();
119         of.nFilterIndex = 1;
120         of.lpstrFile = buf;
121         of.nMaxFile = NUMBER_OF(buf);
122         of.lpstrTitle = title.c_str();
123         of.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST |
124           OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
125         if (GetOpenFileName(&of))
126           SetWindowText(m_hwndMayuPath, buf);
127         return TRUE;
128       }
129       
130       case IDOK:
131       {
132         GetWindowText(m_hwndMayuPathName, buf, NUMBER_OF(buf));
133         m_data->m_name = buf;
134         GetWindowText(m_hwndMayuPath, buf, NUMBER_OF(buf));
135         m_data->m_filename = buf;
136         GetWindowText(m_hwndSymbols, buf, NUMBER_OF(buf));
137         m_data->m_symbols = buf;
138         CHECK_TRUE( EndDialog(m_hwnd, 1) );
139         return TRUE;
140       }
141       
142       case IDCANCEL:
143       {
144         CHECK_TRUE( EndDialog(m_hwnd, 0) );
145         return TRUE;
146       }
147     }
148     return FALSE;
149   }
150 };
151
152
153 //
154 #ifdef MAYU64
155 INT_PTR CALLBACK dlgEditSetting_dlgProc(HWND i_hwnd, UINT i_message,
156 #else
157 BOOL CALLBACK dlgEditSetting_dlgProc(HWND i_hwnd, UINT i_message,
158 #endif
159                                      WPARAM i_wParam, LPARAM i_lParam)
160 {
161   DlgEditSetting *wc;
162   getUserData(i_hwnd, &wc);
163   if (!wc)
164     switch (i_message)
165     {
166       case WM_INITDIALOG:
167         wc = setUserData(i_hwnd, new DlgEditSetting(i_hwnd));
168         return wc->wmInitDialog(
169           reinterpret_cast<HWND>(i_wParam), i_lParam);
170     }
171   else
172     switch (i_message)
173     {
174       case WM_COMMAND:
175         return wc->wmCommand(HIWORD(i_wParam), LOWORD(i_wParam),
176                              reinterpret_cast<HWND>(i_lParam));
177       case WM_CLOSE:
178         return wc->wmClose();
179       case WM_NCDESTROY:
180         delete wc;
181         return TRUE;
182       default:
183         return wc->defaultWMHandler(i_message, i_wParam, i_lParam);
184     }
185   return FALSE;
186 }