⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editor.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 5 页
字号:
                                if (isdigit(index))
                                {
                                    index -= '0';
                                    if (dta && index <= regnum)
                                    {
                                        int j;
                                        for (j = registers->start[index]; j <
                                            registers->end[index] && dest <
                                            255; j++)
                                            buf[dest++] = dta[j];
                                    }
                                }
                                else
                                    buf[dest++] = replace->lpstrReplaceWith[i];
                            }
                        }
                        else
                            buf[dest++] = replace->lpstrReplaceWith[i];
                    }
                    free(dta);
                    buf[dest] = 0;
                }
                else
                {
                    strcpy(buf, replace->lpstrReplaceWith);
                }
                if (selected)
                {
                    a.max += strlen(replace->lpstrReplaceWith) - strlen(replace
                        ->lpstrFindWhat);
                }
                SendMessage(GetDlgItem(hwnd, ID_EDITCHILD), EM_REPLACESEL, 1, 
                    (LPARAM)buf);
                UpdateWindow(GetDlgItem(hwnd, ID_EDITCHILD));
            }
            findpos += strlen(replace->lpstrReplaceWith) - strlen(replace
                ->lpstrFindWhat);
            found = FALSE;
        }
        if (!(flags &FR_REPLACEALL))
        if (flags &FR_REPLACE)
        {
            flags &= ~FR_REPLACE;
            flags |= FR_FINDNEXT;
        }
        else
        {
            SendMessage(GetDlgItem(hwnd, ID_EDITCHILD), EM_HIDESELECTION, 0, 0);
            SendMessage(hwnd, WM_COMMAND, ID_REDRAWSTATUS, 0);
            return ;
        }
    }
}

//-------------------------------------------------------------------------

void drawParams(DWINFO *info, HWND hwnd)
{
    char buf[512];
    int start, ins, col, sel;
    int readonly = SendMessage(info->dwHandle, EM_GETREADONLY, 0, 0);
    int mod = SendMessage(info->dwHandle, EM_GETMODIFY, 0, 0);
    charinfo a;
    SendMessage(info->dwHandle, EM_GETSEL, (WPARAM) &sel, 0);
    SendMessage(GetDlgItem(hwnd, ID_EDITCHILD), EM_EXGETSEL, 0, (LPARAM) &a);
    sel = a.min;
    start = SendMessage(info->dwHandle, EM_EXLINEFROMCHAR, 0, sel);
    ins = SendMessage(info->dwHandle, EM_GETINSERTSTATUS, 0, 0);
    col = SendMessage(info->dwHandle, EM_GETCOLUMN, 0, 0);
    sprintf(buf, "Line: %d", start + 1);
    SendMessage(hwndStatus, SB_SETTEXT, 1, (LPARAM)buf);
    sprintf(buf, "Col: %d", col + 1);
    SendMessage(hwndStatus, SB_SETTEXT, 2, (LPARAM)buf);
    SendMessage(hwndStatus, SB_SETTEXT, 3, (LPARAM)(ins ? "INS" : "OVR"));
    if (readonly)
        SendMessage(hwndStatus, SB_SETTEXT, 4, (LPARAM)("READ-ONLY"));
    else
        SendMessage(hwndStatus, SB_SETTEXT, 4, (LPARAM)(mod ? "MODIFIED" : 
            "    "));
    SendMessage(hwndStatus, SB_SETTEXT, 0 | SBT_NOBORDERS, (LPARAM)"    ");

    strcpy(buf, info->dwTitle);
    if (mod)
        strcat(buf, " *");
    SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)buf);

}

//-------------------------------------------------------------------------

void eraseParams(HWND hwnd)
{
    SendMessage(hwndStatus, SB_SETTEXT, 1, (LPARAM)"    ");
    SendMessage(hwndStatus, SB_SETTEXT, 2, (LPARAM)"    ");
    SendMessage(hwndStatus, SB_SETTEXT, 3, (LPARAM)"    ");
    SendMessage(hwndStatus, SB_SETTEXT, 4, (LPARAM)"    ");

}

