1 #include "studiox_includes.h"
2 #include "grid_setting_dlg.h"
3
4 enum grid_snap_test_commands{
5 TEST_CHECK_SHOW_GRID = 1,
6 TEST_CHECK_SNAP,
7 TEST_SET_GRID_SPACING,
8 TEST_SET_SNAP_SPACING,
9 TEST_SAVE,
10 TEST_CANCEL
11 };
12
IMPLEMENT_DYNAMIC(grid_setting_dlg,express_dialog)13 IMPLEMENT_DYNAMIC(grid_setting_dlg, express_dialog)
14
15 BEGIN_MESSAGE_MAP(grid_setting_dlg, express_dialog)
16 ON_EN_KILLFOCUS(IDC_EDIT_GRID_SPACING, &OnEditGridSpacing)
17 ON_EN_KILLFOCUS(IDC_EDIT_SNAP_SPACING, &OnEditSnapSpacing)
18 ON_MESSAGE(STUDIO_TEST, OnTestMessage)
19 END_MESSAGE_MAP()
20
21 ///////////////////////////////////////////////////////////////////////////////
22 grid_setting_dlg::grid_setting_dlg(CWnd* pParent)
23 : express_dialog(grid_setting_dlg::IDD, pParent)
24 {
25 IconId = IDB_GRID;
26 SetTitleText("Grid and Snap Settings");
27 }
28
29 ///////////////////////////////////////////////////////////////////////////////
~grid_setting_dlg()30 grid_setting_dlg::~grid_setting_dlg()
31 {
32 }
33
34 ///////////////////////////////////////////////////////////////////////////////
OnInitDialog()35 BOOL grid_setting_dlg::OnInitDialog()
36 {
37 express_dialog::OnInitDialog();
38
39 // TODO: Add extra initialization here
40 studiox_project *project = GetOpenProject();
41
42 if (project)
43 {
44 // Set grid spacing spin control
45 mGridSpacingVal = project->mHeader.grid_spacing;
46 CStatic *ps = (CStatic *)GetDlgItem(IDC_EDIT_GRID_SPACING);
47
48 mSpinGridSpacing.SetBuddy(ps);
49 mSpinGridSpacing.SetRange(MIN_GRID_SNAP_SPACE, MAX_GRID_SNAP_SPACE);
50 mSpinGridSpacing.SetPos(mGridSpacingVal);
51
52 // Set snap spacing spin cotnrol
53 mSnapSpacingVal = project->mHeader.snap_spacing;
54 ps = (CStatic *) GetDlgItem(IDC_EDIT_SNAP_SPACING);
55
56 mSpinSnapSpacing.SetBuddy(ps);
57 mSpinSnapSpacing.SetRange(MIN_GRID_SNAP_SPACE, MAX_GRID_SNAP_SPACE);
58 mSpinSnapSpacing.SetPos(mSnapSpacingVal);
59 }
60
61 AddCancelButton();
62 AddSaveButton();
63
64 return TRUE; // return TRUE unless you set the focus to a control
65 // EXCEPTION: OCX Property Pages should return FALSE
66 }
67
68 ///////////////////////////////////////////////////////////////////////////////
DoDataExchange(CDataExchange * pDX)69 void grid_setting_dlg::DoDataExchange(CDataExchange* pDX)
70 {
71 express_dialog::DoDataExchange(pDX);
72
73 DDX_Control(pDX, IDC_SPIN_GRID_SPACING, mSpinGridSpacing);
74 DDX_Control(pDX, IDC_SPIN_SNAP_SPACING, mSpinSnapSpacing);
75
76 studiox_project *project = GetOpenProject();
77 if (!project)
78 {
79 return;
80 }
81 DDX_Check(pDX, IDC_SHOW_GRID, project->mHeader.grid_enabled);
82 DDX_Check(pDX, IDC_SNAP_TO_GRID, project->mHeader.snap_enabled);
83 DDX_Check(pDX, IDC_SNAP_TO_WIDGET, project->mHeader.snap_to_widget_enabled);
84
85 if (pDX->m_bSaveAndValidate)
86 {
87 project->mHeader.grid_spacing = mSpinGridSpacing.GetPos();
88 project->mHeader.snap_spacing = mSpinSnapSpacing.GetPos();
89
90 if (GetTargetScreen())
91 {
92 GetTargetScreen()->Invalidate();
93 }
94 }
95 }
96
97 ///////////////////////////////////////////////////////////////////////////////
PreTranslateMessage(MSG * pMsg)98 BOOL grid_setting_dlg::PreTranslateMessage(MSG* pMsg)
99 {
100 // TODO: Add your specialized code here and/or call the base class
101 CWnd* focus_owner = GetFocus();
102
103 if (focus_owner)
104 {
105 int ctrl_id = focus_owner->GetDlgCtrlID();
106
107 switch (ctrl_id)
108 {
109 case IDC_EDIT_GRID_SPACING:
110 case IDC_EDIT_SNAP_SPACING:
111 if ((pMsg->message == WM_CHAR) && isprint(pMsg->wParam))
112 {
113 if (pMsg->wParam < '0' || pMsg->wParam > '9')
114 {
115 ErrorMsg("Unaccetable Character. You can only type a number here.", this);
116 return TRUE;
117 }
118 }
119 break;
120 }
121 }
122
123 return express_dialog::PreTranslateMessage(pMsg);
124 }
125
126 ///////////////////////////////////////////////////////////////////////////////
OnEditGridSpacing()127 void grid_setting_dlg::OnEditGridSpacing()
128 {
129 int val = GetDlgItemInt(IDC_EDIT_GRID_SPACING);
130
131 if ((val >= MIN_GRID_SNAP_SPACE) && (val <= MAX_GRID_SNAP_SPACE))
132 {
133 mGridSpacingVal = val;
134
135 }
136 else
137 {
138 char msg[255];
139 sprintf_s(msg, sizeof(msg), "Invalid value for grid spacing. Valid range is from %d to %d.", MIN_GRID_SNAP_SPACE, MAX_GRID_SNAP_SPACE);
140 Notify(msg, this);
141 SetDlgItemInt(IDC_EDIT_GRID_SPACING, mGridSpacingVal);
142 }
143 }
144
145 ///////////////////////////////////////////////////////////////////////////////
OnEditSnapSpacing()146 void grid_setting_dlg::OnEditSnapSpacing()
147 {
148 int val = GetDlgItemInt(IDC_EDIT_SNAP_SPACING);
149
150 if ((val >= MIN_GRID_SNAP_SPACE) && (val <= MAX_GRID_SNAP_SPACE))
151 {
152 mSnapSpacingVal = val;
153
154 }
155 else
156 {
157 char msg[255];
158 sprintf_s(msg, sizeof(msg), "Invalid value for snap spacing. Valid range is from %d to %d.", MIN_GRID_SNAP_SPACE, MAX_GRID_SNAP_SPACE);
159 Notify(msg, this);
160 SetDlgItemInt(IDC_EDIT_SNAP_SPACING, mSnapSpacingVal);
161 }
162 }
163
164 ///////////////////////////////////////////////////////////////////////////////
OnTestMessage(WPARAM wParam,LPARAM lParam)165 LRESULT grid_setting_dlg::OnTestMessage(WPARAM wParam, LPARAM lParam)
166 {
167 CWnd *pWnd;
168 NMUPDOWN NMUpDown;
169 NMHDR hdr;
170
171 switch (wParam)
172 {
173 case TEST_CHECK_SHOW_GRID:
174 pWnd = (CButton *)GetDlgItem(IDC_SHOW_GRID);
175 ((CButton *)pWnd)->SetCheck(lParam);
176 SendMessage(WM_COMMAND, MAKEWPARAM(IDC_SHOW_GRID, BN_CLICKED), (LPARAM)pWnd->m_hWnd);
177 break;
178
179 case TEST_CHECK_SNAP:
180 pWnd = (CButton *)GetDlgItem(IDC_SNAP_TO_GRID);
181 ((CButton *)pWnd)->SetCheck(lParam);
182 SendMessage(WM_COMMAND, MAKEWPARAM(IDC_SNAP_TO_GRID, BN_CLICKED), (LPARAM)pWnd->m_hWnd);
183 break;
184
185 case TEST_SET_GRID_SPACING:
186 hdr.hwndFrom = mSpinGridSpacing.m_hWnd;
187 hdr.idFrom = IDC_EDIT_GRID_SPACING;
188 hdr.code = UDN_DELTAPOS;
189
190 NMUpDown.hdr = hdr;
191 NMUpDown.iPos = mSpinGridSpacing.GetPos();
192 NMUpDown.iDelta = lParam - NMUpDown.iPos;
193
194 mSpinGridSpacing.SetPos(lParam);
195 SetDlgItemInt(IDC_EDIT_GRID_SPACING, lParam);
196
197 SendMessage(WM_NOTIFY, IDC_SPIN_GRID_SPACING, (LPARAM)&NMUpDown);
198 break;
199
200 case TEST_SET_SNAP_SPACING:
201 hdr.hwndFrom = mSpinSnapSpacing.m_hWnd;
202 hdr.idFrom = IDC_EDIT_SNAP_SPACING;
203 hdr.code = UDN_DELTAPOS;
204
205 NMUpDown.hdr = hdr;
206 NMUpDown.iPos = mSpinSnapSpacing.GetPos();
207 NMUpDown.iDelta = lParam - NMUpDown.iPos;
208
209 mSpinSnapSpacing.SetPos(lParam);
210 SetDlgItemInt(IDC_EDIT_SNAP_SPACING, lParam);
211
212 SendMessage(WM_NOTIFY, IDC_SPIN_SNAP_SPACING, (LPARAM)&NMUpDown);
213 break;
214
215 case TEST_SAVE:
216 OnOK();
217 break;
218
219 case TEST_CANCEL:
220 OnCancel();
221 break;
222 }
223
224 return 0;
225 }
226