📄 x3.c
字号:
/*
Copyright 2001-2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
You may contact the author at:
mailto::camille@bluegrass.net
or by snail mail at:
David Lindauer
850 Washburn Ave Apt 99
Louisville, KY 40222
**********************************************************************
EDITOR.C superclasses the xedit control, to provide functionality
such as the right-click menu, loading and saving files to disk, and
loading and saving the parts of the project file related to edit windows.
IT also holds the code for the find and find and replace popups.
**********************************************************************
*/
#include <windows.h>
#include <commctrl.h>
#include <commdlg.h>
#include <richedit.h>
#include <stdio.h>
#include "header.h"
#include <ctype.h>
#include "..\gnu_regex\regex.h"
#ifndef __CCDL__
#ifndef LVS_EX_CHECKBOXES
#define LVS_EX_CHECKBOXES 4
#define LVM_FIRST 0x1000
#define LVM_SETEXTENDEDLISTVIEWSTYLE (LVM_FIRST + 54)
// optional wParam == mask
#define ListView_SetExtendedListViewStyle(hwndLV, dw)\
(DWORD)SendMessage((hwndLV), LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dw)
#define ListView_SetCheckState(hwndLV, i, fCheck) \
ListView_SetItemState(hwndLV, i, INDEXTOSTATEIMAGEMASK((fCheck)?2:1),
LVIS_STATEIMAGEMASK)
#define ListView_GetCheckState(hwndLV, i) \
((((UINT)(SendMessage((hwndLV), LVM_GETITEMSTATE, (WPARAM)(i),
LVIS_STATEIMAGEMASK))) >> 12) -1)
#endif
#endif
#define EDITOR_OFFSET 35
HWND CreateDrawWindow(DWINFO *baseinfo);
extern HWND hwndSourceTab;
extern LOGFONT EditFont;
extern HINSTANCE hInstance;
extern HWND hwndClient, hwndStatus, hwndFrame, hwndASM;
extern HANDLE hMenuMain;
extern int iFindMessage;
extern char szSourceFilter[];
extern COLORREF keywordColor;
extern COLORREF numberColor;
extern COLORREF commentColor;
extern COLORREF stringColor;
extern COLORREF escapeColor;
extern COLORREF backgroundColor;
extern COLORREF textColor;
extern int custColors[16];
extern enum DebugState uState;
extern PROJLIST *projectList;
extern int tabs;
HWND hwndFind;
char szDrawClassName[] = "xccDrawClass";
char szUntitled[] = "Untitled";
int childxpos, childypos;
int numberofdrawwindows;
int editFlags = BACKUP_FILES | BACKUP_PROJECTS;
int findflags = 12;
int replaceflags = 4;
DWINFO *newInfo;
HANDLE children[MAX_CHILDREN];
char *findhist1[MAX_COMBO_HISTORY];
char *findhist2[MAX_COMBO_HISTORY];
char *replacehist[MAX_COMBO_HISTORY];
static HBITMAP pcBitmap, stoppcBitmap;
static HBITMAP tagBmps[TAG_MAX];
static char finding, findbuffer[256], replacebuffer[256], findbuffer2[256];
static FINDREPLACE find;
static FINDREPLACE replace;
static int findpos, found, lastfound;
int xstricmpz(char *str1, char *str2)
{
while (*str2)
if (toupper(*str1++) != toupper(*str2++))
return 1;
return *str1 != *str2;
} int xstricmp(char *str1, char *str2)
{
while (*str2)
if (toupper(*str1++) != toupper(*str2++))
return 1;
return 0;
}
//-------------------------------------------------------------------------
char *stristr(char *str1, char *str2)
{
int l = strlen(str2);
while (*str1)
{
if (!xstricmp(str1, str2))
return str1;
str1++;
}
return 0;
}
//-------------------------------------------------------------------------
void ApplyFontSettings(LPLOGFONT lf)
{
int i;
memcpy(&EditFont, lf, sizeof(EditFont));
for (i = 0; i < numberofdrawwindows; i++)
{
HFONT fnt = CreateFontIndirect(&EditFont);
PostMessage(GetDlgItem(children[i], ID_EDITCHILD), WM_SETFONT, (WPARAM)
fnt, 0);
}
}
//-------------------------------------------------------------------------
void InvalidateByName(char *name)
{
int i;
DWINFO info;
strcpy(info.dwName, name);
for (i = 0; i < numberofdrawwindows; i++)
if (SendMessage(children[i], WM_COMMAND, ID_QUERYHASFILE, (LPARAM)
&info))
InvalidateRect(children[i], 0, 0);
}
//-------------------------------------------------------------------------
void ApplyEditSettings(void)
{
int i;
for (i = 0; i < numberofdrawwindows; i++)
PostMessage(GetDlgItem(children[i], ID_EDITCHILD), WM_SETEDITORSETTINGS,
0, 0);
}
//-------------------------------------------------------------------------
int ApplyBreakAddress(char *module, int linenum)
{
char nmodule[260];
int i;
nmodule[0] = 0;
TagBreakpoint(module, linenum);
if (linenum)
{
char *p;
static DWINFO x;
FindModuleName(nmodule, module);
strcpy(x.dwName, nmodule);
p = strrchr(nmodule, '\\');
if (p)
strcpy(x.dwTitle, p + 1);
else
strcpy(x.dwTitle, nmodule);
x.dwLineNo = BPLine(x.dwName);
x.logMRU = TRUE;
CreateDrawWindow(&x);
}
}
//-------------------------------------------------------------------------
static int FileAttributes(char *name)
{
int rv = GetFileAttributes(name);
if (rv == - 1)
{
if (GetLastError() == ERROR_FILE_NOT_FOUND)
return 0;
return - 1; // any other error, it is read only file
}
else
return rv;
}
//-------------------------------------------------------------------------
static int CreateFileSaveData(HWND hwnd, int changed)
{
int items = 0;
int i;
LV_ITEM item;
RECT r;
HWND hwndLV = GetDlgItem(hwnd, IDC_FILELIST);
LV_COLUMN lvC;
ListView_SetExtendedListViewStyle(hwndLV, LVS_EX_CHECKBOXES);
GetWindowRect(hwndLV, &r);
lvC.mask = LVCF_WIDTH | LVCF_SUBITEM;
lvC.cx = 20;
lvC.iSubItem = 0;
ListView_InsertColumn(hwndLV, 0, &lvC);
lvC.mask = LVCF_WIDTH | LVCF_SUBITEM;
lvC.cx = 32;
lvC.iSubItem = 1;
ListView_InsertColumn(hwndLV, 1, &lvC);
lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_SUBITEM;
lvC.fmt = LVCFMT_LEFT;
lvC.cx = r.right - r.left - 56;
lvC.iSubItem = 2;
ListView_InsertColumn(hwndLV, 2, &lvC);
for (i = 0; i < numberofdrawwindows; i++)
{
DWINFO *ptr = (DWINFO*)GetWindowLong(children[i], 0);
int rv;
FILETIME time;
if (changed)
{
int a = FileAttributes(ptr->dwName);
rv = FALSE;
if (a == - 1)
a = 0;
if (FileTime(&time, ptr->dwName))
{
rv = (time.dwHighDateTime != ptr->time.dwHighDateTime ||
time.dwLowDateTime != ptr->time.dwLowDateTime);
ptr->time = time;
}
if (a &FILE_ATTRIBUTE_READONLY)
SendMessage(ptr->dwHandle, EM_SETREADONLY, 1, 0);
else
SendMessage(ptr->dwHandle, EM_SETREADONLY, 0, 0);
}
else
rv = SendMessage(ptr->dwHandle, EM_GETMODIFY, 0, 0);
if (rv)
{
int v;
item.iItem = items++;
item.iSubItem = 0;
item.mask = LVIF_PARAM;
item.lParam = (LPARAM)i;
item.pszText = ""; // LPSTR_TEXTCALLBACK ;
v = ListView_InsertItem(hwndLV, &item);
ListView_SetCheckState(hwndLV, v, TRUE);
}
}
return items;
}
//-------------------------------------------------------------------------
static void ParseFileSaveData(HWND hwnd, UINT wParam, int changed)
{
LV_ITEM item;
HWND hwndLV = GetDlgItem(hwnd, IDC_FILELIST);
int i;
for (i = 0;; i++)
{
DWINFO *ptr;
item.iItem = i;
item.iSubItem = 0;
item.mask = LVIF_PARAM;
if (!ListView_GetItem(hwndLV, &item))
break;
ptr = (DWINFO*)GetWindowLong(children[item.lParam], 0);
switch (wParam)
{
case IDOK:
if (changed)
{
if (ListView_GetCheckState(hwndLV, i))
LoadFile(children[item.lParam], ptr);
}
else
if (ListView_GetCheckState(hwndLV, i))
SendMessage(children[item.lParam], WM_COMMAND, IDM_SAVE,
0);
else
{
TagLinesAdjust(ptr->dwName, TAGM_DISCARDFILE);
}
break;
case IDC_SELECTALL:
case IDC_DESELECTALL:
ListView_SetCheckState(hwndLV, i, wParam == IDC_SELECTALL ? 1 :
0);
break;
}
}
}
//-------------------------------------------------------------------------
long APIENTRY FileSaveProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
switch (message)
{
case WM_INITDIALOG:
if (!CreateFileSaveData(hwnd, FALSE))
EndDialog(hwnd, 1);
else
CenterWindow(hwnd);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -