| 1 |
#include "CaptionBar.h" |
| 2 |
#include "gui.h" |
| 3 |
#include "wxguicraft_main_view.h" |
| 4 |
#include <event_notifier.h> |
| 5 |
#include <wx/dcbuffer.h> |
| 6 |
#include <wx/dcmemory.h> |
| 7 |
#include <wx/renderer.h> |
| 8 |
#include <wx/settings.h> |
| 9 |
|
| 10 |
CaptionBar::CaptionBar(wxWindow* parent, const wxString& caption, const wxString& style, const wxBitmap& icon) |
| 11 |
: CaptionBarBase(parent) |
| 12 |
, m_caption(caption) |
| 13 |
, m_style(style) |
| 14 |
, m_icon(icon) |
| 15 |
{ |
| 16 |
wxMemoryDC memDC; |
| 17 |
wxBitmap bmp(1, 1); |
| 18 |
memDC.SelectObject(bmp); |
| 19 |
memDC.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); |
| 20 |
|
| 21 |
wxSize sz = memDC.GetTextExtent("Tp"); |
| 22 |
SetSizeHints(-1, (sz.y > 22 ? sz.y : 22)); |
| 23 |
} |
| 24 |
|
| 25 |
CaptionBar::~CaptionBar() {} |
| 26 |
void CaptionBar::OnEraseBG(wxEraseEvent& event) { wxUnusedVar(event); } |
| 27 |
|
| 28 |
void CaptionBar::OnPaint(wxPaintEvent& event) |
| 29 |
{ |
| 30 |
wxcImages myImages; |
| 31 |
wxUnusedVar(event); |
| 32 |
wxBufferedPaintDC dc(this); |
| 33 |
wxColour penColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); |
| 34 |
wxColour bgColour1 = wxSystemSettings::GetColour(wxSYS_COLOUR_GRADIENTACTIVECAPTION); |
| 35 |
wxColour bgColour2 = wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION); |
| 36 |
|
| 37 |
PrepareDC(dc); |
| 38 |
|
| 39 |
dc.SetPen(penColour); |
| 40 |
dc.SetBrush(penColour); |
| 41 |
dc.DrawRectangle(GetClientRect()); |
| 42 |
|
| 43 |
// Draw gradient from one side to another |
| 44 |
#ifdef __WXMSW__ |
| 45 |
dc.GradientFillLinear(GetClientRect(), bgColour2, bgColour1); |
| 46 |
|
| 47 |
#elif defined(__WXMAC__) |
| 48 |
bgColour1 = wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW); |
| 49 |
bgColour2 = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW); |
| 50 |
dc.GradientFillLinear(GetClientRect(), bgColour2, bgColour1, wxSOUTH); |
| 51 |
|
| 52 |
#else |
| 53 |
dc.GradientFillLinear(GetClientRect(), bgColour2, bgColour2); |
| 54 |
#endif |
| 55 |
|
| 56 |
wxCoord curx = 5; |
| 57 |
if(m_icon.IsOk()) { |
| 58 |
// Draw the frame icon |
| 59 |
wxCoord bmpy = (GetClientRect().GetHeight() - m_icon.GetHeight()) / 2; |
| 60 |
dc.DrawBitmap(m_icon, 5, bmpy); |
| 61 |
curx += m_icon.GetWidth(); |
| 62 |
curx += 5; // spacer |
| 63 |
} |
| 64 |
|
| 65 |
// Draw the text |
| 66 |
wxColour textColour = wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT); |
| 67 |
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); |
| 68 |
dc.SetFont(font); |
| 69 |
dc.SetTextForeground(textColour); |
| 70 |
|
| 71 |
wxSize textSize = dc.GetTextExtent(m_caption); |
| 72 |
|
| 73 |
wxRect clientRect = GetClientRect(); |
| 74 |
wxCoord texty = (clientRect.GetHeight() - textSize.GetHeight()) / 2; |
| 75 |
dc.DrawText(m_caption, clientRect.GetTopLeft().x + curx, clientRect.GetTopLeft().y + texty); |
| 76 |
|
| 77 |
wxArrayString styles = ::wxStringTokenize(m_style, "|", wxTOKEN_STRTOK); |
| 78 |
bool draw_minimize_button = false; |
| 79 |
bool draw_maximize_button = false; |
| 80 |
bool draw_close_button = false; |
| 81 |
|
| 82 |
int bmpSize = 0; |
| 83 |
|
| 84 |
const wxBitmap& bmpClose = myImages.Bitmap("button_close"); |
| 85 |
if(styles.Index("wxCLOSE_BOX") != wxNOT_FOUND || styles.Index("wxDEFAULT_DIALOG_STYLE") != wxNOT_FOUND || |
| 86 |
styles.Index("wxDEFAULT_FRAME_STYLE") != wxNOT_FOUND) { |
| 87 |
// draw close box |
| 88 |
draw_close_button = true; |
| 89 |
bmpSize += bmpClose.GetWidth(); |
| 90 |
} |
| 91 |
|
| 92 |
if(styles.Index("wxMINIMIZE_BOX") != wxNOT_FOUND || styles.Index("wxDEFAULT_FRAME_STYLE") != wxNOT_FOUND) { |
| 93 |
// draw close box |
| 94 |
draw_minimize_button = true; |
| 95 |
bmpSize += bmpClose.GetWidth(); |
| 96 |
} |
| 97 |
|
| 98 |
if(styles.Index("wxMAXIMIZE_BOX") != wxNOT_FOUND || styles.Index("wxDEFAULT_FRAME_STYLE") != wxNOT_FOUND) { |
| 99 |
// draw close box |
| 100 |
draw_maximize_button = true; |
| 101 |
bmpSize += bmpClose.GetWidth(); |
| 102 |
} |
| 103 |
|
| 104 |
// Draw the buttons |
| 105 |
|
| 106 |
int button_x = clientRect.GetWidth() - bmpSize - 2; |
| 107 |
int button_y = (clientRect.GetHeight() - bmpClose.GetHeight()) / 2; |
| 108 |
if(draw_minimize_button) { |
| 109 |
dc.DrawBitmap(myImages.Bitmap("button_minimize"), button_x, button_y, true); |
| 110 |
button_x += bmpClose.GetWidth(); |
| 111 |
} |
| 112 |
|
| 113 |
if(draw_maximize_button) { |
| 114 |
dc.DrawBitmap(myImages.Bitmap("button_maximize"), button_x, button_y, true); |
| 115 |
button_x += bmpClose.GetWidth(); |
| 116 |
} |
| 117 |
|
| 118 |
if(draw_close_button) { |
| 119 |
dc.DrawBitmap(myImages.Bitmap("button_close"), button_x, button_y, true); |
| 120 |
button_x += bmpClose.GetWidth(); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
void CaptionBar::OnLeftDown(wxMouseEvent& event) |
| 125 |
{ |
| 126 |
event.Skip(); |
| 127 |
wxCommandEvent evt(wxEVT_WXC_SELECT_TREE_TLW); |
| 128 |
EventNotifier::Get()->AddPendingEvent(evt); |
| 129 |
} |