void ClueListBox::OnDrawItem(wxDC & dc, const wxRect & rect, size_t n) const { wxRect numRect(rect); numRect.SetWidth(m_numWidth); wxRect textRect(rect); textRect.SetX(numRect.GetRight() + GetMargins().x); textRect.SetWidth(rect.width - GetMargins().x); // Get fonts and colors dc.SetFont(GetFont()); if (IsSelected(n)) dc.SetTextForeground(GetSelectionForeground()); else dc.SetTextForeground(GetForegroundColour()); XPuzzle::Clue clue = GetItem(n); dc.DrawLabel(wxString::Format(_T("%d."), clue.Number()), numRect, wxALIGN_RIGHT|wxALIGN_TOP); wxASSERT(! m_cachedClues.at(n).empty()); dc.DrawLabel(m_cachedClues.at(n), textRect); //dc.DrawLine(textRect.x, textRect.y, textRect.x + textRect.width, textRect.y + textRect.height); }
// /// Constructs a TControlBar interface object with the specified direction (either /// horizontal or vertical) and window font. // TControlBar::TControlBar(TWindow* parent, TTileDirection direction, TFont* font, TModule* module) : TGadgetWindow(parent, direction, font, module) { GetMargins().Units = TMargins::BorderUnits; if (GetDirection() == Horizontal){ GetMargins().Left = GetMargins().Right = TUIMetric::CxFixedFrame; GetMargins().Top = GetMargins().Bottom = TUIMetric::CyFixedFrame; } else { GetMargins().Left = GetMargins().Right = TUIMetric::CxFixedFrame; GetMargins().Top = GetMargins().Bottom = TUIMetric::CyFixedFrame; } // Margins.Left = Margins.Right = TUIMetric::CxSizeFrame + 2; // (6) fixed? // Margins.Top = Margins.Bottom = TUIMetric::CyFixedFrame; // (2) fixed? // Toolbars default to having tooltips // SetWantTooltip(true); TRACEX(OwlWin, OWL_CDLEVEL, "TControlBar constructed @" << (void*)this); }
wxPoint wxHtmlListBox::GetRootCellCoords(size_t n) const { wxPoint pos(CELL_BORDER, CELL_BORDER); pos += GetMargins(); pos.y += GetRowsHeight(GetVisibleBegin(), n); return pos; }
void wxHtmlListBox::CacheItem(size_t n) const { if ( !m_cache->Has(n) ) { if ( !m_htmlParser ) { wxHtmlListBox *self = wxConstCast(this, wxHtmlListBox); self->m_htmlParser = new wxHtmlWinParser(self); m_htmlParser->SetDC(new wxClientDC(self)); m_htmlParser->SetFS(&self->m_filesystem); #if !wxUSE_UNICODE if (GetFont().IsOk()) m_htmlParser->SetInputEncoding(GetFont().GetEncoding()); #endif // use system's default GUI font by default: m_htmlParser->SetStandardFonts(); } wxHtmlContainerCell *cell = (wxHtmlContainerCell *)m_htmlParser-> Parse(OnGetItemMarkup(n)); wxCHECK_RET( cell, wxT("wxHtmlParser::Parse() returned NULL?") ); // set the cell's ID to item's index so that CellCoordsToPhysical() // can quickly find the item: cell->SetId(wxString::Format(wxT("%lu"), (unsigned long)n)); cell->Layout(GetClientSize().x - 2*GetMargins().x); m_cache->Store(n, cell); } }
void ContentBoxCtrol::CacheItem(size_t n) const { if ( !m_cache->Has(n) ) { if ( !m_htmlParser ) { ContentBoxCtrol *self = wxConstCast(this, ContentBoxCtrol); self->m_htmlParser = LENMUS_NEW wxHtmlWinParser(self); LMB_TagHandler* pTagHandler = LENMUS_NEW LMB_TagHandler(m_appScope); m_htmlParser->AddTagHandler(pTagHandler); m_htmlParser->SetDC(LENMUS_NEW wxClientDC(self)); m_htmlParser->SetFS(&self->m_filesystem); // use system's default GUI font by default: m_htmlParser->SetFontFace("Tahoma"); m_htmlParser->SetFontSize(10); //m_htmlParser->SetStandardFonts(); } wxHtmlContainerCell *cell = (wxHtmlContainerCell *)m_htmlParser-> Parse(OnGetItemMarkup(n)); wxCHECK_RET( cell, "wxHtmlParser::Parse() returned NULL?" ); // set the cell's ID to item's index so that CellCoordsToPhysical() // can quickly find the item: cell->SetId(wxString::Format("%lu", (unsigned long)n)); cell->Layout(GetClientSize().x - 2*GetMargins().x); m_cache->Store(n, cell); } }
void wxOwnerDrawnComboBox::OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const { if ( flags & wxODCB_PAINTING_CONTROL ) { wxString text; if ( !ShouldUseHintText() ) { text = GetValue(); } else { text = GetHint(); wxColour col = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT); dc.SetTextForeground(col); } dc.DrawText( text, rect.x + GetMargins().x, (rect.height-dc.GetCharHeight())/2 + rect.y ); } else { dc.DrawText( GetVListBoxComboPopup()->GetString(item), rect.x + 2, rect.y ); } }
void ODIconCombo::OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const { int offset_x = bmpArray.Item(item).GetWidth(); int bmpHeight = bmpArray.Item(item).GetHeight(); dc.DrawBitmap(bmpArray.Item(item), rect.x, rect.y + (rect.height - bmpHeight)/2, true); if ( flags & wxODCB_PAINTING_CONTROL ) { wxString text = GetValue(); int margin_x = 2; #if wxCHECK_VERSION(2, 9, 0) if ( ShouldUseHintText() ) { text = GetHint(); wxColour col = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT); dc.SetTextForeground(col); } margin_x = GetMargins().x; #endif dc.DrawText( text, rect.x + margin_x + offset_x, (rect.height-dc.GetCharHeight())/2 + rect.y ); } else { dc.DrawText( GetVListBoxComboPopup()->GetString(item), rect.x + 2 + offset_x, (rect.height-dc.GetCharHeight())/2 + rect.y ); } }
bool CListViewDialog::OnSize(WPARAM /* wParam */, int xSize, int ySize) { int mx, my; GetMargins(8, mx, my); int bx1, bx2, by; GetItemSizes(IDCANCEL, bx1, by); GetItemSizes(IDOK, bx2, by); int y = ySize - my - by; int x = xSize - mx - bx1; /* RECT rect; GetClientRect(&rect); rect.top = y - my; InvalidateRect(&rect); */ InvalidateRect(NULL); MoveItem(IDCANCEL, x, y, bx1, by); MoveItem(IDOK, x - mx - bx2, y, bx2, by); /* if (wParam == SIZE_MAXSHOW || wParam == SIZE_MAXIMIZED || wParam == SIZE_MAXHIDE) mx = 0; */ _listView.Move(mx, my, xSize - mx * 2, y - my * 2); return false; }
// /// Overrides TGadget's GetDesiredSize function and computes the size of the cell by /// calling GetMargins to get the margins. // void TToolBox::GetDesiredSize(TSize& size) { // Get border sizes // int cxBorder = 0; int cyBorder = 0; int left, right, top, bottom; GetMargins(Margins, left, right, top, bottom); size.cx = left + right; size.cy = top + bottom; // Add in this window's border size if used // if (Attr.Style & WS_BORDER) { size.cx += 2 * TUIMetric::CxBorder; size.cy += 2 * TUIMetric::CyBorder; } TSize cellSize; ComputeCellSize(cellSize); int numRows, numColumns; ComputeNumRowsColumns(numRows, numColumns); size.cx += numColumns * cellSize.cx; size.cy += numRows * cellSize.cy; // Compensate for the gadgets overlapping if UI style does that // size.cx -= (numColumns - 1) * cxBorder; size.cy -= (numRows - 1) * cyBorder; }
wxCoord ClueListBox::OnMeasureItem(size_t n) const { XPuzzle::Clue clue = GetItem(n); // Cache the wrapped clue's text if it isn't already if (m_cachedClues.at(n).empty()) { int maxWidth; GetClientSize(&maxWidth, NULL); m_cachedClues.at(n) = Wrap(this, clue.Text(), maxWidth - m_numWidth - GetMargins().x); } int height = 0; const wxArrayString lines = wxStringTokenize(m_cachedClues.at(n), _T("\n")); for (wxArrayString::const_iterator it = lines.begin(); it != lines.end(); ++it) { int lineHeight; GetTextExtent(*it, NULL, &lineHeight); height += lineHeight; } return height; }
bool CDEditor::AdjustRect(CRect& rect) { CRect rcOld=rect; CPoint point = rect.TopLeft(); CSize size = rect.Size(); CSize sizeVt = GetVirtualSize(); int restraint = GetRestraints(); if (RESTRAINT_NONE != restraint) { int left=0,top=0,right=sizeVt.cx,bottom=sizeVt.cy; // m_restraint == RESTRAINT_VIRTUAL if (restraint == RESTRAINT_MARGIN) { GetMargins(left,top,right,bottom); right = sizeVt.cx - right; bottom = sizeVt.cy - bottom; } point.x = min(max(left,point.x),right-size.cx); point.y = min(max(top,point.y),bottom-size.cy); } if (GetSnapToGrid()) { point.x = SnapX(point.x); point.y = SnapY(point.y); } rect.SetRect(point,point+size); return rcOld==rect; }
BOOL CMagneticView::LineFull(CDC* pDC, LPCSTR lpszText, int iLength) { CSize TextLen = pDC->GetTextExtent(lpszText,iLength); CRect Client; GetClientRect(Client); return (TextLen.cx >= (Client.Width()-(2*GetMargins().cx))) ? 1 : 0; }
wxPoint ContentBoxCtrol::GetRootCellCoords(size_t n) const { wxPoint pos(CELL_BORDER, CELL_BORDER); pos += GetMargins(); //pos.y += GetRowHeight(GetVisibleRowsBegin(), n); pos.y += GetRowsHeight(GetVisibleBegin(), n); return pos; }
wxSize wxComboBox::DoGetSizeFromTextSize(int xlen, int ylen) const { wxSize tsize( wxChoice::DoGetSizeFromTextSize(xlen, ylen) ); if ( !HasFlag(wxCB_READONLY) ) { // Add the margins we have previously set wxPoint marg( GetMargins() ); marg.x = wxMax(0, marg.x); marg.y = wxMax(0, marg.y); tsize.IncBy( marg ); } return tsize; }
void CMagneticView::SetCursorPos(CDC* pDC, int iRight) { int i = m_PageTable.GetSize()-2; // Start of the last visible line if (m_bMorePrompt) { int offset = m_iLines-m_iMaxLines-1; if (offset > 0) i -= offset; } if (i >= 0) { CSize TextLen = pDC->GetTextExtent((LPCTSTR)m_strOutput+m_PageTable[i], m_PageTable[i+1]-m_PageTable[i]-1-iRight); // Set the caret position SetCaretPos(CPoint(TextLen.cx+GetMargins().cx,m_LastLineRect.top)); } }
void CMagneticView::OnDraw(CDC* pDrawDC) { CMagneticApp* pApp = (CMagneticApp*)AfxGetApp(); // Don't draw anything if there isn't a loaded game if (pApp->GetGameLoaded() == 0) return; CDC BitmapDC; BitmapDC.CreateCompatibleDC(pDrawDC); CRect Client; GetClientRect(Client); CBitmap Bitmap; CSize Size(Client.Width(),Client.Height()); Bitmap.CreateCompatibleBitmap(pDrawDC,Size.cx,Size.cy); CBitmap* pOldBitmap = BitmapDC.SelectObject(&Bitmap); // Set up the font CFont* pOldFont = NULL; TEXTMETRIC FontInfo; pOldFont = BitmapDC.SelectObject(m_pTextFont); BitmapDC.GetTextMetrics(&FontInfo); int iFontHeight = (int)(FontInfo.tmHeight*1.1); int iPicWidth = 0; int iPicHeight = 0; CRect TextClient(Client); CSize Margins(GetMargins()); if (m_bStatusBar) { TextClient.top += iFontHeight; // Display the status line LONG lStatSpace = (LONG)(Client.Width()*0.075); SolidRect(&BitmapDC,CRect(Client.left,0,Client.right,iFontHeight), pApp->GetForeColour()); BitmapDC.SetTextColor(pApp->GetBackColour()); BitmapDC.SetBkColor(pApp->GetForeColour()); BitmapDC.TextOut(lStatSpace,0,m_strStatLocation,m_strStatLocation.GetLength()); BitmapDC.TextOut(lStatSpace*10,0,m_strStatScore,m_strStatScore.GetLength()); } // If the picture is to be drawn in the main window, leave enough // space and draw both background and picture if (pApp->GetShowGraphics() == CMagneticApp::ShowGraphics::MainWindow) { int dpi = DPI::getWindowDPI(this); iPicWidth = m_Picture.GetScaledWidth(dpi); iPicHeight = m_Picture.GetScaledHeight(dpi); if (iPicWidth > 0 && iPicHeight > 0) { TextClient.top += iPicHeight; int iOffset = m_bStatusBar ? iFontHeight : 0; BitmapDC.FillSolidRect(Client.left,Client.top+iOffset,Client.Width(), iPicHeight,pApp->GetGfxColour()); CRect PicArea((Client.Width()-iPicWidth)/2,iOffset, (Client.Width()+iPicWidth)/2,iOffset+iPicHeight); m_Picture.Paint(&BitmapDC,PicArea,m_AnimFrames); } } BitmapDC.FillSolidRect(TextClient,pApp->GetBackColour()); int y = TextClient.top; // Repaginate if necessary TrimOutput(); if (m_PageTable.GetSize() == 0) { Paginate(&BitmapDC,0,0); if (m_bMorePrompt) m_PageTable.RemoveAt(m_PageTable.GetSize()-1); } LPCSTR lpszOutput = m_strOutput; BitmapDC.SetTextColor(pApp->GetForeColour()); BitmapDC.SetBkColor(pApp->GetBackColour()); // Work out the number of lines of text to draw m_iMaxLines = (TextClient.Height()-(2*Margins.cy)) / iFontHeight; y += Margins.cy; // Starting position in the text output buffer int i = m_PageTable.GetSize() - m_iMaxLines - 1; // Adjust for a More... prompt int offset = 0; if (m_bMorePrompt) { if (iPicWidth > 0 && iPicHeight > 0) { if (m_iLines > m_iMaxLines) { if (m_iLines - m_iMaxLines - 1 > 0) { offset = m_iLines - m_iMaxLines - 1; i -= offset; } } } } if (i < 0) i = 0; // Draw the text int iCount = 0; while (i < m_PageTable.GetSize()-1-offset) { iCount = m_PageTable[i+1]-m_PageTable[i]-1; if (iCount > 0) { if (*(lpszOutput+m_PageTable[i]+iCount-1) == '\0') iCount--; } BitmapDC.TextOut(Margins.cx,y,lpszOutput+m_PageTable[i],iCount); y += iFontHeight; i++; } // Store information on the last line for updating later CRect LastLine(0,y-iFontHeight,TextClient.Width(),y); m_LastLineRect = LastLine; // Clear the end of the last line to allow input editing if (i > 0) { CSize TextLen = BitmapDC.GetTextExtent(lpszOutput+m_PageTable[i-1], m_PageTable[i]-m_PageTable[i-1]-1); LastLine.left += TextLen.cx + Margins.cx; SolidRect(&BitmapDC,LastLine,pApp->GetBackColour()); } // Remove the font BitmapDC.SelectObject(pOldFont); pDrawDC->BitBlt(0,0,Size.cx,Size.cy,&BitmapDC,0,0,SRCCOPY); BitmapDC.SelectObject(pOldBitmap); }
/*---------------------------------------------------------------------------------------------- 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); }