-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallbacks.c
354 lines (318 loc) · 8.86 KB
/
callbacks.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#include <stdio.h>
#include <windowsx.h>
#include "callbacks.h"
#include "resource.h"
#include "MIDI.h"
#include "util.h"
BOOLEAN dragging;
HIMAGELIST imageList;
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
static HINSTANCE hInstance;
static HDC hdcStatic = NULL;
INT pos, i, r;
POINT p;
LV_ITEM lvi;
LPWSTR buf;
LVHITTESTINFO lvhti;
switch(msg) {
case WM_COMMAND:
switch(LOWORD(wParam)) {
case ID_HELP_ABOUT:
DialogBox(hInstance, MAKEINTRESOURCE(IDD_ABOUTDIALOG), hWnd, &AboutDialogProc);
return 0;
default:
PostMessage(NULL, msg, wParam, lParam);
break;
}
break;
case WM_MOUSEMOVE:
if(!dragging)
break;
p.x = LOWORD(lParam);
p.y = HIWORD(lParam);
ClientToScreen(hWnd, &p);
ImageList_DragMove(p.x, p.y);
break;
case WM_LBUTTONUP:
if(!dragging)
break;
dragging = FALSE;
ImageList_DragLeave(tlist);
ImageList_EndDrag();
ImageList_Destroy(imageList);
ReleaseCapture();
lvhti.pt.x = LOWORD(lParam);
lvhti.pt.y = HIWORD(lParam);
ClientToScreen(hWnd, &lvhti.pt);
ScreenToClient(tlist, &lvhti.pt);
ListView_HitTest(tlist, &lvhti);
if(lvhti.iItem <= 0 ||
(lvhti.flags & (LVHT_ONITEMLABEL | LVHT_ONITEMSTATEICON)) == 0)
break;
lvi.iItem = lvhti.iItem;
lvi.iSubItem = 0;
lvi.mask = LVIF_STATE;
lvi.stateMask = LVIS_SELECTED;
ListView_GetItem(tlist, &lvi);
if(lvi.state & LVIS_SELECTED)
break;
pos = ListView_GetNextItem(tlist, -1, LVNI_SELECTED);
if(pos != -1) {
buf = malloc(52 * sizeof *buf);
lvi.iItem = pos;
lvi.iSubItem = 0;
lvi.cchTextMax = 51;
lvi.pszText = buf;
lvi.stateMask = (UINT) ~LVIS_SELECTED;
lvi.mask = LVIF_STATE | LVIF_IMAGE
| LVIF_INDENT | LVIF_PARAM | LVIF_TEXT;
ListView_GetItem(tlist, &lvi);
lvi.iItem = lvhti.iItem;
r = ListView_InsertItem(tlist, &lvi);
if(r <= pos)
pos++;
for(i = 1; i < COL_LEN; i++) {
ListView_GetItemText(tlist, pos, i, buf, 51);
ListView_SetItemText(tlist, r, i, buf);
}
ListView_DeleteItem(tlist, pos);
free(buf);
PostMessage(NULL, SWAP_STRACKS, (WPARAM) --lvhti.iItem, (LPARAM) --pos);
}
break;
case WM_NOTIFY:
if(((LPNMHDR) lParam)->code == HDN_BEGINTRACK) {
return TRUE;
}
if(wParam == ID_TRACKS) {
switch(((LPNMHDR) lParam)->code) {
case LVN_ITEMACTIVATE:
break;
case LVN_BEGINDRAG:
p.x = 8;
p.y = 8;
pos = ListView_GetNextItem(tlist, -1, LVNI_SELECTED);
if(pos > 0) {
imageList = ListView_CreateDragImage(tlist, pos, &p);
ImageList_BeginDrag(imageList, 0, 0, 0);
p = ((NM_LISTVIEW *) ((LPNMHDR) lParam))->ptAction;
ClientToScreen(tlist, &p);
ImageList_DragEnter(GetDesktopWindow(), p.x, p.y);
dragging = TRUE;
SetCapture(hWnd);
}
break;
default:
PostMessage(NULL, msg, wParam, lParam);
break;
}
}
else {
PostMessage(NULL, msg, wParam, lParam);
}
break;
case WM_CLOSE:
if(!AreThereAnyFuckingChanges()) {
DestroyWindow(hWnd);
}
else {
switch(MessageBox(hWnd,
TEXT("There are unsaved changes in tracks list.\n Would you like to save them now?"),
TEXT("Unsaved changes"), MB_ICONWARNING | MB_YESNOCANCEL)) {
case IDYES:
PostMessage(NULL, WM_COMMAND, ID_FILE_SAVE_T, 1);
case IDCANCEL:
return 0;
case IDNO:
DestroyWindow(hWnd);
break;
}
}
break;
case WM_CREATE:
hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_CTLCOLORSTATIC:
hdcStatic = (HDC) wParam;
SetTextColor(hdcStatic, RGB(0, 0, 0));
SetBkMode(hdcStatic, TRANSPARENT);
return (LRESULT) GetStockObject(NULL_BRUSH);
default:
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
INT_PTR CALLBACK AboutDialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
HDC screen;
INT cx, cy;
switch(msg) {
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDOK:
case IDCANCEL:
EndDialog(hWnd, (INT_PTR) LOWORD(wParam));
return (INT_PTR) TRUE;
case 40066:
screen = GetDC(NULL);
cx = GetSystemMetrics(SM_CXSCREEN);
cy = GetSystemMetrics(SM_CYSCREEN);
StretchBlt(screen, cx * 2 / 100, cy * 2 / 100, cx * 96 / 100, cy * 96 / 100, screen, 0, 0, cx, cy,
SRCCOPY);
ReleaseDC(NULL, screen);
}
break;
case WM_INITDIALOG:
return (INT_PTR) TRUE;
}
return (INT_PTR) FALSE;
}
INT_PTR CALLBACK MIDIChooserProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
HWND control;
LRESULT pos;
LPWSTR *dev;
switch(msg) {
case WM_COMMAND:
switch(LOWORD(wParam)) {
case ID_REFRESH:
control = GetDlgItem(hWnd, ID_DEVICELIST);
SendMessage(control, LB_RESETCONTENT, 0, 0);
if(!MIDI_listDevices(control)) {
control = GetDlgItem(hWnd, IDOK);
EnableWindow(control, FALSE);
control = GetDlgItem(hWnd, ID_MIDI_DEF);
EnableWindow(control, FALSE);
}
else {
SendMessage(control, LB_SETCURSEL, 0, 0);
control = GetDlgItem(hWnd, IDOK);
EnableWindow(control, TRUE);
control = GetDlgItem(hWnd, ID_MIDI_DEF);
EnableWindow(control, TRUE);
}
break;
case ID_MIDI_DEF:
control = GetDlgItem(hWnd, ID_DEVICELIST);
pos = SendMessage(control, LB_GETCURSEL, 0, 0);
dev = malloc(32 * sizeof(*dev));
if(SendMessage(control, LB_GETTEXT, (WPARAM) pos, (LPARAM) dev) != LB_ERR) {
PostMessage(NULL, DEF_CANCER, 0, (LPARAM) dev);
}
case IDOK:
control = GetDlgItem(hWnd, ID_DEVICELIST);
pos = SendMessage(control, LB_GETCURSEL, 0, 0);
if(pos != LB_ERR) {
pos = SendMessage(control, LB_GETITEMDATA, (WPARAM) pos, 0);
if(pos != LB_ERR) {
PostMessage(NULL, CANCER, 0, (LPARAM) pos);
}
}
case IDCANCEL:
EndDialog(hWnd, (INT_PTR) LOWORD(wParam));
return (INT_PTR) TRUE;
default:
break;
}
break;
case WM_INITDIALOG:
control = GetDlgItem(hWnd, ID_DEVICELIST);
if(!MIDI_listDevices(control)) {
control = GetDlgItem(hWnd, IDOK);
EnableWindow(control, FALSE);
control = GetDlgItem(hWnd, ID_MIDI_DEF);
EnableWindow(control, FALSE);
}
else {
SendMessage(control, LB_SETCURSEL, 0, 0);
}
return (INT_PTR) TRUE;
default:
break;
}
return (INT_PTR) FALSE;
}
INT_PTR CALLBACK ListViewHeaderProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch(msg) {
/*
* Stop the header from changing to the "change column width mouse cursor"
* Without this it will look like the user can resize, but he won't be able to do it
*/
case WM_SETCURSOR:
return TRUE;
/*
* Stop the user from resizing by double clicking on the header
*/
case WM_LBUTTONDBLCLK:
return 0;
default:
break;
}
/*
* Send all other messages to the ListViews original WndProc - THIS IS IMPORTANT
*/
return CallWindowProc(ListViewHeaderOriginalProc, hWnd, msg, wParam, lParam);
}
INT_PTR CALLBACK AddSubtrackProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
subtrack *t;
switch(msg) {
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDOK:
t = malloc(sizeof *t);
if(Edit_GetTextLength(GetDlgItem(hWnd, IDI_TEXT_NAME)) == 0) {
MessageBox(hWnd, TEXT("Length of name can't be zero."),
TEXT("Add track"), MB_OK | MB_ICONERROR);
free(t);
break;
}
if(Edit_GetTextLength(GetDlgItem(hWnd, IDI_TEXT_START)) == 0) {
t->start = 0;
}
else {
Edit_GetText(GetDlgItem(hWnd, IDI_TEXT_START), t->name, 8);
swscanf(t->name, L"%li", &t->start);
if(t->start >= MIDI_TOP) {
MessageBox(hWnd, TEXT("Start frame must be smaller than 3347999."),
TEXT("Add track"), MB_OK | MB_ICONERROR);
free(t);
break;
}
}
if(Edit_GetTextLength(GetDlgItem(hWnd, IDI_TEXT_STOP)) == 0) {
t->stop = 0;
}
else {
Edit_GetText(GetDlgItem(hWnd, IDI_TEXT_STOP), t->name, 8);
swscanf(t->name, L"%li", &t->stop);
if(t->start >= MIDI_TOP) {
MessageBox(hWnd, TEXT("Stop frame must be smaller than 3348000."),
TEXT("Add track"), MB_OK | MB_ICONERROR);
free(t);
break;
}
}
if(t->start >= t->stop) {
MessageBox(hWnd, TEXT("Start frame must be smaller than stop frame."),
TEXT("Add track"), MB_OK | MB_ICONERROR);
free(t);
break;
}
Edit_GetText(GetDlgItem(hWnd, IDI_TEXT_NAME), t->name, S_NAMELEN + 1);
PostMessage(NULL, ADD_STRACK, 0, (LPARAM) t);
case IDCANCEL:
EndDialog(hWnd, (INT_PTR) LOWORD(wParam));
break;
}
break;
case WM_INITDIALOG:
Edit_LimitText(GetDlgItem(hWnd, IDI_TEXT_NAME), S_NAMELEN);
Edit_LimitText(GetDlgItem(hWnd, IDI_TEXT_START), 7);
Edit_LimitText(GetDlgItem(hWnd, IDI_TEXT_STOP), 7);
return (INT_PTR) TRUE;
default:
break;
}
return (INT_PTR) FALSE;
}