📄 mimerichtextedit.c
字号:
//// If the end position is at the beginning of a non-blank string, we can// move to the end of the previous one// if ( endPos.strPos == 0 && endPos.Cmd()->LastPos() > 0 && FindPosPrevCmd(endPos, &newPos) ) { endPos = newPos; }//// If there's no text in-between, we're done// if ( begPos >= endPos ) { ShowCursor(); return; }//// Clear the selection// DrawSelection(); // To clear it selectOn = False;//// If the beginning position is not the beginning of a command, split// the command.// if ( begPos.strPos != 0 ) { SplitCommand(begPos, &newPos); FixPosAfterSplit(&endPos, begPos); begPos = newPos; }//// If the end position is not the end of a command, split the command.// if ( endPos.strPos < endPos.Cmd()->LastPos() ) SplitCommand(endPos, &newPos);//// For each command between the beginning and end (inclusive), make the// color change// TextPosC curPos = begPos; Boolean done = False; while ( !done && curPos <= endPos ) { RichCmdC *cmd = curPos.Cmd(); if ( name.Equals("none", IGNORE_CASE) ) cmd->state.ColorStack().removeAll(); else cmd->state.PushColor(value); done = !FindPosNextCmd(curPos, &newPos); curPos = newPos; } // End for each command changing//// Update all affected lines// LinesChanged(begPos.textLine, endPos.textLine);//// Turn the selection back on// CompactSelection(); DrawSelection(); selectOn = True; } // End if selectOn//// Since there is no current selection, insert a command at the cursor// position.// else {//// See what the text state is at the cursor position// RichCmdC *cmd = cursorPos.Cmd();//// If it's not already correct, add a blank string with the desired state// Boolean correct; if ( name.Equals("none", IGNORE_CASE) ) correct = (cmd->state.ColorStack().size() == 0); else correct = (cmd->state.ColorCount(value) > 0); if ( !correct ) {//// If the cursor is not in a blank text string, create one.// if ( cmd->IsText() && cmd->LastPos() > 0 ) { TextPosC oldPos = cursorPos; SplitCommand(cursorPos, &newPos);//// Splitting may have left one of the two parts blank. If so, use that part.// if ( cursorPos.Cmd()->LastPos() == 0 ) { selectBegPos = selectEndPos = cursorPos; } else if ( newPos.Cmd()->LastPos() == 0 ) { cursorPos = selectBegPos = selectEndPos = newPos; } else if ( oldPos.Cmd()->LastPos() == 0 ) { cursorPos = selectBegPos = selectEndPos = oldPos; }//// If no part is blank, insert a blank command// else { InsertCommand(RC_TEXT, True/*after*/, oldPos, &newPos); cursorPos = selectBegPos = selectEndPos = newPos; } cmd = cursorPos.Cmd(); } // End if a new command is needed//// The cursor should now be in a blank text command// if ( name.Equals("none", IGNORE_CASE) ) cmd->state.ColorStack().removeAll(); else cmd->state.PushColor(value);//// Update the current line// LineChanged(cursorPos.textLine); } // End if not already correct } // End if no current selection//// Keep the cursor in the window// ScrollToCursor(); ScreenPosC spos = cursorPos; desiredCursorX = spos.x; ShowCursor();} // End ChangeColor/*--------------------------------------------------------------- * Remove all markup from the current selection or at the cursor */voidMimeRichTextP::ActPlain(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->ChangeFont(FC_PLAIN);}/*--------------------------------------------------------------- * Make the current selection Bold or start Bold at the cursor */voidMimeRichTextP::ActBold(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->ChangeFont(FC_BOLD);}/*--------------------------------------------------------------- * Make the current selection italic or start italic at the cursor */voidMimeRichTextP::ActItalic(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->ChangeFont(FC_ITALIC);}/*--------------------------------------------------------------- * Make the current selection Fixed or start Fixed at the cursor */voidMimeRichTextP::ActFixed(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->ChangeFont(FC_FIXED);}/*--------------------------------------------------------------- * Make the current selection Smaller or start Smaller at the cursor */voidMimeRichTextP::ActSmaller(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->ChangeFont(FC_SMALLER);}/*--------------------------------------------------------------- * Make the current selection Bigger or start Bigger at the cursor */voidMimeRichTextP::ActBigger(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->ChangeFont(FC_BIGGER);}/*--------------------------------------------------------------- * Make the current selection Underline or start Underline at the cursor */voidMimeRichTextP::ActUnderline(Widget w, XKeyEvent*, String*, Cardinal*){ MimeRichTextC *This; XtVaGetValues(w, XmNuserData, &This, NULL); This->ChangeFont(FC_UNDERLINE);}/*--------------------------------------------------------------- * Make the specified justification change to the current selection or * at the cursor. */voidMimeRichTextC::ChangeJust(JustCmdT jcmd){ priv->ChangeJust(jcmd);}voidMimeRichTextP::ChangeJust(JustCmdT jcmd){ if ( !editable ) { XBell(halApp->display, 0); return; } HideCursor(); TextPosC newPos;//// If there is a current selection, make the change to that. Otherwise, change// the line containing the cursor.// TextPosC begPos; TextPosC endPos; if ( selectOn ) {//// Save copies of the selection positions.// if ( selectBegPos > selectEndPos ) { begPos = selectEndPos; endPos = selectBegPos; } else { begPos = selectBegPos; endPos = selectEndPos; } } // End if there is a selection else {//// Determine the text positions at the beginning and end of the current line// ScreenPosC spos = cursorPos; ScreenPosC bpos(spos.softLine, 0); ScreenPosC epos(spos.softLine, spos.softLine->bounds.xmax); begPos = bpos; endPos = epos; } // End if there is no selection Boolean correct;//// If we're excerpting more, we do so regardless of the current state.// if ( jcmd != JC_EXCERPT_MORE ) {//// If the beginning state is already correct, advance the beginning state until// it's not// if ( jcmd == JC_EXCERPT_LESS ) correct = (begPos.Cmd()->state.Excerpt() == 0); else correct = (begPos.Cmd()->state.CmdCount(jcmd) > 0); while ( correct && begPos < endPos && FindPosNextCmd(begPos, &newPos) ) { begPos = newPos; if ( jcmd == JC_EXCERPT_LESS ) correct = (begPos.Cmd()->state.Excerpt() == 0); else correct = (begPos.Cmd()->state.CmdCount(jcmd) > 0); } } // End if current state is important//// If the beginning position is at the end of a non-blank string, we can// move to the start of the next one// if ( begPos.strPos > 0 && begPos.strPos >= begPos.Cmd()->LastPos() && FindPosNextCmd(begPos, &newPos) ) { begPos = newPos; } if ( jcmd != JC_EXCERPT_MORE ) {//// If the end state is already correct, move the end state until// it's not// if ( jcmd == JC_EXCERPT_LESS ) correct = (endPos.Cmd()->state.Excerpt() == 0); else correct = (endPos.Cmd()->state.CmdCount(jcmd) > 0); while ( correct && endPos > begPos && FindPosPrevCmd(endPos, &newPos) ) { endPos = newPos; if ( jcmd == JC_EXCERPT_LESS ) correct = (endPos.Cmd()->state.Excerpt() == 0); else correct = (endPos.Cmd()->state.CmdCount(jcmd) > 0); } } // End if current state is important//// If the end position is at the beginning of a non-blank string, we can// move to the end of the previous one// if ( endPos.strPos == 0 && endPos.Cmd()->LastPos() > 0 && FindPosPrevCmd(endPos, &newPos) ) { endPos = newPos; }//// If there's no text in-between, we're done// if ( begPos > endPos ) { ShowCursor(); return; }//// Clear the selection// Boolean needSelect = selectOn; if ( selectOn ) { DrawSelection(); // To clear it selectOn = False; }//// If the beginning position is not the beginning of a text command, split// the command.// if ( begPos.strPos != 0 ) { SplitCommand(begPos, &newPos); FixPosAfterSplit(&endPos, begPos); begPos = newPos; }//// If the end position is not the end of a text command, split the command.// if ( endPos.strPos < endPos.Cmd()->LastPos() ) SplitCommand(endPos, &newPos); TextLineC *bline = begPos.textLine; TextLineC *eline = endPos.textLine;//// If the beginning position is not the beginning of a line, insert a line// break// if ( begPos.cmdPos != 0 ) { InsertLineBreak(begPos, &newPos); FixPosAfterBreak(&endPos, begPos, newPos.textLine); begPos = newPos; eline = endPos.textLine; }//// If the end position is not the end of a line, insert a line break// if ( endPos.cmdPos != endPos.textLine->cmdList.size()-1 ) { InsertLineBreak(endPos, &newPos); eline = newPos.textLine; }//// For each command between the beginning and end (inclusive), make the// change// TextPosC curPos = begPos; Boolean done = False; while ( !done && curPos <= endPos ) { RichCmdC *cmd = curPos.Cmd(); if ( jcmd == JC_EXCERPT_MORE ) cmd->state.ExcerptMore(); else if ( jcmd == JC_EXCERPT_LESS ) { cmd->state.ExcerptLess(); } else { cmd->state.JustStack().Clear(); cmd->state.PushJust(jcmd); } done = !FindPosNextCmd(curPos, &newPos); curPos = newPos; }//// Update all affected lines// LinesChanged(bline, eline, True/*reposition*/);//// Turn the selection back on// if ( needSelect ) { selectBegPos = begPos; selectEndPos = endPos; CompactSelection(); DrawSelection(); selectOn = True; }#if 0//// Since there is no current selection, insert a command at the cursor// position.// else {//// See what the text state is at the cursor position// RichCmdC *cmd = cursorPos.Cmd();//// If it's not already correct, add a blank line with the desired state// Boolean correct = False; if ( jcmd == JC_EXCERPT_LESS ) correct = (cmd->state.Excerpt() == 0); else correct = (cmd->state.CmdCount(jcmd) > 0); if ( !correct ) { TextLineC *bline = cursorPos.textLine;//// If the cursor is at the beginning or end of the current line, we only need// to make one break.// Boolean atBeg = (cursorPos.cmdPos == 0 && cursorPos.strPos == 0); Boolean atEnd = (cursorPos.cmdPos == cursorPos.textLine->cmdList.size()-1 && cursorPos.strPos >= cursorPos.Cmd()->LastPos()-1);//// Add a line break// TextPosC curPos = cursorPos; InsertLineBreak(cursorPos, &newPos);//// If the cursor isn't already at the blank line, move it there// if ( !atBeg ) curPos = newPos;//// If we started in the middle add another line break// if ( !(atBeg || atEnd) ) InsertLineBreak(curPos, &newPos); cursorPos = curPos; TextLineC *eline = newPos.textLine;//// Make the change in the blank line// cmd = cursorPos.Cmd(); if ( jcmd == JC_EXCERPT_MORE ) cmd->state.ExcerptMore(); else if ( jcmd == JC_EXCERPT_LESS ) { cmd->state.ExcerptLess(); } else { cmd->state.JustStack().Clear(); cmd->state.PushJust(jcmd); } selectBegPos = selectEndPos = cursorPos;//// Update the new line(s)// LinesChanged(bline, eline, True/*reposition*/); } // End if not already correct } // End if no current selection#endif//// Keep the cursor in the window// ScrollToCursor(); ScreenPosC spos = cursorPos; desiredCursorX = spos.x; ShowCursor();} // End Chang
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -