]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/statbrma.cpp
best size calculations based on bitmap size
[wxWidgets.git] / src / mac / carbon / statbrma.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: statbar.cpp
3 // Purpose: native implementation of wxStatusBar (optional)
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "statbrma.h"
14 #endif
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include "wx/statusbr.h"
21 #include "wx/dc.h"
22 #include "wx/dcclient.h"
23
24 BEGIN_EVENT_TABLE(wxStatusBarMac, wxStatusBarGeneric)
25 EVT_PAINT(wxStatusBarMac::OnPaint)
26 END_EVENT_TABLE()
27
28 #ifdef __WXMAC__
29 #include "wx/mac/private.h"
30 #endif
31
32 // ============================================================================
33 // implementation
34 // ============================================================================
35
36 // ----------------------------------------------------------------------------
37 // wxStatusBarMac class
38 // ----------------------------------------------------------------------------
39
40 wxStatusBarMac::wxStatusBarMac()
41 {
42 SetParent(NULL);
43 }
44
45 wxStatusBarMac::~wxStatusBarMac()
46 {
47 }
48
49 bool wxStatusBarMac::Create(wxWindow *parent, wxWindowID id,
50 long style ,
51 const wxString& name)
52 {
53 if( !wxStatusBarGeneric::Create( parent , id , style , name ) )
54 return FALSE ;
55
56 if ( parent->MacGetTopLevelWindow()->MacGetMetalAppearance() )
57 MacSetBackgroundBrush( wxNullBrush ) ;
58
59 return TRUE ;
60 }
61
62 void wxStatusBarMac::DrawFieldText(wxDC& dc, int i)
63 {
64 int leftMargin = 2;
65 int w, h ;
66 GetSize( &w , &h ) ;
67 wxRect rect;
68 GetFieldRect(i, rect);
69
70 if ( !MacIsReallyHilited() )
71 {
72 dc.SetTextForeground( wxColour( 0x80 , 0x80 , 0x80 ) ) ;
73 }
74
75 wxString text(GetStatusText(i));
76
77 long x, y;
78
79 dc.GetTextExtent(text, &x, &y);
80
81 int xpos = rect.x + leftMargin + 1 ;
82 int ypos = 1 ;
83
84 if ( MacGetTopLevelWindow()->MacGetMetalAppearance() )
85 ypos++ ;
86
87 dc.SetClippingRegion(rect.x, 0, rect.width, h);
88
89 dc.DrawText(text, xpos, ypos);
90
91 dc.DestroyClippingRegion();
92 }
93
94 void wxStatusBarMac::DrawField(wxDC& dc, int i)
95 {
96 DrawFieldText(dc, i);
97 }
98
99 void wxStatusBarMac::SetStatusText(const wxString& text, int number)
100 {
101 wxCHECK_RET( (number >= 0) && (number < m_nFields),
102 _T("invalid status bar field index") );
103
104 m_statusStrings[number] = text;
105 wxRect rect;
106 GetFieldRect(number, rect);
107 int w, h ;
108 GetSize( &w , &h ) ;
109 rect.y=0;
110 rect.height = h ;
111 Refresh( TRUE , &rect ) ;
112 Update();
113 }
114
115 void wxStatusBarMac::OnPaint(wxPaintEvent& WXUNUSED(event) )
116 {
117 wxPaintDC dc(this);
118 dc.Clear() ;
119
120 int major,minor;
121 wxGetOsVersion( &major, &minor );
122 int w, h ;
123 GetSize( &w , &h ) ;
124
125 if ( MacIsReallyHilited() )
126 {
127 wxPen white( wxWHITE , 1 , wxSOLID ) ;
128 if (major >= 10 )
129 {
130 //Finder statusbar border color: (Project builder similar is 9B9B9B)
131 if ( MacGetTopLevelWindow()->MacGetMetalAppearance() )
132 dc.SetPen(wxPen(wxColour(0x40,40,40) ,1,wxSOLID)) ;
133 else
134 dc.SetPen(wxPen(wxColour(0xB1,0xB1,0xB1),1,wxSOLID));
135 }
136 else
137 {
138 wxPen black( wxBLACK , 1 , wxSOLID ) ;
139 dc.SetPen(black);
140 }
141 dc.DrawLine(0, 0 ,
142 w , 0);
143 dc.SetPen(white);
144 dc.DrawLine(0, 1 ,
145 w , 1);
146 }
147 else
148 {
149 if (major >= 10)
150 //Finder statusbar border color: (Project builder similar is 9B9B9B)
151 dc.SetPen(wxPen(wxColour(0xB1,0xB1,0xB1),1,wxSOLID));
152 else
153 dc.SetPen(wxPen(wxColour(0x80,0x80,0x80),1,wxSOLID));
154
155 dc.DrawLine(0, 0 ,
156 w , 0);
157 }
158
159 int i;
160 if ( GetFont().Ok() )
161 dc.SetFont(GetFont());
162 dc.SetBackgroundMode(wxTRANSPARENT);
163
164 for ( i = 0; i < m_nFields; i ++ )
165 DrawField(dc, i);
166 }
167
168 void wxStatusBarMac::MacHiliteChanged()
169 {
170 Refresh() ;
171 Update() ;
172 }