]> git.saurik.com Git - wxWidgets.git/blob - src/mac/statusbr.cpp
Added a param to ::Open() to allow the programmer to specify whether opening the...
[wxWidgets.git] / src / mac / statusbr.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: statbar.cpp
3 // Purpose: native implementation of wxStatusBar (optional)
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 AUTHOR
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "statusbr.h"
14 #endif
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include "wx/defs.h"
21 #include "wx/statusbr.h"
22
23 IMPLEMENT_DYNAMIC_CLASS(wxStatusBarMac, wxStatusBar);
24
25 BEGIN_EVENT_TABLE(wxStatusBarMac, wxStatusBar)
26 EVT_SIZE(wxStatusBarMac::OnSize)
27 END_EVENT_TABLE()
28
29
30 // ============================================================================
31 // implementation
32 // ============================================================================
33
34 // ----------------------------------------------------------------------------
35 // wxStatusBarMac class
36 // ----------------------------------------------------------------------------
37
38 wxStatusBarMac::wxStatusBarMac()
39 {
40 SetParent(NULL);
41 }
42
43 bool wxStatusBarMac::Create(wxWindow *parent, wxWindowID id, long style, const wxString& name = wxPanelNameStr)
44 {
45 SetParent(parent);
46
47 if (id == -1)
48 m_windowId = NewControlId();
49 else
50 m_windowId = id;
51
52 // TODO: create status bar
53 return FALSE;
54 }
55
56 void wxStatusBarMac::SetFieldsCount(int nFields, const int widths[])
57 {
58 wxASSERT( (nFields > 0) && (nFields < 255) );
59
60 m_nFields = nFields;
61
62 CopyFieldsWidth(widths);
63 SetFieldsWidth();
64 }
65
66 void wxStatusBarMac::SetStatusWidths(int n, const int widths[])
67 {
68 wxASSERT( n == m_nFields );
69
70 CopyFieldsWidth(widths);
71 SetFieldsWidth();
72 }
73
74 void wxStatusBarMac::CopyFieldsWidth(const int widths[])
75 {
76 if (widths && !m_statusWidths)
77 m_statusWidths = new int[m_nFields];
78
79 if ( widths != NULL ) {
80 for ( int i = 0; i < m_nFields; i++ )
81 m_statusWidths[i] = widths[i];
82 }
83 else {
84 delete [] m_statusWidths;
85 m_statusWidths = NULL;
86 }
87 }
88
89 void wxStatusBarMac::SetFieldsWidth()
90 {
91 int *pWidths = new int[m_nFields];
92
93 int nWindowWidth, y;
94 GetClientSize(&nWindowWidth, &y);
95
96 if ( m_statusWidths == NULL ) {
97 // default: all fields have the same width
98 int nWidth = nWindowWidth / m_nFields;
99 for ( int i = 0; i < m_nFields; i++ )
100 pWidths[i] = (i + 1) * nWidth;
101 }
102 else {
103 // -1 doesn't mean the same thing for wxWindows and Win32, recalc
104 int nTotalWidth = 0,
105 nVarCount = 0,
106 i;
107 for ( i = 0; i < m_nFields; i++ ) {
108 if ( m_statusWidths[i] == -1 )
109 nVarCount++;
110 else
111 nTotalWidth += m_statusWidths[i];
112 }
113
114 if ( nVarCount == 0 ) {
115 // wrong! at least one field must be of variable width
116 wxFAIL;
117
118 nVarCount++;
119 }
120
121 int nVarWidth = (nWindowWidth - nTotalWidth) / nVarCount;
122
123 // do fill the array
124 int nCurPos = 0;
125 for ( i = 0; i < m_nFields; i++ ) {
126 if ( m_statusWidths[i] == -1 )
127 nCurPos += nVarWidth;
128 else
129 nCurPos += m_statusWidths[i];
130 pWidths[i] = nCurPos;
131 }
132 }
133
134 // TODO: set widths
135
136 delete [] pWidths;
137 }
138
139 void wxStatusBarMac::SetStatusText(const wxString& strText, int nField)
140 {
141 // TODO
142 }
143
144 wxString wxStatusBarMac::GetStatusText(int nField) const
145 {
146 wxASSERT( (nField > -1) && (nField < m_nFields) );
147
148 // TODO
149 return wxString("");
150 }
151
152 void wxStatusBarMac::OnSize(wxSizeEvent& event)
153 {
154 // adjust fields widths to the new size
155 SetFieldsWidth();
156 }