Skip to content

Commit

Permalink
Add option to configure block caret for inline IME.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Sep 2, 2018
1 parent 4476ca9 commit 300590c
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 3 deletions.
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
* Support rendering using Direct2D DirectWrite, and switch between GDI and Direct2D
* Support bidirectional, useful for Arabic and Hebrew
* Support using fractional font size
* Support Inline IME
* Extra support for drag and drop file from Visual Studio, Android Studio, IntelliJ IDEA, etc.
* Other various major or minor changes and tweaks

Expand All @@ -172,7 +173,7 @@ TBD.
Prebuild binaries for each release can be downloaded from [release list](https://github.com/zufuliu/notepad2/releases).

## Notes:
* The default *Win32* build require [SSE2](https://en.wikipedia.org/wiki/SSE2)(Pentium 4), which can be turned off if you [build Notepad2 and metapath](https://github.com/zufuliu/notepad2/wiki/Build-Notepad2) yourself.
* The default *Win32* build require [SSE2](https://en.wikipedia.org/wiki/SSE2) (Pentium 4), which can be turned off if you [build Notepad2 and metapath](https://github.com/zufuliu/notepad2/wiki/Build-Notepad2) yourself.
* If you find any bugs or have any suggestions feel free to **write proposals/issues** and/or **provide patches/pull requests**.

## Contributors:
Expand Down
2 changes: 2 additions & 0 deletions scintilla/include/Scintilla.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SC_IME_INLINE 1
#define SCI_GETIMEINTERACTION 2678
#define SCI_SETIMEINTERACTION 2679
#define SCI_GETINLINEIMEUSEBLOCKCARET 2638
#define SCI_SETINLINEIMEUSEBLOCKCARET 2639
#define MARKER_MAX 31
#define SC_MARK_CIRCLE 0
#define SC_MARK_ROUNDRECT 1
Expand Down
6 changes: 6 additions & 0 deletions scintilla/include/Scintilla.iface
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ get int GetIMEInteraction=2678(,)
# Choose to display the the IME in a winow or inline.
set void SetIMEInteraction=2679(int imeInteraction,)

# Is block caret used in inline IME
get bool GetInlineIMEUseBlockCaret=2638(,)

# Set inline IME to use block caret
set void SetInlineIMEUseBlockCaret=2639(bool useBlockCaret,)

enu MarkerSymbol=SC_MARK_
val MARKER_MAX=31
val SC_MARK_CIRCLE=0
Expand Down
1 change: 1 addition & 0 deletions scintilla/src/EditModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class EditModel {
enum IMEInteraction {
imeWindowed, imeInline
} imeInteraction;
bool inlineIMEUseBlockCaret;
enum class Bidirectional {
bidiDisabled, bidiL2R, bidiR2L
} bidirectional;
Expand Down
7 changes: 7 additions & 0 deletions scintilla/src/Editor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6798,6 +6798,13 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_GETIMEINTERACTION:
return imeInteraction;

case SCI_SETINLINEIMEUSEBLOCKCARET:
inlineIMEUseBlockCaret = wParam != 0;
break;

case SCI_GETINLINEIMEUSEBLOCKCARET:
return inlineIMEUseBlockCaret;

case SCI_SETBIDIRECTIONAL:
// SCI_SETBIDIRECTIONAL is implemented on platform subclasses if they support bidirectional text.
break;
Expand Down
6 changes: 5 additions & 1 deletion scintilla/win32/ScintillaWin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ class ScintillaWin :

sptr_t HandleCompositionWindowed(uptr_t wParam, sptr_t lParam);
sptr_t HandleCompositionInline(uptr_t wParam, sptr_t lParam);
#if 0
static bool KoreanIME() noexcept;
#endif
void MoveImeCarets(Sci::Position offset);
void DrawImeIndicator(int indicator, int len);
void SetCandidateWindowPos();
Expand Down Expand Up @@ -1013,10 +1015,12 @@ sptr_t ScintillaWin::HandleCompositionWindowed(uptr_t wParam, sptr_t lParam) {
return ::DefWindowProc(MainHWND(), WM_IME_COMPOSITION, wParam, lParam);
}

#if 0
bool ScintillaWin::KoreanIME() noexcept {
const int codePage = InputCodePage();
return codePage == 949 || codePage == 1361;
}
#endif

void ScintillaWin::MoveImeCarets(Sci::Position offset) {
// Move carets relatively by bytes.
Expand Down Expand Up @@ -1224,7 +1228,7 @@ sptr_t ScintillaWin::HandleCompositionInline(uptr_t, sptr_t lParam) {

MoveImeCarets(-CurrentPosition() + imeCaretPosDoc);

if (KoreanIME()) {
if (inlineIMEUseBlockCaret) {
view.imeCaretBlockOverride = true;
}
} else if (lParam & GCS_RESULTSTR) {
Expand Down
2 changes: 2 additions & 0 deletions src/Edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ extern BOOL bAutoStripBlanks;
extern int iRenderingTechnology;
extern int iBidirectional;
extern BOOL bUseInlineIME;
extern BOOL bInlineIMEUseBlockCaret;
// Default Codepage and Character Set
extern int iDefaultCodePage;
//extern int iDefaultCharSet;
Expand Down Expand Up @@ -91,6 +92,7 @@ HWND EditCreate(HWND hwndParent) {
SendMessage(hwnd, SCI_SETTECHNOLOGY, iRenderingTechnology, 0);
SendMessage(hwnd, SCI_SETBIDIRECTIONAL, iBidirectional, 0);
SendMessage(hwnd, SCI_SETIMEINTERACTION, bUseInlineIME, 0);
SendMessage(hwnd, SCI_SETINLINEIMEUSEBLOCKCARET, bInlineIMEUseBlockCaret, 0);
SendMessage(hwnd, SCI_SETCODEPAGE, iDefaultCodePage, 0);
SendMessage(hwnd, SCI_SETEOLMODE, SC_EOL_CRLF, 0);
SendMessage(hwnd, SCI_SETPASTECONVERTENDINGS, 1, 0);
Expand Down
10 changes: 10 additions & 0 deletions src/Notepad2.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ BOOL bMinimizeToTray;
BOOL bTransparentMode;
int iRenderingTechnology;
BOOL bUseInlineIME;
BOOL bInlineIMEUseBlockCaret;
int iBidirectional;
BOOL bShowToolbar;
BOOL bShowStatusbar;
Expand Down Expand Up @@ -2315,6 +2316,7 @@ void MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam) {
i = IDM_SET_BIDIRECTIONAL_NONE + iBidirectional;
CheckMenuRadioItem(hmenu, IDM_SET_BIDIRECTIONAL_NONE, IDM_SET_BIDIRECTIONAL_R2L, i, MF_BYCOMMAND);
CheckCmd(hmenu, IDM_SET_USE_INLINE_IME, bUseInlineIME);
CheckCmd(hmenu, IDM_SET_USE_BLOCK_CARET, bInlineIMEUseBlockCaret);

CheckCmd(hmenu, IDM_VIEW_NOSAVEFINDREPL, bSaveFindReplace);
CheckCmd(hmenu, IDM_VIEW_SAVEBEFORERUNNINGTOOLS, bSaveBeforeRunningTools);
Expand Down Expand Up @@ -4104,6 +4106,11 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) {
SendMessage(hwndEdit, SCI_SETIMEINTERACTION, bUseInlineIME, 0);
break;

case IDM_SET_USE_BLOCK_CARET:
bInlineIMEUseBlockCaret = bInlineIMEUseBlockCaret? FALSE : TRUE;
SendMessage(hwndEdit, SCI_SETINLINEIMEUSEBLOCKCARET, bInlineIMEUseBlockCaret, 0);
break;

case IDM_VIEW_FONTQUALITY_DEFAULT:
case IDM_VIEW_FONTQUALITY_NONE:
case IDM_VIEW_FONTQUALITY_STANDARD:
Expand Down Expand Up @@ -5370,11 +5377,13 @@ void LoadSettings(void) {
iCaretBlinkPeriod = IniSectionGetInt(pIniSection, L"CaretBlinkPeriod", -1);
// Korean IME use inline mode (and block caret in inline mode) by default
bUseInlineIME = IniSectionGetBool(pIniSection, L"UseInlineIME", -1);
bInlineIMEUseBlockCaret = IniSectionGetBool(pIniSection, L"InlineIMEUseBlockCaret", 0);
if (bUseInlineIME == -1) {
// ScintillaWin::KoreanIME()
const int codePage = Scintilla_InputCodePage();
if (codePage == 949 || codePage == 1361) {
bUseInlineIME = TRUE;
bInlineIMEUseBlockCaret = TRUE;
}
}

Expand Down Expand Up @@ -5613,6 +5622,7 @@ void SaveSettings(BOOL bSaveSettingsNow) {
IniSectionSetInt(pIniSection, L"CaretStyle", iCaretStyle);
IniSectionSetInt(pIniSection, L"CaretBlinkPeriod", iCaretBlinkPeriod);
IniSectionSetBool(pIniSection, L"UseInlineIME", bUseInlineIME);
IniSectionSetBool(pIniSection, L"InlineIMEUseBlockCaret", bInlineIMEUseBlockCaret);
Toolbar_GetButtons(hwndToolbar, IDT_FILE_NEW, tchToolbarButtons, COUNTOF(tchToolbarButtons));
IniSectionSetString(pIniSection, L"ToolbarButtons", tchToolbarButtons);
IniSectionSetBool(pIniSection, L"ShowToolbar", bShowToolbar);
Expand Down
6 changes: 5 additions & 1 deletion src/Notepad2.rc
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,11 @@ BEGIN
MENUITEM "Left to Right", IDM_SET_BIDIRECTIONAL_L2R
MENUITEM "Right to Left", IDM_SET_BIDIRECTIONAL_R2L
END
MENUITEM "Use Inline IME" IDM_SET_USE_INLINE_IME
POPUP "Inline IME Options"
BEGIN
MENUITEM "Use Inline IME", IDM_SET_USE_INLINE_IME
MENUITEM "Use Block Caret", IDM_SET_USE_BLOCK_CARET
END
MENUITEM SEPARATOR
MENUITEM "Single &File Instance", IDM_VIEW_SINGLEFILEINSTANCE
MENUITEM "File &Change Notification...\tAlt+F5", IDM_VIEW_CHANGENOTIFY
Expand Down
1 change: 1 addition & 0 deletions src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@
#define IDM_SET_RENDER_TECH_D2DRETAIN 40050
#define IDM_SET_RENDER_TECH_D2DDC 40051
#define IDM_SET_USE_INLINE_IME 40052
#define IDM_SET_USE_BLOCK_CARET 40053
#define IDM_SET_BIDIRECTIONAL_NONE 40060
#define IDM_SET_BIDIRECTIONAL_L2R 40061
#define IDM_SET_BIDIRECTIONAL_R2L 40062
Expand Down

0 comments on commit 300590c

Please sign in to comment.