forked from OpenSalamander/salamander
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditwnd.cpp
2008 lines (1839 loc) · 63.5 KB
/
editwnd.cpp
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
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-FileCopyrightText: 2023 Open Salamander Authors
// SPDX-License-Identifier: GPL-2.0-or-later
#include "precomp.h"
#include "cfgdlg.h"
#include "mainwnd.h"
#include "plugins.h"
#include "fileswnd.h"
#include "editwnd.h"
#include "stswnd.h"
#include <uxtheme.h>
#include <Shlwapi.h>
//*****************************************************************************
//
// InstallWordBreakProc
//
// zajisti zastavovani kurzoru na zpetnych lomitkach v cestach
//
// Implementacne prasarna, obchazejici debilni chovani windows.
// Vytazene a prelozene do C z IE 5.5 / BROWSEUI.DLL.
//
BOOL IsCharacterDelimiter(char ch)
{
return ch == ' ' || ch == '/' || ch == '\\' || ch == ';' || ch == ',' || ch == '.';
}
int CALLBACK
EditWordBreakProc(LPTSTR text, int current, int textLen, int code)
{
CALL_STACK_MESSAGE5("EditWordBreakProc(%s, %d, %d, %d)", text, current, textLen, code);
if (textLen == 0)
return 0;
static BOOL gRightBreak = FALSE;
BOOL ebp_8 = FALSE;
char* ebp_10 = NULL;
char* esi = text + current;
switch (code)
{
case WB_LEFT:
{
do
{
esi = CharPrev(text, esi);
if (esi == text)
break;
if (!IsCharacterDelimiter(*esi))
{
gRightBreak = FALSE;
ebp_8 = TRUE;
continue;
}
if (gRightBreak)
break;
if (ebp_8)
break;
} while (1);
if (esi - text <= 0)
return 0;
if (esi - text >= textLen)
return (int)(esi - text);
return (int)(esi - text + 1);
}
case WB_RIGHT:
{
gRightBreak = FALSE;
BOOL edi = !IsCharacterDelimiter(*esi);
ebp_10 = text + textLen;
if (esi == ebp_10)
return (int)(esi - text);
do
{
esi = CharNext(esi);
if (esi == ebp_10)
return (int)(esi - text);
if (IsCharacterDelimiter(*esi))
edi = FALSE;
else if (!edi)
return (int)(esi - text);
} while (1);
return 0;
}
case WB_ISDELIMITER:
{
gRightBreak = TRUE;
return IsCharacterDelimiter(text[current]);
}
}
return textLen;
}
int CALLBACK
EditWordBreakProcUNICODE(LPTSTR text, int current, int textLen, int code)
{
CALL_STACK_MESSAGE5("EditWordBreakProcUNICODE(%s, %d, %d, %d)", text, current, textLen, code);
if (textLen == 0)
return 0;
char buff[10000];
// Convert the String to ANSI
WideCharToMultiByte(CP_ACP, 0, (wchar_t*)text, textLen, buff, 10000, NULL, NULL);
buff[10000 - 1] = 0;
text = buff;
static BOOL gRightBreak = FALSE;
BOOL ebp_8 = FALSE;
char* ebp_10 = NULL;
char* esi = text + current;
switch (code)
{
case WB_LEFT:
{
do
{
esi = CharPrev(text, esi);
if (esi == text)
break;
if (!IsCharacterDelimiter(*esi))
{
gRightBreak = FALSE;
ebp_8 = TRUE;
continue;
}
if (gRightBreak)
break;
if (ebp_8)
break;
} while (1);
if (esi - text <= 0)
return 0;
if (esi - text >= textLen)
return (int)(esi - text);
return (int)(esi - text + 1);
}
case WB_RIGHT:
{
gRightBreak = FALSE;
BOOL edi = !IsCharacterDelimiter(*esi);
ebp_10 = text + textLen;
if (esi == ebp_10)
return (int)(esi - text);
do
{
esi = CharNext(esi);
if (esi == ebp_10)
return (int)(esi - text);
if (IsCharacterDelimiter(*esi))
edi = FALSE;
else if (!edi)
return (int)(esi - text);
} while (1);
return 0;
}
case WB_ISDELIMITER:
{
gRightBreak = TRUE;
return IsCharacterDelimiter(text[current]);
}
}
return textLen;
}
const char* BACKSPACE_SUBCLASSPROC = "SALBSSubClass";
int CALLBACK EditWordBreakProc(LPTSTR text, int current, int textLen, int code);
LRESULT CALLBACK
BSHandlerSubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
WNDPROC OldWndProc = (WNDPROC)GetProp(hwnd, BACKSPACE_SUBCLASSPROC);
if (OldWndProc == NULL)
{
TRACE_E("BSHandlerSubclassProc: OldWndProc == NULL");
return 0;
}
switch (message)
{
case WM_CHAR:
{
if (wParam == 127) // zahodime znak "Ctrl+Backspace"
return 0; // zpracovali jsme
break;
}
case WM_KEYDOWN:
{
// zpracuje Ctrl+Backspace pro smazani slova
if (wParam == VK_BACK)
{
BOOL controlPressed = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
BOOL altPressed = (GetKeyState(VK_MENU) & 0x8000) != 0;
BOOL shiftPressed = (GetKeyState(VK_SHIFT) & 0x8000) != 0;
if (controlPressed && !altPressed && !shiftPressed)
{
int iStart, iEnd;
SendMessage(hwnd, EM_GETSEL, (WPARAM)&iStart, (LPARAM)&iEnd);
// pokud existuje selection, zrusime ji a kurzot umistime na konec
if (iStart != iEnd)
{
SendMessage(hwnd, EM_SETSEL, iEnd, iEnd);
iStart = iEnd;
}
// if (iStart == iEnd) // nesmi byt nic vybrano
// {
char buff[10000];
int len = GetWindowTextLength(hwnd);
if (len >= 10000 - 1)
break;
SendMessage(hwnd, WM_GETTEXT, 10000, (LPARAM)buff);
// smazeme slovo
iStart = EditWordBreakProc(buff, iStart, iStart + 1, WB_LEFT);
SendMessage(hwnd, EM_SETSEL, iStart, iEnd);
SendMessage(hwnd, EM_REPLACESEL, TRUE, (LPARAM) "");
// }
return 0; // zpracovali jsme
}
}
break;
}
case WM_DESTROY:
{
// zameteme po sobe ulozenou OldWndProc
WNDPROC currentWndProc = (WNDPROC)GetWindowLongPtr(hwnd, GWLP_WNDPROC);
SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)OldWndProc);
RemoveProp(hwnd, BACKSPACE_SUBCLASSPROC);
break;
}
}
return CallWindowProc(OldWndProc, hwnd, message, wParam, lParam);
}
// nevyuzijeme pro subclass WinLib, abychom ji nelezli do zeli
// (nektera okna, na ktera se mame pripojit, jiz jsou nebo budou pod WinLib)
BOOL AttachBackspaceHandler(HWND hwndEdit)
{
WNDPROC oldWndProc = (WNDPROC)GetWindowLongPtr(hwndEdit, GWLP_WNDPROC);
if (SetProp(hwndEdit, BACKSPACE_SUBCLASSPROC, (HANDLE)oldWndProc))
{
SetWindowLongPtr(hwndEdit, GWLP_WNDPROC, (LONG_PTR)BSHandlerSubclassProc);
return TRUE;
}
return FALSE;
}
BOOL InstallWordBreakProc(HWND hWindow)
{
CALL_STACK_MESSAGE2("InstallWordBreakProc(0x%p)", hWindow);
if (hWindow == NULL)
{
TRACE_E("InstallWordBreakProc: hWindow == NULL");
return FALSE;
}
char className[31];
className[0] = 0;
if (GetClassName(hWindow, className, 30) == 0 || StrICmp(className, "edit") != 0)
{
// mohlo by jit o combobox, zkusime sahnout pro vnitrni edit
hWindow = GetWindow(hWindow, GW_CHILD);
if (hWindow == NULL || GetClassName(hWindow, className, 30) == 0 || StrICmp(className, "edit") != 0)
{
TRACE_E("InstallWordBreakProc: edit window was not found ClassName is " << className);
return FALSE;
}
}
// Pod Windows XP a .NET s common controls 6 chodi do EditWordBreakProc UNICODE text
if (CCVerMajor >= 6)
SendMessage(hWindow, EM_SETWORDBREAKPROC, NULL, (LPARAM)EditWordBreakProcUNICODE);
else
SendMessage(hWindow, EM_SETWORDBREAKPROC, NULL, (LPARAM)EditWordBreakProc);
// Ctrl+Backspace pro mazani po slovech
if (!AttachBackspaceHandler(hWindow))
TRACE_E("AttachBackspaceHandler on hWnd=0x" << hWindow);
return TRUE;
}
// vraci TRUE, pokud se jedna o prikaz "cd *"
BOOL IsChangeDirAttempt(const char* text)
{
while (*text == ' ')
text++;
return StrNICmp(text, "cd ", 3) == 0;
}
int GetCmdLineLimit()
{
/*
Namerene limity pri spousteni pres COMSPEC:
(4094 + delka stringu exace) W2K (na delce COMSPEC nezavisi)
(8190 + delka stringu exace) XP (na delce COMSPEC nezavisi)
8156 Vista + Win7 pri COMSPEC=C:\Windows\system32\cmd.exe (zalezi na delce COMSPEC: delsi COMSPEC = mensi limit)
*/
#if SALCMDLINE_MAXLEN != 8192 // maximalni hodnota, kterou muze vratit GetCmdLineLimit()
#pragma message(__FILE__ " ERROR: SALCMDLINE_MAXLEN != 8192. SALCMDLINE_MAXLEN and GetCmdLineLimit() must contain the same maximal value!")
#endif
if (WindowsXP64AndLater) // XP64 + Vista + Win7 + ...
{
char cmd[MAX_PATH];
if (!GetEnvironmentVariable("COMSPEC", cmd, MAX_PATH))
cmd[0] = 0;
AddDoubleQuotesIfNeeded(cmd, MAX_PATH); // CreateProcess chce mit jmeno s mezerama v uvozovkach (jinak zkousi ruzny varianty, viz help)
return 8191 - lstrlen(cmd) - 6; // 6 = strlen(" /K ") + 2 (dvoje uvozovky kolem samotneho prikazu)
}
else
return 8192; // XP
}
//
// ****************************************************************************
// CEditLine
//
CEditLine::CEditLine()
: CWindow(ooStatic)
{
SkipCharacter = FALSE;
SelChangeDisabled = FALSE;
}
void CEditLine::InsertText(char* s)
{
SendMessage(HWindow, EM_REPLACESEL, TRUE, (LPARAM)s);
}
BOOL SkipNextSysCharacter = FALSE;
LRESULT
CEditLine::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
SLOW_CALL_STACK_MESSAGE4("CEditLine::WindowProc(0x%X, 0x%IX, 0x%IX)", uMsg, wParam, lParam);
switch (uMsg)
{
case WM_CHAR:
{
if (MainWindow->HasLockedUI())
return 0;
if (MainWindow->EditWindow->Dropped())
break;
if (SkipCharacter)
return 0;
switch ((TCHAR)wParam)
{
case '\t': // change panel
{
MainWindow->ChangePanel();
return 0;
}
case '\r':
{
if (SendMessage(HWindow, WM_GETTEXTLENGTH, 0, 0) == 0)
MainWindow->GetActivePanel()->CtrlPageDnOrEnter(VK_RETURN);
else
{
char cmdLine[SALCMDLINE_MAXLEN + 1];
SendMessage(HWindow, WM_GETTEXT, SALCMDLINE_MAXLEN + 1, (LPARAM)cmdLine);
MainWindow->SetDefaultDirectories();
char command[SALCMDLINE_MAXLEN + 1];
command[0] = 0;
int selFrom = 0;
int selTo = 0;
BOOL executed = FALSE;
CFilesWindow* panel = MainWindow->GetActivePanel();
if (panel->Is(ptDisk)) // spousteni prikazu na disku -> spusteni v DOS Promptu
{
// lide jsou z TC a ostatnich file manageru navykli menit cestu v panelu pomoci command line
// pokusime se je to odnaucit
if (IsChangeDirAttempt(cmdLine))
{
if (Configuration.CnfrmChangeDirTC)
{
BOOL dontShow = !Configuration.CnfrmChangeDirTC;
MSGBOXEX_PARAMS params;
memset(¶ms, 0, sizeof(params));
params.HParent = HWindow;
params.Flags = MB_OK | MB_ICONINFORMATION;
params.Caption = LoadStr(IDS_INFOTITLE);
params.Text = LoadStr(IDS_CHANGEDIR_TC_HINT);
params.CheckBoxText = LoadStr(IDS_DONTSHOWAGAIN2);
params.CheckBoxValue = &dontShow;
SalMessageBoxEx(¶ms);
Configuration.CnfrmChangeDirTC = !dontShow;
}
// nechame prikaz propadnout do shellu, at nekomplikujeme text msgboxu
}
char cmd[SALCMDLINE_MAXLEN + MAX_PATH]; // COMSPEC bude nejspis jen par znaku dlouha, MAX_PATH je velka rezerva (dalsi pro parametry /K, atd. uz nepridavame)
if (!GetEnvironmentVariable("COMSPEC", cmd, SALCMDLINE_MAXLEN + MAX_PATH))
cmd[0] = 0;
AddDoubleQuotesIfNeeded(cmd, SALCMDLINE_MAXLEN + MAX_PATH); // CreateProcess chce mit jmeno s mezerama v uvozovkach (jinak zkousi ruzny varianty, viz help)
if (SystemPolicies.GetMyRunRestricted() &&
(!SystemPolicies.GetMyCanRun(cmd) || !SystemPolicies.GetMyCanRun(cmdLine)))
{
MSGBOXEX_PARAMS params;
memset(¶ms, 0, sizeof(params));
params.HParent = HWindow;
params.Flags = MSGBOXEX_OK | MSGBOXEX_HELP | MSGBOXEX_ICONEXCLAMATION;
params.Caption = LoadStr(IDS_POLICIESRESTRICTION_TITLE);
params.Text = LoadStr(IDS_POLICIESRESTRICTION);
params.ContextHelpId = IDH_GROUPPOLICY;
params.HelpCallback = MessageBoxHelpCallback;
SalMessageBoxEx(¶ms);
return 0;
}
panel->UserWorkedOnThisPath = TRUE;
BOOL setWait = (GetCursor() != LoadCursor(NULL, IDC_WAIT)); // ceka uz ?
HCURSOR oldCur;
if (setWait)
oldCur = SetCursor(LoadCursor(NULL, IDC_WAIT));
BOOL cmdTooLong = FALSE;
if (strlen(cmd) + 4 < SALCMDLINE_MAXLEN + MAX_PATH)
{
if ((Configuration.CloseShell != 0) ^ ((GetKeyState(VK_MENU) & 0x8000) != 0))
strcat(cmd, " /C "); // aby se shell zavrel
else
strcat(cmd, " /K "); // aby zustal aktivni shell
}
else
cmdTooLong = TRUE;
if (strlen(cmd) + strlen(cmdLine) + 2 < SALCMDLINE_MAXLEN + MAX_PATH)
{
strcat(cmd, "\"");
strcat(cmd, cmdLine); // prikazovou radku od uzivatele musime obklopit uvozovkama, jinak nefunguji prikazy obsahujici uvozovky (napr. >>"C:\APPS\WinRAR\UnRAR.exe" e "test.rar"<< napise >>'C:\APPS\WinRAR\UnRAR.exe" e "test.rar' is not recognized<<)
strcat(cmd, "\"");
}
else
cmdTooLong = TRUE;
STARTUPINFO si;
memset(&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.lpTitle = LoadStr(IDS_COMMANDSHELL);
si.dwFlags = STARTF_USESHOWWINDOW;
POINT p;
if (MultiMonGetDefaultWindowPos(MainWindow->HWindow, &p))
{
// pokud je hlavni okno na jinem monitoru, meli bychom tam take otevrit
// okno vznikajici a nejlepe na default pozici (stejne jako na primaru)
si.dwFlags |= STARTF_USEPOSITION;
si.dwX = p.x;
si.dwY = p.y;
}
si.wShowWindow = SW_SHOWNORMAL;
PROCESS_INFORMATION pi;
BOOL proc_ret = FALSE;
DWORD err = 0;
if (!cmdTooLong)
{
CALL_STACK_MESSAGE3("CEditLine::WindowProc::CreateProcess(, %s, , , , , , %s, ,)",
strlen(cmd) > 300 ? "(very long cmd)" : cmd,
MainWindow->GetActivePanel()->GetPath());
proc_ret = HANDLES(CreateProcess(NULL, cmd, NULL, NULL, FALSE,
CREATE_DEFAULT_ERROR_MODE | NORMAL_PRIORITY_CLASS,
NULL, MainWindow->GetActivePanel()->GetPath(), &si, &pi));
err = GetLastError();
}
if (cmdTooLong || !proc_ret)
{
SalMessageBox(HWindow, cmdTooLong ? LoadStr(IDS_TOOLONGPATH) : GetErrorText(err),
LoadStr(IDS_ERROREXECCMDLINE), MB_OK | MB_ICONEXCLAMATION);
}
else
{
HANDLES(CloseHandle(pi.hProcess));
HANDLES(CloseHandle(pi.hThread));
executed = TRUE;
}
if (setWait)
SetCursor(oldCur);
}
else
{
if (panel->Is(ptPluginFS) && panel->GetPluginFS()->NotEmpty() &&
panel->GetPluginFS()->IsServiceSupported(FS_SERVICE_COMMANDLINE))
{ // spousteni prikazu z FS
lstrcpyn(command, cmdLine, SALCMDLINE_MAXLEN + 1);
panel->UserWorkedOnThisPath = TRUE;
// snizime prioritu threadu na "normal" (aby operace prilis nezatezovaly stroj)
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
if (panel->GetPluginFS()->ExecuteCommandLine(HWindow, command, selFrom, selTo))
{
executed = TRUE;
}
// opet zvysime prioritu threadu, operace dobehla
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
}
}
// jeste pridame prikaz do historie
if (executed)
{
if (Configuration.EnableCmdLineHistory)
{
char** history = Configuration.EditHistory;
int from = EDIT_HISTORY_SIZE - 1;
int i;
for (i = 0; i < EDIT_HISTORY_SIZE; i++)
if (history[i] != NULL)
if (strcmp(history[i], cmdLine) == 0)
{
from = i;
break;
}
if (from > 0)
{
char* text = (char*)malloc(strlen(cmdLine) + 1);
if (text != NULL)
{
free(history[from]);
for (i = from - 1; i >= 0; i--)
history[i + 1] = history[i];
history[0] = text;
strcpy(history[0], cmdLine);
}
}
}
MainWindow->EditWindow->FillHistory();
int l = (int)strlen(command);
if (selFrom < 0)
selFrom = 0;
if (selFrom > l)
selFrom = l;
if (selTo < 0)
selTo = 0;
if (selTo > l)
selTo = l;
SendMessage(HWindow, WM_SETTEXT, 0, (LPARAM)command);
SendMessage(HWindow, EM_SETSEL, selFrom, selTo);
}
}
return 0;
}
}
break;
}
case WM_COPY:
case WM_CUT:
case WM_DESTROYCLIPBOARD:
{
// zmena clipboardu -> spustime vypocet enableru clipboard-funkci
IdleRefreshStates = TRUE; // pri pristim Idle vynutime kontrolu stavovych promennych
IdleCheckClipboard = TRUE; // nechame kontrolovat take clipboard
break;
}
case WM_KILLFOCUS:
{
SelChangeDisabled = TRUE;
LRESULT res = CWindow::WindowProc(uMsg, wParam, lParam);
SelChangeDisabled = FALSE;
return res;
}
case WM_SETFOCUS:
{
SelChangeDisabled = TRUE;
LRESULT res = CWindow::WindowProc(uMsg, wParam, lParam);
SelChangeDisabled = FALSE;
return res;
}
case EM_SETSEL:
{
if (SelChangeDisabled)
return 0;
break;
}
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_LBUTTONDBLCLK:
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
case WM_SETCURSOR:
{
if (MainWindow->HasLockedUI())
return 0;
break;
}
case WM_MOUSEHWHEEL:
case WM_MOUSEWHEEL:
{
if (MainWindow->HasLockedUI())
return 0;
// 7.10.2009 - AS253_B1_IB34: Manison nam hlasil, ze mu pod Windows Vista nefunguje horizontalni scroll.
// Me fungoval (touto cestou). Po nainstalovani Intellipoint ovladacu v7 (predtime jsem na Vista x64
// nemel zadne spesl ovladace) prestaly WM_MOUSEHWHEEL zpravy prochazet skraz hooka a natejkaly primo
// do focused okna; zakazal jsem hook a nyni musime chytat zpravy v oknech, ktere mohou mit focus, aby
// doslo k forwardu.
// 30.11.2012 - na foru se objevil clovek, kteremu WM_MOUSEHWEEL nechodi skrz message hook (stejna jako drive
// u Manisona v pripade WM_MOUSEHWHEEL): https://forum.altap.cz/viewtopic.php?f=24&t=6039
// takze nove budeme zpravu chytat take v jednotlivych oknech, kam muze potencialne chodit (dle focusu)
// a nasledne ji routit tak, aby se dorucila do okna pod kurzorem, jak jsme to vzdy delali
// pokud zprava prisla "nedavno" druhym kanalem, budeme tento kanal ignorovat
if (MouseWheelMSGThroughHook && MouseWheelMSGTime != 0 && (GetTickCount() - MouseWheelMSGTime < MOUSEWHEELMSG_VALID))
return 0;
MouseWheelMSGThroughHook = FALSE;
MouseWheelMSGTime = GetTickCount();
MSG msg;
DWORD pos = GetMessagePos();
msg.pt.x = GET_X_LPARAM(pos);
msg.pt.y = GET_Y_LPARAM(pos);
msg.lParam = lParam;
msg.wParam = wParam;
msg.hwnd = HWindow;
msg.message = uMsg;
PostMouseWheelMessage(&msg);
return 0;
}
case WM_USER_MOUSEWHEEL:
{
// zatlucu default processing
return 0;
}
case WM_SYSKEYUP:
case WM_KEYUP:
{
if (MainWindow->HasLockedUI())
return 0;
if (MainWindow->EditWindow->Dropped())
break;
SkipCharacter = FALSE;
break;
}
case WM_SYSCOMMAND:
{
if (MainWindow->HasLockedUI())
return 0;
if (MainWindow->EditWindow->Dropped())
break;
if (SkipCharacter)
return 0;
break;
}
case WM_SYSCHAR:
{
if (MainWindow->HasLockedUI())
return 0;
if (SkipNextSysCharacter)
{
SkipNextSysCharacter = FALSE;
return FALSE;
}
return TRUE;
}
case WM_SYSKEYDOWN:
case WM_KEYDOWN:
{
if (MainWindow->HasLockedUI())
return 0;
SkipCharacter = FALSE;
BOOL controlPressed = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
BOOL altPressed = (GetKeyState(VK_MENU) & 0x8000) != 0;
BOOL shiftPressed = (GetKeyState(VK_SHIFT) & 0x8000) != 0;
if (!IsWindowEnabled(MainWindow->HWindow))
return 0;
// nastavime panelu promennou SelectedItems, aby chodilo oznacovani
// pres Shift+sipky je-li focus zde v edit line
CFilesWindow* panel = MainWindow->GetActivePanel();
BOOL firstPress = (lParam & 0x40000000) == 0;
// j.r.: Dusek nasel problem, kdy neodrazilo UP do paru k DOWN
// proto zavadim test na prvni stisk klavesy SHIFT
if (wParam == VK_SHIFT && firstPress && panel->Dirs->Count + panel->Files->Count > 0)
{
panel->SelectItems = !panel->GetSel(panel->FocusedIndex);
}
if (MainWindow->EditWindow->Dropped())
break;
else
{
if (wParam == VK_UP || wParam == VK_DOWN)
{
// Alt - necham vybalit listbox
if (!controlPressed && altPressed && !shiftPressed)
break;
// Control - necham rolovat bez vybaleni listboxu
if (controlPressed && !altPressed && !shiftPressed)
break;
}
}
if (altPressed && !controlPressed && !shiftPressed)
{
// change panel mode
if (wParam >= '0' && wParam <= '9')
{
int index = (int)(wParam - '0');
if (index == 0)
index = 9;
else
index--;
if (MainWindow->GetActivePanel()->IsViewTemplateValid(index))
MainWindow->GetActivePanel()->SelectViewTemplate(index, TRUE, FALSE);
SkipNextSysCharacter = TRUE; // zamezime pipnuti
return TRUE;
}
}
if (controlPressed && !shiftPressed && !altPressed)
{
// od Windows Vista uz SelectAll standardne funguje, takze tam nechame select all na nich
if (!WindowsVistaAndLater)
{
if (wParam == 'A')
{
SendMessage(HWindow, EM_SETSEL, 0, -1);
SkipCharacter = TRUE; // zamezime pipnuti
return TRUE;
}
}
}
/*
if (shiftPressed && controlPressed && !altPressed)
{
if (wParam >= 'A' && wParam <= 'Z')
{
SkipCharacter = TRUE;
MainWindow->HandleCtrlLetter((char)wParam);
return 0;
}
}
*/
if (wParam >= '0' && wParam <= '9')
{
BOOL exit = FALSE;
// define hot path
if (shiftPressed && controlPressed && !altPressed)
{
MainWindow->GetActivePanel()->SetUnescapedHotPath((char)wParam == '0' ? 9 : (char)wParam - '1');
if (!Configuration.HotPathAutoConfig)
MainWindow->GetActivePanel()->DirectoryLine->FlashText();
exit = TRUE;
}
// go to hot path
// I cannot type the characters @, L, $, {, [, ], } on the command line in
// Open Salamander. With my Danish keyboard these characters all require me
// to press AltGr+<a digit> (= Ctrl+Alt+<digit>), but to Salamander this has a
// special meaning, which seems to be: "go to hot path in the non-focused
// panel". I am not interested in this special Alt-Ctrl-functionality in
// Salamander, I am definitely more interested in being able to type the
// mentioned characters on the command line.
if ((controlPressed && !shiftPressed && !altPressed) /* || // Shift+cisla z edit-line nepujde (je potreba psat '*' a dalsi)
(Configuration.ShiftForHotPaths && !controlPressed && shiftPressed)*/
)
{
MainWindow->GetActivePanel()->GotoHotPath((char)wParam == '0' ? 9 : (char)wParam - '1');
/*
if (altPressed)
MainWindow->GetNonActivePanel()->GotoHotPath((char)wParam == '0' ? 9 : (char)wParam - '1');
else
MainWindow->GetActivePanel()->GotoHotPath((char)wParam == '0' ? 9 : (char)wParam - '1');
*/
exit = TRUE;
}
if (exit)
{
SkipCharacter = TRUE;
return 0;
}
}
if (wParam == VK_BACK && (!controlPressed && !altPressed && shiftPressed))
{ // Shift+backspace
SkipCharacter = TRUE;
MainWindow->GetActivePanel()->GotoRoot();
return 0;
}
if (controlPressed && !altPressed)
{
if (!shiftPressed)
{
if (wParam == 0xBF) // Ctrl+'/'
{
SkipCharacter = TRUE;
PostMessage(MainWindow->HWindow, WM_COMMAND, CM_DOSSHELL, 0);
return 0;
}
if (wParam == 0xBB) // Ctrl+'+'
{
SkipCharacter = TRUE;
PostMessage(MainWindow->HWindow, WM_COMMAND, CM_ACTIVESELECT, 0);
return 0;
}
if (wParam == 0xBD) // Ctrl+'-'
{
SkipCharacter = TRUE;
PostMessage(MainWindow->HWindow, WM_COMMAND, CM_ACTIVEUNSELECT, 0);
return 0;
}
if (wParam == VK_BACKSLASH) // Ctrl+'\\'
{
SkipCharacter = TRUE;
MainWindow->GetActivePanel()->GotoRoot();
return 0;
}
}
}
switch (wParam)
{
case VK_RETURN:
{
if (controlPressed && !altPressed) // filename vybranyho souboru do cmd-liny
{
SkipCharacter = TRUE;
char path[MAX_PATH + 1];
const char* s;
int l;
CFilesWindow* p = MainWindow->GetActivePanel();
if (p->FocusedIndex >= 0 &&
p->FocusedIndex < p->Files->Count + p->Dirs->Count)
{
CFileData* file = (p->FocusedIndex < p->Dirs->Count) ? &p->Dirs->At(p->FocusedIndex) : &p->Files->At(p->FocusedIndex - p->Dirs->Count);
if (shiftPressed) // dos-jmeno
{
s = (file->DosName == NULL) ? file->Name : file->DosName;
}
else
{
s = file->Name;
}
}
else
return 0;
l = (int)strlen(s);
memmove(path, s, l);
path[l++] = ' ';
path[l] = 0;
InsertText(path);
return 0;
}
else
{
if (shiftPressed)
{
SkipCharacter = TRUE;
MainWindow->GetActivePanel()->CtrlPageDnOrEnter(wParam);
return 0;
}
else
{
if (altPressed)
{
SendMessage(HWindow, WM_CHAR, '\r', 0);
SkipCharacter = TRUE;
return 0;
}
}
}
break;
}
case VK_INSERT:
{
if (!shiftPressed && !controlPressed && altPressed ||
shiftPressed && !controlPressed && altPressed)
{ // clipboard: (full) name of focused item
CCopyFocusedNameModeEnum mode;
if (!shiftPressed && !controlPressed && altPressed)
mode = cfnmFull;
else
mode = cfnmShort;
MainWindow->GetActivePanel()->CopyFocusedNameToClipboard(mode);
return 0;
}
if (!shiftPressed && controlPressed && altPressed)
{ // clipboard: current full path
MainWindow->GetActivePanel()->CopyCurrentPathToClipboard();
return 0;
}
if (shiftPressed && controlPressed && !altPressed)
{ // clipboard: (full) UNC name of focused item
MainWindow->GetActivePanel()->CopyFocusedNameToClipboard(cfnmUNC);
return 0;
}
if (controlPressed || shiftPressed)
break;
MainWindow->GetActivePanel()->SelectFocusedIndex();
return 0;
}
case VK_ESCAPE:
case VK_TAB:
{
if (wParam == VK_ESCAPE || controlPressed)
{
if (wParam == VK_ESCAPE)
{
// lide chteji kompatibilitu s WinCmd, NC, FAR -- mazani obsahu na Escape
SetWindowText(HWindow, "");
}
SkipCharacter = TRUE;
MainWindow->FocusPanel(MainWindow->GetActivePanel());
return 0;
}
break;
}
case VK_LBRACKET:
case VK_RBRACKET:
case VK_SPACE:
{
if (controlPressed && !altPressed)
{
SkipCharacter = TRUE;
char path[MAX_PATH];
const char* s;
switch (wParam)
{
case VK_LBRACKET:
s = MainWindow->LeftPanel->Is(ptDisk) ? MainWindow->LeftPanel->GetPath() : NULL;
break;
case VK_RBRACKET:
s = MainWindow->RightPanel->Is(ptDisk) ? MainWindow->RightPanel->GetPath() : NULL;
break;
default:
s = MainWindow->GetActivePanel()->Is(ptDisk) ? MainWindow->GetActivePanel()->GetPath() : NULL;
break;
}
if (s != NULL)
{
if (shiftPressed) // dos-cesta
{
if (!GetShortPathName(s, path, MAX_PATH))
{
strcpy(path, s);
}
}
else
{
strcpy(path, s);
}
SalPathAddBackslash(path, MAX_PATH);
InsertText(path);
}
return 0;
}
break;
}
case VK_UP:
case VK_DOWN:
case VK_PRIOR:
case VK_NEXT: