📄 _range.h
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft shared
// source or premium shared source license agreement under which you licensed
// this source code. If you did not accept the terms of the license agreement,
// you are not authorized to use this source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the SOURCE.RTF on your install media or the root of your tools installation.
// THE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
/*
* @doc
*
* @module _RANGE.H -- CTxtRange Class |
*
* This class implements the internal text range and the TOM ITextRange
*
* Authors: <nl>
* Original RichEdit code: David R. Fulmer
* Christian Fortini
* Murray Sargent
* Alex Gounares (floating ranges, etc.)
*
*/
#ifndef _RANGE_H
#define _RANGE_H
#include "_text.h"
#include "_m_undo.h"
#include "_rtext.h"
#include "_edit.h"
long FPPTS_TO_TWIPS(float x);
#define TWIPS_TO_FPPTS(x) (((float)(x)) * (float)0.05)
class CTxtEdit;
class CTxtFont;
/*
* SELRR
*
* @enum flags used to control how ReplaceRange (RR) should generate
* selection anti-events
*/
enum SELRR
{
SELRR_IGNORE = 0,
SELRR_REMEMBERRANGE = 1,
SELRR_REMEMBERCPMIN = 2,
SELRR_REMEMBERENDIP = 3
};
/*
* FINDWORD_TYPE
*
* @enum defines the different cases for finding a word
*/
enum FINDWORD_TYPE {
FW_EXACT = 1, //@emem Finds the word exactly (no extra chars)
FW_INCLUDE_TRAILING_WHITESPACE = 2, //@emem find the word plus the
// following whitespace (ala double-clicking)
};
enum MOVES
{
MOVE_START = -1,
MOVE_IP = 0,
MOVE_END = 1,
};
enum MATCHES
{
MATCH_UNTIL = 0,
MATCH_WHILE = 1
};
enum EOPADJUST
{
NONEWCHARS = 0,
NEWCHARS = 1
};
/*
* CTxtRange
*
* @class
* The CTxtRange class implements RichEdit's text range, which is the
* main conduit through which changes are made to the document.
* The range inherits from the rich-text ptr, adding a signed length
* insertion-point char-format index, and a ref count for use when
* instantiated as a TOM ITextRange. The range object also contains
* a flag that reveals whether the range is a selection (with associated
* screen behavior) or just a simple range. This distinction is used
* to simplify some of the code.
*
* Some methods are virtual to allow CTxtSelection objects to facilitate
* UI features and selection updating.
*
* See tom.doc for lots of discussion on range and selection objects and
* on all methods in ITextRange, ITextSelection, ITextFont, and ITextPara.
*/
class CTxtRange : public ITextSelection, public CRchTxtPtr
{
friend CTxtFont;
//@access Protected Data
protected:
LONG _cch; //@cmember # chars in range. _cch > 0 for active
// end at range end (cpMost)
LONG _iFormat; //@cmember Character format for degenerate range
LONG _cRefs; //@cmember ITextRange/ITextSelection ref count
union
{
DWORD _dwFlags; // All together now
struct
{
DWORD _fExtend :1; //@cmember True iff Advance methods should
// leave "other" end unchanged
DWORD _fSel :1; //@cmember True iff this is a CTxtSelection
DWORD _fDragProtection :1; //@cmember True is this range should think
// it's protected. Set by drag/drop code
DWORD _fDontUpdateFmt:1;//@cmember Don't update _iFormat
DWORD _fDualFontMode:1; //@cmember Set during dual font mode
DWORD _fUseiFormat:1; //@cmember Use iFormat when replacing
// a non-degenerate range
DWORD _fMoveBack:1; //@cmember TRUE if last change moved backward
DWORD _fSelHasEOP:1; //@cmember TRUE if Sel has EOP
DWORD _fSelHasCell:1; //@cmember TRUE if Sel CELL found looking for EOP
};
};
//@access Public methods
public:
#ifdef DEBUG
BOOL Invariant( void ) const;
#endif // DEBUG
CTxtRange(const CTxtRange &rg);
CTxtRange(CTxtEdit *ped, LONG cp = 0, LONG cch = 0);
virtual ~CTxtRange();
virtual CRchTxtPtr& operator =(const CRchTxtPtr &rtp);
virtual CTxtRange& operator =(const CTxtRange &rp);
// ITxNotify methods
//@cmember Handles notifications
virtual void OnPreReplaceRange( // prior to ReplaceRange calls
DWORD cp, DWORD cchDel, DWORD cchNew,
DWORD cpFormatMin, DWORD cpFormatMax);
//@cmember Handles notifications for
virtual void OnPostReplaceRange( // floating range and display updates
DWORD cp, DWORD cchDel, DWORD cchNew,
DWORD cpFormatMin, DWORD cpFormatMax);
virtual void Zombie(); //@cmember Convert range into zombie
void SetIgnoreFormatUpdate(BOOL fUpdate) { _fDontUpdateFmt = fUpdate; }
void SetDualFontMode(BOOL fDualFontMode) {_fDualFontMode = fDualFontMode; }
// Internal cp/cch methods
LONG GetCch (void) const //@cmember Get signed character count
{return _cch;}
BOOL CpInRange (LONG cp) const; //@cmember Says if cp is in this range
BOOL CheckTextLength (LONG cch); //@cmember Says if cch chars can fit
LONG CheckChange(LONG cpSave); //@cmember Used after _cp change to set
// selection-changed flag, choose _cch
//@cmember In outline mode, maintain _fSelHasEOP
BOOL CheckIfSelHasEOP(LONG cpSave, LONG cchSave);
// GetRange() is faster than calling GetCpMin() and GetCpMost();
LONG GetCpMin () const; //@cmember Get cp of first char in range
LONG GetCpMost () const; //@cmember Get cp just beyond last char in range
//@cmember Get range ends and count
LONG GetRange (LONG& cpMin, LONG& cpMost) const;
BOOL Set(LONG cp, LONG cch);
DWORD SetCp(DWORD cp);
void SetExtend(unsigned f) {_fExtend = f;}
LONG GetAdjustedTextLength() const
{return GetPed()->GetAdjustedTextLength();}
// Range specific methods
LONG Advance(LONG cch);
void Collapser(long fStart);
void FlipRange();
LONG CleanseAndReplaceRange(
LONG cch,
TCHAR const *pch,
BOOL fTestLimit,
IUndoBuilder *publdr);
BOOL AdjustEndEOP (EOPADJUST NewChars);
// Outline management
void CheckOutlineLevel(IUndoBuilder *publdr);
#ifdef PWD_JUPITER // GuyBark 81387: Allow undo of expand/collapse operation
HRESULT ExpandOutline (LONG Level, BOOL fWholeDocument, IUndoBuilder *publdr);
HRESULT OutlineExpander(LONG Level, BOOL fWholeDocument, IUndoBuilder *publdr);
#else
HRESULT ExpandOutline (LONG Level, BOOL fWholeDocument);
HRESULT OutlineExpander(LONG Level, BOOL fWholeDocument);
#endif // PWD_JUPITER
HRESULT Promote (LPARAM lparam, IUndoBuilder *publdr);
// ReplaceRange must be virtual since the callers of
// CLightDTEngine::CutRangeToClipboard() cast CTxtSelection* to CTxtRange*
virtual LONG ReplaceRange(LONG cchNew, TCHAR const *pch, IUndoBuilder *publdr,
SELRR selaemode);
virtual BOOL Update(BOOL fScrollIntoView);
//
// Rich-text methods
//
enum { PROTECTED_YES, PROTECTED_NO, PROTECTED_ASK };
// Get/Set Char/Para Format methods
void Update_iFormat(LONG iFmtDefault);
LONG Get_iCF(); //@cmember Get range CF index
void Set_iCF(LONG iFormat); //@cmember Set range CF index
LONG Get_iPF(); //@cmember Get active end PF index
int IsProtected(LONG iDirection); //@cmember Is range protected?
BOOL IsZombie() {return !GetPed();} //@cmember Is range zombied?
BOOL WriteAccessDenied ();
void GetCharFormat(CCharFormat *pcf, DWORD flags = 0) const;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -