consolidated duplicated static functions into one file

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43439 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Benjamin Williams
2006-11-16 08:21:54 +00:00
parent fd29f9ad65
commit a500c7ed7a
2 changed files with 69 additions and 114 deletions

View File

@@ -57,27 +57,15 @@ IMPLEMENT_DYNAMIC_CLASS(wxAuiNotebookEvent, wxEvent)
// This functions are here for this proof of concept
// and will be factored out later. See dockart.cpp
static wxColor StepColour(const wxColor& c, int percent)
{
int r = c.Red(), g = c.Green(), b = c.Blue();
return wxColour((unsigned char)wxMin((r*percent)/100,255),
(unsigned char)wxMin((g*percent)/100,255),
(unsigned char)wxMin((b*percent)/100,255));
}
// these functions live in dockart.cpp -- they'll eventually
// be moved to a new utility cpp file
// This functions are here for this proof of concept
// and will be factored out later. See dockart.cpp
static wxBitmap BitmapFromBits(const unsigned char bits[], int w, int h,
const wxColour& color)
{
wxImage img = wxBitmap((const char*)bits, w, h).ConvertToImage();
img.Replace(0,0,0,123,123,123);
img.Replace(255,255,255,color.Red(),color.Green(),color.Blue());
img.SetMaskColour(123,123,123);
return wxBitmap(img);
}
wxColor wxAuiStepColour(const wxColor& c, int percent);
wxBitmap wxAuiBitmapFromBits(const unsigned char bits[], int w, int h,
const wxColour& color);
wxString wxAuiChopText(wxDC& dc, const wxString& text, int max_size);
static void DrawButtons(wxDC& dc,
const wxRect& _rect,
@@ -96,8 +84,8 @@ static void DrawButtons(wxDC& dc,
if (button_state == wxAUI_BUTTON_STATE_HOVER ||
button_state == wxAUI_BUTTON_STATE_PRESSED)
{
dc.SetBrush(wxBrush(StepColour(bkcolour, 120)));
dc.SetPen(wxPen(StepColour(bkcolour, 70)));
dc.SetBrush(wxBrush(wxAuiStepColour(bkcolour, 120)));
dc.SetPen(wxPen(wxAuiStepColour(bkcolour, 70)));
// draw the background behind the button
dc.DrawRectangle(rect.x, rect.y, 15, 15);
@@ -116,36 +104,6 @@ static void IndentPressedBitmap(wxRect* rect, int button_state)
}
}
// chops the text so that it fits within |max_size| pixels.
// Also adds an elipsis if necessary
static wxString ChopText(wxDC& dc, const wxString& text, int max_size)
{
wxCoord x,y;
// first check if the text fits with no problems
dc.GetTextExtent(text, &x, &y);
if (x <= max_size)
return text;
size_t i, len = text.Length();
size_t last_good_length = 0;
for (i = 0; i < len; ++i)
{
wxString s = text.Left(i);
s += wxT("...");
dc.GetTextExtent(s, &x, &y);
if (x > max_size)
break;
last_good_length = i;
}
wxString ret = text.Left(last_good_length);
ret += wxT("...");
return ret;
}
// -- GUI helper classes and functions --
@@ -236,23 +194,23 @@ wxAuiDefaultTabArt::wxAuiDefaultTabArt()
#endif
m_base_colour = base_colour;
wxColor darker2_colour = StepColour(base_colour, 70);
wxColor darker2_colour = wxAuiStepColour(base_colour, 70);
m_border_pen = wxPen(darker2_colour);
m_base_colour_pen = wxPen(m_base_colour);
m_base_colour_brush = wxBrush(m_base_colour);
m_active_close_bmp = BitmapFromBits(close_bits, 16, 16, *wxBLACK);
m_disabled_close_bmp = BitmapFromBits(close_bits, 16, 16, wxColour(128,128,128));
m_active_close_bmp = wxAuiBitmapFromBits(close_bits, 16, 16, *wxBLACK);
m_disabled_close_bmp = wxAuiBitmapFromBits(close_bits, 16, 16, wxColour(128,128,128));
m_active_left_bmp = BitmapFromBits(left_bits, 16, 16, *wxBLACK);
m_disabled_left_bmp = BitmapFromBits(left_bits, 16, 16, wxColour(128,128,128));
m_active_left_bmp = wxAuiBitmapFromBits(left_bits, 16, 16, *wxBLACK);
m_disabled_left_bmp = wxAuiBitmapFromBits(left_bits, 16, 16, wxColour(128,128,128));
m_active_right_bmp = BitmapFromBits(right_bits, 16, 16, *wxBLACK);
m_disabled_right_bmp = BitmapFromBits(right_bits, 16, 16, wxColour(128,128,128));
m_active_right_bmp = wxAuiBitmapFromBits(right_bits, 16, 16, *wxBLACK);
m_disabled_right_bmp = wxAuiBitmapFromBits(right_bits, 16, 16, wxColour(128,128,128));
m_active_windowlist_bmp = BitmapFromBits(list_bits, 16, 16, *wxBLACK);
m_disabled_windowlist_bmp = BitmapFromBits(list_bits, 16, 16, wxColour(128,128,128));
m_active_windowlist_bmp = wxAuiBitmapFromBits(list_bits, 16, 16, *wxBLACK);
m_disabled_windowlist_bmp = wxAuiBitmapFromBits(list_bits, 16, 16, wxColour(128,128,128));
m_flags = 0;
}
@@ -308,8 +266,8 @@ void wxAuiDefaultTabArt::DrawBackground(wxDC& dc,
{
// draw background
wxRect r(rect.x, rect.y, rect.width+2, rect.height-3);
wxColor top_color = StepColour(m_base_colour, 90);
wxColor bottom_color = StepColour(m_base_colour, 110);
wxColor top_color = wxAuiStepColour(m_base_colour, 90);
wxColor bottom_color = wxAuiStepColour(m_base_colour, 110);
dc.GradientFillLinear(r, top_color, bottom_color, wxSOUTH);
// draw base lines
@@ -473,7 +431,7 @@ void wxAuiDefaultTabArt::DrawTab(wxDC& dc,
// -- draw top gradient fill for glossy look
wxColor top_color = m_base_colour;
wxColor bottom_color = StepColour(top_color, 106);
wxColor bottom_color = wxAuiStepColour(top_color, 106);
dc.GradientFillLinear(r, bottom_color, top_color, wxNORTH);
r.y += r.height;
@@ -530,7 +488,7 @@ void wxAuiDefaultTabArt::DrawTab(wxDC& dc,
}
wxString draw_text = ChopText(dc,
wxString draw_text = wxAuiChopText(dc,
caption,
tab_width - (text_offset-tab_x) - close_button_width);
@@ -814,7 +772,7 @@ wxAuiSimpleTabArt::wxAuiSimpleTabArt()
wxColour base_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
wxColour background_colour = StepColour(base_colour, 95);
wxColour background_colour = wxAuiStepColour(base_colour, 95);
wxColour normaltab_colour = base_colour;
wxColour selectedtab_colour = *wxWHITE;
@@ -824,17 +782,17 @@ wxAuiSimpleTabArt::wxAuiSimpleTabArt()
m_selected_bkbrush = wxBrush(selectedtab_colour);
m_selected_bkpen = wxPen(selectedtab_colour);
m_active_close_bmp = BitmapFromBits(close_bits, 16, 16, *wxBLACK);
m_disabled_close_bmp = BitmapFromBits(close_bits, 16, 16, wxColour(128,128,128));
m_active_close_bmp = wxAuiBitmapFromBits(close_bits, 16, 16, *wxBLACK);
m_disabled_close_bmp = wxAuiBitmapFromBits(close_bits, 16, 16, wxColour(128,128,128));
m_active_left_bmp = BitmapFromBits(left_bits, 16, 16, *wxBLACK);
m_disabled_left_bmp = BitmapFromBits(left_bits, 16, 16, wxColour(128,128,128));
m_active_left_bmp = wxAuiBitmapFromBits(left_bits, 16, 16, *wxBLACK);
m_disabled_left_bmp = wxAuiBitmapFromBits(left_bits, 16, 16, wxColour(128,128,128));
m_active_right_bmp = BitmapFromBits(right_bits, 16, 16, *wxBLACK);
m_disabled_right_bmp = BitmapFromBits(right_bits, 16, 16, wxColour(128,128,128));
m_active_right_bmp = wxAuiBitmapFromBits(right_bits, 16, 16, *wxBLACK);
m_disabled_right_bmp = wxAuiBitmapFromBits(right_bits, 16, 16, wxColour(128,128,128));
m_active_windowlist_bmp = BitmapFromBits(list_bits, 16, 16, *wxBLACK);
m_disabled_windowlist_bmp = BitmapFromBits(list_bits, 16, 16, wxColour(128,128,128));
m_active_windowlist_bmp = wxAuiBitmapFromBits(list_bits, 16, 16, *wxBLACK);
m_disabled_windowlist_bmp = wxAuiBitmapFromBits(list_bits, 16, 16, wxColour(128,128,128));
}
@@ -1012,7 +970,7 @@ void wxAuiSimpleTabArt::DrawTab(wxDC& dc,
text_offset = tab_x + tab_height;
// chop text if necessary
wxString draw_text = ChopText(dc,
wxString draw_text = wxAuiChopText(dc,
caption,
tab_width - (text_offset-tab_x) - close_button_width);

View File

@@ -56,9 +56,7 @@
// wxAuiManager::SetDockArt()
// StepColour() it a utility function that simply darkens
// or lightens a color, based on the specified percentage
static wxColor StepColour(const wxColor& c, int percent)
wxColor wxAuiStepColour(const wxColor& c, int percent)
{
int r = c.Red(), g = c.Green(), b = c.Blue();
return wxColour((unsigned char)wxMin((r*percent)/100,255),
@@ -66,7 +64,7 @@ static wxColor StepColour(const wxColor& c, int percent)
(unsigned char)wxMin((b*percent)/100,255));
}
static wxColor LightContrastColour(const wxColour& c)
wxColor wxAuiLightContrastColour(const wxColour& c)
{
int amount = 120;
@@ -75,13 +73,13 @@ static wxColor LightContrastColour(const wxColour& c)
if (c.Red() < 128 && c.Green() < 128 && c.Blue() < 128)
amount = 160;
return StepColour(c, amount);
return wxAuiStepColour(c, amount);
}
// BitmapFromBits() is a utility function that creates a
// wxAuiBitmapFromBits() is a utility function that creates a
// masked bitmap from raw bits (XBM format)
static wxBitmap BitmapFromBits(const unsigned char bits[], int w, int h,
const wxColour& color)
wxBitmap wxAuiBitmapFromBits(const unsigned char bits[], int w, int h,
const wxColour& color)
{
wxImage img = wxBitmap((const char*)bits, w, h).ConvertToImage();
img.Replace(0,0,0,123,123,123);
@@ -89,7 +87,7 @@ static wxBitmap BitmapFromBits(const unsigned char bits[], int w, int h,
img.SetMaskColour(123,123,123);
return wxBitmap(img);
}
static void DrawGradientRectangle(wxDC& dc,
const wxRect& rect,
@@ -126,10 +124,9 @@ static void DrawGradientRectangle(wxDC& dc,
else
dc.DrawLine(rect.x+i, rect.y, rect.x+i, rect.y+rect.height);
}
}
static wxString ChopText(wxDC& dc, const wxString& text, int max_size)
wxString wxAuiChopText(wxDC& dc, const wxString& text, int max_size)
{
wxCoord x,y;
@@ -168,17 +165,17 @@ wxAuiDefaultDockArt::wxAuiDefaultDockArt()
#endif
m_base_colour = base_colour;
wxColor darker1_colour = StepColour(base_colour, 85);
wxColor darker2_colour = StepColour(base_colour, 70);
wxColor darker3_colour = StepColour(base_colour, 60);
wxColor darker4_colour = StepColour(base_colour, 50);
wxColor darker5_colour = StepColour(base_colour, 40);
wxColor darker1_colour = wxAuiStepColour(base_colour, 85);
wxColor darker2_colour = wxAuiStepColour(base_colour, 70);
wxColor darker3_colour = wxAuiStepColour(base_colour, 60);
wxColor darker4_colour = wxAuiStepColour(base_colour, 50);
wxColor darker5_colour = wxAuiStepColour(base_colour, 40);
m_active_caption_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
m_active_caption_gradient_colour = LightContrastColour(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
m_active_caption_gradient_colour = wxAuiLightContrastColour(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
m_active_caption_text_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
m_inactive_caption_colour = darker1_colour;
m_inactive_caption_gradient_colour = StepColour(base_colour, 97);
m_inactive_caption_gradient_colour = wxAuiStepColour(base_colour, 97);
m_inactive_caption_text_colour = *wxBLACK;
#ifdef __WXMAC__
@@ -235,31 +232,31 @@ wxAuiDefaultDockArt::wxAuiDefaultDockArt()
0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
#ifdef __WXMAC__
m_inactive_close_bitmap = BitmapFromBits(close_bits, 16, 16, *wxWHITE);
m_active_close_bitmap = BitmapFromBits(close_bits, 16, 16, *wxWHITE );
m_inactive_close_bitmap = wxAuiBitmapFromBits(close_bits, 16, 16, *wxWHITE);
m_active_close_bitmap = wxAuiBitmapFromBits(close_bits, 16, 16, *wxWHITE );
#else
m_inactive_close_bitmap = BitmapFromBits(close_bits, 16, 16, m_inactive_caption_text_colour);
m_active_close_bitmap = BitmapFromBits(close_bits, 16, 16, m_active_caption_text_colour);
m_inactive_close_bitmap = wxAuiBitmapFromBits(close_bits, 16, 16, m_inactive_caption_text_colour);
m_active_close_bitmap = wxAuiBitmapFromBits(close_bits, 16, 16, m_active_caption_text_colour);
#endif
#ifdef __WXMAC__
m_inactive_maximize_bitmap = BitmapFromBits(maximize_bits, 16, 16, *wxWHITE);
m_active_maximize_bitmap = BitmapFromBits(maximize_bits, 16, 16, *wxWHITE );
m_inactive_maximize_bitmap = wxAuiBitmapFromBits(maximize_bits, 16, 16, *wxWHITE);
m_active_maximize_bitmap = wxAuiBitmapFromBits(maximize_bits, 16, 16, *wxWHITE );
#else
m_inactive_maximize_bitmap = BitmapFromBits(maximize_bits, 16, 16, m_inactive_caption_text_colour);
m_active_maximize_bitmap = BitmapFromBits(maximize_bits, 16, 16, m_active_caption_text_colour);
m_inactive_maximize_bitmap = wxAuiBitmapFromBits(maximize_bits, 16, 16, m_inactive_caption_text_colour);
m_active_maximize_bitmap = wxAuiBitmapFromBits(maximize_bits, 16, 16, m_active_caption_text_colour);
#endif
#ifdef __WXMAC__
m_inactive_restore_bitmap = BitmapFromBits(restore_bits, 16, 16, *wxWHITE);
m_active_restore_bitmap = BitmapFromBits(restore_bits, 16, 16, *wxWHITE );
m_inactive_restore_bitmap = wxAuiBitmapFromBits(restore_bits, 16, 16, *wxWHITE);
m_active_restore_bitmap = wxAuiBitmapFromBits(restore_bits, 16, 16, *wxWHITE );
#else
m_inactive_restore_bitmap = BitmapFromBits(restore_bits, 16, 16, m_inactive_caption_text_colour);
m_active_restore_bitmap = BitmapFromBits(restore_bits, 16, 16, m_active_caption_text_colour);
m_inactive_restore_bitmap = wxAuiBitmapFromBits(restore_bits, 16, 16, m_inactive_caption_text_colour);
m_active_restore_bitmap = wxAuiBitmapFromBits(restore_bits, 16, 16, m_active_caption_text_colour);
#endif
m_inactive_pin_bitmap = BitmapFromBits(pin_bits, 16, 16, m_inactive_caption_text_colour);
m_active_pin_bitmap = BitmapFromBits(pin_bits, 16, 16, m_active_caption_text_colour);
m_inactive_pin_bitmap = wxAuiBitmapFromBits(pin_bits, 16, 16, m_inactive_caption_text_colour);
m_active_pin_bitmap = wxAuiBitmapFromBits(pin_bits, 16, 16, m_active_caption_text_colour);
// default metric values
#if defined(__WXMAC__)
@@ -343,8 +340,8 @@ void wxAuiDefaultDockArt::SetColour(int id, const wxColor& colour)
case wxAUI_ART_BORDER_COLOUR: m_border_pen.SetColour(colour); break;
case wxAUI_ART_GRIPPER_COLOUR:
m_gripper_brush.SetColour(colour);
m_gripper_pen1.SetColour(StepColour(colour, 40));
m_gripper_pen2.SetColour(StepColour(colour, 60));
m_gripper_pen1.SetColour(wxAuiStepColour(colour, 40));
m_gripper_pen2.SetColour(wxAuiStepColour(colour, 60));
break;
default: wxFAIL_MSG(wxT("Invalid Metric Ordinal")); break;
}
@@ -569,7 +566,7 @@ void wxAuiDefaultDockArt::DrawCaption(wxDC& dc, wxWindow *WXUNUSED(window),
if (pane.HasMaximizeButton())
clip_rect.width -= m_button_size;
wxString draw_text = ChopText(dc, text, clip_rect.width);
wxString draw_text = wxAuiChopText(dc, text, clip_rect.width);
dc.SetClippingRegion(clip_rect);
dc.DrawText(draw_text, rect.x+3, rect.y+(rect.height/2)-(h/2)-1);
@@ -646,13 +643,13 @@ void wxAuiDefaultDockArt::DrawPaneButton(wxDC& dc, wxWindow *WXUNUSED(window),
{
if (pane.state & wxAuiPaneInfo::optionActive)
{
dc.SetBrush(wxBrush(StepColour(m_active_caption_colour, 120)));
dc.SetPen(wxPen(StepColour(m_active_caption_colour, 70)));
dc.SetBrush(wxBrush(wxAuiStepColour(m_active_caption_colour, 120)));
dc.SetPen(wxPen(wxAuiStepColour(m_active_caption_colour, 70)));
}
else
{
dc.SetBrush(wxBrush(StepColour(m_inactive_caption_colour, 120)));
dc.SetPen(wxPen(StepColour(m_inactive_caption_colour, 70)));
dc.SetBrush(wxBrush(wxAuiStepColour(m_inactive_caption_colour, 120)));
dc.SetPen(wxPen(wxAuiStepColour(m_inactive_caption_colour, 70)));
}
// draw the background behind the button