Skip to content

Commit

Permalink
1、修复自定义图标不显示
Browse files Browse the repository at this point in the history
2、补上遗失的pinyin_simp方案(五笔拼音依赖项)
3、修复通知消息只通知一次的bug
  • Loading branch information
Techince committed Jan 29, 2024
1 parent 66287eb commit 5472a50
Show file tree
Hide file tree
Showing 16 changed files with 372 additions and 159 deletions.
288 changes: 165 additions & 123 deletions RimeWithWeasel/RimeWithWeasel.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions WeaselServer/WeaselServerApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module;
#include "resource.h"
#include <winsparkle.h>

// #define WEASEL_ENABLE_LOGGING
// #include "logging.h"
//#define WEASEL_ENABLE_LOGGING
//#include "logging.h"
module WeaselServerApp;

WeaselServerApp::WeaselServerApp()
Expand Down
2 changes: 1 addition & 1 deletion WeaselServer/WeaselTrayIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void WeaselTrayIcon::Refresh()
RemoveIcon();
m_mode = INITIAL;
}
// m_disabled = false;
m_disabled = false;
return;
}
WeaselTrayMode mode = m_status.disabled ? DISABLED :
Expand Down
1 change: 1 addition & 0 deletions WeaselTSF/Composition.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import EditSession;
import ResponseParser;
import CandidateList;
import WeaselUtility;
// import TransitoryExtension;

