Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

7177 lines (5763 sloc) 216.552 kb
/******************************************************************************
*
*
* Notepad2
*
* Notepad2.c
* Main application window functionality
*
* See Readme.txt for more information about this source code.
* Please send me your comments to this work.
*
* See License.txt for details about distribution and modification.
*
* (c) Florian Balmer 1996-2010
* florian.balmer@gmail.com
* http://www.flos-freeware.ch
*
*
******************************************************************************/
#define _WIN32_WINNT 0x501
#include <windows.h>
#include <commctrl.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <shellapi.h>
#include <commdlg.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "scintilla.h"
#include "scilexer.h"
#include "edit.h"
#include "styles.h"
#include "helpers.h"
#include "dialogs.h"
#include "notepad2.h"
#include "scicall.h"
#include "resource.h"
/******************************************************************************
*
* Local and global Variables for Notepad2.c
*
*/
HWND hwndStatus;
HWND hwndToolbar;
HWND hwndReBar;
HWND hwndEdit;
HWND hwndEditFrame;
HWND hwndMain;
HWND hwndNextCBChain = NULL;
HWND hDlgFindReplace = NULL;
#define NUMTOOLBITMAPS 24
#define NUMINITIALTOOLS 24
#define MARGIN_FOLD_INDEX 2
TBBUTTON tbbMainWnd[] = { {0,IDT_FILE_NEW,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{1,IDT_FILE_OPEN,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{2,IDT_FILE_BROWSE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{3,IDT_FILE_SAVE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{0,0,0,TBSTYLE_SEP,0,0},
{4,IDT_EDIT_UNDO,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{5,IDT_EDIT_REDO,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{0,0,0,TBSTYLE_SEP,0,0},
{6,IDT_EDIT_CUT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{7,IDT_EDIT_COPY,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{8,IDT_EDIT_PASTE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{0,0,0,TBSTYLE_SEP,0,0},
{9,IDT_EDIT_FIND,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{10,IDT_EDIT_REPLACE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{0,0,0,TBSTYLE_SEP,0,0},
{11,IDT_VIEW_WORDWRAP,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{0,0,0,TBSTYLE_SEP,0,0},
{12,IDT_VIEW_ZOOMIN,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{13,IDT_VIEW_ZOOMOUT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{0,0,0,TBSTYLE_SEP,0,0},
{14,IDT_VIEW_SCHEME,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{15,IDT_VIEW_SCHEMECONFIG,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{0,0,0,TBSTYLE_SEP,0,0},
{16,IDT_FILE_EXIT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{17,IDT_FILE_SAVEAS,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{18,IDT_FILE_SAVECOPY,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{19,IDT_EDIT_CLEAR,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{20,IDT_FILE_PRINT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{21,IDT_FILE_OPENFAV,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{22,IDT_FILE_ADDTOFAV,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0},
{23,IDT_VIEW_TOGGLEFOLDS,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0} };
WCHAR szIniFile[MAX_PATH] = L"";
WCHAR szIniFile2[MAX_PATH] = L"";
BOOL bSaveSettings;
BOOL bSaveRecentFiles;
BOOL bSaveFindReplace;
WCHAR tchLastSaveCopyDir[MAX_PATH] = L"";
WCHAR tchOpenWithDir[MAX_PATH];
WCHAR tchFavoritesDir[MAX_PATH];
WCHAR tchDefaultDir[MAX_PATH];
WCHAR tchDefaultExtension[64];
WCHAR tchFileDlgFilters[5*1024];
WCHAR tchToolbarButtons[512];
WCHAR tchToolbarBitmap[MAX_PATH];
WCHAR tchToolbarBitmapHot[MAX_PATH];
WCHAR tchToolbarBitmapDisabled[MAX_PATH];
int iPathNameFormat;
BOOL fWordWrap;
int iWordWrapMode;
int iWordWrapIndent;
int iWordWrapSymbols;
BOOL bShowWordWrapSymbols;
BOOL bMatchBraces;
BOOL bAutoIndent;
BOOL bAutoCloseTags;
BOOL bShowIndentGuides;
BOOL bHiliteCurrentLine;
BOOL bTabsAsSpaces;
BOOL bTabsAsSpacesG;
BOOL bTabIndents;
int iTabWidth;
int iTabWidthG;
int iIndentWidth;
int iIndentWidthG;
BOOL bMarkLongLines;
int iLongLinesLimit;
int iLongLinesLimitG;
int iLongLineMode;
int iWrapCol = 0;
BOOL bShowSelectionMargin;
BOOL bShowLineNumbers;
BOOL bShowCodeFolding;
BOOL bViewWhiteSpace;
BOOL bViewEOLs;
int iDefaultEncoding;
BOOL bSkipUnicodeDetection;
BOOL bLoadASCIIasUTF8;
BOOL bNoEncodingTags;
int iSrcEncoding = -1;
int iWeakSrcEncoding = -1;
int iDefaultEOLMode;
BOOL bFixLineEndings;
BOOL bAutoStripBlanks;
int iPrintHeader;
int iPrintFooter;
int iPrintColor;
int iPrintZoom;
RECT pagesetupMargin;
BOOL bSaveBeforeRunningTools;
int iFileWatchingMode;
BOOL bResetFileWatching;
int iFileCheckInverval;
int iEscFunction;
BOOL bAlwaysOnTop;
BOOL bMinimizeToTray;
BOOL bTransparentMode;
BOOL bTransparentModeAvailable;
BOOL bShowToolbar;
BOOL bShowStatusbar;
typedef struct _wi
{
int x;
int y;
int cx;
int cy;
int max;
} WININFO;
WININFO wi;
BOOL bStickyWinPos;
BOOL bIsAppThemed;
int cyReBar;
int cyReBarFrame;
int cxEditFrame;
int cyEditFrame;
int cxEncodingDlg;
int cyEncodingDlg;
int cxRecodeDlg;
int cyRecodeDlg;
int cxFileMRUDlg;
int cyFileMRUDlg;
int cxOpenWithDlg;
int cyOpenWithDlg;
int cxFavoritesDlg;
int cyFavoritesDlg;
int xFindReplaceDlg;
int yFindReplaceDlg;
LPWSTR lpFileList[32];
int cFileList = 0;
int cchiFileList = 0;
LPWSTR lpFileArg = NULL;
LPWSTR lpSchemeArg = NULL;
LPWSTR lpMatchArg = NULL;
LPWSTR lpEncodingArg = NULL;
LPMRULIST pFileMRU;
LPMRULIST mruFind;
LPMRULIST mruReplace;
DWORD dwLastIOError;
WCHAR szCurFile[MAX_PATH+40];
FILEVARS fvCurFile;
BOOL bModified;
BOOL bReadOnly = FALSE;
int iEncoding;
int iOriginalEncoding;
int iEOLMode;
int iDefaultCodePage;
int iDefaultCharSet;
int iInitialLine;
int iInitialColumn;
int iInitialLexer;
BOOL bLastCopyFromMe = FALSE;
DWORD dwLastCopyTime;
UINT uidsAppTitle = IDS_APPTITLE;
WCHAR szTitleExcerpt[128] = L"";
int fKeepTitleExcerpt = 0;
HANDLE hChangeHandle = NULL;
BOOL bRunningWatch = FALSE;
WIN32_FIND_DATA fdCurFile;
UINT msgTaskbarCreated = 0;
HMODULE hModUxTheme = NULL;
EDITFINDREPLACE efrData = { "", "", "", "", 0, 0, 0, 0, 0, 0, NULL };
UINT cpLastFind = 0;
BOOL bReplaceInitialized = FALSE;
extern NP2ENCODING mEncoding[];
int iLineEndings[3] = {
SC_EOL_CRLF,
SC_EOL_LF,
SC_EOL_CR
};
WCHAR wchPrefixSelection[256] = L"";
WCHAR wchAppendSelection[256] = L"";
WCHAR wchPrefixLines[256] = L"";
WCHAR wchAppendLines[256] = L"";
int iSortOptions = 0;
BOOL fIsElevated = FALSE;
WCHAR wchWndClass[16] = WC_NOTEPAD2;
LPMALLOC g_lpMalloc;
HINSTANCE g_hInstance;
HANDLE g_hScintilla;
UINT16 g_uWinVer;
WCHAR g_wchAppUserModelID[64];
//=============================================================================
//
// Flags
//
int flagNoReuseWindow = 0;
int flagReuseWindow = 0;
int flagMultiFileArg = 0;
int flagSingleFileInstance = 0;
int flagStartAsTrayIcon = 0;
int flagRelativeFileMRU = 0;
int flagPortableMyDocs = 0;
int flagNoFadeHidden = 0;
int flagSimpleIndentGuides = 0;
int fNoHTMLGuess = 0;
int fNoCGIGuess = 0;
int fNoFileVariables = 0;
int flagPosParam = 0;
int flagDefaultPos = 0;
int flagNewFromClipboard = 0;
int flagPasteBoard = 0;
int flagSetEncoding = 0;
int flagSetEOLMode = 0;
int flagJumpTo = 0;
int flagMatchText = 0;
int flagLexerSpecified = 0;
int flagQuietCreate = 0;
int flagUseSystemMRU = 0;
int flagRelaunchElevated = 0;
int flagDisplayHelp = 0;
//==============================================================================
//
// Folding Functions
//
//
typedef enum {
EXPAND = 1,
SNIFF = 0,
FOLD = -1
} FOLD_ACTION;
#define FOLD_CHILDREN SCMOD_CTRL
#define FOLD_SIBLINGS SCMOD_SHIFT
BOOL __stdcall FoldToggleNode( int ln, FOLD_ACTION action )
{
BOOL fExpanded = SciCall_GetFoldExpanded(ln);
if ((action == FOLD && fExpanded) || (action == EXPAND && !fExpanded))
{
SciCall_ToggleFold(ln);
return(TRUE);
}
return(FALSE);
}
void __stdcall FoldToggleAll( FOLD_ACTION action )
{
BOOL fToggled = FALSE;
int lnTotal = SciCall_GetLineCount();
int ln;
for (ln = 0; ln < lnTotal; ++ln)
{
if (SciCall_GetFoldLevel(ln) & SC_FOLDLEVELHEADERFLAG)
{
if (action == SNIFF)
action = SciCall_GetFoldExpanded(ln) ? FOLD : EXPAND;
if (FoldToggleNode(ln, action))
fToggled = TRUE;
}
}
if (fToggled)
{
SciCall_SetXCaretPolicy(CARET_SLOP|CARET_STRICT|CARET_EVEN,50);
SciCall_SetYCaretPolicy(CARET_SLOP|CARET_STRICT|CARET_EVEN,5);
SciCall_ScrollCaret();
SciCall_SetXCaretPolicy(CARET_SLOP|CARET_EVEN,50);
SciCall_SetYCaretPolicy(CARET_EVEN,0);
}
}
void __stdcall FoldPerformAction( int ln, int mode, FOLD_ACTION action )
{
if (action == SNIFF)
action = SciCall_GetFoldExpanded(ln) ? FOLD : EXPAND;
if (mode & (FOLD_CHILDREN | FOLD_SIBLINGS))
{
// ln/lvNode: line and level of the source of this fold action
int lnNode = ln;
int lvNode = SciCall_GetFoldLevel(lnNode) & SC_FOLDLEVELNUMBERMASK;
int lnTotal = SciCall_GetLineCount();
// lvStop: the level over which we should not cross
int lvStop = lvNode;
if (mode & FOLD_SIBLINGS)
{
ln = SciCall_GetFoldParent(lnNode) + 1; // -1 + 1 = 0 if no parent
--lvStop;
}
for ( ; ln < lnTotal; ++ln)
{
int lv = SciCall_GetFoldLevel(ln);
BOOL fHeader = lv & SC_FOLDLEVELHEADERFLAG;
lv &= SC_FOLDLEVELNUMBERMASK;
if (lv < lvStop || (lv == lvStop && fHeader && ln != lnNode))
return;
else if (fHeader && (lv == lvNode || (lv > lvNode && mode & FOLD_CHILDREN)))
FoldToggleNode(ln, action);
}
}
else
{
FoldToggleNode(ln, action);
}
}
void __stdcall FoldClick( int ln, int mode )
{
static struct {
int ln;
int mode;
DWORD dwTickCount;
} prev;
BOOL fGotoFoldPoint = mode & FOLD_SIBLINGS;
if (!(SciCall_GetFoldLevel(ln) & SC_FOLDLEVELHEADERFLAG))
{
// Not a fold point: need to look for a double-click
if ( prev.ln == ln && prev.mode == mode &&
GetTickCount() - prev.dwTickCount <= GetDoubleClickTime() )
{
prev.ln = -1; // Prevent re-triggering on a triple-click
ln = SciCall_GetFoldParent(ln);
if (ln >= 0 && SciCall_GetFoldExpanded(ln))
fGotoFoldPoint = TRUE;
else
return;
}
else
{
// Save the info needed to match this click with the next click
prev.ln = ln;
prev.mode = mode;
prev.dwTickCount = GetTickCount();
return;
}
}
FoldPerformAction(ln, mode, SNIFF);
if (fGotoFoldPoint)
EditJumpTo(hwndEdit, ln + 1, 0);
}
void __stdcall FoldAltArrow( int key, int mode )
{
// Because Alt-Shift is already in use (and because the sibling fold feature
// is not as useful from the keyboard), only the Ctrl modifier is supported
if (bShowCodeFolding && (mode & (SCMOD_ALT | SCMOD_SHIFT)) == SCMOD_ALT)
{
int ln = SciCall_LineFromPosition(SciCall_GetCurrentPos());
// Jump to the next visible fold point
if (key == SCK_DOWN && !(mode & SCMOD_CTRL))
{
int lnTotal = SciCall_GetLineCount();
for (ln = ln + 1; ln < lnTotal; ++ln)
{
if ( SciCall_GetFoldLevel(ln) & SC_FOLDLEVELHEADERFLAG &&
SciCall_GetLineVisible(ln) )
{
EditJumpTo(hwndEdit, ln + 1, 0);
return;
}
}
}
// Jump to the previous visible fold point
else if (key == SCK_UP && !(mode & SCMOD_CTRL))
{
for (ln = ln - 1; ln >= 0; --ln)
{
if ( SciCall_GetFoldLevel(ln) & SC_FOLDLEVELHEADERFLAG &&
SciCall_GetLineVisible(ln) )
{
EditJumpTo(hwndEdit, ln + 1, 0);
return;
}
}
}
// Perform a fold/unfold operation
else if (SciCall_GetFoldLevel(ln) & SC_FOLDLEVELHEADERFLAG)
{
if (key == SCK_LEFT ) FoldPerformAction(ln, mode, FOLD);
if (key == SCK_RIGHT) FoldPerformAction(ln, mode, EXPAND);
}
}
}
//=============================================================================
//
// WinMain()
//
//
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,
LPSTR lpCmdLine,int nCmdShow)
{
MSG msg;
HWND hwnd;
HACCEL hAccMain;
HACCEL hAccFindReplace;
INITCOMMONCONTROLSEX icex;
//HMODULE hSciLexer;
// Set global variable g_hInstance
g_hInstance = hInstance;
// Set the Windows version global variable
g_uWinVer = LOWORD(GetVersion());
g_uWinVer = MAKEWORD(HIBYTE(g_uWinVer),LOBYTE(g_uWinVer));
SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
// check if running at least on Windows 2000
if (!Is2k()) {
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER|
FORMAT_MESSAGE_FROM_SYSTEM|
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
ERROR_OLD_WIN_VERSION,
MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), // Default language
(LPWSTR)&lpMsgBuf,
0,
NULL);
MessageBox(NULL,(LPCWSTR)lpMsgBuf,L"Notepad2",MB_OK|MB_ICONEXCLAMATION);
LocalFree(lpMsgBuf);
return(0);
}
// Check if running with elevated privileges
fIsElevated = IsElevated();
// Default Encodings (may already be used for command line parsing)
Encoding_InitDefaults();
// Needed to make W7 jump lists work when NP2 is not explicitly associated
// Notepad2 should be registered under HKCR\*\OpenWithList
if (IsW7()) {
typedef HRESULT (WINAPI *PFNSCPEAUMID)( PCWSTR AppID );
PFNSCPEAUMID pfnSetCurrentProcessExplicitAppUserModelID = (PFNSCPEAUMID)
GetProcAddress(GetModuleHandleA("SHELL32.dll"), "SetCurrentProcessExplicitAppUserModelID");
if (pfnSetCurrentProcessExplicitAppUserModelID)
pfnSetCurrentProcessExplicitAppUserModelID(L"Notepad2");
}
// Command Line, Ini File and Flags
ParseCommandLine();
FindIniFile();
TestIniFile();
CreateIniFile();
LoadFlags();
// set AppUserModelID
PrivateSetCurrentProcessExplicitAppUserModelID(g_wchAppUserModelID);
// Command Line Help Dialog
if (flagDisplayHelp) {
DisplayCmdLineHelp();
return(0);
}
// Adapt window class name
if (fIsElevated)
StrCat(wchWndClass,L"U");
if (flagPasteBoard)
StrCat(wchWndClass,L"B");
// Relaunch with elevated privileges
if (RelaunchElevated())
return(0);
// Try to run multiple instances
if (RelaunchMultiInst())
return(0);
// Try to activate another window
if (ActivatePrevInst())
return(0);
// Init OLE and Common Controls
OleInitialize(NULL);
SHGetMalloc(&g_lpMalloc);
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_WIN95_CLASSES|ICC_COOL_CLASSES|ICC_BAR_CLASSES|ICC_USEREX_CLASSES;
InitCommonControlsEx(&icex);
msgTaskbarCreated = RegisterWindowMessage(L"TaskbarCreated");
hModUxTheme = LoadLibrary(L"uxtheme.dll");
Scintilla_RegisterClasses(hInstance);
// Load Settings
LoadSettings();
if (!InitApplication(hInstance))
return FALSE;
if (!(hwnd = InitInstance(hInstance,lpCmdLine,nCmdShow)))
return FALSE;
hAccMain = LoadAccelerators(hInstance,MAKEINTRESOURCE(IDR_MAINWND));
hAccFindReplace = LoadAccelerators(hInstance,MAKEINTRESOURCE(IDR_ACCFINDREPLACE));
while (GetMessage(&msg,NULL,0,0))
{
if (IsWindow(hDlgFindReplace) && (msg.hwnd == hDlgFindReplace || IsChild(hDlgFindReplace,msg.hwnd)))
if (TranslateAccelerator(hDlgFindReplace,hAccFindReplace,&msg) || IsDialogMessage(hDlgFindReplace,&msg))
continue;
if (!TranslateAccelerator(hwnd,hAccMain,&msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
// Save Settings is done elsewhere
Scintilla_ReleaseResources();
UnregisterClass(wchWndClass,hInstance);
if (hModUxTheme)
FreeLibrary(hModUxTheme);
g_lpMalloc->lpVtbl->Release(g_lpMalloc);
OleUninitialize();
return(msg.wParam);
hPrevInst;
}
//=============================================================================
//
// InitApplication()
//
//
BOOL InitApplication(HINSTANCE hInstance)
{
WNDCLASS wc;
wc.style = CS_BYTEALIGNWINDOW | CS_DBLCLKS;
wc.lpfnWndProc = (WNDPROC)MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDR_MAINWND));
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAINWND);
wc.lpszClassName = wchWndClass;
return RegisterClass(&wc);
}
//=============================================================================
//
// InitInstance()
//
//
HWND InitInstance(HINSTANCE hInstance,LPSTR pszCmdLine,int nCmdShow)
{
RECT rc = { wi.x, wi.y, wi.x+wi.cx, wi.y+wi.cy };
RECT rc2;
MONITORINFO mi;
HMONITOR hMonitor = MonitorFromRect(&rc,MONITOR_DEFAULTTONEAREST);
mi.cbSize = sizeof(mi);
GetMonitorInfo(hMonitor,&mi);
if (flagDefaultPos == 1) {
wi.x = wi.y = wi.cx = wi.cy = CW_USEDEFAULT;
wi.max = 0;
}
else if (flagDefaultPos >= 4) {
SystemParametersInfo(SPI_GETWORKAREA,0,&rc,0);
if (flagDefaultPos & 8)
wi.x = (rc.right - rc.left) / 2;
else
wi.x = rc.left;
wi.cx = rc.right - rc.left;
if (flagDefaultPos & (4|8))
wi.cx /= 2;
if (flagDefaultPos & 32)
wi.y = (rc.bottom - rc.top) / 2;
else
wi.y = rc.top;
wi.cy = rc.bottom - rc.top;
if (flagDefaultPos & (16|32))
wi.cy /= 2;
if (flagDefaultPos & 64) {
wi.x = rc.left;
wi.y = rc.top;
wi.cx = rc.right - rc.left;
wi.cy = rc.bottom - rc.top;
}
if (flagDefaultPos & 128) {
wi.x += (flagDefaultPos & 8) ? 4 : 8;
wi.cx -= (flagDefaultPos & (4|8)) ? 12 : 16;
wi.y += (flagDefaultPos & 32) ? 4 : 8;
wi.cy -= (flagDefaultPos & (16|32)) ? 12 : 16;
}
}
else if (flagDefaultPos == 2 || flagDefaultPos == 3 ||
wi.x == CW_USEDEFAULT || wi.y == CW_USEDEFAULT ||
wi.cx == CW_USEDEFAULT || wi.cy == CW_USEDEFAULT) {
// default window position
SystemParametersInfo(SPI_GETWORKAREA,0,&rc,0);
wi.y = rc.top + 16;
wi.cy = rc.bottom - rc.top - 32;
wi.cx = min(rc.right - rc.left - 32,wi.cy);
wi.x = (flagDefaultPos == 3) ? 16 : rc.right - wi.cx - 16;
}
else {
// fit window into working area of current monitor
wi.x += (mi.rcWork.left - mi.rcMonitor.left);
wi.y += (mi.rcWork.top - mi.rcMonitor.top);
if (wi.x < mi.rcWork.left)
wi.x = mi.rcWork.left;
if (wi.y < mi.rcWork.top)
wi.y = mi.rcWork.top;
if (wi.x + wi.cx > mi.rcWork.right) {
wi.x -= (wi.x + wi.cx - mi.rcWork.right);
if (wi.x < mi.rcWork.left)
wi.x = mi.rcWork.left;
if (wi.x + wi.cx > mi.rcWork.right)
wi.cx = mi.rcWork.right - wi.x;
}
if (wi.y + wi.cy > mi.rcWork.bottom) {
wi.y -= (wi.y + wi.cy - mi.rcWork.bottom);
if (wi.y < mi.rcWork.top)
wi.y = mi.rcWork.top;
if (wi.y + wi.cy > mi.rcWork.bottom)
wi.cy = mi.rcWork.bottom - wi.y;
}
SetRect(&rc,wi.x,wi.y,wi.x+wi.cx,wi.y+wi.cy);
if (!IntersectRect(&rc2,&rc,&mi.rcWork)) {
wi.y = mi.rcWork.top + 16;
wi.cy = mi.rcWork.bottom - mi.rcWork.top - 32;
wi.cx = min(mi.rcWork.right - mi.rcWork.left - 32,wi.cy);
wi.x = mi.rcWork.right - wi.cx - 16;
}
}
hwndMain = CreateWindowEx(
0,
wchWndClass,
L"Notepad2",
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
wi.x,
wi.y,
wi.cx,
wi.cy,
NULL,
NULL,
hInstance,
NULL);
if (wi.max)
nCmdShow = SW_SHOWMAXIMIZED;
if (bAlwaysOnTop)
SetWindowPos(hwndMain,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
if (bTransparentMode)
SetWindowTransparentMode(hwndMain,TRUE);
// Current file information -- moved in front of ShowWindow()
FileLoad(TRUE,TRUE,FALSE,FALSE,L"");
if (!flagStartAsTrayIcon) {
ShowWindow(hwndMain,nCmdShow);
UpdateWindow(hwndMain);
}
else {
ShowWindow(hwndMain,SW_HIDE); // trick ShowWindow()
ShowNotifyIcon(hwndMain,TRUE);
}
// Source Encoding
if (lpEncodingArg)
iSrcEncoding = Encoding_MatchW(lpEncodingArg);
// Pathname parameter
if (lpFileArg /*&& !flagNewFromClipboard*/)
{
// Open from Directory
if (PathIsDirectory(lpFileArg)) {
WCHAR tchFile[MAX_PATH];
if (OpenFileDlg(hwndMain,tchFile,COUNTOF(tchFile),lpFileArg))
FileLoad(FALSE,FALSE,FALSE,FALSE,tchFile);
}
else {
if (FileLoad(FALSE,FALSE,FALSE,FALSE,lpFileArg)) {
if (flagJumpTo) // Jump to position
EditJumpTo(hwndEdit,iInitialLine,iInitialColumn);
}
}
GlobalFree(lpFileArg);
}
else {
if (iSrcEncoding != -1) {
iEncoding = iSrcEncoding;
iOriginalEncoding = iSrcEncoding;
SendMessage(hwndEdit,SCI_SETCODEPAGE,(iEncoding == CPI_DEFAULT) ? iDefaultCodePage : SC_CP_UTF8,0);
}
}
// reset
iSrcEncoding = -1;
flagQuietCreate = 0;
fKeepTitleExcerpt = 0;
// Check for /c [if no file is specified] -- even if a file is specified
/*else */if (flagNewFromClipboard) {
if (SendMessage(hwndEdit,SCI_CANPASTE,0,0)) {
BOOL bAutoIndent2 = bAutoIndent;
bAutoIndent = 0;
EditJumpTo(hwndEdit,-1,0);
SendMessage(hwndEdit,SCI_BEGINUNDOACTION,0,0);
if (SendMessage(hwndEdit,SCI_GETLENGTH,0,0) > 0)
SendMessage(hwndEdit,SCI_NEWLINE,0,0);
SendMessage(hwndEdit,SCI_PASTE,0,0);
SendMessage(hwndEdit,SCI_NEWLINE,0,0);
SendMessage(hwndEdit,SCI_ENDUNDOACTION,0,0);
bAutoIndent = bAutoIndent2;
}
}
// Encoding
if (0 != flagSetEncoding) {
SendMessage(
hwndMain,
WM_COMMAND,
MAKELONG(IDM_ENCODING_ANSI + flagSetEncoding -1,1),
0);
flagSetEncoding = 0;
}
// EOL mode
if (0 != flagSetEOLMode) {
SendMessage(
hwndMain,
WM_COMMAND,
MAKELONG(IDM_LINEENDINGS_CRLF + flagSetEOLMode -1,1),
0);
flagSetEOLMode = 0;
}
// Match Text
if (flagMatchText && lpMatchArg) {
if (lstrlen(lpMatchArg) && SendMessage(hwndEdit,SCI_GETLENGTH,0,0)) {
UINT cp = SendMessage(hwndEdit,SCI_GETCODEPAGE,0,0);
WideCharToMultiByte(cp,0,lpMatchArg,-1,efrData.szFind,COUNTOF(efrData.szFind),NULL,NULL);
WideCharToMultiByte(CP_UTF8,0,lpMatchArg,-1,efrData.szFindUTF8,COUNTOF(efrData.szFindUTF8),NULL,NULL);
cpLastFind = cp;
if (flagMatchText & 4)
efrData.fuFlags |= SCFIND_REGEXP;
else if (flagMatchText & 8)
efrData.bTransformBS = TRUE;
if (flagMatchText & 2) {
EditJumpTo(hwndEdit,-1,0);
EditFindPrev(hwndEdit,&efrData,FALSE);
}
else {
SendMessage(hwndEdit,SCI_DOCUMENTSTART,0,0);
EditFindNext(hwndEdit,&efrData,FALSE);
}
}
GlobalFree(lpMatchArg);
}
// Check for Paste Board option -- after loading files
if (flagPasteBoard) {
bLastCopyFromMe = TRUE;
hwndNextCBChain = SetClipboardViewer(hwndMain);
uidsAppTitle = IDS_APPTITLE_PASTEBOARD;
SetWindowTitle(hwndMain,uidsAppTitle,fIsElevated,IDS_UNTITLED,szCurFile,
iPathNameFormat,bModified || iEncoding != iOriginalEncoding,
IDS_READONLY,bReadOnly,szTitleExcerpt);
bLastCopyFromMe = FALSE;
dwLastCopyTime = 0;
SetTimer(hwndMain,ID_PASTEBOARDTIMER,100,PasteBoardTimer);
}
// check if a lexer was specified from the command line
if (flagLexerSpecified) {
if (lpSchemeArg) {
Style_SetLexerFromName(hwndEdit,szCurFile,lpSchemeArg);
LocalFree(lpSchemeArg);
}
else if (iInitialLexer >=0 && iInitialLexer < NUMLEXERS)
Style_SetLexerFromID(hwndEdit,iInitialLexer);
flagLexerSpecified = 0;
}
// If start as tray icon, set current filename as tooltip
if (flagStartAsTrayIcon)
SetNotifyIconTitle(hwndMain);
UpdateToolbar();
UpdateStatusbar();
return(hwndMain);
}
//=============================================================================
//
// MainWndProc()
//
// Messages are distributed to the MsgXXX-handlers
//
//
LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
{
static BOOL bShutdownOK;
switch(umsg)
{
// Quickly handle painting and sizing messages, found in ScintillaWin.cxx
// Cool idea, don't know if this has any effect... ;-)
case WM_MOVE:
case WM_MOUSEACTIVATE:
case WM_NCHITTEST:
case WM_NCCALCSIZE:
case WM_NCPAINT:
case WM_PAINT:
case WM_ERASEBKGND:
case WM_NCMOUSEMOVE:
case WM_NCLBUTTONDOWN:
case WM_WINDOWPOSCHANGING:
case WM_WINDOWPOSCHANGED:
return DefWindowProc(hwnd,umsg,wParam,lParam);
case WM_CREATE:
return MsgCreate(hwnd,wParam,lParam);
case WM_DESTROY:
case WM_ENDSESSION:
if (!bShutdownOK) {
WINDOWPLACEMENT wndpl;
// Terminate file watching
InstallFileWatching(NULL);
// GetWindowPlacement
wndpl.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(hwnd,&wndpl);
wi.x = wndpl.rcNormalPosition.left;
wi.y = wndpl.rcNormalPosition.top;
wi.cx = wndpl.rcNormalPosition.right - wndpl.rcNormalPosition.left;
wi.cy = wndpl.rcNormalPosition.bottom - wndpl.rcNormalPosition.top;
wi.max = (IsZoomed(hwnd) || (wndpl.flags & WPF_RESTORETOMAXIMIZED));
DragAcceptFiles(hwnd,FALSE);
// Terminate clipboard watching
if (flagPasteBoard) {
KillTimer(hwnd,ID_PASTEBOARDTIMER);
ChangeClipboardChain(hwnd,hwndNextCBChain);
}
// Destroy find / replace dialog
if (IsWindow(hDlgFindReplace))
DestroyWindow(hDlgFindReplace);
// call SaveSettings() when hwndToolbar is still valid
SaveSettings(FALSE);
if (lstrlen(szIniFile) != 0) {
// Cleanup unwanted MRU's
if (!bSaveRecentFiles) {
MRU_Empty(pFileMRU);
MRU_Save(pFileMRU);
}
else
MRU_MergeSave(pFileMRU,TRUE,flagRelativeFileMRU,flagPortableMyDocs);
MRU_Destroy(pFileMRU);
if (!bSaveFindReplace) {
MRU_Empty(mruFind);
MRU_Empty(mruReplace);
MRU_Save(mruFind);
MRU_Save(mruReplace);
}
else {
MRU_MergeSave(mruFind,FALSE,FALSE,FALSE);
MRU_MergeSave(mruReplace,FALSE,FALSE,FALSE);
}
MRU_Destroy(mruFind);
MRU_Destroy(mruReplace);
}
// Remove tray icon if necessary
ShowNotifyIcon(hwnd,FALSE);
bShutdownOK = TRUE;
}
if (umsg == WM_DESTROY)
PostQuitMessage(0);
break;
case WM_CLOSE:
if (FileSave(FALSE,TRUE,FALSE,FALSE))
DestroyWindow(hwnd);
break;
case WM_QUERYENDSESSION:
if (FileSave(FALSE,TRUE,FALSE,FALSE))
return TRUE;
else
return FALSE;
// Reinitialize theme-dependent values and resize windows
case WM_THEMECHANGED:
MsgThemeChanged(hwnd,wParam,lParam);
break;
// update Scintilla colors
case WM_SYSCOLORCHANGE:
{
extern PEDITLEXER pLexCurrent;
Style_SetLexer(hwndEdit,pLexCurrent);
return DefWindowProc(hwnd,umsg,wParam,lParam);
}
//case WM_TIMER:
// break;
case WM_SIZE:
MsgSize(hwnd,wParam,lParam);
break;
case WM_SETFOCUS:
SetFocus(hwndEdit);
UpdateToolbar();
UpdateStatusbar();
//if (bPendingChangeNotify)
// PostMessage(hwnd,WM_CHANGENOTIFY,0,0);
break;
case WM_DROPFILES:
{
WCHAR szBuf[MAX_PATH+40];
HDROP hDrop = (HDROP)wParam;
// Reset Change Notify
//bPendingChangeNotify = FALSE;
if (IsIconic(hwnd))
ShowWindow(hwnd,SW_RESTORE);
//SetForegroundWindow(hwnd);
DragQueryFile(hDrop,0,szBuf,COUNTOF(szBuf));
if (PathIsDirectory(szBuf)) {
WCHAR tchFile[MAX_PATH];
if (OpenFileDlg(hwndMain,tchFile,COUNTOF(tchFile),szBuf))
FileLoad(FALSE,FALSE,FALSE,FALSE,tchFile);
}
else
FileLoad(FALSE,FALSE,FALSE,FALSE,szBuf);
if (DragQueryFile(hDrop,(UINT)(-1),NULL,0) > 1)
MsgBox(MBINFO,IDS_ERR_DROP);
DragFinish(hDrop);
}
break;
case WM_COPYDATA:
{
PCOPYDATASTRUCT pcds = (PCOPYDATASTRUCT)lParam;
// Reset Change Notify
//bPendingChangeNotify = FALSE;
SetDlgItemInt(hwnd,IDC_REUSELOCK,GetTickCount(),FALSE);
if (pcds->dwData == DATA_NOTEPAD2_PARAMS) {
LPNP2PARAMS params = LocalAlloc(LPTR,pcds->cbData);
CopyMemory(params,pcds->lpData,pcds->cbData);
if (params->flagLexerSpecified)
flagLexerSpecified = 1;
if (params->flagQuietCreate)
flagQuietCreate = 1;
if (params->flagFileSpecified) {
BOOL bOpened = FALSE;
iSrcEncoding = params->iSrcEncoding;
if (PathIsDirectory(&params->wchData)) {
WCHAR tchFile[MAX_PATH];
if (OpenFileDlg(hwndMain,tchFile,COUNTOF(tchFile),&params->wchData))
bOpened = FileLoad(FALSE,FALSE,FALSE,FALSE,tchFile);
}
else
bOpened = FileLoad(FALSE,FALSE,FALSE,FALSE,&params->wchData);
if (bOpened) {
if (0 != params->flagSetEncoding) {
flagSetEncoding = params->flagSetEncoding;
SendMessage(
hwnd,
WM_COMMAND,
MAKELONG(IDM_ENCODING_ANSI + flagSetEncoding -1,1),
0);
flagSetEncoding = 0;
}
if (0 != params->flagSetEOLMode) {
flagSetEOLMode = params->flagSetEOLMode;
SendMessage(
hwndMain,
WM_COMMAND,
MAKELONG(IDM_LINEENDINGS_CRLF + flagSetEOLMode -1,1),
0);
flagSetEOLMode = 0;
}
if (params->flagLexerSpecified) {
if (params->iInitialLexer < 0) {
WCHAR wchExt[32] = L".";
lstrcpyn(CharNext(wchExt),StrEnd(&params->wchData)+1,30);
Style_SetLexerFromName(hwndEdit,&params->wchData,wchExt);
}
else if (params->iInitialLexer >=0 && params->iInitialLexer < NUMLEXERS)
Style_SetLexerFromID(hwndEdit,params->iInitialLexer);
}
if (params->flagTitleExcerpt) {
lstrcpyn(szTitleExcerpt,StrEnd(&params->wchData)+1,COUNTOF(szTitleExcerpt));
SetWindowTitle(hwnd,uidsAppTitle,fIsElevated,IDS_UNTITLED,szCurFile,
iPathNameFormat,bModified || iEncoding != iOriginalEncoding,
IDS_READONLY,bReadOnly,szTitleExcerpt);
}
}
// reset
iSrcEncoding = -1;
}
if (params->flagJumpTo) {
if (params->iInitialLine == 0)
params->iInitialLine = 1;
EditJumpTo(hwndEdit,params->iInitialLine,params->iInitialColumn);
}
flagLexerSpecified = 0;
flagQuietCreate = 0;
LocalFree(params);
UpdateStatusbar();
}
}
return TRUE;
case WM_CONTEXTMENU:
{
HMENU hmenu;
int imenu = 0;
POINT pt;
int nID = GetDlgCtrlID((HWND)wParam);
if ((nID != IDC_EDIT) && (nID != IDC_STATUSBAR) &&
(nID != IDC_REBAR) && (nID != IDC_TOOLBAR))
return DefWindowProc(hwnd,umsg,wParam,lParam);
hmenu = LoadMenu(g_hInstance,MAKEINTRESOURCE(IDR_POPUPMENU));
//SetMenuDefaultItem(GetSubMenu(hmenu,1),0,FALSE);
pt.x = (int)(short)LOWORD(lParam);
pt.y = (int)(short)HIWORD(lParam);
switch(nID)
{
case IDC_EDIT:
{
int iSelStart = SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0);
int iSelEnd = SendMessage(hwndEdit,SCI_GETSELECTIONEND,0,0);
if (iSelStart == iSelEnd && pt.x != -1 && pt.y != -1)
{
int iNewPos;
POINT ptc = { pt.x, pt.y };
ScreenToClient(hwndEdit,&ptc);
iNewPos = SendMessage(hwndEdit,SCI_POSITIONFROMPOINT,(WPARAM)ptc.x,(LPARAM)ptc.y);
SendMessage(hwndEdit,SCI_GOTOPOS,(WPARAM)iNewPos,0);
}
if (pt.x == -1 && pt.y == -1)
{
int iCurrentPos = SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0);
pt.x = SendMessage(hwndEdit,SCI_POINTXFROMPOSITION,0,(LPARAM)iCurrentPos);
pt.y = SendMessage(hwndEdit,SCI_POINTYFROMPOSITION,0,(LPARAM)iCurrentPos);
ClientToScreen(hwndEdit,&pt);
}
imenu = 0;
}
break;
case IDC_TOOLBAR:
case IDC_STATUSBAR:
case IDC_REBAR:
if (pt.x == -1 && pt.y == -1)
GetCursorPos(&pt);
imenu = 1;
break;
}
TrackPopupMenuEx(GetSubMenu(hmenu,imenu),
TPM_LEFTBUTTON | TPM_RIGHTBUTTON,pt.x+1,pt.y+1,hwnd,NULL);
DestroyMenu(hmenu);
}
break;
case WM_INITMENU:
MsgInitMenu(hwnd,wParam,lParam);
break;
case WM_NOTIFY:
return MsgNotify(hwnd,wParam,lParam);
case WM_COMMAND:
return MsgCommand(hwnd,wParam,lParam);
case WM_SYSCOMMAND:
switch (wParam)
{
case SC_MINIMIZE:
ShowOwnedPopups(hwnd,FALSE);
if (bMinimizeToTray) {
MinimizeWndToTray(hwnd);
ShowNotifyIcon(hwnd,TRUE);
SetNotifyIconTitle(hwnd);
return(0);
}
else
return DefWindowProc(hwnd,umsg,wParam,lParam);
case SC_RESTORE: {
LRESULT lrv = DefWindowProc(hwnd,umsg,wParam,lParam);
ShowOwnedPopups(hwnd,TRUE);
return(lrv);
}
}
return DefWindowProc(hwnd,umsg,wParam,lParam);
case WM_CHANGENOTIFY:
if (iFileWatchingMode == 1 || bModified || iEncoding != iOriginalEncoding)
SetForegroundWindow(hwnd);
if (PathFileExists(szCurFile)) {
if ((iFileWatchingMode == 2 && !bModified && iEncoding == iOriginalEncoding) ||
MsgBox(MBYESNO,IDS_FILECHANGENOTIFY) == IDYES) {
int iCurPos = SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0);
int iAnchorPos = SendMessage(hwndEdit,SCI_GETANCHOR,0,0);
int iCurTopLine = SendMessage(hwndEdit,SCI_GETFIRSTVISIBLELINE,0,0);
int iXOffset = SendMessage(hwndEdit,SCI_GETXOFFSET,0,0);
BOOL bIsTail = (iCurPos == iAnchorPos) && (iCurPos == SendMessage(hwndEdit,SCI_GETLENGTH,0,0));
iWeakSrcEncoding = iEncoding;
if (FileLoad(TRUE,FALSE,TRUE,FALSE,szCurFile)) {
if (bIsTail && iFileWatchingMode == 2)
EditJumpTo(hwndEdit,-1,0);
else if (SendMessage(hwndEdit,SCI_GETLENGTH,0,0) >= 4) {
char tch[5] = "";
SendMessage(hwndEdit,SCI_GETTEXT,5,(LPARAM)tch);
if (lstrcmpiA(tch,".LOG") != 0) {
int iTopLineAfterLoad;
SendMessage(hwndEdit,SCI_SETSEL,(WPARAM)iAnchorPos,(LPARAM)iCurPos);
iTopLineAfterLoad = SendMessage(hwndEdit,SCI_GETFIRSTVISIBLELINE,0,0);
SendMessage(hwndEdit,SCI_LINESCROLL,0,(LPARAM)(iCurTopLine - iTopLineAfterLoad));
SendMessage(hwndEdit,SCI_SETXOFFSET,(WPARAM)iXOffset,0);
}
}
}
}
}
else {
if (MsgBox(MBYESNO,IDS_FILECHANGENOTIFY2) == IDYES)
FileSave(TRUE,FALSE,FALSE,FALSE);
}
if (!bRunningWatch)
InstallFileWatching(szCurFile);
break;
//// This message is posted before Notepad2 reactivates itself
//case WM_CHANGENOTIFYCLEAR:
// bPendingChangeNotify = FALSE;
// break;
case WM_DRAWCLIPBOARD:
if (!bLastCopyFromMe)
dwLastCopyTime = GetTickCount();
else
bLastCopyFromMe = FALSE;
if (hwndNextCBChain)
SendMessage(hwndNextCBChain,WM_DRAWCLIPBOARD,wParam,lParam);
break;
case WM_CHANGECBCHAIN:
if ((HWND)wParam == hwndNextCBChain)
hwndNextCBChain = (HWND)lParam;
if (hwndNextCBChain)
SendMessage(hwndNextCBChain,WM_CHANGECBCHAIN,lParam,wParam);
break;
case WM_TRAYMESSAGE:
switch(lParam)
{
case WM_RBUTTONUP: {
HMENU hMenu = LoadMenu(g_hInstance,MAKEINTRESOURCE(IDR_POPUPMENU));
HMENU hMenuPopup = GetSubMenu(hMenu,2);
POINT pt;
int iCmd;
SetForegroundWindow(hwnd);
GetCursorPos(&pt);
SetMenuDefaultItem(hMenuPopup,IDM_TRAY_RESTORE,FALSE);
iCmd = TrackPopupMenu(hMenuPopup,
TPM_NONOTIFY|TPM_RETURNCMD|TPM_LEFTBUTTON|TPM_RIGHTBUTTON,
pt.x,pt.y,0,hwnd,NULL);
PostMessage(hwnd,WM_NULL,0,0);
DestroyMenu(hMenu);
if (iCmd == IDM_TRAY_RESTORE) {
ShowNotifyIcon(hwnd,FALSE);
RestoreWndFromTray(hwnd);
ShowOwnedPopups(hwnd,TRUE);
}
else if (iCmd == IDM_TRAY_EXIT) {
//ShowNotifyIcon(hwnd,FALSE);
SendMessage(hwnd,WM_CLOSE,0,0);
}
}
return TRUE;
case WM_LBUTTONUP:
ShowNotifyIcon(hwnd,FALSE);
RestoreWndFromTray(hwnd);
ShowOwnedPopups(hwnd,TRUE);
return TRUE;
}
break;
default:
if (umsg == msgTaskbarCreated) {
if (!IsWindowVisible(hwnd))
ShowNotifyIcon(hwnd,TRUE);
SetNotifyIconTitle(hwnd);
return(0);
}
return DefWindowProc(hwnd,umsg,wParam,lParam);
}
return(0);
}
//=============================================================================
//
// MsgCreate() - Handles WM_CREATE
//
//
LRESULT MsgCreate(HWND hwnd,WPARAM wParam,LPARAM lParam)
{
HINSTANCE hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
// Setup edit control
hwndEdit = EditCreate(hwnd);
InitScintillaHandle(hwndEdit);
// Tabs
SendMessage(hwndEdit,SCI_SETUSETABS,!bTabsAsSpaces,0);
SendMessage(hwndEdit,SCI_SETTABINDENTS,bTabIndents,0);
SendMessage(hwndEdit,SCI_SETTABWIDTH,iTabWidth,0);
SendMessage(hwndEdit,SCI_SETINDENT,iIndentWidth,0);
// Indent Guides
Style_SetIndentGuides(hwndEdit,bShowIndentGuides);
// Word wrap
if (!fWordWrap)
SendMessage(hwndEdit,SCI_SETWRAPMODE,SC_WRAP_NONE,0);
else
SendMessage(hwndEdit,SCI_SETWRAPMODE,(iWordWrapMode == 0) ? SC_WRAP_WORD : SC_WRAP_CHAR,0);
if (iWordWrapIndent == 5)
SendMessage(hwndEdit,SCI_SETWRAPINDENTMODE,SC_WRAPINDENT_SAME,0);
else if (iWordWrapIndent == 6)
SendMessage(hwndEdit,SCI_SETWRAPINDENTMODE,SC_WRAPINDENT_INDENT,0);
else {
int i = 0;
switch (iWordWrapIndent) {
case 1: i = 1; break;
case 2: i = 2; break;
case 3: i = (iIndentWidth) ? 1 * iIndentWidth : 1 * iTabWidth; break;
case 4: i = (iIndentWidth) ? 2 * iIndentWidth : 2 * iTabWidth; break;
}
SendMessage(hwndEdit,SCI_SETWRAPSTARTINDENT,i,0);
SendMessage(hwndEdit,SCI_SETWRAPINDENTMODE,SC_WRAPINDENT_FIXED,0);
}
if (bShowWordWrapSymbols) {
int wrapVisualFlags = 0;
int wrapVisualFlagsLocation = 0;
if (iWordWrapSymbols == 0)
iWordWrapSymbols = 22;
switch (iWordWrapSymbols%10) {
case 1: wrapVisualFlags |= SC_WRAPVISUALFLAG_END; wrapVisualFlagsLocation |= SC_WRAPVISUALFLAGLOC_END_BY_TEXT; break;
case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_END; break;
}
switch (((iWordWrapSymbols%100)-(iWordWrapSymbols%10))/10) {
case 1: wrapVisualFlags |= SC_WRAPVISUALFLAG_START; wrapVisualFlagsLocation |= SC_WRAPVISUALFLAGLOC_START_BY_TEXT; break;
case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_START; break;
}
SendMessage(hwndEdit,SCI_SETWRAPVISUALFLAGSLOCATION,wrapVisualFlagsLocation,0);
SendMessage(hwndEdit,SCI_SETWRAPVISUALFLAGS,wrapVisualFlags,0);
}
else {
SendMessage(hwndEdit,SCI_SETWRAPVISUALFLAGS,0,0);
}
// Long Lines
if (bMarkLongLines)
SendMessage(hwndEdit,SCI_SETEDGEMODE,(iLongLineMode == EDGE_LINE)?EDGE_LINE:EDGE_BACKGROUND,0);
else
SendMessage(hwndEdit,SCI_SETEDGEMODE,EDGE_NONE,0);
SendMessage(hwndEdit,SCI_SETEDGECOLUMN,iLongLinesLimit,0);
// Margins
SendMessage(hwndEdit,SCI_SETMARGINWIDTHN,2,0);
SendMessage(hwndEdit,SCI_SETMARGINWIDTHN,1,(bShowSelectionMargin)?16:0);
UpdateLineNumberWidth();
//SendMessage(hwndEdit,SCI_SETMARGINWIDTHN,0,
// (bShowLineNumbers)?SendMessage(hwndEdit,SCI_TEXTWIDTH,STYLE_LINENUMBER,(LPARAM)L"_999999_"):0);
// Code folding
SciCall_SetMarginType(MARGIN_FOLD_INDEX, SC_MARGIN_SYMBOL);
SciCall_SetMarginMask(MARGIN_FOLD_INDEX, SC_MASK_FOLDERS);
SciCall_SetMarginWidth(MARGIN_FOLD_INDEX, (bShowCodeFolding) ? 11 : 0);
SciCall_SetMarginSensitive(MARGIN_FOLD_INDEX, TRUE);
SciCall_SetProperty("fold", "1");
SciCall_SetProperty("fold.compact", "0");
SciCall_SetProperty("fold.comment", "1");
SciCall_SetProperty("fold.html", "1");
SciCall_SetProperty("fold.preprocessor", "1");
SciCall_MarkerDefine(SC_MARKNUM_FOLDEROPEN, SC_MARK_BOXMINUS);
SciCall_MarkerDefine(SC_MARKNUM_FOLDER, SC_MARK_BOXPLUS);
SciCall_MarkerDefine(SC_MARKNUM_FOLDERSUB, SC_MARK_VLINE);
SciCall_MarkerDefine(SC_MARKNUM_FOLDERTAIL, SC_MARK_LCORNER);
SciCall_MarkerDefine(SC_MARKNUM_FOLDEREND, SC_MARK_BOXPLUSCONNECTED);
SciCall_MarkerDefine(SC_MARKNUM_FOLDEROPENMID, SC_MARK_BOXMINUSCONNECTED);
SciCall_MarkerDefine(SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_TCORNER);
SciCall_SetFoldFlags(16);
// Nonprinting characters
SendMessage(hwndEdit,SCI_SETVIEWWS,(bViewWhiteSpace)?SCWS_VISIBLEALWAYS:SCWS_INVISIBLE,0);
SendMessage(hwndEdit,SCI_SETVIEWEOL,bViewEOLs,0);
hwndEditFrame = CreateWindowEx(
WS_EX_CLIENTEDGE,
WC_LISTVIEW,
NULL,
WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,
0,0,100,100,
hwnd,
(HMENU)IDC_EDITFRAME,
hInstance,
NULL);
if (PrivateIsAppThemed()) {
RECT rc, rc2;
bIsAppThemed = TRUE;
SetWindowLongPtr(hwndEdit,GWL_EXSTYLE,GetWindowLongPtr(hwndEdit,GWL_EXSTYLE) & ~WS_EX_CLIENTEDGE);
SetWindowPos(hwndEdit,NULL,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);
if (IsVista()) {
cxEditFrame = 0;
cyEditFrame = 0;
}
else {
GetClientRect(hwndEditFrame,&rc);
GetWindowRect(hwndEditFrame,&rc2);
cxEditFrame = ((rc2.right-rc2.left) - (rc.right-rc.left)) / 2;
cyEditFrame = ((rc2.bottom-rc2.top) - (rc.bottom-rc.top)) / 2;
}
}
else {
bIsAppThemed = FALSE;
cxEditFrame = 0;
cyEditFrame = 0;
}
// Create Toolbar and Statusbar
CreateBars(hwnd,hInstance);
// Window Initialization
CreateWindow(
WC_STATIC,
NULL,
WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,
0,0,10,10,
hwnd,
(HMENU)IDC_FILENAME,
hInstance,
NULL);
SetDlgItemText(hwnd,IDC_FILENAME,szCurFile);
CreateWindow(
WC_STATIC,
NULL,
WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,
10,10,10,10,
hwnd,
(HMENU)IDC_REUSELOCK,
hInstance,
NULL);
SetDlgItemInt(hwnd,IDC_REUSELOCK,GetTickCount(),FALSE);
// Menu
//SetMenuDefaultItem(GetSubMenu(GetMenu(hwnd),0),0);
// Drag & Drop
DragAcceptFiles(hwnd,TRUE);
// File MRU
pFileMRU = MRU_Create(L"Recent Files",MRU_NOCASE,32);
MRU_Load(pFileMRU);
mruFind = MRU_Create(L"Recent Find",(/*IsWindowsNT()*/1) ? MRU_UTF8 : 0,16);
MRU_Load(mruFind);
mruReplace = MRU_Create(L"Recent Replace",(/*IsWindowsNT()*/1) ? MRU_UTF8 : 0,16);
MRU_Load(mruReplace);
if (hwndEdit == NULL || hwndEditFrame == NULL ||
hwndStatus == NULL || hwndToolbar == NULL || hwndReBar == NULL)
return(-1);
return(0);
}
//=============================================================================
//
// CreateBars() - Create Toolbar and Statusbar
//
//
void CreateBars(HWND hwnd,HINSTANCE hInstance)
{
RECT rc;
REBARINFO rbi;
REBARBANDINFO rbBand;
BITMAP bmp;
HBITMAP hbmp;
HIMAGELIST himl;
WCHAR szTmp[MAX_PATH];
BOOL bExternalBitmap = TRUE;
DWORD dwToolbarStyle = WS_TOOLBAR;
DWORD dwStatusbarStyle = WS_CHILD | WS_CLIPSIBLINGS;
DWORD dwReBarStyle = WS_REBAR;
BOOL bIsAppThemed = PrivateIsAppThemed();
int i,n;
WCHAR tchDesc[256];
WCHAR tchIndex[256];
WCHAR *pIniSection = NULL;
int cchIniSection = 0;
if (bShowToolbar)
dwReBarStyle |= WS_VISIBLE;
hwndToolbar = CreateWindowEx(0,TOOLBARCLASSNAME,NULL,dwToolbarStyle,
0,0,0,0,hwnd,(HMENU)IDC_TOOLBAR,hInstance,NULL);
SendMessage(hwndToolbar,TB_BUTTONSTRUCTSIZE,(WPARAM)sizeof(TBBUTTON),0);
// Add normal Toolbar Bitmap
hbmp = NULL;
if (lstrlen(tchToolbarBitmap))
{
if (!SearchPath(NULL,tchToolbarBitmap,NULL,COUNTOF(szTmp),szTmp,NULL))
lstrcpy(szTmp,tchToolbarBitmap);
hbmp = LoadImage(NULL,szTmp,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);
}
if (!hbmp) {
hbmp = LoadImage(hInstance,MAKEINTRESOURCE(IDR_MAINWND),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);
bExternalBitmap = FALSE;
}
GetObject(hbmp,sizeof(BITMAP),&bmp);
himl = ImageList_Create(bmp.bmWidth/NUMTOOLBITMAPS,bmp.bmHeight,ILC_COLOR32|ILC_MASK,0,0);
ImageList_AddMasked(himl,hbmp,CLR_DEFAULT);
DeleteObject(hbmp);
SendMessage(hwndToolbar,TB_SETIMAGELIST,0,(LPARAM)himl);
// Optionally add hot Toolbar Bitmap
hbmp = NULL;
if (lstrlen(tchToolbarBitmapHot))
{
if (!SearchPath(NULL,tchToolbarBitmapHot,NULL,COUNTOF(szTmp),szTmp,NULL))
lstrcpy(szTmp,tchToolbarBitmapHot);
if (hbmp = LoadImage(NULL,szTmp,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE))
{
GetObject(hbmp,sizeof(BITMAP),&bmp);
himl = ImageList_Create(bmp.bmWidth/NUMTOOLBITMAPS,bmp.bmHeight,ILC_COLOR32|ILC_MASK,0,0);
ImageList_AddMasked(himl,hbmp,CLR_DEFAULT);
DeleteObject(hbmp);
SendMessage(hwndToolbar,TB_SETHOTIMAGELIST,0,(LPARAM)himl);
}
}
// Optionally add disabled Toolbar Bitmap
hbmp = NULL;
if (lstrlen(tchToolbarBitmapDisabled))
{
if (!SearchPath(NULL,tchToolbarBitmapDisabled,NULL,COUNTOF(szTmp),szTmp,NULL))
lstrcpy(szTmp,tchToolbarBitmapDisabled);
if (hbmp = LoadImage(NULL,szTmp,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE))
{
GetObject(hbmp,sizeof(BITMAP),&bmp);
himl = ImageList_Create(bmp.bmWidth/NUMTOOLBITMAPS,bmp.bmHeight,ILC_COLOR32|ILC_MASK,0,0);
ImageList_AddMasked(himl,hbmp,CLR_DEFAULT);
DeleteObject(hbmp);
SendMessage(hwndToolbar,TB_SETDISABLEDIMAGELIST,0,(LPARAM)himl);
}
}
// Load toolbar labels
pIniSection = LocalAlloc(LPTR,sizeof(WCHAR)*32*1024);
cchIniSection = LocalSize(pIniSection)/sizeof(WCHAR);
LoadIniSection(L"Toolbar Labels",pIniSection,cchIniSection);
n = 1;
for (i = 0; i < COUNTOF(tbbMainWnd); i++) {
if (tbbMainWnd[i].fsStyle == TBSTYLE_SEP)
continue;
wsprintf(tchIndex,L"%02i",n++);
if (IniSectionGetString(pIniSection,tchIndex,L"",tchDesc,COUNTOF(tchDesc))) {
tbbMainWnd[i].iString = SendMessage(hwndToolbar,TB_ADDSTRING,0,(LPARAM)tchDesc);
tbbMainWnd[i].fsStyle |= BTNS_AUTOSIZE | BTNS_SHOWTEXT;
}
else
tbbMainWnd[i].fsStyle &= ~(BTNS_AUTOSIZE | BTNS_SHOWTEXT);
}
LocalFree(pIniSection);
SendMessage(hwndToolbar,TB_SETEXTENDEDSTYLE,0,
SendMessage(hwndToolbar,TB_GETEXTENDEDSTYLE,0,0) | TBSTYLE_EX_MIXEDBUTTONS);
SendMessage(hwndToolbar,TB_ADDBUTTONS,NUMINITIALTOOLS,(LPARAM)tbbMainWnd);
if (Toolbar_SetButtons(hwndToolbar,IDT_FILE_NEW,tchToolbarButtons,tbbMainWnd,COUNTOF(tbbMainWnd)) == 0)
SendMessage(hwndToolbar,TB_ADDBUTTONS,NUMINITIALTOOLS,(LPARAM)tbbMainWnd);
SendMessage(hwndToolbar,TB_GETITEMRECT,0,(LPARAM)&rc);
//SendMessage(hwndToolbar,TB_SETINDENT,2,0);
if (bShowStatusbar)
dwStatusbarStyle |= WS_VISIBLE;
hwndStatus = CreateStatusWindow(dwStatusbarStyle,NULL,hwnd,IDC_STATUSBAR);
// Create ReBar and add Toolbar
hwndReBar = CreateWindowEx(WS_EX_TOOLWINDOW,REBARCLASSNAME,NULL,dwReBarStyle,
0,0,0,0,hwnd,(HMENU)IDC_REBAR,hInstance,NULL);
rbi.cbSize = sizeof(REBARINFO);
rbi.fMask = 0;
rbi.himl = (HIMAGELIST)NULL;
SendMessage(hwndReBar,RB_SETBARINFO,0,(LPARAM)&rbi);
rbBand.cbSize = sizeof(REBARBANDINFO);
rbBand.fMask = /*RBBIM_COLORS | RBBIM_TEXT | RBBIM_BACKGROUND | */
RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE /*| RBBIM_SIZE*/;
rbBand.fStyle = /*RBBS_CHILDEDGE |*//* RBBS_BREAK |*/ RBBS_FIXEDSIZE /*| RBBS_GRIPPERALWAYS*/;
if (bIsAppThemed)
rbBand.fStyle |= RBBS_CHILDEDGE;
rbBand.hbmBack = NULL;
rbBand.lpText = L"Toolbar";
rbBand.hwndChild = hwndToolbar;
rbBand.cxMinChild = (rc.right - rc.left) * COUNTOF(tbbMainWnd);
rbBand.cyMinChild = (rc.bottom - rc.top) + 2 * rc.top;
rbBand.cx = 0;
SendMessage(hwndReBar,RB_INSERTBAND,(WPARAM)-1,(LPARAM)&rbBand);
SetWindowPos(hwndReBar,NULL,0,0,0,0,SWP_NOZORDER);
GetWindowRect(hwndReBar,&rc);
cyReBar = rc.bottom - rc.top;
cyReBarFrame = bIsAppThemed ? 0 : 2;
}
//=============================================================================
//
// MsgThemeChanged() - Handle WM_THEMECHANGED
//
//
void MsgThemeChanged(HWND hwnd,WPARAM wParam,LPARAM lParam)
{
RECT rc, rc2;
HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtr(hwnd,GWLP_HINSTANCE);
// reinitialize edit frame
if (PrivateIsAppThemed()) {
bIsAppThemed = TRUE;
SetWindowLongPtr(hwndEdit,GWL_EXSTYLE,GetWindowLongPtr(hwndEdit,GWL_EXSTYLE) & ~WS_EX_CLIENTEDGE);
SetWindowPos(hwndEdit,NULL,0,0,0,0,SWP_NOZORDER|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE);
if (IsVista()) {
cxEditFrame = 0;
cyEditFrame = 0;
}
else {
SetWindowPos(hwndEditFrame,NULL,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);
GetClientRect(hwndEditFrame,&rc);
GetWindowRect(hwndEditFrame,&rc2);
cxEditFrame = ((rc2.right-rc2.left) - (rc.right-rc.left)) / 2;
cyEditFrame = ((rc2.bottom-rc2.top) - (rc.bottom-rc.top)) / 2;
}
}
else {
bIsAppThemed = FALSE;
SetWindowLongPtr(hwndEdit,GWL_EXSTYLE,WS_EX_CLIENTEDGE|GetWindowLongPtr(hwndEdit,GWL_EXSTYLE));
SetWindowPos(hwndEdit,NULL,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);
cxEditFrame = 0;
cyEditFrame = 0;
}
// recreate toolbar and statusbar
Toolbar_GetButtons(hwndToolbar,IDT_FILE_NEW,tchToolbarButtons,COUNTOF(tchToolbarButtons));
DestroyWindow(hwndToolbar);
DestroyWindow(hwndReBar);
DestroyWindow(hwndStatus);
CreateBars(hwnd,hInstance);
UpdateToolbar();
GetClientRect(hwnd,&rc);
SendMessage(hwnd,WM_SIZE,SIZE_RESTORED,MAKELONG(rc.right,rc.bottom));
UpdateStatusbar();
}
//=============================================================================
//
// MsgSize() - Handles WM_SIZE
//
//
void MsgSize(HWND hwnd,WPARAM wParam,LPARAM lParam)
{
RECT rc;
int x,y,cx,cy;
HDWP hdwp;
// Statusbar
int aWidth[6];
if (wParam == SIZE_MINIMIZED)
return;
x = 0;
y = 0;
cx = LOWORD(lParam);
cy = HIWORD(lParam);
if (bShowToolbar)
{
/* SendMessage(hwndToolbar,WM_SIZE,0,0);
GetWindowRect(hwndToolbar,&rc);
y = (rc.bottom - rc.top);
cy -= (rc.bottom - rc.top);*/
//SendMessage(hwndToolbar,TB_GETITEMRECT,0,(LPARAM)&rc);
SetWindowPos(hwndReBar,NULL,0,0,LOWORD(lParam),cyReBar,SWP_NOZORDER);
// the ReBar automatically sets the correct height
// calling SetWindowPos() with the height of one toolbar button
// causes the control not to temporarily use the whole client area
// and prevents flickering
//GetWindowRect(hwndReBar,&rc);
y = cyReBar + cyReBarFrame; // define
cy -= cyReBar + cyReBarFrame; // border
}
if (bShowStatusbar)
{
SendMessage(hwndStatus,WM_SIZE,0,0);
GetWindowRect(hwndStatus,&rc);
cy -= (rc.bottom - rc.top);
}
hdwp = BeginDeferWindowPos(2);
DeferWindowPos(hdwp,hwndEditFrame,NULL,x,y,cx,cy,
SWP_NOZORDER | SWP_NOACTIVATE);
DeferWindowPos(hdwp,hwndEdit,NULL,x+cxEditFrame,y+cyEditFrame,
cx-2*cxEditFrame,cy-2*cyEditFrame,
SWP_NOZORDER | SWP_NOACTIVATE);
EndDeferWindowPos(hdwp);
// Statusbar width
aWidth[0] = max(120,min(cx/3,StatusCalcPaneWidth(hwndStatus,L"Ln 9'999'999 : 9'999'999 Col 9'999'999 : 999 Sel 9'999'999")));
aWidth[1] = aWidth[0] + StatusCalcPaneWidth(hwndStatus,L"9'999'999 Bytes");
aWidth[2] = aWidth[1] + StatusCalcPaneWidth(hwndStatus,L"Unicode BE BOM");
aWidth[3] = aWidth[2] + StatusCalcPaneWidth(hwndStatus,L"CR+LF");
aWidth[4] = aWidth[3] + StatusCalcPaneWidth(hwndStatus,L"OVR");
aWidth[5] = -1;
SendMessage(hwndStatus,SB_SETPARTS,COUNTOF(aWidth),(LPARAM)aWidth);
//UpdateStatusbar();
}
//=============================================================================
//
// MsgInitMenu() - Handles WM_INITMENU
//
//
void MsgInitMenu(HWND hwnd,WPARAM wParam,LPARAM lParam)
{
int i,i2;
HMENU hmenu = (HMENU)wParam;
i = lstrlen(szCurFile);
EnableCmd(hmenu,IDM_FILE_REVERT,i);
EnableCmd(hmenu,IDM_FILE_LAUNCH,i);
EnableCmd(hmenu,IDM_FILE_PROPERTIES,i);
EnableCmd(hmenu,IDM_FILE_CREATELINK,i);
EnableCmd(hmenu,IDM_FILE_ADDTOFAV,i);
EnableCmd(hmenu,IDM_FILE_READONLY,i);
CheckCmd(hmenu,IDM_FILE_READONLY,bReadOnly);
//EnableCmd(hmenu,IDM_ENCODING_UNICODEREV,!bReadOnly);
//EnableCmd(hmenu,IDM_ENCODING_UNICODE,!bReadOnly);
//EnableCmd(hmenu,IDM_ENCODING_UTF8SIGN,!bReadOnly);
//EnableCmd(hmenu,IDM_ENCODING_UTF8,!bReadOnly);
//EnableCmd(hmenu,IDM_ENCODING_ANSI,!bReadOnly);
//EnableCmd(hmenu,IDM_LINEENDINGS_CRLF,!bReadOnly);
//EnableCmd(hmenu,IDM_LINEENDINGS_LF,!bReadOnly);
//EnableCmd(hmenu,IDM_LINEENDINGS_CR,!bReadOnly);
EnableCmd(hmenu,IDM_ENCODING_RECODE,i);
if (mEncoding[iEncoding].uFlags & NCP_UNICODE_REVERSE)
i = IDM_ENCODING_UNICODEREV;
else if (mEncoding[iEncoding].uFlags & NCP_UNICODE)
i = IDM_ENCODING_UNICODE;
else if (mEncoding[iEncoding].uFlags & NCP_UTF8_SIGN)
i = IDM_ENCODING_UTF8SIGN;
else if (mEncoding[iEncoding].uFlags & NCP_UTF8)
i = IDM_ENCODING_UTF8;
else if (mEncoding[iEncoding].uFlags & NCP_DEFAULT)
i = IDM_ENCODING_ANSI;
else
i = -1;
CheckMenuRadioItem(hmenu,IDM_ENCODING_ANSI,IDM_ENCODING_UTF8SIGN,i,MF_BYCOMMAND);
if (iEOLMode == SC_EOL_CRLF)
i = IDM_LINEENDINGS_CRLF;
else if (iEOLMode == SC_EOL_LF)
i = IDM_LINEENDINGS_LF;
else
i = IDM_LINEENDINGS_CR;
CheckMenuRadioItem(hmenu,IDM_LINEENDINGS_CRLF,IDM_LINEENDINGS_CR,i,MF_BYCOMMAND);
EnableCmd(hmenu,IDM_FILE_RECENT,(MRU_Enum(pFileMRU,0,NULL,0) > 0));
EnableCmd(hmenu,IDM_EDIT_UNDO,SendMessage(hwndEdit,SCI_CANUNDO,0,0) /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_REDO,SendMessage(hwndEdit,SCI_CANREDO,0,0) /*&& !bReadOnly*/);
i = SendMessage(hwndEdit,SCI_GETSELECTIONEND,0,0) - SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0);
i2 = SendMessage(hwndEdit,SCI_CANPASTE,0,0);
EnableCmd(hmenu,IDM_EDIT_CUT,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_COPY,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_COPYALL,SendMessage(hwndEdit,SCI_GETLENGTH,0,0) /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_COPYADD,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_PASTE,i2 /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_SWAP,i || i2 /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_CLEAR,i /*&& !bReadOnly*/);
OpenClipboard(hwnd);
EnableCmd(hmenu,IDM_EDIT_CLEARCLIPBOARD,CountClipboardFormats());
CloseClipboard();
//EnableCmd(hmenu,IDM_EDIT_MOVELINEUP,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_MOVELINEDOWN,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_DUPLICATELINE,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_CUTLINE,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_COPYLINE,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_DELETELINE,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_INDENT,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_UNINDENT,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_PADWITHSPACES,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_STRIP1STCHAR,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_STRIPLASTCHAR,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_TRIMLINES,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_REMOVEBLANKLINES,!bReadOnly);
EnableCmd(hmenu,IDM_EDIT_SORTLINES,
SendMessage(hwndEdit,SCI_LINEFROMPOSITION,(WPARAM)SendMessage(hwndEdit,SCI_GETSELECTIONEND,0,0),0) -
SendMessage(hwndEdit,SCI_LINEFROMPOSITION,(WPARAM)SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0),0) >= 1);
EnableCmd(hmenu,IDM_EDIT_COLUMNWRAP,i /*&& IsWindowsNT()*/);
EnableCmd(hmenu,IDM_EDIT_SPLITLINES,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_JOINLINES,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_JOINLINESEX,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_CONVERTUPPERCASE,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_CONVERTLOWERCASE,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_INVERTCASE,i /*&& !bReadOnly*/ /*&& IsWindowsNT()*/);
EnableCmd(hmenu,IDM_EDIT_TITLECASE,i /*&& !bReadOnly*/ /*&& IsWindowsNT()*/);
EnableCmd(hmenu,IDM_EDIT_SENTENCECASE,i /*&& !bReadOnly*/ /*&& IsWindowsNT()*/);
EnableCmd(hmenu,IDM_EDIT_CONVERTTABS,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_CONVERTSPACES,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_CONVERTTABS2,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_CONVERTSPACES2,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_URLENCODE,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_URLDECODE,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_ESCAPECCHARS,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_EDIT_UNESCAPECCHARS,i /*&& !bReadOnly*/);
//EnableCmd(hmenu,IDM_EDIT_INCREASENUM,i /*&& !bReadOnly*/);
//EnableCmd(hmenu,IDM_EDIT_DECREASENUM,i /*&& !bReadOnly*/);
EnableCmd(hmenu,IDM_VIEW_SHOWEXCERPT,i);
i = SendMessage(hwndEdit,SCI_GETLEXER,0,0);
EnableCmd(hmenu,IDM_EDIT_LINECOMMENT,
!(i == SCLEX_NULL || i == SCLEX_CSS || i == SCLEX_DIFF));
EnableCmd(hmenu,IDM_EDIT_STREAMCOMMENT,
!(i == SCLEX_NULL || i == SCLEX_VBSCRIPT || i == SCLEX_MAKEFILE || i == SCLEX_VB || i == SCLEX_ASM ||
i == SCLEX_SQL || i == SCLEX_PERL || i == SCLEX_PYTHON || i == SCLEX_PROPERTIES ||i == SCLEX_CONF ||
i == SCLEX_POWERSHELL || i == SCLEX_BATCH || i == SCLEX_DIFF));
EnableCmd(hmenu,IDM_EDIT_INSERT_ENCODING,*mEncoding[iEncoding].pszParseNames);
//EnableCmd(hmenu,IDM_EDIT_INSERT_SHORTDATE,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_INSERT_LONGDATE,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_INSERT_FILENAME,!bReadOnly);
//EnableCmd(hmenu,IDM_EDIT_INSERT_PATHNAME,!bReadOnly);
i = SendMessage(hwndEdit,SCI_GETLENGTH,0,0);
EnableCmd(hmenu,IDM_EDIT_FIND,i);
EnableCmd(hmenu,IDM_EDIT_SAVEFIND,i);
EnableCmd(hmenu,IDM_EDIT_FINDNEXT,i);
EnableCmd(hmenu,IDM_EDIT_FINDPREV,i && lstrlenA(efrData.szFind));
EnableCmd(hmenu,IDM_EDIT_SELTONEXT,i);
EnableCmd(hmenu,IDM_EDIT_SELTOPREV,i && lstrlenA(efrData.szFind));
EnableCmd(hmenu,IDM_EDIT_REPLACE,i /*&& !bReadOnly*/);
CheckCmd(hmenu,IDM_VIEW_USE2NDDEFAULT,Style_GetUse2ndDefault(hwndEdit));
CheckCmd(hmenu,IDM_VIEW_WORDWRAP,fWordWrap);
CheckCmd(hmenu,IDM_VIEW_LONGLINEMARKER,bMarkLongLines);
CheckCmd(hmenu,IDM_VIEW_TABSASSPACES,bTabsAsSpaces);
CheckCmd(hmenu,IDM_VIEW_SHOWINDENTGUIDES,bShowIndentGuides);
CheckCmd(hmenu,IDM_VIEW_AUTOINDENTTEXT,bAutoIndent);
CheckCmd(hmenu,IDM_VIEW_LINENUMBERS,bShowLineNumbers);
CheckCmd(hmenu,IDM_VIEW_MARGIN,bShowSelectionMargin);
CheckCmd(hmenu,IDM_VIEW_FOLDING,bShowCodeFolding);
EnableCmd(hmenu,IDM_VIEW_TOGGLEFOLDS,bShowCodeFolding);
CheckCmd(hmenu,IDM_VIEW_SHOWWHITESPACE,bViewWhiteSpace);
CheckCmd(hmenu,IDM_VIEW_SHOWEOLS,bViewEOLs);
CheckCmd(hmenu,IDM_VIEW_WORDWRAPSYMBOLS,bShowWordWrapSymbols);
CheckCmd(hmenu,IDM_VIEW_MATCHBRACES,bMatchBraces);
CheckCmd(hmenu,IDM_VIEW_TOOLBAR,bShowToolbar);
EnableCmd(hmenu,IDM_VIEW_CUSTOMIZETB,bShowToolbar);
CheckCmd(hmenu,IDM_VIEW_STATUSBAR,bShowStatusbar);
i = SendMessage(hwndEdit,SCI_GETLEXER,0,0);
//EnableCmd(hmenu,IDM_VIEW_AUTOCLOSETAGS,(i == SCLEX_HTML || i == SCLEX_XML));
CheckCmd(hmenu,IDM_VIEW_AUTOCLOSETAGS,bAutoCloseTags /*&& (i == SCLEX_HTML || i == SCLEX_XML)*/);
CheckCmd(hmenu,IDM_VIEW_HILITECURRENTLINE,bHiliteCurrentLine);
i = IniGetInt(L"Settings2",L"ReuseWindow",0);
CheckCmd(hmenu,IDM_VIEW_REUSEWINDOW,i);
i = IniGetInt(L"Settings2",L"SingleFileInstance",0);
CheckCmd(hmenu,IDM_VIEW_SINGLEFILEINSTANCE,i);
bStickyWinPos = IniGetInt(L"Settings2",L"StickyWindowPosition",0);
CheckCmd(hmenu,IDM_VIEW_STICKYWINPOS,bStickyWinPos);
CheckCmd(hmenu,IDM_VIEW_ALWAYSONTOP,bAlwaysOnTop);
CheckCmd(hmenu,IDM_VIEW_MINTOTRAY,bMinimizeToTray);
CheckCmd(hmenu,IDM_VIEW_TRANSPARENT,bTransparentMode && bTransparentModeAvailable);
EnableCmd(hmenu,IDM_VIEW_TRANSPARENT,bTransparentModeAvailable);
CheckCmd(hmenu,IDM_VIEW_NOSAVERECENT,bSaveRecentFiles);
CheckCmd(hmenu,IDM_VIEW_NOSAVEFINDREPL,bSaveFindReplace);
CheckCmd(hmenu,IDM_VIEW_SAVEBEFORERUNNINGTOOLS,bSaveBeforeRunningTools);
CheckCmd(hmenu,IDM_VIEW_CHANGENOTIFY,iFileWatchingMode);
if (lstrlen(szTitleExcerpt))
i = IDM_VIEW_SHOWEXCERPT;
else if (iPathNameFormat == 0)
i = IDM_VIEW_SHOWFILENAMEONLY;
else if (iPathNameFormat == 1)
i = IDM_VIEW_SHOWFILENAMEFIRST;
else
i = IDM_VIEW_SHOWFULLPATH;
CheckMenuRadioItem(hmenu,IDM_VIEW_SHOWFILENAMEONLY,IDM_VIEW_SHOWEXCERPT,i,MF_BYCOMMAND);
if (iEscFunction == 1)
i = IDM_VIEW_ESCMINIMIZE;
else if (iEscFunction == 2)
i = IDM_VIEW_ESCEXIT;
else
i = IDM_VIEW_NOESCFUNC;
CheckMenuRadioItem(hmenu,IDM_VIEW_NOESCFUNC,IDM_VIEW_ESCEXIT,i,MF_BYCOMMAND);
i = lstrlen(szIniFile);
CheckCmd(hmenu,IDM_VIEW_SAVESETTINGS,bSaveSettings && i);
EnableCmd(hmenu,IDM_VIEW_REUSEWINDOW,i);
EnableCmd(hmenu,IDM_VIEW_STICKYWINPOS,i);
EnableCmd(hmenu,IDM_VIEW_SINGLEFILEINSTANCE,i);
EnableCmd(hmenu,IDM_VIEW_NOSAVERECENT,i);
EnableCmd(hmenu,IDM_VIEW_NOSAVEFINDREPL,i);
EnableCmd(hmenu,IDM_VIEW_SAVESETTINGS,i);
i = (lstrlen(szIniFile) > 0 || lstrlen(szIniFile2) > 0);
EnableCmd(hmenu,IDM_VIEW_SAVESETTINGSNOW,i);
}
//=============================================================================
//
// MsgCommand() - Handles WM_COMMAND
//
//
LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam)
{
switch(LOWORD(wParam))
{
case IDM_FILE_NEW:
FileLoad(FALSE,TRUE,FALSE,FALSE,L"");
break;
case IDM_FILE_OPEN:
FileLoad(FALSE,FALSE,FALSE,FALSE,L"");
break;
case IDM_FILE_REVERT:
{
if (lstrlen(szCurFile)) {
WCHAR tchCurFile2[MAX_PATH];
int iCurPos = SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0);
int iAnchorPos = SendMessage(hwndEdit,SCI_GETANCHOR,0,0);
int iCurTopLine = SendMessage(hwndEdit,SCI_GETFIRSTVISIBLELINE,0,0);
int iXOffset = SendMessage(hwndEdit,SCI_GETXOFFSET,0,0);
if ((bModified || iEncoding != iOriginalEncoding) && MsgBox(MBOKCANCEL,IDS_ASK_REVERT) != IDOK)
return(0);
lstrcpy(tchCurFile2,szCurFile);
iWeakSrcEncoding = iEncoding;
if (FileLoad(TRUE,FALSE,TRUE,FALSE,tchCurFile2))
{
if (SendMessage(hwndEdit,SCI_GETLENGTH,0,0) >= 4) {
char tch[5] = "";
SendMessage(hwndEdit,SCI_GETTEXT,5,(LPARAM)tch);
if (lstrcmpiA(tch,".LOG") != 0) {
int iTopLineAfterLoad;
SendMessage(hwndEdit,SCI_SETSEL,(WPARAM)iAnchorPos,(LPARAM)iCurPos);
iTopLineAfterLoad = SendMessage(hwndEdit,SCI_GETFIRSTVISIBLELINE,0,0);
SendMessage(hwndEdit,SCI_LINESCROLL,0,(LPARAM)(iCurTopLine - iTopLineAfterLoad));
SendMessage(hwndEdit,SCI_SETXOFFSET,(WPARAM)iXOffset,0);
}
}
}
}
}
break;
case IDM_FILE_SAVE:
FileSave(TRUE,FALSE,FALSE,FALSE);
break;
case IDM_FILE_SAVEAS:
FileSave(TRUE,FALSE,TRUE,FALSE);
break;
case IDM_FILE_SAVECOPY:
FileSave(TRUE,FALSE,TRUE,TRUE);
break;
case IDM_FILE_READONLY:
//bReadOnly = (bReadOnly) ? FALSE : TRUE;
//SendMessage(hwndEdit,SCI_SETREADONLY,bReadOnly,0);
//UpdateToolbar();
//UpdateStatusbar();
if (lstrlen(szCurFile))
{
BOOL bSuccess = FALSE;
DWORD dwFileAttributes = GetFileAttributes(szCurFile);
if (dwFileAttributes != INVALID_FILE_ATTRIBUTES) {
if (bReadOnly)
dwFileAttributes = (dwFileAttributes & ~FILE_ATTRIBUTE_READONLY);
else
dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
if (!SetFileAttributes(szCurFile,dwFileAttributes))
MsgBox(MBWARN,IDS_READONLY_MODIFY,szCurFile);
}
else
MsgBox(MBWARN,IDS_READONLY_MODIFY,szCurFile);
dwFileAttributes = GetFileAttributes(szCurFile);
if (dwFileAttributes != INVALID_FILE_ATTRIBUTES)
bReadOnly = (dwFileAttributes & FILE_ATTRIBUTE_READONLY);
SetWindowTitle(hwnd,uidsAppTitle,fIsElevated,IDS_UNTITLED,szCurFile,
iPathNameFormat,bModified || iEncoding != iOriginalEncoding,
IDS_READONLY,bReadOnly,szTitleExcerpt);
}
break;
case IDM_FILE_BROWSE:
{
SHELLEXECUTEINFO sei;
WCHAR tchParam[MAX_PATH+4];
WCHAR tchExeFile[MAX_PATH+4];
lstrcpy(tchParam,szCurFile);
PathQuoteSpaces(tchParam);
if (!IniGetString(L"Settings2",L"filebrowser.exe",L"",tchExeFile,COUNTOF(tchExeFile))) {
if (!SearchPath(NULL,L"metapath.exe",NULL,COUNTOF(tchExeFile),tchExeFile,NULL)) {
GetModuleFileName(NULL,tchExeFile,COUNTOF(tchExeFile));
PathRemoveFileSpec(tchExeFile);
PathAppend(tchExeFile,L"metapath.exe");
}
}
else if (PathIsRelative(tchExeFile)) {
WCHAR tch[MAX_PATH];
if (!SearchPath(NULL,tchExeFile,NULL,COUNTOF(tch),tch,NULL)) {
GetModuleFileName(NULL,tch,COUNTOF(tch));
PathRemoveFileSpec(tch);
PathAppend(tch,tchExeFile);
lstrcpy(tchExeFile,tch);
}
else
lstrcpy(tchExeFile,tch);
}
ZeroMemory(&sei,sizeof(SHELLEXECUTEINFO));
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.fMask = SEE_MASK_FLAG_NO_UI | /*SEE_MASK_NOZONECHECKS*/0x00800000;
sei.hwnd = hwnd;
sei.lpVerb = NULL;
sei.lpFile = tchExeFile;
sei.lpParameters = tchParam;
sei.lpDirectory = NULL;
sei.nShow = SW_SHOWNORMAL;
ShellExecuteEx(&sei);
if ((int)sei.hInstApp < 32)
MsgBox(MBWARN,IDS_ERR_BROWSE);
}
break;
case IDM_FILE_NEWWINDOW:
case IDM_FILE_NEWWINDOW2:
{
SHELLEXECUTEINFO sei;
WCHAR szModuleName[MAX_PATH];
WCHAR szFileName[MAX_PATH];
WCHAR szParameters[2*MAX_PATH+64];
MONITORINFO mi;
HMONITOR hMonitor;
WINDOWPLACEMENT wndpl;
int x,y,cx,cy,imax;
WCHAR tch[64];
if (bSaveBeforeRunningTools && !FileSave(FALSE,TRUE,FALSE,FALSE))
break;
GetModuleFileName(NULL,szModuleName,COUNTOF(szModuleName));
lstrcpy(szParameters,L"-f");
if (lstrlen(szIniFile)) {
lstrcat(szParameters,L" \"");
lstrcat(szParameters,szIniFile);
lstrcat(szParameters,L"\"");
}
else
lstrcat(szParameters,L"0");
lstrcat(szParameters,L" -n");
wndpl.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(hwnd,&wndpl);
hMonitor = MonitorFromRect(&wndpl.rcNormalPosition,MONITOR_DEFAULTTONEAREST);
mi.cbSize = sizeof(mi);
GetMonitorInfo(hMonitor,&mi);
// offset new window position +10/+10
x = wndpl.rcNormalPosition.left + 10;
y = wndpl.rcNormalPosition.top + 10;
cx = wndpl.rcNormalPosition.right - wndpl.rcNormalPosition.left;
cy = wndpl.rcNormalPosition.bottom - wndpl.rcNormalPosition.top;
// check if window fits monitor
if ((x + cx) > mi.rcWork.right || (y + cy) > mi.rcWork.bottom) {
x = mi.rcMonitor.left;
y = mi.rcMonitor.top;
}
imax = IsZoomed(hwnd);
wsprintf(tch,L" -p %i,%i,%i,%i,%i",x,y,cx,cy,imax);
lstrcat(szParameters,tch);
if (LOWORD(wParam) != IDM_FILE_NEWWINDOW2 && lstrlen(szCurFile)) {
lstrcpy(szFileName,szCurFile);
PathQuoteSpaces(szFileName);
lstrcat(szParameters,L" ");
lstrcat(szParameters,szFileName);
}
ZeroMemory(&sei,sizeof(SHELLEXECUTEINFO));
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.fMask = /*SEE_MASK_NOZONECHECKS*/0x00800000;
sei.hwnd = hwnd;
sei.lpVerb = NULL;
sei.lpFile = szModuleName;
sei.lpParameters = szParameters;
sei.lpDirectory = NULL;
sei.nShow = SW_SHOWNORMAL;
ShellExecuteEx(&sei);
}
break;
case IDM_FILE_LAUNCH:
{
SHELLEXECUTEINFO sei;
WCHAR wchDirectory[MAX_PATH] = L"";
if (!lstrlen(szCurFile))
break;
if (bSaveBeforeRunningTools && !FileSave(FALSE,TRUE,FALSE,FALSE))
break;
if (lstrlen(szCurFile)) {
lstrcpy(wchDirectory,szCurFile);
PathRemoveFileSpec(wchDirectory);
}
ZeroMemory(&sei,sizeof(SHELLEXECUTEINFO));
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.fMask = 0;
sei.hwnd = hwnd;
sei.lpVerb = NULL;
sei.lpFile = szCurFile;
sei.lpParameters = NULL;
sei.lpDirectory = NULL;
sei.nShow = SW_SHOWNORMAL;
ShellExecuteEx(&sei);
}
break;
case IDM_FILE_RUN:
{
WCHAR tchCmdLine[MAX_PATH+4];
if (bSaveBeforeRunningTools && !FileSave(FALSE,TRUE,FALSE,FALSE))
break;
lstrcpy(tchCmdLine,szCurFile);
PathQuoteSpaces(tchCmdLine);
RunDlg(hwnd,tchCmdLine);
}
break;
case IDM_FILE_OPENWITH:
if (bSaveBeforeRunningTools && !FileSave(FALSE,TRUE,FALSE,FALSE))
break;
OpenWithDlg(hwnd,szCurFile);
break;
case IDM_FILE_PAGESETUP:
EditPrintSetup(hwndEdit);
break;
case IDM_FILE_PRINT:
{
SHFILEINFO shfi;
WCHAR *pszTitle;
WCHAR tchUntitled[32];
WCHAR tchPageFmt[32];
if (lstrlen(szCurFile)) {
SHGetFileInfo2(szCurFile,0,&shfi,sizeof(SHFILEINFO),SHGFI_DISPLAYNAME);
pszTitle = shfi.szDisplayName;
}
else {
GetString(IDS_UNTITLED,tchUntitled,COUNTOF(tchUntitled));
pszTitle = tchUntitled;
}
GetString(IDS_PRINT_PAGENUM,tchPageFmt,COUNTOF(tchPageFmt));
if (!EditPrint(hwndEdit,pszTitle,tchPageFmt))
MsgBox(MBWARN,IDS_PRINT_ERROR,pszTitle);
}
break;
case IDM_FILE_PROPERTIES:
{
SHELLEXECUTEINFO sei;
if (lstrlen(szCurFile) == 0)
break;
ZeroMemory(&sei,sizeof(SHELLEXECUTEINFO));
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.fMask = SEE_MASK_INVOKEIDLIST;
sei.hwnd = hwnd;
sei.lpVerb = L"properties";
sei.lpFile = szCurFile;
sei.nShow = SW_SHOWNORMAL;
ShellExecuteEx(&sei);
}
break;
case IDM_FILE_CREATELINK:
{
if (!lstrlen(szCurFile))
break;
if (!PathCreateDeskLnk(szCurFile))
MsgBox(MBWARN,IDS_ERR_CREATELINK);
}
break;
case IDM_FILE_OPENFAV:
if (FileSave(FALSE,TRUE,FALSE,FALSE)) {
WCHAR tchSelItem[MAX_PATH];
if (FavoritesDlg(hwnd,tchSelItem))
{
if (PathIsLnkToDirectory(tchSelItem,NULL,0))
PathGetLnkPath(tchSelItem,tchSelItem,COUNTOF(tchSelItem));
if (PathIsDirectory(tchSelItem))
{
WCHAR tchFile[MAX_PATH];
if (OpenFileDlg(hwndMain,tchFile,COUNTOF(tchFile),tchSelItem))
FileLoad(TRUE,FALSE,FALSE,FALSE,tchFile);
}
else
FileLoad(TRUE,FALSE,FALSE,FALSE,tchSelItem);
}
}
break;
case IDM_FILE_ADDTOFAV:
if (lstrlen(szCurFile)) {
SHFILEINFO shfi;
SHGetFileInfo2(szCurFile,0,&shfi,sizeof(SHFILEINFO),SHGFI_DISPLAYNAME);
AddToFavDlg(hwnd,shfi.szDisplayName,szCurFile);
}
break;
case IDM_FILE_MANAGEFAV:
{
SHELLEXECUTEINFO sei;
ZeroMemory(&sei,sizeof(SHELLEXECUTEINFO));
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.fMask = 0;
sei.hwnd = hwnd;
sei.lpVerb = NULL;
sei.lpFile = tchFavoritesDir;
sei.lpParameters = NULL;
sei.lpDirectory = NULL;
sei.nShow = SW_SHOWNORMAL;
// Run favorites directory
ShellExecuteEx(&sei);
}
break;
case IDM_FILE_RECENT:
if (MRU_Enum(pFileMRU,0,NULL,0) > 0) {
if (FileSave(FALSE,TRUE,FALSE,FALSE)) {
WCHAR tchFile[MAX_PATH];
if (FileMRUDlg(hwnd,tchFile))
FileLoad(TRUE,FALSE,FALSE,FALSE,tchFile);
}
}
break;
case IDM_FILE_EXIT:
SendMessage(hwnd,WM_CLOSE,0,0);
break;
case IDM_ENCODING_ANSI:
case IDM_ENCODING_UNICODE:
case IDM_ENCODING_UNICODEREV:
case IDM_ENCODING_UTF8:
case IDM_ENCODING_UTF8SIGN:
case IDM_ENCODING_SELECT:
{
int iNewEncoding = iEncoding;
if (LOWORD(wParam) == IDM_ENCODING_SELECT && !SelectEncodingDlg(hwnd,&iNewEncoding))
break;
else {
switch (LOWORD(wParam)) {
case IDM_ENCODING_UNICODE: iNewEncoding = CPI_UNICODEBOM; break;
case IDM_ENCODING_UNICODEREV: iNewEncoding = CPI_UNICODEBEBOM; break;
case IDM_ENCODING_UTF8: iNewEncoding = CPI_UTF8; break;
case IDM_ENCODING_UTF8SIGN: iNewEncoding = CPI_UTF8SIGN; break;
case IDM_ENCODING_ANSI: iNewEncoding = CPI_DEFAULT; break;
}
}
if (EditSetNewEncoding(hwndEdit,
iEncoding,iNewEncoding,
(flagSetEncoding),lstrlen(szCurFile) == 0)) {
if (SendMessage(hwndEdit,SCI_GETLENGTH,0,0) == 0) {
iEncoding = iNewEncoding;
iOriginalEncoding = iNewEncoding;
}
else {
if (iEncoding == CPI_DEFAULT || iNewEncoding == CPI_DEFAULT)
iOriginalEncoding = -1;
iEncoding = iNewEncoding;
}
UpdateToolbar();
UpdateStatusbar();
SetWindowTitle(hwnd,uidsAppTitle,fIsElevated,IDS_UNTITLED,szCurFile,
iPathNameFormat,bModified || iEncoding != iOriginalEncoding,
IDS_READONLY,bReadOnly,szTitleExcerpt);
}
}
break;
case IDM_ENCODING_RECODE:
{
if (lstrlen(szCurFile)) {
WCHAR tchCurFile2[MAX_PATH];
int iNewEncoding = -1;
if (iEncoding != CPI_DEFAULT)
iNewEncoding = iEncoding;
if (iEncoding == CPI_UTF8SIGN)
iNewEncoding = CPI_UTF8;
if ((bModified || iEncoding != iOriginalEncoding) && MsgBox(MBOKCANCEL,IDS_ASK_RECODE) != IDOK)
return(0);
if (RecodeDlg(hwnd,&iNewEncoding)) {
lstrcpy(tchCurFile2,szCurFile);
iSrcEncoding = iNewEncoding;
FileLoad(TRUE,FALSE,TRUE,FALSE,tchCurFile2);
}
}
}
break;
case IDM_ENCODING_SETDEFAULT:
SelectDefEncodingDlg(hwnd,&iDefaultEncoding);
break;
case IDM_LINEENDINGS_CRLF:
case IDM_LINEENDINGS_LF:
case IDM_LINEENDINGS_CR:
{
int iNewEOLMode = iLineEndings[LOWORD(wParam)-IDM_LINEENDINGS_CRLF];
iEOLMode = iNewEOLMode;
SendMessage(hwndEdit,SCI_SETEOLMODE,iEOLMode,0);
SendMessage(hwndEdit,SCI_CONVERTEOLS,iEOLMode,0);
UpdateToolbar();
UpdateStatusbar();
SetWindowTitle(hwnd,uidsAppTitle,fIsElevated,IDS_UNTITLED,szCurFile,
iPathNameFormat,bModified || iEncoding != iOriginalEncoding,
IDS_READONLY,bReadOnly,szTitleExcerpt);
}
break;
case IDM_LINEENDINGS_SETDEFAULT:
SelectDefLineEndingDlg(hwnd,&iDefaultEOLMode);
break;
case IDM_EDIT_UNDO:
SendMessage(hwndEdit,SCI_UNDO,0,0);
break;
case IDM_EDIT_REDO:
SendMessage(hwndEdit,SCI_REDO,0,0);
break;
case IDM_EDIT_CUT:
if (flagPasteBoard)
bLastCopyFromMe = TRUE;
SendMessage(hwndEdit,SCI_CUT,0,0);
break;
case IDM_EDIT_COPY:
if (flagPasteBoard)
bLastCopyFromMe = TRUE;
SendMessage(hwndEdit,SCI_COPY,0,0);
UpdateToolbar();
break;
case IDM_EDIT_COPYALL:
if (flagPasteBoard)
bLastCopyFromMe = TRUE;
SendMessage(hwndEdit,SCI_COPYRANGE,0,SendMessage(hwndEdit,SCI_GETLENGTH,0,0));
UpdateToolbar();
break;
case IDM_EDIT_COPYADD:
if (flagPasteBoard)
bLastCopyFromMe = TRUE;
EditCopyAppend(hwndEdit);
UpdateToolbar();
break;
case IDM_EDIT_PASTE:
SendMessage(hwndEdit,SCI_PASTE,0,0);
break;
case IDM_EDIT_SWAP:
if (SendMessage(hwndEdit,SCI_GETSELECTIONEND,0,0) -
SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0) == 0) {
int iNewPos = -1;
int iPos = SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0);
SendMessage(hwndEdit,SCI_PASTE,0,0);
iNewPos = SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0);
SendMessage(hwndEdit,SCI_SETSEL,iPos,iNewPos);
SendMessage(hwnd,WM_COMMAND,MAKELONG(IDM_EDIT_CLEARCLIPBOARD,1),0);
}
else {
int iPos = SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0);
int iAnchor = SendMessage(hwndEdit,SCI_GETANCHOR,0,0);
char *pClip = EditGetClipboardText(hwndEdit);
if (flagPasteBoard)
bLastCopyFromMe = TRUE;
SendMessage(hwndEdit,SCI_BEGINUNDOACTION,0,0);
SendMessage(hwndEdit,SCI_CUT,0,0);
SendMessage(hwndEdit,SCI_REPLACESEL,(WPARAM)0,(LPARAM)pClip);
if (iPos > iAnchor)
SendMessage(hwndEdit,SCI_SETSEL,iAnchor,iAnchor + lstrlenA(pClip));
else
SendMessage(hwndEdit,SCI_SETSEL,iPos + lstrlenA(pClip),iPos);
SendMessage(hwndEdit,SCI_ENDUNDOACTION,0,0);
LocalFree(pClip);
}
break;
case IDM_EDIT_CLEAR:
SendMessage(hwndEdit,SCI_CLEAR,0,0);
break;
case IDM_EDIT_CLEARCLIPBOARD:
if (OpenClipboard(hwnd)) {
if (CountClipboardFormats() > 0) {
EmptyClipboard();
UpdateToolbar();
UpdateStatusbar();
}
CloseClipboard();
}
break;
case IDM_EDIT_SELECTALL:
SendMessage(hwndEdit,SCI_SELECTALL,0,0);
//SendMessage(hwndEdit,SCI_SETSEL,0,(LPARAM)-1);
break;
case IDM_EDIT_SELECTWORD:
{
int iSel =
SendMessage(hwndEdit,SCI_GETSELECTIONEND,0,0) -
SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0);
int iPos = SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0);
if (iSel == 0) {
int iWordStart = SendMessage(hwndEdit,SCI_WORDSTARTPOSITION,iPos,TRUE);
int iWordEnd = SendMessage(hwndEdit,SCI_WORDENDPOSITION,iPos,TRUE);
if (iWordStart == iWordEnd) // we are in whitespace salad...
{
iWordStart = SendMessage(hwndEdit,SCI_WORDENDPOSITION,iPos,FALSE);
iWordEnd = SendMessage(hwndEdit,SCI_WORDENDPOSITION,iWordStart,TRUE);
if (iWordStart != iWordEnd) {
//if (SCLEX_HTML == SendMessage(hwndEdit,SCI_GETLEXER,0,0) &&
// SCE_HPHP_VARIABLE == SendMessage(hwndEdit,SCI_GETSTYLEAT,(WPARAM)iWordStart,0) &&
// '$' == (char)SendMessage(hwndEdit,SCI_GETCHARAT,(WPARAM)iWordStart-1,0))
// iWordStart--;
SendMessage(hwndEdit,SCI_SETSEL,iWordStart,iWordEnd);
}
}
else {
//if (SCLEX_HTML == SendMessage(hwndEdit,SCI_GETLEXER,0,0) &&
// SCE_HPHP_VARIABLE == SendMessage(hwndEdit,SCI_GETSTYLEAT,(WPARAM)iWordStart,0) &&
// '$' == (char)SendMessage(hwndEdit,SCI_GETCHARAT,(WPARAM)iWordStart-1,0))
// iWordStart--;
SendMessage(hwndEdit,SCI_SETSEL,iWordStart,iWordEnd);
}
iSel =
SendMessage(hwndEdit,SCI_GETSELECTIONEND,0,0) -
SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0);
if (iSel == 0) {
int iLine = SendMessage(hwndEdit,SCI_LINEFROMPOSITION,iPos,0);
int iLineStart = SendMessage(hwndEdit,SCI_GETLINEINDENTPOSITION,iLine,0);
int iLineEnd = SendMessage(hwndEdit,SCI_GETLINEENDPOSITION,iLine,0);
SendMessage(hwndEdit,SCI_SETSEL,iLineStart,iLineEnd);
}
}
else {
int iLine = SendMessage(hwndEdit,SCI_LINEFROMPOSITION,iPos,0);
int iLineStart = SendMessage(hwndEdit,SCI_GETLINEINDENTPOSITION,iLine,0);
int iLineEnd = SendMessage(hwndEdit,SCI_GETLINEENDPOSITION,iLine,0);
SendMessage(hwndEdit,SCI_SETSEL,iLineStart,iLineEnd);
}
}
break;
case IDM_EDIT_SELECTLINE:
{
int iSelStart = SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0);
int iSelEnd = SendMessage(hwndEdit,SCI_GETSELECTIONEND,0,0);
int iLineStart = SendMessage(hwndEdit,SCI_LINEFROMPOSITION,iSelStart,0);
int iLineEnd = SendMessage(hwndEdit,SCI_LINEFROMPOSITION,iSelEnd,0);
iSelStart = SendMessage(hwndEdit,SCI_POSITIONFROMLINE,iLineStart,0);
iSelEnd = SendMessage(hwndEdit,SCI_POSITIONFROMLINE,iLineEnd+1,0);
SendMessage(hwndEdit,SCI_SETSEL,iSelStart,iSelEnd);
SendMessage(hwndEdit,SCI_CHOOSECARETX,0,0);
}
break;
case IDM_EDIT_MOVELINEUP:
EditMoveUp(hwndEdit);
break;
case IDM_EDIT_MOVELINEDOWN:
EditMoveDown(hwndEdit);
break;
case IDM_EDIT_DUPLICATELINE:
SendMessage(hwndEdit,SCI_LINEDUPLICATE,0,0);
break;
case IDM_EDIT_CUTLINE:
if (flagPasteBoard)
bLastCopyFromMe = TRUE;
SendMessage(hwndEdit,SCI_LINECUT,0,0);
break;
case IDM_EDIT_COPYLINE:
if (flagPasteBoard)
bLastCopyFromMe = TRUE;
SendMessage(hwndEdit,SCI_LINECOPY,0,0);
UpdateToolbar();
break;
case IDM_EDIT_DELETELINE:
SendMessage(hwndEdit,SCI_LINEDELETE,0,0);
break;
case IDM_EDIT_DELETELINELEFT:
SendMessage(hwndEdit,SCI_DELLINELEFT,0,0);
break;
case IDM_EDIT_DELETELINERIGHT:
SendMessage(hwndEdit,SCI_DELLINERIGHT,0,0);
break;
case IDM_EDIT_INDENT:
{
int iLineSelStart = SendMessage(hwndEdit,SCI_LINEFROMPOSITION,
SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0),0);
int iLineSelEnd = SendMessage(hwndEdit,SCI_LINEFROMPOSITION,
SendMessage(hwndEdit,SCI_GETSELECTIONEND,0,0),0);
SendMessage(hwndEdit,SCI_SETTABINDENTS,TRUE,0);
if (iLineSelStart == iLineSelEnd) {
SendMessage(hwndEdit,SCI_VCHOME,0,0);
SendMessage(hwndEdit,SCI_TAB,0,0);
}
else
SendMessage(hwndEdit,SCI_TAB,0,0);
SendMessage(hwndEdit,SCI_SETTABINDENTS,bTabIndents,0);
}
break;
case IDM_EDIT_UNINDENT:
{
int iLineSelStart = SendMessage(hwndEdit,SCI_LINEFROMPOSITION,
SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0),0);
int iLineSelEnd = SendMessage(hwndEdit,SCI_LINEFROMPOSITION,
SendMessage(hwndEdit,SCI_GETSELECTIONEND,0,0),0);
SendMessage(hwndEdit,SCI_SETTABINDENTS,TRUE,0);
if (iLineSelStart == iLineSelEnd) {
SendMessage(hwndEdit,SCI_VCHOME,0,0);
SendMessage(hwndEdit,SCI_BACKTAB,0,0);
}
else
SendMessage(hwndEdit,SCI_BACKTAB,0,0);
SendMessage(hwndEdit,SCI_SETTABINDENTS,bTabIndents,0);
}
break;
case IDM_EDIT_ENCLOSESELECTION:
if (EditEncloseSelectionDlg(hwnd,wchPrefixSelection,wchAppendSelection)) {
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditEncloseSelection(hwndEdit,wchPrefixSelection,wchAppendSelection);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
}
break;
case IDM_EDIT_SELECTIONDUPLICATE:
SendMessage(hwndEdit,SCI_BEGINUNDOACTION,0,0);
SendMessage(hwndEdit,SCI_SELECTIONDUPLICATE,0,0);
SendMessage(hwndEdit,SCI_ENDUNDOACTION,0,0);
break;
case IDM_EDIT_PADWITHSPACES:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditPadWithSpaces(hwndEdit);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_STRIP1STCHAR:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditStripFirstCharacter(hwndEdit);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_STRIPLASTCHAR:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditStripLastCharacter(hwndEdit);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_TRIMLINES:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditStripTrailingBlanks(hwndEdit,FALSE);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_COMPRESSWS:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditCompressSpaces(hwndEdit);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_REMOVEBLANKLINES:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditRemoveBlankLines(hwndEdit);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_MODIFYLINES:
if (EditModifyLinesDlg(hwnd,wchPrefixLines,wchAppendLines)) {
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditModifyLines(hwndEdit,wchPrefixLines,wchAppendLines);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
}
break;
case IDM_EDIT_SORTLINES:
if (EditSortDlg(hwnd,&iSortOptions)) {
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
StatusSetText(hwndStatus,255,L"...");
StatusSetSimple(hwndStatus,TRUE);
InvalidateRect(hwndStatus,NULL,TRUE);
UpdateWindow(hwndStatus);
EditSortLines(hwndEdit,iSortOptions);
StatusSetSimple(hwndStatus,FALSE);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
}
break;
case IDM_EDIT_COLUMNWRAP:
{
if (iWrapCol == 0)
iWrapCol = iLongLinesLimit;
if (ColumnWrapDlg(hwnd,IDD_COLUMNWRAP,&iWrapCol))
{
iWrapCol = max(min(iWrapCol,512),1);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditWrapToColumn(hwndEdit,iWrapCol);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
}
}
break;
case IDM_EDIT_SPLITLINES:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
SendMessage(hwndEdit,SCI_TARGETFROMSELECTION,0,0);
SendMessage(hwndEdit,SCI_LINESSPLIT,0,0);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_JOINLINES:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
SendMessage(hwndEdit,SCI_TARGETFROMSELECTION,0,0);
SendMessage(hwndEdit,SCI_LINESJOIN,0,0);
EditJoinLinesEx(hwndEdit);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_JOINLINESEX:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditJoinLinesEx(hwndEdit);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_CONVERTUPPERCASE:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditMakeUppercase(hwndEdit);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_CONVERTLOWERCASE:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditMakeLowercase(hwndEdit);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_INVERTCASE:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditInvertCase(hwndEdit);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_TITLECASE:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditTitleCase(hwndEdit);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_SENTENCECASE:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditSentenceCase(hwndEdit);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_CONVERTTABS:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditTabsToSpaces(hwndEdit,iTabWidth,FALSE);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_CONVERTSPACES:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditSpacesToTabs(hwndEdit,iTabWidth,FALSE);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_CONVERTTABS2:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditTabsToSpaces(hwndEdit,iTabWidth,TRUE);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_CONVERTSPACES2:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditSpacesToTabs(hwndEdit,iTabWidth,TRUE);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_INSERT_TAG:
{
WCHAR wszOpen[256] = L"";
WCHAR wszClose[256] = L"";
if (EditInsertTagDlg(hwnd,wszOpen,wszClose))
EditEncloseSelection(hwndEdit,wszOpen,wszClose);
}
break;
case IDM_EDIT_INSERT_ENCODING:
{
if (*mEncoding[iEncoding].pszParseNames) {
char msz[32];
char *p;
int iSelStart;
lstrcpynA(msz,mEncoding[iEncoding].pszParseNames,COUNTOF(msz));
if (p = StrChrA(msz,','))
*p = 0;
iSelStart = SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0);
SendMessage(hwndEdit,SCI_REPLACESEL,0,(LPARAM)msz);
SendMessage(hwndEdit,SCI_SETANCHOR,(WPARAM)iSelStart,0);
}
}
break;
case IDM_EDIT_INSERT_SHORTDATE:
case IDM_EDIT_INSERT_LONGDATE:
{
WCHAR tchDate[128];
WCHAR tchTime[128];
WCHAR tchDateTime[256];
WCHAR tchTemplate[256];
SYSTEMTIME st;
char mszBuf[MAX_PATH*3];
UINT uCP;
int iSelStart;
GetLocalTime(&st);
if (IniGetString(L"Settings2",
(LOWORD(wParam) == IDM_EDIT_INSERT_SHORTDATE) ? L"DateTimeShort" : L"DateTimeLong",
L"",tchTemplate,COUNTOF(tchTemplate))) {
struct tm sst;
sst.tm_isdst = -1;
sst.tm_sec = (int)st.wSecond;
sst.tm_min = (int)st.wMinute;
sst.tm_hour = (int)st.wHour;
sst.tm_mday = (int)st.wDay;
sst.tm_mon = (int)st.wMonth - 1;
sst.tm_year = (int)st.wYear - 1900;
sst.tm_wday = (int)st.wDayOfWeek;
mktime(&sst);
wcsftime(tchDateTime,COUNTOF(tchDateTime),tchTemplate,&sst);
}
else {
GetDateFormat(LOCALE_USER_DEFAULT,(
LOWORD(wParam) == IDM_EDIT_INSERT_SHORTDATE) ? DATE_SHORTDATE : DATE_LONGDATE,
&st,NULL,tchDate,COUNTOF(tchDate));
GetTimeFormat(LOCALE_USER_DEFAULT,TIME_NOSECONDS,&st,NULL,tchTime,COUNTOF(tchTime));
wsprintf(tchDateTime,L"%s %s",tchTime,tchDate);
}
uCP = (SendMessage(hwndEdit,SCI_GETCODEPAGE,0,0) == SC_CP_UTF8) ? CP_UTF8 : CP_ACP;
WideCharToMultiByte(uCP,0,tchDateTime,-1,mszBuf,COUNTOF(mszBuf),NULL,NULL);
iSelStart = SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0);
SendMessage(hwndEdit,SCI_REPLACESEL,0,(LPARAM)mszBuf);
SendMessage(hwndEdit,SCI_SETANCHOR,(WPARAM)iSelStart,0);
}
break;
case IDM_EDIT_INSERT_FILENAME:
case IDM_EDIT_INSERT_PATHNAME:
{
SHFILEINFO shfi;
WCHAR *pszInsert;
WCHAR tchUntitled[32];
char mszBuf[MAX_PATH*3];
UINT uCP;
int iSelStart;
if (lstrlen(szCurFile)) {
if (LOWORD(wParam) == IDM_EDIT_INSERT_FILENAME) {
SHGetFileInfo2(szCurFile,0,&shfi,sizeof(SHFILEINFO),SHGFI_DISPLAYNAME);
pszInsert = shfi.szDisplayName;
}
else
pszInsert = szCurFile;
}
else {
GetString(IDS_UNTITLED,tchUntitled,COUNTOF(tchUntitled));
pszInsert = tchUntitled;
}
uCP = (SendMessage(hwndEdit,SCI_GETCODEPAGE,0,0) == SC_CP_UTF8) ? CP_UTF8 : CP_ACP;
WideCharToMultiByte(uCP,0,pszInsert,-1,mszBuf,COUNTOF(mszBuf),NULL,NULL);
iSelStart = SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0);
SendMessage(hwndEdit,SCI_REPLACESEL,0,(LPARAM)mszBuf);
SendMessage(hwndEdit,SCI_SETANCHOR,(WPARAM)iSelStart,0);
}
break;
case IDM_EDIT_LINECOMMENT:
switch (SendMessage(hwndEdit,SCI_GETLEXER,0,0)) {
case SCLEX_NULL:
case SCLEX_CSS:
case SCLEX_DIFF:
break;
case SCLEX_HTML:
case SCLEX_XML:
case SCLEX_CPP:
case SCLEX_PASCAL:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditToggleLineComments(hwndEdit,L"//",FALSE);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case SCLEX_VBSCRIPT:
case SCLEX_VB:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditToggleLineComments(hwndEdit,L"'",FALSE);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case SCLEX_MAKEFILE:
case SCLEX_PERL:
case SCLEX_PYTHON:
case SCLEX_CONF:
case SCLEX_POWERSHELL:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditToggleLineComments(hwndEdit,L"#",TRUE);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case SCLEX_ASM:
case SCLEX_PROPERTIES:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditToggleLineComments(hwndEdit,L";",TRUE);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case SCLEX_SQL:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditToggleLineComments(hwndEdit,L"--",TRUE);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case SCLEX_BATCH:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditToggleLineComments(hwndEdit,L"rem ",TRUE);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
}
break;
case IDM_EDIT_STREAMCOMMENT:
switch (SendMessage(hwndEdit,SCI_GETLEXER,0,0)) {
case SCLEX_NULL:
case SCLEX_VBSCRIPT:
case SCLEX_MAKEFILE:
case SCLEX_VB:
case SCLEX_ASM:
case SCLEX_SQL:
case SCLEX_PERL:
case SCLEX_PYTHON:
case SCLEX_PROPERTIES:
case SCLEX_CONF:
case SCLEX_POWERSHELL:
case SCLEX_BATCH:
case SCLEX_DIFF:
break;
case SCLEX_HTML:
case SCLEX_XML:
case SCLEX_CSS:
case SCLEX_CPP:
EditEncloseSelection(hwndEdit,L"/*",L"*/");
break;
case SCLEX_PASCAL:
EditEncloseSelection(hwndEdit,L"{",L"}");
}
break;
case IDM_EDIT_URLENCODE:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditURLEncode(hwndEdit);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_URLDECODE:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditURLDecode(hwndEdit);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_ESCAPECCHARS:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditEscapeCChars(hwndEdit);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_UNESCAPECCHARS:
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORWAIT,0);
EditUnescapeCChars(hwndEdit);
SendMessage(hwndEdit,SCI_SETCURSOR,SC_CURSORNORMAL,0);
break;
case IDM_EDIT_FINDMATCHINGBRACE:
{
int iBrace2 = -1;
int iPos = SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0);
char c = (char)SendMessage(hwndEdit,SCI_GETCHARAT,iPos,0);
if (StrChrA("()[]{}",c))
iBrace2 = SendMessage(hwndEdit,SCI_BRACEMATCH,iPos,0);
// Try one before
else {
iPos = SendMessage(hwndEdit,SCI_POSITIONBEFORE,iPos,0);
c = (char)SendMessage(hwndEdit,SCI_GETCHARAT,iPos,0);
if (StrChrA("()[]{}",c))
iBrace2 = SendMessage(hwndEdit,SCI_BRACEMATCH,iPos,0);
}
if (iBrace2 != -1)
SendMessage(hwndEdit,SCI_GOTOPOS,(WPARAM)iBrace2,0);
}
break;
case IDM_EDIT_SELTOMATCHINGBRACE:
{
int iBrace2 = -1;
int iPos = SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0);
char c = (char)SendMessage(hwndEdit,SCI_GETCHARAT,iPos,0);
if (StrChrA("()[]{}",c))
iBrace2 = SendMessage(hwndEdit,SCI_BRACEMATCH,iPos,0);
// Try one before
else {
iPos = SendMessage(hwndEdit,SCI_POSITIONBEFORE,iPos,0);
c = (char)SendMessage(hwndEdit,SCI_GETCHARAT,iPos,0);
if (StrChrA("()[]{}",c))
iBrace2 = SendMessage(hwndEdit,SCI_BRACEMATCH,iPos,0);
}
if (iBrace2 != -1) {
if (iBrace2 > iPos)
SendMessage(hwndEdit,SCI_SETSEL,(WPARAM)iPos,(LPARAM)iBrace2+1);
else
SendMessage(hwndEdit,SCI_SETSEL,(WPARAM)iPos+1,(LPARAM)iBrace2);
}
}
break;
case IDM_EDIT_FIND:
if (!IsWindow(hDlgFindReplace))
hDlgFindReplace = EditFindReplaceDlg(hwndEdit,&efrData,FALSE);
else {
if (GetDlgItem(hDlgFindReplace,IDC_REPLACE)) {
SendMessage(hDlgFindReplace,WM_COMMAND,MAKELONG(IDMSG_SWITCHTOFIND,1),0);
DestroyWindow(hDlgFindReplace);
hDlgFindReplace = EditFindReplaceDlg(hwndEdit,&efrData,FALSE);
}
else {
SetForegroundWindow(hDlgFindReplace);
PostMessage(hDlgFindReplace,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hDlgFindReplace,IDC_FINDTEXT)),1);
}
}
break;
case IDM_EDIT_FINDNEXT:
case IDM_EDIT_FINDPREV:
case IDM_EDIT_SELTONEXT:
case IDM_EDIT_SELTOPREV:
case IDM_EDIT_REPLACENEXT:
if (SendMessage(hwndEdit,SCI_GETLENGTH,0,0) == 0)
break;
if (!lstrlenA(efrData.szFind)) {
if (LOWORD(wParam) != IDM_EDIT_REPLACENEXT)
SendMessage(hwnd,WM_COMMAND,MAKELONG(IDM_EDIT_FIND,1),0);
else
SendMessage(hwnd,WM_COMMAND,MAKELONG(IDM_EDIT_REPLACE,1),0);
}
else {
UINT cp = SendMessage(hwndEdit,SCI_GETCODEPAGE,0,0);
if (cpLastFind != cp) {
if (cp != SC_CP_UTF8) {
WCHAR wch[512];
MultiByteToWideChar(CP_UTF8,0,efrData.szFindUTF8,-1,wch,COUNTOF(wch));
WideCharToMultiByte(cp,0,wch,-1,efrData.szFind,COUNTOF(efrData.szFind),NULL,NULL);
MultiByteToWideChar(CP_UTF8,0,efrData.szReplaceUTF8,-1,wch,COUNTOF(wch));
WideCharToMultiByte(cp,0,wch,-1,efrData.szReplace,COUNTOF(efrData.szReplace),NULL,NULL);
}
else {
lstrcpyA(efrData.szFind,efrData.szFindUTF8);
lstrcpyA(efrData.szReplace,efrData.szReplaceUTF8);
}
}
cpLastFind = cp;
switch (LOWORD(wParam)) {
case IDM_EDIT_FINDNEXT:
EditFindNext(hwndEdit,&efrData,FALSE);
break;
case IDM_EDIT_FINDPREV:
EditFindPrev(hwndEdit,&efrData,FALSE);
break;
case IDM_EDIT_SELTONEXT:
EditFindNext(hwndEdit,&efrData,TRUE);
break;
case IDM_EDIT_SELTOPREV:
EditFindPrev(hwndEdit,&efrData,TRUE);
break;
case IDM_EDIT_REPLACENEXT:
if (bReplaceInitialized)
EditReplace(hwndEdit,&efrData);
else
SendMessage(hwnd,WM_COMMAND,MAKELONG(IDM_EDIT_REPLACE,1),0);
break;
}
}
break;
case IDM_EDIT_REPLACE:
if (!IsWindow(hDlgFindReplace))
hDlgFindReplace = EditFindReplaceDlg(hwndEdit,&efrData,TRUE);
else {
if (!GetDlgItem(hDlgFindReplace,IDC_REPLACE)) {
SendMessage(hDlgFindReplace,WM_COMMAND,MAKELONG(IDMSG_SWITCHTOREPLACE,1),0);
DestroyWindow(hDlgFindReplace);
hDlgFindReplace = EditFindReplaceDlg(hwndEdit,&efrData,TRUE);
}
else {
SetForegroundWindow(hDlgFindReplace);
PostMessage(hDlgFindReplace,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hDlgFindReplace,IDC_FINDTEXT)),1);
}
}
break;
case IDM_EDIT_GOTOLINE:
EditLinenumDlg(hwndEdit);
break;
case IDM_VIEW_SCHEME:
Style_SelectLexerDlg(hwndEdit);
UpdateStatusbar();
UpdateLineNumberWidth();
break;
case IDM_VIEW_USE2NDDEFAULT:
Style_ToggleUse2ndDefault(hwndEdit);
UpdateStatusbar();
UpdateLineNumberWidth();
break;
case IDM_VIEW_SCHEMECONFIG:
Style_ConfigDlg(hwndEdit);
UpdateStatusbar();
UpdateLineNumberWidth();
break;
case IDM_VIEW_FONT:
Style_SetDefaultFont(hwndEdit);
UpdateStatusbar();
UpdateLineNumberWidth();
break;
case IDM_VIEW_WORDWRAP:
fWordWrap = (fWordWrap) ? FALSE : TRUE;
if (!fWordWrap)
SendMessage(hwndEdit,SCI_SETWRAPMODE,SC_WRAP_NONE,0);
else
SendMessage(hwndEdit,SCI_SETWRAPMODE,(iWordWrapMode == 0) ? SC_WRAP_WORD : SC_WRAP_CHAR,0);
UpdateToolbar();
break;
case IDM_VIEW_WORDWRAPSETTINGS:
if (WordWrapSettingsDlg(hwnd,IDD_WORDWRAP,&iWordWrapIndent))
{
if (fWordWrap)
SendMessage(hwndEdit,SCI_SETWRAPMODE,(iWordWrapMode == 0) ? SC_WRAP_WORD : SC_WRAP_CHAR,0);
if (iWordWrapIndent == 5)
SendMessage(hwndEdit,SCI_SETWRAPINDENTMODE,SC_WRAPINDENT_SAME,0);
else if (iWordWrapIndent == 6)
SendMessage(hwndEdit,SCI_SETWRAPINDENTMODE,SC_WRAPINDENT_INDENT,0);
else {
int i = 0;
switch (iWordWrapIndent) {
case 1: i = 1; break;
case 2: i = 2; break;
case 3: i = (iIndentWidth) ? 1 * iIndentWidth : 1 * iTabWidth; break;
case 4: i = (iIndentWidth) ? 2 * iIndentWidth : 2 * iTabWidth; break;
}
SendMessage(hwndEdit,SCI_SETWRAPSTARTINDENT,i,0);
SendMessage(hwndEdit,SCI_SETWRAPINDENTMODE,SC_WRAPINDENT_FIXED,0);
}
if (bShowWordWrapSymbols) {
int wrapVisualFlags = 0;
int wrapVisualFlagsLocation = 0;
if (iWordWrapSymbols == 0)
iWordWrapSymbols = 22;
switch (iWordWrapSymbols%10) {
case 1: wrapVisualFlags |= SC_WRAPVISUALFLAG_END; wrapVisualFlagsLocation |= SC_WRAPVISUALFLAGLOC_END_BY_TEXT; break;
case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_END; break;
}
switch (((iWordWrapSymbols%100)-(iWordWrapSymbols%10))/10) {
case 1: wrapVisualFlags |= SC_WRAPVISUALFLAG_START; wrapVisualFlagsLocation |= SC_WRAPVISUALFLAGLOC_START_BY_TEXT; break;
case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_START; break;
}
SendMessage(hwndEdit,SCI_SETWRAPVISUALFLAGSLOCATION,wrapVisualFlagsLocation,0);
SendMessage(hwndEdit,SCI_SETWRAPVISUALFLAGS,wrapVisualFlags,0);
}
else {
SendMessage(hwndEdit,SCI_SETWRAPVISUALFLAGS,0,0);
}
}
break;
case IDM_VIEW_LONGLINEMARKER:
bMarkLongLines = (bMarkLongLines) ? FALSE: TRUE;
if (bMarkLongLines) {
SendMessage(hwndEdit,SCI_SETEDGEMODE,(iLongLineMode == EDGE_LINE)?EDGE_LINE:EDGE_BACKGROUND,0);
Style_SetLongLineColors(hwndEdit);
}
else
SendMessage(hwndEdit,SCI_SETEDGEMODE,EDGE_NONE,0);
UpdateStatusbar();
break;
case IDM_VIEW_LONGLINESETTINGS:
if (LongLineSettingsDlg(hwnd,IDD_LONGLINES,&iLongLinesLimit)) {
bMarkLongLines = TRUE;
SendMessage(hwndEdit,SCI_SETEDGEMODE,(iLongLineMode == EDGE_LINE)?EDGE_LINE:EDGE_BACKGROUND,0);
Style_SetLongLineColors(hwndEdit);
iLongLinesLimit = max(min(iLongLinesLimit,4096),0);
SendMessage(hwndEdit,SCI_SETEDGECOLUMN,iLongLinesLimit,0);
UpdateStatusbar();
iLongLinesLimitG = iLongLinesLimit;
}
break;
case IDM_VIEW_TABSASSPACES:
bTabsAsSpaces = (bTabsAsSpaces) ? FALSE : TRUE;
SendMessage(hwndEdit,SCI_SETUSETABS,!bTabsAsSpaces,0);
bTabsAsSpacesG = bTabsAsSpaces;
break;
case IDM_VIEW_TABSETTINGS:
if (TabSettingsDlg(hwnd,IDD_TABSETTINGS,NULL))
{
SendMessage(hwndEdit,SCI_SETUSETABS,!bTabsAsSpaces,0);
SendMessage(hwndEdit,SCI_SETTABINDENTS,bTabIndents,0);
iTabWidth = max(min(iTabWidth,256),1);
iIndentWidth = max(min(iIndentWidth,256),0);
SendMessage(hwndEdit,SCI_SETTABWIDTH,iTabWidth,0);
SendMessage(hwndEdit,SCI_SETINDENT,iIndentWidth,0);
bTabsAsSpacesG = bTabsAsSpaces;
iTabWidthG = iTabWidth;
iIndentWidthG = iIndentWidth;
if (SendMessage(hwndEdit,SCI_GETWRAPINDENTMODE,0,0) == SC_WRAPINDENT_FIXED) {
int i = 0;
switch (iWordWrapIndent) {
case 1: i = 1; break;
case 2: i = 2; break;
case 3: i = (iIndentWidth) ? 1 * iIndentWidth : 1 * iTabWidth; break;
case 4: i = (iIndentWidth) ? 2 * iIndentWidth : 2 * iTabWidth; break;
}
SendMessage(hwndEdit,SCI_SETWRAPSTARTINDENT,i,0);
}
}
break;
case IDM_VIEW_SHOWINDENTGUIDES:
bShowIndentGuides = (bShowIndentGuides) ? FALSE : TRUE;
Style_SetIndentGuides(hwndEdit,bShowIndentGuides);
break;
case IDM_VIEW_AUTOINDENTTEXT:
bAutoIndent = (bAutoIndent) ? FALSE : TRUE;
break;
case IDM_VIEW_LINENUMBERS:
bShowLineNumbers = (bShowLineNumbers) ? FALSE : TRUE;
UpdateLineNumberWidth();
//SendMessage(hwndEdit,SCI_SETMARGINWIDTHN,0,
// (bShowLineNumbers)?SendMessage(hwndEdit,SCI_TEXTWIDTH,STYLE_LINENUMBER,(LPARAM)"_999999_"):0);
break;
case IDM_VIEW_MARGIN:
bShowSelectionMargin = (bShowSelectionMargin) ? FALSE : TRUE;
SendMessage(hwndEdit,SCI_SETMARGINWIDTHN,1,(bShowSelectionMargin)?16:0);
break;
case IDM_VIEW_SHOWWHITESPACE:
bViewWhiteSpace = (bViewWhiteSpace) ? FALSE : TRUE;
SendMessage(hwndEdit,SCI_SETVIEWWS,(bViewWhiteSpace)?SCWS_VISIBLEALWAYS:SCWS_INVISIBLE,0);
break;
case IDM_VIEW_FOLDING:
bShowCodeFolding = (bShowCodeFolding) ? FALSE : TRUE;
SciCall_SetMarginWidth(MARGIN_FOLD_INDEX, (bShowCodeFolding) ? 11 : 0);
UpdateToolbar();
if (!bShowCodeFolding)
FoldToggleAll(EXPAND);
break;
case IDM_VIEW_TOGGLEFOLDS:
FoldToggleAll(SNIFF);
break;
case IDM_VIEW_SHOWEOLS:
bViewEOLs = (bViewEOLs) ? FALSE : TRUE;
SendMessage(hwndEdit,SCI_SETVIEWEOL,bViewEOLs,0);
break;
case IDM_VIEW_WORDWRAPSYMBOLS:
bShowWordWrapSymbols = (bShowWordWrapSymbols) ? 0 : 1;
if (bShowWordWrapSymbols) {
int wrapVisualFlags = 0;
int wrapVisualFlagsLocation = 0;
if (iWordWrapSymbols == 0)
iWordWrapSymbols = 22;
switch (iWordWrapSymbols%10) {
case 1: wrapVisualFlags |= SC_WRAPVISUALFLAG_END; wrapVisualFlagsLocation |= SC_WRAPVISUALFLAGLOC_END_BY_TEXT; break;
case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_END; break;
}
switch (((iWordWrapSymbols%100)-(iWordWrapSymbols%10))/10) {
case 1: wrapVisualFlags |= SC_WRAPVISUALFLAG_START; wrapVisualFlagsLocation |= SC_WRAPVISUALFLAGLOC_START_BY_TEXT; break;
case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_START; break;
}
SendMessage(hwndEdit,SCI_SETWRAPVISUALFLAGSLOCATION,wrapVisualFlagsLocation,0);
SendMessage(hwndEdit,SCI_SETWRAPVISUALFLAGS,wrapVisualFlags,0);
}
else {
SendMessage(hwndEdit,SCI_SETWRAPVISUALFLAGS,0,0);
}
break;
case IDM_VIEW_MATCHBRACES:
bMatchBraces = (bMatchBraces) ? FALSE : TRUE;
if (bMatchBraces) {
NMHDR nmhdr;
nmhdr.hwndFrom = hwndEdit;
nmhdr.idFrom = IDC_EDIT;
nmhdr.code = SCN_UPDATEUI;
SendMessage(hwnd,WM_NOTIFY,IDC_EDIT,(LPARAM)&nmhdr);
}
else
SendMessage(hwndEdit,SCI_BRACEHIGHLIGHT,(WPARAM)-1,(LPARAM)-1);
break;
case IDM_VIEW_AUTOCLOSETAGS:
bAutoCloseTags = (bAutoCloseTags) ? FALSE : TRUE;
break;
case IDM_VIEW_HILITECURRENTLINE:
bHiliteCurrentLine = (bHiliteCurrentLine) ? FALSE : TRUE;
Style_SetCurrentLineBackground(hwndEdit);
break;
case IDM_VIEW_ZOOMIN:
SendMessage(hwndEdit,SCI_ZOOMIN,0,0);
//UpdateLineNumberWidth();
break;
case IDM_VIEW_ZOOMOUT:
SendMessage(hwndEdit,SCI_ZOOMOUT,0,0);
//UpdateLineNumberWidth();
break;
case IDM_VIEW_RESETZOOM:
SendMessage(hwndEdit,SCI_SETZOOM,0,0);
//UpdateLineNumberWidth();
break;
case IDM_VIEW_TOOLBAR:
if (bShowToolbar) {
bShowToolbar = 0;
ShowWindow(hwndReBar,SW_HIDE);
}
else {
bShowToolbar = 1;
UpdateToolbar();
ShowWindow(hwndReBar,SW_SHOW);
}
SendWMSize(hwnd);
break;
case IDM_VIEW_CUSTOMIZETB:
SendMessage(hwndToolbar,TB_CUSTOMIZE,0,0);
break;
case IDM_VIEW_STATUSBAR:
if (bShowStatusbar) {
bShowStatusbar = 0;
ShowWindow(hwndStatus,SW_HIDE);
}
else {
bShowStatusbar = 1;
UpdateStatusbar();
ShowWindow(hwndStatus,SW_SHOW);
}
SendWMSize(hwnd);
break;
case IDM_VIEW_STICKYWINPOS:
bStickyWinPos = IniGetInt(L"Settings2",L"StickyWindowPosition",bStickyWinPos);
if (!bStickyWinPos) {
WINDOWPLACEMENT wndpl;
WCHAR tchPosX[32], tchPosY[32], tchSizeX[32], tchSizeY[32], tchMaximized[32];
int ResX = GetSystemMetrics(SM_CXSCREEN);
int ResY = GetSystemMetrics(SM_CYSCREEN);
// GetWindowPlacement
wndpl.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(hwndMain,&wndpl);
wi.x = wndpl.rcNormalPosition.left;
wi.y = wndpl.rcNormalPosition.top;
wi.cx = wndpl.rcNormalPosition.right - wndpl.rcNormalPosition.left;
wi.cy = wndpl.rcNormalPosition.bottom - wndpl.rcNormalPosition.top;
wi.max = (IsZoomed(hwndMain) || (wndpl.flags & WPF_RESTORETOMAXIMIZED));
wsprintf(tchPosX,L"%ix%i PosX",ResX,ResY);
wsprintf(tchPosY,L"%ix%i PosY",ResX,ResY);
wsprintf(tchSizeX,L"%ix%i SizeX",ResX,ResY);
wsprintf(tchSizeY,L"%ix%i SizeY",ResX,ResY);
wsprintf(tchMaximized,L"%ix%i Maximized",ResX,ResY);
bStickyWinPos = 1;
IniSetInt(L"Settings2",L"StickyWindowPosition",1);
IniSetInt(L"Window",tchPosX,wi.x);
IniSetInt(L"Window",tchPosY,wi.y);
IniSetInt(L"Window",tchSizeX,wi.cx);
IniSetInt(L"Window",tchSizeY,wi.cy);
IniSetInt(L"Window",tchMaximized,wi.max);
InfoBox(0,L"MsgStickyWinPos",IDS_STICKYWINPOS);
}
else {
bStickyWinPos = 0;
IniSetInt(L"Settings2",L"StickyWindowPosition",0);
}
break;
case IDM_VIEW_REUSEWINDOW:
if (IniGetInt(L"Settings2",L"ReuseWindow",0))
IniSetInt(L"Settings2",L"ReuseWindow",0);
else
IniSetInt(L"Settings2",L"ReuseWindow",1);
break;
case IDM_VIEW_SINGLEFILEINSTANCE:
if (IniGetInt(L"Settings2",L"SingleFileInstance",0))
IniSetInt(L"Settings2",L"SingleFileInstance",0);
else
IniSetInt(L"Settings2",L"SingleFileInstance",1);
break;
case IDM_VIEW_ALWAYSONTOP:
if (bAlwaysOnTop) {
bAlwaysOnTop = 0;
SetWindowPos(hwnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
}
else {
bAlwaysOnTop = 1;
SetWindowPos(hwnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
}
break;
case IDM_VIEW_MINTOTRAY:
bMinimizeToTray =(bMinimizeToTray) ? FALSE : TRUE;
break;
case IDM_VIEW_TRANSPARENT:
bTransparentMode =(bTransparentMode) ? FALSE : TRUE;
SetWindowTransparentMode(hwnd,bTransparentMode);
break;
case IDM_VIEW_SHOWFILENAMEONLY:
iPathNameFormat = 0;
lstrcpy(szTitleExcerpt,L"");
SetWindowTitle(hwnd,uidsAppTitle,fIsElevated,IDS_UNTITLED,szCurFile,
iPathNameFormat,bModified || iEncoding != iOriginalEncoding,
IDS_READONLY,bReadOnly,szTitleExcerpt);
break;
case IDM_VIEW_SHOWFILENAMEFIRST:
iPathNameFormat = 1;
lstrcpy(szTitleExcerpt,L"");
SetWindowTitle(hwnd,uidsAppTitle,fIsElevated,IDS_UNTITLED,szCurFile,
iPathNameFormat,bModified || iEncoding != iOriginalEncoding,
IDS_READONLY,bReadOnly,szTitleExcerpt);
break;
case IDM_VIEW_SHOWFULLPATH:
iPathNameFormat = 2;
lstrcpy(szTitleExcerpt,L"");
SetWindowTitle(hwnd,uidsAppTitle,fIsElevated,IDS_UNTITLED,szCurFile,
iPathNameFormat,bModified || iEncoding != iOriginalEncoding,
IDS_READONLY,bReadOnly,szTitleExcerpt);
break;
case IDM_VIEW_SHOWEXCERPT:
EditGetExcerpt(hwndEdit,szTitleExcerpt,COUNTOF(szTitleExcerpt));
SetWindowTitle(hwnd,uidsAppTitle,fIsElevated,IDS_UNTITLED,szCurFile,
iPathNameFormat,bModified || iEncoding != iOriginalEncoding,
IDS_READONLY,bReadOnly,szTitleExcerpt);
break;
case IDM_VIEW_NOSAVERECENT:
bSaveRecentFiles = (bSaveRecentFiles) ? FALSE : TRUE;
break;
case IDM_VIEW_NOSAVEFINDREPL:
bSaveFindReplace = (bSaveFindReplace) ? FALSE : TRUE;
break;
case IDM_VIEW_SAVEBEFORERUNNINGTOOLS:
bSaveBeforeRunningTools = (bSaveBeforeRunningTools) ? FALSE : TRUE;
break;
case IDM_VIEW_CHANGENOTIFY:
if (ChangeNotifyDlg(hwnd))
InstallFileWatching(szCurFile);
break;
case IDM_VIEW_NOESCFUNC:
iEscFunction = 0;
break;
case IDM_VIEW_ESCMINIMIZE:
iEscFunction = 1;
break;
case IDM_VIEW_ESCEXIT:
iEscFunction = 2;
break;
case IDM_VIEW_SAVESETTINGS:
bSaveSettings = (bSaveSettings) ? FALSE : TRUE;
break;
case IDM_VIEW_SAVESETTINGSNOW:
{
BOOL bCreateFailure = FALSE;
if (lstrlen(szIniFile) == 0) {
if (lstrlen(szIniFile2) > 0) {
if (CreateIniFileEx(szIniFile2)) {
lstrcpy(szIniFile,szIniFile2);
lstrcpy(szIniFile2,L"");
}
else
bCreateFailure = TRUE;
}
else
break;
}
if (!bCreateFailure) {
if (WritePrivateProfileString(L"Settings",L"WriteTest",L"ok",szIniFile)) {
BeginWaitCursor();
StatusSetTextID(hwndStatus,STATUS_HELP,IDS_SAVINGSETTINGS);
StatusSetSimple(hwndStatus,TRUE);
InvalidateRect(hwndStatus,NULL,TRUE);
UpdateWindow(hwndStatus);
SaveSettings(TRUE);
StatusSetSimple(hwndStatus,FALSE);
EndWaitCursor();
MsgBox(MBINFO,IDS_SAVEDSETTINGS);
}
else {
dwLastIOError = GetLastError();
MsgBox(MBINFO,IDS_WRITEINI_FAIL);
}
}
else
MsgBox(MBINFO,IDS_CREATEINI_FAIL);
}
break;
case IDM_HELP_ABOUT:
ThemedDialogBox(g_hInstance,MAKEINTRESOURCE(IDD_ABOUT),
hwnd,AboutDlgProc);
break;
case CMD_ESCAPE:
if (iEscFunction == 1)
SendMessage(hwnd,WM_SYSCOMMAND,SC_MINIMIZE,0);
else if (iEscFunction == 2)
SendMessage(hwnd,WM_CLOSE,0,0);
break;
case CMD_SHIFTESC:
if (FileSave(TRUE,FALSE,FALSE,FALSE))
SendMessage(hwnd,WM_CLOSE,0,0);
break;
// Newline with toggled auto indent setting
case CMD_CTRLENTER:
bAutoIndent = (bAutoIndent) ? 0 : 1;
SendMessage(hwndEdit,SCI_NEWLINE,0,0);
bAutoIndent = (bAutoIndent) ? 0 : 1;
break;
case CMD_CTRLBACK:
{
int iPos = SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0);
int iAnchor = SendMessage(hwndEdit,SCI_GETANCHOR,0,0);
int iLine = SendMessage(hwndEdit,SCI_LINEFROMPOSITION,(WPARAM)iPos,0);
int iStartPos = SendMessage(hwndEdit,SCI_POSITIONFROMLINE,(WPARAM)iLine,0);
int iEndPos = SendMessage(hwndEdit,SCI_GETLINEENDPOSITION,(WPARAM)iLine,0);
int iIndentPos = SendMessage(hwndEdit,SCI_GETLINEINDENTPOSITION,(WPARAM)iLine,0);
if (iPos != iAnchor)
SendMessage(hwndEdit,SCI_SETSEL,(WPARAM)iPos,(LPARAM)iPos);
else {
if (iPos == iStartPos)
SendMessage(hwndEdit,SCI_DELETEBACK,0,0);
else if (iPos <= iIndentPos)
SendMessage(hwndEdit,SCI_DELLINELEFT,0,0);
else
SendMessage(hwndEdit,SCI_DELWORDLEFT,0,0);
}
}
break;
case CMD_CTRLDEL:
{
int iPos = SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0);
int iAnchor = SendMessage(hwndEdit,SCI_GETANCHOR,0,0);
int iLine = SendMessage(hwndEdit,SCI_LINEFROMPOSITION,(WPARAM)iPos,0);
int iStartPos = SendMessage(hwndEdit,SCI_POSITIONFROMLINE,(WPARAM)iLine,0);
int iEndPos = SendMessage(hwndEdit,SCI_GETLINEENDPOSITION,(WPARAM)iLine,0);
if (iPos != iAnchor)
SendMessage(hwndEdit,SCI_SETSEL,(WPARAM)iPos,(LPARAM)iPos);
else {
if (iStartPos != iEndPos)
SendMessage(hwndEdit,SCI_DELWORDRIGHT,0,0);
else // iStartPos == iEndPos
SendMessage(hwndEdit,SCI_LINEDELETE,0,0);
}
}
break;
case CMD_CTRLTAB:
SendMessage(hwndEdit,SCI_SETTABINDENTS,FALSE,0);
SendMessage(hwndEdit,SCI_SETUSETABS,TRUE,0);
SendMessage(hwndEdit,SCI_TAB,0,0);
SendMessage(hwndEdit,SCI_SETUSETABS,!bTabsAsSpaces,0);
SendMessage(hwndEdit,SCI_SETTABINDENTS,bTabIndents,0);
break;
case CMD_RELOADANSI:
{
WCHAR tchCurFile2[MAX_PATH];
if (lstrlen(szCurFile)) {
iSrcEncoding = CPI_DEFAULT;
lstrcpy(tchCurFile2,szCurFile);
FileLoad(FALSE,FALSE,TRUE,FALSE,tchCurFile2);
}
}
break;
case CMD_RELOADOEM:
{
WCHAR tchCurFile2[MAX_PATH];
if (lstrlen(szCurFile)) {
iSrcEncoding = CPI_OEM;
lstrcpy(tchCurFile2,szCurFile);
FileLoad(FALSE,FALSE,TRUE,FALSE,tchCurFile2);
}
}
break;
case CMD_RELOADASCIIASUTF8:
{
WCHAR tchCurFile2[MAX_PATH];
BOOL _bLoadASCIIasUTF8 = bLoadASCIIasUTF8;
if (lstrlen(szCurFile)) {
bLoadASCIIasUTF8 = 1;
lstrcpy(tchCurFile2,szCurFile);
FileLoad(FALSE,FALSE,TRUE,FALSE,tchCurFile2);
bLoadASCIIasUTF8 = _bLoadASCIIasUTF8;
}
}
break;
case CMD_RELOADNOFILEVARS:
{
WCHAR tchCurFile2[MAX_PATH];
if (lstrlen(szCurFile)) {
int _fNoFileVariables = fNoFileVariables;
BOOL _bNoEncodingTags = bNoEncodingTags;
fNoFileVariables = 1;
bNoEncodingTags = 1;
lstrcpy(tchCurFile2,szCurFile);
FileLoad(FALSE,FALSE,TRUE,FALSE,tchCurFile2);
fNoFileVariables = _fNoFileVariables;
bNoEncodingTags = _bNoEncodingTags;
}
}
break;
case CMD_LEXDEFAULT:
Style_SetDefaultLexer(hwndEdit);
UpdateStatusbar();
UpdateLineNumberWidth();
break;
case CMD_LEXHTML:
Style_SetHTMLLexer(hwndEdit);
UpdateStatusbar();
UpdateLineNumberWidth();
break;
case CMD_LEXXML:
Style_SetXMLLexer(hwndEdit);
UpdateStatusbar();
UpdateLineNumberWidth();
break;
case CMD_TIMESTAMPS:
{
WCHAR wchFind[256] = {0};
WCHAR wchTemplate[256] = {0};
WCHAR *pwchSep;
WCHAR wchReplace[256];
SYSTEMTIME st;
struct tm sst;
UINT cp;
EDITFINDREPLACE efrTS = { "", "", "", "", SCFIND_REGEXP, 0, 0, 0, 0, 0, hwndEdit };
IniGetString(L"Settings2",L"TimeStamp",L"\\$Date:[^\\$]+\\$ | $Date: %Y/%m/%d %H:%M:%S $",wchFind,COUNTOF(wchFind));
if (pwchSep = StrChr(wchFind,L'|')) {
lstrcpy(wchTemplate,pwchSep+1);
*pwchSep = 0;
}
StrTrim(wchFind,L" ");
StrTrim(wchTemplate,L" ");
if (lstrlen(wchFind) == 0 || lstrlen(wchTemplate) == 0)
break;
GetLocalTime(&st);
sst.tm_isdst = -1;
sst.tm_sec = (int)st.wSecond;
sst.tm_min = (int)st.wMinute;
sst.tm_hour = (int)st.wHour;
sst.tm_mday = (int)st.wDay;
sst.tm_mon = (int)st.wMonth - 1;
sst.tm_year = (int)st.wYear - 1900;
sst.tm_wday = (int)st.wDayOfWeek;
mktime(&sst);
wcsftime(wchReplace,COUNTOF(wchReplace),wchTemplate,&sst);
cp = SendMessage(hwndEdit,SCI_GETCODEPAGE,0,0);
WideCharToMultiByte(cp,0,wchFind,-1,efrTS.szFind,COUNTOF(efrTS.szFind),NULL,NULL);
WideCharToMultiByte(cp,0,wchReplace,-1,efrTS.szReplace,COUNTOF(efrTS.szReplace),NULL,NULL);
if (SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0) !=
SendMessage(hwndEdit,SCI_GETSELECTIONEND,0,0))
EditReplaceAllInSelection(hwndEdit,&efrTS,TRUE);
else
EditReplaceAll(hwndEdit,&efrTS,TRUE);
}
break;
case CMD_WEBACTION1:
case CMD_WEBACTION2:
{
BOOL bCmdEnabled = FALSE;
LPWSTR lpszTemplateName;
WCHAR szCmdTemplate[256];
char mszSelection[512] = { 0 };
DWORD cchSelection;
char *lpsz;
LPWSTR lpszCommand;
LPWSTR lpszArgs;
SHELLEXECUTEINFO sei;
WCHAR wchDirectory[MAX_PATH] = L"";
lpszTemplateName = (LOWORD(wParam) == CMD_WEBACTION1) ? L"WebTemplate1" : L"WebTemplate2";
bCmdEnabled = IniGetString(L"Settings2",lpszTemplateName,L"",szCmdTemplate,COUNTOF(szCmdTemplate));
if (bCmdEnabled) {
cchSelection = SendMessage(hwndEdit,SCI_GETSELECTIONEND,0,0) -
SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0);
if (cchSelection > 0 && cchSelection <= 500 && SendMessage(hwndEdit,SCI_GETSELTEXT,0,0) < COUNTOF(mszSelection))
{
SendMessage(hwndEdit,SCI_GETSELTEXT,0,(LPARAM)mszSelection);
mszSelection[cchSelection] = 0; // zero terminate
// Check lpszSelection and truncate bad WCHARs
lpsz = StrChrA(mszSelection,13);
if (lpsz) *lpsz = '\0';
lpsz = StrChrA(mszSelection,10);
if (lpsz) *lpsz = '\0';
lpsz = StrChrA(mszSelection,9);
if (lpsz) *lpsz = '\0';
if (lstrlenA(mszSelection)) {
WCHAR wszSelection[512];
UINT uCP = (SendMessage(hwndEdit,SCI_GETCODEPAGE,0,0) == SC_CP_UTF8) ? CP_UTF8 : CP_ACP;
MultiByteToWideChar(uCP,0,mszSelection,-1,wszSelection,COUNTOF(wszSelection));
lpszCommand = GlobalAlloc(GPTR,sizeof(WCHAR)*(512+COUNTOF(szCmdTemplate)+MAX_PATH+32));
wsprintf(lpszCommand,szCmdTemplate,wszSelection);
ExpandEnvironmentStringsEx(lpszCommand,GlobalSize(lpszCommand)/sizeof(WCHAR));
lpszArgs = GlobalAlloc(GPTR,GlobalSize(lpszCommand));
ExtractFirstArgument(lpszCommand,lpszCommand,lpszArgs);
if (lstrlen(szCurFile)) {
lstrcpy(wchDirectory,szCurFile);
PathRemoveFileSpec(wchDirectory);
}
ZeroMemory(&sei,sizeof(SHELLEXECUTEINFO));
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.fMask = /*SEE_MASK_NOZONECHECKS*/0x00800000;
sei.hwnd = NULL;
sei.lpVerb = NULL;
sei.lpFile = lpszCommand;
sei.lpParameters = lpszArgs;
sei.lpDirectory = wchDirectory;
sei.nShow = SW_SHOWNORMAL;
ShellExecuteEx(&sei);
GlobalFree(lpszCommand);
GlobalFree(lpszArgs);
}
}
}
}
break;
case CMD_FINDNEXTSEL:
case CMD_FINDPREVSEL:
case IDM_EDIT_SAVEFIND:
{
int cchSelection = SendMessage(hwndEdit,SCI_GETSELECTIONEND,0,0) -
SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0);
if (cchSelection == 0)
{
SendMessage(hwnd,WM_COMMAND,MAKELONG(IDM_EDIT_SELECTWORD,1),0);
cchSelection = SendMessage(hwndEdit,SCI_GETSELECTIONEND,0,0) -
SendMessage(hwndEdit,SCI_GETSELECTIONSTART,0,0);
}
if (cchSelection > 0 && cchSelection <= 500 && SendMessage(hwndEdit,SCI_GETSELTEXT,0,0) < 512)
{
char mszSelection[512];
char *lpsz;
SendMessage(hwndEdit,SCI_GETSELTEXT,0,(LPARAM)mszSelection);
mszSelection[cchSelection] = 0; // zero terminate
// Check lpszSelection and truncate newlines
lpsz = StrChrA(mszSelection,'\n');
if (lpsz) *lpsz = '\0';
lpsz = StrChrA(mszSelection,'\r');
if (lpsz) *lpsz = '\0';
cpLastFind = SendMessage(hwndEdit,SCI_GETCODEPAGE,0,0);
lstrcpyA(efrData.szFind,mszSelection);
if (cpLastFind != SC_CP_UTF8)
{
WCHAR wszBuf[512];
MultiByteToWideChar(cpLastFind,0,mszSelection,-1,wszBuf,COUNTOF(wszBuf));
WideCharToMultiByte(CP_UTF8,0,wszBuf,-1,efrData.szFindUTF8,COUNTOF(efrData.szFindUTF8),NULL,NULL);
}
else
lstrcpyA(efrData.szFindUTF8,mszSelection);
efrData.fuFlags &= (~SCFIND_REGEXP);
efrData.bTransformBS = FALSE;
switch (LOWORD(wParam)) {
case IDM_EDIT_SAVEFIND:
break;
case CMD_FINDNEXTSEL:
EditFindNext(hwndEdit,&efrData,FALSE);
break;
case CMD_FINDPREVSEL:
EditFindPrev(hwndEdit,&efrData,FALSE);
break;
}
}
}
break;
case CMD_INCLINELIMIT:
case CMD_DECLINELIMIT:
if (!bMarkLongLines)
SendMessage(hwnd,WM_COMMAND,MAKELONG(IDM_VIEW_LONGLINEMARKER,1),0);
else {
if (LOWORD(wParam) == CMD_INCLINELIMIT)
iLongLinesLimit++;
else
iLongLinesLimit--;
iLongLinesLimit = max(min(iLongLinesLimit,4096),0);
SendMessage(hwndEdit,SCI_SETEDGECOLUMN,iLongLinesLimit,0);
UpdateStatusbar();
iLongLinesLimitG = iLongLinesLimit;
}
break;
case CMD_STRINGIFY:
EditEncloseSelection(hwndEdit,L"'",L"'");
break;
case CMD_STRINGIFY2:
EditEncloseSelection(hwndEdit,L"\"",L"\"");
break;
case CMD_EMBRACE:
EditEncloseSelection(hwndEdit,L"(",L")");
break;
case CMD_EMBRACE2:
EditEncloseSelection(hwndEdit,L"[",L"]");
break;
case CMD_EMBRACE3:
EditEncloseSelection(hwndEdit,L"{",L"}");
break;
case CMD_EMBRACE4:
EditEncloseSelection(hwndEdit,L"`",L"`");
break;
case CMD_INCREASENUM:
EditModifyNumber(hwndEdit,TRUE);
break;
case CMD_DECREASENUM:
EditModifyNumber(hwndEdit,FALSE);
break;
case CMD_TOGGLETITLE:
EditGetExcerpt(hwndEdit,szTitleExcerpt,COUNTOF(szTitleExcerpt));
SetWindowTitle(hwnd,uidsAppTitle,fIsElevated,IDS_UNTITLED,szCurFile,
iPathNameFormat,bModified || iEncoding != iOriginalEncoding,
IDS_READONLY,bReadOnly,szTitleExcerpt);
break;
case CMD_JUMP2SELSTART:
if (SC_SEL_RECTANGLE != SendMessage(hwnd,SCI_GETSELECTIONMODE,0,0)) {
int iAnchorPos = SendMessage(hwndEdit,SCI_GETANCHOR,0,0);
int iCursorPos = SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0);
if (iCursorPos > iAnchorPos) {
SendMessage(hwndEdit,SCI_SETSEL,iCursorPos,iAnchorPos);
SendMessage(hwndEdit,SCI_CHOOSECARETX,0,0);
}
}
break;
case CMD_JUMP2SELEND:
if (SC_SEL_RECTANGLE != SendMessage(hwnd,SCI_GETSELECTIONMODE,0,0)) {
int iAnchorPos = SendMessage(hwndEdit,SCI_GETANCHOR,0,0);
int iCursorPos = SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0);
if (iCursorPos < iAnchorPos) {
SendMessage(hwndEdit,SCI_SETSEL,iCursorPos,iAnchorPos);
SendMessage(hwndEdit,SCI_CHOOSECARETX,0,0);
}
}
break;
case CMD_COPYPATHNAME: {
WCHAR *pszCopy;
WCHAR tchUntitled[32];
if (lstrlen(szCurFile))
pszCopy = szCurFile;
else {
GetString(IDS_UNTITLED,tchUntitled,COUNTOF(tchUntitled));
pszCopy = tchUntitled;
}
if (OpenClipboard(hwnd)) {
HANDLE hData;
WCHAR *pData;
EmptyClipboard();
hData = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,sizeof(WCHAR) * (lstrlen(pszCopy) + 1));
pData = GlobalLock(hData);
StrCpyN(pData,pszCopy,GlobalSize(hData) / sizeof(WCHAR));
GlobalUnlock(hData);
SetClipboardData(CF_UNICODETEXT,hData);
CloseClipboard();
}
}
break;
case CMD_OPENINIFILE:
if (lstrlen(szIniFile)) {
CreateIniFile();
FileLoad(FALSE,FALSE,FALSE,FALSE,szIniFile);
}
break;