wxSize wxBannerWindow::DoGetBestClientSize() const { if ( m_bitmap.IsOk() ) { return m_bitmap.GetSize(); } else { wxClientDC dc(const_cast<wxBannerWindow *>(this)); const wxSize sizeText = dc.GetMultiLineTextExtent(m_message); dc.SetFont(GetTitleFont()); const wxSize sizeTitle = dc.GetTextExtent(m_title); wxSize sizeWin(wxMax(sizeTitle.x, sizeText.x), sizeTitle.y + sizeText.y); // If we draw the text vertically width and height are swapped. if ( m_direction == wxLEFT || m_direction == wxRIGHT ) wxSwap(sizeWin.x, sizeWin.y); sizeWin += 2*wxSize(MARGIN_X, MARGIN_Y); return sizeWin; } }
//: Returns width and postion of the title. //!param: width - In this parameter the available space //!param: for the title is returned. //!param: pos - In this parameter the position for the //!param: title is returned. void CMDITitleView::GetTitleWidthAndPos(float &width, BPoint &pos) { BFont titleFont; GetTitleFont(&titleFont); font_height titleFontHeight; titleFont.GetHeight(&titleFontHeight); width = Bounds().Width() - distFromMaximizeBox - distFromCloseBox; if(DisplayCloseButton()) { pos.x = CloseButtonRect().right + distFromCloseBox; width -= CloseButtonRect().right; } else { pos.x = distFromCloseBox; } if(DisplayMaximizeButton()) { width -= MaximizeButtonRect().Width() - distFromRightBorder; } pos.y = titleFontHeight.ascent + 3; }
void wxBannerWindow::OnPaint(wxPaintEvent& WXUNUSED(event)) { if ( m_bitmap.IsOk() && m_title.empty() && m_message.empty() ) { // No need for buffering in this case. wxPaintDC dc(this); DrawBitmapBackground(dc); } else // We need to compose our contents ourselves. { wxAutoBufferedPaintDC dc(this); // Deal with the background first. if ( m_bitmap.IsOk() ) { DrawBitmapBackground(dc); } else // Draw gradient background. { wxDirection gradientDir; if ( m_direction == wxLEFT ) { gradientDir = wxTOP; } else if ( m_direction == wxRIGHT ) { gradientDir = wxBOTTOM; } else // For both wxTOP and wxBOTTOM. { gradientDir = wxRIGHT; } dc.GradientFillLinear(GetClientRect(), m_colStart, m_colEnd, gradientDir); } // Now draw the text on top of it. dc.SetFont(GetTitleFont()); wxPoint pos(MARGIN_X, MARGIN_Y); DrawBannerTextLine(dc, m_title, pos); pos.y += dc.GetTextExtent(m_title).y; dc.SetFont(GetFont()); wxArrayString lines = wxSplit(m_message, '\n', '\0'); const unsigned numLines = lines.size(); for ( unsigned n = 0; n < numLines; n++ ) { const wxString& line = lines[n]; DrawBannerTextLine(dc, line, pos); pos.y += dc.GetTextExtent(line).y; } } }
void wxPaneBase::CalcHeaderSize() { // header size calculation wxFont font = GetTitleFont(); int cyFont = font.GetPointSize() + (HEADER_BORDER*2); int cyBtn = m_toolButtonSize.y + (HEADER_BORDER*2); // which is largest, text height or button height? m_headerSize = max( cyFont, cyBtn ); }
void wxPaneBase::OnPaint( wxPaintEvent& WXUNUSED(event) ) { wxPaintDC dc(this); int headerSize = GetHeaderSize(); // draw header wxRect hr = GetClientRect(); if( m_orientation == wxVERTICAL ) { hr.SetRight( hr.x + headerSize ); } else { hr.SetBottom( hr.y + headerSize ); } // create a clipping region to exclude the close button if( m_pCloseButton && m_showClosebutton ) { dc.DestroyClippingRegion(); wxRegion region( hr ); wxRect sr = m_pCloseButton->GetRect(); region.Subtract( sr ); dc.SetClippingRegion( region ); } g_gdi.DrawHeader( dc, hr, m_orientation, GetName(), GetTitleFont() ); // draw contents wxRect cr = GetClientRect(); if( m_orientation == wxVERTICAL ) { cr.x += headerSize; } else { cr.y += headerSize; } // create a clipping region to exclude the child window dc.DestroyClippingRegion(); wxRegion region( cr ); if( m_pClient ) { wxRect sr = m_pClient->GetRect(); region.Subtract( sr ); } dc.SetClippingRegion( region ); g_gdi.DrawEmptyWorkspace( dc, cr, true ); }
//: Returns the preferred size of this view. // The width and height depend on the depend on the width and height of // the title. The method ensures thate the title tab never gets broader than // its target. void CMDITitleView::GetPreferredSize(float *width, float *height) { BFont titleFont; font_height fh; GetTitleFont(&titleFont); titleFont.GetHeight(&fh); *height = MAX(fh.ascent + fh.descent, CloseButtonRect().Height()) + distFromTopBorder + distFromBottomBorder; float totalWidth; totalWidth = titleFont.StringWidth(target->Title()) + distFromCloseBox + distFromMaximizeBox + distFromRightBorder + distFromLeftBorder + CloseButtonRect().Width() + MaximizeButtonRect().Width() + 1; *width = MIN(totalWidth, target->Bounds().Width()); }
//: BeOS hook function // Draws a BeOS style title tab. This method class the two attached // decorations to draw the maximize and close buttons. void CMDITitleView::Draw(BRect updateRect) { Window()->BeginViewTransaction(); // --- Calc colors CColor background = BackgroundColor(); CColor highlight( MIN(background.red+80, 255), MIN(background.green+80, 255), MIN(background.blue+80, 255) ); CColor darkShadow( MAX(background.red-81, 0), MAX(background.green-81, 0), MAX(background.blue-81, 0) ); CColor textColor = Active() ? CColor::Black : CColor(80, 80, 80); // --- Fill background SetHighColor(background); FillRect(updateRect); // --- Draw borders BRect bounds = Bounds(); float width = bounds.Width(); float height = bounds.Height(); SetHighColor(CColor::BeShadow); MovePenTo(0, height); StrokeLine(BPoint(0, 0)); StrokeLine(BPoint(width, 0)); SetHighColor(CColor::BeDarkShadow); MovePenTo(width, 1); StrokeLine(BPoint(width, height)); SetHighColor(highlight); MovePenTo(1, height); StrokeLine(BPoint(1, 1)); StrokeLine(BPoint(width-1, 1)); SetHighColor(darkShadow); MovePenTo(width-1, 2); StrokeLine(BPoint(width-1, height)); // --- Draw close button if(DisplayCloseButton()) { closeButton->SetPosition(CloseButtonRect().LeftTop()); closeButton->SetBackgroundColor(background); closeButton->Draw(); } // --- Draw maximize button if(DisplayMaximizeButton()) { maximizeButton->SetPosition(MaximizeButtonRect().LeftTop()); maximizeButton->SetBackgroundColor(background); maximizeButton->Draw(); } // --- Draw title BFont titleFont; GetTitleFont(&titleFont); const char *title = target->Title(); char *truncatedTitle = new char [strlen(title)+3]; float titleWidth; BPoint titlePos; GetTitleWidthAndPos(titleWidth, titlePos); titleFont.GetTruncatedStrings(&title, 1, B_TRUNCATE_END, titleWidth, &truncatedTitle); SetHighColor(textColor); SetLowColor(background); SetFont(&titleFont); DrawString(truncatedTitle, strlen(truncatedTitle), titlePos); delete [] truncatedTitle; Window()->EndViewTransaction(); }