//-------------------------------------------------------------------------

int PaintBreakpoints(HWND hwnd, HDC dc, PAINTSTRUCT *paint, RECT *rcl)
{
    HBRUSH graybrush, graybrush1;
    RECT r, r1;
    int i;
    HDC hMemDC = CreateCompatibleDC(dc);
    DWINFO *ptr = (DWINFO*)GetWindowLong(hwnd, 0);
    int linenum = SendMessage(ptr->dwHandle, EM_GETFIRSTVISIBLELINE, 0, 0) + 1;
    int chpos1 = SendMessage(ptr->dwHandle, EM_LINEINDEX, linenum, 0);
    int ypos;
    int lines, offset = 0;
    int height;
    short *lt;
    int lc;
    POINTL pt;
    int bpline = BPLine(ptr->dwName);
    SendMessage(ptr->dwHandle, EM_POSFROMCHAR, (WPARAM) &pt, chpos1);
    ypos = pt.y;

    SendMessage(ptr->dwHandle, EM_GETRECT, 0, (LPARAM) &r1);
    lines = r1.bottom / (height = SendMessage(ptr->dwHandle, EM_GETTEXTHEIGHT,
        0, 0));

    if (ypos < height)
        offset = ypos - height;

    graybrush = CreateSolidBrush(GetSysColor(COLOR_3DFACE));
    FillRect(dc, rcl, graybrush);
    DeleteObject(graybrush);
    if (uState != notDebugging)
    {
        lt = GetLineTable(ptr->dwName, &lc);
        if (lt)
        {
            int j = 0;
            graybrush1 = GetStockObject(BLACK_BRUSH);
            r.left = 28;
            r.right = 32;
            for (i = linenum; i <= linenum + lines; i++)
            {
                int oldline = TagOldLine(ptr->dwName, i);
                while (lt[j] < oldline)
                    j++;
                if (lt[j] == oldline)
                {
                    r.top = offset + (i - linenum) *height;
                    r.bottom = r.top + height;
                    FillRect(dc, &r, graybrush1);
                }
            }
        }
    }
    for (i = linenum; i <= linenum + lines; i++)
    {
        int type = IsTagged(ptr->dwName, i);
        switch (type)
        {
            case TAG_BP:
                if (bpline == i)
                {
                    SelectObject(hMemDC, stoppcBitmap);
                    BitBlt(dc, 12, (i - linenum) *height + offset, 16, 16,
                        hMemDC, 0, 0, SRCCOPY);
                    break;
                }
                // fallthrough 
            default:
                SelectObject(hMemDC, tagBmps[type]);
                BitBlt(dc, 12, (i - linenum) *height + offset, 16, 16, hMemDC,
                    0, 0, SRCCOPY);
                break;
                case  - 1: if (bpline == i)
                {
                    SelectObject(hMemDC, pcBitmap);
                    BitBlt(dc, 12, (i - linenum) *height + offset, 16, 16,
                        hMemDC, 0, 0, SRCCOPY);
                }
                break;
        }
    }
    DeleteDC(hMemDC);
}

//-------------------------------------------------------------------------

LRESULT CALLBACK _export gotoProc(HWND hwnd, UINT iMessage, WPARAM wParam,
    LPARAM lParam)
{
    char buf[3];
    switch (iMessage)
    {
        case WM_COMMAND:
            if (wParam == IDOK)
            {
                int i = GetEditFieldValue(hwnd, IDC_GOTO);
                EndDialog(hwnd, i);
                break;
            }
            if (HIWORD(wParam) == EN_CHANGE)
            {
                DisableControl(hwnd, IDOK, !GetWindowText((HWND)lParam, buf, 2))
                    ;
                break;
            }
            if (wParam != IDCANCEL)
                break;
        case WM_CLOSE:
            EndDialog(hwnd, 0);
            break;
        case WM_INITDIALOG:
            CenterWindow(hwnd);
            SetEditField(hwnd, IDC_GOTO, "");
            DisableControl(hwnd, IDOK, 1);
            break;
    }
    return 0;
}

