-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqueue_dlg.c
810 lines (671 loc) · 20.7 KB
/
queue_dlg.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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
/*
This file is part of NppEventExec
Copyright (C) 2016-2017 Mihail Ivanchev
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base.h"
#include "exec_def.h"
#include "mem.h"
#include "plugin.h"
#include "queue_dlg.h"
#include "resource.h"
#include "util.h"
/**
* A placeholder which is displayed in the position column for queue entries
* the position of which cannot be displayed.
*/
#define PLACEHOLDER L"<n/a>"
/**
* The highest position in the queue for which a number will be shown in the
* position column; for positions higher than this, a placeholder string will
* be shown instead of a number.
*
* \sa POS_ENTRY_LEN
*/
#define MAX_ENTRY_POS 999
/**
* The length in code units of a string that can hold the number of the
* highest position in the queue, for which a number will be shown.
*
* \sa MAX_ENTRY_POS
*/
#define POS_ENTRY_LEN 4
/**
* The least number of position strings which are allocated in one step; the
* number of allocated position strings is always a multiple of this constant
* unless the maximum number of position strings is reached.
*
* \sa MAX_ENTRY_POS
*/
#define POS_ENTRIES_CHUNK 5
typedef struct
{
QueueDlgLaunchReason reason;
HWND handle;
HWND lvQueue;
HWND btnMode;
HWND btnAbort;
HWND btnClose;
LONG minWidth;
LONG minHeight;
int clientWidth;
int clientHeight;
bool closing;
bool canceled;
/*const wchar_t *title;*/
/*const wchar_t *msg;*/
wchar_t *posEntries;
size_t posEntryCnt;
size_t maxPosEntries;
unsigned int queueSize;
unsigned int foregroundCnt;
} Dialog;
typedef enum
{
COL_POS,
COL_RULE,
COL_STATE,
COL_PATH,
COL_BACKGROUND
} Column;
static INT_PTR CALLBACK dlgProc(HWND dlg, UINT msg, WPARAM wp, LPARAM lp);
static void onInitDlg(HWND dlg);
static void onSize(LONG clientWidth, LONG clientHeight);
static void onGetDispInfo(NMLVDISPINFO *dispInfo);
static void onAbort(void);
static void onClose(void);
static void onItemChanged(NMLISTVIEW *nmlv);
static void onOdsStateChanged(NMLVODSTATECHANGE *nmosc);
static void onQueueAdd(bool foreground);
static void onQueueRemove(bool foreground);
static void onQueueStatusUpdate(void);
static void layoutDlg(void);
static void enlargePosEntries(unsigned int count);
static void compactPosEntries(void);
static unsigned int countPosDigits(unsigned int pos);
static void formatPos(wchar_t *buf, unsigned int pos);
static bool tryCloseDlg(void);
static void deferClosing(void);
static void appendToTitle(const wchar_t *suffix);
static void updateAbortBtn(void);
static Dialog *dlg;
INT_PTR openQueueDlg(HWND parent, QueueDlgLaunchReason reason)
{
INT_PTR res;
bool canceled;
if (!(dlg = allocMem(sizeof *dlg)))
{
/* TODO error */
goto fail_mem;
}
dlg->reason = reason;
dlg->canceled = false;
dlg->posEntries = NULL;
dlg->posEntryCnt = 0;
res = DialogBoxW(getPluginInstance(), MAKEINTRESOURCE(IDD_QUEUE), parent,
dlgProc);
/* Cache the value, because the memory is freed immediately. */
canceled = dlg->canceled;
freeStr(dlg->posEntries);
freeMem(dlg);
dlg = NULL;
if (res == -1)
{
/* TODO error */
goto fail_dlg;
}
return canceled;
fail_dlg:
fail_mem:
return -1;
}
int isQueueDlgVisible(void)
{
return dlg != NULL;
}
void processQueueEvent(QueueEvent event)
{
switch (event)
{
case QUEUE_ADD_FOREGROUND:
case QUEUE_ADD_BACKGROUND:
onQueueAdd(event == QUEUE_ADD_FOREGROUND);
break;
case QUEUE_REMOVE_FOREGROUND:
case QUEUE_REMOVE_BACKGROUND:
onQueueRemove(event == QUEUE_REMOVE_FOREGROUND);
break;
case QUEUE_STATUS_UPDATE:
onQueueStatusUpdate();
break;
}
}
INT_PTR CALLBACK dlgProc(HWND handle, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg)
{
case WM_INITDIALOG:
onInitDlg(handle);
return TRUE;
case WM_GETMINMAXINFO:
((MINMAXINFO*) lp)->ptMinTrackSize.x = dlg->minWidth;
((MINMAXINFO*) lp)->ptMinTrackSize.y = dlg->minHeight;
DLGPROC_RESULT(handle, 0);
case WM_SIZE:
onSize(LOWORD(lp), HIWORD(lp));
DLGPROC_RESULT(handle, 0);
case WM_SYSKEYDOWN:
if (wp == SC_CLOSE)
{
onClose();
DLGPROC_RESULT(handle, 0);
}
break;
case WM_COMMAND:
switch (LOWORD(wp))
{
case IDC_BT_ABORT:
onAbort();
DLGPROC_RESULT(handle, 0);
case IDCANCEL:
onClose();
DLGPROC_RESULT(handle, 0);
}
break;
case WM_NOTIFY:
switch (LOWORD(wp))
{
case IDC_LV_QUEUE:
switch (((NMHDR*) lp)->code)
{
case LVN_ITEMCHANGED:
onItemChanged((NMLISTVIEW*) lp);
break;
case LVN_ODSTATECHANGED:
onOdsStateChanged((NMLVODSTATECHANGE*) lp);
break;
case LVN_GETDISPINFO:
onGetDispInfo((NMLVDISPINFO*) lp);
break;
}
break;
} /* switch (LOWORD(wp)) */
break;
} /* switch (msg) */
return FALSE;
}
void onInitDlg(HWND handle)
{
assert(MAX_ENTRY_POS >= 0);
assert(MAX_ENTRY_POS <= SIZE_MAX);
assert(POS_ENTRY_LEN > 0);
assert(POS_ENTRY_LEN <= SIZE_MAX);
assert(POS_ENTRIES_CHUNK > 0);
assert(POS_ENTRIES_CHUNK <= UINT_MAX);
dlg->handle = handle;
dlg->lvQueue = GetDlgItem(handle, IDC_LV_QUEUE);
dlg->btnMode = GetDlgItem(handle, IDC_BT_MODE);
dlg->btnAbort = GetDlgItem(handle, IDC_BT_ABORT);
dlg->btnClose = GetDlgItem(handle, IDCANCEL);
dlg->maxPosEntries = MIN(SIZE_MAX / POS_ENTRY_LEN, MAX_ENTRY_POS);
dlg->queueSize = getQueueSize(&dlg->foregroundCnt);
enlargePosEntries(MAX(POS_ENTRIES_CHUNK, dlg->queueSize));
ListView_SetExtendedListViewStyleEx(dlg->lvQueue,
LVS_EX_FULLROWSELECT,
LVS_EX_FULLROWSELECT);
addListViewColumns(dlg->lvQueue, (ListViewColumn[]) {
{COL_POS, L"#"},
{COL_RULE, L"Rule"},
{COL_STATE, L"State"},
{COL_PATH, L"Path"},
{COL_BACKGROUND, L"Background?"},
{-1}
});
/* If the dialog was opened, because a foreground rule was queued -- and
** there are no other rules -- try to submit the rule to Notepad++ for
** execution immediately instead of waiting for the first timer event. This
** is not done upon the rule's addition, because of the possibility of the
** dialog's creation failure and also since the dialog creation's function
** does not return until the rule is executed.
*/
if (dlg->reason == QDLR_FOREGROUND_RULE && dlg->queueSize == 1)
updateQueue();
ListView_SetItemCount(dlg->lvQueue, dlg->queueSize);
switch (dlg->reason)
{
case QDLR_PLUGIN_MENU:
dlg->closing = false;
break;
case QDLR_SAVING_CHANGES:
dlg->closing = true;
SetWindowTextW(dlg->btnClose, L"Cancel");
break;
case QDLR_FOREGROUND_RULE:
case QDLR_NPP_CLOSING:
deferClosing();
break;
}
EnableWindow(dlg->btnAbort, FALSE);
EnableWindow(dlg->btnMode, FALSE);
layoutDlg();
centerWndToParent(dlg->handle);
}
void onSize(LONG clientWidth, LONG clientHeight)
{
LONG offsWidth;
LONG offsHeight;
RECT lvQueueRc;
RECT btnModeRc;
RECT btnAbortRc;
RECT btnCloseRc;
LONG lvQueueWidth;
LONG lvQueueHeight;
LONG btnCloseLeft;
LONG btnCloseTop;
offsWidth = clientWidth - dlg->clientWidth;
offsHeight = clientHeight - dlg->clientHeight;
dlg->clientWidth = clientWidth;
dlg->clientHeight = clientHeight;
GetWindowRect(dlg->lvQueue, &lvQueueRc);
GetWindowRect(dlg->btnMode, &btnModeRc);
GetWindowRect(dlg->btnAbort, &btnAbortRc);
GetWindowRect(dlg->btnClose, &btnCloseRc);
MapWindowPoints(NULL, dlg->handle, (POINT*) &btnModeRc, 2);
MapWindowPoints(NULL, dlg->handle, (POINT*) &btnAbortRc, 2);
MapWindowPoints(NULL, dlg->handle, (POINT*) &btnCloseRc, 2);
lvQueueWidth = lvQueueRc.right - lvQueueRc.left + offsWidth;
lvQueueHeight = lvQueueRc.bottom - lvQueueRc.top + offsHeight;
btnModeRc.top += offsHeight;
btnAbortRc.top += offsHeight;
btnCloseLeft = clientWidth / 2
- (btnCloseRc.right - btnCloseRc.left) / 2;
btnCloseTop = btnCloseRc.top + offsHeight;
#define sizeWnd(dlg, width, height) \
{ (dlg), NULL, 0, 0, (width), (height), SWP_NOMOVE | SWP_NOZORDER }
#define positionWnd(dlg, px, py) \
{ (dlg), NULL, (px), (py), 0, 0, SWP_NOSIZE | SWP_NOZORDER }
setWndPosDeferred((SetWindowPosArgs[]) {
sizeWnd(dlg->lvQueue, lvQueueWidth, lvQueueHeight),
positionWnd(dlg->btnMode, btnModeRc.left, btnModeRc.top),
positionWnd(dlg->btnAbort, btnAbortRc.left, btnAbortRc.top),
positionWnd(dlg->btnClose, btnCloseLeft, btnCloseTop),
{NULL}
});
}
void onGetDispInfo(NMLVDISPINFO *dispInfo)
{
LVITEM *item;
unsigned int pos;
item = &dispInfo->item;
pos = item->iItem;
switch (item->iSubItem)
{
case COL_POS:
if (pos < dlg->posEntryCnt)
item->pszText = dlg->posEntries + pos * POS_ENTRY_LEN;
else
item->pszText = PLACEHOLDER;
break;
case COL_RULE:
item->pszText = (wchar_t*) getExecRule(pos);
break;
case COL_STATE:
switch (getExecState(pos))
{
case STATE_QUEUED:
item->pszText = L"Queued";
break;
case STATE_WAITING:
item->pszText = L"Waiting";
break;
case STATE_EXECUTING:
item->pszText = L"Executing";
break;
}
break;
case COL_PATH:
item->pszText = (wchar_t*) getExecPath(pos);
break;
case COL_BACKGROUND:
item->pszText = BOOL_TO_STR_YES_NO(!isExecForeground(pos));
break;
}
}
void onAbort(void)
{
int positions[16];
int selectedCnt;
int abortedCnt;
int focusedItem;
int posInList;
int posInQueue;
bool firstSelected;
int ii;
assert(BUFLEN(positions) > 1);
selectedCnt = ListView_GetSelectedCount(dlg->lvQueue);
abortedCnt = 0;
posInList = -1;
focusedItem = ListView_GetNextItem(dlg->lvQueue, -1, LVIS_FOCUSED);
firstSelected = false; /* Shut up compiler... */
do
{
for (ii = 0; ii < BUFLEN(positions) - 1 && ii < selectedCnt; ii++)
{
posInList = ListView_GetNextItem(dlg->lvQueue,
posInList,
LVNI_SELECTED);
posInQueue = posInList - abortedCnt;
positions[ii] = posInQueue;
firstSelected = !posInList;
}
positions[ii] = -1;
abortExecs(positions);
abortedCnt += ii;
selectedCnt -= ii;
}
while (selectedCnt);
dlg->queueSize = getQueueSize(&dlg->foregroundCnt);
if (!(dlg->closing && tryCloseDlg()))
{
compactPosEntries();
if (dlg->queueSize)
{
if (firstSelected)
updateQueue();
/* IMPORTANT: Adjust the count before deselecting all items. */
ListView_SetItemCount(dlg->lvQueue, dlg->queueSize);
ListView_SetItemState(dlg->lvQueue, -1, 0,
LVIS_SELECTED | LVIS_FOCUSED);
if (focusedItem != -1)
{
focusedItem = (unsigned int) focusedItem <
dlg->queueSize ? focusedItem : dlg->queueSize - 1;
ListView_SetItemState(dlg->lvQueue,
focusedItem,
LVIS_SELECTED | LVIS_FOCUSED,
LVIS_SELECTED | LVIS_FOCUSED);
ListView_EnsureVisible(dlg->lvQueue, focusedItem, FALSE);
}
}
else
{
ListView_SetItemCount(dlg->lvQueue, 0);
EnableWindow(dlg->btnAbort, FALSE);
}
SetFocus(dlg->lvQueue);
}
}
void onClose(void)
{
int choice;
if (dlg->reason == QDLR_SAVING_CHANGES)
{
choice = msgBox(MB_YESNO | MB_ICONQUESTION,
dlg->handle,
L"Cancel",
L"Are you sure you want to cancel saving the changes "
L"to the rule list?");
if (choice == IDYES)
{
dlg->canceled = true;
if (!tryCloseDlg())
{
deferClosing();
appendToTitle(L"(canceled)");
}
}
}
else if (!tryCloseDlg())
{
deferClosing();
appendToTitle(L"(closing)");
}
}
void onItemChanged(NMLISTVIEW *nmlv)
{
if ((nmlv->uNewState & LVIS_SELECTED) != (nmlv->uOldState & LVIS_SELECTED))
updateAbortBtn();
}
void onOdsStateChanged(NMLVODSTATECHANGE *nmosc)
{
if ((nmosc->uNewState & LVIS_SELECTED)
!= (nmosc->uOldState & LVIS_SELECTED))
{
updateAbortBtn();
}
}
void onQueueAdd(bool foreground)
{
dlg->queueSize++;
dlg->foregroundCnt += foreground;
enlargePosEntries(dlg->queueSize);
ListView_SetItemCount(dlg->lvQueue, dlg->queueSize);
}
void onQueueRemove(bool foreground)
{
int lastState;
int state;
unsigned int ii;
dlg->queueSize--;
dlg->foregroundCnt -= foreground;
if (dlg->closing && tryCloseDlg())
return;
compactPosEntries();
/* IMPORTANT: Set the new count before modifying the item states
** or else the list might try to access the now deleted last
** item in the event handler.
*/
if (dlg->queueSize)
{
lastState = ListView_GetItemState(dlg->lvQueue,
dlg->queueSize,
LVNI_SELECTED | LVNI_FOCUSED);
}
else
{
lastState = 0; /* Shut up MSVC... */
}
ListView_SetItemCount(dlg->lvQueue, dlg->queueSize);
for (ii = 1; ii < dlg->queueSize; ii++)
{
state = ListView_GetItemState(dlg->lvQueue,
ii,
LVNI_SELECTED | LVNI_FOCUSED);
ListView_SetItemState(dlg->lvQueue,
ii - 1,
state,
LVNI_SELECTED | LVNI_FOCUSED);
}
if (dlg->queueSize)
{
ListView_SetItemState(dlg->lvQueue,
dlg->queueSize - 1,
lastState,
LVNI_SELECTED | LVNI_FOCUSED);
}
}
void onQueueStatusUpdate(void)
{
ListView_Update(dlg->lvQueue, 0);
}
void layoutDlg(void)
{
RECT dlgRc;
RECT clientRc;
GetWindowRect(dlg->handle, &dlgRc);
GetClientRect(dlg->handle, &clientRc);
dlg->minWidth = dlgRc.right - dlgRc.left;
dlg->minHeight = dlgRc.bottom - dlgRc.top;
dlg->clientWidth = clientRc.right - clientRc.left;
dlg->clientHeight = clientRc.bottom - clientRc.top;
sizeListViewColumns(dlg->lvQueue, (ListViewColumnSize[]) {
{COL_POS, 0.08},
{COL_RULE, 0.25},
{COL_STATE, 0.15},
{COL_PATH, 0.40},
{COL_BACKGROUND, 0.12},
{-1}
});
}
void enlargePosEntries(unsigned int count)
{
wchar_t *entries;
size_t newEntryCnt;
size_t ii;
assert(count);
assert(POS_ENTRIES_CHUNK > 0);
assert(POS_ENTRIES_CHUNK <= UINT_MAX);
if (count <= dlg->posEntryCnt
|| dlg->posEntryCnt == dlg->maxPosEntries)
{
return;
}
if (count % POS_ENTRIES_CHUNK)
{
count -= count % POS_ENTRIES_CHUNK;
if (count > UINT_MAX - POS_ENTRIES_CHUNK)
count = UINT_MAX;
else
count += POS_ENTRIES_CHUNK;
}
if (count > dlg->maxPosEntries)
newEntryCnt = dlg->maxPosEntries;
else
newEntryCnt = count;
if (!(entries = reallocStr(dlg->posEntries, newEntryCnt * POS_ENTRY_LEN)))
{
/* TODO warning
**
** We cannot allocate enough entries, but that's not a fatal issue
** because a placeholder will be shown instead of the actual number.
*/
return;
}
for (ii = dlg->posEntryCnt; ii < newEntryCnt; ii++)
formatPos(entries + ii * POS_ENTRY_LEN, (unsigned int) ii);
dlg->posEntries = entries;
dlg->posEntryCnt = newEntryCnt;
}
void compactPosEntries(void)
{
wchar_t *entries;
size_t newEntryCnt;
assert(POS_ENTRIES_CHUNK > 0);
assert(POS_ENTRIES_CHUNK <= SIZE_MAX);
/* The initial chunk is never released from memory so don't bother. */
if (dlg->posEntryCnt <= dlg->queueSize
|| dlg->posEntryCnt <= POS_ENTRIES_CHUNK)
{
return;
}
if (dlg->queueSize <= POS_ENTRIES_CHUNK)
newEntryCnt = POS_ENTRIES_CHUNK;
else
{
/* Find out the next multiple of POS_ENTRIES_CHUNK, but do not compact
** if the current number of rules fits within the last allocated chunk.
*/
newEntryCnt = dlg->queueSize - 1;
newEntryCnt -= newEntryCnt % POS_ENTRIES_CHUNK;
if (newEntryCnt >= dlg->posEntryCnt - POS_ENTRIES_CHUNK)
return;
newEntryCnt += POS_ENTRIES_CHUNK;
}
if (!(entries = reallocStr(dlg->posEntries, newEntryCnt * POS_ENTRY_LEN)))
{
/* TODO warning
**
** Don't take any other action other than issuing a warning. The failed
** reallocation is not really fatal (yet).
*/
return;
}
dlg->posEntries = entries;
dlg->posEntryCnt = newEntryCnt;
}
unsigned int countPosDigits(unsigned int pos)
{
unsigned int cnt;
cnt = 0;
do
{
cnt++;
}
while (pos /= 10);
return cnt;
}
void formatPos(wchar_t *buf, unsigned int pos)
{
unsigned int digitCnt;
/* Avoid the signed overflow. */
if (pos < INT_MAX)
pos++;
digitCnt = countPosDigits(pos);
buf[digitCnt] = L'\0';
do
{
buf[--digitCnt] = L'0' + (pos % 10);
}
while (pos /= 10);
}
bool tryCloseDlg(void)
{
switch (dlg->reason)
{
case QDLR_SAVING_CHANGES:
if ((dlg->canceled && !dlg->foregroundCnt) || !dlg->queueSize)
{
EndDialog(dlg->handle, IDCANCEL);
return true;
}
return false;
case QDLR_NPP_CLOSING:
if (!dlg->queueSize)
{
EndDialog(dlg->handle, IDCANCEL);
return true;
}
return false;
default:
break;
}
if (!dlg->foregroundCnt)
{
EndDialog(dlg->handle, IDCANCEL);
return true;
}
return false;
}
void deferClosing(void)
{
UINT flags;
flags = MF_BYCOMMAND | MF_DISABLED | MF_GRAYED;
EnableMenuItem(GetSystemMenu(dlg->handle, FALSE), SC_CLOSE, flags);
EnableWindow(dlg->btnClose, FALSE);
dlg->closing = true;
}
void appendToTitle(const wchar_t *suffix)
{
wchar_t title[1024];
wchar_t buf[1024];
GetWindowTextW(dlg->handle, title, BUFLEN(title));
StringCbPrintfW(buf, sizeof(buf), L"%s %s", title, suffix);
SetWindowTextW(dlg->handle, buf);
}
void updateAbortBtn(void)
{
int curr;
BOOL enabled;
curr = ListView_GetNextItem(dlg->lvQueue, -1, LVNI_SELECTED);
enabled = curr != -1 && (curr || getExecState(curr) != STATE_EXECUTING);
EnableWindow(dlg->btnAbort, enabled);
}