-
Notifications
You must be signed in to change notification settings - Fork 0
/
etlframe.h
967 lines (875 loc) · 25.6 KB
/
etlframe.h
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
/*
Copyright (c) 2018 Emurasoft, Inc.
Licensed under the MIT license. See LICENSE for details.
*/
#if _MSC_VER > 1000
#pragma once
#endif
#include "plugin.h"
#include <crtdbg.h>
#pragma warning( push )
#pragma warning( disable : 4995 ) // 'function': name was marked as #pragma deprecated
#if _MSC_VER < 0x0700
#pragma warning( disable : 4786 ) // identifier was truncated to '255' characters in the browser information
#pragma warning( disable : 4512 ) // assignment operator could not be generated
#pragma warning( disable : 4100 ) // unreferenced formal parameter
#endif
#include <shlwapi.h>
#include <strsafe.h>
#include <map>
#pragma warning( pop )
#if _MSC_VER < 0x0700
#pragma warning( push )
#pragma warning( disable : 4127 ) // conditional expression is constant
#pragma warning( disable : 4786 ) // identifier was truncated to '255' characters in the browser information
#endif
#ifndef _countof
#define _countof(array) (sizeof(array)/sizeof(array[0]))
#endif
#define LOC_USE_EMEDLOC_DLL 2 // use emedloc.dll
#define LOC_USE_LOC_DLL 1 // use _loc.dll in MUI sub folder
#define LOC_USE_PLUGIN_DLL 0 // use the resource within plugin dll
// these asserts fail on previous versions of EmEditor (v4.13 or earlier).
#ifdef TEST_V5
#define ASSERT_STRICT(x) _ASSERTE(x)
#else
#define ASSERT_STRICT(x) (void(0))
#endif
#ifdef EE_IMPLEMENT
#define EE_EXTERN
#else
#define EE_EXTERN extern
#endif
#ifdef _DEBUG
#ifdef _DEBUG_NEW
#define new _DEBUG_NEW
#endif
#endif
LPCWSTR const szDefaultLang = L"DefaultLang";
// forward declaration
#define DEFINE_CREATE(c)
class ETL_FRAME_CLASS_NAME;
template <typename T> class CETLFrame;
typedef CETLFrame<ETL_FRAME_CLASS_NAME> CETLFrameX;
typedef std::map<HWND, CETLFrameX*> CETLFrameMap;
CETLFrameX* _ETLCreateFrame();
void _ETLDeleteFrame( CETLFrameX* pFrame );
BOOL IsFileExist( LPCWSTR pszPathName );
void GetModuleFilePath( LPCWSTR szFile, LPWSTR szPath );
HINSTANCE GetInstancePath( LPCWSTR szPath, bool bResourceOnly );
#define _ETL_IMPLEMENT CETLFrameX* _ETLCreateFrame() { CETLFrameX* pFrame = new ETL_FRAME_CLASS_NAME; return pFrame; } void _ETLDeleteFrame( CETLFrameX* pFrame ) { delete static_cast<ETL_FRAME_CLASS_NAME*>(pFrame); }
#pragma warning( push )
#pragma warning( disable : 4127 ) // C4127: conditional expression is constant
extern HINSTANCE EEGetLocaleInstanceHandle();
extern HINSTANCE EEGetInstanceHandle();
extern BOOL IsFileExist( LPCWSTR pszPathName );
extern BOOL GetModuleFile( LPWSTR szFileName );
extern WORD EEGetCmdID();
extern CETLFrameX* GetFrameFromFrame( HWND hwndFrame );
extern CETLFrameX* GetFrame( HWND hwnd );
extern CETLFrameX* GetFrameFromDlg( HWND hwnd );
extern CETLFrameX* GetFrameFromView( HWND hwndView );
// global data definition
class CETLData
{
public:
HINSTANCE m_hInstance;
HINSTANCE m_hinstLoc;
CRITICAL_SECTION m_cs;
CETLFrameMap* m_pETLFrameMap;
WORD m_wCmdID;
CETLData()
{
ZeroMemory( this, sizeof( CETLData ) );
InitializeCriticalSection( &m_cs );
}
~CETLData()
{
DeleteCriticalSection( &m_cs );
}
void Lock()
{
EnterCriticalSection( &m_cs );
}
void Unlock()
{
::LeaveCriticalSection( &m_cs );
}
};
#ifndef EE_EXTERN_ONLY
class CETLData _ETLData;
#endif
class CETLLock
{
public:
#ifdef EE_EXTERN_ONLY
CETLLock();
~CETLLock();
#else
CETLLock()
{
_ETLData.Lock();
}
~CETLLock()
{
_ETLData.Unlock();
}
#endif
};
#pragma warning( push )
#pragma warning( disable : 4995 ) // 'PathAddBackslashW': name was marked as #pragma deprecated
template <typename T> class __declspec(novtable) CETLFrame
{
public:
HWND m_hWnd;
CETLFrame<T>() : m_hWnd(0)
{
}
~CETLFrame<T>()
{
}
virtual void OnCommand( HWND hwndView )
{
T* pT = static_cast<T*>(this);
pT->OnCommand( hwndView );
}
void OnEvents( HWND hwndView, UINT nEvent, LPARAM lParam )
{
T* pT = static_cast<T*>(this);
pT->OnEvents( hwndView, nEvent, lParam );
}
BOOL QueryStatus( HWND hwndView, LPBOOL pbChecked )
{
T* pT = static_cast<T*>(this);
return pT->QueryStatus( hwndView, pbChecked );
}
static UINT GetMenuTextID()
{
if( T::_USE_LOC_DLL ){
return 0;
}
else {
return T::_IDS_MENU;
}
}
static UINT GetStatusMessageID()
{
if( T::_USE_LOC_DLL ){
return 0;
}
else {
return T::_IDS_STATUS;
}
}
static UINT GetBitmapID()
{
return T::_IDB_BITMAP;
}
static LRESULT GetStringA( LPSTR pBuf, size_t cchBuf, UINT nID )
{
char sz[80];
HINSTANCE hinst = EEGetLocaleInstanceHandle();
LRESULT lResult = 0;
if( hinst ){
lResult = LoadStringA( hinst, nID, sz, _countof( sz ) ) + 1;
//_ASSERTE( lResult > 1 );
if( pBuf ){
StringCchCopyA( pBuf, cchBuf, sz );
}
}
return lResult;
}
static LRESULT GetStringW( LPWSTR pBuf, size_t cchBuf, UINT nID )
{
WCHAR sz[80];
HINSTANCE hinst = EEGetLocaleInstanceHandle();
LRESULT lResult = 0;
if( hinst ){
lResult = LoadStringW( hinst, nID, sz, _countof( sz ) ) + 1; // LoadStringW does not work on Windows 9x, but that is OK.
//_ASSERTE( lResult > 1 );
if( pBuf ){
StringCchCopyW( pBuf, cchBuf, sz );
}
}
return lResult;
}
static LRESULT GetNameA( LPSTR pBuf, size_t cchBuf )
{
return GetStringA( pBuf, cchBuf, T::_IDS_NAME );
}
static LRESULT GetNameW( LPWSTR pBuf, size_t cchBuf )
{
return GetStringW( pBuf, cchBuf, T::_IDS_NAME );
}
static LRESULT GetVersionA( LPSTR pBuf, size_t cchBuf )
{
return GetStringA( pBuf, cchBuf, T::_IDS_VER );
}
static LRESULT GetVersionW( LPWSTR pBuf, size_t cchBuf )
{
return GetStringW( pBuf, cchBuf, T::_IDS_VER );
}
static LRESULT GetMenuW( LPWSTR pBuf, size_t cchBuf )
{
return GetStringW( pBuf, cchBuf, T::_IDS_MENU );
}
static LRESULT GetStatusW( LPWSTR pBuf, size_t cchBuf )
{
return GetStringW( pBuf, cchBuf, T::_IDS_STATUS );
}
static LRESULT GetInfo( WPARAM flag )
{
LRESULT lResult = 0;
switch( flag ){
case EPGI_ALLOW_OPEN_SAME_GROUP:
lResult = T::_ALLOW_OPEN_SAME_GROUP;
break;
case EPGI_ALLOW_MULTIPLE_INSTANCES:
lResult = T::_ALLOW_MULTIPLE_INSTANCES;
break;
case EPGI_MAX_EE_VERSION:
lResult = T::_MAX_EE_VERSION;
break;
case EPGI_MIN_EE_VERSION:
lResult = T::_MIN_EE_VERSION;
break;
case EPGI_SUPPORT_EE_PRO:
lResult = T::_SUPPORT_EE_PRO;
break;
case EPGI_SUPPORT_EE_STD:
lResult = T::_SUPPORT_EE_STD;
break;
}
return lResult;
}
virtual LRESULT SyncNow( HWND /*hwnd*/, UINT /*nFlags*/ )
{
return 0;
}
LRESULT PlugInProc( HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
{
LRESULT lResult = 0;
T* pT = static_cast<T*>(this);
switch( nMsg ){
case EP_QUERY_UNINSTALL:
lResult = pT->QueryUninstall( hwnd );
break;
case EP_SET_UNINSTALL:
lResult = pT->SetUninstall( hwnd, (LPWSTR)wParam, (LPWSTR)lParam );
break;
case EP_QUERY_PROPERTIES:
lResult = pT->QueryProperties( hwnd );
break;
case EP_SET_PROPERTIES:
lResult = pT->SetProperties( hwnd );
break;
case EP_PRE_TRANSLATE_MSG:
lResult = pT->PreTranslateMessage( hwnd, (MSG*)lParam );
break;
case EP_USE_DROPPED_FILES:
lResult = pT->UseDroppedFiles( hwnd );
break;
case EP_DISABLE_AUTO_COMPLETE:
lResult = pT->DisableAutoComplete( hwnd );
break;
case EP_USER_MSG:
lResult = pT->UserMessage( hwnd, wParam, lParam );
break;
case EP_SYNC_NOW:
lResult = SyncNow( hwnd, (UINT)wParam );
break;
}
return lResult;
}
static LRESULT GetMask( WPARAM wParam )
{
LRESULT lResult = 0;
if( wParam & BITMAP_24BIT_COLOR ){
lResult = T::_MASK_TRUE_COLOR;
}
return lResult;
}
static LRESULT GetBitmap( WPARAM wParam )
{
LRESULT lResult = 0;
if( wParam & BITMAP_LARGE ){
if( wParam & BITMAP_24BIT_COLOR ){
if( wParam & BITMAP_DISABLED ){
lResult = T::_IDB_TRUE_24_BW;
}
else if( wParam & BITMAP_HOT ){
lResult = T::_IDB_TRUE_24_HOT;
}
else {
lResult = T::_IDB_TRUE_24_DEFAULT;
}
}
else {
lResult = T::_IDB_16C_24;
}
}
else {
if( wParam & BITMAP_24BIT_COLOR ){
if( wParam & BITMAP_DISABLED ){
lResult = T::_IDB_TRUE_16_BW;
}
else if( wParam & BITMAP_HOT ){
lResult = T::_IDB_TRUE_16_HOT;
}
else {
lResult = T::_IDB_TRUE_16_DEFAULT;
}
}
else {
lResult = T::_IDB_BITMAP;
}
}
return lResult;
}
// Registry/INI
void GetProfileString( DWORD dwKey, LPCWSTR pszConfig, LPCWSTR lpszEntry, LPWSTR lpszBuf, DWORD cchBufSize, LPCWSTR lpszDefault )
{
DWORD dwSize = cchBufSize * sizeof( WCHAR );
if( ERROR_SUCCESS == Editor_RegQueryValue( m_hWnd, dwKey, pszConfig, lpszEntry, REG_SZ, (LPBYTE)lpszBuf, &dwSize, 0 ) ){
return;
}
lstrcpynW( lpszBuf, lpszDefault, cchBufSize );
}
void GetProfileString( LPCWSTR lpszEntry, LPWSTR lpszBuf, DWORD cchBufSize, LPCWSTR lpszDefault )
{
WCHAR szFileName[MAX_PATH];
if( GetModuleFile( szFileName ) ) {
GetProfileString( EEREG_EMEDITORPLUGIN, szFileName, lpszEntry, lpszBuf, cchBufSize, lpszDefault );
return;
}
lstrcpynW( lpszBuf, lpszDefault, cchBufSize );
}
int GetProfileInt( DWORD dwKey, LPCWSTR pszConfig, LPCWSTR lpszEntry, int nDefault )
{
_ASSERT( lpszEntry );
DWORD dwSize = sizeof( DWORD );
DWORD dwData = 0;
if( ERROR_SUCCESS == Editor_RegQueryValue( m_hWnd, dwKey, pszConfig, lpszEntry, REG_DWORD, (LPBYTE)&dwData, &dwSize, 0 ) ){
return (int)dwData;
}
return nDefault;
}
int GetProfileInt( LPCWSTR lpszEntry, int nDefault )
{
WCHAR szFileName[MAX_PATH];
if( GetModuleFile( szFileName ) ) {
return GetProfileInt( EEREG_EMEDITORPLUGIN, szFileName, lpszEntry, nDefault );
}
return nDefault;
}
DWORD GetProfileBinary( DWORD dwKey, LPCWSTR pszConfig, LPCWSTR lpszEntry, LPBYTE lpBuf, DWORD cbBufSize )
{
_ASSERT( lpszEntry );
if( ERROR_SUCCESS == Editor_RegQueryValue( m_hWnd, dwKey, pszConfig, lpszEntry, REG_BINARY, (LPBYTE)lpBuf, &cbBufSize, 0 ) ){
return cbBufSize;
}
return 0;
}
DWORD GetProfileBinary( LPCWSTR lpszEntry, LPBYTE lpBuf, DWORD cbBufSize )
{
WCHAR szFileName[MAX_PATH];
if( GetModuleFile( szFileName ) ) {
return GetProfileBinary( EEREG_EMEDITORPLUGIN, szFileName, lpszEntry, lpBuf, cbBufSize );
}
return 0;
}
void WriteProfileString( DWORD dwKey, LPCWSTR pszConfig, LPCWSTR lpszEntry, LPCWSTR lpszValue )
{
_ASSERT( lpszEntry );
_ASSERT( lpszValue );
VERIFY( ERROR_SUCCESS == Editor_RegSetValue( m_hWnd, dwKey, pszConfig, lpszEntry, REG_SZ, (const LPBYTE)lpszValue, (lstrlen( lpszValue ) + 1) * sizeof( WCHAR ), 0 ) );
}
void WriteProfileString( LPCWSTR lpszEntry, LPCWSTR lpszValue )
{
WCHAR szFileName[MAX_PATH];
if( GetModuleFile( szFileName ) ) {
WriteProfileString( EEREG_EMEDITORPLUGIN, szFileName, lpszEntry, lpszValue );
}
}
void WriteProfileInt( DWORD dwKey, LPCWSTR pszConfig, LPCWSTR lpszEntry, int nValue )
{
_ASSERT( lpszEntry );
DWORD dwData = nValue;
VERIFY( ERROR_SUCCESS == Editor_RegSetValue( m_hWnd, dwKey, pszConfig, lpszEntry, REG_DWORD, (const LPBYTE)&dwData, sizeof( DWORD ), 0 ) );
}
void WriteProfileInt( LPCWSTR lpszEntry, int nValue )
{
WCHAR szFileName[MAX_PATH];
if( GetModuleFile( szFileName ) ) {
WriteProfileInt( EEREG_EMEDITORPLUGIN, szFileName, lpszEntry, nValue );
}
}
void WriteProfileBinary( DWORD dwKey, LPCWSTR pszConfig, LPCWSTR lpszEntry, const LPBYTE lpBuf, DWORD cbBufSize, bool bVariableSize )
{
_ASSERT( lpszEntry );
_ASSERT( lpBuf );
VERIFY( ERROR_SUCCESS == Editor_RegSetValue( m_hWnd, dwKey, pszConfig, lpszEntry, REG_BINARY, (const LPBYTE)lpBuf, cbBufSize, bVariableSize ? EE_REG_VARIABLE_SIZE : 0 ) );
}
void WriteProfileBinary( LPCWSTR lpszEntry, const LPBYTE lpBuf, DWORD cbBufSize, bool bVariableSize )
{
WCHAR szFileName[MAX_PATH];
if( GetModuleFile( szFileName ) ) {
WriteProfileBinary( EEREG_EMEDITORPLUGIN, szFileName, lpszEntry, lpBuf, cbBufSize, bVariableSize );
}
}
void EraseProfile()
{
WCHAR szFileName[MAX_PATH];
if( GetModuleFile( szFileName ) ) {
Editor_RegSetValue( m_hWnd, EEREG_EMEDITORPLUGIN, szFileName, NULL, REG_SZ, (const LPBYTE)NULL, 0, 0 );
}
}
void EraseEntry( LPCWSTR lpszEntry )
{
WCHAR szFileName[MAX_PATH];
if( GetModuleFile( szFileName ) ) {
Editor_RegSetValue( m_hWnd, EEREG_EMEDITORPLUGIN, szFileName, lpszEntry, REG_SZ, (const LPBYTE)NULL, 0, 0 );
}
}
BOOL IsLangExist( LPCWSTR szLang )
{
if( szLang[0] != '.' ){
WCHAR szPath[MAX_PATH];
GetModuleFilePath( L"mui", szPath );
PathAppend( szPath, szLang );
return PathIsDirectory( szPath );
}
return FALSE;
}
BOOL GetResourceFolder( LPWSTR szFolder, bool bSystemLang, LPCWSTR szLang )
{
WCHAR szPath[MAX_PATH];
GetModuleFilePath( L"mui", szPath );
if( bSystemLang ){
WCHAR szFile[MAX_PATH];
UINT nLang = GetUserDefaultUILanguage();
StringCchPrintf( szFile, _countof( szFile ), L"%u", nLang );
if( IsLangExist( szFile ) ){
PathCombine( szFolder, szPath, szFile );
return TRUE;
}
}
if( szLang[0] ){
if( IsLangExist( szLang ) ){
PathCombine( szFolder, szPath, szLang );
return TRUE;
}
}
szFolder[0] = 0;
return FALSE;
}
BOOL GetAnyResourceFolder( LPWSTR szFolder )
{
// find anything available.
WCHAR szLang[MAX_PATH];
szLang[0] = 0;
WCHAR szPath[MAX_PATH];
GetModuleFilePath( L"mui\\*", szPath );
WIN32_FIND_DATA find;
HANDLE hFind = INVALID_HANDLE_VALUE;
hFind = FindFirstFile( szPath, &find );
if( hFind != INVALID_HANDLE_VALUE ) {
do {
if( find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ){
if( IsLangExist( find.cFileName ) ){
StringCchCopy( szLang, _countof( szLang ), find.cFileName );
break;
}
}
} while( FindNextFile(hFind, &find) );
FindClose(hFind);
}
if( szLang[0] ){
return GetResourceFolder( szFolder, false, szLang );
}
return FALSE;
}
BOOL GetDefaultResourceFolder( LPWSTR szFolder )
{
WCHAR szLang[MAX_PATH];
int nLang = GetProfileInt( EEREG_LM_COMMON, NULL, szDefaultLang, 1033 );
StringCchPrintf( szLang, _countof( szLang ), L"%d", nLang );
BOOL bResult = GetResourceFolder( szFolder, false, szLang );
if( !bResult ){
bResult = GetAnyResourceFolder( szFolder );
}
return bResult;
}
BOOL GetResourceFolder( LPWSTR szFolder )
{
WCHAR szDir[MAX_PATH];
szDir[0] = 0;
Editor_Info( m_hWnd, EI_GET_LANGUAGE, (LPARAM)szDir );
if( szDir[0] ){
PathStripPath( szDir );
GetModuleFilePath( L"mui", szFolder );
PathAppend( szFolder, szDir );
return TRUE;
}
return FALSE;
}
BOOL GetResourceFile( LPWSTR szPath, LPCWSTR szFile )
{
if( GetResourceFolder( szPath ) ){
PathAppend( szPath, szFile );
if( IsFileExist( szPath ) ){
return TRUE;
}
if( GetDefaultResourceFolder( szPath ) ){
PathAppend( szPath, szFile );
if( IsFileExist( szPath ) ){
return TRUE;
}
}
}
szPath[0] = 0;
return FALSE;
}
HINSTANCE GetEmedLocInstance()
{
if( T::_USE_LOC_DLL == LOC_USE_EMEDLOC_DLL ){
HINSTANCE hinstLoc = (HINSTANCE)Editor_Info( m_hWnd, EI_GET_LOC_DLL_INSTANCE, 0 );
_ASSERT( hinstLoc );
return hinstLoc;
//WCHAR szPath[MAX_PATH];
//szPath[0] = 0;
//Editor_Info( m_hWnd, EI_GET_LANGUAGE, (LPARAM)szPath );
//PathAppend( szPath, L"emedloc.dll" );
//return GetInstancePath( szPath );
}
else if( T::_USE_LOC_DLL == LOC_USE_LOC_DLL ){
WCHAR szFileName[MAX_PATH];
WCHAR szPath[MAX_PATH];
szPath[0] = 0;
if( GetModuleFile( szFileName ) ) {
StringCchCat( szFileName, _countof( szFileName ), L"_loc.dll" );
if( !GetResourceFile( szPath, szFileName ) ){
WCHAR sz[260];
StringCchCopy( sz, _countof( sz ), L"No localized file found - " );
StringCchCat( sz, _countof( sz ), szFileName );
::MessageBox( NULL, sz, L"EmEditor", MB_ICONSTOP | MB_OK );
return NULL;
}
}
else {
return NULL;
}
return GetInstancePath( szPath, true );
}
else {
return NULL;
}
}
void FreeLocInstance( HINSTANCE hinstLoc )
{
if( T::_USE_LOC_DLL != LOC_USE_EMEDLOC_DLL ){
if( hinstLoc != NULL ){
FreeLibrary( hinstLoc );
}
}
}
};
#pragma warning( pop )
#ifndef EE_EXTERN_ONLY
HINSTANCE EEGetLocaleInstanceHandle()
{
CETLLock lock;
{
if( _ETLData.m_hinstLoc != NULL ){
return _ETLData.m_hinstLoc;
}
}
return _ETLData.m_hInstance;
}
HINSTANCE EEGetInstanceHandle()
{
_ASSERTE( _ETLData.m_hInstance != NULL );
return _ETLData.m_hInstance;
}
BOOL IsFileExist( LPCWSTR pszPathName )
{
return( !(GetFileAttributes( pszPathName ) & FILE_ATTRIBUTE_DIRECTORY) );
}
// buffer must be MAX_PATH character long.
BOOL GetModuleFile( LPWSTR szFileName )
{
WCHAR szPath[MAX_PATH];
if( !GetModuleFileName( EEGetInstanceHandle(), szPath, _countof( szPath ) ) ){
return FALSE;
}
WCHAR szBuf[MAX_PATH];
LPWSTR pszFile = szBuf;
if( !GetFullPathName( szPath, MAX_PATH, szBuf, &pszFile ) ){
return FALSE;
}
LPWSTR p = wcschr( pszFile, L'.' );
if( p != NULL ) *p = L'\0';
StringCchCopy( szFileName, MAX_PATH, pszFile );
return TRUE;
}
void GetModuleFilePath( LPCWSTR szFile, LPWSTR szPath )
{
szPath[0] = '\0';
WCHAR szModulePath[MAX_PATH];
LPWSTR p = szPath;
if( ::GetModuleFileName( EEGetInstanceHandle(), szModulePath, MAX_PATH ) ) {
GetFullPathName( szModulePath, MAX_PATH, szPath, &p );
}
StringCchCopy( p, (size_t)( MAX_PATH - ( p - szPath ) ), szFile );
}
HINSTANCE GetInstancePath( LPCWSTR szPath, bool bResourceOnly )
{
_ASSERT( szPath[0] );
_ASSERT( !PathIsRelative( szPath ) ); // szPath must be full path to avoid dll hijacking issues
HINSTANCE hinstRes = ::LoadLibraryEx( szPath, NULL, bResourceOnly ? (LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE) : 0 );
if( hinstRes == NULL ){
WCHAR sz[MAX_PATH + 64];
StringCchPrintf( sz, _countof( sz ), L"Cannot load %s.", szPath );
MessageBox( NULL, sz, L"EmEditor", MB_OK | MB_ICONSTOP );
return NULL;
}
return hinstRes;
}
WORD EEGetCmdID()
{
_ASSERTE( _ETLData.m_wCmdID >= EEID_PLUG_IN1 );
_ASSERTE( _ETLData.m_wCmdID <= EEID_PLUG_IN1 + 255 );
return _ETLData.m_wCmdID;
}
CETLFrameX* GetFrameFromFrame( HWND hwndFrame )
{
_ASSERTE( hwndFrame );
_ASSERTE( IsWindow( hwndFrame ) );
ASSERT_STRICT( _ETLData.m_pETLFrameMap != NULL );
if( _ETLData.m_pETLFrameMap == NULL ) return NULL;
CETLFrameX* pFrame = NULL;
{
CETLLock lock;
CETLFrameMap::iterator it = _ETLData.m_pETLFrameMap->find( hwndFrame );
ASSERT_STRICT( it != _ETLData.m_pETLFrameMap->end() );
if( it != _ETLData.m_pETLFrameMap->end() ){
pFrame = it->second;
_ASSERTE( pFrame != NULL );
}
}
return pFrame;
}
CETLFrameX* GetFrame( HWND hwnd )
{
_ASSERTE( IsWindow( hwnd ) );
HWND hwndFrame = GetAncestor( hwnd, GA_ROOTOWNER );
_ASSERTE( IsWindow( hwndFrame ) );
CETLFrameX* pFrame = GetFrameFromFrame( hwndFrame );
// _ASSERTE( pFrame );
return pFrame;
}
CETLFrameX* GetFrameFromDlg( HWND hwnd )
{
return GetFrame( hwnd );
}
CETLFrameX* GetFrameFromView( HWND hwndView )
{
return GetFrame( hwndView );
}
void DeleteAllFrames()
{
for( CETLFrameMap::iterator it = _ETLData.m_pETLFrameMap->begin(); it != _ETLData.m_pETLFrameMap->end(); it++ ){
CETLFrameX* pFrame = it->second;
pFrame->OnEvents( NULL, EVENT_CLOSE_FRAME, 0 );
delete pFrame;
}
_ETLData.m_pETLFrameMap->clear();
}
BOOL APIENTRY DllMain( HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID /*lpReserved*/ )
{
if( ul_reason_for_call == DLL_PROCESS_ATTACH ){
#ifdef _DEBUG
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_EVERY_1024_DF /* _CRTDBG_CHECK_ALWAYS_DF */ );
#endif
_ASSERTE( _ETLData.m_hInstance == NULL );
_ETLData.m_hInstance = hModule;
}
else if( ul_reason_for_call == DLL_PROCESS_DETACH ){
// _ASSERTE( _ETLData.m_pETLFrameMap == NULL );
if( _ETLData.m_pETLFrameMap ) {
for( CETLFrameMap::iterator it = _ETLData.m_pETLFrameMap->begin(); it != _ETLData.m_pETLFrameMap->end(); it++ ){
CETLFrameX* pFrame = it->second;
delete pFrame;
}
delete _ETLData.m_pETLFrameMap;
_ETLData.m_pETLFrameMap = NULL;
_ETLData.m_wCmdID = 0;
}
}
return TRUE;
}
extern "C" void __stdcall OnCommand( HWND hwndView )
{
CETLFrameX* pFrame = GetFrameFromView( hwndView );
pFrame->OnCommand( hwndView );
}
extern "C" BOOL __stdcall QueryStatus( HWND hwndView, LPBOOL pbChecked )
{
CETLFrameX* pFrame = GetFrameFromView( hwndView );
if( pFrame == NULL ) return FALSE;
return pFrame->QueryStatus( hwndView, pbChecked );
}
extern "C" UINT __stdcall GetMenuTextID()
{
return CETLFrameX::GetMenuTextID();
}
extern "C" UINT __stdcall GetStatusMessageID()
{
return CETLFrameX::GetStatusMessageID();
}
extern "C" UINT __stdcall GetBitmapID()
{
return CETLFrameX::GetBitmapID();
}
extern "C" void __stdcall OnEvents( HWND hwndView, UINT nEvent, LPARAM lParam )
{
HWND hwndFrame = NULL;
if( nEvent != EVENT_CLOSE ){
_ASSERTE( hwndView );
if( !IsWindow( hwndView ) ) { // hwndView can be already destroyed if PostMessage( WM_ENDSESSION, ...) is used ("Do not share process between documents (disables tabs)" is checked in the Advanced page of Customize dialog box)
return;
}
hwndFrame = GetParent( hwndView );
_ASSERTE( hwndFrame );
if( !hwndFrame ) {
return;
}
}
if( nEvent & EVENT_CREATE ){
_ASSERTE( (UINT)lParam >= EEID_PLUG_IN1 && (UINT)lParam <= EEID_PLUG_IN1 + 255 );
_ASSERTE( _ETLData.m_wCmdID == 0 );
_ASSERTE( _ETLData.m_pETLFrameMap == NULL );
_ETLData.m_wCmdID = LOWORD( lParam );
if( _ETLData.m_pETLFrameMap == NULL ) {
_ETLData.m_pETLFrameMap = new CETLFrameMap;
}
_ASSERT( _ETLData.m_pETLFrameMap->size() == 0 );
if( Editor_GetVersion( hwndView ) < 5000 ){ // previous versions of EmEditor do not fire EVENT_CREATE_FRAME.
OnEvents( hwndView, EVENT_CREATE_FRAME, lParam );
}
}
else {
ASSERT_STRICT( _ETLData.m_pETLFrameMap != NULL );
if( _ETLData.m_pETLFrameMap != NULL ){
if( nEvent & EVENT_CREATE_FRAME ){
_ASSERTE( _ETLData.m_wCmdID == LOWORD( lParam ) );
CETLFrameX* pFrame = static_cast<CETLFrameX*>(_ETLCreateFrame());
pFrame->m_hWnd = hwndFrame;
{
CETLLock lock;
_ASSERTE( _ETLData.m_pETLFrameMap->find( hwndFrame ) == _ETLData.m_pETLFrameMap->end() );
_ETLData.m_pETLFrameMap->insert( std::pair<HWND, CETLFrameX*>( hwndFrame, pFrame ) );
if( _ETLData.m_pETLFrameMap->size() == 1 ){
_ASSERT( _ETLData.m_hinstLoc == NULL );
_ETLData.m_hinstLoc = pFrame->GetEmedLocInstance();
}
pFrame->OnEvents( hwndView, nEvent, lParam );
}
}
else if( nEvent & EVENT_CLOSE_FRAME ){
CETLFrameX* pFrame;
{
CETLLock lock;
CETLFrameMap::iterator it = _ETLData.m_pETLFrameMap->find( hwndFrame );
_ASSERTE( it != _ETLData.m_pETLFrameMap->end() );
if( it == _ETLData.m_pETLFrameMap->end() ) {
return;
}
pFrame = it->second;
pFrame->OnEvents( hwndView, nEvent, lParam );
_ETLData.m_pETLFrameMap->erase( it );
if( _ETLData.m_pETLFrameMap->size() == 0 ){
if( _ETLData.m_hinstLoc != NULL ){
pFrame->FreeLocInstance( _ETLData.m_hinstLoc );
_ETLData.m_hinstLoc = NULL;
}
}
}
_ETLDeleteFrame( pFrame );
}
else if( nEvent & EVENT_CLOSE ){
ASSERT_STRICT( _ETLData.m_pETLFrameMap->empty() );
DeleteAllFrames(); // previous versions of EmEditor do not fire EVENT_CLOSE_FRAME.
delete _ETLData.m_pETLFrameMap;
_ETLData.m_pETLFrameMap = NULL;
_ETLData.m_wCmdID = 0;
}
else {
CETLFrameX* pFrame;
{
CETLLock lock;
CETLFrameMap::iterator it = _ETLData.m_pETLFrameMap->find( hwndFrame );
if( it == _ETLData.m_pETLFrameMap->end() ) {
return;
}
pFrame = it->second;
}
if( nEvent & EVENT_UI_CHANGED ){
if( lParam & UI_CHANGED_LANGUAGE ){
CETLLock lock;
if( _ETLData.m_hinstLoc != NULL ){
_ETLData.m_hinstLoc = pFrame->GetEmedLocInstance();
}
}
}
pFrame->OnEvents( hwndView, nEvent, lParam );
}
}
}
}
extern "C" LRESULT __stdcall PlugInProc( HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
{
// hwnd can be either view handle, frame handle, or plug-ins settings dialog handle.
LRESULT lResult = 0;
switch( nMsg ){
case EP_GET_BITMAP:
lResult = CETLFrameX::GetBitmap( wParam );
break;
case EP_GET_MASK:
lResult = CETLFrameX::GetMask( wParam );
break;
case EP_GET_NAMEA:
lResult = CETLFrameX::GetNameA( (LPSTR)lParam, (size_t)wParam );
break;
case EP_GET_NAMEW:
lResult = CETLFrameX::GetNameW( (LPWSTR)lParam, (size_t)wParam );
break;
case EP_GET_VERSIONA:
lResult = CETLFrameX::GetVersionA( (LPSTR)lParam, (size_t)wParam );
break;
case EP_GET_VERSIONW:
lResult = CETLFrameX::GetVersionW( (LPWSTR)lParam, (size_t)wParam );
break;
case EP_GET_INFO:
lResult = CETLFrameX::GetInfo( wParam );
break;
case EP_GET_MENU_TEXT:
lResult = CETLFrameX::GetMenuW( (LPWSTR)lParam, (size_t)wParam );
break;
case EP_GET_STATUS_MESSAGE:
lResult = CETLFrameX::GetStatusW( (LPWSTR)lParam, (size_t)wParam );
break;
default:
{
// hwnd is plug-ins settings dialog handle or view window handle.
CETLFrameX* pFrame = GetFrame( hwnd );
if( pFrame ){
lResult = pFrame->PlugInProc( hwnd, nMsg, wParam, lParam );
}
}
break;
}
return lResult;
}
#pragma warning( pop )
#endif // EE_EXTERN_ONLY