00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "framemanager.h"
00021 #include "dockart.h"
00022
00023 #if wxXTRA_AUI
00024
00025 #include <wx/settings.h>
00026 #include <wx/dcclient.h>
00027 #include <wx/image.h>
00028
00029 #ifdef __WXMAC__
00030 #include <wx/mac/private.h>
00031 #endif
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 static wxColor wxAuiStepColour(const wxColor& c, int percent)
00046 {
00047 int r = c.Red(), g = c.Green(), b = c.Blue();
00048 return wxColour((unsigned char)wxMin((r*percent)/100,255),
00049 (unsigned char)wxMin((g*percent)/100,255),
00050 (unsigned char)wxMin((b*percent)/100,255));
00051 }
00052
00053 static wxColor wxAuiLightContrastColour(const wxColour& c)
00054 {
00055 int amount = 120;
00056
00057
00058
00059 if (c.Red() < 128 && c.Green() < 128 && c.Blue() < 128)
00060 amount = 160;
00061
00062 return wxAuiStepColour(c, amount);
00063 }
00064
00065
00066
00067 static wxBitmap wxAuiBitmapFromBits(const unsigned char bits[], int w, int h,
00068 const wxColour& color)
00069 {
00070 wxImage img = wxBitmap((const char*)bits, w, h).ConvertToImage();
00071 img.Replace(255,255,255,123,123,123);
00072 img.Replace(0,0,0,color.Red(),color.Green(),color.Blue());
00073 img.SetMaskColour(123,123,123);
00074 return wxBitmap(img);
00075 }
00076
00077
00078 static void DrawGradientRectangle(wxDC& dc,
00079 const wxRect& rect,
00080 const wxColour& start_color,
00081 const wxColour& end_color,
00082 int direction)
00083 {
00084 int rd, gd, bd, high = 0;
00085 rd = end_color.Red() - start_color.Red();
00086 gd = end_color.Green() - start_color.Green();
00087 bd = end_color.Blue() - start_color.Blue();
00088
00089 if (direction == wxAUI_GRADIENT_VERTICAL)
00090 high = rect.GetHeight()-1;
00091 else
00092 high = rect.GetWidth()-1;
00093
00094 for (int i = 0; i <= high; ++i)
00095 {
00096 int r = start_color.Red() + ((i*rd*100)/high)/100;
00097 int g = start_color.Green() + ((i*gd*100)/high)/100;
00098 int b = start_color.Blue() + ((i*bd*100)/high)/100;
00099
00100 wxPen p(wxColor((unsigned char)r,
00101 (unsigned char)g,
00102 (unsigned char)b));
00103 dc.SetPen(p);
00104
00105 if (direction == wxAUI_GRADIENT_VERTICAL)
00106 dc.DrawLine(rect.x, rect.y+i, rect.x+rect.width, rect.y+i);
00107 else
00108 dc.DrawLine(rect.x+i, rect.y, rect.x+i, rect.y+rect.height);
00109 }
00110
00111 }
00112
00113 wxAuiDefaultDockArt::wxAuiDefaultDockArt()
00114 {
00115 #ifdef __WXMAC__
00116 wxBrush toolbarbrush;
00117 toolbarbrush.MacSetTheme( kThemeBrushToolbarBackground );
00118 wxColor base_color = toolbarbrush.GetColour();
00119 #else
00120 wxColor base_color = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
00121 #endif
00122
00123 wxColor darker1_color = wxAuiStepColour(base_color, 85);
00124 wxColor darker2_color = wxAuiStepColour(base_color, 70);
00125 wxColor darker3_color = wxAuiStepColour(base_color, 60);
00126 wxColor darker4_color = wxAuiStepColour(base_color, 50);
00127 wxColor darker5_color = wxAuiStepColour(base_color, 40);
00128
00129 m_active_caption_colour = wxAuiLightContrastColour(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
00130 m_active_caption_gradient_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
00131 m_active_caption_text_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
00132 m_inactive_caption_colour = wxAuiStepColour(darker1_color, 80);
00133 m_inactive_caption_gradient_colour = darker1_color;
00134 m_inactive_caption_text_colour = *wxBLACK;
00135
00136 #ifdef __WXMAC__
00137 m_sash_brush = toolbarbrush;
00138 m_background_brush = toolbarbrush;
00139 m_gripper_brush = toolbarbrush;
00140 #else
00141 m_sash_brush = wxBrush(base_color);
00142 m_background_brush = wxBrush(base_color);
00143 m_gripper_brush = wxBrush(base_color);
00144 #endif
00145 m_border_pen = wxPen(darker2_color);
00146 m_gripper_pen1 = wxPen(darker5_color);
00147 m_gripper_pen2 = wxPen(darker3_color);
00148 m_gripper_pen3 = *wxWHITE_PEN;
00149
00150 #ifdef __WXMAC__
00151 m_caption_font = *wxSMALL_FONT;
00152 #else
00153 m_caption_font = wxFont(8, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE);
00154 #endif
00155
00156
00157 #ifdef __WXMAC__
00158 static unsigned char close_bits[]={
00159 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xFE, 0x03, 0xF8, 0x01, 0xF0, 0x19, 0xF3,
00160 0xB8, 0xE3, 0xF0, 0xE1, 0xE0, 0xE0, 0xF0, 0xE1, 0xB8, 0xE3, 0x19, 0xF3,
00161 0x01, 0xF0, 0x03, 0xF8, 0x0F, 0xFE, 0xFF, 0xFF };
00162 #else
00163 static unsigned char close_bits[]={
00164 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0xfb,0xcf,0xf9,
00165 0x9f,0xfc,0x3f,0xfe,0x3f,0xfe,0x9f,0xfc,0xcf,0xf9,0xef,0xfb,
00166 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
00167 #endif
00168
00169 static unsigned char pin_bits[]={
00170 0xff,0xff,0xff,0xff,0xff,0xff,0x1f,0xfc,0xdf,0xfc,0xdf,0xfc,
00171 0xdf,0xfc,0xdf,0xfc,0xdf,0xfc,0x0f,0xf8,0x7f,0xff,0x7f,0xff,
00172 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
00173
00174 #ifdef __WXMAC__
00175 m_inactive_close_bitmap = wxAuiBitmapFromBits(close_bits, 16, 16, *wxWHITE);
00176 #else
00177 m_inactive_close_bitmap = wxAuiBitmapFromBits(close_bits, 16, 16, m_inactive_caption_text_colour);
00178 #endif
00179 m_inactive_pin_bitmap = wxAuiBitmapFromBits(pin_bits, 16, 16, m_inactive_caption_text_colour);
00180 #ifdef __WXMAC__
00181 m_active_close_bitmap = wxAuiBitmapFromBits(close_bits, 16, 16, *wxWHITE );
00182 #else
00183 m_active_close_bitmap = wxAuiBitmapFromBits(close_bits, 16, 16, m_active_caption_text_colour);
00184 #endif
00185 m_active_pin_bitmap = wxAuiBitmapFromBits(pin_bits, 16, 16, m_active_caption_text_colour);
00186
00187
00188 #ifdef __WXMAC__
00189 SInt32 height;
00190 GetThemeMetric( kThemeMetricSmallPaneSplitterHeight , &height );
00191 m_sash_size = height;
00192 #else
00193 m_sash_size = 4;
00194 #endif
00195 m_caption_size = 17;
00196 m_border_size = 1;
00197 m_button_size = 14;
00198 m_gripper_size = 9;
00199 m_gradient_type = wxAUI_GRADIENT_VERTICAL;
00200 }
00201
00202 int wxAuiDefaultDockArt::GetMetric(int id)
00203 {
00204 switch (id)
00205 {
00206 case wxAUI_ART_SASH_SIZE: return m_sash_size;
00207 case wxAUI_ART_CAPTION_SIZE: return m_caption_size;
00208 case wxAUI_ART_GRIPPER_SIZE: return m_gripper_size;
00209 case wxAUI_ART_PANE_BORDER_SIZE: return m_border_size;
00210 case wxAUI_ART_PANE_BUTTON_SIZE: return m_button_size;
00211 case wxAUI_ART_GRADIENT_TYPE: return m_gradient_type;
00212 default: wxFAIL_MSG(wxT("Invalid Metric Ordinal")); break;
00213 }
00214
00215 return 0;
00216 }
00217
00218 void wxAuiDefaultDockArt::SetMetric(int id, int new_val)
00219 {
00220 switch (id)
00221 {
00222 case wxAUI_ART_SASH_SIZE: m_sash_size = new_val; break;
00223 case wxAUI_ART_CAPTION_SIZE: m_caption_size = new_val; break;
00224 case wxAUI_ART_GRIPPER_SIZE: m_gripper_size = new_val; break;
00225 case wxAUI_ART_PANE_BORDER_SIZE: m_border_size = new_val; break;
00226 case wxAUI_ART_PANE_BUTTON_SIZE: m_button_size = new_val; break;
00227 case wxAUI_ART_GRADIENT_TYPE: m_gradient_type = new_val; break;
00228 default: wxFAIL_MSG(wxT("Invalid Metric Ordinal")); break;
00229 }
00230 }
00231
00232 wxColour wxAuiDefaultDockArt::GetColour(int id)
00233 {
00234 switch (id)
00235 {
00236 case wxAUI_ART_BACKGROUND_COLOUR: return m_background_brush.GetColour();
00237 case wxAUI_ART_SASH_COLOUR: return m_sash_brush.GetColour();
00238 case wxAUI_ART_INACTIVE_CAPTION_COLOUR: return m_inactive_caption_colour;
00239 case wxAUI_ART_INACTIVE_CAPTION_GRADIENT_COLOUR: return m_inactive_caption_gradient_colour;
00240 case wxAUI_ART_INACTIVE_CAPTION_TEXT_COLOUR: return m_inactive_caption_text_colour;
00241 case wxAUI_ART_ACTIVE_CAPTION_COLOUR: return m_active_caption_colour;
00242 case wxAUI_ART_ACTIVE_CAPTION_GRADIENT_COLOUR: return m_active_caption_gradient_colour;
00243 case wxAUI_ART_ACTIVE_CAPTION_TEXT_COLOUR: return m_active_caption_text_colour;
00244 case wxAUI_ART_BORDER_COLOUR: return m_border_pen.GetColour();
00245 case wxAUI_ART_GRIPPER_COLOUR: return m_gripper_brush.GetColour();
00246 default: wxFAIL_MSG(wxT("Invalid Metric Ordinal")); break;
00247 }
00248
00249 return wxColour();
00250 }
00251
00252 void wxAuiDefaultDockArt::SetColour(int id, const wxColor& colour)
00253 {
00254 switch (id)
00255 {
00256 case wxAUI_ART_BACKGROUND_COLOUR: m_background_brush.SetColour(colour); break;
00257 case wxAUI_ART_SASH_COLOUR: m_sash_brush.SetColour(colour); break;
00258 case wxAUI_ART_INACTIVE_CAPTION_COLOUR: m_inactive_caption_colour = colour; break;
00259 case wxAUI_ART_INACTIVE_CAPTION_GRADIENT_COLOUR: m_inactive_caption_gradient_colour = colour; break;
00260 case wxAUI_ART_INACTIVE_CAPTION_TEXT_COLOUR: m_inactive_caption_text_colour = colour; break;
00261 case wxAUI_ART_ACTIVE_CAPTION_COLOUR: m_active_caption_colour = colour; break;
00262 case wxAUI_ART_ACTIVE_CAPTION_GRADIENT_COLOUR: m_active_caption_gradient_colour = colour; break;
00263 case wxAUI_ART_ACTIVE_CAPTION_TEXT_COLOUR: m_active_caption_text_colour = colour; break;
00264 case wxAUI_ART_BORDER_COLOUR: m_border_pen.SetColour(colour); break;
00265 case wxAUI_ART_GRIPPER_COLOUR:
00266 m_gripper_brush.SetColour(colour);
00267 m_gripper_pen1.SetColour(wxAuiStepColour(colour, 40));
00268 m_gripper_pen2.SetColour(wxAuiStepColour(colour, 60));
00269 break;
00270 default: wxFAIL_MSG(wxT("Invalid Metric Ordinal")); break;
00271 }
00272 }
00273
00274 void wxAuiDefaultDockArt::SetFont(int id, const wxFont& font)
00275 {
00276 if (id == wxAUI_ART_CAPTION_FONT)
00277 m_caption_font = font;
00278 }
00279
00280 wxFont wxAuiDefaultDockArt::GetFont(int id)
00281 {
00282 if (id == wxAUI_ART_CAPTION_FONT)
00283 return m_caption_font;
00284 return wxNullFont;
00285 }
00286
00287 void wxAuiDefaultDockArt::DrawSash(wxDC& dc, int, const wxRect& rect)
00288 {
00289 #ifdef __WXMAC__
00290 HIRect splitterRect = CGRectMake( rect.x , rect.y , rect.width , rect.height );
00291 CGContextRef cgContext ;
00292 #if wxMAC_USE_CORE_GRAPHICS
00293 cgContext = ((wxMacCGContext*)(dc.GetGraphicContext()))->GetNativeContext() ;
00294 #else
00295 Rect bounds ;
00296 GetPortBounds( (CGrafPtr) dc.m_macPort , &bounds ) ;
00297 QDBeginCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
00298 CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ;
00299 CGContextScaleCTM( cgContext , 1 , -1 ) ;
00300 #endif
00301
00302 HIThemeSplitterDrawInfo drawInfo ;
00303 drawInfo.version = 0 ;
00304 drawInfo.state = kThemeStateActive ;
00305 drawInfo.adornment = kHIThemeSplitterAdornmentNone ;
00306 HIThemeDrawPaneSplitter( &splitterRect , &drawInfo , cgContext , kHIThemeOrientationNormal ) ;
00307
00308 #if wxMAC_USE_CORE_GRAPHICS
00309 #else
00310 QDEndCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
00311 #endif
00312
00313 #else
00314 dc.SetPen(*wxTRANSPARENT_PEN);
00315 dc.SetBrush(m_sash_brush);
00316 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
00317 #endif
00318 }
00319
00320
00321 void wxAuiDefaultDockArt::DrawBackground(wxDC& dc, int, const wxRect& rect)
00322 {
00323 dc.SetPen(*wxTRANSPARENT_PEN);
00324 #ifdef __WXMAC__
00325
00326
00327 dc.SetBrush(*wxWHITE_BRUSH) ;
00328 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
00329 #endif
00330 dc.SetBrush(m_background_brush);
00331 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
00332 }
00333
00334 void wxAuiDefaultDockArt::DrawBorder(wxDC& dc, const wxRect& _rect,
00335 wxAuiPaneInfo& pane)
00336 {
00337 dc.SetPen(m_border_pen);
00338 dc.SetBrush(*wxTRANSPARENT_BRUSH);
00339
00340 wxRect rect = _rect;
00341 int i, border_width = GetMetric(wxAUI_ART_PANE_BORDER_SIZE);
00342
00343 if (pane.IsToolbar())
00344 {
00345 for (i = 0; i < border_width; ++i)
00346 {
00347 dc.SetPen(*wxWHITE_PEN);
00348 dc.DrawLine(rect.x, rect.y, rect.x+rect.width, rect.y);
00349 dc.DrawLine(rect.x, rect.y, rect.x, rect.y+rect.height);
00350 dc.SetPen(m_border_pen);
00351 dc.DrawLine(rect.x, rect.y+rect.height-1,
00352 rect.x+rect.width, rect.y+rect.height-1);
00353 dc.DrawLine(rect.x+rect.width-1, rect.y,
00354 rect.x+rect.width-1, rect.y+rect.height);
00355 rect.Deflate(1);
00356 }
00357 }
00358 else
00359 {
00360 for (i = 0; i < border_width; ++i)
00361 {
00362 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
00363 rect.Deflate(1);
00364 }
00365 }
00366 }
00367
00368
00369 void wxAuiDefaultDockArt::DrawCaptionBackground(wxDC& dc, const wxRect& rect, bool active)
00370 {
00371 if (m_gradient_type == wxAUI_GRADIENT_NONE)
00372 {
00373 if (active)
00374 dc.SetBrush(wxBrush(m_active_caption_colour));
00375 else
00376 dc.SetBrush(wxBrush(m_inactive_caption_colour));
00377
00378 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
00379 }
00380 else
00381 {
00382 if (active)
00383 {
00384
00385 #ifdef __WXMAC__
00386 DrawGradientRectangle(dc, rect,
00387 m_active_caption_gradient_colour,
00388 m_active_caption_colour,
00389 m_gradient_type);
00390 #else
00391 DrawGradientRectangle(dc, rect,
00392 m_active_caption_colour,
00393 m_active_caption_gradient_colour,
00394 m_gradient_type);
00395 #endif
00396 }
00397 else
00398 {
00399
00400 #ifdef __WXMAC__
00401 DrawGradientRectangle(dc, rect,
00402 m_inactive_caption_gradient_colour,
00403 m_inactive_caption_colour,
00404 m_gradient_type);
00405 #else
00406 DrawGradientRectangle(dc, rect,
00407 m_inactive_caption_colour,
00408 m_inactive_caption_gradient_colour,
00409 m_gradient_type);
00410 #endif
00411 }
00412 }
00413 }
00414
00415
00416 void wxAuiDefaultDockArt::DrawCaption(wxDC& dc,
00417 const wxString& text,
00418 const wxRect& rect,
00419 wxAuiPaneInfo& pane)
00420 {
00421 dc.SetPen(*wxTRANSPARENT_PEN);
00422 dc.SetFont(m_caption_font);
00423
00424 DrawCaptionBackground(dc, rect,
00425 (pane.state & wxAuiPaneInfo::optionActive)?true:false);
00426
00427 if (pane.state & wxAuiPaneInfo::optionActive)
00428 dc.SetTextForeground(m_active_caption_text_colour);
00429 else
00430 dc.SetTextForeground(m_inactive_caption_text_colour);
00431
00432
00433 wxCoord w,h;
00434 dc.GetTextExtent(wxT("ABCDEFHXfgkj"), &w, &h);
00435
00436 dc.SetClippingRegion(rect);
00437 dc.DrawText(text, rect.x+3, rect.y+(rect.height/2)-(h/2)-1);
00438 dc.DestroyClippingRegion();
00439 }
00440
00441 void wxAuiDefaultDockArt::DrawGripper(wxDC& dc,
00442 const wxRect& rect,
00443 wxAuiPaneInfo& pane)
00444 {
00445 dc.SetPen(*wxTRANSPARENT_PEN);
00446 dc.SetBrush(m_gripper_brush);
00447
00448 dc.DrawRectangle(rect.x, rect.y, rect.width,rect.height);
00449
00450 if (!pane.HasGripperTop())
00451 {
00452 int y = 5;
00453 while (1)
00454 {
00455 dc.SetPen(m_gripper_pen1);
00456 dc.DrawPoint(rect.x+3, rect.y+y);
00457 dc.SetPen(m_gripper_pen2);
00458 dc.DrawPoint(rect.x+3, rect.y+y+1);
00459 dc.DrawPoint(rect.x+4, rect.y+y);
00460 dc.SetPen(m_gripper_pen3);
00461 dc.DrawPoint(rect.x+5, rect.y+y+1);
00462 dc.DrawPoint(rect.x+5, rect.y+y+2);
00463 dc.DrawPoint(rect.x+4, rect.y+y+2);
00464
00465 y += 4;
00466 if (y > rect.GetHeight()-5)
00467 break;
00468 }
00469 }
00470 else
00471 {
00472 int x = 5;
00473 while (1)
00474 {
00475 dc.SetPen(m_gripper_pen1);
00476 dc.DrawPoint(rect.x+x, rect.y+3);
00477 dc.SetPen(m_gripper_pen2);
00478 dc.DrawPoint(rect.x+x+1, rect.y+3);
00479 dc.DrawPoint(rect.x+x, rect.y+4);
00480 dc.SetPen(m_gripper_pen3);
00481 dc.DrawPoint(rect.x+x+1, rect.y+5);
00482 dc.DrawPoint(rect.x+x+2, rect.y+5);
00483 dc.DrawPoint(rect.x+x+2, rect.y+4);
00484
00485 x += 4;
00486 if (x > rect.GetWidth()-5)
00487 break;
00488 }
00489 }
00490 }
00491
00492 void wxAuiDefaultDockArt::DrawPaneButton(wxDC& dc,
00493 int button,
00494 int button_state,
00495 const wxRect& _rect,
00496 wxAuiPaneInfo& pane)
00497 {
00498 wxRect rect = _rect;
00499
00500 if (button_state == wxAUI_BUTTON_STATE_PRESSED)
00501 {
00502 rect.x++;
00503 rect.y++;
00504 }
00505
00506 if (button_state == wxAUI_BUTTON_STATE_HOVER ||
00507 button_state == wxAUI_BUTTON_STATE_PRESSED)
00508 {
00509 if (pane.state & wxAuiPaneInfo::optionActive)
00510 {
00511 dc.SetBrush(wxBrush(wxAuiStepColour(m_active_caption_colour, 120)));
00512 dc.SetPen(wxPen(wxAuiStepColour(m_active_caption_colour, 70)));
00513 }
00514 else
00515 {
00516 dc.SetBrush(wxBrush(wxAuiStepColour(m_inactive_caption_colour, 120)));
00517 dc.SetPen(wxPen(wxAuiStepColour(m_inactive_caption_colour, 70)));
00518 }
00519
00520
00521 dc.DrawRectangle(rect.x, rect.y, 15, 15);
00522 }
00523
00524 wxBitmap bmp;
00525 switch (button)
00526 {
00527 default:
00528 case wxAuiPaneInfo::buttonClose:
00529 if (pane.state & wxAuiPaneInfo::optionActive)
00530 bmp = m_active_close_bitmap;
00531 else
00532 bmp = m_inactive_close_bitmap;
00533 break;
00534 case wxAuiPaneInfo::buttonPin:
00535 if (pane.state & wxAuiPaneInfo::optionActive)
00536 bmp = m_active_pin_bitmap;
00537 else
00538 bmp = m_inactive_pin_bitmap;
00539 break;
00540 }
00541
00542
00543 dc.DrawBitmap(bmp, rect.x, rect.y, true);
00544 }
00545
00546
00547 #endif // wxUSE_AUI