]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/drawer.cpp
uninitialized variable warning fixed (modified patch 1434065)
[wxWidgets.git] / src / mac / carbon / drawer.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: drawer.cpp
3 // Purpose: Drawer child window classes.
4 // Drawer windows appear under their parent window and
5 // behave like a drawer, opening and closing to reveal
6 // content that does not need to be visible at all times.
7 // Author: Jason Bagley
8 // Modified by: Ryan Norton (To make it work :), plus bug fixes)
9 // Created: 2004-30-01
10 // RCS-ID: $Id$
11 // Copyright: (c) Jason Bagley; Art & Logic, Inc.
12 // Licence: wxWindows licence
13 /////////////////////////////////////////////////////////////////////////////
14
15 #include "wx/wxprec.h"
16
17 #include "wx/mac/private.h"
18
19 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
20
21 #include "wx/mac/carbon/drawer.h"
22
23 IMPLEMENT_DYNAMIC_CLASS(wxDrawerWindow, wxWindow)
24
25 // Use constants for now.
26 // These can be made into member variables and set dynamically.
27 const int kLeadingOffset = 20;
28 const int kTrailingOffset = 20;
29
30
31 // Converts Mac window edge constants to wxDirections, wxLEFT, wxRIGHT, etc.
32 static wxDirection WindowEdgeToDirection(OptionBits edge);
33
34 // Convert wxDirections to MAc window edge constants.
35 static OptionBits DirectionToWindowEdge(wxDirection direction);
36
37
38 wxDrawerWindow::wxDrawerWindow()
39 {
40 }
41
42 wxDrawerWindow::~wxDrawerWindow()
43 {
44 m_isBeingDeleted = TRUE;
45 this->Show(FALSE);
46 }
47
48 bool wxDrawerWindow::Create(wxWindow *parent,
49 wxWindowID id, const wxString& title,
50 wxSize size, wxDirection edge, const wxString& name)
51 {
52 wxASSERT_MSG(NULL != parent, wxT("wxDrawerWindows must be attached to a parent window."));
53
54 // Constrain the drawer size to the parent window.
55 const wxSize parentSize(parent->GetClientSize());
56 if (wxLEFT == edge || wxRIGHT == edge)
57 {
58 if (size.GetHeight() > parentSize.GetHeight())
59 size.SetHeight(parentSize.GetHeight() - (kLeadingOffset + kTrailingOffset));
60 }
61 else
62 {
63 if (size.GetWidth() > parentSize.GetWidth())
64 size.SetWidth(parentSize.GetWidth() - (kLeadingOffset + kTrailingOffset));
65 }
66
67 // Create the drawer window.
68 const wxPoint pos(0, 0);
69 const wxSize dummySize(0,0);
70 const long style = wxFRAME_DRAWER;
71
72 bool success = wxWindow::Create(parent, id, pos, dummySize, style, name);
73 if (success)
74 {
75 this->MacCreateRealWindow(title, pos, size, style, name);
76 success = (m_macWindow != NULL);
77 }
78
79 if (success)
80 {
81 // Use drawer brush.
82 m_macBackgroundBrush.MacSetTheme(kThemeBrushDrawerBackground);
83 ::SetThemeWindowBackground((WindowRef)m_macWindow,
84 m_macBackgroundBrush.MacGetTheme(), false);
85
86 // Leading and trailing offset are gaps from parent window edges
87 // to where the drawer starts.
88 ::SetDrawerOffsets((WindowRef)m_macWindow, kLeadingOffset, kTrailingOffset);
89
90 // Set the drawers parent.
91 // Is there a better way to get the parent's WindowRef?
92 wxTopLevelWindow* tlwParent = wxDynamicCast(parent, wxTopLevelWindow);
93 if (NULL != tlwParent)
94 {
95 OSStatus status = ::SetDrawerParent((WindowRef)m_macWindow,
96 (WindowRef)tlwParent->MacGetWindowRef());
97 success = (noErr == status);
98 }
99 else
100 success = false;
101 }
102
103 return success && SetPreferredEdge(edge);
104 }
105
106 wxDirection wxDrawerWindow::GetCurrentEdge() const
107 {
108 const OptionBits edge = ::GetDrawerCurrentEdge((WindowRef)m_macWindow);
109 return WindowEdgeToDirection(edge);
110 }
111
112 wxDirection wxDrawerWindow::GetPreferredEdge() const
113 {
114 const OptionBits edge = ::GetDrawerPreferredEdge((WindowRef)m_macWindow);
115 return WindowEdgeToDirection(edge);
116 }
117
118 bool wxDrawerWindow::IsOpen() const
119 {
120 WindowDrawerState state = ::GetDrawerState((WindowRef)m_macWindow);
121 return (state == kWindowDrawerOpen || state == kWindowDrawerOpening);
122 }
123
124 bool wxDrawerWindow::Open(bool show)
125 {
126 static const Boolean kAsynchronous = true;
127 OSStatus status = noErr;
128
129 if (show)
130 {
131 const OptionBits preferredEdge = ::GetDrawerPreferredEdge((WindowRef)m_macWindow);
132 status = ::OpenDrawer((WindowRef)m_macWindow, preferredEdge, kAsynchronous);
133 }
134 else
135 status = ::CloseDrawer((WindowRef)m_macWindow, kAsynchronous);
136
137 return (noErr == status);
138 }
139
140 bool wxDrawerWindow::SetPreferredEdge(wxDirection edge)
141 {
142 const OSStatus status = ::SetDrawerPreferredEdge((WindowRef)m_macWindow,
143 DirectionToWindowEdge(edge));
144 return (noErr == status);
145 }
146
147
148 OptionBits DirectionToWindowEdge(wxDirection direction)
149 {
150 OptionBits edge;
151 switch (direction)
152 {
153 case wxTOP:
154 edge = kWindowEdgeTop;
155 break;
156
157 case wxBOTTOM:
158 edge = kWindowEdgeBottom;
159 break;
160
161 case wxRIGHT:
162 edge = kWindowEdgeRight;
163 break;
164
165 case wxLEFT:
166 default:
167 edge = kWindowEdgeLeft;
168 break;
169 }
170 return edge;
171 }
172
173 wxDirection WindowEdgeToDirection(OptionBits edge)
174 {
175 wxDirection direction;
176 switch (edge)
177 {
178 case kWindowEdgeTop:
179 direction = wxTOP;
180 break;
181
182 case kWindowEdgeBottom:
183 direction = wxBOTTOM;
184 break;
185
186 case kWindowEdgeRight:
187 direction = wxRIGHT;
188 break;
189
190 case kWindowEdgeDefault: // store current preferred and return that here?
191 case kWindowEdgeLeft:
192 default:
193 direction = wxLEFT;
194 break;
195 }
196
197 return direction;
198 }
199
200 #endif // defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
201