export
{
Expand Down
2 changes: 2 additions & 0 deletions WeaselTSF/CompositionTSF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module WeaselTSF;
import Composition;
import CandidateList;
import WeaselUtility;
// import TransitoryExtension;

void WeaselTSF::_StartComposition(ITfContext* pContext, bool not_inline_preedit)
{
Expand Down Expand Up @@ -159,6 +160,7 @@ void WeaselTSF::_UpdateComposition(ITfContext* pContext)
{
HRESULT hr;
_pEditSessionContext = pContext;
// _pEditSessionContext = TransitoryExtension::ToParentContextIfExists(pContext);
ResetBit(WeaselFlag::ASYNC_EDIT);
auto ret = _pEditSessionContext->RequestEditSession(_tfClientId, this, TF_ES_ASYNCDONTCARE | TF_ES_READWRITE, &hr);
if (hr == TF_S_ASYNC)
Expand Down
4 changes: 2 additions & 2 deletions WeaselTSF/KeyEventSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ void WeaselTSF::_ProcessKeyEvent(WPARAM wParam, LPARAM lParam, BOOL* pfEaten, bo
return;
}

ResetBit(WeaselFlag::FIRST_KEY_COMPOSITION);

if (GetBit(WeaselFlag::COMPOSITION_WITH_CAPSLOCK) && wParam == VK_CAPITAL && GetKeyState(VK_CAPITAL) > 0)
{
ResetBit(WeaselFlag::COMPOSITION_WITH_CAPSLOCK);
Expand Down Expand Up @@ -86,7 +88,6 @@ STDAPI WeaselTSF::OnTestKeyDown(ITfContext* pContext, WPARAM wParam, LPARAM lPar
LOG(INFO) << std::format("From OnTestKeyDown. wParam = {:#x}, lParam = {:#x}, pContext = {:#x}", wParam, lParam, (size_t)pContext);
#endif // TEST
_fTestKeyUpPending = false;
ResetBit(WeaselFlag::FIRST_KEY_COMPOSITION);
if (_fTestKeyDownPending)
{
*pfEaten = TRUE;
Expand Down Expand Up @@ -114,7 +115,6 @@ STDAPI WeaselTSF::OnKeyDown(ITfContext* pContext, WPARAM wParam, LPARAM lParam,
}
else
{
ResetBit(WeaselFlag::FIRST_KEY_COMPOSITION);
_ProcessKeyEvent(wParam, lParam, pfEaten);
#ifdef TEST
LOG(INFO) << std::format("From OnKeyDown. *pfEaten = {}", *pfEaten);
Expand Down
90 changes: 90 additions & 0 deletions WeaselTSF/TransitoryExtension.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
module;
#include "stdafx.h"
#include "test.h"

#ifdef TEST
#define WEASEL_ENABLE_LOGGING
#include "logging.h"
#endif // TEST
module TransitoryExtension;

com_ptr<ITfDocumentMgr> TransitoryExtension::ToParentDocumentIfExists(ITfDocumentMgr* pDocumentMgr)
{
if (pDocumentMgr == nullptr)
{
return nullptr;
}

com_ptr<ITfContext> pContext;
if (FAILED(pDocumentMgr->GetTop(&pContext)) || pContext == nullptr)
{
return pDocumentMgr;
}

TF_STATUS status{};
if (FAILED(pContext->GetStatus(&status)))
{
return pDocumentMgr;
}

if ((status.dwStaticFlags & TF_SS_TRANSITORY) != TF_SS_TRANSITORY)
{
return pDocumentMgr;
}

com_ptr<ITfCompartmentMgr> pCompartmentMgr;
if (SUCCEEDED(pDocumentMgr->QueryInterface(&pCompartmentMgr)))
{
com_ptr<ITfCompartment> pCompartment;
if (SUCCEEDED(pCompartmentMgr->GetCompartment(GUID_COMPARTMENT_TRANSITORYEXTENSION_PARENT, &pCompartment)))
{
VARIANT var{};
if (SUCCEEDED(pCompartment->GetValue(&var)))
{
if (var.vt == VT_UNKNOWN && var.punkVal)
{
com_ptr<ITfDocumentMgr> pParentDocumentMgr;
auto hr = var.punkVal->QueryInterface(&pParentDocumentMgr);
#ifdef TEST
LOG(INFO) << std::format("From TransitoryExtension::ToParentDocumentIfExists. punkVal = 0x{:X}, hr = 0x{:X}, ret = 0x{:X}", (size_t)var.punkVal, (unsigned)hr);
#endif // TEST
if (pParentDocumentMgr)
{
#ifdef TEST
LOG(INFO) << std::format("From TransitoryExtension::ToParentDocumentIfExists. ok");
#endif // TEST
return pParentDocumentMgr;
}
}
}
}
}

return pDocumentMgr;
}

com_ptr<ITfContext> TransitoryExtension::ToParentContextIfExists(ITfContext* pContext)
{
if (pContext == nullptr)
{
return nullptr;
}

com_ptr<ITfDocumentMgr> pDocumentMgr;
if (SUCCEEDED(pContext->GetDocumentMgr(&pDocumentMgr)))
{
com_ptr<ITfContext> pParentContext;
if (SUCCEEDED(ToParentDocumentIfExists(pDocumentMgr)->GetTop(&pParentContext)))
{
if (pParentContext)
{
#ifdef TEST
LOG(INFO) << std::format("From TransitoryExtension::ToParentContextIfExists.");
#endif // TEST
return pParentContext;
}
}
}

return pContext;
}
16 changes: 16 additions & 0 deletions WeaselTSF/TransitoryExtension.ixx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "stdafx.h"
export module TransitoryExtension;

export
{
class TransitoryExtension
{
public:
TransitoryExtension() = delete;
TransitoryExtension(const TransitoryExtension&) = delete;
TransitoryExtension& operator=(const TransitoryExtension&) = delete;

static com_ptr<ITfDocumentMgr> ToParentDocumentIfExists(ITfDocumentMgr* pDocumentMgr);
static com_ptr<ITfContext> ToParentContextIfExists(ITfContext* pContext);
};
}
3 changes: 3 additions & 0 deletions WeaselTSF/WeaselTSF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ STDAPI WeaselTSF::ActivateEx(ITfThreadMgr *pThreadMgr, TfClientId tfClientId, DW

if (!_InitActiveLanguageProfileNotifySink())
{
#ifdef TEST
LOG(INFO) << std::format("From WeaselTSF::ActivateEx. _InitActiveLanguageProfileNotifySink Failed.");
#endif // TEST
goto ExitError;
}

Expand Down
11 changes: 8 additions & 3 deletions WeaselUI/FullScreenLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ void weasel::FullScreenLayout::DoLayout(CDCHandle dc, PDWR pDWR)
int step = 32;
do {
m_layout->DoLayout(dc, pDWR);
if (!_style.mark_text.empty() && (_style.hilited_mark_color & 0xff000000))
if (_style.hilited_mark_color && 0xff000000)
{
CSize sg;
GetTextSizeDW(_style.mark_text, _style.mark_text.length(), pDWR->pTextFormat.Get(), pDWR, &sg);
if (_style.mark_text.empty())
GetTextSizeDW(L"|", 1, pDWR->pTextFormat, pDWR, &sg);
else
GetTextSizeDW(_style.mark_text, _style.mark_text.length(), pDWR->pTextFormat, pDWR, &sg);
MARK_WIDTH = sg.cx;
MARK_HEIGHT = sg.cy;
MARK_GAP = MARK_WIDTH + 4;
if (_style.mark_text.empty())
MARK_WIDTH /= 2;
MARK_GAP = _style.mark_text.empty() ? MARK_WIDTH : MARK_WIDTH + _style.hilite_spacing;
}
}
while (AdjustFontPoint(dc, workArea, step, pDWR));
Expand Down
10 changes: 7 additions & 3 deletions WeaselUI/HorizontalLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ void HorizontalLayout::DoLayout(CDCHandle dc, PDWR pDWR )

MARK_WIDTH = sg.cx;
MARK_HEIGHT = sg.cy;
MARK_GAP = MARK_WIDTH + 4;
if (_style.mark_text.empty())
MARK_WIDTH /= 2;
MARK_GAP = _style.mark_text.empty() ? MARK_WIDTH : MARK_WIDTH + _style.hilite_spacing;
}
int base_offset = ((_style.hilited_mark_color & 0xff00'0000) && !_style.mark_text.empty()) ? MARK_GAP : 0;
int base_offset = (_style.hilited_mark_color & 0xff00'0000) ? MARK_GAP : 0;

// calc page indicator
CSize pgszl, pgszr;
Expand Down Expand Up @@ -102,7 +104,9 @@ void HorizontalLayout::DoLayout(CDCHandle dc, PDWR pDWR )
current_cand_width += (size.cx + _style.hilite_spacing) * textFontValid;

/* Comment */
if (!comments.at(i).str.empty() && cmtFontValid )
bool cmtFontNotTrans = (i == id && (_style.hilited_comment_text_color & 0xff00'0000)) ||
(i != id && (_style.comment_text_color & 0xff00'0000));
if (!comments.at(i).str.empty() && cmtFontValid && cmtFontNotTrans)
{
std::wstring_view comment = comments.at(i).str;
GetTextSizeDW(comment, comment.length(), pDWR->pCommentTextFormat, pDWR, &size);
Expand Down
25 changes: 18 additions & 7 deletions WeaselUI/VHorizontalLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ void VHorizontalLayout::DoLayout(CDCHandle dc, PDWR pDWR )

MARK_WIDTH = sg.cx;
MARK_HEIGHT = sg.cy;
MARK_GAP = MARK_HEIGHT + 4;
if (_style.mark_text.empty())
MARK_WIDTH /= 2;
MARK_GAP = _style.mark_text.empty() ? MARK_WIDTH : MARK_WIDTH + _style.hilite_spacing;
}
int base_offset = ((_style.hilited_mark_color & 0xff00'0000) && !_style.mark_text.empty()) ? MARK_GAP : 0;
int base_offset = (_style.hilited_mark_color & 0xff00'0000) ? MARK_GAP : 0;

// calc page indicator
CSize pgszl, pgszr;
Expand Down Expand Up @@ -100,7 +102,9 @@ void VHorizontalLayout::DoLayout(CDCHandle dc, PDWR pDWR )
wid = max(wid, size.cx);

/* Comment */
if (!comments.at(i).str.empty() && cmtFontValid)
bool cmtFontNotTrans = (i == id && (_style.hilited_comment_text_color & 0xff00'0000)) ||
(i != id && (_style.comment_text_color & 0xff00'0000));
if (!comments.at(i).str.empty() && cmtFontValid && cmtFontNotTrans)
{
h += _style.hilite_spacing;
std::wstring_view comment = comments.at(i).str;
Expand Down Expand Up @@ -239,12 +243,17 @@ void VHorizontalLayout::DoLayoutWithWrap(CDCHandle dc, PDWR pDWR)
if (!_style.mark_text.empty() && (_style.hilited_mark_color & 0xff000000))
{
CSize sg;
GetTextSizeDW(_style.mark_text, _style.mark_text.length(), pDWR->pTextFormat, pDWR, &sg);
if (_style.mark_text.empty())
GetTextSizeDW(L"|", 1, pDWR->pTextFormat, pDWR, &sg);
else
GetTextSizeDW(_style.mark_text, _style.mark_text.length(), pDWR->pTextFormat, pDWR, &sg);
MARK_WIDTH = sg.cx;
MARK_HEIGHT = sg.cy;
MARK_GAP = MARK_HEIGHT + 4;
if (_style.mark_text.empty())
MARK_WIDTH /= 2;
MARK_GAP = _style.mark_text.empty() ? MARK_WIDTH : MARK_WIDTH + _style.hilite_spacing;
}
int base_offset = ((_style.hilited_mark_color & 0xff000000) && !_style.mark_text.empty()) ? MARK_GAP : 0;
int base_offset = (_style.hilited_mark_color & 0xff000000) ? MARK_GAP : 0;

// calc page indicator
CSize pgszl, pgszr;
Expand Down Expand Up @@ -306,7 +315,9 @@ void VHorizontalLayout::DoLayoutWithWrap(CDCHandle dc, PDWR pDWR)
current_cand_height += (size.cy + _style.hilite_spacing) * textFontValid;

/* Comment */
if (!comments.at(i).str.empty() && cmtFontValid )
bool cmtFontNotTrans = (i == id && (_style.hilited_comment_text_color & 0xff00'0000)) ||
(i != id && (_style.comment_text_color & 0xff00'0000));
if (!comments.at(i).str.empty() && cmtFontValid && cmtFontNotTrans)
{
std::wstring_view comment = comments.at(i).str;
GetTextSizeDW(comment, comment.length(), pDWR->pCommentTextFormat, pDWR, &size);
Expand Down
15 changes: 11 additions & 4 deletions WeaselUI/VerticalLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ void weasel::VerticalLayout::DoLayout(CDCHandle dc, PDWR pDWR)
if (!_style.mark_text.empty() && (_style.hilited_mark_color & 0xff000000))
{
CSize sg;
GetTextSizeDW(_style.mark_text, _style.mark_text.length(), pDWR->pTextFormat, pDWR, &sg);
if (_style.mark_text.empty())
GetTextSizeDW(L"|", 1, pDWR->pTextFormat, pDWR, &sg);
else
GetTextSizeDW(_style.mark_text, _style.mark_text.length(), pDWR->pTextFormat, pDWR, &sg);
MARK_WIDTH = sg.cx;
MARK_HEIGHT = sg.cy;
MARK_GAP = MARK_WIDTH + 4;
if (_style.mark_text.empty())
MARK_WIDTH /= 2;
MARK_GAP = _style.mark_text.empty() ? MARK_WIDTH : MARK_WIDTH + _style.hilite_spacing;
}
int base_offset = ((_style.hilited_mark_color & 0xff000000) && !_style.mark_text.empty()) ? MARK_GAP : 0;
int base_offset = (_style.hilited_mark_color & 0xff000000) ? MARK_GAP : 0;

// calc page indicator
CSize pgszl, pgszr;
Expand Down Expand Up @@ -86,7 +91,9 @@ void weasel::VerticalLayout::DoLayout(CDCHandle dc, PDWR pDWR)
max_candidate_width = max(max_candidate_width, candidate_width);

/* Comment */
if (!comments.at(i).str.empty() && cmtFontValid)
bool cmtFontNotTrans = (i == id && (_style.hilited_comment_text_color & 0xff00'0000)) ||
(i != id && (_style.comment_text_color & 0xff00'0000));
if (!comments.at(i).str.empty() && cmtFontValid && cmtFontNotTrans)
{
w += space;
comment_shift_width = max(comment_shift_width, w);
Expand Down
21 changes: 13 additions & 8 deletions WeaselUI/WeaselPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,14 +805,14 @@ bool WeaselPanel::_DrawCandidates(CDCHandle& dc, bool back)
if (m_style.layout_type == UIStyle::LAYOUT_VERTICAL_TEXT)
{
int x = rect.left + (rect.Width() - width) / 2;
CRect mkrc{ x, rect.top, x + width, rect.top + m_layout->MARK_HEIGHT / 2 };
CRect mkrc{ x, rect.top, x + width, rect.top + m_layout->MARK_HEIGHT };
GraphicsRoundRectPath mk_path(mkrc, 2);
g_back.FillPath(&mk_brush, &mk_path);
}
else
{
int y = rect.top + (rect.Height() - height) / 2;
CRect mkrc{ rect.left, y, rect.left + m_layout->MARK_WIDTH / 2, y + height };
CRect mkrc{ rect.left, y, rect.left + m_layout->MARK_WIDTH, y + height };
GraphicsRoundRectPath mk_path(mkrc, 2);
g_back.FillPath(&mk_brush, &mk_path);
}
Expand Down Expand Up @@ -858,7 +858,7 @@ bool WeaselPanel::_DrawCandidates(CDCHandle& dc, bool back)
}
// Draw comment
std::wstring comment = comments.at(i).str;
if (!comment.empty()) {
if (!comment.empty() && COLORNOTTRANSPARENT(comment_text_color)) {
rect = m_layout->GetCandidateCommentRect((int)i);
if (m_istorepos) rect.OffsetRect(0, m_offsetys[i]);
_TextOut(rect, comment, comment.length(), comment_text_color, commenttxtFormat.Get());
Expand All @@ -875,11 +875,15 @@ bool WeaselPanel::_DrawCandidates(CDCHandle& dc, bool back)
int hgap = m_layout->MARK_WIDTH ? (rc.Width() - m_layout->MARK_WIDTH) / 2 : 0;
CRect hlRc;
if (m_style.layout_type == UIStyle::LAYOUT_VERTICAL_TEXT)
hlRc = CRect(rc.left + hgap, rc.top + m_style.hilite_padding_y + (m_layout->MARK_GAP - m_layout->MARK_HEIGHT) / 2 + 1,
rc.left + hgap + m_layout->MARK_WIDTH, rc.top + m_style.hilite_padding_y + (m_layout->MARK_GAP - m_layout->MARK_HEIGHT) / 2 + 1 + m_layout->MARK_HEIGHT);
hlRc = CRect(rc.left + hgap,
rc.top + m_style.hilite_padding_y,
rc.left + hgap + m_layout->MARK_WIDTH,
rc.top + m_style.hilite_padding_y + m_layout->MARK_HEIGHT);
else
hlRc = CRect(rc.left + m_style.hilite_padding_x + (m_layout->MARK_GAP - m_layout->MARK_WIDTH) / 2 + 1, rc.top + vgap,
rc.left + m_style.hilite_padding_x + (m_layout->MARK_GAP - m_layout->MARK_WIDTH) / 2 + 1 + m_layout->MARK_WIDTH, rc.bottom - vgap);
hlRc = CRect(rc.left + m_style.hilite_padding_x,
rc.top + vgap,
rc.left + m_style.hilite_padding_x + m_layout->MARK_WIDTH,
rc.bottom - vgap);
_TextOut(hlRc, m_style.mark_text, m_style.mark_text.length(), m_style.hilited_mark_color, m_pDWR->pTextFormat.Get());
}
}
Expand Down Expand Up @@ -1001,7 +1005,8 @@ void WeaselPanel::DoPaint(CDCHandle dc/*, RECT& rect*/)
else if (m_istorepos && !m_layout->IsInlinePreedit() && !m_ctx.preedit.str.empty())
iconRect.OffsetRect(0, m_offsety_preedit);

CIcon& icon(m_status.disabled ? m_iconDisabled : m_status.ascii_mode ? m_iconAlpha : m_iconEnabled);
CIcon& icon(m_status.disabled ? m_iconDisabled : m_status.ascii_mode ? m_iconAlpha :
(m_status.type == SCHEMA ? m_iconEnabled : (m_status.full_shape ? m_iconFull : m_iconHalf)));
memDC.DrawIconEx(iconRect.left, iconRect.top, icon, 0, 0);
drawn = true;
}
Expand Down
Loading

0 comments on commit 5472a50

Please sign in to comment.