/** * @file XTPSyntaxEditSelection.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPSYNTAXEDITSELECTION_H__) # define __XTPSYNTAXEDITSELECTION_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" /** @cond */ # ifdef _XTP_ACTIVEX class CXTPSyntaxEditSelPosEx_imp; class CXTPSyntaxEditSelPosExNormal_imp; # endif /** @endcond */ /** * @brief * This class is used to represent syntax edit text selection and allows * for selection properties to be get and set in two measurements: * string and display. Also the selection may be 'Normal' if its start is * less then its end or 'Reverse' if its end is less than its start. */ class _XTP_EXT_CLASS CXTPSyntaxEditSelection : public CXTPCmdTarget { /** @cond */ friend class CXTPSyntaxEditCtrl; friend class CXTPSyntaxEditSelection; DECLARE_DYNAMIC(CXTPSyntaxEditSelection) /** @endcond */ public: /** * @brief * Default object constructor. */ CXTPSyntaxEditSelection(); /** * @brief * Copy constructor. * @param rSrc [in] Reference to a source object. */ CXTPSyntaxEditSelection(const CXTPSyntaxEditSelection& rSrc); /** * @brief * Default object destructor. */ virtual ~CXTPSyntaxEditSelection(); /** * @brief * Gets the selection start position * where the column is a zero-based char index in the string. * @return * A reference to an XTP_EDIT_LINECOL object containing the selection start. * @see * GetEnd_str, GetStart_disp, GetEnd_disp, GetNormalStart_str, * GetNormalStart_disp, GetNormalEnd_str, GetNormalEnd_disp, * SetStart_str, SetStart_disp, SetEnd_str, SetEnd_disp, * Reset_str, Reset_disp */ const XTP_EDIT_LINECOL& GetStart_str() const; /** * @brief * Gets the selection end position * where the column is a zero-based char index in the string. * @return * A reference to an XTP_EDIT_LINECOL object containing the selection end. * @see * GetStart_str, GetStart_disp, GetEnd_disp, GetNormalStart_str, * GetNormalStart_disp, GetNormalEnd_str, GetNormalEnd_disp, * SetStart_str, SetStart_disp, SetEnd_str, SetEnd_disp, * Reset_str, Reset_disp */ const XTP_EDIT_LINECOL& GetEnd_str() const; /** * @brief * Gets the selection start position * where the column is a one-based column index on the screen. * @return * A reference to an XTP_EDIT_LINECOL object containing the selection start. * @see * GetStart_str, GetEnd_str, GetEnd_disp, GetNormalStart_str, * GetNormalStart_disp, GetNormalEnd_str, GetNormalEnd_disp, * SetStart_str, SetStart_disp, SetEnd_str, SetEnd_disp, * Reset_str, Reset_disp */ const XTP_EDIT_LINECOL& GetStart_disp() const; /** * @brief * Gets the selection end position * where the column is a one-based column index on the screen. * @return * A reference to an XTP_EDIT_LINECOL object containing the selection end. * @see * GetStart_str, GetEnd_str, GetStart_disp, GetNormalStart_str, * GetNormalStart_disp, GetNormalEnd_str, GetNormalEnd_disp, * SetStart_str, SetStart_disp, SetEnd_str, SetEnd_disp, * Reset_str, Reset_disp */ const XTP_EDIT_LINECOL& GetEnd_disp() const; /** * @brief * Gets the normalized selection start. * @return * A reference to an XTP_EDIT_LINECOL object which contains * the normalized selection start. * @see * GetStart_str, GetEnd_str, GetStart_disp, GetEnd_disp, GetNormalEnd_str, * GetNormalEnd_disp, SetStart_str, SetStart_disp, SetEnd_str, SetEnd_disp, * Reset_str, Reset_disp */ XTP_EDIT_LINECOL GetNormalStart_str() const; /** * @brief * Gets the normalized selection start. * @return * A reference to an XTP_EDIT_LINECOL object which contains * the normalized selection start. * @see * GetStart_str, GetEnd_str, GetStart_disp, GetEnd_disp, GetNormalEnd_str, * GetNormalEnd_disp, SetStart_str, SetStart_disp, SetEnd_str, SetEnd_disp, * Reset_str, Reset_disp */ XTP_EDIT_LINECOL GetNormalStart_disp() const; /** * @brief * Gets the normalized selection end. * @return * A reference to an XTP_EDIT_LINECOL object which contains * the normalized selection end. * @see * GetStart_str, GetEnd_str, GetStart_disp, GetEnd_disp, GetNormalStart_str, * GetNormalStart_disp, SetStart_str, SetStart_disp, SetEnd_str, SetEnd_disp, * Reset_str, Reset_disp */ XTP_EDIT_LINECOL GetNormalEnd_str() const; /** * @brief * Gets the normalized selection end. * @return * A reference to an XTP_EDIT_LINECOL object which contains * the normalized selection end. * @see * GetStart_str, GetEnd_str, GetStart_disp, GetEnd_disp, GetNormalStart_str, * GetNormalStart_disp, SetStart_str, SetStart_disp, SetEnd_str, SetEnd_disp, * Reset_str, Reset_disp */ XTP_EDIT_LINECOL GetNormalEnd_disp() const; /** * @brief * Sets the selection start position. * @param nTextRow Text row number. * @param nStrPos Zero-based char index in the string. * @see * SetEnd_str, SetEnd_disp, GetStart_str, GetEnd_str, GetStart_disp, * GetEnd_disp, GetNormalStart_str, GetNormalStart_disp, GetNormalEnd_str, * GetNormalEnd_disp, Reset_str, Reset_disp */ void SetStart_str(int nTextRow, int nStrPos); /** * @brief * Sets the selection start position. * @param nTextRow Text row number. * @param nDispCol One-based column index on the screen. * @see * SetEnd_str, SetEnd_disp, GetStart_str, GetEnd_str, GetStart_disp, * GetEnd_disp, GetNormalStart_str, GetNormalStart_disp, GetNormalEnd_str, * GetNormalEnd_disp, Reset_str, Reset_disp */ void SetStart_disp(int nTextRow, int nDispCol); /** * @brief * Sets the selection end position. * @param nTextRow Text row number. * @param nStrPos Zero-based char index in the string. * @see * SetStart_str, SetStart_disp, GetStart_str, GetEnd_str, GetStart_disp, * GetNormalStart_str, GetNormalStart_disp, GetNormalEnd_str, * GetNormalEnd_disp, Reset_str, Reset_disp */ void SetEnd_str(int nTextRow, int nStrPos); /** * @brief * Sets the selection end position. * @param nTextRow Text row number. * @param nDispCol One-based column index on the screen. * @see * SetStart_str, SetStart_disp, GetStart_str, GetEnd_str, GetStart_disp, * GetNormalStart_str, GetNormalStart_disp, GetNormalEnd_str, * GetNormalEnd_disp, Reset_str, Reset_disp */ void SetEnd_disp(int nTextRow, int nDispCol); /** * @brief * Sets the selection start and end positions. * The selection is empty in this case. * @param nTextRow Text row number. * @param nStrPos Zero-based char index in the string. * @see * SetStart_str, SetStart_disp, GetStart_str, GetEnd_str, GetStart_disp, * GetEnd_disp, GetNormalStart_str, GetNormalStart_disp, GetNormalEnd_str, * GetNormalEnd_disp */ void Reset_str(int nTextRow, int nStrPos); /** * @brief * Sets the selection start and end positions. * The selection is empty in this case. * @param nTextRow Text row number. * @param nDispCol One-based column index on the screen. * @see * SetStart_str, SetStart_disp, GetStart_str, GetEnd_str, GetStart_disp, * GetEnd_disp, GetNormalStart_str, GetNormalStart_disp, GetNormalEnd_str, * GetNormalEnd_disp */ void Reset_disp(int nTextRow, int nDispCol); /** * @brief * Determines if the selection mode is 'Word' * (enabled by pressing and holding Ctrl before selecting). * @return * TRUE if the selection mode is 'Word', otherwise FALSE. */ BOOL IsWordSelectionMode() const; /** * @brief * Determines if the selection mode is 'Block' * (enabled by pressing and holding Alt before selecting). * @return * TRUE if the selection mode is 'Block', otherwise FALSE. */ BOOL IsbBlockSelectionMode() const; /** * @brief * Determines if the selection exists (i.e. start != end). * @return * TRUE if the selection exists, otherwise FALSE. */ BOOL IsSelExist() const; /** * @brief * Determines if the selection is 'Normal' (i.e. start \< end). * @return * TRUE if the selection is 'Normal', otherwise FALSE. */ BOOL IsSelNormal() const; /** * @brief * Determines if a specified position is inside the selection. * @param nTextRow Text row number. * @param nStrPos Zero-based char index in the string. * @return * TRUE if the specified position is inside the selection, otherwise FALSE. * @see * IsIntersectSel_str, IsIntersectSel_disp */ BOOL IsInSel_str(int nTextRow, int nStrPos) const; /** * @brief * Determines if a specified position is inside the selection. * @param nTextRow Text row number. * @param nDispCol One-based column index on the screen. * @return * TRUE if the specified position is inside the selection, otherwise FALSE. */ BOOL IsInSel_disp(int nTextRow, int nDispCol) const; /** * @brief * Determines if a specified text range intersects the selection. * @param nTextRow Text row number. * @param nStrPos1 Text range start position (zero-based char index in the string). * @param nStrPos2 Text range end position (zero-based char index in the string). * @return * TRUE if the specified text range intersects the selection, otherwise FALSE. * @see * IsIntersectSel_str, IsIntersectSel_disp */ BOOL IsIntersectSel_str(int nTextRow, int nStrPos1, int nStrPos2) const; /** * @brief * Determines if a specified text range intersects the selection. * @param nTextRow Text row number. * @param nDispCol1 Text range start position (one-based column index on the screen). * @param nDispCol2 Text range end position (one-based column index on the screen). * @return * TRUE if the specified text range intersects the selection, otherwise FALSE. * @see * IsIntersectSel_str, IsIntersectSel_disp */ BOOL IsIntersectSel_disp(int nTextRow, int nDispCol1, int nDispCol2) const; /** * @brief * Equality operator. * Compares the current object to a specified object. * @param rSrc Reference to a CXTPSyntaxEditSelection object to compare to. * @return * TRUE if the current object and the specified object * are equal, otherwise FALSE. */ BOOL operator==(const CXTPSyntaxEditSelection& rSrc) const; /** * @brief * Non-Equality operator. * Compares the current object to a specified object. * @param rSrc Reference to a CXTPSyntaxEditSelection object to compare to. * @return * TRUE if the current object and the specified object * are not equal, otherwise FALSE. */ BOOL operator!=(const CXTPSyntaxEditSelection& rSrc) const; /** * @brief * Copy operator. * Initializes members from a specified object. * @param rSrc Reference to a CXTPSyntaxEditSelection object to copy from. * @return * A reference to the current object. */ const CXTPSyntaxEditSelection& operator=(const CXTPSyntaxEditSelection& rSrc); /** @cond */ int GetSelStartForRow_str(int nTextRow, int nDispLine); int GetSelEndForRow_str(int nTextRow, int nDispLine, BOOL* pbInfinitSelEnd); /** @endcond */ protected: /** @cond */ BOOL _IsInSel(BOOL bStr, int nTextRow, int nColX) const; BOOL _IsIntersectSel(BOOL bStr, int nTextRow, int nCol1, int nCol2) const; /** @endcond */ protected: BOOL bSelectingRunning; /**< Stores the 'SelectingRunning' mode. */ BOOL bWordSelectionMode; /**< TRUE if the selection mode is 'Word', otherwise FALSE. */ BOOL bBlockSelectionMode; /**< TRUE if the selection mode is 'Block', otherwise FALSE. */ int nSelStartTextRowFromLeftBar; /**< Stores the start selection line for full line selecting (from the left bar). */ private: CXTPSyntaxEditCtrl* m_pOwnerCtrl; XTP_EDIT_LINECOL selStart_disp; XTP_EDIT_LINECOL selEnd_disp; XTP_EDIT_LINECOL selStart_str; XTP_EDIT_LINECOL selEnd_str; protected: # ifdef _XTP_ACTIVEX /** @cond */ DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPSyntaxEditSelection) LPDISPATCH OleGetStart(); LPDISPATCH OleGetEnd(); LPDISPATCH OleGetNormalStart(); LPDISPATCH OleGetNormalEnd(); BSTR OleGetText(); void OleSetText(LPCTSTR pcszSelText); void OleReset(); CXTPSyntaxEditSelPosEx_imp* m_pAxStart; CXTPSyntaxEditSelPosEx_imp* m_pAxEnd; CXTPSyntaxEditSelPosExNormal_imp* m_pAxNormalStart; CXTPSyntaxEditSelPosExNormal_imp* m_pAxNormalEnd; /** @endcond */ # endif }; # ifdef _XTP_ACTIVEX /** @cond */ class _XTP_EXT_CLASS CXTPSyntaxEditTextPosition_imp : public CXTPCmdTarget { DECLARE_DYNAMIC(CXTPSyntaxEditTextPosition_imp) public: CXTPSyntaxEditTextPosition_imp(); virtual long OleGetRow() = 0; virtual long OleGetCol() = 0; virtual long OleGetStrPos() = 0; virtual void Ole_SetPos(long nRow, long nCol) = 0; virtual void Ole_SetPosStr(long nRow, long nStrPos) = 0; virtual void OleSetRow(long nRow) { Ole_SetPos(nRow, OleGetCol()); }; virtual void OleSetCol(long nCol) { Ole_SetPos(OleGetRow(), nCol); }; virtual void OleSetStrPos(long nStrPos) { Ole_SetPosStr(OleGetRow(), nStrPos); }; protected: DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPSyntaxEditTextPosition_imp) }; ////////////////////////////////////////////////////////////////////////// class _XTP_EXT_CLASS CXTPSyntaxEditSelPosEx_imp : public CXTPSyntaxEditTextPosition_imp { public: CXTPSyntaxEditSelPosEx_imp(CXTPSyntaxEditSelection* pOwner, BOOL bUseStart); virtual long OleGetRow(); virtual long OleGetCol(); virtual long OleGetStrPos(); virtual void Ole_SetPos(long nRow, long nCol); virtual void Ole_SetPosStr(long nRow, long nStrPos); void Detach() { m_pOwner = NULL; } protected: CXTPSyntaxEditSelection* m_pOwner; BOOL m_bUseStart; }; ////////////////////////////////////////////////////////////////////////// class _XTP_EXT_CLASS CXTPSyntaxEditSelPosExNormal_imp : public CXTPSyntaxEditSelPosEx_imp { public: CXTPSyntaxEditSelPosExNormal_imp(CXTPSyntaxEditSelection* pOwner, BOOL bUseStart); virtual long OleGetRow(); virtual long OleGetCol(); virtual long OleGetStrPos(); virtual void Ole_SetPos(long nRow, long nCol); virtual void Ole_SetPosStr(long nRow, long nStrPos); }; /** @endcond */ # endif ////////////////////////////////////////////////////////////////////////// AFX_INLINE const XTP_EDIT_LINECOL& CXTPSyntaxEditSelection::GetStart_str() const { return selStart_str; } AFX_INLINE const XTP_EDIT_LINECOL& CXTPSyntaxEditSelection::GetEnd_str() const { return selEnd_str; } AFX_INLINE const XTP_EDIT_LINECOL& CXTPSyntaxEditSelection::GetStart_disp() const { return selStart_disp; } AFX_INLINE const XTP_EDIT_LINECOL& CXTPSyntaxEditSelection::GetEnd_disp() const { return selEnd_disp; } AFX_INLINE BOOL CXTPSyntaxEditSelection::IsWordSelectionMode() const { return bWordSelectionMode; } AFX_INLINE BOOL CXTPSyntaxEditSelection::IsbBlockSelectionMode() const { return bBlockSelectionMode; } AFX_INLINE XTP_EDIT_LINECOL CXTPSyntaxEditSelection::GetNormalStart_str() const { if (bBlockSelectionMode) return XTP_EDIT_LINECOL::min2(selStart_str, selEnd_str); return selStart_str <= selEnd_str ? selStart_str : selEnd_str; } AFX_INLINE XTP_EDIT_LINECOL CXTPSyntaxEditSelection::GetNormalEnd_str() const { if (bBlockSelectionMode) return XTP_EDIT_LINECOL::max2(selStart_str, selEnd_str); return selEnd_str <= selStart_str ? selStart_str : selEnd_str; } AFX_INLINE XTP_EDIT_LINECOL CXTPSyntaxEditSelection::GetNormalStart_disp() const { if (bBlockSelectionMode) return XTP_EDIT_LINECOL::min2(selStart_disp, selEnd_disp); return selStart_disp <= selEnd_disp ? selStart_disp : selEnd_disp; } AFX_INLINE XTP_EDIT_LINECOL CXTPSyntaxEditSelection::GetNormalEnd_disp() const { if (bBlockSelectionMode) return XTP_EDIT_LINECOL::max2(selStart_disp, selEnd_disp); return selEnd_disp <= selStart_disp ? selStart_disp : selEnd_disp; } AFX_INLINE BOOL CXTPSyntaxEditSelection::IsSelNormal() const { return selStart_disp <= selEnd_disp; } AFX_INLINE BOOL CXTPSyntaxEditSelection::IsInSel_str(int nTextRow, int nStrPos) const { _ASSERTE(nStrPos >= 0); return _IsInSel(TRUE, nTextRow, nStrPos); } AFX_INLINE BOOL CXTPSyntaxEditSelection::IsInSel_disp(int nTextRow, int nDispCol) const { return _IsInSel(FALSE, nTextRow, nDispCol); } AFX_INLINE BOOL CXTPSyntaxEditSelection::IsIntersectSel_str(int nTextRow, int nStrPos1, int nStrPos2) const { return _IsIntersectSel(TRUE, nTextRow, nStrPos1, nStrPos2); } AFX_INLINE BOOL CXTPSyntaxEditSelection::IsIntersectSel_disp(int nTextRow, int nDispCol1, int nDispCol2) const { return _IsIntersectSel(FALSE, nTextRow, nDispCol1, nDispCol2); } # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // !defined(__XTPSYNTAXEDITSELECTION_H__) /** @endcond */