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
11 // Copyright: (c) Jason Bagley; Art & Logic, Inc.
12 // Licence: wxWindows licence
13 /////////////////////////////////////////////////////////////////////////////
16 #pragma implementation "control.h"
21 #include "wx/mac/carbon/drawer.h"
22 #include "wx/mac/private.h"
24 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
27 // ¥ Contents do not draw on drawer opening. They do when a window is deactivated
28 // with the drawer open, and contents stay visible thereafter.
30 IMPLEMENT_DYNAMIC_CLASS(wxDrawerWindow
, wxWindow
)
32 // Use consants for now.
33 // These can be made into member variables and set dynamically.
34 const int kLeadingOffset
= 20;
35 const int kTrailingOffset
= 20;
38 // Converts Mac window edge constants to wxDirections, wxLEFT, wxRIGHT, etc.
39 static wxDirection
WindowEdgeToDirection(OptionBits edge
);
41 // Convert wxDirections to MAc window edge constants.
42 static OptionBits
DirectionToWindowEdge(wxDirection direction
);
45 wxDrawerWindow::wxDrawerWindow()
49 wxDrawerWindow::~wxDrawerWindow()
51 m_isBeingDeleted
= TRUE
;
55 bool wxDrawerWindow::Create(wxWindow
*parent
,
56 wxWindowID id
, const wxString
& title
,
57 wxSize size
, wxDirection edge
, const wxString
& name
)
59 wxASSERT_MSG(NULL
!= parent
, "wxDrawerWindows must be attached to a parent window.");
61 // Constrain the drawer size to the parent window.
62 const wxSize
parentSize(parent
->GetClientSize());
63 if (wxLEFT
== edge
|| wxRIGHT
== edge
)
65 if (size
.GetHeight() > parentSize
.GetHeight())
66 size
.SetHeight(parentSize
.GetHeight() - (kLeadingOffset
+ kTrailingOffset
));
70 if (size
.GetWidth() > parentSize
.GetWidth())
71 size
.SetWidth(parentSize
.GetWidth() - (kLeadingOffset
+ kTrailingOffset
));
74 // Create the drawer window.
75 const wxPoint
pos(0, 0);
76 const wxSize
dummySize(0,0);
77 const long style
= wxFRAME_DRAWER
;
79 bool success
= wxWindow::Create(parent
, id
, pos
, dummySize
, style
, name
);
82 this->MacCreateRealWindow(title
, pos
, size
, style
, name
);
83 success
= (m_macWindow
!= NULL
);
89 m_macBackgroundBrush
.MacSetTheme(kThemeBrushDrawerBackground
);
90 ::SetThemeWindowBackground((WindowRef
)m_macWindow
,
91 m_macBackgroundBrush
.MacGetTheme(), false);
93 // Leading and trailing offset are gaps from parent window edges
94 // to where the drawer starts.
95 ::SetDrawerOffsets((WindowRef
)m_macWindow
, kLeadingOffset
, kTrailingOffset
);
97 // Set the drawers parent.
98 // Is there a better way to get the parent's WindowRef?
99 wxTopLevelWindow
* tlwParent
= wxDynamicCast(parent
, wxTopLevelWindow
);
100 if (NULL
!= tlwParent
)
102 OSStatus status
= ::SetDrawerParent((WindowRef
)m_macWindow
,
103 (WindowRef
)tlwParent
->MacGetWindowRef());
104 success
= (noErr
== status
);
110 return success
&& SetPreferredEdge(edge
);
113 wxDirection
wxDrawerWindow::GetCurrentEdge() const
115 const OptionBits edge
= ::GetDrawerCurrentEdge((WindowRef
)m_macWindow
);
116 return WindowEdgeToDirection(edge
);
119 wxDirection
wxDrawerWindow::GetPreferredEdge() const
121 const OptionBits edge
= ::GetDrawerPreferredEdge((WindowRef
)m_macWindow
);
122 return WindowEdgeToDirection(edge
);
125 bool wxDrawerWindow::IsOpen() const
127 WindowDrawerState state
= ::GetDrawerState((WindowRef
)m_macWindow
);
128 return (state
== kWindowDrawerOpen
|| state
== kWindowDrawerOpening
);
131 bool wxDrawerWindow::Open(bool show
)
133 static const Boolean kAsynchronous
= true;
134 OSStatus status
= noErr
;
138 const OptionBits preferredEdge
= ::GetDrawerPreferredEdge((WindowRef
)m_macWindow
);
139 status
= ::OpenDrawer((WindowRef
)m_macWindow
, preferredEdge
, kAsynchronous
);
142 status
= ::CloseDrawer((WindowRef
)m_macWindow
, kAsynchronous
);
144 return (noErr
== status
);
147 bool wxDrawerWindow::SetPreferredEdge(wxDirection edge
)
149 const OSStatus status
= ::SetDrawerPreferredEdge((WindowRef
)m_macWindow
,
150 DirectionToWindowEdge(edge
));
151 return (noErr
== status
);
155 OptionBits
DirectionToWindowEdge(wxDirection direction
)
161 edge
= kWindowEdgeTop
;
165 edge
= kWindowEdgeBottom
;
169 edge
= kWindowEdgeRight
;
174 edge
= kWindowEdgeLeft
;
180 wxDirection
WindowEdgeToDirection(OptionBits edge
)
182 wxDirection direction
;
189 case kWindowEdgeBottom
:
190 direction
= wxBOTTOM
;
193 case kWindowEdgeRight
:
197 case kWindowEdgeDefault
: // store current preferred and return that here?
198 case kWindowEdgeLeft
:
207 #endif // defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )