wxSize clEditorTipWindow::DoGetTipSize() { wxDC* dc; wxGCDC gdc; wxBitmap bmp(1, 1); wxMemoryDC memDC(bmp); if(!DrawingUtils::GetGCDC(memDC, gdc)) { dc = (wxDC*)&memDC; } else { dc = (wxDC*)&gdc; } wxSize sz; wxSize sz2; dc->SetFont(m_font); sz = dc->GetTextExtent(m_tipText); if(GetTip() && GetTip()->Count() > 1) { // for multiple tips, use second line as well sz2 = dc->GetTextExtent(wxT("100 of 100")); sz.y *= 2; } else { sz2 = wxSize(1, 1); } sz.y += (2 * TIP_SPACER); sz.x += (2 * TIP_SPACER); if(sz.x < sz2.x) { sz.x = sz2.x; } return sz; }
void clEditorTipWindow::SelectSignature(const wxString& signature) { m_selectedSignature = signature; if ( GetTip() ) { GetTip()->SelectSiganture( m_selectedSignature ); m_selectedSignature.clear(); } }
CString CToolbarHelper::GetTip(UINT nID, LPPOINT pPoint) const { if (!nID) { return _T(""); // separator } // are we over the dropbutton? BOOL bOverDropBtn = FALSE; if (pPoint) { CSize sizeBtn(m_pToolbar->GetToolBarCtrl().GetButtonSize()); CRect rButton; m_pToolbar->GetToolBarCtrl().GetRect(nID, rButton); rButton.left += sizeBtn.cx; if (rButton.PtInRect(*pPoint)) { bOverDropBtn = TRUE; } } CString sTip; // do we have a mapping for this THButton dm; if (m_mapTHButtons.Lookup(nID, dm)) { if (!bOverDropBtn) { // try the default item first if (dm.nDefCmdID && IsCmdEnabled(dm.nDefCmdID)/* && (dm.nDefCmdID != nID)*/) { sTip = GetTip(dm.nDefCmdID); if (!sTip.IsEmpty()) { return sTip; } } } // try override tip if (_tcslen(dm.szTip)) { return dm.szTip; } } return GetTip(nID); }
//----------------------------------------------------------------------------- // Purpose: Returns a random tip, selected from tips for all classes //----------------------------------------------------------------------------- const wchar_t *CFRTips::GetRandomTip() { Init(); // pick a random tip int iTip = RandomInt( 0, m_iTipCountAll-1 ); return GetTip(iTip + 1); }
wxString clEditorTipWindow::GetText() { clCallTipPtr tip = GetTip(); if(tip) { return tip->All(); } return wxT(""); }
void clEditorTipWindow::SelectPrev(int argIdxToHilight) { clCallTipPtr tip = GetTip(); if(tip) { m_tipText = tip->Prev(); m_highlighIndex = argIdxToHilight; DoLayoutTip(); } }
int32 ToolTip::Tool_Thread(){ BPoint loc; BPoint oldloc; ulong button; int32 count = 0; BView *v = NULL; // Wait until the BApplication becomes valid, in case // someone creates this as a global variable. while(!be_app_messenger.IsValid()){ snooze(200000); } // while the app is valid, run. This is a // easy way to let the thread natually die while(be_app_messenger.IsValid()){ if(ttWin->Lock()){ ttWin->ChildAt(0)->GetMouse(&loc, &button); ttWin->ConvertToScreen(&loc); if((loc == oldloc) && !button){ if(count == 5){ if(ttWin->IsHidden()){ BPoint tr = loc; v = FindView(tr); const char *tip = NULL; while(v && (tip = GetTip(v)) == NULL){ v = v->Parent(); } if(tip){ if(tip && strcmp(tip,"")){ ttWin->Tip(loc,tip); }else{ //ttWin->Tip(loc,"whats up with the No tip haven tool?"); } } } }else{ count++; } }else{ count = 0; if(!(ttWin->IsHidden())){ ttWin->Bye(); } } oldloc = loc; ttWin->Unlock(); //snooze(250000); snooze(150000); }else{ snooze(1000000); } } return B_OK; }
void clEditorTipWindow::Highlight(int argIdxToHilight) { clCallTipPtr tip = GetTip(); if(tip) { m_tipText = tip->Current(); m_highlighIndex = argIdxToHilight; DoLayoutTip(); } else { Deactivate(); } }
// ------------------------------------------------------------ // TOOL TIPS // // ajouter dans le .cpp: // remplacer les deux Wid1:: par le nom de la classe:: // dans la message map, ajouter // ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify ) // dans initdialog ajouter // EnableToolTips(true); // TOOL TIPS // // ajouter dans le .h: // char* GetTip(int id); // et en generated message map // afx_msg BOOL OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult ); BOOL COptionTab9::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult ) { TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR; UINT_PTR nID =pNMHDR->idFrom; if (pTTT->uFlags & TTF_IDISHWND) { // idFrom is actually the HWND of the tool nID = ::GetDlgCtrlID((HWND)nID); if(nID) { char* st=GetTip((int)nID); if (st != "") { pTTT->lpszText = st; pTTT->hinst = AfxGetResourceHandle(); return(TRUE); } } } return(FALSE); }
void DTipWatcherView::Pulse(void) { // Check to see if there has been any activity. If so, just reset. BPoint pt; uint32 buttons; GetMouse(&pt,&buttons); ConvertToScreen(&pt); if (pt != fLastPoint || buttons) { fDelayCounter = 0; fLastPoint = pt; HideTip(); return; } fLastPoint = pt; if (!Window()->IsHidden()) return; fDelayCounter += Window()->PulseRate(); if (fDelayCounter < fDelayMax) return; // We got this far, so it's time to show a tip BView *view = ViewForPoint(pt); if (!view) return; BString text = GetTip(view); if (text.CountChars() < 1) return; ShowTip(pt, text.String()); }
LRESULT CToolbarHelper::WindowProc(HWND hRealWnd, UINT msg, WPARAM wp, LPARAM lp) { switch (msg) { case WM_NOTIFY: { LPNMHDR pNMHDR = (LPNMHDR)lp; switch (pNMHDR->code) { case TBN_DROPDOWN: // check its our toolbar if (pNMHDR->hwndFrom == m_pToolbar->GetSafeHwnd()) { // load the menu LPNMTOOLBAR pNMTB = (LPNMTOOLBAR)pNMHDR; if (DisplayDropMenu((UINT)pNMTB->iItem)) return FALSE; // we handled it } break; #ifndef _UNICODE case TTN_NEEDTEXTA: #else case TTN_NEEDTEXTW: #endif { // to be thorough we will need to handle UNICODE versions of the message also !! TOOLTIPTEXT* pTTT = (TOOLTIPTEXT*)pNMHDR; // only handle this if it's not already been done if (pTTT->lpszText && *(pTTT->lpszText)) break; UINT nID = pNMHDR->idFrom; if (pTTT->uFlags & TTF_IDISHWND) // idFrom is actually the HWND of the tool nID = ::GetDlgCtrlID((HWND)nID); // get cursor pos CPoint point(::GetMessagePos()); m_pToolbar->ScreenToClient(&point); // get tip static CString sTipText; sTipText = GetTip(nID, &point); if (!sTipText.IsEmpty()) // will be zero on a separator { pTTT->lpszText = (LPTSTR)(LPCTSTR)sTipText; return TRUE; } } break; case TTN_SHOW: { CWnd* pTooltipCtrl = CWnd::FromHandle(pNMHDR->hwndFrom); ASSERT (pTooltipCtrl); pTooltipCtrl->SendMessage(TTM_SETMAXTIPWIDTH, 0, (m_bMultiline ? m_nMultilineWidth : UINT_MAX)); if (m_pShortcutMgr) { static UINT nIDLastShow = 0; UINT nCmdID = pNMHDR->idFrom; // prevent re-entrancy on same tip if (nCmdID != nIDLastShow) { TOOLINFO ti = { 0 }; ti.cbSize = sizeof(ti); ti.hwnd = *m_pToolbar; // restore callback on last shown item if (nIDLastShow) { ti.uId = nIDLastShow; pTooltipCtrl->SendMessage(TTM_GETTOOLINFO, 0, (LPARAM)&ti); ti.lpszText = LPSTR_TEXTCALLBACK; pTooltipCtrl->SendMessage(TTM_SETTOOLINFO, 0, (LPARAM)&ti); nIDLastShow = 0; } // append shortcut text to new item THButton dm = { 0 }; if (m_mapTHButtons.Lookup(nCmdID, dm)) { if (dm.nDefCmdID) nCmdID = dm.nDefCmdID; } CString sShortcut = m_pShortcutMgr->GetShortcutTextByCmd(nCmdID); if (!sShortcut.IsEmpty()) { // store original id immediately to prevent re-entrancy nIDLastShow = pNMHDR->idFrom; const int TIP_LEN = 80; TCHAR szTip[TIP_LEN] = { 0 }; ti.lpszText = szTip; ti.hwnd = *m_pToolbar; ti.uId = pNMHDR->idFrom; pTooltipCtrl->SendMessage(TTM_GETTEXT, TIP_LEN, (LPARAM)&ti); CString sTip; sTip.Format(_T("%s (%s)"), szTip, sShortcut); ti.lpszText = (LPTSTR)(LPCTSTR)sTip; pTooltipCtrl->SendMessage(TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); pTooltipCtrl->SendMessage(TTM_UPDATE); } } } } break; } } break; case WM_COMMAND: { HWND hCtrlFrom = (HWND)lp; // if m_pToolbar sent the command and we have a mapping for it then // change it to the default cmd for that button if (hCtrlFrom == *m_pToolbar) { THButton dm = { 0 }; UINT nCmdID = LOWORD(wp); if (m_mapTHButtons.Lookup(nCmdID, dm)) { // if we have an enabled default command then send it if (dm.nDefCmdID && IsCmdEnabled(dm.nDefCmdID)) { wp = MAKEWPARAM(dm.nDefCmdID, HIWORD(wp)); } else { BOOL bRes = DisplayDropMenu(nCmdID, TRUE); if (bRes) return 0L; // we handled it } } } } break; case WM_DESTROY: { // must call rest of chain first LRESULT lr = CSubclassWnd::WindowProc(hRealWnd, msg, wp, lp); HookWindow(NULL); return lr; } } return CSubclassWnd::WindowProc(hRealWnd, msg, wp, lp); }
void clEditorTipWindow::OnPaint(wxPaintEvent& e) { wxUnusedVar(e); wxBufferedPaintDC dc(this); wxGCDC gdc; if ( !DrawingUtils::GetGCDC(dc, gdc) ) return; wxColour bgColour = DrawingUtils::GetThemeTipBgColour(); wxColour penColour = DrawingUtils::GetThemeBorderColour(); bool isDarkTheme = DrawingUtils::IsDark(bgColour); wxUnusedVar(isDarkTheme); wxRect rr = GetClientRect(); // draw the background using the parent background colour gdc.SetBrush(bgColour); gdc.SetPen (penColour); gdc.DrawRectangle(rr); gdc.SetFont(m_font); // Highlight the text clCallTipPtr tip = GetTip(); int secondLineY = (rr.GetHeight()/2) + 1; int firstLineY = TIP_SPACER; // Draw the Tip text gdc.SetFont(m_font); gdc.SetTextForeground( EditorConfigST::Get()->GetCurrentOutputviewFgColour() ); gdc.DrawText(m_tipText, wxPoint(TIP_SPACER, firstLineY)); if(tip) { wxString txt; txt << tip->GetCurr()+1 << wxT(" of ") << tip->Count(); int txtLen = DoGetTextLen(gdc, txt); int summaryLineXText (rr.GetWidth()); summaryLineXText -= (txtLen + TIP_SPACER); // Draw the summary line gdc.SetFont(m_font); gdc.SetTextForeground( DrawingUtils::GetThemeTextColour() ); gdc.DrawText(txt, summaryLineXText, secondLineY + TIP_SPACER/2); int start(-1), len(-1); tip->GetHighlightPos(m_highlighIndex, start, len); if(len != -1 && start != -1 ) { wxString txtBefore = m_tipText.Mid(0, start); wxString txtInclude = m_tipText.Mid(start, len); int x = DoGetTextLen(gdc, txtBefore); int w = DoGetTextLen(gdc, txtInclude); wxColour bodyColour, borderColour; wxColour base = *wxBLUE; bodyColour = base.ChangeLightness(180); borderColour = base.ChangeLightness(150); if ( isDarkTheme ) { gdc.SetBrush( *wxTRANSPARENT_BRUSH ); gdc.SetPen( borderColour ); gdc.DrawRoundedRectangle(x + TIP_SPACER - 1, firstLineY-(TIP_SPACER/2), w + 2, (rr.GetHeight()/2), 3.5); } else { gdc.SetBrush( bodyColour ); gdc.SetPen( borderColour ); gdc.DrawRoundedRectangle(x + TIP_SPACER - 1, firstLineY-(TIP_SPACER/2), w + 2, (rr.GetHeight()/2), 3.5); wxFont f = m_font; f.SetWeight(wxFONTWEIGHT_BOLD); gdc.SetFont(f); gdc.DrawText(txtInclude, wxPoint(x + TIP_SPACER, firstLineY)); } } } }
void clEditorTipWindow::OnPaint(wxPaintEvent& e) { wxUnusedVar(e); wxBufferedPaintDC dc(this); wxGCDC gdc; if(!DrawingUtils::GetGCDC(dc, gdc)) return; // Define the colours used by this tooltip window wxColour bgColour, penColour, textColour, higlighTextBg, higlighTextFg, higlighTextPen; bgColour = wxColour("#feffcd"); // basic colour penColour = bgColour.ChangeLightness(80); textColour = wxColour("#000023"); higlighTextBg = wxColour("rgb(204, 153, 0)"); higlighTextPen = higlighTextBg; higlighTextFg = *wxWHITE; wxRect rr = GetClientRect(); // draw the background using the parent background colour gdc.SetBrush(bgColour); gdc.SetPen(penColour); gdc.DrawRectangle(rr); gdc.SetFont(m_font); // Highlight the text clCallTipPtr tip = GetTip(); int secondLineY = (rr.GetHeight() / 2) + 1; int firstLineY = TIP_SPACER; // Draw the Tip text gdc.SetTextForeground(textColour); gdc.DrawText(m_tipText, wxPoint(TIP_SPACER, firstLineY)); if(tip) { bool twoLinesTip = (tip->Count() > 1); wxString txt; if(twoLinesTip) { txt << tip->GetCurr() + 1 << wxT(" of ") << tip->Count(); int txtLen = DoGetTextLen(gdc, txt); int summaryLineXText(rr.GetWidth()); summaryLineXText -= (txtLen + TIP_SPACER); // Draw the summary line gdc.SetTextForeground(textColour); gdc.DrawText(txt, summaryLineXText, secondLineY + TIP_SPACER / 2); } int start(-1), len(-1); tip->GetHighlightPos(m_highlighIndex, start, len); if(len != -1 && start != -1) { wxString txtBefore = m_tipText.Mid(0, start); wxString txtInclude = m_tipText.Mid(start, len); int x = DoGetTextLen(gdc, txtBefore); int w = DoGetTextLen(gdc, txtInclude); // darken the background colour and use it as the highlight colour gdc.SetBrush(higlighTextBg); gdc.SetPen(higlighTextPen); gdc.SetTextForeground(higlighTextFg); // if this is a 2 liner tip, the highlight rect is 1/2 the tip window height, // otherwise its the same as the height int highlightRectHeight = twoLinesTip ? (rr.GetHeight() / 2) : rr.GetHeight(); int highlightRectY = twoLinesTip ? firstLineY - (TIP_SPACER / 2) : 0; gdc.DrawRoundedRectangle(x + TIP_SPACER - 1, highlightRectY, w + 2, highlightRectHeight, 0); gdc.DrawText(txtInclude, wxPoint(x + TIP_SPACER, firstLineY)); } } }
LRESULT CToolbarHelper::WindowProc(HWND hRealWnd, UINT msg, WPARAM wp, LPARAM lp) { switch (msg) { case WM_NOTIFY: { LPNMHDR pNMHDR = (LPNMHDR)lp; switch (pNMHDR->code) { case TBN_DROPDOWN: // check its our toolbar if (pNMHDR->hwndFrom == m_pToolbar->GetSafeHwnd()) { // load the menu LPNMTOOLBAR pNMTB = (LPNMTOOLBAR)pNMHDR; if (DisplayDropMenu((UINT)pNMTB->iItem)) { return FALSE; // we handled it } } break; case TTN_NEEDTEXT: { // to be thorough we will need to handle UNICODE versions of the message also !! TOOLTIPTEXT* pTTT = (TOOLTIPTEXT*)pNMHDR; UINT nID = pNMHDR->idFrom; if (pTTT->uFlags & TTF_IDISHWND) // idFrom is actually the HWND of the tool { nID = ::GetDlgCtrlID((HWND)nID); } // get cursor pos CPoint point(::GetMessagePos()); m_pToolbar->ScreenToClient(&point); // get tip static CString sTipText; sTipText = GetTip(nID, &point); if (!sTipText.IsEmpty()) // will be zero on a separator { pTTT->lpszText = (LPTSTR)(LPCTSTR)sTipText; return TRUE; } } break; case TTN_SHOW: { CWnd* pTooltipCtrl = CWnd::FromHandle(pNMHDR->hwndFrom); ASSERT(pTooltipCtrl); pTooltipCtrl->SendMessage(TTM_SETMAXTIPWIDTH, 0, m_bMultiline ? m_nMultilineWidth : UINT_MAX); } break; } } break; case WM_COMMAND: { HWND hCtrlFrom = (HWND)lp; // if m_pToolbar sent the command and we have a mapping for it then // change it to the default cmd for that button if (hCtrlFrom == *m_pToolbar) { THButton dm; UINT nCmdID = LOWORD(wp); if (m_mapTHButtons.Lookup(nCmdID, dm)) { // if we have an enabled default command then send it if (dm.nDefCmdID && IsCmdEnabled(dm.nDefCmdID)) { wp = MAKEWPARAM(dm.nDefCmdID, HIWORD(wp)); } else { BOOL bRes = DisplayDropMenu(nCmdID, TRUE); if (bRes) { return 0L; // we handled it } } } } } break; case WM_KICKIDLE: break; case WM_DESTROY: { // must call rest of chain first LRESULT lr = CSubclassWnd::WindowProc(hRealWnd, msg, wp, lp); HookWindow(NULL); return lr; } } return CSubclassWnd::WindowProc(hRealWnd, msg, wp, lp); }