//-------------------------------------------------------------------------

void recolorize(DWINFO *ptr)
{
    int colorizing = COLORIZE_NONE;
    if (stristr(ptr->dwName, ".c") == ptr->dwName + strlen(ptr->dwName) - 2 ||
        stristr(ptr->dwName, ".cpp") == ptr->dwName + strlen(ptr->dwName) - 4 
        || stristr(ptr->dwName, ".h") == ptr->dwName + strlen(ptr->dwName) - 2)
        colorizing = COLORIZE_C;
    else if (stristr(ptr->dwName, ".asm") == ptr->dwName + strlen(ptr->dwName) 
        - 4 || stristr(ptr->dwName, ".asi") == ptr->dwName + strlen(ptr->dwName)
        - 4 || stristr(ptr->dwName, ".inc") == ptr->dwName + strlen(ptr->dwName)
        - 4 || stristr(ptr->dwName, ".nas") == ptr->dwName + strlen(ptr->dwName)
        - 4)
        colorizing = COLORIZE_ASM;
    SendMessage(ptr->dwHandle, EM_COLORIZE, 0, colorizing);
}

//-------------------------------------------------------------------------

void asyncLoadFile(DWINFO *ptr)
{
    recolorize(ptr);
    if (ptr->dwName[0])
        LoadFile(ptr->self, ptr);
    else
        ShowWindow(ptr->dwHandle, SW_SHOW);
    if (ptr->dwLineNo !=  - 1)
    {
        PostMessage(ptr->self, WM_COMMAND, IDM_SETLINE, ptr->dwLineNo);
    }
    PostMessage(hwndSourceTab, WM_RESETTABS, 0, 0);
}

//-------------------------------------------------------------------------

