1 /////////////////////////////////////////////////////////////////////////////
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)
11 // Copyright: (c) Jason Bagley; Art & Logic, Inc.
12 // Licence: wxWindows licence
13 /////////////////////////////////////////////////////////////////////////////
16 #pragma implementation "control.h"
20 #include "wx/mac/private.h"
22 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
24 #include "wx/mac/carbon/drawer.h"
26 IMPLEMENT_DYNAMIC_CLASS(wxDrawerWindow
, wxWindow
)
28 // Use constants for now.
29 // These can be made into member variables and set dynamically.
30 const int kLeadingOffset
= 20;
31 const int kTrailingOffset
= 20;
34 // Converts Mac window edge constants to wxDirections, wxLEFT, wxRIGHT, etc.
35 static wxDirection
WindowEdgeToDirection(OptionBits edge
);
37 // Convert wxDirections to MAc window edge constants.
38 static OptionBits
DirectionToWindowEdge(wxDirection direction
);
41 wxDrawerWindow::wxDrawerWindow()
45 wxDrawerWindow::~wxDrawerWindow()
47 m_isBeingDeleted
= TRUE
;
51 bool wxDrawerWindow::Create(wxWindow
*parent
,
52 wxWindowID id
, const wxString
& title
,
53 wxSize size
, wxDirection edge
, const wxString
& name
)
55 wxASSERT_MSG(NULL
!= parent
, wxT("wxDrawerWindows must be attached to a parent window."));
57 // Constrain the drawer size to the parent window.
58 const wxSize
parentSize(parent
->GetClientSize());
59 if (wxLEFT
== edge
|| wxRIGHT
== edge
)
61 if (size
.GetHeight() > parentSize
.GetHeight())
62 size
.SetHeight(parentSize
.GetHeight() - (kLeadingOffset
+ kTrailingOffset
));
66 if (size
.GetWidth() > parentSize
.GetWidth())
67 size
.SetWidth(parentSize
.GetWidth() - (kLeadingOffset
+ kTrailingOffset
));
70 // Create the drawer window.
71 const wxPoint
pos(0, 0);
72 const wxSize
dummySize(0,0);
73 const long style
= wxFRAME_DRAWER
;
75 bool success
= wxWindow::Create(parent
, id
, pos
, dummySize
, style
, name
);
78 this->MacCreateRealWindow(title
, pos
, size
, style
, name
);
79 success
= (m_macWindow
!= NULL
);
85 m_macBackgroundBrush
.MacSetTheme(kThemeBrushDrawerBackground
);
86 ::SetThemeWindowBackground((WindowRef
)m_macWindow
,
87 m_macBackgroundBrush
.MacGetTheme(), false);
89 // Leading and trailing offset are gaps from parent window edges
90 // to where the drawer starts.
91 ::SetDrawerOffsets((WindowRef
)m_macWindow
, kLeadingOffset
, kTrailingOffset
);
93 // Set the drawers parent.
94 // Is there a better way to get the parent's WindowRef?
95 wxTopLevelWindow
* tlwParent
= wxDynamicCast(parent
, wxTopLevelWindow
);
96 if (NULL
!= tlwParent
)
98 OSStatus status
= ::SetDrawerParent((WindowRef
)m_macWindow
,
99 (WindowRef
)tlwParent
->MacGetWindowRef());
100 success
= (noErr
== status
);
106 return success
&& SetPreferredEdge(edge
);
109 wxDirection
wxDrawerWindow::GetCurrentEdge() const
111 const OptionBits edge
= ::GetDrawerCurrentEdge((WindowRef
)m_macWindow
);
112 return WindowEdgeToDirection(edge
);
115 wxDirection
wxDrawerWindow::GetPreferredEdge() const
117 const OptionBits edge
= ::GetDrawerPreferredEdge((WindowRef
)m_macWindow
);
118 return WindowEdgeToDirection(edge
);
121 bool wxDrawerWindow::IsOpen() const
123 WindowDrawerState state
= ::GetDrawerState((WindowRef
)m_macWindow
);
124 return (state
== kWindowDrawerOpen
|| state
== kWindowDrawerOpening
);
127 bool wxDrawerWindow::Open(bool show
)
129 static const Boolean kAsynchronous
= true;
130 OSStatus status
= noErr
;
134 const OptionBits preferredEdge
= ::GetDrawerPreferredEdge((WindowRef
)m_macWindow
);
135 status
= ::OpenDrawer((WindowRef
)m_macWindow
, preferredEdge
, kAsynchronous
);
138 status
= ::CloseDrawer((WindowRef
)m_macWindow
, kAsynchronous
);
140 return (noErr
== status
);
143 bool wxDrawerWindow::SetPreferredEdge(wxDirection edge
)
145 const OSStatus status
= ::SetDrawerPreferredEdge((WindowRef
)m_macWindow
,
146 DirectionToWindowEdge(edge
));
147 return (noErr
== status
);
151 OptionBits
DirectionToWindowEdge(wxDirection direction
)
157 edge
= kWindowEdgeTop
;
161 edge
= kWindowEdgeBottom
;
165 edge
= kWindowEdgeRight
;
170 edge
= kWindowEdgeLeft
;
176 wxDirection
WindowEdgeToDirection(OptionBits edge
)
178 wxDirection direction
;
185 case kWindowEdgeBottom
:
186 direction
= wxBOTTOM
;
189 case kWindowEdgeRight
:
193 case kWindowEdgeDefault
: // store current preferred and return that here?
194 case kWindowEdgeLeft
:
203 #endif // defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )