2009-04-24 23:35:41 +00:00
|
|
|
// Scintilla source code edit control
|
|
|
|
/** @file ScintillaWin.cxx
|
|
|
|
** Windows specific subclass of ScintillaBase.
|
|
|
|
**/
|
|
|
|
// Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
|
|
|
|
// The License.txt file describes the conditions under which this software may be distributed.
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstdio>
|
2015-06-07 21:19:26 +00:00
|
|
|
#include <cmath>
|
2019-05-04 18:14:48 +00:00
|
|
|
#include <climits>
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <new>
|
2009-08-23 02:24:48 +00:00
|
|
|
#include <string>
|
2019-05-04 18:14:48 +00:00
|
|
|
#include <string_view>
|
2009-08-23 02:24:48 +00:00
|
|
|
#include <vector>
|
2013-08-28 00:44:27 +00:00
|
|
|
#include <map>
|
|
|
|
#include <algorithm>
|
2019-05-04 18:14:48 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <chrono>
|
2009-08-23 02:24:48 +00:00
|
|
|
|
2010-08-21 23:59:56 +00:00
|
|
|
#undef _WIN32_WINNT
|
2013-08-28 00:44:27 +00:00
|
|
|
#define _WIN32_WINNT 0x0500
|
|
|
|
#undef WINVER
|
|
|
|
#define WINVER 0x0500
|
2009-04-24 23:35:41 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <commctrl.h>
|
|
|
|
#include <richedit.h>
|
|
|
|
#include <windowsx.h>
|
2015-06-07 21:19:26 +00:00
|
|
|
#include <zmouse.h>
|
|
|
|
#include <ole2.h>
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
#if !defined(DISABLE_D2D)
|
2013-08-28 00:44:27 +00:00
|
|
|
#define USE_D2D 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(USE_D2D)
|
|
|
|
#include <d2d1.h>
|
|
|
|
#include <dwrite.h>
|
|
|
|
#endif
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
#include "Platform.h"
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
#include "ILoader.h"
|
2010-08-21 23:59:56 +00:00
|
|
|
#include "ILexer.h"
|
2009-04-24 23:35:41 +00:00
|
|
|
#include "Scintilla.h"
|
2010-08-21 23:59:56 +00:00
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
#ifdef SCI_LEXER
|
|
|
|
#include "SciLexer.h"
|
2015-06-07 21:19:26 +00:00
|
|
|
#endif
|
2019-07-21 13:26:02 +00:00
|
|
|
#include "CharacterCategory.h"
|
2015-06-07 21:19:26 +00:00
|
|
|
#ifdef SCI_LEXER
|
2010-08-21 23:59:56 +00:00
|
|
|
#include "LexerModule.h"
|
2009-04-24 23:35:41 +00:00
|
|
|
#endif
|
2019-05-04 18:14:48 +00:00
|
|
|
#include "Position.h"
|
|
|
|
#include "UniqueString.h"
|
2009-04-24 23:35:41 +00:00
|
|
|
#include "SplitVector.h"
|
|
|
|
#include "Partitioning.h"
|
|
|
|
#include "RunStyles.h"
|
|
|
|
#include "ContractionState.h"
|
|
|
|
#include "CellBuffer.h"
|
|
|
|
#include "CallTip.h"
|
|
|
|
#include "KeyMap.h"
|
|
|
|
#include "Indicator.h"
|
|
|
|
#include "LineMarker.h"
|
|
|
|
#include "Style.h"
|
|
|
|
#include "ViewStyle.h"
|
|
|
|
#include "CharClassify.h"
|
|
|
|
#include "Decoration.h"
|
2013-08-28 00:44:27 +00:00
|
|
|
#include "CaseFolder.h"
|
2009-04-24 23:35:41 +00:00
|
|
|
#include "Document.h"
|
2015-06-07 21:19:26 +00:00
|
|
|
#include "CaseConvert.h"
|
|
|
|
#include "UniConversion.h"
|
2009-08-23 02:24:48 +00:00
|
|
|
#include "Selection.h"
|
2009-04-24 23:35:41 +00:00
|
|
|
#include "PositionCache.h"
|
2015-06-07 21:19:26 +00:00
|
|
|
#include "EditModel.h"
|
|
|
|
#include "MarginView.h"
|
|
|
|
#include "EditView.h"
|
2009-04-24 23:35:41 +00:00
|
|
|
#include "Editor.h"
|
2019-05-04 18:14:48 +00:00
|
|
|
#include "ElapsedPeriod.h"
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
#include "AutoComplete.h"
|
|
|
|
#include "ScintillaBase.h"
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
#ifdef SCI_LEXER
|
|
|
|
#include "ExternalLexer.h"
|
|
|
|
#endif
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
#include "PlatWin.h"
|
|
|
|
#include "HanjaDic.h"
|
2019-05-04 18:14:48 +00:00
|
|
|
#include "ScintillaWin.h"
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
#ifndef SPI_GETWHEELSCROLLLINES
|
|
|
|
#define SPI_GETWHEELSCROLLLINES 104
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WM_UNICHAR
|
|
|
|
#define WM_UNICHAR 0x0109
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef UNICODE_NOCHAR
|
|
|
|
#define UNICODE_NOCHAR 0xFFFF
|
|
|
|
#endif
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
#ifndef IS_HIGH_SURROGATE
|
|
|
|
#define IS_HIGH_SURROGATE(x) ((x) >= SURROGATE_LEAD_FIRST && (x) <= SURROGATE_LEAD_LAST)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef IS_LOW_SURROGATE
|
|
|
|
#define IS_LOW_SURROGATE(x) ((x) >= SURROGATE_TRAIL_FIRST && (x) <= SURROGATE_TRAIL_LAST)
|
|
|
|
#endif
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
#ifndef MK_ALT
|
|
|
|
#define MK_ALT 32
|
|
|
|
#endif
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
// Two idle messages SC_WIN_IDLE and SC_WORK_IDLE.
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
// SC_WIN_IDLE is low priority so should occur after the next WM_PAINT
|
|
|
|
// It is for lengthy actions like wrapping and background styling
|
|
|
|
constexpr UINT SC_WIN_IDLE = 5001;
|
|
|
|
// SC_WORK_IDLE is high priority and should occur before the next WM_PAINT
|
|
|
|
// It is for shorter actions like restyling the text just inserted
|
|
|
|
// and delivering SCN_UPDATEUI
|
|
|
|
constexpr UINT SC_WORK_IDLE = 5002;
|
|
|
|
|
|
|
|
#define SC_INDICATOR_INPUT INDICATOR_IME
|
|
|
|
#define SC_INDICATOR_TARGET INDICATOR_IME+1
|
|
|
|
#define SC_INDICATOR_CONVERTED INDICATOR_IME+2
|
|
|
|
#define SC_INDICATOR_UNKNOWN INDICATOR_IME_MAX
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
#ifndef SCS_CAP_SETRECONVERTSTRING
|
|
|
|
#define SCS_CAP_SETRECONVERTSTRING 0x00000004
|
|
|
|
#define SCS_QUERYRECONVERTSTRING 0x00020000
|
|
|
|
#define SCS_SETRECONVERTSTRING 0x00010000
|
|
|
|
#endif
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
typedef UINT_PTR (WINAPI *SetCoalescableTimerSig)(HWND hwnd, UINT_PTR nIDEvent,
|
|
|
|
UINT uElapse, TIMERPROC lpTimerFunc, ULONG uToleranceDelay);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
// GCC has trouble with the standard COM ABI so do it the old C way with explicit vtables.
|
|
|
|
|
2009-04-25 23:38:15 +00:00
|
|
|
using namespace Scintilla;
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
const TCHAR callClassName[] = TEXT("CallTip");
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
void *PointerFromWindow(HWND hWnd) noexcept {
|
2011-07-17 22:30:49 +00:00
|
|
|
return reinterpret_cast<void *>(::GetWindowLongPtr(hWnd, 0));
|
|
|
|
}
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
void SetWindowPointer(HWND hWnd, void *ptr) noexcept {
|
2011-07-17 22:30:49 +00:00
|
|
|
::SetWindowLongPtr(hWnd, 0, reinterpret_cast<LONG_PTR>(ptr));
|
|
|
|
}
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
void SetWindowID(HWND hWnd, int identifier) noexcept {
|
2011-07-17 22:30:49 +00:00
|
|
|
::SetWindowLongPtr(hWnd, GWLP_ID, identifier);
|
|
|
|
}
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
Point PointFromPOINT(POINT pt) noexcept {
|
2015-06-07 21:19:26 +00:00
|
|
|
return Point::FromInts(pt.x, pt.y);
|
2011-07-17 22:30:49 +00:00
|
|
|
}
|
2019-07-21 13:26:02 +00:00
|
|
|
Point PointFromLParam(sptr_t lpoint) noexcept {
|
2019-05-04 18:14:48 +00:00
|
|
|
return Point::FromInts(GET_X_LPARAM(lpoint), GET_Y_LPARAM(lpoint));
|
|
|
|
}
|
|
|
|
constexpr POINT POINTFromPoint(Point pt) noexcept {
|
|
|
|
return POINT{ static_cast<LONG>(pt.x), static_cast<LONG>(pt.y) };
|
|
|
|
}
|
2019-07-21 13:26:02 +00:00
|
|
|
bool KeyboardIsKeyDown(int key) noexcept {
|
2019-05-04 18:14:48 +00:00
|
|
|
return (::GetKeyState(key) & 0x80000000) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2011-07-17 22:30:49 +00:00
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
class ScintillaWin; // Forward declaration for COM interface subobjects
|
|
|
|
|
2010-07-12 22:19:51 +00:00
|
|
|
typedef void VFunction(void);
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
class FormatEnumerator {
|
|
|
|
public:
|
2010-07-12 22:19:51 +00:00
|
|
|
VFunction **vtbl;
|
2009-04-24 23:35:41 +00:00
|
|
|
int ref;
|
2015-06-07 21:19:26 +00:00
|
|
|
unsigned int pos;
|
|
|
|
std::vector<CLIPFORMAT> formats;
|
|
|
|
FormatEnumerator(int pos_, CLIPFORMAT formats_[], size_t formatsLen_);
|
2009-04-24 23:35:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
class DropSource {
|
|
|
|
public:
|
2010-07-12 22:19:51 +00:00
|
|
|
VFunction **vtbl;
|
2009-04-24 23:35:41 +00:00
|
|
|
ScintillaWin *sci;
|
2019-07-21 13:26:02 +00:00
|
|
|
DropSource() noexcept;
|
2009-04-24 23:35:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
class DataObject {
|
|
|
|
public:
|
2010-07-12 22:19:51 +00:00
|
|
|
VFunction **vtbl;
|
2009-04-24 23:35:41 +00:00
|
|
|
ScintillaWin *sci;
|
2019-07-21 13:26:02 +00:00
|
|
|
DataObject() noexcept;
|
2009-04-24 23:35:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
class DropTarget {
|
|
|
|
public:
|
2010-07-12 22:19:51 +00:00
|
|
|
VFunction **vtbl;
|
2009-04-24 23:35:41 +00:00
|
|
|
ScintillaWin *sci;
|
2019-07-21 13:26:02 +00:00
|
|
|
DropTarget() noexcept;
|
2009-04-24 23:35:41 +00:00
|
|
|
};
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class IMContext {
|
|
|
|
HWND hwnd;
|
|
|
|
public:
|
|
|
|
HIMC hIMC;
|
2019-07-21 13:26:02 +00:00
|
|
|
IMContext(HWND hwnd_) noexcept :
|
2019-05-04 18:14:48 +00:00
|
|
|
hwnd(hwnd_), hIMC(::ImmGetContext(hwnd_)) {
|
|
|
|
}
|
|
|
|
// Deleted so IMContext objects can not be copied.
|
|
|
|
IMContext(const IMContext &) = delete;
|
|
|
|
IMContext(IMContext &&) = delete;
|
|
|
|
IMContext &operator=(const IMContext &) = delete;
|
|
|
|
IMContext &operator=(IMContext &&) = delete;
|
|
|
|
~IMContext() {
|
|
|
|
if (hIMC)
|
|
|
|
::ImmReleaseContext(hwnd, hIMC);
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
unsigned int GetImeCaretPos() const noexcept {
|
|
|
|
return ImmGetCompositionStringW(hIMC, GCS_CURSORPOS, nullptr, 0);
|
2019-05-04 18:14:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<BYTE> GetImeAttributes() {
|
2019-07-21 13:26:02 +00:00
|
|
|
const int attrLen = ::ImmGetCompositionStringW(hIMC, GCS_COMPATTR, nullptr, 0);
|
2019-05-04 18:14:48 +00:00
|
|
|
std::vector<BYTE> attr(attrLen, 0);
|
|
|
|
::ImmGetCompositionStringW(hIMC, GCS_COMPATTR, &attr[0], static_cast<DWORD>(attr.size()));
|
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::wstring GetCompositionString(DWORD dwIndex) {
|
2019-07-21 13:26:02 +00:00
|
|
|
const LONG byteLen = ::ImmGetCompositionStringW(hIMC, dwIndex, nullptr, 0);
|
2019-05-04 18:14:48 +00:00
|
|
|
std::wstring wcs(byteLen / 2, 0);
|
|
|
|
::ImmGetCompositionStringW(hIMC, dwIndex, &wcs[0], byteLen);
|
|
|
|
return wcs;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
class ScintillaWin :
|
|
|
|
public ScintillaBase {
|
|
|
|
|
|
|
|
bool lastKeyDownConsumed;
|
2019-05-04 18:14:48 +00:00
|
|
|
wchar_t lastHighSurrogateChar;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
bool capturedMouse;
|
2010-07-12 22:19:51 +00:00
|
|
|
bool trackedMouseLeave;
|
2015-06-07 21:19:26 +00:00
|
|
|
SetCoalescableTimerSig SetCoalescableTimerFn;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
unsigned int linesPerScroll; ///< Intellimouse support
|
|
|
|
int wheelDelta; ///< Wheel delta from roll
|
|
|
|
|
|
|
|
HRGN hRgnUpdate;
|
|
|
|
|
|
|
|
bool hasOKText;
|
|
|
|
|
|
|
|
CLIPFORMAT cfColumnSelect;
|
2015-06-07 21:19:26 +00:00
|
|
|
CLIPFORMAT cfBorlandIDEBlockType;
|
2009-04-24 23:35:41 +00:00
|
|
|
CLIPFORMAT cfLineSelect;
|
2015-06-07 21:19:26 +00:00
|
|
|
CLIPFORMAT cfVSLineTag;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
HRESULT hrOle;
|
|
|
|
DropSource ds;
|
|
|
|
DataObject dob;
|
|
|
|
DropTarget dt;
|
|
|
|
|
|
|
|
static HINSTANCE hInstance;
|
2015-06-07 21:19:26 +00:00
|
|
|
static ATOM scintillaClassAtom;
|
|
|
|
static ATOM callClassAtom;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
#if defined(USE_D2D)
|
2015-06-07 21:19:26 +00:00
|
|
|
ID2D1RenderTarget *pRenderTarget;
|
2013-08-28 00:44:27 +00:00
|
|
|
bool renderTargetValid;
|
|
|
|
#endif
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
explicit ScintillaWin(HWND hwnd);
|
2019-05-04 18:14:48 +00:00
|
|
|
// Deleted so ScintillaWin objects can not be copied.
|
|
|
|
ScintillaWin(const ScintillaWin &) = delete;
|
|
|
|
ScintillaWin(ScintillaWin &&) = delete;
|
|
|
|
ScintillaWin &operator=(const ScintillaWin &) = delete;
|
|
|
|
ScintillaWin &operator=(ScintillaWin &&) = delete;
|
2019-07-21 13:26:02 +00:00
|
|
|
// ~ScintillaWin() in public section
|
2019-05-04 18:14:48 +00:00
|
|
|
|
|
|
|
void Init();
|
|
|
|
void Finalise() override;
|
2013-08-28 00:44:27 +00:00
|
|
|
#if defined(USE_D2D)
|
2015-06-07 21:19:26 +00:00
|
|
|
void EnsureRenderTarget(HDC hdc);
|
2013-08-28 00:44:27 +00:00
|
|
|
void DropRenderTarget();
|
|
|
|
#endif
|
2019-07-21 13:26:02 +00:00
|
|
|
HWND MainHWND() const noexcept;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
static sptr_t DirectFunction(
|
2015-06-07 21:19:26 +00:00
|
|
|
sptr_t ptr, UINT iMessage, uptr_t wParam, sptr_t lParam);
|
2019-05-04 18:14:48 +00:00
|
|
|
static LRESULT PASCAL SWndProc(
|
|
|
|
HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam);
|
|
|
|
static LRESULT PASCAL CTWndProc(
|
|
|
|
HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
enum { invalidTimerID, standardTimerID, idleTimerID, fineTimerStart };
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
bool DragThreshold(Point ptStart, Point ptNow) override;
|
|
|
|
void StartDrag() override;
|
2019-07-21 13:26:02 +00:00
|
|
|
static int MouseModifiers(uptr_t wParam) noexcept;
|
2019-05-04 18:14:48 +00:00
|
|
|
|
|
|
|
Sci::Position TargetAsUTF8(char *text) const;
|
|
|
|
Sci::Position EncodedFromUTF8(const char *utf8, char *encoded) const;
|
2019-07-21 13:26:02 +00:00
|
|
|
sptr_t WndPaint();
|
2015-06-07 21:19:26 +00:00
|
|
|
|
|
|
|
sptr_t HandleCompositionWindowed(uptr_t wParam, sptr_t lParam);
|
|
|
|
sptr_t HandleCompositionInline(uptr_t wParam, sptr_t lParam);
|
2019-07-21 13:26:02 +00:00
|
|
|
static bool KoreanIME() noexcept;
|
2019-05-04 18:14:48 +00:00
|
|
|
void MoveImeCarets(Sci::Position offset);
|
2015-06-07 21:19:26 +00:00
|
|
|
void DrawImeIndicator(int indicator, int len);
|
|
|
|
void SetCandidateWindowPos();
|
|
|
|
void SelectionToHangul();
|
|
|
|
void EscapeHanja();
|
|
|
|
void ToggleHanja();
|
2019-07-21 13:26:02 +00:00
|
|
|
void AddWString(std::wstring_view wsv, CharacterSource charSource);
|
2015-06-07 21:19:26 +00:00
|
|
|
|
|
|
|
UINT CodePageOfDocument() const;
|
2019-05-04 18:14:48 +00:00
|
|
|
bool ValidCodePage(int codePage) const override;
|
|
|
|
sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) override;
|
2019-07-21 13:26:02 +00:00
|
|
|
void IdleWork() override;
|
|
|
|
void QueueIdleWork(WorkNeeded::workItems items, Sci::Position upTo) override;
|
2019-05-04 18:14:48 +00:00
|
|
|
bool SetIdle(bool on) override;
|
|
|
|
UINT_PTR timers[tickDwell+1] {};
|
|
|
|
bool FineTickerRunning(TickReason reason) override;
|
|
|
|
void FineTickerStart(TickReason reason, int millis, int tolerance) override;
|
|
|
|
void FineTickerCancel(TickReason reason) override;
|
|
|
|
void SetMouseCapture(bool on) override;
|
|
|
|
bool HaveMouseCapture() override;
|
2019-07-21 13:26:02 +00:00
|
|
|
void SetTrackMouseLeaveEvent(bool on) noexcept;
|
2019-05-04 18:14:48 +00:00
|
|
|
bool PaintContains(PRectangle rc) override;
|
|
|
|
void ScrollText(Sci::Line linesToMove) override;
|
|
|
|
void NotifyCaretMove() override;
|
|
|
|
void UpdateSystemCaret() override;
|
|
|
|
void SetVerticalScrollPos() override;
|
|
|
|
void SetHorizontalScrollPos() override;
|
|
|
|
bool ModifyScrollBars(Sci::Line nMax, Sci::Line nPage) override;
|
|
|
|
void NotifyChange() override;
|
|
|
|
void NotifyFocus(bool focus) override;
|
|
|
|
void SetCtrlID(int identifier) override;
|
|
|
|
int GetCtrlID() override;
|
|
|
|
void NotifyParent(SCNotification scn) override;
|
|
|
|
void NotifyDoubleClick(Point pt, int modifiers) override;
|
|
|
|
CaseFolder *CaseFolderForEncoding() override;
|
|
|
|
std::string CaseMapString(const std::string &s, int caseMapping) override;
|
|
|
|
void Copy() override;
|
|
|
|
void CopyAllowLine() override;
|
|
|
|
bool CanPaste() override;
|
|
|
|
void Paste() override;
|
|
|
|
void CreateCallTipWindow(PRectangle rc) override;
|
|
|
|
void AddToPopUp(const char *label, int cmd = 0, bool enabled = true) override;
|
|
|
|
void ClaimSelection() override;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
// DBCS
|
|
|
|
void ImeStartComposition();
|
|
|
|
void ImeEndComposition();
|
2019-05-04 18:14:48 +00:00
|
|
|
LRESULT ImeOnReconvert(LPARAM lParam);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
void GetIntelliMouseParameters() noexcept;
|
2019-05-04 18:14:48 +00:00
|
|
|
void CopyToClipboard(const SelectionText &selectedText) override;
|
2009-04-24 23:35:41 +00:00
|
|
|
void ScrollMessage(WPARAM wParam);
|
|
|
|
void HorizontalScrollMessage(WPARAM wParam);
|
|
|
|
void FullPaint();
|
2019-05-04 18:14:48 +00:00
|
|
|
void FullPaintDC(HDC hdc);
|
2019-07-21 13:26:02 +00:00
|
|
|
bool IsCompatibleDC(HDC hOtherDC) noexcept;
|
|
|
|
DWORD EffectFromState(DWORD grfKeyState) const noexcept;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
int SetScrollInfo(int nBar, LPCSCROLLINFO lpsi, BOOL bRedraw) noexcept;
|
|
|
|
bool GetScrollInfo(int nBar, LPSCROLLINFO lpsi) noexcept;
|
2019-05-04 18:14:48 +00:00
|
|
|
void ChangeScrollPos(int barType, Sci::Position pos);
|
2015-06-07 21:19:26 +00:00
|
|
|
sptr_t GetTextLength();
|
|
|
|
sptr_t GetText(uptr_t wParam, sptr_t lParam);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
public:
|
2019-07-21 13:26:02 +00:00
|
|
|
~ScintillaWin() override;
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
// Public for benefit of Scintilla_DirectFunction
|
2019-05-04 18:14:48 +00:00
|
|
|
sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) override;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
/// Implement IUnknown
|
|
|
|
STDMETHODIMP QueryInterface(REFIID riid, PVOID *ppv);
|
|
|
|
STDMETHODIMP_(ULONG)AddRef();
|
|
|
|
STDMETHODIMP_(ULONG)Release();
|
|
|
|
|
|
|
|
/// Implement IDropTarget
|
|
|
|
STDMETHODIMP DragEnter(LPDATAOBJECT pIDataSource, DWORD grfKeyState,
|
|
|
|
POINTL pt, PDWORD pdwEffect);
|
|
|
|
STDMETHODIMP DragOver(DWORD grfKeyState, POINTL pt, PDWORD pdwEffect);
|
|
|
|
STDMETHODIMP DragLeave();
|
|
|
|
STDMETHODIMP Drop(LPDATAOBJECT pIDataSource, DWORD grfKeyState,
|
|
|
|
POINTL pt, PDWORD pdwEffect);
|
|
|
|
|
|
|
|
/// Implement important part of IDataObject
|
|
|
|
STDMETHODIMP GetData(FORMATETC *pFEIn, STGMEDIUM *pSTM);
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
static bool Register(HINSTANCE hInstance_) noexcept;
|
|
|
|
static bool Unregister() noexcept;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
friend class DropSource;
|
|
|
|
friend class DataObject;
|
|
|
|
friend class DropTarget;
|
2019-07-21 13:26:02 +00:00
|
|
|
bool DragIsRectangularOK(CLIPFORMAT fmt) const noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
return drag.rectangular && (fmt == cfColumnSelect);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// For use in creating a system caret
|
2019-07-21 13:26:02 +00:00
|
|
|
bool HasCaretSizeChanged() const noexcept;
|
2009-04-24 23:35:41 +00:00
|
|
|
BOOL CreateSystemCaret();
|
2019-07-21 13:26:02 +00:00
|
|
|
BOOL DestroySystemCaret() noexcept;
|
2009-04-24 23:35:41 +00:00
|
|
|
HBITMAP sysCaretBitmap;
|
|
|
|
int sysCaretWidth;
|
|
|
|
int sysCaretHeight;
|
2019-07-21 13:26:02 +00:00
|
|
|
bool styleIdleInQueue;
|
2009-04-24 23:35:41 +00:00
|
|
|
};
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
HINSTANCE ScintillaWin::hInstance {};
|
2015-06-07 21:19:26 +00:00
|
|
|
ATOM ScintillaWin::scintillaClassAtom = 0;
|
|
|
|
ATOM ScintillaWin::callClassAtom = 0;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
ScintillaWin::ScintillaWin(HWND hwnd) {
|
|
|
|
|
|
|
|
lastKeyDownConsumed = false;
|
2019-05-04 18:14:48 +00:00
|
|
|
lastHighSurrogateChar = 0;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
capturedMouse = false;
|
2010-07-12 22:19:51 +00:00
|
|
|
trackedMouseLeave = false;
|
2019-05-04 18:14:48 +00:00
|
|
|
SetCoalescableTimerFn = nullptr;
|
2010-07-12 22:19:51 +00:00
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
linesPerScroll = 0;
|
|
|
|
wheelDelta = 0; // Wheel delta from roll
|
|
|
|
|
|
|
|
hRgnUpdate = 0;
|
|
|
|
|
|
|
|
hasOKText = false;
|
|
|
|
|
|
|
|
// There does not seem to be a real standard for indicating that the clipboard
|
2015-06-07 21:19:26 +00:00
|
|
|
// contains a rectangular selection, so copy Developer Studio and Borland Delphi.
|
2009-04-24 23:35:41 +00:00
|
|
|
cfColumnSelect = static_cast<CLIPFORMAT>(
|
|
|
|
::RegisterClipboardFormat(TEXT("MSDEVColumnSelect")));
|
2015-06-07 21:19:26 +00:00
|
|
|
cfBorlandIDEBlockType = static_cast<CLIPFORMAT>(
|
|
|
|
::RegisterClipboardFormat(TEXT("Borland IDE Block Type")));
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
// Likewise for line-copy (copies a full line when no text is selected)
|
|
|
|
cfLineSelect = static_cast<CLIPFORMAT>(
|
|
|
|
::RegisterClipboardFormat(TEXT("MSDEVLineSelect")));
|
2015-06-07 21:19:26 +00:00
|
|
|
cfVSLineTag = static_cast<CLIPFORMAT>(
|
|
|
|
::RegisterClipboardFormat(TEXT("VisualStudioEditorOperationsLineCutCopyClipboardTag")));
|
2009-04-24 23:35:41 +00:00
|
|
|
hrOle = E_FAIL;
|
|
|
|
|
|
|
|
wMain = hwnd;
|
|
|
|
|
|
|
|
dob.sci = this;
|
|
|
|
ds.sci = this;
|
|
|
|
dt.sci = this;
|
|
|
|
|
|
|
|
sysCaretBitmap = 0;
|
|
|
|
sysCaretWidth = 0;
|
|
|
|
sysCaretHeight = 0;
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
styleIdleInQueue = false;
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
#if defined(USE_D2D)
|
2019-05-04 18:14:48 +00:00
|
|
|
pRenderTarget = nullptr;
|
2013-08-28 00:44:27 +00:00
|
|
|
renderTargetValid = true;
|
|
|
|
#endif
|
|
|
|
|
2011-03-22 00:16:49 +00:00
|
|
|
caret.period = ::GetCaretBlinkTime();
|
|
|
|
if (caret.period < 0)
|
|
|
|
caret.period = 0;
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
Init();
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ScintillaWin::~ScintillaWin() {}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
void ScintillaWin::Init() {
|
2009-04-24 23:35:41 +00:00
|
|
|
// Initialize COM. If the app has already done this it will have
|
2019-05-04 18:14:48 +00:00
|
|
|
// no effect. If the app hasn't, we really shouldn't ask them to call
|
2009-04-24 23:35:41 +00:00
|
|
|
// it just so this internal feature works.
|
2019-05-04 18:14:48 +00:00
|
|
|
hrOle = ::OleInitialize(nullptr);
|
2010-07-12 22:19:51 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
// Find SetCoalescableTimer which is only available from Windows 8+
|
2010-07-12 22:19:51 +00:00
|
|
|
HMODULE user32 = ::GetModuleHandle(TEXT("user32.dll"));
|
2015-06-07 21:19:26 +00:00
|
|
|
if (user32) {
|
2019-05-04 18:14:48 +00:00
|
|
|
SetCoalescableTimerFn = reinterpret_cast<SetCoalescableTimerSig>(
|
|
|
|
::GetProcAddress(user32, "SetCoalescableTimer"));
|
2015-06-07 21:19:26 +00:00
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
vs.indicators[SC_INDICATOR_UNKNOWN] = Indicator(INDIC_HIDDEN, ColourDesired(0, 0, 0xff));
|
|
|
|
vs.indicators[SC_INDICATOR_INPUT] = Indicator(INDIC_DOTS, ColourDesired(0, 0, 0xff));
|
|
|
|
vs.indicators[SC_INDICATOR_CONVERTED] = Indicator(INDIC_COMPOSITIONTHICK, ColourDesired(0, 0, 0xff));
|
|
|
|
vs.indicators[SC_INDICATOR_TARGET] = Indicator(INDIC_STRAIGHTBOX, ColourDesired(0, 0, 0xff));
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::Finalise() {
|
|
|
|
ScintillaBase::Finalise();
|
2015-06-07 21:19:26 +00:00
|
|
|
for (TickReason tr = tickCaret; tr <= tickDwell; tr = static_cast<TickReason>(tr + 1)) {
|
|
|
|
FineTickerCancel(tr);
|
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
SetIdle(false);
|
2013-08-28 00:44:27 +00:00
|
|
|
#if defined(USE_D2D)
|
|
|
|
DropRenderTarget();
|
|
|
|
#endif
|
2009-04-24 23:35:41 +00:00
|
|
|
::RevokeDragDrop(MainHWND());
|
|
|
|
if (SUCCEEDED(hrOle)) {
|
|
|
|
::OleUninitialize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
#if defined(USE_D2D)
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
void ScintillaWin::EnsureRenderTarget(HDC hdc) {
|
2013-08-28 00:44:27 +00:00
|
|
|
if (!renderTargetValid) {
|
|
|
|
DropRenderTarget();
|
|
|
|
renderTargetValid = true;
|
|
|
|
}
|
|
|
|
if (pD2DFactory && !pRenderTarget) {
|
|
|
|
HWND hw = MainHWND();
|
2019-05-04 18:14:48 +00:00
|
|
|
RECT rc;
|
2013-08-28 00:44:27 +00:00
|
|
|
GetClientRect(hw, &rc);
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
const D2D1_SIZE_U size = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top);
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
// Create a Direct2D render target.
|
|
|
|
#if 1
|
|
|
|
D2D1_RENDER_TARGET_PROPERTIES drtp;
|
|
|
|
drtp.type = D2D1_RENDER_TARGET_TYPE_DEFAULT;
|
|
|
|
drtp.pixelFormat.format = DXGI_FORMAT_UNKNOWN;
|
|
|
|
drtp.pixelFormat.alphaMode = D2D1_ALPHA_MODE_UNKNOWN;
|
|
|
|
drtp.dpiX = 96.0;
|
|
|
|
drtp.dpiY = 96.0;
|
|
|
|
drtp.usage = D2D1_RENDER_TARGET_USAGE_NONE;
|
|
|
|
drtp.minLevel = D2D1_FEATURE_LEVEL_DEFAULT;
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
if (technology == SC_TECHNOLOGY_DIRECTWRITEDC) {
|
|
|
|
// Explicit pixel format needed.
|
|
|
|
drtp.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM,
|
|
|
|
D2D1_ALPHA_MODE_IGNORE);
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
ID2D1DCRenderTarget *pDCRT = nullptr;
|
|
|
|
const HRESULT hr = pD2DFactory->CreateDCRenderTarget(&drtp, &pDCRT);
|
2015-06-07 21:19:26 +00:00
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
pRenderTarget = pDCRT;
|
|
|
|
} else {
|
2019-07-21 13:26:02 +00:00
|
|
|
Platform::DebugPrintf("Failed CreateDCRenderTarget 0x%lx\n", hr);
|
2019-05-04 18:14:48 +00:00
|
|
|
pRenderTarget = nullptr;
|
2015-06-07 21:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
D2D1_HWND_RENDER_TARGET_PROPERTIES dhrtp;
|
|
|
|
dhrtp.hwnd = hw;
|
|
|
|
dhrtp.pixelSize = size;
|
|
|
|
dhrtp.presentOptions = (technology == SC_TECHNOLOGY_DIRECTWRITERETAIN) ?
|
|
|
|
D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS : D2D1_PRESENT_OPTIONS_NONE;
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
ID2D1HwndRenderTarget *pHwndRenderTarget = nullptr;
|
|
|
|
const HRESULT hr = pD2DFactory->CreateHwndRenderTarget(drtp, dhrtp, &pHwndRenderTarget);
|
2015-06-07 21:19:26 +00:00
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
pRenderTarget = pHwndRenderTarget;
|
|
|
|
} else {
|
2019-07-21 13:26:02 +00:00
|
|
|
Platform::DebugPrintf("Failed CreateHwndRenderTarget 0x%lx\n", hr);
|
2019-05-04 18:14:48 +00:00
|
|
|
pRenderTarget = nullptr;
|
2015-06-07 21:19:26 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
#else
|
|
|
|
pD2DFactory->CreateHwndRenderTarget(
|
|
|
|
D2D1::RenderTargetProperties(
|
|
|
|
D2D1_RENDER_TARGET_TYPE_DEFAULT ,
|
|
|
|
D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED),
|
|
|
|
96.0f, 96.0f, D2D1_RENDER_TARGET_USAGE_NONE, D2D1_FEATURE_LEVEL_DEFAULT),
|
|
|
|
D2D1::HwndRenderTargetProperties(hw, size),
|
|
|
|
&pRenderTarget);
|
|
|
|
#endif
|
|
|
|
// Pixmaps were created to be compatible with previous render target so
|
|
|
|
// need to be recreated.
|
|
|
|
DropGraphics(false);
|
|
|
|
}
|
2015-06-07 21:19:26 +00:00
|
|
|
|
|
|
|
if ((technology == SC_TECHNOLOGY_DIRECTWRITEDC) && pRenderTarget) {
|
|
|
|
RECT rcWindow;
|
|
|
|
GetClientRect(MainHWND(), &rcWindow);
|
2019-05-04 18:14:48 +00:00
|
|
|
const HRESULT hr = static_cast<ID2D1DCRenderTarget*>(pRenderTarget)->BindDC(hdc, &rcWindow);
|
2015-06-07 21:19:26 +00:00
|
|
|
if (FAILED(hr)) {
|
2019-07-21 13:26:02 +00:00
|
|
|
Platform::DebugPrintf("BindDC failed 0x%lx\n", hr);
|
2015-06-07 21:19:26 +00:00
|
|
|
DropRenderTarget();
|
|
|
|
}
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::DropRenderTarget() {
|
|
|
|
if (pRenderTarget) {
|
|
|
|
pRenderTarget->Release();
|
2019-05-04 18:14:48 +00:00
|
|
|
pRenderTarget = nullptr;
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
HWND ScintillaWin::MainHWND() const noexcept {
|
2019-05-04 18:14:48 +00:00
|
|
|
return static_cast<HWND>(wMain.GetID());
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ScintillaWin::DragThreshold(Point ptStart, Point ptNow) {
|
2019-07-21 13:26:02 +00:00
|
|
|
const Point ptDifference = ptStart - ptNow;
|
|
|
|
const XYPOSITION xMove = std::trunc(std::abs(ptDifference.x));
|
|
|
|
const XYPOSITION yMove = std::trunc(std::abs(ptDifference.y));
|
2009-04-24 23:35:41 +00:00
|
|
|
return (xMove > ::GetSystemMetrics(SM_CXDRAG)) ||
|
|
|
|
(yMove > ::GetSystemMetrics(SM_CYDRAG));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::StartDrag() {
|
|
|
|
inDragDrop = ddDragging;
|
|
|
|
DWORD dwEffect = 0;
|
|
|
|
dropWentOutside = true;
|
|
|
|
IDataObject *pDataObject = reinterpret_cast<IDataObject *>(&dob);
|
|
|
|
IDropSource *pDropSource = reinterpret_cast<IDropSource *>(&ds);
|
|
|
|
//Platform::DebugPrintf("About to DoDragDrop %x %x\n", pDataObject, pDropSource);
|
2019-05-04 18:14:48 +00:00
|
|
|
const HRESULT hr = ::DoDragDrop(
|
2009-04-24 23:35:41 +00:00
|
|
|
pDataObject,
|
|
|
|
pDropSource,
|
|
|
|
DROPEFFECT_COPY | DROPEFFECT_MOVE, &dwEffect);
|
|
|
|
//Platform::DebugPrintf("DoDragDrop = %x\n", hr);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
if ((hr == DRAGDROP_S_DROP) && (dwEffect == DROPEFFECT_MOVE) && dropWentOutside) {
|
|
|
|
// Remove dragged out text
|
|
|
|
ClearSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inDragDrop = ddNone;
|
2019-05-04 18:14:48 +00:00
|
|
|
SetDragPosition(SelectionPosition(Sci::invalidPosition));
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
int ScintillaWin::MouseModifiers(uptr_t wParam) noexcept {
|
2019-05-04 18:14:48 +00:00
|
|
|
return ModifierFlags((wParam & MK_SHIFT) != 0,
|
|
|
|
(wParam & MK_CONTROL) != 0,
|
|
|
|
KeyboardIsKeyDown(VK_MENU));
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
namespace {
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
int InputCodePage() noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
HKL inputLocale = ::GetKeyboardLayout(0);
|
2019-05-04 18:14:48 +00:00
|
|
|
const LANGID inputLang = LOWORD(inputLocale);
|
2009-04-24 23:35:41 +00:00
|
|
|
char sCodePage[10];
|
2019-05-04 18:14:48 +00:00
|
|
|
const int res = ::GetLocaleInfoA(MAKELCID(inputLang, SORT_DEFAULT),
|
2009-04-24 23:35:41 +00:00
|
|
|
LOCALE_IDEFAULTANSICODEPAGE, sCodePage, sizeof(sCodePage));
|
|
|
|
if (!res)
|
|
|
|
return 0;
|
|
|
|
return atoi(sCodePage);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Map the key codes to their equivalent SCK_ form. */
|
2019-07-21 13:26:02 +00:00
|
|
|
int KeyTranslate(int keyIn) noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
//PLATFORM_ASSERT(!keyIn);
|
|
|
|
switch (keyIn) {
|
|
|
|
case VK_DOWN: return SCK_DOWN;
|
|
|
|
case VK_UP: return SCK_UP;
|
|
|
|
case VK_LEFT: return SCK_LEFT;
|
|
|
|
case VK_RIGHT: return SCK_RIGHT;
|
|
|
|
case VK_HOME: return SCK_HOME;
|
|
|
|
case VK_END: return SCK_END;
|
|
|
|
case VK_PRIOR: return SCK_PRIOR;
|
|
|
|
case VK_NEXT: return SCK_NEXT;
|
|
|
|
case VK_DELETE: return SCK_DELETE;
|
|
|
|
case VK_INSERT: return SCK_INSERT;
|
|
|
|
case VK_ESCAPE: return SCK_ESCAPE;
|
|
|
|
case VK_BACK: return SCK_BACK;
|
|
|
|
case VK_TAB: return SCK_TAB;
|
|
|
|
case VK_RETURN: return SCK_RETURN;
|
|
|
|
case VK_ADD: return SCK_ADD;
|
|
|
|
case VK_SUBTRACT: return SCK_SUBTRACT;
|
|
|
|
case VK_DIVIDE: return SCK_DIVIDE;
|
|
|
|
case VK_LWIN: return SCK_WIN;
|
|
|
|
case VK_RWIN: return SCK_RWIN;
|
|
|
|
case VK_APPS: return SCK_MENU;
|
|
|
|
case VK_OEM_2: return '/';
|
|
|
|
case VK_OEM_3: return '`';
|
|
|
|
case VK_OEM_4: return '[';
|
|
|
|
case VK_OEM_5: return '\\';
|
|
|
|
case VK_OEM_6: return ']';
|
|
|
|
default: return keyIn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
bool BoundsContains(PRectangle rcBounds, HRGN hRgnBounds, PRectangle rcCheck) noexcept {
|
2015-06-07 21:19:26 +00:00
|
|
|
bool contains = true;
|
|
|
|
if (!rcCheck.Empty()) {
|
|
|
|
if (!rcBounds.Contains(rcCheck)) {
|
|
|
|
contains = false;
|
|
|
|
} else if (hRgnBounds) {
|
|
|
|
// In bounding rectangle so check more accurately using region
|
2019-05-04 18:14:48 +00:00
|
|
|
const RECT rcw = RectFromPRectangle(rcCheck);
|
|
|
|
HRGN hRgnCheck = ::CreateRectRgnIndirect(&rcw);
|
2015-06-07 21:19:26 +00:00
|
|
|
if (hRgnCheck) {
|
|
|
|
HRGN hRgnDifference = ::CreateRectRgn(0, 0, 0, 0);
|
|
|
|
if (hRgnDifference) {
|
2019-05-04 18:14:48 +00:00
|
|
|
const int combination = ::CombineRgn(hRgnDifference, hRgnCheck, hRgnBounds, RGN_DIFF);
|
2015-06-07 21:19:26 +00:00
|
|
|
if (combination != NULLREGION) {
|
|
|
|
contains = false;
|
|
|
|
}
|
|
|
|
::DeleteRgn(hRgnDifference);
|
|
|
|
}
|
|
|
|
::DeleteRgn(hRgnCheck);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return contains;
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
// Simplify calling WideCharToMultiByte and MultiByteToWideChar by providing default parameters and using string view.
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
int MultiByteFromWideChar(UINT codePage, std::wstring_view wsv, LPSTR lpMultiByteStr, ptrdiff_t cbMultiByte) noexcept {
|
2019-05-04 18:14:48 +00:00
|
|
|
return ::WideCharToMultiByte(codePage, 0, wsv.data(), static_cast<int>(wsv.length()), lpMultiByteStr, static_cast<int>(cbMultiByte), nullptr, nullptr);
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
int MultiByteLenFromWideChar(UINT codePage, std::wstring_view wsv) noexcept {
|
2019-05-04 18:14:48 +00:00
|
|
|
return MultiByteFromWideChar(codePage, wsv, nullptr, 0);
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
int WideCharFromMultiByte(UINT codePage, std::string_view sv, LPWSTR lpWideCharStr, ptrdiff_t cchWideChar) noexcept {
|
2019-05-04 18:14:48 +00:00
|
|
|
return ::MultiByteToWideChar(codePage, 0, sv.data(), static_cast<int>(sv.length()), lpWideCharStr, static_cast<int>(cchWideChar));
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
int WideCharLenFromMultiByte(UINT codePage, std::string_view sv) noexcept {
|
2019-05-04 18:14:48 +00:00
|
|
|
return WideCharFromMultiByte(codePage, sv, nullptr, 0);
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
std::string StringEncode(std::wstring_view wsv, int codePage) {
|
|
|
|
const int cchMulti = wsv.length() ? MultiByteLenFromWideChar(codePage, wsv) : 0;
|
2019-05-04 18:14:48 +00:00
|
|
|
std::string sMulti(cchMulti, 0);
|
|
|
|
if (cchMulti) {
|
2019-07-21 13:26:02 +00:00
|
|
|
MultiByteFromWideChar(codePage, wsv, sMulti.data(), cchMulti);
|
2019-05-04 18:14:48 +00:00
|
|
|
}
|
|
|
|
return sMulti;
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
std::wstring StringDecode(std::string_view sv, int codePage) {
|
|
|
|
const int cchWide = sv.length() ? WideCharLenFromMultiByte(codePage, sv) : 0;
|
2019-05-04 18:14:48 +00:00
|
|
|
std::wstring sWide(cchWide, 0);
|
|
|
|
if (cchWide) {
|
2019-07-21 13:26:02 +00:00
|
|
|
WideCharFromMultiByte(codePage, sv, sWide.data(), cchWide);
|
2019-05-04 18:14:48 +00:00
|
|
|
}
|
|
|
|
return sWide;
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
std::wstring StringMapCase(std::wstring_view wsv, DWORD mapFlags) {
|
2019-05-04 18:14:48 +00:00
|
|
|
const int charsConverted = ::LCMapStringW(LOCALE_SYSTEM_DEFAULT, mapFlags,
|
2019-07-21 13:26:02 +00:00
|
|
|
wsv.data(), static_cast<int>(wsv.length()), nullptr, 0);
|
2019-05-04 18:14:48 +00:00
|
|
|
std::wstring wsConverted(charsConverted, 0);
|
|
|
|
if (charsConverted) {
|
|
|
|
::LCMapStringW(LOCALE_SYSTEM_DEFAULT, mapFlags,
|
2019-07-21 13:26:02 +00:00
|
|
|
wsv.data(), static_cast<int>(wsv.length()), wsConverted.data(), charsConverted);
|
2019-05-04 18:14:48 +00:00
|
|
|
}
|
|
|
|
return wsConverted;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
// Returns the target converted to UTF8.
|
|
|
|
// Return the length in bytes.
|
2019-05-04 18:14:48 +00:00
|
|
|
Sci::Position ScintillaWin::TargetAsUTF8(char *text) const {
|
|
|
|
const Sci::Position targetLength = targetEnd - targetStart;
|
2015-06-07 21:19:26 +00:00
|
|
|
if (IsUnicodeMode()) {
|
|
|
|
if (text) {
|
|
|
|
pdoc->GetCharRange(text, targetStart, targetLength);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Need to convert
|
2019-05-04 18:14:48 +00:00
|
|
|
const std::string s = RangeText(targetStart, targetEnd);
|
|
|
|
const std::wstring characters = StringDecode(s, CodePageOfDocument());
|
|
|
|
const int utf8Len = MultiByteLenFromWideChar(CP_UTF8, characters);
|
2015-06-07 21:19:26 +00:00
|
|
|
if (text) {
|
2019-05-04 18:14:48 +00:00
|
|
|
MultiByteFromWideChar(CP_UTF8, characters, text, utf8Len);
|
2015-06-07 21:19:26 +00:00
|
|
|
text[utf8Len] = '\0';
|
|
|
|
}
|
|
|
|
return utf8Len;
|
|
|
|
}
|
|
|
|
return targetLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Translates a nul terminated UTF8 string into the document encoding.
|
|
|
|
// Return the length of the result in bytes.
|
2019-05-04 18:14:48 +00:00
|
|
|
Sci::Position ScintillaWin::EncodedFromUTF8(const char *utf8, char *encoded) const {
|
|
|
|
const Sci::Position inputLength = (lengthForEncode >= 0) ? lengthForEncode : strlen(utf8);
|
2015-06-07 21:19:26 +00:00
|
|
|
if (IsUnicodeMode()) {
|
|
|
|
if (encoded) {
|
|
|
|
memcpy(encoded, utf8, inputLength);
|
|
|
|
}
|
|
|
|
return inputLength;
|
|
|
|
} else {
|
|
|
|
// Need to convert
|
2019-05-04 18:14:48 +00:00
|
|
|
const std::string_view utf8Input(utf8, inputLength);
|
|
|
|
const int charsLen = WideCharLenFromMultiByte(CP_UTF8, utf8Input);
|
|
|
|
std::wstring characters(charsLen, L'\0');
|
|
|
|
WideCharFromMultiByte(CP_UTF8, utf8Input, &characters[0], charsLen);
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
const int encodedLen = MultiByteLenFromWideChar(CodePageOfDocument(), characters);
|
2015-06-07 21:19:26 +00:00
|
|
|
if (encoded) {
|
2019-05-04 18:14:48 +00:00
|
|
|
MultiByteFromWideChar(CodePageOfDocument(), characters, encoded, encodedLen);
|
2015-06-07 21:19:26 +00:00
|
|
|
encoded[encodedLen] = '\0';
|
|
|
|
}
|
|
|
|
return encodedLen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
sptr_t ScintillaWin::WndPaint() {
|
2019-05-04 18:14:48 +00:00
|
|
|
//ElapsedPeriod ep;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
// Redirect assertions to debug output and save current state
|
2019-05-04 18:14:48 +00:00
|
|
|
const bool assertsPopup = Platform::ShowAssertionPopUps(false);
|
2009-04-24 23:35:41 +00:00
|
|
|
paintState = painting;
|
2019-07-21 13:26:02 +00:00
|
|
|
PAINTSTRUCT ps = {};
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
// Removed since this interferes with reporting other assertions as it occurs repeatedly
|
|
|
|
//PLATFORM_ASSERT(hRgnUpdate == NULL);
|
|
|
|
hRgnUpdate = ::CreateRectRgn(0, 0, 0, 0);
|
2019-07-21 13:26:02 +00:00
|
|
|
::GetUpdateRgn(MainHWND(), hRgnUpdate, FALSE);
|
|
|
|
::BeginPaint(MainHWND(), &ps);
|
|
|
|
rcPaint = PRectangle::FromInts(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
|
2019-05-04 18:14:48 +00:00
|
|
|
const PRectangle rcClient = GetClientRectangle();
|
2015-06-07 21:19:26 +00:00
|
|
|
paintingAllText = BoundsContains(rcPaint, hRgnUpdate, rcClient);
|
2013-08-28 00:44:27 +00:00
|
|
|
if (technology == SC_TECHNOLOGY_DEFAULT) {
|
2019-07-21 13:26:02 +00:00
|
|
|
AutoSurface surfaceWindow(ps.hdc, this);
|
2013-08-28 00:44:27 +00:00
|
|
|
if (surfaceWindow) {
|
|
|
|
Paint(surfaceWindow, rcPaint);
|
|
|
|
surfaceWindow->Release();
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
} else {
|
|
|
|
#if defined(USE_D2D)
|
2019-07-21 13:26:02 +00:00
|
|
|
EnsureRenderTarget(ps.hdc);
|
2015-06-07 21:19:26 +00:00
|
|
|
AutoSurface surfaceWindow(pRenderTarget, this);
|
|
|
|
if (surfaceWindow) {
|
|
|
|
pRenderTarget->BeginDraw();
|
|
|
|
Paint(surfaceWindow, rcPaint);
|
|
|
|
surfaceWindow->Release();
|
2019-05-04 18:14:48 +00:00
|
|
|
const HRESULT hr = pRenderTarget->EndDraw();
|
|
|
|
if (hr == static_cast<HRESULT>(D2DERR_RECREATE_TARGET)) {
|
2015-06-07 21:19:26 +00:00
|
|
|
DropRenderTarget();
|
|
|
|
paintState = paintAbandoned;
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
if (hRgnUpdate) {
|
|
|
|
::DeleteRgn(hRgnUpdate);
|
|
|
|
hRgnUpdate = 0;
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
::EndPaint(MainHWND(), &ps);
|
2009-04-24 23:35:41 +00:00
|
|
|
if (paintState == paintAbandoned) {
|
|
|
|
// Painting area was insufficient to cover new styling or brace highlight positions
|
2019-07-21 13:26:02 +00:00
|
|
|
FullPaint();
|
|
|
|
::ValidateRect(MainHWND(), nullptr);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
paintState = notPainting;
|
|
|
|
|
|
|
|
// Restore debug output state
|
|
|
|
Platform::ShowAssertionPopUps(assertsPopup);
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
//Platform::DebugPrintf("Paint took %g\n", ep.Duration());
|
|
|
|
return 0;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
sptr_t ScintillaWin::HandleCompositionWindowed(uptr_t wParam, sptr_t lParam) {
|
2009-04-24 23:35:41 +00:00
|
|
|
if (lParam & GCS_RESULTSTR) {
|
2019-05-04 18:14:48 +00:00
|
|
|
IMContext imc(MainHWND());
|
|
|
|
if (imc.hIMC) {
|
2019-07-21 13:26:02 +00:00
|
|
|
AddWString(imc.GetCompositionString(GCS_RESULTSTR), CharacterSource::imeResult);
|
2019-05-04 18:14:48 +00:00
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
// Set new position after converted
|
2019-05-04 18:14:48 +00:00
|
|
|
const Point pos = PointMainCaret();
|
2009-04-24 23:35:41 +00:00
|
|
|
COMPOSITIONFORM CompForm;
|
|
|
|
CompForm.dwStyle = CFS_POINT;
|
2019-05-04 18:14:48 +00:00
|
|
|
CompForm.ptCurrentPos = POINTFromPoint(pos);
|
|
|
|
::ImmSetCompositionWindow(imc.hIMC, &CompForm);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ::DefWindowProc(MainHWND(), WM_IME_COMPOSITION, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
bool ScintillaWin::KoreanIME() noexcept {
|
2015-06-07 21:19:26 +00:00
|
|
|
const int codePage = InputCodePage();
|
|
|
|
return codePage == 949 || codePage == 1361;
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
void ScintillaWin::MoveImeCarets(Sci::Position offset) {
|
2015-06-07 21:19:26 +00:00
|
|
|
// Move carets relatively by bytes.
|
|
|
|
for (size_t r=0; r<sel.Count(); r++) {
|
2019-05-04 18:14:48 +00:00
|
|
|
const Sci::Position positionInsert = sel.Range(r).Start().Position();
|
2015-06-07 21:19:26 +00:00
|
|
|
sel.Range(r).caret.SetPosition(positionInsert + offset);
|
|
|
|
sel.Range(r).anchor.SetPosition(positionInsert + offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::DrawImeIndicator(int indicator, int len) {
|
|
|
|
// Emulate the visual style of IME characters with indicators.
|
|
|
|
// Draw an indicator on the character before caret by the character bytes of len
|
2019-07-21 13:26:02 +00:00
|
|
|
// so it should be called after InsertCharacter().
|
2015-06-07 21:19:26 +00:00
|
|
|
// It does not affect caret positions.
|
2019-07-21 13:26:02 +00:00
|
|
|
if (indicator < 8 || indicator > INDICATOR_MAX) {
|
2015-06-07 21:19:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
pdoc->DecorationSetCurrentIndicator(indicator);
|
2015-06-07 21:19:26 +00:00
|
|
|
for (size_t r=0; r<sel.Count(); r++) {
|
2019-05-04 18:14:48 +00:00
|
|
|
const Sci::Position positionInsert = sel.Range(r).Start().Position();
|
2015-06-07 21:19:26 +00:00
|
|
|
pdoc->DecorationFillRange(positionInsert - len, 1, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::SetCandidateWindowPos() {
|
2019-05-04 18:14:48 +00:00
|
|
|
IMContext imc(MainHWND());
|
|
|
|
if (imc.hIMC) {
|
|
|
|
const Point pos = PointMainCaret();
|
2015-06-07 21:19:26 +00:00
|
|
|
CANDIDATEFORM CandForm;
|
|
|
|
CandForm.dwIndex = 0;
|
|
|
|
CandForm.dwStyle = CFS_CANDIDATEPOS;
|
|
|
|
CandForm.ptCurrentPos.x = static_cast<int>(pos.x);
|
|
|
|
CandForm.ptCurrentPos.y = static_cast<int>(pos.y + vs.lineHeight);
|
2019-05-04 18:14:48 +00:00
|
|
|
::ImmSetCandidateWindow(imc.hIMC, &CandForm);
|
2015-06-07 21:19:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::SelectionToHangul() {
|
|
|
|
// Convert every hanja to hangul within the main range.
|
2019-05-04 18:14:48 +00:00
|
|
|
const Sci::Position selStart = sel.RangeMain().Start().Position();
|
|
|
|
const Sci::Position documentStrLen = sel.RangeMain().Length();
|
|
|
|
const Sci::Position selEnd = selStart + documentStrLen;
|
|
|
|
const Sci::Position utf16Len = pdoc->CountUTF16(selStart, selEnd);
|
2015-06-07 21:19:26 +00:00
|
|
|
|
|
|
|
if (utf16Len > 0) {
|
|
|
|
std::string documentStr(documentStrLen, '\0');
|
|
|
|
pdoc->GetCharRange(&documentStr[0], selStart, documentStrLen);
|
|
|
|
|
|
|
|
std::wstring uniStr = StringDecode(documentStr, CodePageOfDocument());
|
2019-05-04 18:14:48 +00:00
|
|
|
const int converted = HanjaDict::GetHangulOfHanja(&uniStr[0]);
|
2015-06-07 21:19:26 +00:00
|
|
|
documentStr = StringEncode(uniStr, CodePageOfDocument());
|
|
|
|
|
|
|
|
if (converted > 0) {
|
|
|
|
pdoc->BeginUndoAction();
|
|
|
|
ClearSelection();
|
2019-05-04 18:14:48 +00:00
|
|
|
InsertPaste(&documentStr[0], documentStr.size());
|
2015-06-07 21:19:26 +00:00
|
|
|
pdoc->EndUndoAction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::EscapeHanja() {
|
|
|
|
// The candidate box pops up to user to select a hanja.
|
|
|
|
// It comes into WM_IME_COMPOSITION with GCS_RESULTSTR.
|
|
|
|
// The existing hangul or hanja is replaced with it.
|
|
|
|
if (sel.Count() > 1) {
|
|
|
|
return; // Do not allow multi carets.
|
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
const Sci::Position currentPos = CurrentPosition();
|
|
|
|
const int oneCharLen = pdoc->LenChar(currentPos);
|
2015-06-07 21:19:26 +00:00
|
|
|
|
|
|
|
if (oneCharLen < 2) {
|
|
|
|
return; // No need to handle SBCS.
|
|
|
|
}
|
|
|
|
|
|
|
|
// ImmEscapeW() may overwrite uniChar[] with a null terminated string.
|
|
|
|
// So enlarge it enough to Maximum 4 as in UTF-8.
|
|
|
|
unsigned int const safeLength = UTF8MaxBytes+1;
|
|
|
|
std::string oneChar(safeLength, '\0');
|
|
|
|
pdoc->GetCharRange(&oneChar[0], currentPos, oneCharLen);
|
|
|
|
|
|
|
|
std::wstring uniChar = StringDecode(oneChar, CodePageOfDocument());
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
IMContext imc(MainHWND());
|
|
|
|
if (imc.hIMC) {
|
2015-06-07 21:19:26 +00:00
|
|
|
// Set the candidate box position since IME may show it.
|
|
|
|
SetCandidateWindowPos();
|
|
|
|
// IME_ESC_HANJA_MODE appears to receive the first character only.
|
2019-05-04 18:14:48 +00:00
|
|
|
if (ImmEscapeW(GetKeyboardLayout(0), imc.hIMC, IME_ESC_HANJA_MODE, &uniChar[0])) {
|
|
|
|
SetSelection(currentPos, currentPos + oneCharLen);
|
2015-06-07 21:19:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::ToggleHanja() {
|
2019-05-04 18:14:48 +00:00
|
|
|
// If selection, convert every hanja to hangul within the main range.
|
2015-06-07 21:19:26 +00:00
|
|
|
// If no selection, commit to IME.
|
|
|
|
if (sel.Count() > 1) {
|
|
|
|
return; // Do not allow multi carets.
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sel.Empty()) {
|
|
|
|
EscapeHanja();
|
|
|
|
} else {
|
|
|
|
SelectionToHangul();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
std::vector<int> MapImeIndicators(std::vector<BYTE> inputStyle) {
|
|
|
|
std::vector<int> imeIndicator(inputStyle.size(), SC_INDICATOR_UNKNOWN);
|
|
|
|
for (size_t i = 0; i < inputStyle.size(); i++) {
|
|
|
|
switch (static_cast<int>(inputStyle.at(i))) {
|
|
|
|
case ATTR_INPUT:
|
|
|
|
imeIndicator[i] = SC_INDICATOR_INPUT;
|
|
|
|
break;
|
|
|
|
case ATTR_TARGET_NOTCONVERTED:
|
|
|
|
case ATTR_TARGET_CONVERTED:
|
|
|
|
imeIndicator[i] = SC_INDICATOR_TARGET;
|
|
|
|
break;
|
|
|
|
case ATTR_CONVERTED:
|
|
|
|
imeIndicator[i] = SC_INDICATOR_CONVERTED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
imeIndicator[i] = SC_INDICATOR_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return imeIndicator;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
void ScintillaWin::AddWString(std::wstring_view wsv, CharacterSource charSource) {
|
|
|
|
if (wsv.empty())
|
2019-05-04 18:14:48 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
const int codePage = CodePageOfDocument();
|
2019-07-21 13:26:02 +00:00
|
|
|
for (size_t i = 0; i < wsv.size(); ) {
|
|
|
|
const size_t ucWidth = UTF16CharLength(wsv[i]);
|
|
|
|
const std::string docChar = StringEncode(wsv.substr(i, ucWidth), codePage);
|
2019-05-04 18:14:48 +00:00
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
InsertCharacter(docChar, charSource);
|
2019-05-04 18:14:48 +00:00
|
|
|
i += ucWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
sptr_t ScintillaWin::HandleCompositionInline(uptr_t, sptr_t lParam) {
|
|
|
|
// Copy & paste by johnsonj with a lot of helps of Neil.
|
|
|
|
// Great thanks for my foreruners, jiniya and BLUEnLIVE.
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
IMContext imc(MainHWND());
|
|
|
|
if (!imc.hIMC)
|
|
|
|
return 0;
|
|
|
|
if (pdoc->IsReadOnly() || SelectionContainsProtected()) {
|
|
|
|
::ImmNotifyIME(imc.hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
|
2015-06-07 21:19:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
bool initialCompose = false;
|
2015-06-07 21:19:26 +00:00
|
|
|
if (pdoc->TentativeActive()) {
|
|
|
|
pdoc->TentativeUndo();
|
|
|
|
} else {
|
|
|
|
// No tentative undo means start of this composition so
|
|
|
|
// fill in any virtual spaces.
|
2019-05-04 18:14:48 +00:00
|
|
|
initialCompose = true;
|
2015-06-07 21:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
view.imeCaretBlockOverride = false;
|
|
|
|
|
|
|
|
if (lParam & GCS_COMPSTR) {
|
2019-05-04 18:14:48 +00:00
|
|
|
const std::wstring wcs = imc.GetCompositionString(GCS_COMPSTR);
|
2019-07-21 13:26:02 +00:00
|
|
|
if (wcs.empty()) {
|
2015-06-07 21:19:26 +00:00
|
|
|
ShowCaretAtCurrentPosition();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
if (initialCompose)
|
|
|
|
ClearBeforeTentativeStart();
|
2015-06-07 21:19:26 +00:00
|
|
|
pdoc->TentativeStart(); // TentativeActive from now on.
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
std::vector<int> imeIndicator = MapImeIndicators(imc.GetImeAttributes());
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
const int codePage = CodePageOfDocument();
|
2019-07-21 13:26:02 +00:00
|
|
|
const std::wstring_view wsv = wcs;
|
|
|
|
for (size_t i = 0; i < wsv.size(); ) {
|
|
|
|
const size_t ucWidth = UTF16CharLength(wsv[i]);
|
|
|
|
const std::string docChar = StringEncode(wsv.substr(i, ucWidth), codePage);
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
InsertCharacter(docChar, CharacterSource::tentativeInput);
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
DrawImeIndicator(imeIndicator[i], static_cast<unsigned int>(docChar.size()));
|
2015-06-07 21:19:26 +00:00
|
|
|
i += ucWidth;
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
// Move IME caret from current last position to imeCaretPos.
|
|
|
|
const int imeEndToImeCaretU16 = imc.GetImeCaretPos() - static_cast<unsigned int>(wcs.size());
|
|
|
|
const Sci::Position imeCaretPosDoc = pdoc->GetRelativePositionUTF16(CurrentPosition(), imeEndToImeCaretU16);
|
|
|
|
|
|
|
|
MoveImeCarets(- CurrentPosition() + imeCaretPosDoc);
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
if (KoreanIME()) {
|
|
|
|
view.imeCaretBlockOverride = true;
|
|
|
|
}
|
|
|
|
} else if (lParam & GCS_RESULTSTR) {
|
2019-07-21 13:26:02 +00:00
|
|
|
AddWString(imc.GetCompositionString(GCS_RESULTSTR), CharacterSource::imeResult);
|
2015-06-07 21:19:26 +00:00
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
EnsureCaretVisible();
|
2015-06-07 21:19:26 +00:00
|
|
|
SetCandidateWindowPos();
|
|
|
|
ShowCaretAtCurrentPosition();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
namespace {
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
// Translate message IDs from WM_* and EM_* to SCI_* so can partly emulate Windows Edit control
|
2019-07-21 13:26:02 +00:00
|
|
|
unsigned int SciMessageFromEM(unsigned int iMessage) noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
switch (iMessage) {
|
|
|
|
case EM_CANPASTE: return SCI_CANPASTE;
|
|
|
|
case EM_CANUNDO: return SCI_CANUNDO;
|
|
|
|
case EM_EMPTYUNDOBUFFER: return SCI_EMPTYUNDOBUFFER;
|
|
|
|
case EM_FINDTEXTEX: return SCI_FINDTEXT;
|
|
|
|
case EM_FORMATRANGE: return SCI_FORMATRANGE;
|
|
|
|
case EM_GETFIRSTVISIBLELINE: return SCI_GETFIRSTVISIBLELINE;
|
|
|
|
case EM_GETLINECOUNT: return SCI_GETLINECOUNT;
|
|
|
|
case EM_GETSELTEXT: return SCI_GETSELTEXT;
|
|
|
|
case EM_GETTEXTRANGE: return SCI_GETTEXTRANGE;
|
|
|
|
case EM_HIDESELECTION: return SCI_HIDESELECTION;
|
|
|
|
case EM_LINEINDEX: return SCI_POSITIONFROMLINE;
|
|
|
|
case EM_LINESCROLL: return SCI_LINESCROLL;
|
|
|
|
case EM_REPLACESEL: return SCI_REPLACESEL;
|
|
|
|
case EM_SCROLLCARET: return SCI_SCROLLCARET;
|
|
|
|
case EM_SETREADONLY: return SCI_SETREADONLY;
|
|
|
|
case WM_CLEAR: return SCI_CLEAR;
|
|
|
|
case WM_COPY: return SCI_COPY;
|
|
|
|
case WM_CUT: return SCI_CUT;
|
|
|
|
case WM_SETTEXT: return SCI_SETTEXT;
|
|
|
|
case WM_PASTE: return SCI_PASTE;
|
|
|
|
case WM_UNDO: return SCI_UNDO;
|
|
|
|
}
|
|
|
|
return iMessage;
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace Scintilla {
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
UINT CodePageFromCharSet(DWORD characterSet, UINT documentCodePage) noexcept {
|
2010-07-12 22:19:51 +00:00
|
|
|
if (documentCodePage == SC_CP_UTF8) {
|
|
|
|
return SC_CP_UTF8;
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
switch (characterSet) {
|
|
|
|
case SC_CHARSET_ANSI: return 1252;
|
2019-06-11 06:38:35 +00:00
|
|
|
|
|
|
|
// Cyrillic / Turkish or other languages cannot be shown in ANSI mode.
|
|
|
|
// This fixes such problem. For more information about this fix, check:
|
|
|
|
// https://github.com/notepad-plus-plus/notepad-plus-plus/issues/5671
|
|
|
|
//case SC_CHARSET_DEFAULT: return documentCodePage ? documentCodePage : 1252;
|
|
|
|
case SC_CHARSET_DEFAULT: return documentCodePage;
|
2019-07-21 13:26:02 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
case SC_CHARSET_BALTIC: return 1257;
|
|
|
|
case SC_CHARSET_CHINESEBIG5: return 950;
|
|
|
|
case SC_CHARSET_EASTEUROPE: return 1250;
|
|
|
|
case SC_CHARSET_GB2312: return 936;
|
|
|
|
case SC_CHARSET_GREEK: return 1253;
|
|
|
|
case SC_CHARSET_HANGUL: return 949;
|
|
|
|
case SC_CHARSET_MAC: return 10000;
|
|
|
|
case SC_CHARSET_OEM: return 437;
|
|
|
|
case SC_CHARSET_RUSSIAN: return 1251;
|
|
|
|
case SC_CHARSET_SHIFTJIS: return 932;
|
|
|
|
case SC_CHARSET_TURKISH: return 1254;
|
|
|
|
case SC_CHARSET_JOHAB: return 1361;
|
|
|
|
case SC_CHARSET_HEBREW: return 1255;
|
|
|
|
case SC_CHARSET_ARABIC: return 1256;
|
|
|
|
case SC_CHARSET_VIETNAMESE: return 1258;
|
|
|
|
case SC_CHARSET_THAI: return 874;
|
|
|
|
case SC_CHARSET_8859_15: return 28605;
|
|
|
|
// Not supported
|
|
|
|
case SC_CHARSET_CYRILLIC: return documentCodePage;
|
|
|
|
case SC_CHARSET_SYMBOL: return documentCodePage;
|
|
|
|
}
|
|
|
|
return documentCodePage;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
UINT ScintillaWin::CodePageOfDocument() const {
|
2010-07-12 22:19:51 +00:00
|
|
|
return CodePageFromCharSet(vs.styles[STYLE_DEFAULT].characterSet, pdoc->dbcsCodePage);
|
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
sptr_t ScintillaWin::GetTextLength() {
|
2019-07-21 13:26:02 +00:00
|
|
|
return pdoc->CountUTF16(0, pdoc->Length());
|
2015-06-07 21:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sptr_t ScintillaWin::GetText(uptr_t wParam, sptr_t lParam) {
|
2019-07-21 13:26:02 +00:00
|
|
|
if (lParam == 0) {
|
|
|
|
return pdoc->CountUTF16(0, pdoc->Length());
|
|
|
|
}
|
|
|
|
if (wParam == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
wchar_t *ptr = static_cast<wchar_t *>(PtrFromSPtr(lParam));
|
2015-06-07 21:19:26 +00:00
|
|
|
if (pdoc->Length() == 0) {
|
|
|
|
*ptr = L'\0';
|
|
|
|
return 0;
|
|
|
|
}
|
2019-07-21 13:26:02 +00:00
|
|
|
const Sci::Position lengthWanted = wParam - 1;
|
|
|
|
Sci::Position sizeRequestedRange = pdoc->GetRelativePositionUTF16(0, lengthWanted);
|
|
|
|
if (sizeRequestedRange < 0) {
|
|
|
|
// Requested more text than there is in the document.
|
|
|
|
sizeRequestedRange = pdoc->CountUTF16(0, pdoc->Length());
|
|
|
|
}
|
|
|
|
std::string docBytes(sizeRequestedRange, '\0');
|
|
|
|
pdoc->GetCharRange(&docBytes[0], 0, sizeRequestedRange);
|
2015-06-07 21:19:26 +00:00
|
|
|
if (IsUnicodeMode()) {
|
2019-07-21 13:26:02 +00:00
|
|
|
const size_t uLen = UTF16FromUTF8(docBytes, ptr, lengthWanted);
|
2015-06-07 21:19:26 +00:00
|
|
|
ptr[uLen] = L'\0';
|
|
|
|
return uLen;
|
|
|
|
} else {
|
|
|
|
// Not Unicode mode
|
|
|
|
// Convert to Unicode using the current Scintilla code page
|
|
|
|
const UINT cpSrc = CodePageOfDocument();
|
2019-05-04 18:14:48 +00:00
|
|
|
int lengthUTF16 = WideCharLenFromMultiByte(cpSrc, docBytes);
|
2019-07-21 13:26:02 +00:00
|
|
|
if (lengthUTF16 > lengthWanted)
|
|
|
|
lengthUTF16 = static_cast<int>(lengthWanted);
|
2019-05-04 18:14:48 +00:00
|
|
|
WideCharFromMultiByte(cpSrc, docBytes, ptr, lengthUTF16);
|
2015-06-07 21:19:26 +00:00
|
|
|
ptr[lengthUTF16] = L'\0';
|
|
|
|
return lengthUTF16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
|
2009-08-23 02:24:48 +00:00
|
|
|
try {
|
|
|
|
//Platform::DebugPrintf("S M:%x WP:%x L:%x\n", iMessage, wParam, lParam);
|
|
|
|
iMessage = SciMessageFromEM(iMessage);
|
|
|
|
switch (iMessage) {
|
|
|
|
|
|
|
|
case WM_CREATE:
|
2019-05-04 18:14:48 +00:00
|
|
|
ctrlID = ::GetDlgCtrlID(static_cast<HWND>(wMain.GetID()));
|
2009-08-23 02:24:48 +00:00
|
|
|
// Get Intellimouse scroll line parameters
|
|
|
|
GetIntelliMouseParameters();
|
|
|
|
::RegisterDragDrop(MainHWND(), reinterpret_cast<IDropTarget *>(&dt));
|
|
|
|
break;
|
|
|
|
case WM_COMMAND:
|
2019-05-04 18:14:48 +00:00
|
|
|
Command(LOWORD(wParam));
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
|
|
|
case WM_PAINT:
|
2019-07-21 13:26:02 +00:00
|
|
|
return WndPaint();
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_PRINTCLIENT: {
|
|
|
|
HDC hdc = reinterpret_cast<HDC>(wParam);
|
|
|
|
if (!IsCompatibleDC(hdc)) {
|
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
|
|
|
|
}
|
|
|
|
FullPaintDC(hdc);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_VSCROLL:
|
|
|
|
ScrollMessage(wParam);
|
|
|
|
break;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_HSCROLL:
|
|
|
|
HorizontalScrollMessage(wParam);
|
|
|
|
break;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_SIZE: {
|
2013-08-28 00:44:27 +00:00
|
|
|
#if defined(USE_D2D)
|
|
|
|
if (paintState == notPainting) {
|
|
|
|
DropRenderTarget();
|
|
|
|
} else {
|
|
|
|
renderTargetValid = false;
|
|
|
|
}
|
|
|
|
#endif
|
2019-05-04 18:14:48 +00:00
|
|
|
//Platform::DebugPrintf("Scintilla WM_SIZE %d %d\n", LOWORD(lParam), HIWORD(lParam));
|
2009-08-23 02:24:48 +00:00
|
|
|
ChangeSize();
|
|
|
|
}
|
|
|
|
break;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_MOUSEWHEEL:
|
2019-05-04 18:14:48 +00:00
|
|
|
if (!mouseWheelCaptures) {
|
|
|
|
// if the mouse wheel is not captured, test if the mouse
|
|
|
|
// pointer is over the editor window and if not, don't
|
|
|
|
// handle the message but pass it on.
|
|
|
|
RECT rc;
|
|
|
|
GetWindowRect(MainHWND(), &rc);
|
|
|
|
POINT pt;
|
|
|
|
pt.x = GET_X_LPARAM(lParam);
|
|
|
|
pt.y = GET_Y_LPARAM(lParam);
|
|
|
|
if (!PtInRect(&rc, pt))
|
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
// if autocomplete list active then send mousewheel message to it
|
|
|
|
if (ac.Active()) {
|
2019-05-04 18:14:48 +00:00
|
|
|
HWND hWnd = static_cast<HWND>(ac.lb->GetID());
|
2013-08-28 00:44:27 +00:00
|
|
|
::SendMessage(hWnd, iMessage, wParam, lParam);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
// Don't handle datazoom.
|
|
|
|
// (A good idea for datazoom would be to "fold" or "unfold" details.
|
|
|
|
// i.e. if datazoomed out only class structures are visible, when datazooming in the control
|
|
|
|
// structures appear, then eventually the individual statements...)
|
|
|
|
if (wParam & MK_SHIFT) {
|
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
// Either SCROLL or ZOOM. We handle the wheel steppings calculation
|
2019-05-04 18:14:48 +00:00
|
|
|
wheelDelta -= GET_WHEEL_DELTA_WPARAM(wParam);
|
2019-07-21 13:26:02 +00:00
|
|
|
if (std::abs(wheelDelta) >= WHEEL_DELTA && linesPerScroll > 0) {
|
2019-05-04 18:14:48 +00:00
|
|
|
Sci::Line linesToScroll = linesPerScroll;
|
2009-08-23 02:24:48 +00:00
|
|
|
if (linesPerScroll == WHEEL_PAGESCROLL)
|
|
|
|
linesToScroll = LinesOnScreen() - 1;
|
|
|
|
if (linesToScroll == 0) {
|
|
|
|
linesToScroll = 1;
|
|
|
|
}
|
|
|
|
linesToScroll *= (wheelDelta / WHEEL_DELTA);
|
|
|
|
if (wheelDelta >= 0)
|
|
|
|
wheelDelta = wheelDelta % WHEEL_DELTA;
|
|
|
|
else
|
|
|
|
wheelDelta = - (-wheelDelta % WHEEL_DELTA);
|
|
|
|
|
|
|
|
if (wParam & MK_CONTROL) {
|
|
|
|
// Zoom! We play with the font sizes in the styles.
|
|
|
|
// Number of steps/line is ignored, we just care if sizing up or down
|
|
|
|
if (linesToScroll < 0) {
|
|
|
|
KeyCommand(SCI_ZOOMIN);
|
|
|
|
} else {
|
|
|
|
KeyCommand(SCI_ZOOMOUT);
|
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
} else {
|
2009-08-23 02:24:48 +00:00
|
|
|
// Scroll
|
|
|
|
ScrollTo(topLine + linesToScroll);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
return 0;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_TIMER:
|
2015-06-07 21:19:26 +00:00
|
|
|
if (wParam == idleTimerID && idler.state) {
|
2009-08-23 02:24:48 +00:00
|
|
|
SendMessage(MainHWND(), SC_WIN_IDLE, 0, 1);
|
|
|
|
} else {
|
2015-06-07 21:19:26 +00:00
|
|
|
TickFor(static_cast<TickReason>(wParam - fineTimerStart));
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case SC_WIN_IDLE:
|
|
|
|
// wParam=dwTickCountInitial, or 0 to initialize. lParam=bSkipUserInputTest
|
|
|
|
if (idler.state) {
|
2019-07-21 13:26:02 +00:00
|
|
|
if (lParam || (WAIT_TIMEOUT == MsgWaitForMultipleObjects(0, nullptr, 0, 0, QS_INPUT|QS_HOTKEY))) {
|
2009-08-23 02:24:48 +00:00
|
|
|
if (Idle()) {
|
|
|
|
// User input was given priority above, but all events do get a turn. Other
|
|
|
|
// messages, notifications, etc. will get interleaved with the idle messages.
|
|
|
|
|
|
|
|
// However, some things like WM_PAINT are a lower priority, and will not fire
|
|
|
|
// when there's a message posted. So, several times a second, we stop and let
|
|
|
|
// the low priority events have a turn (after which the timer will fire again).
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
// Suppress a warning from Code Analysis that the GetTickCount function
|
|
|
|
// wraps after 49 days. The WM_TIMER will kick off another SC_WIN_IDLE
|
|
|
|
// after the wrap.
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(suppress: 28159)
|
|
|
|
#endif
|
|
|
|
const DWORD dwCurrent = GetTickCount();
|
|
|
|
const DWORD dwStart = wParam ? static_cast<DWORD>(wParam) : dwCurrent;
|
2013-08-28 00:44:27 +00:00
|
|
|
const DWORD maxWorkTime = 50;
|
2009-08-23 02:24:48 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
if (dwCurrent >= dwStart && dwCurrent > maxWorkTime && dwCurrent - maxWorkTime < dwStart)
|
2009-08-23 02:24:48 +00:00
|
|
|
PostMessage(MainHWND(), SC_WIN_IDLE, dwStart, 0);
|
|
|
|
} else {
|
|
|
|
SetIdle(false);
|
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
case SC_WORK_IDLE:
|
|
|
|
IdleWork();
|
|
|
|
break;
|
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_GETMINMAXINFO:
|
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_LBUTTONDOWN: {
|
|
|
|
// For IME, set the composition string as the result string.
|
2019-05-04 18:14:48 +00:00
|
|
|
IMContext imc(MainHWND());
|
|
|
|
::ImmNotifyIME(imc.hIMC, NI_COMPOSITIONSTR, CPS_COMPLETE, 0);
|
2009-08-23 02:24:48 +00:00
|
|
|
//
|
|
|
|
//Platform::DebugPrintf("Buttdown %d %x %x %x %x %x\n",iMessage, wParam, lParam,
|
2019-05-04 18:14:48 +00:00
|
|
|
// KeyboardIsKeyDown(VK_SHIFT),
|
|
|
|
// KeyboardIsKeyDown(VK_CONTROL),
|
|
|
|
// KeyboardIsKeyDown(VK_MENU));
|
2010-09-05 22:56:27 +00:00
|
|
|
::SetFocus(MainHWND());
|
2019-05-04 18:14:48 +00:00
|
|
|
ButtonDownWithModifiers(PointFromLParam(lParam), ::GetMessageTime(),
|
|
|
|
MouseModifiers(wParam));
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
|
|
|
break;
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2010-07-12 22:19:51 +00:00
|
|
|
case WM_MBUTTONDOWN:
|
2019-05-04 18:14:48 +00:00
|
|
|
::SetFocus(MainHWND());
|
|
|
|
break;
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
case WM_MOUSEMOVE: {
|
2019-05-04 18:14:48 +00:00
|
|
|
const Point pt = PointFromLParam(lParam);
|
2015-06-07 21:19:26 +00:00
|
|
|
|
|
|
|
// Windows might send WM_MOUSEMOVE even though the mouse has not been moved:
|
|
|
|
// http://blogs.msdn.com/b/oldnewthing/archive/2003/10/01/55108.aspx
|
2019-07-21 13:26:02 +00:00
|
|
|
if (ptMouseLast != pt) {
|
2015-06-07 21:19:26 +00:00
|
|
|
SetTrackMouseLeaveEvent(true);
|
2019-05-04 18:14:48 +00:00
|
|
|
ButtonMoveWithModifiers(pt, ::GetMessageTime(), MouseModifiers(wParam));
|
2015-06-07 21:19:26 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2010-07-12 22:19:51 +00:00
|
|
|
case WM_MOUSELEAVE:
|
|
|
|
SetTrackMouseLeaveEvent(false);
|
|
|
|
MouseLeave();
|
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
|
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_LBUTTONUP:
|
2019-05-04 18:14:48 +00:00
|
|
|
ButtonUpWithModifiers(PointFromLParam(lParam),
|
|
|
|
::GetMessageTime(), MouseModifiers(wParam));
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
case WM_RBUTTONDOWN: {
|
|
|
|
::SetFocus(MainHWND());
|
|
|
|
const Point pt = PointFromLParam(lParam);
|
|
|
|
if (!PointInSelection(pt)) {
|
|
|
|
CancelModes();
|
|
|
|
SetEmptySelection(PositionFromLocation(PointFromLParam(lParam)));
|
|
|
|
}
|
|
|
|
|
|
|
|
RightButtonDownWithModifiers(pt, ::GetMessageTime(), MouseModifiers(wParam));
|
2011-03-22 00:16:49 +00:00
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
|
|
|
case WM_SETCURSOR:
|
2019-05-04 18:14:48 +00:00
|
|
|
if (LOWORD(lParam) == HTCLIENT) {
|
2009-08-23 02:24:48 +00:00
|
|
|
if (inDragDrop == ddDragging) {
|
|
|
|
DisplayCursor(Window::cursorUp);
|
|
|
|
} else {
|
|
|
|
// Display regular (drag) cursor over selection
|
|
|
|
POINT pt;
|
2013-08-28 00:44:27 +00:00
|
|
|
if (0 != ::GetCursorPos(&pt)) {
|
|
|
|
::ScreenToClient(MainHWND(), &pt);
|
2015-06-07 21:19:26 +00:00
|
|
|
if (PointInSelMargin(PointFromPOINT(pt))) {
|
|
|
|
DisplayCursor(GetMarginCursor(PointFromPOINT(pt)));
|
|
|
|
} else if (PointInSelection(PointFromPOINT(pt)) && !SelectionEmpty()) {
|
2013-08-28 00:44:27 +00:00
|
|
|
DisplayCursor(Window::cursorArrow);
|
2015-06-07 21:19:26 +00:00
|
|
|
} else if (PointIsHotspot(PointFromPOINT(pt))) {
|
2013-08-28 00:44:27 +00:00
|
|
|
DisplayCursor(Window::cursorHand);
|
|
|
|
} else {
|
|
|
|
DisplayCursor(Window::cursorText);
|
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
2009-04-24 23:35:41 +00:00
|
|
|
} else {
|
2009-08-23 02:24:48 +00:00
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_CHAR:
|
2015-06-07 21:19:26 +00:00
|
|
|
if (((wParam >= 128) || !iscntrl(static_cast<int>(wParam))) || !lastKeyDownConsumed) {
|
2019-05-04 18:14:48 +00:00
|
|
|
wchar_t wcs[3] = {static_cast<wchar_t>(wParam), 0};
|
|
|
|
unsigned int wclen = 1;
|
|
|
|
if (IS_HIGH_SURROGATE(wcs[0])) {
|
|
|
|
// If this is a high surrogate character, we need a second one
|
|
|
|
lastHighSurrogateChar = wcs[0];
|
|
|
|
return 0;
|
|
|
|
} else if (IS_LOW_SURROGATE(wcs[0])) {
|
|
|
|
wcs[1] = wcs[0];
|
|
|
|
wcs[0] = lastHighSurrogateChar;
|
|
|
|
lastHighSurrogateChar = 0;
|
|
|
|
wclen = 2;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2019-07-21 13:26:02 +00:00
|
|
|
AddWString(std::wstring_view(wcs, wclen), CharacterSource::directInput);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
return 0;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_UNICHAR:
|
|
|
|
if (wParam == UNICODE_NOCHAR) {
|
2019-05-04 18:14:48 +00:00
|
|
|
return TRUE;
|
2009-08-23 02:24:48 +00:00
|
|
|
} else if (lastKeyDownConsumed) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
2019-05-04 18:14:48 +00:00
|
|
|
wchar_t wcs[3] = {0};
|
|
|
|
const unsigned int wclen = UTF16FromUTF32Character(static_cast<unsigned int>(wParam), wcs);
|
2019-07-21 13:26:02 +00:00
|
|
|
AddWString(std::wstring_view(wcs, wclen), CharacterSource::directInput);
|
2019-05-04 18:14:48 +00:00
|
|
|
return FALSE;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
case WM_KEYDOWN: {
|
|
|
|
//Platform::DebugPrintf("S keydown %d %x %x %x %x\n",iMessage, wParam, lParam, ::IsKeyDown(VK_SHIFT), ::IsKeyDown(VK_CONTROL));
|
|
|
|
lastKeyDownConsumed = false;
|
2019-05-04 18:14:48 +00:00
|
|
|
const int ret = KeyDownWithModifiers(KeyTranslate(static_cast<int>(wParam)),
|
|
|
|
ModifierFlags(KeyboardIsKeyDown(VK_SHIFT),
|
|
|
|
KeyboardIsKeyDown(VK_CONTROL),
|
|
|
|
KeyboardIsKeyDown(VK_MENU)),
|
2009-08-23 02:24:48 +00:00
|
|
|
&lastKeyDownConsumed);
|
|
|
|
if (!ret && !lastKeyDownConsumed) {
|
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
|
|
|
|
}
|
|
|
|
break;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
case WM_IME_KEYDOWN: {
|
|
|
|
if (wParam == VK_HANJA) {
|
|
|
|
ToggleHanja();
|
|
|
|
}
|
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
|
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
case WM_IME_REQUEST: {
|
|
|
|
if (wParam == IMR_RECONVERTSTRING) {
|
|
|
|
return ImeOnReconvert(lParam);
|
|
|
|
}
|
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_KEYUP:
|
|
|
|
//Platform::DebugPrintf("S keyup %d %x %x\n",iMessage, wParam, lParam);
|
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_SETTINGCHANGE:
|
|
|
|
//Platform::DebugPrintf("Setting Changed\n");
|
|
|
|
InvalidateStyleData();
|
|
|
|
// Get Intellimouse scroll line parameters
|
|
|
|
GetIntelliMouseParameters();
|
|
|
|
break;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_GETDLGCODE:
|
|
|
|
return DLGC_HASSETSEL | DLGC_WANTALLKEYS;
|
|
|
|
|
|
|
|
case WM_KILLFOCUS: {
|
|
|
|
HWND wOther = reinterpret_cast<HWND>(wParam);
|
|
|
|
HWND wThis = MainHWND();
|
2019-05-04 18:14:48 +00:00
|
|
|
const HWND wCT = static_cast<HWND>(ct.wCallTip.GetID());
|
2009-08-23 02:24:48 +00:00
|
|
|
if (!wParam ||
|
2010-07-12 22:19:51 +00:00
|
|
|
!(::IsChild(wThis, wOther) || (wOther == wCT))) {
|
2009-08-23 02:24:48 +00:00
|
|
|
SetFocusState(false);
|
|
|
|
DestroySystemCaret();
|
|
|
|
}
|
2015-06-07 21:19:26 +00:00
|
|
|
// Explicitly complete any IME composition
|
2019-05-04 18:14:48 +00:00
|
|
|
IMContext imc(MainHWND());
|
|
|
|
if (imc.hIMC) {
|
|
|
|
::ImmNotifyIME(imc.hIMC, NI_COMPOSITIONSTR, CPS_COMPLETE, 0);
|
2015-06-07 21:19:26 +00:00
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_SETFOCUS:
|
|
|
|
SetFocusState(true);
|
|
|
|
DestroySystemCaret();
|
|
|
|
CreateSystemCaret();
|
|
|
|
break;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_SYSCOLORCHANGE:
|
|
|
|
//Platform::DebugPrintf("Setting Changed\n");
|
|
|
|
InvalidateStyleData();
|
|
|
|
break;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_IME_STARTCOMPOSITION: // dbcs
|
2015-06-07 21:19:26 +00:00
|
|
|
if (KoreanIME() || imeInteraction == imeInline) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
ImeStartComposition();
|
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
|
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_IME_ENDCOMPOSITION: // dbcs
|
|
|
|
ImeEndComposition();
|
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_IME_COMPOSITION:
|
2019-05-04 18:14:48 +00:00
|
|
|
if (KoreanIME() || imeInteraction == imeInline) {
|
2015-06-07 21:19:26 +00:00
|
|
|
return HandleCompositionInline(wParam, lParam);
|
|
|
|
} else {
|
|
|
|
return HandleCompositionWindowed(wParam, lParam);
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
case WM_CONTEXTMENU: {
|
|
|
|
Point pt = PointFromLParam(lParam);
|
|
|
|
POINT rpt = {static_cast<int>(pt.x), static_cast<int>(pt.y)};
|
|
|
|
::ScreenToClient(MainHWND(), &rpt);
|
|
|
|
const Point ptClient = PointFromPOINT(rpt);
|
|
|
|
if (ShouldDisplayPopup(ptClient)) {
|
|
|
|
if ((pt.x == -1) && (pt.y == -1)) {
|
|
|
|
// Caused by keyboard so display menu near caret
|
|
|
|
pt = PointMainCaret();
|
|
|
|
POINT spt = POINTFromPoint(pt);
|
|
|
|
::ClientToScreen(MainHWND(), &spt);
|
|
|
|
pt = PointFromPOINT(spt);
|
|
|
|
}
|
|
|
|
ContextMenu(pt);
|
|
|
|
return 0;
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
|
|
|
|
case WM_INPUTLANGCHANGE:
|
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
|
|
|
|
case WM_INPUTLANGCHANGEREQUEST:
|
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_ERASEBKGND:
|
|
|
|
return 1; // Avoid any background erasure as whole window painted.
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case WM_CAPTURECHANGED:
|
|
|
|
capturedMouse = false;
|
|
|
|
return 0;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
case WM_IME_SETCONTEXT:
|
|
|
|
if (KoreanIME() || imeInteraction == imeInline) {
|
|
|
|
if (wParam) {
|
|
|
|
LPARAM NoImeWin = lParam;
|
|
|
|
NoImeWin = NoImeWin & (~ISC_SHOWUICOMPOSITIONWINDOW);
|
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, NoImeWin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
|
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
// These are not handled in Scintilla and its faster to dispatch them here.
|
|
|
|
// Also moves time out to here so profile doesn't count lots of empty message calls.
|
|
|
|
|
|
|
|
case WM_MOVE:
|
|
|
|
case WM_MOUSEACTIVATE:
|
|
|
|
case WM_NCHITTEST:
|
|
|
|
case WM_NCCALCSIZE:
|
|
|
|
case WM_NCPAINT:
|
|
|
|
case WM_NCMOUSEMOVE:
|
|
|
|
case WM_NCLBUTTONDOWN:
|
|
|
|
case WM_IME_NOTIFY:
|
|
|
|
case WM_SYSCOMMAND:
|
|
|
|
case WM_WINDOWPOSCHANGING:
|
|
|
|
case WM_WINDOWPOSCHANGED:
|
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
case WM_GETTEXTLENGTH:
|
|
|
|
return GetTextLength();
|
|
|
|
|
|
|
|
case WM_GETTEXT:
|
|
|
|
return GetText(wParam, lParam);
|
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case EM_LINEFROMCHAR:
|
|
|
|
if (static_cast<int>(wParam) < 0) {
|
|
|
|
wParam = SelectionStart().Position();
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2015-06-07 21:19:26 +00:00
|
|
|
return pdoc->LineFromPosition(static_cast<int>(wParam));
|
2009-08-23 02:24:48 +00:00
|
|
|
|
|
|
|
case EM_EXLINEFROMCHAR:
|
2015-06-07 21:19:26 +00:00
|
|
|
return pdoc->LineFromPosition(static_cast<int>(lParam));
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case EM_GETSEL:
|
|
|
|
if (wParam) {
|
2019-05-04 18:14:48 +00:00
|
|
|
*reinterpret_cast<int *>(wParam) = static_cast<int>(SelectionStart().Position());
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
if (lParam) {
|
2019-05-04 18:14:48 +00:00
|
|
|
*reinterpret_cast<int *>(lParam) = static_cast<int>(SelectionEnd().Position());
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
return MAKELRESULT(SelectionStart().Position(), SelectionEnd().Position());
|
2009-08-23 02:24:48 +00:00
|
|
|
|
|
|
|
case EM_EXGETSEL: {
|
|
|
|
if (lParam == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
Sci_CharacterRange *pCR = reinterpret_cast<Sci_CharacterRange *>(lParam);
|
2019-05-04 18:14:48 +00:00
|
|
|
pCR->cpMin = static_cast<Sci_PositionCR>(SelectionStart().Position());
|
|
|
|
pCR->cpMax = static_cast<Sci_PositionCR>(SelectionEnd().Position());
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case EM_SETSEL: {
|
2019-05-04 18:14:48 +00:00
|
|
|
Sci::Position nStart = static_cast<Sci::Position>(wParam);
|
|
|
|
Sci::Position nEnd = lParam;
|
2009-08-23 02:24:48 +00:00
|
|
|
if (nStart == 0 && nEnd == -1) {
|
|
|
|
nEnd = pdoc->Length();
|
|
|
|
}
|
|
|
|
if (nStart == -1) {
|
|
|
|
nStart = nEnd; // Remove selection
|
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
SetSelection(nEnd, nStart);
|
2009-08-23 02:24:48 +00:00
|
|
|
EnsureCaretVisible();
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EM_EXSETSEL: {
|
|
|
|
if (lParam == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
const Sci_CharacterRange *pCR = reinterpret_cast<const Sci_CharacterRange *>(lParam);
|
2009-08-23 02:24:48 +00:00
|
|
|
sel.selType = Selection::selStream;
|
|
|
|
if (pCR->cpMin == 0 && pCR->cpMax == -1) {
|
|
|
|
SetSelection(pCR->cpMin, pdoc->Length());
|
|
|
|
} else {
|
|
|
|
SetSelection(pCR->cpMin, pCR->cpMax);
|
|
|
|
}
|
|
|
|
EnsureCaretVisible();
|
|
|
|
return pdoc->LineFromPosition(SelectionStart().Position());
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case SCI_GETDIRECTFUNCTION:
|
|
|
|
return reinterpret_cast<sptr_t>(DirectFunction);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case SCI_GETDIRECTPOINTER:
|
|
|
|
return reinterpret_cast<sptr_t>(this);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case SCI_GRABFOCUS:
|
|
|
|
::SetFocus(MainHWND());
|
|
|
|
break;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
#ifdef INCLUDE_DEPRECATED_FEATURES
|
2009-08-23 02:24:48 +00:00
|
|
|
case SCI_SETKEYSUNICODE:
|
|
|
|
break;
|
2009-04-25 23:38:15 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
case SCI_GETKEYSUNICODE:
|
2015-06-07 21:19:26 +00:00
|
|
|
return true;
|
|
|
|
#endif
|
2009-04-25 23:38:15 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
case SCI_SETTECHNOLOGY:
|
2019-05-04 18:14:48 +00:00
|
|
|
if ((wParam == SC_TECHNOLOGY_DEFAULT) ||
|
2015-06-07 21:19:26 +00:00
|
|
|
(wParam == SC_TECHNOLOGY_DIRECTWRITERETAIN) ||
|
|
|
|
(wParam == SC_TECHNOLOGY_DIRECTWRITEDC) ||
|
|
|
|
(wParam == SC_TECHNOLOGY_DIRECTWRITE)) {
|
2019-05-04 18:14:48 +00:00
|
|
|
const int technologyNew = static_cast<int>(wParam);
|
|
|
|
if (technology != technologyNew) {
|
|
|
|
if (technologyNew > SC_TECHNOLOGY_DEFAULT) {
|
2013-08-28 00:44:27 +00:00
|
|
|
#if defined(USE_D2D)
|
|
|
|
if (!LoadD2D())
|
|
|
|
// Failed to load Direct2D or DirectWrite so no effect
|
|
|
|
return 0;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2019-05-04 18:14:48 +00:00
|
|
|
} else {
|
|
|
|
bidirectional = EditModel::Bidirectional::bidiDisabled;
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
2015-06-07 21:19:26 +00:00
|
|
|
#if defined(USE_D2D)
|
|
|
|
DropRenderTarget();
|
|
|
|
#endif
|
2019-05-04 18:14:48 +00:00
|
|
|
technology = technologyNew;
|
2013-08-28 00:44:27 +00:00
|
|
|
// Invalidate all cached information including layout.
|
|
|
|
DropGraphics(true);
|
|
|
|
InvalidateStyleRedraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
case SCI_SETBIDIRECTIONAL:
|
|
|
|
if (technology == SC_TECHNOLOGY_DEFAULT) {
|
|
|
|
bidirectional = EditModel::Bidirectional::bidiDisabled;
|
|
|
|
} else if (wParam <= SC_BIDIRECTIONAL_R2L) {
|
|
|
|
bidirectional = static_cast<EditModel::Bidirectional>(wParam);
|
|
|
|
}
|
|
|
|
// Invalidate all cached information including layout.
|
|
|
|
DropGraphics(true);
|
|
|
|
InvalidateStyleRedraw();
|
|
|
|
break;
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
#ifdef SCI_LEXER
|
2009-08-23 02:24:48 +00:00
|
|
|
case SCI_LOADLEXERLIBRARY:
|
2019-05-04 18:14:48 +00:00
|
|
|
LexerManager::GetInstance()->Load(ConstCharPtrFromSPtr(lParam));
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
2009-04-24 23:35:41 +00:00
|
|
|
#endif
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
case SCI_TARGETASUTF8:
|
2019-05-04 18:14:48 +00:00
|
|
|
return TargetAsUTF8(CharPtrFromSPtr(lParam));
|
2015-06-07 21:19:26 +00:00
|
|
|
|
|
|
|
case SCI_ENCODEDFROMUTF8:
|
2019-05-04 18:14:48 +00:00
|
|
|
return EncodedFromUTF8(ConstCharPtrFromUPtr(wParam),
|
|
|
|
CharPtrFromSPtr(lParam));
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
default:
|
|
|
|
return ScintillaBase::WndProc(iMessage, wParam, lParam);
|
|
|
|
}
|
2010-07-12 22:19:51 +00:00
|
|
|
} catch (std::bad_alloc &) {
|
2009-08-23 02:24:48 +00:00
|
|
|
errorStatus = SC_STATUS_BADALLOC;
|
|
|
|
} catch (...) {
|
|
|
|
errorStatus = SC_STATUS_FAILURE;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
return 0;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ScintillaWin::ValidCodePage(int codePage) const {
|
|
|
|
return codePage == 0 || codePage == SC_CP_UTF8 ||
|
|
|
|
codePage == 932 || codePage == 936 || codePage == 949 ||
|
|
|
|
codePage == 950 || codePage == 1361;
|
|
|
|
}
|
|
|
|
|
|
|
|
sptr_t ScintillaWin::DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
|
|
|
|
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
bool ScintillaWin::FineTickerRunning(TickReason reason) {
|
|
|
|
return timers[reason] != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::FineTickerStart(TickReason reason, int millis, int tolerance) {
|
|
|
|
FineTickerCancel(reason);
|
|
|
|
if (SetCoalescableTimerFn && tolerance) {
|
2019-07-21 13:26:02 +00:00
|
|
|
timers[reason] = SetCoalescableTimerFn(MainHWND(), fineTimerStart + reason, millis, nullptr, tolerance);
|
2015-06-07 21:19:26 +00:00
|
|
|
} else {
|
2019-07-21 13:26:02 +00:00
|
|
|
timers[reason] = ::SetTimer(MainHWND(), fineTimerStart + reason, millis, nullptr);
|
2015-06-07 21:19:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::FineTickerCancel(TickReason reason) {
|
|
|
|
if (timers[reason]) {
|
|
|
|
::KillTimer(MainHWND(), timers[reason]);
|
|
|
|
timers[reason] = 0;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
bool ScintillaWin::SetIdle(bool on) {
|
|
|
|
// On Win32 the Idler is implemented as a Timer on the Scintilla window. This
|
|
|
|
// takes advantage of the fact that WM_TIMER messages are very low priority,
|
|
|
|
// and are only posted when the message queue is empty, i.e. during idle time.
|
|
|
|
if (idler.state != on) {
|
|
|
|
if (on) {
|
2019-07-21 13:26:02 +00:00
|
|
|
idler.idlerID = ::SetTimer(MainHWND(), idleTimerID, 10, nullptr)
|
2009-04-24 23:35:41 +00:00
|
|
|
? reinterpret_cast<IdlerID>(idleTimerID) : 0;
|
|
|
|
} else {
|
|
|
|
::KillTimer(MainHWND(), reinterpret_cast<uptr_t>(idler.idlerID));
|
|
|
|
idler.idlerID = 0;
|
|
|
|
}
|
|
|
|
idler.state = idler.idlerID != 0;
|
|
|
|
}
|
|
|
|
return idler.state;
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
void ScintillaWin::IdleWork() {
|
|
|
|
styleIdleInQueue = false;
|
|
|
|
Editor::IdleWork();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::QueueIdleWork(WorkNeeded::workItems items, Sci::Position upTo) {
|
|
|
|
Editor::QueueIdleWork(items, upTo);
|
|
|
|
if (!styleIdleInQueue) {
|
|
|
|
if (PostMessage(MainHWND(), SC_WORK_IDLE, 0, 0)) {
|
|
|
|
styleIdleInQueue = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
void ScintillaWin::SetMouseCapture(bool on) {
|
|
|
|
if (mouseDownCaptures) {
|
|
|
|
if (on) {
|
|
|
|
::SetCapture(MainHWND());
|
|
|
|
} else {
|
|
|
|
::ReleaseCapture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
capturedMouse = on;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScintillaWin::HaveMouseCapture() {
|
|
|
|
// Cannot just see if GetCapture is this window as the scroll bar also sets capture for the window
|
|
|
|
return capturedMouse;
|
|
|
|
//return capturedMouse && (::GetCapture() == MainHWND());
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
void ScintillaWin::SetTrackMouseLeaveEvent(bool on) noexcept {
|
2019-05-04 18:14:48 +00:00
|
|
|
if (on && !trackedMouseLeave) {
|
2010-07-12 22:19:51 +00:00
|
|
|
TRACKMOUSEEVENT tme;
|
|
|
|
tme.cbSize = sizeof(tme);
|
|
|
|
tme.dwFlags = TME_LEAVE;
|
|
|
|
tme.hwndTrack = MainHWND();
|
2015-06-07 21:19:26 +00:00
|
|
|
tme.dwHoverTime = HOVER_DEFAULT; // Unused but triggers Dr. Memory if not initialized
|
2019-05-04 18:14:48 +00:00
|
|
|
TrackMouseEvent(&tme);
|
2010-07-12 22:19:51 +00:00
|
|
|
}
|
|
|
|
trackedMouseLeave = on;
|
|
|
|
}
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
bool ScintillaWin::PaintContains(PRectangle rc) {
|
2015-06-07 21:19:26 +00:00
|
|
|
if (paintState == painting) {
|
|
|
|
return BoundsContains(rcPaint, hRgnUpdate, rc);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2015-06-07 21:19:26 +00:00
|
|
|
return true;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
void ScintillaWin::ScrollText(Sci::Line /* linesToMove */) {
|
2009-04-24 23:35:41 +00:00
|
|
|
//Platform::DebugPrintf("ScintillaWin::ScrollText %d\n", linesToMove);
|
2013-08-28 00:44:27 +00:00
|
|
|
//::ScrollWindow(MainHWND(), 0,
|
|
|
|
// vs.lineHeight * linesToMove, 0, 0);
|
|
|
|
//::UpdateWindow(MainHWND());
|
|
|
|
Redraw();
|
2015-06-07 21:19:26 +00:00
|
|
|
UpdateSystemCaret();
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
void ScintillaWin::NotifyCaretMove() {
|
|
|
|
NotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, MainHWND(), OBJID_CARET, CHILDID_SELF);
|
|
|
|
}
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
void ScintillaWin::UpdateSystemCaret() {
|
|
|
|
if (hasFocus) {
|
|
|
|
if (HasCaretSizeChanged()) {
|
|
|
|
DestroySystemCaret();
|
|
|
|
CreateSystemCaret();
|
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
const Point pos = PointMainCaret();
|
2015-06-07 21:19:26 +00:00
|
|
|
::SetCaretPos(static_cast<int>(pos.x), static_cast<int>(pos.y));
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
int ScintillaWin::SetScrollInfo(int nBar, LPCSCROLLINFO lpsi, BOOL bRedraw) noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
return ::SetScrollInfo(MainHWND(), nBar, lpsi, bRedraw);
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
bool ScintillaWin::GetScrollInfo(int nBar, LPSCROLLINFO lpsi) noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
return ::GetScrollInfo(MainHWND(), nBar, lpsi) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change the scroll position but avoid repaint if changing to same value
|
2019-05-04 18:14:48 +00:00
|
|
|
void ScintillaWin::ChangeScrollPos(int barType, Sci::Position pos) {
|
2009-04-24 23:35:41 +00:00
|
|
|
SCROLLINFO sci = {
|
2010-07-12 22:19:51 +00:00
|
|
|
sizeof(sci), 0, 0, 0, 0, 0, 0
|
2009-04-24 23:35:41 +00:00
|
|
|
};
|
|
|
|
sci.fMask = SIF_POS;
|
|
|
|
GetScrollInfo(barType, &sci);
|
|
|
|
if (sci.nPos != pos) {
|
|
|
|
DwellEnd(true);
|
2019-05-04 18:14:48 +00:00
|
|
|
sci.nPos = static_cast<int>(pos);
|
2009-04-24 23:35:41 +00:00
|
|
|
SetScrollInfo(barType, &sci, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::SetVerticalScrollPos() {
|
|
|
|
ChangeScrollPos(SB_VERT, topLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::SetHorizontalScrollPos() {
|
|
|
|
ChangeScrollPos(SB_HORZ, xOffset);
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
bool ScintillaWin::ModifyScrollBars(Sci::Line nMax, Sci::Line nPage) {
|
2009-04-24 23:35:41 +00:00
|
|
|
bool modified = false;
|
|
|
|
SCROLLINFO sci = {
|
2010-07-12 22:19:51 +00:00
|
|
|
sizeof(sci), 0, 0, 0, 0, 0, 0
|
2009-04-24 23:35:41 +00:00
|
|
|
};
|
|
|
|
sci.fMask = SIF_PAGE | SIF_RANGE;
|
|
|
|
GetScrollInfo(SB_VERT, &sci);
|
2019-05-04 18:14:48 +00:00
|
|
|
const Sci::Line vertEndPreferred = nMax;
|
2009-04-24 23:35:41 +00:00
|
|
|
if (!verticalScrollBarVisible)
|
2013-08-28 00:44:27 +00:00
|
|
|
nPage = vertEndPreferred + 1;
|
2009-04-24 23:35:41 +00:00
|
|
|
if ((sci.nMin != 0) ||
|
|
|
|
(sci.nMax != vertEndPreferred) ||
|
|
|
|
(sci.nPage != static_cast<unsigned int>(nPage)) ||
|
|
|
|
(sci.nPos != 0)) {
|
|
|
|
sci.fMask = SIF_PAGE | SIF_RANGE;
|
|
|
|
sci.nMin = 0;
|
2019-05-04 18:14:48 +00:00
|
|
|
sci.nMax = static_cast<int>(vertEndPreferred);
|
|
|
|
sci.nPage = static_cast<UINT>(nPage);
|
2009-04-24 23:35:41 +00:00
|
|
|
sci.nPos = 0;
|
|
|
|
sci.nTrackPos = 1;
|
|
|
|
SetScrollInfo(SB_VERT, &sci, TRUE);
|
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
const PRectangle rcText = GetTextRectangle();
|
2009-04-24 23:35:41 +00:00
|
|
|
int horizEndPreferred = scrollWidth;
|
|
|
|
if (horizEndPreferred < 0)
|
|
|
|
horizEndPreferred = 0;
|
2019-05-04 18:14:48 +00:00
|
|
|
int pageWidth = static_cast<int>(rcText.Width());
|
2015-06-07 21:19:26 +00:00
|
|
|
if (!horizontalScrollBarVisible || Wrapping())
|
2013-08-28 00:44:27 +00:00
|
|
|
pageWidth = horizEndPreferred + 1;
|
2009-04-24 23:35:41 +00:00
|
|
|
sci.fMask = SIF_PAGE | SIF_RANGE;
|
|
|
|
GetScrollInfo(SB_HORZ, &sci);
|
|
|
|
if ((sci.nMin != 0) ||
|
|
|
|
(sci.nMax != horizEndPreferred) ||
|
2019-05-04 18:14:48 +00:00
|
|
|
(sci.nPage != static_cast<unsigned int>(pageWidth)) ||
|
2009-04-24 23:35:41 +00:00
|
|
|
(sci.nPos != 0)) {
|
|
|
|
sci.fMask = SIF_PAGE | SIF_RANGE;
|
|
|
|
sci.nMin = 0;
|
|
|
|
sci.nMax = horizEndPreferred;
|
|
|
|
sci.nPage = pageWidth;
|
|
|
|
sci.nPos = 0;
|
|
|
|
sci.nTrackPos = 1;
|
|
|
|
SetScrollInfo(SB_HORZ, &sci, TRUE);
|
|
|
|
modified = true;
|
2019-05-04 18:14:48 +00:00
|
|
|
if (scrollWidth < pageWidth) {
|
2009-04-24 23:35:41 +00:00
|
|
|
HorizontalScrollTo(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return modified;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::NotifyChange() {
|
|
|
|
::SendMessage(::GetParent(MainHWND()), WM_COMMAND,
|
2019-05-04 18:14:48 +00:00
|
|
|
MAKEWPARAM(GetCtrlID(), SCEN_CHANGE),
|
2009-04-24 23:35:41 +00:00
|
|
|
reinterpret_cast<LPARAM>(MainHWND()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::NotifyFocus(bool focus) {
|
2019-05-04 18:14:48 +00:00
|
|
|
if (commandEvents) {
|
|
|
|
::SendMessage(::GetParent(MainHWND()), WM_COMMAND,
|
|
|
|
MAKEWPARAM(GetCtrlID(), focus ? SCEN_SETFOCUS : SCEN_KILLFOCUS),
|
|
|
|
reinterpret_cast<LPARAM>(MainHWND()));
|
|
|
|
}
|
2015-06-07 21:19:26 +00:00
|
|
|
Editor::NotifyFocus(focus);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
2011-07-17 22:30:49 +00:00
|
|
|
void ScintillaWin::SetCtrlID(int identifier) {
|
2019-05-04 18:14:48 +00:00
|
|
|
::SetWindowID(static_cast<HWND>(wMain.GetID()), identifier);
|
2011-07-17 22:30:49 +00:00
|
|
|
}
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
int ScintillaWin::GetCtrlID() {
|
2019-05-04 18:14:48 +00:00
|
|
|
return ::GetDlgCtrlID(static_cast<HWND>(wMain.GetID()));
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::NotifyParent(SCNotification scn) {
|
|
|
|
scn.nmhdr.hwndFrom = MainHWND();
|
|
|
|
scn.nmhdr.idFrom = GetCtrlID();
|
|
|
|
::SendMessage(::GetParent(MainHWND()), WM_NOTIFY,
|
|
|
|
GetCtrlID(), reinterpret_cast<LPARAM>(&scn));
|
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
void ScintillaWin::NotifyDoubleClick(Point pt, int modifiers) {
|
2009-04-24 23:35:41 +00:00
|
|
|
//Platform::DebugPrintf("ScintillaWin Double click 0\n");
|
2015-06-07 21:19:26 +00:00
|
|
|
ScintillaBase::NotifyDoubleClick(pt, modifiers);
|
2009-04-24 23:35:41 +00:00
|
|
|
// Send myself a WM_LBUTTONDBLCLK, so the container can handle it too.
|
|
|
|
::SendMessage(MainHWND(),
|
|
|
|
WM_LBUTTONDBLCLK,
|
2015-06-07 21:19:26 +00:00
|
|
|
(modifiers & SCI_SHIFT) ? MK_SHIFT : 0,
|
2009-04-24 23:35:41 +00:00
|
|
|
MAKELPARAM(pt.x, pt.y));
|
|
|
|
}
|
|
|
|
|
2010-09-05 22:56:27 +00:00
|
|
|
class CaseFolderDBCS : public CaseFolderTable {
|
|
|
|
// Allocate the expandable storage here so that it does not need to be reallocated
|
|
|
|
// for each call to Fold.
|
|
|
|
std::vector<wchar_t> utf16Mixed;
|
|
|
|
std::vector<wchar_t> utf16Folded;
|
|
|
|
UINT cp;
|
|
|
|
public:
|
2015-06-07 21:19:26 +00:00
|
|
|
explicit CaseFolderDBCS(UINT cp_) : cp(cp_) {
|
2010-09-05 22:56:27 +00:00
|
|
|
StandardASCII();
|
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
size_t Fold(char *folded, size_t sizeFolded, const char *mixed, size_t lenMixed) override {
|
2010-09-05 22:56:27 +00:00
|
|
|
if ((lenMixed == 1) && (sizeFolded > 0)) {
|
|
|
|
folded[0] = mapping[static_cast<unsigned char>(mixed[0])];
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
if (lenMixed > utf16Mixed.size()) {
|
|
|
|
utf16Mixed.resize(lenMixed + 8);
|
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
const size_t nUtf16Mixed = WideCharFromMultiByte(cp,
|
|
|
|
std::string_view(mixed, lenMixed),
|
2013-08-28 00:44:27 +00:00
|
|
|
&utf16Mixed[0],
|
2019-05-04 18:14:48 +00:00
|
|
|
utf16Mixed.size());
|
2010-09-05 22:56:27 +00:00
|
|
|
|
|
|
|
if (nUtf16Mixed == 0) {
|
|
|
|
// Failed to convert -> bad input
|
|
|
|
folded[0] = '\0';
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
size_t lenFlat = 0;
|
2013-08-28 00:44:27 +00:00
|
|
|
for (size_t mixIndex=0; mixIndex < nUtf16Mixed; mixIndex++) {
|
|
|
|
if ((lenFlat + 20) > utf16Folded.size())
|
|
|
|
utf16Folded.resize(lenFlat + 60);
|
|
|
|
const char *foldedUTF8 = CaseConvert(utf16Mixed[mixIndex], CaseConversionFold);
|
|
|
|
if (foldedUTF8) {
|
|
|
|
// Maximum length of a case conversion is 6 bytes, 3 characters
|
|
|
|
wchar_t wFolded[20];
|
2019-05-04 18:14:48 +00:00
|
|
|
const size_t charsConverted = UTF16FromUTF8(std::string_view(foldedUTF8),
|
|
|
|
wFolded, std::size(wFolded));
|
2015-06-07 21:19:26 +00:00
|
|
|
for (size_t j=0; j<charsConverted; j++)
|
2013-08-28 00:44:27 +00:00
|
|
|
utf16Folded[lenFlat++] = wFolded[j];
|
|
|
|
} else {
|
|
|
|
utf16Folded[lenFlat++] = utf16Mixed[mixIndex];
|
|
|
|
}
|
2010-09-05 22:56:27 +00:00
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
const std::wstring_view wsvFolded(&utf16Folded[0], lenFlat);
|
|
|
|
const size_t lenOut = MultiByteLenFromWideChar(cp, wsvFolded);
|
2010-09-05 22:56:27 +00:00
|
|
|
|
|
|
|
if (lenOut < sizeFolded) {
|
2019-05-04 18:14:48 +00:00
|
|
|
MultiByteFromWideChar(cp, wsvFolded, folded, lenOut);
|
2010-09-05 22:56:27 +00:00
|
|
|
return lenOut;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-12 22:19:51 +00:00
|
|
|
CaseFolder *ScintillaWin::CaseFolderForEncoding() {
|
2019-05-04 18:14:48 +00:00
|
|
|
const UINT cpDest = CodePageOfDocument();
|
2010-07-12 22:19:51 +00:00
|
|
|
if (cpDest == SC_CP_UTF8) {
|
2013-08-28 00:44:27 +00:00
|
|
|
return new CaseFolderUnicode();
|
2010-07-12 22:19:51 +00:00
|
|
|
} else {
|
|
|
|
if (pdoc->dbcsCodePage == 0) {
|
2010-09-05 22:56:27 +00:00
|
|
|
CaseFolderTable *pcf = new CaseFolderTable();
|
2010-07-12 22:19:51 +00:00
|
|
|
pcf->StandardASCII();
|
|
|
|
// Only for single byte encodings
|
|
|
|
for (int i=0x80; i<0x100; i++) {
|
|
|
|
char sCharacter[2] = "A";
|
|
|
|
sCharacter[0] = static_cast<char>(i);
|
|
|
|
wchar_t wCharacter[20];
|
2019-05-04 18:14:48 +00:00
|
|
|
const unsigned int lengthUTF16 = WideCharFromMultiByte(cpDest, sCharacter,
|
|
|
|
wCharacter, std::size(wCharacter));
|
2010-07-12 22:19:51 +00:00
|
|
|
if (lengthUTF16 == 1) {
|
2013-08-28 00:44:27 +00:00
|
|
|
const char *caseFolded = CaseConvert(wCharacter[0], CaseConversionFold);
|
|
|
|
if (caseFolded) {
|
|
|
|
wchar_t wLower[20];
|
2019-05-04 18:14:48 +00:00
|
|
|
const size_t charsConverted = UTF16FromUTF8(std::string_view(caseFolded),
|
|
|
|
wLower, std::size(wLower));
|
2013-08-28 00:44:27 +00:00
|
|
|
if (charsConverted == 1) {
|
|
|
|
char sCharacterLowered[20];
|
2019-05-04 18:14:48 +00:00
|
|
|
const unsigned int lengthConverted = MultiByteFromWideChar(cpDest,
|
|
|
|
std::wstring_view(wLower, charsConverted),
|
|
|
|
sCharacterLowered, std::size(sCharacterLowered));
|
2013-08-28 00:44:27 +00:00
|
|
|
if ((lengthConverted == 1) && (sCharacter[0] != sCharacterLowered[0])) {
|
|
|
|
pcf->SetTranslation(sCharacter[0], sCharacterLowered[0]);
|
|
|
|
}
|
|
|
|
}
|
2010-07-12 22:19:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-05 22:56:27 +00:00
|
|
|
return pcf;
|
|
|
|
} else {
|
|
|
|
return new CaseFolderDBCS(cpDest);
|
2010-07-12 22:19:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ScintillaWin::CaseMapString(const std::string &s, int caseMapping) {
|
2013-08-28 00:44:27 +00:00
|
|
|
if ((s.size() == 0) || (caseMapping == cmSame))
|
2010-07-12 22:19:51 +00:00
|
|
|
return s;
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
const UINT cpDoc = CodePageOfDocument();
|
2013-08-28 00:44:27 +00:00
|
|
|
if (cpDoc == SC_CP_UTF8) {
|
2019-05-04 18:14:48 +00:00
|
|
|
return CaseConvertString(s, (caseMapping == cmUpper) ? CaseConversionUpper : CaseConversionLower);
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
2010-07-12 22:19:51 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
// Change text to UTF-16
|
|
|
|
const std::wstring wsText = StringDecode(s, cpDoc);
|
2010-07-12 22:19:51 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
const DWORD mapFlags = LCMAP_LINGUISTIC_CASING |
|
2010-07-12 22:19:51 +00:00
|
|
|
((caseMapping == cmUpper) ? LCMAP_UPPERCASE : LCMAP_LOWERCASE);
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
// Change case
|
2019-05-04 18:14:48 +00:00
|
|
|
const std::wstring wsConverted = StringMapCase(wsText, mapFlags);
|
2010-07-12 22:19:51 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
// Change back to document encoding
|
2019-05-04 18:14:48 +00:00
|
|
|
std::string sConverted = StringEncode(wsConverted, cpDoc);
|
2010-07-12 22:19:51 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
return sConverted;
|
2010-07-12 22:19:51 +00:00
|
|
|
}
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
void ScintillaWin::Copy() {
|
|
|
|
//Platform::DebugPrintf("Copy\n");
|
2009-08-23 02:24:48 +00:00
|
|
|
if (!sel.Empty()) {
|
2009-04-24 23:35:41 +00:00
|
|
|
SelectionText selectedText;
|
|
|
|
CopySelectionRange(&selectedText);
|
|
|
|
CopyToClipboard(selectedText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::CopyAllowLine() {
|
|
|
|
SelectionText selectedText;
|
|
|
|
CopySelectionRange(&selectedText, true);
|
|
|
|
CopyToClipboard(selectedText);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScintillaWin::CanPaste() {
|
|
|
|
if (!Editor::CanPaste())
|
|
|
|
return false;
|
|
|
|
if (::IsClipboardFormatAvailable(CF_TEXT))
|
|
|
|
return true;
|
|
|
|
if (IsUnicodeMode())
|
|
|
|
return ::IsClipboardFormatAvailable(CF_UNICODETEXT) != 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
namespace {
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
class GlobalMemory {
|
2019-05-04 18:14:48 +00:00
|
|
|
HGLOBAL hand {};
|
2009-04-24 23:35:41 +00:00
|
|
|
public:
|
2019-05-04 18:14:48 +00:00
|
|
|
void *ptr {};
|
2019-07-21 13:26:02 +00:00
|
|
|
GlobalMemory() noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2019-07-21 13:26:02 +00:00
|
|
|
explicit GlobalMemory(HGLOBAL hand_) noexcept : hand(hand_) {
|
2009-04-24 23:35:41 +00:00
|
|
|
if (hand) {
|
|
|
|
ptr = ::GlobalLock(hand);
|
|
|
|
}
|
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
// Deleted so GlobalMemory objects can not be copied.
|
|
|
|
GlobalMemory(const GlobalMemory &) = delete;
|
|
|
|
GlobalMemory(GlobalMemory &&) = delete;
|
|
|
|
GlobalMemory &operator=(const GlobalMemory &) = delete;
|
|
|
|
GlobalMemory &operator=(GlobalMemory &&) = delete;
|
2009-04-24 23:35:41 +00:00
|
|
|
~GlobalMemory() {
|
2019-07-21 13:26:02 +00:00
|
|
|
assert(!ptr);
|
2015-06-07 21:19:26 +00:00
|
|
|
assert(!hand);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2019-07-21 13:26:02 +00:00
|
|
|
void Allocate(size_t bytes) noexcept {
|
2015-06-07 21:19:26 +00:00
|
|
|
assert(!hand);
|
2009-04-24 23:35:41 +00:00
|
|
|
hand = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, bytes);
|
|
|
|
if (hand) {
|
|
|
|
ptr = ::GlobalLock(hand);
|
|
|
|
}
|
|
|
|
}
|
2019-07-21 13:26:02 +00:00
|
|
|
HGLOBAL Unlock() noexcept {
|
|
|
|
assert(ptr);
|
2009-04-24 23:35:41 +00:00
|
|
|
HGLOBAL handCopy = hand;
|
|
|
|
::GlobalUnlock(hand);
|
2019-07-21 13:26:02 +00:00
|
|
|
ptr = nullptr;
|
|
|
|
hand = {};
|
2009-04-24 23:35:41 +00:00
|
|
|
return handCopy;
|
|
|
|
}
|
2019-07-21 13:26:02 +00:00
|
|
|
void SetClip(UINT uFormat) noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
::SetClipboardData(uFormat, Unlock());
|
|
|
|
}
|
2019-07-21 13:26:02 +00:00
|
|
|
operator bool() const noexcept {
|
2019-05-04 18:14:48 +00:00
|
|
|
return ptr != nullptr;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2019-07-21 13:26:02 +00:00
|
|
|
SIZE_T Size() const noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
return ::GlobalSize(hand);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
// OpenClipboard may fail if another application has opened the clipboard.
|
|
|
|
// Try up to 8 times, with an initial delay of 1 ms and an exponential back off
|
|
|
|
// for a maximum total delay of 127 ms (1+2+4+8+16+32+64).
|
2019-07-21 13:26:02 +00:00
|
|
|
bool OpenClipboardRetry(HWND hwnd) noexcept {
|
2019-05-04 18:14:48 +00:00
|
|
|
for (int attempt=0; attempt<8; attempt++) {
|
|
|
|
if (attempt > 0) {
|
|
|
|
::Sleep(1 << (attempt-1));
|
|
|
|
}
|
|
|
|
if (::OpenClipboard(hwnd)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
void ScintillaWin::Paste() {
|
2019-05-04 18:14:48 +00:00
|
|
|
if (!::OpenClipboardRetry(MainHWND())) {
|
2009-04-24 23:35:41 +00:00
|
|
|
return;
|
2019-05-04 18:14:48 +00:00
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
UndoGroup ug(pdoc);
|
2019-05-04 18:14:48 +00:00
|
|
|
const bool isLine = SelectionEmpty() &&
|
2015-06-07 21:19:26 +00:00
|
|
|
(::IsClipboardFormatAvailable(cfLineSelect) || ::IsClipboardFormatAvailable(cfVSLineTag));
|
2011-03-22 00:16:49 +00:00
|
|
|
ClearSelection(multiPasteMode == SC_MULTIPASTE_EACH);
|
2015-06-07 21:19:26 +00:00
|
|
|
bool isRectangular = (::IsClipboardFormatAvailable(cfColumnSelect) != 0);
|
|
|
|
|
|
|
|
if (!isRectangular) {
|
|
|
|
// Evaluate "Borland IDE Block Type" explicitly
|
|
|
|
GlobalMemory memBorlandSelection(::GetClipboardData(cfBorlandIDEBlockType));
|
|
|
|
if (memBorlandSelection) {
|
|
|
|
isRectangular = (memBorlandSelection.Size() == 1) && (static_cast<BYTE *>(memBorlandSelection.ptr)[0] == 0x02);
|
|
|
|
memBorlandSelection.Unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const PasteShape pasteShape = isRectangular ? pasteRectangular : (isLine ? pasteLine : pasteStream);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
// Always use CF_UNICODETEXT if available
|
|
|
|
GlobalMemory memUSelection(::GetClipboardData(CF_UNICODETEXT));
|
|
|
|
if (memUSelection) {
|
2019-05-04 18:14:48 +00:00
|
|
|
const wchar_t *uptr = static_cast<const wchar_t *>(memUSelection.ptr);
|
2009-04-24 23:35:41 +00:00
|
|
|
if (uptr) {
|
2019-05-04 18:14:48 +00:00
|
|
|
size_t len;
|
2013-08-28 00:44:27 +00:00
|
|
|
std::vector<char> putf;
|
2009-04-24 23:35:41 +00:00
|
|
|
// Default Scintilla behaviour in Unicode mode
|
|
|
|
if (IsUnicodeMode()) {
|
2019-05-04 18:14:48 +00:00
|
|
|
const size_t bytes = memUSelection.Size();
|
|
|
|
const std::wstring_view wsv(uptr, bytes / 2);
|
|
|
|
len = UTF8Length(wsv);
|
2013-08-28 00:44:27 +00:00
|
|
|
putf.resize(len + 1);
|
2019-05-04 18:14:48 +00:00
|
|
|
UTF8FromUTF16(wsv, &putf[0], len);
|
2009-04-24 23:35:41 +00:00
|
|
|
} else {
|
|
|
|
// CF_UNICODETEXT available, but not in Unicode mode
|
|
|
|
// Convert from Unicode to current Scintilla code page
|
2019-05-04 18:14:48 +00:00
|
|
|
const UINT cpDest = CodePageOfDocument();
|
|
|
|
len = MultiByteLenFromWideChar(cpDest, uptr);
|
|
|
|
putf.resize(len);
|
|
|
|
MultiByteFromWideChar(cpDest, uptr, &putf[0], len);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
InsertPasteShape(&putf[0], len, pasteShape);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
memUSelection.Unlock();
|
|
|
|
} else {
|
|
|
|
// CF_UNICODETEXT not available, paste ANSI text
|
|
|
|
GlobalMemory memSelection(::GetClipboardData(CF_TEXT));
|
|
|
|
if (memSelection) {
|
2019-05-04 18:14:48 +00:00
|
|
|
const char *ptr = static_cast<const char *>(memSelection.ptr);
|
2009-04-24 23:35:41 +00:00
|
|
|
if (ptr) {
|
2019-05-04 18:14:48 +00:00
|
|
|
const size_t bytes = memSelection.Size();
|
|
|
|
size_t len = bytes;
|
|
|
|
for (size_t i = 0; i < bytes; i++) {
|
2009-04-24 23:35:41 +00:00
|
|
|
if ((len == bytes) && (0 == ptr[i]))
|
|
|
|
len = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
// In Unicode mode, convert clipboard text to UTF-8
|
|
|
|
if (IsUnicodeMode()) {
|
2013-08-28 00:44:27 +00:00
|
|
|
std::vector<wchar_t> uptr(len+1);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
const size_t ulen = WideCharFromMultiByte(CP_ACP,
|
2019-07-21 13:26:02 +00:00
|
|
|
std::string_view(ptr, len), &uptr[0], len + 1);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
const std::wstring_view wsv(&uptr[0], ulen);
|
|
|
|
const size_t mlen = UTF8Length(wsv);
|
2013-08-28 00:44:27 +00:00
|
|
|
std::vector<char> putf(mlen+1);
|
2019-05-04 18:14:48 +00:00
|
|
|
UTF8FromUTF16(wsv, &putf[0], mlen);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
InsertPasteShape(&putf[0], mlen, pasteShape);
|
2009-04-24 23:35:41 +00:00
|
|
|
} else {
|
2015-06-07 21:19:26 +00:00
|
|
|
InsertPasteShape(ptr, len, pasteShape);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
memSelection.Unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
::CloseClipboard();
|
|
|
|
Redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::CreateCallTipWindow(PRectangle) {
|
|
|
|
if (!ct.wCallTip.Created()) {
|
2019-05-04 18:14:48 +00:00
|
|
|
HWND wnd = ::CreateWindow(callClassName, TEXT("ACallTip"),
|
2009-04-24 23:35:41 +00:00
|
|
|
WS_POPUP, 100, 100, 150, 20,
|
|
|
|
MainHWND(), 0,
|
|
|
|
GetWindowInstance(MainHWND()),
|
|
|
|
this);
|
2019-05-04 18:14:48 +00:00
|
|
|
ct.wCallTip = wnd;
|
|
|
|
ct.wDraw = wnd;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::AddToPopUp(const char *label, int cmd, bool enabled) {
|
2019-05-04 18:14:48 +00:00
|
|
|
HMENU hmenuPopup = static_cast<HMENU>(popup.GetID());
|
2009-04-24 23:35:41 +00:00
|
|
|
if (!label[0])
|
|
|
|
::AppendMenuA(hmenuPopup, MF_SEPARATOR, 0, "");
|
|
|
|
else if (enabled)
|
|
|
|
::AppendMenuA(hmenuPopup, MF_STRING, cmd, label);
|
|
|
|
else
|
|
|
|
::AppendMenuA(hmenuPopup, MF_STRING | MF_DISABLED | MF_GRAYED, cmd, label);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::ClaimSelection() {
|
|
|
|
// Windows does not have a primary selection
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Implement IUnknown
|
|
|
|
|
|
|
|
STDMETHODIMP_(ULONG)FormatEnumerator_AddRef(FormatEnumerator *fe);
|
|
|
|
STDMETHODIMP FormatEnumerator_QueryInterface(FormatEnumerator *fe, REFIID riid, PVOID *ppv) {
|
|
|
|
//Platform::DebugPrintf("EFE QI");
|
2019-05-04 18:14:48 +00:00
|
|
|
*ppv = nullptr;
|
2009-04-24 23:35:41 +00:00
|
|
|
if (riid == IID_IUnknown)
|
|
|
|
*ppv = reinterpret_cast<IEnumFORMATETC *>(fe);
|
|
|
|
if (riid == IID_IEnumFORMATETC)
|
|
|
|
*ppv = reinterpret_cast<IEnumFORMATETC *>(fe);
|
|
|
|
if (!*ppv)
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
FormatEnumerator_AddRef(fe);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
STDMETHODIMP_(ULONG)FormatEnumerator_AddRef(FormatEnumerator *fe) {
|
|
|
|
return ++fe->ref;
|
|
|
|
}
|
|
|
|
STDMETHODIMP_(ULONG)FormatEnumerator_Release(FormatEnumerator *fe) {
|
|
|
|
fe->ref--;
|
|
|
|
if (fe->ref > 0)
|
|
|
|
return fe->ref;
|
|
|
|
delete fe;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/// Implement IEnumFORMATETC
|
|
|
|
STDMETHODIMP FormatEnumerator_Next(FormatEnumerator *fe, ULONG celt, FORMATETC *rgelt, ULONG *pceltFetched) {
|
2019-05-04 18:14:48 +00:00
|
|
|
if (!rgelt) return E_POINTER;
|
2009-04-24 23:35:41 +00:00
|
|
|
unsigned int putPos = 0;
|
2015-06-07 21:19:26 +00:00
|
|
|
while ((fe->pos < fe->formats.size()) && (putPos < celt)) {
|
2009-04-24 23:35:41 +00:00
|
|
|
rgelt->cfFormat = fe->formats[fe->pos];
|
2019-07-21 13:26:02 +00:00
|
|
|
rgelt->ptd = nullptr;
|
2009-04-24 23:35:41 +00:00
|
|
|
rgelt->dwAspect = DVASPECT_CONTENT;
|
|
|
|
rgelt->lindex = -1;
|
|
|
|
rgelt->tymed = TYMED_HGLOBAL;
|
2015-06-07 21:19:26 +00:00
|
|
|
rgelt++;
|
2009-04-24 23:35:41 +00:00
|
|
|
fe->pos++;
|
|
|
|
putPos++;
|
|
|
|
}
|
|
|
|
if (pceltFetched)
|
|
|
|
*pceltFetched = putPos;
|
|
|
|
return putPos ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
STDMETHODIMP FormatEnumerator_Skip(FormatEnumerator *fe, ULONG celt) {
|
|
|
|
fe->pos += celt;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
STDMETHODIMP FormatEnumerator_Reset(FormatEnumerator *fe) {
|
|
|
|
fe->pos = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
STDMETHODIMP FormatEnumerator_Clone(FormatEnumerator *fe, IEnumFORMATETC **ppenum) {
|
2009-08-23 02:24:48 +00:00
|
|
|
FormatEnumerator *pfe;
|
|
|
|
try {
|
2015-06-07 21:19:26 +00:00
|
|
|
pfe = new FormatEnumerator(fe->pos, &fe->formats[0], fe->formats.size());
|
2009-08-23 02:24:48 +00:00
|
|
|
} catch (...) {
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
return FormatEnumerator_QueryInterface(pfe, IID_IEnumFORMATETC,
|
|
|
|
reinterpret_cast<void **>(ppenum));
|
|
|
|
}
|
|
|
|
|
2010-07-12 22:19:51 +00:00
|
|
|
static VFunction *vtFormatEnumerator[] = {
|
|
|
|
(VFunction *)(FormatEnumerator_QueryInterface),
|
|
|
|
(VFunction *)(FormatEnumerator_AddRef),
|
|
|
|
(VFunction *)(FormatEnumerator_Release),
|
|
|
|
(VFunction *)(FormatEnumerator_Next),
|
|
|
|
(VFunction *)(FormatEnumerator_Skip),
|
|
|
|
(VFunction *)(FormatEnumerator_Reset),
|
|
|
|
(VFunction *)(FormatEnumerator_Clone)
|
2009-04-24 23:35:41 +00:00
|
|
|
};
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
FormatEnumerator::FormatEnumerator(int pos_, CLIPFORMAT formats_[], size_t formatsLen_) {
|
2009-04-24 23:35:41 +00:00
|
|
|
vtbl = vtFormatEnumerator;
|
|
|
|
ref = 0; // First QI adds first reference...
|
|
|
|
pos = pos_;
|
2015-06-07 21:19:26 +00:00
|
|
|
formats.insert(formats.begin(), formats_, formats_+formatsLen_);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Implement IUnknown
|
|
|
|
STDMETHODIMP DropSource_QueryInterface(DropSource *ds, REFIID riid, PVOID *ppv) {
|
|
|
|
return ds->sci->QueryInterface(riid, ppv);
|
|
|
|
}
|
|
|
|
STDMETHODIMP_(ULONG)DropSource_AddRef(DropSource *ds) {
|
|
|
|
return ds->sci->AddRef();
|
|
|
|
}
|
|
|
|
STDMETHODIMP_(ULONG)DropSource_Release(DropSource *ds) {
|
|
|
|
return ds->sci->Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Implement IDropSource
|
|
|
|
STDMETHODIMP DropSource_QueryContinueDrag(DropSource *, BOOL fEsc, DWORD grfKeyState) {
|
|
|
|
if (fEsc)
|
|
|
|
return DRAGDROP_S_CANCEL;
|
|
|
|
if (!(grfKeyState & MK_LBUTTON))
|
|
|
|
return DRAGDROP_S_DROP;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP DropSource_GiveFeedback(DropSource *, DWORD) {
|
|
|
|
return DRAGDROP_S_USEDEFAULTCURSORS;
|
|
|
|
}
|
|
|
|
|
2010-07-12 22:19:51 +00:00
|
|
|
static VFunction *vtDropSource[] = {
|
|
|
|
(VFunction *)(DropSource_QueryInterface),
|
|
|
|
(VFunction *)(DropSource_AddRef),
|
|
|
|
(VFunction *)(DropSource_Release),
|
|
|
|
(VFunction *)(DropSource_QueryContinueDrag),
|
|
|
|
(VFunction *)(DropSource_GiveFeedback)
|
2009-04-24 23:35:41 +00:00
|
|
|
};
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
DropSource::DropSource() noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
vtbl = vtDropSource;
|
2019-05-04 18:14:48 +00:00
|
|
|
sci = nullptr;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Implement IUnkown
|
|
|
|
STDMETHODIMP DataObject_QueryInterface(DataObject *pd, REFIID riid, PVOID *ppv) {
|
|
|
|
//Platform::DebugPrintf("DO QI %x\n", pd);
|
|
|
|
return pd->sci->QueryInterface(riid, ppv);
|
|
|
|
}
|
|
|
|
STDMETHODIMP_(ULONG)DataObject_AddRef(DataObject *pd) {
|
|
|
|
return pd->sci->AddRef();
|
|
|
|
}
|
|
|
|
STDMETHODIMP_(ULONG)DataObject_Release(DataObject *pd) {
|
|
|
|
return pd->sci->Release();
|
|
|
|
}
|
|
|
|
/// Implement IDataObject
|
|
|
|
STDMETHODIMP DataObject_GetData(DataObject *pd, FORMATETC *pFEIn, STGMEDIUM *pSTM) {
|
|
|
|
return pd->sci->GetData(pFEIn, pSTM);
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP DataObject_GetDataHere(DataObject *, FORMATETC *, STGMEDIUM *) {
|
|
|
|
//Platform::DebugPrintf("DOB GetDataHere\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP DataObject_QueryGetData(DataObject *pd, FORMATETC *pFE) {
|
|
|
|
if (pd->sci->DragIsRectangularOK(pFE->cfFormat) &&
|
2019-07-21 13:26:02 +00:00
|
|
|
pFE->ptd == nullptr &&
|
2009-04-24 23:35:41 +00:00
|
|
|
(pFE->dwAspect & DVASPECT_CONTENT) != 0 &&
|
|
|
|
pFE->lindex == -1 &&
|
|
|
|
(pFE->tymed & TYMED_HGLOBAL) != 0
|
|
|
|
) {
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
const bool formatOK = (pFE->cfFormat == CF_TEXT) ||
|
2009-04-24 23:35:41 +00:00
|
|
|
((pFE->cfFormat == CF_UNICODETEXT) && pd->sci->IsUnicodeMode());
|
|
|
|
if (!formatOK ||
|
2019-07-21 13:26:02 +00:00
|
|
|
pFE->ptd != nullptr ||
|
2009-04-24 23:35:41 +00:00
|
|
|
(pFE->dwAspect & DVASPECT_CONTENT) == 0 ||
|
|
|
|
pFE->lindex != -1 ||
|
|
|
|
(pFE->tymed & TYMED_HGLOBAL) == 0
|
|
|
|
) {
|
|
|
|
//Platform::DebugPrintf("DOB QueryGetData No %x\n",pFE->cfFormat);
|
|
|
|
//return DATA_E_FORMATETC;
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
//Platform::DebugPrintf("DOB QueryGetData OK %x\n",pFE->cfFormat);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP DataObject_GetCanonicalFormatEtc(DataObject *pd, FORMATETC *, FORMATETC *pFEOut) {
|
|
|
|
//Platform::DebugPrintf("DOB GetCanon\n");
|
|
|
|
if (pd->sci->IsUnicodeMode())
|
|
|
|
pFEOut->cfFormat = CF_UNICODETEXT;
|
|
|
|
else
|
|
|
|
pFEOut->cfFormat = CF_TEXT;
|
2019-07-21 13:26:02 +00:00
|
|
|
pFEOut->ptd = nullptr;
|
2009-04-24 23:35:41 +00:00
|
|
|
pFEOut->dwAspect = DVASPECT_CONTENT;
|
|
|
|
pFEOut->lindex = -1;
|
|
|
|
pFEOut->tymed = TYMED_HGLOBAL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP DataObject_SetData(DataObject *, FORMATETC *, STGMEDIUM *, BOOL) {
|
|
|
|
//Platform::DebugPrintf("DOB SetData\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP DataObject_EnumFormatEtc(DataObject *pd, DWORD dwDirection, IEnumFORMATETC **ppEnum) {
|
2009-08-23 02:24:48 +00:00
|
|
|
try {
|
|
|
|
//Platform::DebugPrintf("DOB EnumFormatEtc %d\n", dwDirection);
|
|
|
|
if (dwDirection != DATADIR_GET) {
|
2019-07-21 13:26:02 +00:00
|
|
|
*ppEnum = nullptr;
|
2009-08-23 02:24:48 +00:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
FormatEnumerator *pfe;
|
|
|
|
if (pd->sci->IsUnicodeMode()) {
|
|
|
|
CLIPFORMAT formats[] = {CF_UNICODETEXT, CF_TEXT};
|
2019-05-04 18:14:48 +00:00
|
|
|
pfe = new FormatEnumerator(0, formats, std::size(formats));
|
2009-08-23 02:24:48 +00:00
|
|
|
} else {
|
|
|
|
CLIPFORMAT formats[] = {CF_TEXT};
|
2019-05-04 18:14:48 +00:00
|
|
|
pfe = new FormatEnumerator(0, formats, std::size(formats));
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
|
|
|
return FormatEnumerator_QueryInterface(pfe, IID_IEnumFORMATETC,
|
|
|
|
reinterpret_cast<void **>(ppEnum));
|
2010-07-12 22:19:51 +00:00
|
|
|
} catch (std::bad_alloc &) {
|
2009-08-23 02:24:48 +00:00
|
|
|
pd->sci->errorStatus = SC_STATUS_BADALLOC;
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
} catch (...) {
|
|
|
|
pd->sci->errorStatus = SC_STATUS_FAILURE;
|
2009-04-24 23:35:41 +00:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP DataObject_DAdvise(DataObject *, FORMATETC *, DWORD, IAdviseSink *, PDWORD) {
|
|
|
|
//Platform::DebugPrintf("DOB DAdvise\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP DataObject_DUnadvise(DataObject *, DWORD) {
|
|
|
|
//Platform::DebugPrintf("DOB DUnadvise\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP DataObject_EnumDAdvise(DataObject *, IEnumSTATDATA **) {
|
|
|
|
//Platform::DebugPrintf("DOB EnumDAdvise\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2010-07-12 22:19:51 +00:00
|
|
|
static VFunction *vtDataObject[] = {
|
|
|
|
(VFunction *)(DataObject_QueryInterface),
|
|
|
|
(VFunction *)(DataObject_AddRef),
|
|
|
|
(VFunction *)(DataObject_Release),
|
|
|
|
(VFunction *)(DataObject_GetData),
|
|
|
|
(VFunction *)(DataObject_GetDataHere),
|
|
|
|
(VFunction *)(DataObject_QueryGetData),
|
|
|
|
(VFunction *)(DataObject_GetCanonicalFormatEtc),
|
|
|
|
(VFunction *)(DataObject_SetData),
|
|
|
|
(VFunction *)(DataObject_EnumFormatEtc),
|
|
|
|
(VFunction *)(DataObject_DAdvise),
|
|
|
|
(VFunction *)(DataObject_DUnadvise),
|
|
|
|
(VFunction *)(DataObject_EnumDAdvise)
|
2009-04-24 23:35:41 +00:00
|
|
|
};
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
DataObject::DataObject() noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
vtbl = vtDataObject;
|
2019-05-04 18:14:48 +00:00
|
|
|
sci = nullptr;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Implement IUnknown
|
|
|
|
STDMETHODIMP DropTarget_QueryInterface(DropTarget *dt, REFIID riid, PVOID *ppv) {
|
|
|
|
//Platform::DebugPrintf("DT QI %x\n", dt);
|
|
|
|
return dt->sci->QueryInterface(riid, ppv);
|
|
|
|
}
|
|
|
|
STDMETHODIMP_(ULONG)DropTarget_AddRef(DropTarget *dt) {
|
|
|
|
return dt->sci->AddRef();
|
|
|
|
}
|
|
|
|
STDMETHODIMP_(ULONG)DropTarget_Release(DropTarget *dt) {
|
|
|
|
return dt->sci->Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Implement IDropTarget by forwarding to Scintilla
|
|
|
|
STDMETHODIMP DropTarget_DragEnter(DropTarget *dt, LPDATAOBJECT pIDataSource, DWORD grfKeyState,
|
|
|
|
POINTL pt, PDWORD pdwEffect) {
|
2009-08-23 02:24:48 +00:00
|
|
|
try {
|
|
|
|
return dt->sci->DragEnter(pIDataSource, grfKeyState, pt, pdwEffect);
|
|
|
|
} catch (...) {
|
|
|
|
dt->sci->errorStatus = SC_STATUS_FAILURE;
|
|
|
|
}
|
|
|
|
return E_FAIL;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
STDMETHODIMP DropTarget_DragOver(DropTarget *dt, DWORD grfKeyState, POINTL pt, PDWORD pdwEffect) {
|
2009-08-23 02:24:48 +00:00
|
|
|
try {
|
|
|
|
return dt->sci->DragOver(grfKeyState, pt, pdwEffect);
|
|
|
|
} catch (...) {
|
|
|
|
dt->sci->errorStatus = SC_STATUS_FAILURE;
|
|
|
|
}
|
|
|
|
return E_FAIL;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
STDMETHODIMP DropTarget_DragLeave(DropTarget *dt) {
|
2009-08-23 02:24:48 +00:00
|
|
|
try {
|
|
|
|
return dt->sci->DragLeave();
|
|
|
|
} catch (...) {
|
|
|
|
dt->sci->errorStatus = SC_STATUS_FAILURE;
|
|
|
|
}
|
|
|
|
return E_FAIL;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
STDMETHODIMP DropTarget_Drop(DropTarget *dt, LPDATAOBJECT pIDataSource, DWORD grfKeyState,
|
|
|
|
POINTL pt, PDWORD pdwEffect) {
|
2009-08-23 02:24:48 +00:00
|
|
|
try {
|
|
|
|
return dt->sci->Drop(pIDataSource, grfKeyState, pt, pdwEffect);
|
|
|
|
} catch (...) {
|
|
|
|
dt->sci->errorStatus = SC_STATUS_FAILURE;
|
|
|
|
}
|
|
|
|
return E_FAIL;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 22:19:51 +00:00
|
|
|
static VFunction *vtDropTarget[] = {
|
|
|
|
(VFunction *)(DropTarget_QueryInterface),
|
|
|
|
(VFunction *)(DropTarget_AddRef),
|
|
|
|
(VFunction *)(DropTarget_Release),
|
|
|
|
(VFunction *)(DropTarget_DragEnter),
|
|
|
|
(VFunction *)(DropTarget_DragOver),
|
|
|
|
(VFunction *)(DropTarget_DragLeave),
|
|
|
|
(VFunction *)(DropTarget_Drop)
|
2009-04-24 23:35:41 +00:00
|
|
|
};
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
DropTarget::DropTarget() noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
vtbl = vtDropTarget;
|
2019-05-04 18:14:48 +00:00
|
|
|
sci = nullptr;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DBCS: support Input Method Editor (IME).
|
|
|
|
* Called when IME Window opened.
|
|
|
|
*/
|
|
|
|
void ScintillaWin::ImeStartComposition() {
|
|
|
|
if (caret.active) {
|
|
|
|
// Move IME Window to current caret position
|
2019-05-04 18:14:48 +00:00
|
|
|
IMContext imc(MainHWND());
|
|
|
|
const Point pos = PointMainCaret();
|
2009-04-24 23:35:41 +00:00
|
|
|
COMPOSITIONFORM CompForm;
|
|
|
|
CompForm.dwStyle = CFS_POINT;
|
2019-05-04 18:14:48 +00:00
|
|
|
CompForm.ptCurrentPos = POINTFromPoint(pos);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
::ImmSetCompositionWindow(imc.hIMC, &CompForm);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
// Set font of IME window to same as surrounded text.
|
|
|
|
if (stylesValid) {
|
|
|
|
// Since the style creation code has been made platform independent,
|
|
|
|
// The logfont for the IME is recreated here.
|
2019-05-04 18:14:48 +00:00
|
|
|
const int styleHere = pdoc->StyleIndexAt(sel.MainCaret());
|
2015-06-07 21:19:26 +00:00
|
|
|
LOGFONTW lf = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L""};
|
2013-08-28 00:44:27 +00:00
|
|
|
int sizeZoomed = vs.styles[styleHere].size + vs.zoomLevel * SC_FONT_SIZE_MULTIPLIER;
|
|
|
|
if (sizeZoomed <= 2 * SC_FONT_SIZE_MULTIPLIER) // Hangs if sizeZoomed <= 1
|
|
|
|
sizeZoomed = 2 * SC_FONT_SIZE_MULTIPLIER;
|
2009-04-24 23:35:41 +00:00
|
|
|
AutoSurface surface(this);
|
|
|
|
int deviceHeight = sizeZoomed;
|
|
|
|
if (surface) {
|
|
|
|
deviceHeight = (sizeZoomed * surface->LogPixelsY()) / 72;
|
|
|
|
}
|
|
|
|
// The negative is to allow for leading
|
2019-07-21 13:26:02 +00:00
|
|
|
lf.lfHeight = -(std::abs(deviceHeight / SC_FONT_SIZE_MULTIPLIER));
|
2013-08-28 00:44:27 +00:00
|
|
|
lf.lfWeight = vs.styles[styleHere].weight;
|
2009-04-24 23:35:41 +00:00
|
|
|
lf.lfItalic = static_cast<BYTE>(vs.styles[styleHere].italic ? 1 : 0);
|
|
|
|
lf.lfCharSet = DEFAULT_CHARSET;
|
2015-06-07 21:19:26 +00:00
|
|
|
lf.lfFaceName[0] = L'\0';
|
|
|
|
if (vs.styles[styleHere].fontName) {
|
|
|
|
const char* fontName = vs.styles[styleHere].fontName;
|
2019-05-04 18:14:48 +00:00
|
|
|
UTF16FromUTF8(std::string_view(fontName), lf.lfFaceName, LF_FACESIZE);
|
2015-06-07 21:19:26 +00:00
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
::ImmSetCompositionFontW(imc.hIMC, &lf);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
// Caret is displayed in IME window. So, caret in Scintilla is useless.
|
|
|
|
DropCaret();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Called when IME Window closed. */
|
|
|
|
void ScintillaWin::ImeEndComposition() {
|
|
|
|
ShowCaretAtCurrentPosition();
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
LRESULT ScintillaWin::ImeOnReconvert(LPARAM lParam) {
|
|
|
|
// Reconversion on windows limits within one line without eol.
|
|
|
|
// Look around: baseStart <-- (|mainStart| -- mainEnd) --> baseEnd.
|
|
|
|
const Sci::Position mainStart = sel.RangeMain().Start().Position();
|
|
|
|
const Sci::Position mainEnd = sel.RangeMain().End().Position();
|
|
|
|
const Sci::Line curLine = pdoc->SciLineFromPosition(mainStart);
|
|
|
|
if (curLine != pdoc->LineFromPosition(mainEnd))
|
|
|
|
return 0;
|
|
|
|
const Sci::Position baseStart = pdoc->LineStart(curLine);
|
|
|
|
const Sci::Position baseEnd = pdoc->LineEnd(curLine);
|
|
|
|
if ((baseStart == baseEnd) || (mainEnd > baseEnd))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const int codePage = CodePageOfDocument();
|
|
|
|
const std::wstring rcFeed = StringDecode(RangeText(baseStart, baseEnd), codePage);
|
|
|
|
const int rcFeedLen = static_cast<int>(rcFeed.length()) * sizeof(wchar_t);
|
|
|
|
const int rcSize = sizeof(RECONVERTSTRING) + rcFeedLen + sizeof(wchar_t);
|
|
|
|
|
|
|
|
RECONVERTSTRING *rc = static_cast<RECONVERTSTRING *>(PtrFromSPtr(lParam));
|
|
|
|
if (!rc)
|
|
|
|
return rcSize; // Immediately be back with rcSize of memory block.
|
|
|
|
|
|
|
|
wchar_t *rcFeedStart = reinterpret_cast<wchar_t*>(rc + 1);
|
|
|
|
memcpy(rcFeedStart, &rcFeed[0], rcFeedLen);
|
|
|
|
|
|
|
|
std::string rcCompString = RangeText(mainStart, mainEnd);
|
|
|
|
std::wstring rcCompWstring = StringDecode(rcCompString, codePage);
|
|
|
|
std::string rcCompStart = RangeText(baseStart, mainStart);
|
|
|
|
std::wstring rcCompWstart = StringDecode(rcCompStart, codePage);
|
|
|
|
|
|
|
|
// Map selection to dwCompStr.
|
|
|
|
// No selection assumes current caret as rcCompString without length.
|
|
|
|
rc->dwVersion = 0; // It should be absolutely 0.
|
|
|
|
rc->dwStrLen = static_cast<DWORD>(rcFeed.length());
|
|
|
|
rc->dwStrOffset = sizeof(RECONVERTSTRING);
|
|
|
|
rc->dwCompStrLen = static_cast<DWORD>(rcCompWstring.length());
|
|
|
|
rc->dwCompStrOffset = static_cast<DWORD>(rcCompWstart.length()) * sizeof(wchar_t);
|
|
|
|
rc->dwTargetStrLen = rc->dwCompStrLen;
|
|
|
|
rc->dwTargetStrOffset =rc->dwCompStrOffset;
|
|
|
|
|
|
|
|
IMContext imc(MainHWND());
|
|
|
|
if (!imc.hIMC)
|
|
|
|
return 0;
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
if (!::ImmSetCompositionStringW(imc.hIMC, SCS_QUERYRECONVERTSTRING, rc, rcSize, nullptr, 0))
|
2019-05-04 18:14:48 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
// No selection asks IME to fill target fields with its own value.
|
|
|
|
const int tgWlen = rc->dwTargetStrLen;
|
|
|
|
const int tgWstart = rc->dwTargetStrOffset / sizeof(wchar_t);
|
|
|
|
|
|
|
|
std::string tgCompStart = StringEncode(rcFeed.substr(0, tgWstart), codePage);
|
|
|
|
std::string tgComp = StringEncode(rcFeed.substr(tgWstart, tgWlen), codePage);
|
|
|
|
|
|
|
|
// No selection needs to adjust reconvert start position for IME set.
|
|
|
|
const int adjust = static_cast<int>(tgCompStart.length() - rcCompStart.length());
|
|
|
|
const int docCompLen = static_cast<int>(tgComp.length());
|
|
|
|
|
|
|
|
// Make place for next composition string to sit in.
|
|
|
|
for (size_t r=0; r<sel.Count(); r++) {
|
|
|
|
const Sci::Position rBase = sel.Range(r).Start().Position();
|
|
|
|
const Sci::Position docCompStart = rBase + adjust;
|
|
|
|
|
|
|
|
if (inOverstrike) { // the docCompLen of bytes will be overstriked.
|
|
|
|
sel.Range(r).caret.SetPosition(docCompStart);
|
|
|
|
sel.Range(r).anchor.SetPosition(docCompStart);
|
|
|
|
} else {
|
|
|
|
// Ensure docCompStart+docCompLen be not beyond lineEnd.
|
|
|
|
// since docCompLen by byte might break eol.
|
|
|
|
const Sci::Position lineEnd = pdoc->LineEnd(pdoc->LineFromPosition(rBase));
|
|
|
|
const Sci::Position overflow = (docCompStart + docCompLen) - lineEnd;
|
|
|
|
if (overflow > 0) {
|
|
|
|
pdoc->DeleteChars(docCompStart, docCompLen - overflow);
|
|
|
|
} else {
|
|
|
|
pdoc->DeleteChars(docCompStart, docCompLen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Immediately Target Input or candidate box choice with GCS_COMPSTR.
|
|
|
|
return rcSize;
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
void ScintillaWin::GetIntelliMouseParameters() noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
// This retrieves the number of lines per scroll as configured inthe Mouse Properties sheet in Control Panel
|
|
|
|
::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &linesPerScroll, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::CopyToClipboard(const SelectionText &selectedText) {
|
2019-05-04 18:14:48 +00:00
|
|
|
if (!::OpenClipboardRetry(MainHWND())) {
|
2010-08-21 23:59:56 +00:00
|
|
|
return;
|
2019-05-04 18:14:48 +00:00
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
::EmptyClipboard();
|
|
|
|
|
|
|
|
GlobalMemory uniText;
|
|
|
|
|
|
|
|
// Default Scintilla behaviour in Unicode mode
|
|
|
|
if (IsUnicodeMode()) {
|
2019-05-04 18:14:48 +00:00
|
|
|
const std::string_view sv(selectedText.Data(), selectedText.LengthWithTerminator());
|
|
|
|
const size_t uchars = UTF16Length(sv);
|
2009-04-24 23:35:41 +00:00
|
|
|
uniText.Allocate(2 * uchars);
|
|
|
|
if (uniText) {
|
2019-05-04 18:14:48 +00:00
|
|
|
UTF16FromUTF8(sv,
|
2013-08-28 00:44:27 +00:00
|
|
|
static_cast<wchar_t *>(uniText.ptr), uchars);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Not Unicode mode
|
|
|
|
// Convert to Unicode using the current Scintilla code page
|
2019-05-04 18:14:48 +00:00
|
|
|
const UINT cpSrc = CodePageFromCharSet(
|
2009-04-24 23:35:41 +00:00
|
|
|
selectedText.characterSet, selectedText.codePage);
|
2019-05-04 18:14:48 +00:00
|
|
|
const std::string_view svSelected(selectedText.Data(), selectedText.LengthWithTerminator());
|
2019-07-21 13:26:02 +00:00
|
|
|
const size_t uLen = WideCharLenFromMultiByte(cpSrc, svSelected);
|
2010-07-12 22:19:51 +00:00
|
|
|
uniText.Allocate(2 * uLen);
|
2009-04-24 23:35:41 +00:00
|
|
|
if (uniText) {
|
2019-05-04 18:14:48 +00:00
|
|
|
WideCharFromMultiByte(cpSrc, svSelected,
|
2010-07-12 22:19:51 +00:00
|
|
|
static_cast<wchar_t *>(uniText.ptr), uLen);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uniText) {
|
|
|
|
uniText.SetClip(CF_UNICODETEXT);
|
|
|
|
} else {
|
|
|
|
// There was a failure - try to copy at least ANSI text
|
|
|
|
GlobalMemory ansiText;
|
2013-08-28 00:44:27 +00:00
|
|
|
ansiText.Allocate(selectedText.LengthWithTerminator());
|
2009-04-24 23:35:41 +00:00
|
|
|
if (ansiText) {
|
2019-05-04 18:14:48 +00:00
|
|
|
memcpy(ansiText.ptr, selectedText.Data(), selectedText.LengthWithTerminator());
|
2009-04-24 23:35:41 +00:00
|
|
|
ansiText.SetClip(CF_TEXT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectedText.rectangular) {
|
|
|
|
::SetClipboardData(cfColumnSelect, 0);
|
2015-06-07 21:19:26 +00:00
|
|
|
|
|
|
|
GlobalMemory borlandSelection;
|
|
|
|
borlandSelection.Allocate(1);
|
|
|
|
if (borlandSelection) {
|
|
|
|
static_cast<BYTE *>(borlandSelection.ptr)[0] = 0x02;
|
|
|
|
borlandSelection.SetClip(cfBorlandIDEBlockType);
|
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (selectedText.lineCopy) {
|
|
|
|
::SetClipboardData(cfLineSelect, 0);
|
2015-06-07 21:19:26 +00:00
|
|
|
::SetClipboardData(cfVSLineTag, 0);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
::CloseClipboard();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::ScrollMessage(WPARAM wParam) {
|
|
|
|
//DWORD dwStart = timeGetTime();
|
|
|
|
//Platform::DebugPrintf("Scroll %x %d\n", wParam, lParam);
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
SCROLLINFO sci = {};
|
2009-04-24 23:35:41 +00:00
|
|
|
sci.cbSize = sizeof(sci);
|
|
|
|
sci.fMask = SIF_ALL;
|
|
|
|
|
|
|
|
GetScrollInfo(SB_VERT, &sci);
|
|
|
|
|
|
|
|
//Platform::DebugPrintf("ScrollInfo %d mask=%x min=%d max=%d page=%d pos=%d track=%d\n", b,sci.fMask,
|
|
|
|
//sci.nMin, sci.nMax, sci.nPage, sci.nPos, sci.nTrackPos);
|
2019-05-04 18:14:48 +00:00
|
|
|
Sci::Line topLineNew = topLine;
|
|
|
|
switch (LOWORD(wParam)) {
|
2009-04-24 23:35:41 +00:00
|
|
|
case SB_LINEUP:
|
|
|
|
topLineNew -= 1;
|
|
|
|
break;
|
|
|
|
case SB_LINEDOWN:
|
|
|
|
topLineNew += 1;
|
|
|
|
break;
|
|
|
|
case SB_PAGEUP:
|
|
|
|
topLineNew -= LinesToScroll(); break;
|
|
|
|
case SB_PAGEDOWN: topLineNew += LinesToScroll(); break;
|
|
|
|
case SB_TOP: topLineNew = 0; break;
|
|
|
|
case SB_BOTTOM: topLineNew = MaxScrollPos(); break;
|
|
|
|
case SB_THUMBPOSITION: topLineNew = sci.nTrackPos; break;
|
|
|
|
case SB_THUMBTRACK: topLineNew = sci.nTrackPos; break;
|
|
|
|
}
|
|
|
|
ScrollTo(topLineNew);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaWin::HorizontalScrollMessage(WPARAM wParam) {
|
|
|
|
int xPos = xOffset;
|
2019-05-04 18:14:48 +00:00
|
|
|
const PRectangle rcText = GetTextRectangle();
|
|
|
|
const int pageWidth = static_cast<int>(rcText.Width() * 2 / 3);
|
|
|
|
switch (LOWORD(wParam)) {
|
2009-04-24 23:35:41 +00:00
|
|
|
case SB_LINEUP:
|
|
|
|
xPos -= 20;
|
|
|
|
break;
|
|
|
|
case SB_LINEDOWN: // May move past the logical end
|
|
|
|
xPos += 20;
|
|
|
|
break;
|
|
|
|
case SB_PAGEUP:
|
|
|
|
xPos -= pageWidth;
|
|
|
|
break;
|
|
|
|
case SB_PAGEDOWN:
|
|
|
|
xPos += pageWidth;
|
|
|
|
if (xPos > scrollWidth - rcText.Width()) { // Hit the end exactly
|
2015-06-07 21:19:26 +00:00
|
|
|
xPos = scrollWidth - static_cast<int>(rcText.Width());
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SB_TOP:
|
|
|
|
xPos = 0;
|
|
|
|
break;
|
|
|
|
case SB_BOTTOM:
|
|
|
|
xPos = scrollWidth;
|
|
|
|
break;
|
|
|
|
case SB_THUMBPOSITION:
|
|
|
|
case SB_THUMBTRACK: {
|
|
|
|
// Do NOT use wParam, its 16 bit and not enough for very long lines. Its still possible to overflow the 32 bit but you have to try harder =]
|
|
|
|
SCROLLINFO si;
|
|
|
|
si.cbSize = sizeof(si);
|
|
|
|
si.fMask = SIF_TRACKPOS;
|
|
|
|
if (GetScrollInfo(SB_HORZ, &si)) {
|
|
|
|
xPos = si.nTrackPos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
HorizontalScrollTo(xPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redraw all of text area.
|
|
|
|
* This paint will not be abandoned.
|
|
|
|
*/
|
|
|
|
void ScintillaWin::FullPaint() {
|
2015-06-07 21:19:26 +00:00
|
|
|
if ((technology == SC_TECHNOLOGY_DEFAULT) || (technology == SC_TECHNOLOGY_DIRECTWRITEDC)) {
|
2013-08-28 00:44:27 +00:00
|
|
|
HDC hdc = ::GetDC(MainHWND());
|
|
|
|
FullPaintDC(hdc);
|
|
|
|
::ReleaseDC(MainHWND(), hdc);
|
|
|
|
} else {
|
|
|
|
FullPaintDC(0);
|
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redraw all of text area on the specified DC.
|
|
|
|
* This paint will not be abandoned.
|
|
|
|
*/
|
|
|
|
void ScintillaWin::FullPaintDC(HDC hdc) {
|
|
|
|
paintState = painting;
|
|
|
|
rcPaint = GetClientRectangle();
|
|
|
|
paintingAllText = true;
|
2013-08-28 00:44:27 +00:00
|
|
|
if (technology == SC_TECHNOLOGY_DEFAULT) {
|
|
|
|
AutoSurface surfaceWindow(hdc, this);
|
|
|
|
if (surfaceWindow) {
|
|
|
|
Paint(surfaceWindow, rcPaint);
|
|
|
|
surfaceWindow->Release();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
#if defined(USE_D2D)
|
2015-06-07 21:19:26 +00:00
|
|
|
EnsureRenderTarget(hdc);
|
2013-08-28 00:44:27 +00:00
|
|
|
AutoSurface surfaceWindow(pRenderTarget, this);
|
|
|
|
if (surfaceWindow) {
|
|
|
|
pRenderTarget->BeginDraw();
|
|
|
|
Paint(surfaceWindow, rcPaint);
|
|
|
|
surfaceWindow->Release();
|
2019-05-04 18:14:48 +00:00
|
|
|
const HRESULT hr = pRenderTarget->EndDraw();
|
|
|
|
if (hr == static_cast<HRESULT>(D2DERR_RECREATE_TARGET)) {
|
2013-08-28 00:44:27 +00:00
|
|
|
DropRenderTarget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
paintState = notPainting;
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
namespace {
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
bool CompareDevCap(HDC hdc, HDC hOtherDC, int nIndex) noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
return ::GetDeviceCaps(hdc, nIndex) == ::GetDeviceCaps(hOtherDC, nIndex);
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
bool ScintillaWin::IsCompatibleDC(HDC hOtherDC) noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
HDC hdc = ::GetDC(MainHWND());
|
2019-05-04 18:14:48 +00:00
|
|
|
const bool isCompatible =
|
2009-04-24 23:35:41 +00:00
|
|
|
CompareDevCap(hdc, hOtherDC, TECHNOLOGY) &&
|
|
|
|
CompareDevCap(hdc, hOtherDC, LOGPIXELSY) &&
|
|
|
|
CompareDevCap(hdc, hOtherDC, LOGPIXELSX) &&
|
|
|
|
CompareDevCap(hdc, hOtherDC, BITSPIXEL) &&
|
|
|
|
CompareDevCap(hdc, hOtherDC, PLANES);
|
|
|
|
::ReleaseDC(MainHWND(), hdc);
|
|
|
|
return isCompatible;
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
DWORD ScintillaWin::EffectFromState(DWORD grfKeyState) const noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
// These are the Wordpad semantics.
|
|
|
|
DWORD dwEffect;
|
|
|
|
if (inDragDrop == ddDragging) // Internal defaults to move
|
|
|
|
dwEffect = DROPEFFECT_MOVE;
|
|
|
|
else
|
|
|
|
dwEffect = DROPEFFECT_COPY;
|
|
|
|
if (grfKeyState & MK_ALT)
|
|
|
|
dwEffect = DROPEFFECT_MOVE;
|
|
|
|
if (grfKeyState & MK_CONTROL)
|
|
|
|
dwEffect = DROPEFFECT_COPY;
|
|
|
|
return dwEffect;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Implement IUnknown
|
|
|
|
STDMETHODIMP ScintillaWin::QueryInterface(REFIID riid, PVOID *ppv) {
|
2019-05-04 18:14:48 +00:00
|
|
|
*ppv = nullptr;
|
2009-04-24 23:35:41 +00:00
|
|
|
if (riid == IID_IUnknown)
|
|
|
|
*ppv = reinterpret_cast<IDropTarget *>(&dt);
|
|
|
|
if (riid == IID_IDropSource)
|
|
|
|
*ppv = reinterpret_cast<IDropSource *>(&ds);
|
|
|
|
if (riid == IID_IDropTarget)
|
|
|
|
*ppv = reinterpret_cast<IDropTarget *>(&dt);
|
|
|
|
if (riid == IID_IDataObject)
|
|
|
|
*ppv = reinterpret_cast<IDataObject *>(&dob);
|
|
|
|
if (!*ppv)
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP_(ULONG) ScintillaWin::AddRef() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP_(ULONG) ScintillaWin::Release() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Implement IDropTarget
|
|
|
|
STDMETHODIMP ScintillaWin::DragEnter(LPDATAOBJECT pIDataSource, DWORD grfKeyState,
|
|
|
|
POINTL, PDWORD pdwEffect) {
|
2019-05-04 18:14:48 +00:00
|
|
|
if (!pIDataSource )
|
2009-04-24 23:35:41 +00:00
|
|
|
return E_POINTER;
|
2019-05-04 18:14:48 +00:00
|
|
|
FORMATETC fmtu = {CF_UNICODETEXT, nullptr, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
|
|
|
|
const HRESULT hrHasUText = pIDataSource->QueryGetData(&fmtu);
|
2009-04-24 23:35:41 +00:00
|
|
|
hasOKText = (hrHasUText == S_OK);
|
|
|
|
if (!hasOKText) {
|
2019-05-04 18:14:48 +00:00
|
|
|
FORMATETC fmte = {CF_TEXT, nullptr, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
|
|
|
|
const HRESULT hrHasText = pIDataSource->QueryGetData(&fmte);
|
2009-04-24 23:35:41 +00:00
|
|
|
hasOKText = (hrHasText == S_OK);
|
|
|
|
}
|
|
|
|
if (!hasOKText) {
|
|
|
|
*pdwEffect = DROPEFFECT_NONE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pdwEffect = EffectFromState(grfKeyState);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP ScintillaWin::DragOver(DWORD grfKeyState, POINTL pt, PDWORD pdwEffect) {
|
2009-08-23 02:24:48 +00:00
|
|
|
try {
|
|
|
|
if (!hasOKText || pdoc->IsReadOnly()) {
|
|
|
|
*pdwEffect = DROPEFFECT_NONE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
*pdwEffect = EffectFromState(grfKeyState);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
// Update the cursor.
|
|
|
|
POINT rpt = {pt.x, pt.y};
|
|
|
|
::ScreenToClient(MainHWND(), &rpt);
|
2015-06-07 21:19:26 +00:00
|
|
|
SetDragPosition(SPositionFromLocation(PointFromPOINT(rpt), false, false, UserVirtualSpace()));
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
return S_OK;
|
|
|
|
} catch (...) {
|
|
|
|
errorStatus = SC_STATUS_FAILURE;
|
|
|
|
}
|
|
|
|
return E_FAIL;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP ScintillaWin::DragLeave() {
|
2009-08-23 02:24:48 +00:00
|
|
|
try {
|
2019-05-04 18:14:48 +00:00
|
|
|
SetDragPosition(SelectionPosition(Sci::invalidPosition));
|
2009-08-23 02:24:48 +00:00
|
|
|
return S_OK;
|
|
|
|
} catch (...) {
|
|
|
|
errorStatus = SC_STATUS_FAILURE;
|
|
|
|
}
|
|
|
|
return E_FAIL;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP ScintillaWin::Drop(LPDATAOBJECT pIDataSource, DWORD grfKeyState,
|
|
|
|
POINTL pt, PDWORD pdwEffect) {
|
2009-08-23 02:24:48 +00:00
|
|
|
try {
|
|
|
|
*pdwEffect = EffectFromState(grfKeyState);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
if (!pIDataSource)
|
2009-08-23 02:24:48 +00:00
|
|
|
return E_POINTER;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
SetDragPosition(SelectionPosition(Sci::invalidPosition));
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
STGMEDIUM medium {};
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
std::vector<char> data; // Includes terminating NUL
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
FORMATETC fmtu = {CF_UNICODETEXT, nullptr, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
|
2009-08-23 02:24:48 +00:00
|
|
|
HRESULT hr = pIDataSource->GetData(&fmtu, &medium);
|
|
|
|
if (SUCCEEDED(hr) && medium.hGlobal) {
|
2013-08-28 00:44:27 +00:00
|
|
|
GlobalMemory memUDrop(medium.hGlobal);
|
2019-05-04 18:14:48 +00:00
|
|
|
const wchar_t *udata = static_cast<const wchar_t *>(memUDrop.ptr);
|
2013-08-28 00:44:27 +00:00
|
|
|
if (udata) {
|
|
|
|
if (IsUnicodeMode()) {
|
2019-05-04 18:14:48 +00:00
|
|
|
const size_t tlen = memUDrop.Size();
|
2013-08-28 00:44:27 +00:00
|
|
|
// Convert UTF-16 to UTF-8
|
2019-05-04 18:14:48 +00:00
|
|
|
const std::wstring_view wsv(udata, tlen / 2);
|
|
|
|
const size_t dataLen = UTF8Length(wsv);
|
|
|
|
data.resize(dataLen);
|
|
|
|
UTF8FromUTF16(wsv, &data[0], dataLen);
|
2013-08-28 00:44:27 +00:00
|
|
|
} else {
|
|
|
|
// Convert UTF-16 to ANSI
|
|
|
|
//
|
|
|
|
// Default Scintilla behavior in Unicode mode
|
|
|
|
// CF_UNICODETEXT available, but not in Unicode mode
|
|
|
|
// Convert from Unicode to current Scintilla code page
|
2019-05-04 18:14:48 +00:00
|
|
|
const UINT cpDest = CodePageOfDocument();
|
|
|
|
const int tlen = MultiByteLenFromWideChar(cpDest, udata);
|
|
|
|
data.resize(tlen);
|
|
|
|
MultiByteFromWideChar(cpDest, udata, &data[0], tlen);
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
memUDrop.Unlock();
|
|
|
|
} else {
|
2019-05-04 18:14:48 +00:00
|
|
|
FORMATETC fmte = {CF_TEXT, nullptr, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
|
2009-08-23 02:24:48 +00:00
|
|
|
hr = pIDataSource->GetData(&fmte, &medium);
|
|
|
|
if (SUCCEEDED(hr) && medium.hGlobal) {
|
2013-08-28 00:44:27 +00:00
|
|
|
GlobalMemory memDrop(medium.hGlobal);
|
2019-05-04 18:14:48 +00:00
|
|
|
const char *cdata = static_cast<const char *>(memDrop.ptr);
|
2013-08-28 00:44:27 +00:00
|
|
|
if (cdata)
|
2019-05-04 18:14:48 +00:00
|
|
|
data.assign(cdata, cdata+strlen(cdata));
|
2013-08-28 00:44:27 +00:00
|
|
|
memDrop.Unlock();
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
if (!SUCCEEDED(hr) || data.empty()) {
|
2009-08-23 02:24:48 +00:00
|
|
|
//Platform::DebugPrintf("Bad data format: 0x%x\n", hres);
|
|
|
|
return hr;
|
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
FORMATETC fmtr = {cfColumnSelect, nullptr, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
|
|
|
|
const HRESULT hrRectangular = pIDataSource->QueryGetData(&fmtr);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
POINT rpt = {pt.x, pt.y};
|
|
|
|
::ScreenToClient(MainHWND(), &rpt);
|
2019-05-04 18:14:48 +00:00
|
|
|
const SelectionPosition movePos = SPositionFromLocation(PointFromPOINT(rpt), false, false, UserVirtualSpace());
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
DropAt(movePos, &data[0], data.size(), *pdwEffect == DROPEFFECT_MOVE, hrRectangular == S_OK);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
// Free data
|
2019-05-04 18:14:48 +00:00
|
|
|
if (medium.pUnkForRelease)
|
2009-08-23 02:24:48 +00:00
|
|
|
medium.pUnkForRelease->Release();
|
|
|
|
else
|
|
|
|
::GlobalFree(medium.hGlobal);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
return S_OK;
|
|
|
|
} catch (...) {
|
|
|
|
errorStatus = SC_STATUS_FAILURE;
|
|
|
|
}
|
|
|
|
return E_FAIL;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Implement important part of IDataObject
|
|
|
|
STDMETHODIMP ScintillaWin::GetData(FORMATETC *pFEIn, STGMEDIUM *pSTM) {
|
2019-05-04 18:14:48 +00:00
|
|
|
const bool formatOK = (pFEIn->cfFormat == CF_TEXT) ||
|
2009-04-24 23:35:41 +00:00
|
|
|
((pFEIn->cfFormat == CF_UNICODETEXT) && IsUnicodeMode());
|
|
|
|
if (!formatOK ||
|
2019-07-21 13:26:02 +00:00
|
|
|
pFEIn->ptd != nullptr ||
|
2009-04-24 23:35:41 +00:00
|
|
|
(pFEIn->dwAspect & DVASPECT_CONTENT) == 0 ||
|
|
|
|
pFEIn->lindex != -1 ||
|
|
|
|
(pFEIn->tymed & TYMED_HGLOBAL) == 0
|
|
|
|
) {
|
|
|
|
//Platform::DebugPrintf("DOB GetData No %d %x %x fmt=%x\n", lenDrag, pFEIn, pSTM, pFEIn->cfFormat);
|
|
|
|
return DATA_E_FORMATETC;
|
|
|
|
}
|
|
|
|
pSTM->tymed = TYMED_HGLOBAL;
|
|
|
|
//Platform::DebugPrintf("DOB GetData OK %d %x %x\n", lenDrag, pFEIn, pSTM);
|
|
|
|
|
|
|
|
GlobalMemory text;
|
|
|
|
if (pFEIn->cfFormat == CF_UNICODETEXT) {
|
2019-05-04 18:14:48 +00:00
|
|
|
const std::string_view sv(drag.Data(), drag.LengthWithTerminator());
|
|
|
|
const size_t uchars = UTF16Length(sv);
|
2009-04-24 23:35:41 +00:00
|
|
|
text.Allocate(2 * uchars);
|
|
|
|
if (text) {
|
2019-05-04 18:14:48 +00:00
|
|
|
UTF16FromUTF8(sv,
|
2013-08-28 00:44:27 +00:00
|
|
|
static_cast<wchar_t *>(text.ptr), uchars);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
} else {
|
2013-08-28 00:44:27 +00:00
|
|
|
text.Allocate(drag.LengthWithTerminator());
|
2009-04-24 23:35:41 +00:00
|
|
|
if (text) {
|
2019-05-04 18:14:48 +00:00
|
|
|
memcpy(text.ptr, drag.Data(), drag.LengthWithTerminator());
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pSTM->hGlobal = text ? text.Unlock() : 0;
|
2019-07-21 13:26:02 +00:00
|
|
|
pSTM->pUnkForRelease = nullptr;
|
2009-04-24 23:35:41 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
bool ScintillaWin::Register(HINSTANCE hInstance_) noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
hInstance = hInstance_;
|
|
|
|
|
|
|
|
// Register the Scintilla class
|
2015-06-07 21:19:26 +00:00
|
|
|
// Register Scintilla as a wide character window
|
2019-07-21 13:26:02 +00:00
|
|
|
WNDCLASSEXW wndclass {};
|
2015-06-07 21:19:26 +00:00
|
|
|
wndclass.cbSize = sizeof(wndclass);
|
|
|
|
wndclass.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW;
|
|
|
|
wndclass.lpfnWndProc = ScintillaWin::SWndProc;
|
|
|
|
wndclass.cbWndExtra = sizeof(ScintillaWin *);
|
|
|
|
wndclass.hInstance = hInstance;
|
|
|
|
wndclass.lpszClassName = L"Scintilla";
|
|
|
|
scintillaClassAtom = ::RegisterClassExW(&wndclass);
|
2019-05-04 18:14:48 +00:00
|
|
|
bool result = 0 != scintillaClassAtom;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
if (result) {
|
|
|
|
// Register the CallTip class
|
2019-07-21 13:26:02 +00:00
|
|
|
WNDCLASSEX wndclassc {};
|
2009-04-24 23:35:41 +00:00
|
|
|
wndclassc.cbSize = sizeof(wndclassc);
|
|
|
|
wndclassc.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW;
|
|
|
|
wndclassc.cbWndExtra = sizeof(ScintillaWin *);
|
|
|
|
wndclassc.hInstance = hInstance;
|
|
|
|
wndclassc.lpfnWndProc = ScintillaWin::CTWndProc;
|
|
|
|
wndclassc.hCursor = ::LoadCursor(NULL, IDC_ARROW);
|
|
|
|
wndclassc.lpszClassName = callClassName;
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
callClassAtom = ::RegisterClassEx(&wndclassc);
|
|
|
|
result = 0 != callClassAtom;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
bool ScintillaWin::Unregister() noexcept {
|
2015-06-07 21:19:26 +00:00
|
|
|
bool result = true;
|
|
|
|
if (0 != scintillaClassAtom) {
|
|
|
|
if (::UnregisterClass(MAKEINTATOM(scintillaClassAtom), hInstance) == 0) {
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
scintillaClassAtom = 0;
|
|
|
|
}
|
|
|
|
if (0 != callClassAtom) {
|
|
|
|
if (::UnregisterClass(MAKEINTATOM(callClassAtom), hInstance) == 0) {
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
callClassAtom = 0;
|
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
bool ScintillaWin::HasCaretSizeChanged() const noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
if (
|
|
|
|
( (0 != vs.caretWidth) && (sysCaretWidth != vs.caretWidth) )
|
2010-07-12 22:19:51 +00:00
|
|
|
|| ((0 != vs.lineHeight) && (sysCaretHeight != vs.lineHeight))
|
2009-04-24 23:35:41 +00:00
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL ScintillaWin::CreateSystemCaret() {
|
|
|
|
sysCaretWidth = vs.caretWidth;
|
|
|
|
if (0 == sysCaretWidth) {
|
|
|
|
sysCaretWidth = 1;
|
|
|
|
}
|
|
|
|
sysCaretHeight = vs.lineHeight;
|
2019-05-04 18:14:48 +00:00
|
|
|
const int bitmapSize = (((sysCaretWidth + 15) & ~15) >> 3) *
|
2009-04-24 23:35:41 +00:00
|
|
|
sysCaretHeight;
|
2019-05-04 18:14:48 +00:00
|
|
|
std::vector<BYTE> bits(bitmapSize);
|
2009-04-24 23:35:41 +00:00
|
|
|
sysCaretBitmap = ::CreateBitmap(sysCaretWidth, sysCaretHeight, 1,
|
2019-05-04 18:14:48 +00:00
|
|
|
1, &bits[0]);
|
|
|
|
const BOOL retval = ::CreateCaret(
|
2009-04-24 23:35:41 +00:00
|
|
|
MainHWND(), sysCaretBitmap,
|
|
|
|
sysCaretWidth, sysCaretHeight);
|
2015-06-07 21:19:26 +00:00
|
|
|
if (technology == SC_TECHNOLOGY_DEFAULT) {
|
|
|
|
// System caret interferes with Direct2D drawing so only show it for GDI.
|
|
|
|
::ShowCaret(MainHWND());
|
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
BOOL ScintillaWin::DestroySystemCaret() noexcept {
|
2009-04-24 23:35:41 +00:00
|
|
|
::HideCaret(MainHWND());
|
2019-05-04 18:14:48 +00:00
|
|
|
const BOOL retval = ::DestroyCaret();
|
2009-04-24 23:35:41 +00:00
|
|
|
if (sysCaretBitmap) {
|
|
|
|
::DeleteObject(sysCaretBitmap);
|
|
|
|
sysCaretBitmap = 0;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
LRESULT PASCAL ScintillaWin::CTWndProc(
|
|
|
|
HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) {
|
2009-04-24 23:35:41 +00:00
|
|
|
// Find C++ object associated with window.
|
2019-05-04 18:14:48 +00:00
|
|
|
ScintillaWin *sciThis = static_cast<ScintillaWin *>(PointerFromWindow(hWnd));
|
2009-08-23 02:24:48 +00:00
|
|
|
try {
|
|
|
|
// ctp will be zero if WM_CREATE not seen yet
|
2019-05-04 18:14:48 +00:00
|
|
|
if (sciThis == nullptr) {
|
2009-08-23 02:24:48 +00:00
|
|
|
if (iMessage == WM_CREATE) {
|
|
|
|
// Associate CallTip object with window
|
2019-05-04 18:14:48 +00:00
|
|
|
CREATESTRUCT *pCreate = static_cast<CREATESTRUCT *>(PtrFromSPtr(lParam));
|
2009-08-23 02:24:48 +00:00
|
|
|
SetWindowPointer(hWnd, pCreate->lpCreateParams);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return ::DefWindowProc(hWnd, iMessage, wParam, lParam);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
} else {
|
2009-08-23 02:24:48 +00:00
|
|
|
if (iMessage == WM_NCDESTROY) {
|
|
|
|
::SetWindowLong(hWnd, 0, 0);
|
|
|
|
return ::DefWindowProc(hWnd, iMessage, wParam, lParam);
|
|
|
|
} else if (iMessage == WM_PAINT) {
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
::BeginPaint(hWnd, &ps);
|
2019-05-04 18:14:48 +00:00
|
|
|
std::unique_ptr<Surface> surfaceWindow(Surface::Allocate(sciThis->technology));
|
2013-08-28 00:44:27 +00:00
|
|
|
#if defined(USE_D2D)
|
2019-05-04 18:14:48 +00:00
|
|
|
ID2D1HwndRenderTarget *pCTRenderTarget = nullptr;
|
2013-08-28 00:44:27 +00:00
|
|
|
#endif
|
2019-05-04 18:14:48 +00:00
|
|
|
RECT rc;
|
|
|
|
GetClientRect(hWnd, &rc);
|
|
|
|
// Create a Direct2D render target.
|
|
|
|
if (sciThis->technology == SC_TECHNOLOGY_DEFAULT) {
|
|
|
|
surfaceWindow->Init(ps.hdc, hWnd);
|
|
|
|
} else {
|
2013-08-28 00:44:27 +00:00
|
|
|
#if defined(USE_D2D)
|
2019-05-04 18:14:48 +00:00
|
|
|
D2D1_HWND_RENDER_TARGET_PROPERTIES dhrtp;
|
|
|
|
dhrtp.hwnd = hWnd;
|
|
|
|
dhrtp.pixelSize = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top);
|
|
|
|
dhrtp.presentOptions = (sciThis->technology == SC_TECHNOLOGY_DIRECTWRITERETAIN) ?
|
|
|
|
D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS : D2D1_PRESENT_OPTIONS_NONE;
|
|
|
|
|
|
|
|
D2D1_RENDER_TARGET_PROPERTIES drtp;
|
|
|
|
drtp.type = D2D1_RENDER_TARGET_TYPE_DEFAULT;
|
|
|
|
drtp.pixelFormat.format = DXGI_FORMAT_UNKNOWN;
|
|
|
|
drtp.pixelFormat.alphaMode = D2D1_ALPHA_MODE_UNKNOWN;
|
|
|
|
drtp.dpiX = 96.0;
|
|
|
|
drtp.dpiY = 96.0;
|
|
|
|
drtp.usage = D2D1_RENDER_TARGET_USAGE_NONE;
|
|
|
|
drtp.minLevel = D2D1_FEATURE_LEVEL_DEFAULT;
|
|
|
|
|
|
|
|
if (!SUCCEEDED(pD2DFactory->CreateHwndRenderTarget(drtp, dhrtp, &pCTRenderTarget))) {
|
|
|
|
surfaceWindow->Release();
|
|
|
|
::EndPaint(hWnd, &ps);
|
|
|
|
return 0;
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
2019-07-21 13:26:02 +00:00
|
|
|
// If above SUCCEEDED, then pCTRenderTarget not nullptr
|
|
|
|
assert(pCTRenderTarget);
|
2019-05-04 18:14:48 +00:00
|
|
|
surfaceWindow->Init(pCTRenderTarget, hWnd);
|
|
|
|
pCTRenderTarget->BeginDraw();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
surfaceWindow->SetUnicodeMode(SC_CP_UTF8 == sciThis->ct.codePage);
|
|
|
|
surfaceWindow->SetDBCSMode(sciThis->ct.codePage);
|
|
|
|
surfaceWindow->SetBidiR2L(sciThis->BidirectionalR2L());
|
|
|
|
sciThis->ct.PaintCT(surfaceWindow.get());
|
2013-08-28 00:44:27 +00:00
|
|
|
#if defined(USE_D2D)
|
2019-05-04 18:14:48 +00:00
|
|
|
if (pCTRenderTarget)
|
|
|
|
pCTRenderTarget->EndDraw();
|
2013-08-28 00:44:27 +00:00
|
|
|
#endif
|
2019-05-04 18:14:48 +00:00
|
|
|
surfaceWindow->Release();
|
2013-08-28 00:44:27 +00:00
|
|
|
#if defined(USE_D2D)
|
2019-05-04 18:14:48 +00:00
|
|
|
if (pCTRenderTarget)
|
|
|
|
pCTRenderTarget->Release();
|
2013-08-28 00:44:27 +00:00
|
|
|
#endif
|
2009-08-23 02:24:48 +00:00
|
|
|
::EndPaint(hWnd, &ps);
|
|
|
|
return 0;
|
|
|
|
} else if ((iMessage == WM_NCLBUTTONDOWN) || (iMessage == WM_NCLBUTTONDBLCLK)) {
|
2019-05-04 18:14:48 +00:00
|
|
|
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
|
2009-08-23 02:24:48 +00:00
|
|
|
ScreenToClient(hWnd, &pt);
|
2015-06-07 21:19:26 +00:00
|
|
|
sciThis->ct.MouseClick(PointFromPOINT(pt));
|
2009-08-23 02:24:48 +00:00
|
|
|
sciThis->CallTipClick();
|
|
|
|
return 0;
|
|
|
|
} else if (iMessage == WM_LBUTTONDOWN) {
|
|
|
|
// This does not fire due to the hit test code
|
2019-05-04 18:14:48 +00:00
|
|
|
sciThis->ct.MouseClick(PointFromLParam(lParam));
|
2009-08-23 02:24:48 +00:00
|
|
|
sciThis->CallTipClick();
|
|
|
|
return 0;
|
|
|
|
} else if (iMessage == WM_SETCURSOR) {
|
2010-07-12 22:19:51 +00:00
|
|
|
::SetCursor(::LoadCursor(NULL, IDC_ARROW));
|
2009-08-23 02:24:48 +00:00
|
|
|
return 0;
|
|
|
|
} else if (iMessage == WM_NCHITTEST) {
|
|
|
|
return HTCAPTION;
|
|
|
|
} else {
|
|
|
|
return ::DefWindowProc(hWnd, iMessage, wParam, lParam);
|
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
} catch (...) {
|
|
|
|
sciThis->errorStatus = SC_STATUS_FAILURE;
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
return ::DefWindowProc(hWnd, iMessage, wParam, lParam);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sptr_t ScintillaWin::DirectFunction(
|
2015-06-07 21:19:26 +00:00
|
|
|
sptr_t ptr, UINT iMessage, uptr_t wParam, sptr_t lParam) {
|
2019-05-04 18:14:48 +00:00
|
|
|
PLATFORM_ASSERT(::GetCurrentThreadId() == ::GetWindowThreadProcessId(reinterpret_cast<ScintillaWin *>(ptr)->MainHWND(), nullptr));
|
2015-06-07 21:19:26 +00:00
|
|
|
return reinterpret_cast<ScintillaWin *>(ptr)->WndProc(iMessage, wParam, lParam);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
namespace Scintilla {
|
|
|
|
|
|
|
|
sptr_t DirectFunction(
|
2009-04-24 23:35:41 +00:00
|
|
|
ScintillaWin *sci, UINT iMessage, uptr_t wParam, sptr_t lParam) {
|
|
|
|
return sci->WndProc(iMessage, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT PASCAL ScintillaWin::SWndProc(
|
|
|
|
HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) {
|
2009-04-24 23:35:41 +00:00
|
|
|
//Platform::DebugPrintf("S W:%x M:%x WP:%x L:%x\n", hWnd, iMessage, wParam, lParam);
|
|
|
|
|
|
|
|
// Find C++ object associated with window.
|
2019-05-04 18:14:48 +00:00
|
|
|
ScintillaWin *sci = static_cast<ScintillaWin *>(PointerFromWindow(hWnd));
|
2009-04-24 23:35:41 +00:00
|
|
|
// sci will be zero if WM_CREATE not seen yet
|
2019-05-04 18:14:48 +00:00
|
|
|
if (sci == nullptr) {
|
2009-08-23 02:24:48 +00:00
|
|
|
try {
|
|
|
|
if (iMessage == WM_CREATE) {
|
|
|
|
// Create C++ object associated with window
|
|
|
|
sci = new ScintillaWin(hWnd);
|
|
|
|
SetWindowPointer(hWnd, sci);
|
|
|
|
return sci->WndProc(iMessage, wParam, lParam);
|
2010-07-12 22:19:51 +00:00
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
} catch (...) {
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
return ::DefWindowProc(hWnd, iMessage, wParam, lParam);
|
2009-04-24 23:35:41 +00:00
|
|
|
} else {
|
|
|
|
if (iMessage == WM_NCDESTROY) {
|
2009-08-23 02:24:48 +00:00
|
|
|
try {
|
|
|
|
sci->Finalise();
|
|
|
|
delete sci;
|
|
|
|
} catch (...) {
|
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
::SetWindowLong(hWnd, 0, 0);
|
|
|
|
return ::DefWindowProc(hWnd, iMessage, wParam, lParam);
|
|
|
|
} else {
|
|
|
|
return sci->WndProc(iMessage, wParam, lParam);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function is externally visible so it can be called from container when building statically.
|
|
|
|
// Must be called once only.
|
2010-07-12 22:19:51 +00:00
|
|
|
int Scintilla_RegisterClasses(void *hInstance) {
|
2009-04-24 23:35:41 +00:00
|
|
|
Platform_Initialise(hInstance);
|
2019-05-04 18:14:48 +00:00
|
|
|
const bool result = ScintillaWin::Register(static_cast<HINSTANCE>(hInstance));
|
2009-04-24 23:35:41 +00:00
|
|
|
#ifdef SCI_LEXER
|
|
|
|
Scintilla_LinkLexers();
|
|
|
|
#endif
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
namespace Scintilla {
|
|
|
|
|
|
|
|
int ResourcesRelease(bool fromDllMain) {
|
|
|
|
const bool result = ScintillaWin::Unregister();
|
2015-06-07 21:19:26 +00:00
|
|
|
Platform_Finalise(fromDllMain);
|
2009-04-24 23:35:41 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
}
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
// This function is externally visible so it can be called from container when building statically.
|
|
|
|
int Scintilla_ReleaseResources() {
|
2019-05-04 18:14:48 +00:00
|
|
|
return Scintilla::ResourcesRelease(false);
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|