DragonNest/Third/XTToolkitPro/Source/SyntaxEdit/XTPSyntaxEditSelection.h
2024-12-19 09:48:26 +08:00

434 lines
17 KiB
C++

// XTPSyntaxEditSelection.h: interface for the CXTPSyntaxEditAutoCompleteWnd class.
//
// This file is a part of the XTREME TOOLKIT PRO MFC class library.
// (c)1998-2008 Codejock Software, All Rights Reserved.
//
// THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
// RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
// CONSENT OF CODEJOCK SOFTWARE.
//
// THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
// IN THE XTREME SYNTAX EDIT LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
// YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
// SINGLE COMPUTER.
//
// CONTACT INFORMATION:
// support@codejock.com
// http://www.codejock.com
//
//////////////////////////////////////////////////////////////////////
//{{AFX_CODEJOCK_PRIVATE
#if !defined(__XTPSYNTAXEDITSELECTION_H__)
#define __XTPSYNTAXEDITSELECTION_H__
//}}AFX_CODEJOCK_PRIVATE
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "XTPSyntaxEditStruct.h"
#include <imm.h>
//{{AFX_CODEJOCK_PRIVATE
//}}AFX_CODEJOCK_PRIVATE
//===========================================================================
// Summary:
// This class used to represent syntax edit text selection.
// It allow to get and set selection properties in 2 measurements:
// string and display. Also selection may be 'Normal' if its start less
// then its end, and 'Reverse' otherwise.
//===========================================================================
class _XTP_EXT_CLASS CXTPSyntaxEditSelection : public CXTPCmdTarget
{
//{{AFX_CODEJOCK_PRIVATE
friend class CXTPSyntaxEditCtrl;
friend class CXTPSyntaxEditSelection;
DECLARE_DYNAMIC(CXTPSyntaxEditSelection)
//}}AFX_CODEJOCK_PRIVATE
public:
//-----------------------------------------------------------------------
// Summary:
// Default object constructor.
//-----------------------------------------------------------------------
CXTPSyntaxEditSelection();
//-----------------------------------------------------------------------
// Summary:
// Copy constructor.
// Parameters:
// rSrc - [in] A reference to source object.
//-----------------------------------------------------------------------
CXTPSyntaxEditSelection(const CXTPSyntaxEditSelection& rSrc);
//-----------------------------------------------------------------------
// Summary:
// Default object destructor.
//-----------------------------------------------------------------------
virtual ~CXTPSyntaxEditSelection();
//-----------------------------------------------------------------------
// Summary:
// Get the selection start position where column is a zero based
// char index in the string.
// Returns:
// A reference to XTP_EDIT_LINECOL object which contains selection start.
// See Also:
// 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();
//-----------------------------------------------------------------------
// Summary:
// Get the selection end position where column is a zero based
// char index in the string.
// Returns:
// A reference to XTP_EDIT_LINECOL object which contains selection end.
// See Also:
// 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();
//-----------------------------------------------------------------------
// Summary:
// Get the selection start position where column is a 1 based
// column index on the screen.
// Returns:
// A reference to XTP_EDIT_LINECOL object which contains selection start.
// See Also:
// 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();
//-----------------------------------------------------------------------
// Summary:
// Get the selection end position where column is a 1 based
// column index on the screen.
// Returns:
// A reference to XTP_EDIT_LINECOL object which contains selection end.
// See Also:
// 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();
//-----------------------------------------------------------------------
// Summary:
// Get the normalized selection start.
// Returns:
// A reference to XTP_EDIT_LINECOL object which contains normalized
// selection start.
// See Also:
// 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();
XTP_EDIT_LINECOL GetNormalStart_disp();//<COMBINE GetNormalStart_str>
//-----------------------------------------------------------------------
// Summary:
// Get the normalized selection end.
// Returns:
// A reference to XTP_EDIT_LINECOL object which contains normalized
// selection end.
// See Also:
// 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();
XTP_EDIT_LINECOL GetNormalEnd_disp();//<COMBINE GetNormalEnd_str>
//-----------------------------------------------------------------------
// Summary:
// Set the selection start position.
// Parameters:
// nTextRow - A text row number.
// nStrPos - A zero based char index in the string.
// nDispCol - A 1 based column index on the screen.
// See Also:
// 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);
void SetStart_disp(int nTextRow, int nDispCol); //<COMBINE SetStart_str@int@int>
//-----------------------------------------------------------------------
// Summary:
// Set the selection end position.
// Parameters:
// nTextRow - A text row number.
// nStrPos - A zero based char index in the string.
// nDispCol - A 1 based column index on the screen.
// See Also:
// 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);
void SetEnd_disp(int nTextRow, int nDispCol); //<COMBINE SetEnd_str@int@int>
//-----------------------------------------------------------------------
// Summary:
// Set the selection start and end positions. The selection is empty
// in this case.
// Parameters:
// nTextRow - A text row number.
// nStrPos - A zero based char index in the string.
// nDispCol - A 1 based column index on the screen.
// See Also:
// 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);
void Reset_disp(int nTextRow, int nDispCol); //<COMBINE Reset_str@int@int>
//-----------------------------------------------------------------------
// Summary:
// Used to determine is selection mode 'Word' (enabled by press and
// hold Ctrl before selecting).
// Returns:
// TRUE if selection mode is 'Word', FALSE otherwise.
//-----------------------------------------------------------------------
BOOL IsWordSelectionMode() const;
//-----------------------------------------------------------------------
// Summary:
// Used to determine is selection mode 'Block' (enabled by press and
// hold Alt before selecting).
// Returns:
// TRUE if selection mode is 'Block', FALSE otherwise.
//-----------------------------------------------------------------------
BOOL IsbBlockSelectionMode() const;
//-----------------------------------------------------------------------
// Summary:
// Used to determine is selection exists (start != end).
// Returns:
// TRUE if selection exists, FALSE otherwise.
//-----------------------------------------------------------------------
BOOL IsSelExist();
//-----------------------------------------------------------------------
// Summary:
// Used to determine is selection 'Normal' (start < end).
// Returns:
// TRUE if selection 'Normal', FALSE otherwise.
//-----------------------------------------------------------------------
BOOL IsSelNormal();
//-----------------------------------------------------------------------
// Summary:
// Use this member function to determine is specified position inside
// the selection.
// Parameters:
// nTextRow - A text row number.
// nStrPos - A zero based char index in the string.
// nDispCol - A 1 based column index on the screen.
// Returns:
// TRUE if specified position inside the selection, FALSE otherwise.
//-----------------------------------------------------------------------
// See Also:
// IsIntersectSel_str, IsIntersectSel_disp
//-----------------------------------------------------------------------
BOOL IsInSel_str(int nTextRow, int nStrPos);
BOOL IsInSel_disp(int nTextRow, int nDispCol); //<COMBINE IsInSel_str@int@int>
//-----------------------------------------------------------------------
// Summary:
// Use this member function to determine is specified text range
// intersect the selection.
// Parameters:
// nTextRow - A text row number.
// nStrPos1 - Begin text range position (as zero based char index in the string).
// nStrPos2 - End text range position (as zero based char index in the string).
// nDispCol1 - Begin text range position (as 1 based column index on the screen).
// nDispCol2 - End text range position (as 1 based column index on the screen).
// Returns:
// TRUE if specified text range intersect the selection, FALSE otherwise.
// See Also:
// IsIntersectSel_str, IsIntersectSel_disp
//-----------------------------------------------------------------------
BOOL IsIntersectSel_str(int nTextRow, int nStrPos1, int nStrPos2);
BOOL IsIntersectSel_disp(int nTextRow, int nDispCol1, int nDispCol2); //<COMBINE IsIntersectSel_str@int@int>
//-----------------------------------------------------------------------
// Summary:
// Equality operator.
// Parameters:
// rSrc - Second CXTPSyntaxEditSelection object to compare.
// Remarks:
// Compare 2 CXTPSyntaxEditSelection objects.
// Returns:
// TRUE if specified objects are equal, otherwise FALSE.
//-----------------------------------------------------------------------
BOOL operator==(const CXTPSyntaxEditSelection& rSrc) const;
//-----------------------------------------------------------------------
// Summary:
// Non-Equality operator.
// Parameters:
// rSrc - Second CXTPSyntaxEditSelection object to compare.
// Remarks:
// Compare 2 CXTPSyntaxEditSelection objects.
// Returns:
// TRUE if specified objects are not equal, otherwise FALSE.
//-----------------------------------------------------------------------
BOOL operator!=(const CXTPSyntaxEditSelection& rSrc) const;
//-----------------------------------------------------------------------
// Summary:
// Copy operator.
// Parameters:
// rSrc - The source object.
// Remarks:
// Initialize members from the specified object.
// Returns:
// Reference to the current object.
//-----------------------------------------------------------------------
const CXTPSyntaxEditSelection& operator=(const CXTPSyntaxEditSelection& rSrc);
//{{AFX_CODEJOCK_PRIVATE
int GetSelStartForRow_str(int nTextRow, int nDispLine);
int GetSelEndForRow_str(int nTextRow, int nDispLine, BOOL* pbInfinitSelEnd);
//}}AFX_CODEJOCK_PRIVATE
protected:
//{{AFX_CODEJOCK_PRIVATE
BOOL _IsInSel(BOOL bStr, int nTextRow, int nColX);
BOOL _IsIntersectSel(BOOL bStr, int nTextRow, int nCol1, int nCol2);
//}}AFX_CODEJOCK_PRIVATE
protected:
BOOL bSelectingRunning; // Stores 'SelectingRunning' mode
BOOL bWordSelectionMode; // Stores 'Word' selecting mode
BOOL bBlockSelectionMode; // Stores 'Block' selecting mode
int nSelStartTextRowFromLeftBar; // Stores 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:
};
//////////////////////////////////////////////////////////////////////////
AFX_INLINE const XTP_EDIT_LINECOL& CXTPSyntaxEditSelection::GetStart_str() {
return selStart_str;
}
AFX_INLINE const XTP_EDIT_LINECOL& CXTPSyntaxEditSelection::GetEnd_str() {
return selEnd_str;
}
AFX_INLINE const XTP_EDIT_LINECOL& CXTPSyntaxEditSelection::GetStart_disp() {
return selStart_disp;
}
AFX_INLINE const XTP_EDIT_LINECOL& CXTPSyntaxEditSelection::GetEnd_disp() {
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() {
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() {
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() {
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() {
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() {
return selStart_disp <= selEnd_disp;
}
AFX_INLINE BOOL CXTPSyntaxEditSelection::IsInSel_str(int nTextRow, int nStrPos) {
ASSERT(nStrPos >= 0);
return _IsInSel(TRUE, nTextRow, nStrPos);
}
AFX_INLINE BOOL CXTPSyntaxEditSelection::IsInSel_disp(int nTextRow, int nDispCol) {
return _IsInSel(FALSE, nTextRow, nDispCol);
}
AFX_INLINE BOOL CXTPSyntaxEditSelection::IsIntersectSel_str(int nTextRow, int nStrPos1, int nStrPos2) {
return _IsIntersectSel(TRUE, nTextRow, nStrPos1, nStrPos2);
}
AFX_INLINE BOOL CXTPSyntaxEditSelection::IsIntersectSel_disp(int nTextRow, int nDispCol1, int nDispCol2) {
return _IsIntersectSel(FALSE, nTextRow, nDispCol1, nDispCol2);
}
//{{AFX_CODEJOCK_PRIVATE
class _XTP_EXT_CLASS CXTPImmWrapper
{
public:
CXTPImmWrapper();
virtual ~CXTPImmWrapper();
BOOL ImmIsIME(HKL hKL = NULL);
XTP_HIMC ImmGetContext(HWND hWnd);
BOOL ImmReleaseContext(HWND hWnd, XTP_HIMC hIMC);
BOOL ImmSetCompositionWindow(XTP_HIMC hIMC, COMPOSITIONFORM* pCompForm);
BOOL ImmSetCompositionFont(XTP_HIMC hIMC, LOGFONT* plfFont);
public:
typedef BOOL (WINAPI *PFN_ImmIsIME)(HKL);
typedef XTP_HIMC (WINAPI *PFN_ImmGetContext)(HWND);
typedef BOOL (WINAPI *PFN_ImmReleaseContext)(HWND, XTP_HIMC);
typedef BOOL (WINAPI *PFN_ImmSetCompositionFont)(XTP_HIMC, LPLOGFONT); // A/W
typedef BOOL (WINAPI *PFN_ImmSetCompositionWindow)(XTP_HIMC, COMPOSITIONFORM*);
protected:
HMODULE m_hImmDll; // Handle to the imm32 dll.
PFN_ImmIsIME m_pfnImmIsIME;
PFN_ImmGetContext m_pfnImmGetContext;
PFN_ImmReleaseContext m_pfnImmReleaseContext;
PFN_ImmSetCompositionFont m_pfnImmSetCompositionFont;
PFN_ImmSetCompositionWindow m_pfnImmSetCompositionWindow;
};
//}}AFX_CODEJOCK_PRIVATE
#endif // !defined(__XTPSYNTAXEDITSELECTION_H__)