📄 mimerichtextedit.c
字号:
/* * $Id: MimeRichTextEdit.C,v 1.3 2000/11/12 12:32:25 evgeny Exp $ * * Copyright (c) 1994 HAL Computer Systems International, Ltd. * * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. * 1315 Dell Avenue * Campbell, CA 95008 * * Author: Greg Hilton * Contributors: Tom Lang, Frank Bieser, and others * * 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. * * http://www.gnu.org/copyleft/gpl.html * * 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. */#include <config.h>#include "MimeRichTextC.h"#include "MimeRichTextP.h"#include "HalAppC.h"#include "CharC.h"#include "WArgList.h"#include "RichSearchWinC.h"#include "rsrc.h"#include <Xm/AtomMgr.h>#include <Xm/ScrollBar.h>#include <Xm/CutPaste.h>#include <X11/Xatom.h>#include <X11/Xmu/Atoms.h>#include <X11/keysym.h>extern int debuglev;/*----------------------------------------------------------------------- * Insert the character string at the current cursor position. */voidMimeRichTextC::InsertString(CharC cs){ priv->HideCursor();//// Clear the current selection// if ( priv->selectOn ) priv->DrawSelection();//// Add a line record if necessary// priv->inputLine = priv->cursorPos.textLine; if ( !priv->inputLine ) { priv->NewInputLine(); priv->cursorPos.Set(priv->inputLine, 0, 0); }//// Point to the command under the cursor.// priv->inputCmd = priv->cursorPos.Cmd();//// If the cursor is not at the end of a text command, split it// TextPosC newPos; if ( priv->inputCmd->IsText() && priv->cursorPos.strPos < priv->inputCmd->LastPos()) { priv->SplitCommand(priv->cursorPos, &newPos); priv->cursorPos = newPos; }//// If we're not in a text command, add one// else {//// See if the text should be inserted before or after the current command.// Boolean after = (priv->cursorPos.strPos>0); priv->InsertCommand(RC_TEXT, after, priv->cursorPos, &newPos); priv->inputCmd = newPos.Cmd(); } // End if cursor is not on a text command//// Add string based on type// TextLineC *bline = priv->inputLine; priv->defer++; if ( priv->textType == TT_ENRICHED ) AddStringEnriched(cs); else if ( priv->textType == TT_RICH ) AddStringRichtext(cs); else if ( priv->textType == TT_HTML ) AddStringHTML(cs); else AddStringPlain(cs); priv->defer--; if ( !priv->defer ) priv->LinesChanged(bline, priv->inputLine);//// Keep the cursor visible// priv->ScrollToCursor(); ScreenPosC spos = priv->cursorPos; priv->desiredCursorX = spos.x;//// Redisplay the current selection// if ( priv->selectOn ) priv->DrawSelection(); priv->ShowCursor();} // End InsertString/*----------------------------------------------------------------------- * Delete the text in the selection range */voidMimeRichTextP::DeleteSelection(){ if ( !editable ) { XBell(halApp->display, 0); return; } if ( !selectOn ) return; DrawSelection(); selectOn = False;//// Only delete the text if the cursor is inside the selection// if ( cursorPos >= selectBegPos && cursorPos <= selectEndPos ) DeleteRange(selectBegPos, selectEndPos);} // End DeleteSelection/*--------------------------------------------------------------- * Move the cursor one character to the left */voidMimeRichTextP::ActMoveLeftChar(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->MoveLeftChar();}voidMimeRichTextC::MoveLeftChar(){ priv->HideCursor(); if ( priv->selectOn ) priv->DrawSelection(); priv->selectOn = False; TextPosC newPos; if ( priv->FindPosPrevChar(priv->cursorPos, &newPos) ) { priv->cursorPos = newPos; priv->ScrollToCursor(); ScreenPosC spos = priv->cursorPos; priv->desiredCursorX = spos.x; } priv->ShowCursor();} // End MoveLeftChar/*--------------------------------------------------------------- * Move the cursor one word to the left. Move to the first non-white * character after the first white character or to the beginning * of the line. */voidMimeRichTextP::ActMoveLeftWord(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->MoveLeftWord();}voidMimeRichTextC::MoveLeftWord(){ priv->HideCursor(); if ( priv->selectOn ) priv->DrawSelection(); priv->selectOn = False; TextPosC newPos; if ( priv->FindPosPrevWord(priv->cursorPos, &newPos) ) { priv->cursorPos = newPos; priv->ScrollToCursor(); ScreenPosC spos = priv->cursorPos; priv->desiredCursorX = spos.x; } priv->ShowCursor();} // End MoveLeftWord/*--------------------------------------------------------------- * Move the cursor one character to the right */voidMimeRichTextP::ActMoveRightChar(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->MoveRightChar();}voidMimeRichTextC::MoveRightChar(){ priv->HideCursor(); if ( priv->selectOn ) priv->DrawSelection(); priv->selectOn = False; TextPosC newPos; if ( priv->FindPosNextChar(priv->cursorPos, &newPos) ) { priv->cursorPos = newPos; priv->ScrollToCursor(); ScreenPosC spos = priv->cursorPos; priv->desiredCursorX = spos.x; } priv->ShowCursor();} // End MoveRightChar/*--------------------------------------------------------------- * Move the cursor one word to the right. Move to the first whitespace * character after the first non-white character. */voidMimeRichTextP::ActMoveRightWord(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->MoveRightWord();}voidMimeRichTextC::MoveRightWord(){ priv->HideCursor(); if ( priv->selectOn ) priv->DrawSelection(); priv->selectOn = False; TextPosC newPos; if ( priv->FindPosNextWord(priv->cursorPos, &newPos) ) { priv->cursorPos = newPos; priv->ScrollToCursor(); ScreenPosC spos = priv->cursorPos; priv->desiredCursorX = spos.x; } priv->ShowCursor();} // End MoveRightWord/*--------------------------------------------------------------- * Move the cursor to the start of the line */voidMimeRichTextP::ActMoveLineBeg(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->MoveLineBeg();}voidMimeRichTextC::MoveLineBeg(){ priv->HideCursor(); if ( priv->selectOn ) priv->DrawSelection(); priv->selectOn = False; ScreenPosC spos = priv->cursorPos; spos.Set(spos.softLine, spos.softLine->bounds.xmin); priv->cursorPos = spos; priv->ScrollToCursor(); priv->desiredCursorX = spos.x; priv->ShowCursor();} // End MoveLineBeg/*--------------------------------------------------------------- * Move the cursor to the end of the line */voidMimeRichTextP::ActMoveLineEnd(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->MoveLineEnd();}voidMimeRichTextC::MoveLineEnd(){ priv->HideCursor(); if ( priv->selectOn ) priv->DrawSelection(); priv->selectOn = False; ScreenPosC spos = priv->cursorPos; spos.Set(spos.softLine, spos.softLine->bounds.xmax); priv->cursorPos = spos; priv->ScrollToCursor(); priv->desiredCursorX = spos.x; priv->ShowCursor();} // End MoveLineEnd/*--------------------------------------------------------------- * Move the cursor up one line */voidMimeRichTextP::ActMoveUpLine(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->MoveUpLine();}voidMimeRichTextC::MoveUpLine(){ priv->HideCursor(); if ( priv->selectOn ) priv->DrawSelection(); priv->selectOn = False; ScreenPosC spos = priv->cursorPos; SoftLineC *prev = spos.softLine->prev; if ( prev ) { spos.Set(prev, priv->desiredCursorX); priv->cursorPos = spos; priv->ScrollToCursor(); } priv->ShowCursor();} // End MoveUpLine/*--------------------------------------------------------------- * Move the cursor up one paragraph */voidMimeRichTextP::ActMoveUpPara(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->MoveUpPara();}voidMimeRichTextC::MoveUpPara(){#if 0 priv->HideCursor(); if ( priv->selectOn ) priv->DrawSelection(); priv->selectOn = False; priv->ShowCursor();#else MoveUpLine();#endif} // End MoveUpPara/*--------------------------------------------------------------- * Move the cursor down one line */voidMimeRichTextP::ActMoveDownLine(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->MoveDownLine();}voidMimeRichTextC::MoveDownLine(){ priv->HideCursor(); if ( priv->selectOn ) priv->DrawSelection(); priv->selectOn = False; ScreenPosC spos = priv->cursorPos; SoftLineC *next = spos.softLine->next; if ( next ) { spos.Set(next, priv->desiredCursorX); priv->cursorPos = spos; priv->ScrollToCursor(); } priv->ShowCursor();} // End MoveDownLine/*--------------------------------------------------------------- * Move the cursor down one paragraph */voidMimeRichTextP::ActMoveDownPara(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->MoveDownPara();}voidMimeRichTextC::MoveDownPara(){#if 0 priv->HideCursor(); if ( priv->selectOn ) priv->DrawSelection(); priv->selectOn = False; priv->ShowCursor();#else MoveDownLine();#endif} // End MoveDownPara/*--------------------------------------------------------------- * Move the cursor to the top of the file */voidMimeRichTextP::ActMoveFileBeg(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->MoveFileBeg();}voidMimeRichTextC::MoveFileBeg(){ priv->HideCursor(); if ( priv->selectOn ) priv->DrawSelection(); priv->selectOn = False; priv->cursorPos.Set(priv->topTextLine, 0, 0); priv->ScrollToCursor(); priv->desiredCursorX = 0; priv->ShowCursor();} // End MoveFileBeg/*--------------------------------------------------------------- * Move the cursor to the bottom of the file */voidMimeRichTextP::ActMoveFileEnd(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->MoveFileEnd();}voidMimeRichTextC::MoveFileEnd(){ priv->HideCursor(); if ( priv->selectOn ) priv->DrawSelection(); priv->selectOn = False; if ( priv->botTextLine ) { TextLineC *tline = priv->botTextLine; unsigned cmdCount = tline->cmdList.size(); RichCmdC *cmd = tline->Cmd(cmdCount-1); unsigned strSize = cmd->LastPos(); priv->cursorPos.Set(tline, cmdCount-1, strSize); priv->ScrollToCursor(); ScreenPosC spos = priv->cursorPos; priv->desiredCursorX = spos.x; } priv->ShowCursor();} // End MoveFileEnd/*--------------------------------------------------------------- * Delete the character to the left of the cursor */voidMimeRichTextP::ActDeleteLeftChar(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->DeleteLeftChar();}voidMimeRichTextC::DeleteLeftChar(){ if ( !priv->editable ) { XBell(halApp->display, 0); return; }//// Delete the current selection// if ( priv->selectOn ) { priv->DeleteSelection(); return; } TextPosC newPos; if ( !priv->FindPosPrevChar(priv->cursorPos, &newPos) ) return; priv->DeleteRange(newPos, priv->cursorPos);} // End DeleteLeftChar/*--------------------------------------------------------------- * Delete the word to the left of the cursor */voidMimeRichTextP::ActDeleteLeftWord(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -