// Scintilla source code edit control
/** @file Editor.cxx
** Main code for the edit control.
**/
// Copyright 1998-2011 by Neil Hodgson <[email protected]>
// The License.txt file describes the conditions under which this software may be distributed.
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <ctype.h>
#include <cmath>
#include <stdexcept>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <memory>
#include "Platform.h"
#include "ILexer.h"
#include "Scintilla.h"
#include "StringCopy.h"
#include "Position.h"
#include "SplitVector.h"
#include "Partitioning.h"
#include "RunStyles.h"
#include "ContractionState.h"
#include "CellBuffer.h"
#include "PerLine.h"
#include "KeyMap.h"
#include "Indicator.h"
#include "XPM.h"
#include "LineMarker.h"
#include "Style.h"
#include "ViewStyle.h"
#include "CharClassify.h"
#include "Decoration.h"
#include "CaseFolder.h"
#include "Document.h"
#include "UniConversion.h"
#include "Selection.h"
#include "PositionCache.h"
#include "EditModel.h"
#include "MarginView.h"
#include "EditView.h"
#include "Editor.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
/*
return whether this modification represents an operation that
may reasonably be deferred (not done now OR [possibly] at all)
*/
static bool CanDeferToLastStep(const DocModification &mh) {
if (mh.modificationType & (SC_MOD_BEFOREINSERT | SC_MOD_BEFOREDELETE))
return true; // CAN skip
if (!(mh.modificationType & (SC_PERFORMED_UNDO | SC_PERFORMED_REDO)))
return false; // MUST do
if (mh.modificationType & SC_MULTISTEPUNDOREDO)
return true; // CAN skip
return false; // PRESUMABLY must do
}
static bool CanEliminate(const DocModification &mh) {
return
(mh.modificationType & (SC_MOD_BEFOREINSERT | SC_MOD_BEFOREDELETE)) != 0;
}
/*
return whether this modification represents the FINAL step
in a [possibly lengthy] multi-step Undo/Redo sequence
*/
static bool IsLastStep(const DocModification &mh) {
return
(mh.modificationType & (SC_PERFORMED_UNDO | SC_PERFORMED_REDO)) != 0
&& (mh.modificationType & SC_MULTISTEPUNDOREDO) != 0
&& (mh.modificationType & SC_LASTSTEPINUNDOREDO) != 0
&& (mh.modificationType & SC_MULTILINEUNDOREDO) != 0;
}
Timer::Timer() :
ticking(false), ticksToWait(0), tickerID(0) {}
Idler::Idler() :
state(false), idlerID(0) {}
static inline bool IsAllSpacesOrTabs(const char *s, unsigned int len) {
for (unsigned int i = 0; i < len; i++) {
// This is safe because IsSpaceOrTab() will return false for null terminators
if (!IsSpaceOrTab(s[i]))
return false;
}
return true;
}
Editor::Editor() {
ctrlID = 0;
stylesValid = false;
technology = SC_TECHNOLOGY_DEFAULT;
scaleRGBAImage = 100.0f;
cursorMode = SC_CURSORNORMAL;
hasFocus = false;
errorStatus = 0;
mouseDownCaptures = true;
mouseWheelCaptures = true;
lastClickTime = 0;
doubleClickCloseThreshold = Point(3, 3);
dwellDelay = SC_TIME_FOREVER;
ticksToDwell = SC_TIME_FOREVER;
dwelling = false;
ptMouseLast.x = 0;
ptMouseLast.y = 0;
inDragDrop = ddNone;
dropWentOutside = false;
posDrop = SelectionPosition(invalidPosition);
hotSpotClickPos = INVALID_POSITION;
selectionType = selChar;
lastXChosen = 0;
lineAnchorPos = 0;
originalAnchorPos = 0;
wordSelectAnchorStartPos = 0;
wordSelectAnchorEndPos = 0;
wordSelectInitialCaretPos = -1;
caretXPolicy = CARET_SLOP | CARET_EVEN;
caretXSlop = 50;
caretYPolicy = CARET_EVEN;
caretYSlop = 0;
visiblePolicy = 0;
visibleSlop = 0;
searchAnchor = 0;
xCaretMargin = 50;
horizontalScrollBarVisible = true;
scrollWidth = 2000;
verticalScrollBarVisible = true;
endAtLastLine = true;
caretSticky = SC_CARETSTICKY_OFF;
marginOptions = SC_MARGINOPTION_NONE;
mouseSelectionRectangularSwitch = false;
multipleSelection = false;
additionalSelectionTyping = false;
multiPasteMode = SC_MULTIPASTE_ONCE;
virtualSpaceOptions = SCVS_NONE;
targetStart = 0;
targetEnd = 0;
searchFlags = 0;
topLine = 0;
posTopLine = 0;
lengthForEncode = -1;
needUpdateUI = 0;
ContainerNeedsUpdate(SC_UPDATE_CONTENT);
paintState = notPainting;
paintAbandonedByStyling = false;
paintingAllText = false;
willRedrawAll = false;
idleStyling = SC_IDLESTYLING_NONE;
needIdleStyling = false;
modEventMask = SC_MODEVENTMASKALL;
pdoc->AddWatcher(this, 0);
recordingMacro = false;
foldAutomatic = 0;
convertPastes = true;
SetRepresentations();
}
Editor::~Editor() {
pdoc->RemoveWatcher(this, 0);
DropGraphics(true);
}
void Editor::Finalise() {
SetIdle(false);
CancelModes();
}
void Editor::SetRepresentations() {
reprs.Clear();
// C0 control set
const char *reps[] = {
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",
"BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI",
"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
"CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"
};
for (size_t j=0; j < ELEMENTS(reps); j++) {
char c[2] = { static_cast<char>(j), 0 };
reprs.SetRepresentation(c, reps[j]);
}
// C1 control set
// As well as Unicode mode, ISO-8859-1 should use these
if (IsUnicodeMode()) {
const char *repsC1[] = {
"PAD", "HOP", "BPH", "NBH", "IND", "NEL", "SSA", "ESA",
"HTS", "HTJ", "VTS", "PLD", "PLU", "RI", "SS2", "SS3",
"DCS", "PU1", "PU2", "STS", "CCH", "MW", "SPA", "EPA",
"SOS", "SGCI", "SCI", "CSI", "ST", "OSC", "PM", "APC"
};
for (size_t j=0; j < ELEMENTS(repsC1); j++) {
char c1[3] = { '\xc2', static_cast<char>(0x80+j), 0 };
reprs.SetRepresentation(c1, repsC1[j]);
}
reprs.SetRepresentation("\xe2\x80\xa8", "LS");
reprs.SetRepresentation("\xe2\x80\xa9", "PS");
}
// UTF-8 invalid bytes
if (IsUnicodeMode()) {
for (int k=0x80; k < 0x100; k++) {
char hiByte[2] = { static_cast<char>(k), 0 };
char hexits[4];
sprintf(hexits, "x%2X", k);
reprs.SetRepresentation(hiByte, hexits);
}
}
}
void Editor::DropGraphics(bool freeObjects) {
marginView.DropGraphics(freeObjects);
view.DropGraphics(freeObjects);
}
void Editor::AllocateGraphics() {
marginView.AllocateGraphics(vs);
view.AllocateGraphics(vs);
}
void Editor::InvalidateStyleData() {
stylesValid = false;
vs.technology = technology;
DropGraphics(false);
AllocateGraphics();
view.llc.Invalidate(LineLayout::llInvalid);
view.posCache.Clear();
}
void Editor::InvalidateStyleRedraw() {
NeedWrapping();
InvalidateStyleData();
Redraw();
}
void Editor::RefreshStyleData() {
if (!stylesValid) {
stylesValid = true;
AutoSurface surface(this);
if (surface) {
vs.Refresh(*surface, pdoc->tabInChars);
}
SetScrollBars();
SetRectangularRange();
}
}
Point Editor::GetVisibleOriginInMain() const {
return Point(0,0);
}
PointDocument Editor::DocumentPointFromView(Point ptView) const {
PointDocument ptDocument(ptView);
if (wMargin.GetID()) {
Point ptOrigin = GetVisibleOriginInMain();
ptDocument.x += ptOrigin.x;
ptDocument.y += ptOrigin.y;
} else {
ptDocument.x += xOffset;
ptDocument.y += topLine * vs.lineHeight;
}
return ptDocument;
}
int Editor::TopLineOfMain() const {
if (wMargin.GetID())
return 0;
else
return topLine;
}
PRectangle Editor::GetClientRectangle() const {
Window win = wMain;
return win.GetClientPosition();
}
PRectangle Editor::GetClientDrawingRectangle() {
return GetClientRectangle();
}
PRectangle Editor::GetTextRectangle() const {
PRectangle rc = GetClientRectangle();
rc.left += vs.textStart;
rc.right -= vs.rightMarginWidth;
return rc;
}
int Editor::LinesOnScreen() const {
PRectangle rcClient = GetClientRectangle();
int htClient = static_cast<int>(rcClient.bottom - rcClient.top);
//Platform::DebugPrintf("lines on screen = %d\n", htClient / lineHeight + 1);
return htClient / vs.lineHeight;
}
int Editor::LinesToScroll() const {
int retVal = LinesOnScreen() - 1;
if (retVal < 1)
return 1;
else
return retVal;
}
int Editor::MaxScrollPos() const {
//Platform::DebugPrintf("Lines %d screen = %d maxScroll = %d\n",
//LinesTotal(), LinesOnSc
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论




























收起资源包目录





































































































共 860 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论


刚出道的菜鸟@丢丢
- 粉丝: 89
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 汇安康脚底按摩器商业计划书.doc
- 造价基础知识之建设工程施工阶段工程造价的控制与调整.ppt
- 【全国】精装修设计管理流程及实施细则.doc
- 混凝土工程安全技术交底.doc
- 新世界大厦项目清洁招标书-.doc
- 质保工期安全环保.doc
- 基于ZXing与ZBar混合引擎的高性能Android二维码扫描识别库-支持自定义界面布局-连续扫描-相册识别-多种二维码生成样式-相机管理-NDK编译-二维码生成-仿QQ风格-带.zip
- 房屋建筑开发项目工程施工样板管理制度.doc
- 建筑工程计量与计价依据图文精讲.ppt
- 综合楼电气施工组织设计.doc
- 15玻璃幕墙安装工艺流程.doc
- [江苏]发电厂机组烟气脱硫工程循环浆液泵房施工作业指导书.doc
- 潜污泵安装工艺标准.doc
- 项目三-非正常情况下的行车组织.ppt
- 工程预算与管理-工程项目建设监理的目标控制.ppt
- xxxxxx供销合作协议.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