LRESULT CALLBACK _export DrawProc(HWND hwnd, UINT iMessage, WPARAM wParam,
    LPARAM lParam)
{
    DWORD threadhand;
    DWINFO *ptr,  *ptr1;
    OPENFILENAME ofn;
    HDC dc;
    HPEN hpen, oldpen;
    RECT r;
    HBRUSH graybrush;
    LOGBRUSH lbrush;
    PAINTSTRUCT paint;
    int childheight;
    int startpos, endpos, flag, i;
    HWND win;
    FILETIME time;
    NMHDR *nm;
    int rv;
    charinfo s;
    switch (iMessage)
    {
        case EN_LINECHANGE:
            found = FALSE;
            ptr = (DWINFO*)GetWindowLong(hwnd, 0);
            TagLineChange(ptr->dwName, wParam + 1, lParam);
            GetClientRect(hwnd, &r);
            r.right = EDITOR_OFFSET;
            InvalidateRect(hwnd, &r, 0);
            break;
        case WM_NOTIFY:
            nm = (NMHDR*)lParam;
            if (nm->code == NM_RCLICK)
            {
                HMENU menu = LoadMenu(hInstance, "EDITMENU");
                HMENU popup = GetSubMenu(menu, 0);
                POINT pos, pos1;
                ptr = (DWINFO*)GetWindowLong(hwnd, 0);
                SendMessage(hwnd, EN_SETCURSOR, 0, 0);
                if (!SendMessage(ptr->dwHandle, EM_GETMODIFY, 0, 0))
                    EnableMenuItem(menu, IDM_SAVE, MF_GRAYED);
                if (uState != atBreakpoint && uState != atException)
                {
                    EnableMenuItem(menu, IDM_RUNTO, MF_GRAYED);
                    EnableMenuItem(menu, IDM_ADDWATCHINDIRECT, MF_GRAYED);
                }
                GetCursorPos(&pos);
                pos1.x = pos.x;
                pos1.y = pos.y;
                ScreenToClient(ptr->dwHandle, &pos1);
                i = SendMessage(ptr->dwHandle, EM_CHARFROMPOS, 0, (LPARAM)
                    &pos1);
                s.min = i;
                s.max = i;
                SendMessage(ptr->dwHandle, EM_EXSETSEL, 0, (LPARAM) &s);
                TrackPopupMenuEx(popup, TPM_BOTTOMALIGN | TPM_LEFTBUTTON, pos.x,
                    pos.y, hwndFrame, NULL);
                DestroyMenu(menu);
            }
            return 0;
        case WM_SYSCOMMAND:
            if (wParam == SC_CLOSE)
                return SendMessage(hwnd, WM_COMMAND, IDM_CLOSE, 0);
            break;
        case WM_COMMAND:
            switch (LOWORD(wParam))
            {
            case IDM_CONTEXTHELP:
                ptr = (DWINFO*)GetWindowLong(hwnd, 0);
                i = SendMessage(ptr->dwHandle, WM_COMMAND, wParam, lParam);
                break;
            case IDM_GOTO:
                lParam = DialogBox(hInstance, "GOTODIALOG", hwnd, (DLGPROC)
                    gotoProc);
                if (lParam == 0)
                    break;
                // fall through
            case IDM_SETLINE:
                ptr = (DWINFO*)GetWindowLong(hwnd, 0);
                SendMessage(ptr->dwHandle, EM_GETLINECOUNT, 0, 0); 
                    // force update of vertical scroll range
                i = SendMessage(ptr->dwHandle, EM_LINEINDEX, lParam - 1, 0);
                s.min = i;
                s.max = i;
                SendMessage(ptr->dwHandle, EM_EXSETSEL, 0, (LPARAM) &s);
                SendMessage(ptr->dwHandle, EM_SCROLLCARET, 0, 0);
                drawParams(ptr, hwnd);
                found = FALSE;
                InvalidateRect(hwnd, 0, 0);
                break;
            case ID_REDRAWSTATUS:
                ptr = (DWINFO*)GetWindowLong(hwnd, 0);
                drawParams(ptr, hwnd);
                InvalidateRect(hwnd, 0, 0);
                break;
            case ID_QUERYHASFILE:
                ptr = (DWINFO*)GetWindowLong(hwnd, 0);
                ptr1 = (DWINFO*)lParam;
                return !xstricmpz(ptr->dwName, ptr1->dwName);
            case ID_QUERYSAVE:
                ptr = (DWINFO*)GetWindowLong(hwnd, 0);
                rv = SendMessage(ptr->dwHandle, EM_GETMODIFY, 0, 0);
                if (rv)
                {
                    return ExtendedMessageBox("File Has Changed",
                        MB_YESNOCANCEL, 
                        "File %s has changed.  Do you wish to save it?", ptr
                        ->dwTitle);
                }
                else
                    return IDNO;
            case IDM_SAVEAS:
                dialog: ptr = (DWINFO*)GetWindowLong(hwnd, 0);
                if (!SaveFileDialog(&ofn, ptr->dwName, hwnd, TRUE,
                    szSourceFilter, "FILEDIR", 0))
                    break;
                if (projectList && ptr->dwName[0] == 0)
                {
                    if (ExtendedMessageBox("Project Query", MB_TASKMODAL |
                        MB_YESNO, "Add file to project?") == IDYES)
                    {
                        AddFileInternal(projectList, 0, ofn.lpstrFile,
                            ofn.lpstrFileTitle);
                    }
                }
                strcpy(ptr->dwTitle, ofn.lpstrFileTitle);
                strcpy(ptr->dwName, ofn.lpstrFile);
                SetWindowText(hwnd, ptr->dwTitle);
                recolorize(ptr);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -