FX_BOOL CFWL_ToolTipContainer::ProcessLeave(CFWL_EvtMouse* pEvt) { if (HasToolTip(pEvt->m_pDstTarget) && NULL != m_pToolTipImp) { m_pToolTipImp->Hide(); pCurTarget = NULL; return TRUE; } return FALSE; }
FX_BOOL CFWL_ToolTipContainer::ProcessEnter(CFWL_EvtMouse* pEvt, IFWL_Widget* pOwner) { if (HasToolTip(pEvt->m_pDstTarget)) { if (NULL == m_pToolTipImp) { CFWL_WidgetImpProperties prop; prop.m_pDataProvider = m_ToolTipDp; prop.m_pOwner = pOwner; CFX_RectF rtTooltip; rtTooltip.Set(150, 150, 100, 50); prop.m_rtWidget = rtTooltip; IFWL_ToolTip* pToolTip = IFWL_ToolTip::Create(prop, nullptr); pToolTip->Initialize(); m_pToolTipImp = static_cast<CFWL_ToolTipImp*>(pToolTip->GetImpl()); m_pToolTipImp->ModifyStylesEx(FWL_STYLEEXT_TTP_Multiline, 0); m_pToolTipImp->SetStates(FWL_WGTSTATE_Invisible, TRUE); } if (pCurTarget->IsShowed()) { CFX_WideString wsCaption; pCurTarget->GetCaption(wsCaption); if (!wsCaption.IsEmpty()) { m_ToolTipDp->m_wsCaption = wsCaption; } CFX_RectF rt; rt.Reset(); CFX_SizeF sz; sz.Reset(); pCurTarget->GetToolTipSize(sz); if (sz.x > 0 && sz.y > 0) { rt.width = sz.x; rt.height = sz.y; } else { CFX_RectF r; m_pToolTipImp->GetWidgetRect(r, TRUE); rt.width = r.width; rt.height = r.height; } CFX_PointF pt; pt.Set(pEvt->m_fx, pEvt->m_fy); if (pCurTarget->GetToolTipPos(pt) == FWL_ERR_Succeeded) { rt.left = pt.x; rt.top = pt.y; m_pToolTipImp->ModifyStylesEx(FWL_STYLEEXT_TTP_NoAnchor, 0); } else { CFX_RectF rtAnchor; pCurTarget->GetWidget()->GetClientRect(rtAnchor); pCurTarget->GetWidget()->TransformTo(NULL, rtAnchor.left, rtAnchor.top); m_pToolTipImp->SetAnchor(rtAnchor); m_pToolTipImp->ModifyStylesEx(0, FWL_STYLEEXT_TTP_NoAnchor); } m_pToolTipImp->SetWidgetRect(rt); m_pToolTipImp->Update(); m_pToolTipImp->Show(); } return TRUE; } return FALSE; }
/*---------------------------------------------------------------------------------------------- Create a new TssEdit. ptss can be NULL if the control should start out empty. ----------------------------------------------------------------------------------------------*/ void TssEdit::Create(HWND hwndPar, int cid, DWORD dwStyle, HWND hwndToolTip, ITsString * ptss, ILgWritingSystemFactory * pwsf, int ws, IActionHandler * pacth) { AssertPtr(pwsf); PreCreate(pwsf, ws, ptss, pacth); m_cid = cid; m_hwndToolTip = hwndToolTip; m_wsBase = ws; m_qwsf = pwsf; if (!m_wsBase) CheckHr(pwsf->get_UserWs(&m_wsBase)); // get the user interface writing system id. // Create the window. WndCreateStruct wcs; wcs.lpszClass = _T("AfVwWnd"); wcs.hwndParent = hwndPar; wcs.SetWid(cid); wcs.style = dwStyle; CreateHwnd(wcs); // Add a tool tip. if (HasToolTip()) { // Add the combo information to the tooltip. TOOLINFO ti = { isizeof(ti), TTF_IDISHWND }; #ifdef DEBUG static StrApp s_str; s_str.Format(_T("Missing a tooltip for edit control with ID %d"), m_cid); ti.lpszText = const_cast<achar *>(s_str.Chars()); #else // !DEBUG ti.lpszText = _T("Dummy text"); #endif // !DEBUG ti.hwnd = Hwnd(); ti.uId = (uint)ti.hwnd; ::GetClientRect(Hwnd(), &ti.rect); ::SendMessage(m_hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti); } PostCreate(ptss); }
/*---------------------------------------------------------------------------------------------- Handle notifications. @param ctid Identifier of the common control sending the message. @param pnmh Pointer to an NMHDR structure containing notification code and additional info. @param lnRet Value to be returned to system windows send message call. @return True if the notification has been handled, otherwise false. ----------------------------------------------------------------------------------------------*/ bool TssEdit::OnNotifyChild(int id, NMHDR * pnmh, long & lnRet) { AssertPtr(pnmh); if (SuperClass::OnNotifyChild(id, pnmh, lnRet)) return true; bool fToolTip = HasToolTip(); HWND hwndParent = ::GetParent(m_hwnd); if (fToolTip && pnmh->code == TTN_POP) { // Wait 1/2 second after the tooltip disappears before resetting the text on the // status bar. ::SetTimer(hwndParent, knToolTipTimer, 500, NULL); return true; } else if (fToolTip && pnmh->code == TTN_SHOW) { // This flag keeps the tooltip from recursively appearing and crashing the program. static bool s_fIgnore = false; if (!s_fIgnore) { // If another tooltip shows up in the 1/2 second time interval set above, cancel // the timer, so the status bar doesn't get changed back to the idle string. ::KillTimer(hwndParent, knToolTipTimer); // Create a new notification message and forward it to the parent in order to get // the default response for a normal tooltip (which is currently defined in // AfMainWnd::OnNotifyChild). NMTTDISPINFO nmtdi; nmtdi.hdr.hwndFrom = (HWND)id; nmtdi.hdr.code = TTN_GETDISPINFO; nmtdi.hdr.idFrom = ::GetDlgCtrlID((HWND)id); *nmtdi.szText = 0; ::SendMessage(::GetParent(m_hwnd), WM_NOTIFY, nmtdi.hdr.idFrom, (LPARAM)&nmtdi); // Update the status bar here rather than above after ::KillTimer() so that the // string for the new command is already set. AfMainWnd * pafw = MainWindow(); AssertPtr(pafw); AfStatusBar * pstat = pafw->GetStatusBarWnd(); if (pstat) pstat->DisplayHelpText(); if (*nmtdi.szText) { // Now we have the text for the control, so update the text in the tooltip. TOOLINFO ti = { isizeof(ti) }; ti.hwnd = (HWND)id; ti.uId = (uint)ti.hwnd; ti.lpszText = nmtdi.szText; ::SendMessage(pnmh->hwndFrom, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); // This is required so the tooltip gets resized properly. s_fIgnore = true; ::SendMessage(pnmh->hwndFrom, TTM_UPDATE, 0, 0); s_fIgnore = false; return true; } } } return false; }
/*---------------------------------------------------------------------------------------------- This processes Windows messages on the window. In general, it normally calls the appropriate method on the edit class. ----------------------------------------------------------------------------------------------*/ bool TssEdit::FWndProc(uint wm, WPARAM wp, LPARAM lp, long & lnRet) { bool fRet; switch (wm) { case WM_GETDLGCODE: // This is essential when embedded in a dialog to tell the dialog manager that it // wants to get key strokes. (We could try DLGC_WANTALLKEYS but I think we would then // get the Tab and Return keys...we may get them anyway with this combination...) // The last value tells Windows that when tabbing to this control we should use // EM_SETSEL to select all the text. lnRet = DLGC_WANTCHARS | DLGC_WANTARROWS | DLGC_HASSETSEL; return true; case EM_GETLINE: // Use FW_EM_GETLINE. case EM_REPLACESEL: // Use FW_EM_REPLACESEL. // We don't support these methods. Use the replacement TsString versions instead. Assert(false); lnRet = LB_ERR; return true; // NOTE: DO NOT send this message to a TssEdit if you want the actual text. Send the // FW_EM_GETTEXT message instead. This method is required for TssEdit controls on a // dialog because Windows will send the message to the control anytime the user hits a // key. case WM_GETTEXT: { ITsStringPtr qtss; GetText(&qtss); const wchar * pwrgch; int cch; HRESULT hr; IgnoreHr(hr = qtss->LockText(&pwrgch, &cch)); if (FAILED(hr)) return true; StrApp str(pwrgch, cch); qtss->UnlockText(pwrgch); lnRet = Min(cch + 1, (int)wp); achar * psz = reinterpret_cast<achar *>(lp); StrCpyN(psz, str.Chars(), lnRet); } return true; // NOTE: You should be sending an FW_EM_SETTEXT message instead of this. case WM_SETTEXT: { achar * psz = reinterpret_cast<achar *>(lp); StrUni stu(psz); ITsStrFactoryPtr qtsf; qtsf.CreateInstance(CLSID_TsStrFactory); ITsStringPtr qtss; CheckHr(qtsf->MakeStringRgch(stu.Chars(), stu.Length(), m_wsBase, &qtss)); SetText(qtss); } return true; case EM_CANUNDO: case EM_CHARFROMPOS: case EM_EMPTYUNDOBUFFER: case EM_FMTLINES: case EM_GETFIRSTVISIBLELINE: case EM_GETHANDLE: case EM_GETMODIFY: case EM_GETPASSWORDCHAR: case EM_GETRECT: case EM_GETTHUMB: case EM_GETWORDBREAKPROC: case EM_POSFROMCHAR: case EM_SETHANDLE: case EM_SETMODIFY: case EM_SETPASSWORDCHAR: case EM_SETRECT: case EM_SETRECTNP: case EM_SETTABSTOPS: case EM_SETWORDBREAKPROC: case EM_UNDO: case WM_GETFONT: case WM_SETFONT: // We don't support these methods. Assert(false); lnRet = LB_ERR; return true; case EM_GETLIMITTEXT: lnRet = GetLimitText(); return true; case FW_EM_GETLINE: lnRet = GetLine(wp, (ITsString **)lp); return true; case EM_GETLINECOUNT: lnRet = GetLineCount(); return true; case EM_GETMARGINS: lnRet = GetMargins(); return true; case FW_EM_GETSTYLE: GetStyle((StrUni *)lp, (COLORREF *)wp); return true; case EM_GETSEL: lnRet = GetSel((int *)wp, (int *)lp); return true; case EM_LINEFROMCHAR: lnRet = LineFromChar(wp); return true; case EM_LINEINDEX: lnRet = LineIndex(wp); return true; case EM_LINELENGTH: lnRet = LineLength(wp); return true; case EM_LINESCROLL: LineScroll(lp, wp); return true; case FW_EM_REPLACESEL: ReplaceSel((ITsString *)lp); return true; case EM_SCROLL: lnRet = ::SendMessage(m_hwnd, WM_VSCROLL, LOWORD(wp), 0); return true; case EM_SCROLLCARET: ScrollCaret(); return true; case EM_SETLIMITTEXT: SetLimitText(wp); return true; case EM_SETMARGINS: SetMargins(wp, LOWORD(lp), HIWORD(lp)); return true; case EM_SETREADONLY: SetReadOnly(wp); return true; case EM_SETSEL: SetSel(wp, lp); return true; case FW_EM_SETSTYLE: SetStyle((StrUni *)lp, (COLORREF)wp); return true; case WM_GETTEXTLENGTH: lnRet = GetTextLength(); return true; case FW_EM_GETTEXT: GetText((ITsString **)lp); return true; case FW_EM_SETTEXT: SetText((ITsString *)lp); return true; case WM_COPY: Copy(); return true; case WM_CUT: Cut(); return true; case WM_PASTE: Paste(); return true; case WM_HSCROLL: if (!OnHScroll(LOWORD(wp), HIWORD(wp), (HWND)lp)) { ::SendMessage(::GetParent(m_hwnd), WM_COMMAND, MAKEWPARAM(::GetDlgCtrlID(m_hwnd), EN_HSCROLL), (LPARAM)m_hwnd); } return true; case WM_VSCROLL: if (!OnVScroll(LOWORD(wp), HIWORD(wp), (HWND)lp)) { ::SendMessage(::GetParent(m_hwnd), WM_COMMAND, MAKEWPARAM(::GetDlgCtrlID(m_hwnd), EN_VSCROLL), (LPARAM)m_hwnd); } return true; case WM_KILLFOCUS: if (!OnKillFocus((HWND)wp)) { ::SendMessage(::GetParent(m_hwnd), WM_COMMAND, MAKEWPARAM(::GetDlgCtrlID(m_hwnd), EN_KILLFOCUS), (LPARAM)m_hwnd); } return true; case WM_SETFOCUS: if (!OnSetFocus((HWND)wp)) { ::SendMessage(::GetParent(m_hwnd), WM_COMMAND, MAKEWPARAM(::GetDlgCtrlID(m_hwnd), EN_SETFOCUS), (LPARAM)m_hwnd); } return true; // Calling SuperClass here causes two OnSetFocus calls for each OnKillFocus. //return SuperClass::FWndProc(wm, wp, lp, lnRet); case WM_CHAR: fRet = false; if (wp == VK_TAB) // '\t' { fRet = OnCharTab(); } else if (wp == VK_RETURN) // '\r' { fRet = OnCharEnter(); } else if (wp == VK_ESCAPE) // '\33' { fRet = OnCharEscape(); } if (fRet) return fRet; else return SuperClass::FWndProc(wm, wp, lp, lnRet); case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_MBUTTONDOWN: case WM_MBUTTONUP: case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_MOUSEMOVE: if (HasToolTip()) { // Notify the tooltip belonging to the parent toolbar of the mouse message. Assert(m_hwndToolTip); MSG msg; msg.hwnd = m_hwnd; // ::GetParent(m_hwnd); msg.message = wm; msg.wParam = wp; msg.lParam = lp; ::SendMessage(m_hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg); } break; default: break; } return SuperClass::FWndProc(wm, wp, lp, lnRet); }