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 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma implementation "control.h"
19 #include "wx/wxprec.h"
21 #include "wx/mac/private.h"
23 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
25 #include "wx/mac/carbon/drawer.h"
27 IMPLEMENT_DYNAMIC_CLASS(wxDrawerWindow
, wxWindow
)
29 // Use constants for now.
30 // These can be made into member variables and set dynamically.
31 const int kLeadingOffset
= 20;
32 const int kTrailingOffset
= 20;
35 // Converts Mac window edge constants to wxDirections, wxLEFT, wxRIGHT, etc.
36 static wxDirection
WindowEdgeToDirection(OptionBits edge
);
38 // Convert wxDirections to MAc window edge constants.
39 static OptionBits
DirectionToWindowEdge(wxDirection direction
);
42 wxDrawerWindow::wxDrawerWindow()
46 wxDrawerWindow::~wxDrawerWindow()
48 m_isBeingDeleted
= TRUE
;
52 bool wxDrawerWindow::Create(wxWindow
*parent
,
53 wxWindowID id
, const wxString
& title
,
54 wxSize size
, wxDirection edge
, const wxString
& name
)
56 wxASSERT_MSG(NULL
!= parent
, wxT("wxDrawerWindows must be attached to a parent window."));
58 // Constrain the drawer size to the parent window.
59 const wxSize
parentSize(parent
->GetClientSize());
60 if (wxLEFT
== edge
|| wxRIGHT
== edge
)
62 if (size
.GetHeight() > parentSize
.GetHeight())
63 size
.SetHeight(parentSize
.GetHeight() - (kLeadingOffset
+ kTrailingOffset
));
67 if (size
.GetWidth() > parentSize
.GetWidth())
68 size
.SetWidth(parentSize
.GetWidth() - (kLeadingOffset
+ kTrailingOffset
));
71 // Create the drawer window.
72 const wxPoint
pos(0, 0);
73 const wxSize
dummySize(0,0);
74 const long style
= wxFRAME_DRAWER
;
76 bool success
= wxWindow::Create(parent
, id
, pos
, dummySize
, style
, name
);
79 this->MacCreateRealWindow(title
, pos
, size
, style
, name
);
80 success
= (m_macWindow
!= NULL
);
86 m_macBackgroundBrush
.MacSetTheme(kThemeBrushDrawerBackground
);
87 ::SetThemeWindowBackground((WindowRef
)m_macWindow
,
88 m_macBackgroundBrush
.MacGetTheme(), false);
90 // Leading and trailing offset are gaps from parent window edges
91 // to where the drawer starts.
92 ::SetDrawerOffsets((WindowRef
)m_macWindow
, kLeadingOffset
, kTrailingOffset
);
94 // Set the drawers parent.
95 // Is there a better way to get the parent's WindowRef?
96 wxTopLevelWindow
* tlwParent
= wxDynamicCast(parent
, wxTopLevelWindow
);
97 if (NULL
!= tlwParent
)
99 OSStatus status
= ::SetDrawerParent((WindowRef
)m_macWindow
,
100 (WindowRef
)tlwParent
->MacGetWindowRef());
101 success
= (noErr
== status
);
107 return success
&& SetPreferredEdge(edge
);
110 wxDirection
wxDrawerWindow::GetCurrentEdge() const
112 const OptionBits edge
= ::GetDrawerCurrentEdge((WindowRef
)m_macWindow
);
113 return WindowEdgeToDirection(edge
);
116 wxDirection
wxDrawerWindow::GetPreferredEdge() const
118 const OptionBits edge
= ::GetDrawerPreferredEdge((WindowRef
)m_macWindow
);
119 return WindowEdgeToDirection(edge
);
122 bool wxDrawerWindow::IsOpen() const
124 WindowDrawerState state
= ::GetDrawerState((WindowRef
)m_macWindow
);
125 return (state
== kWindowDrawerOpen
|| state
== kWindowDrawerOpening
);
128 bool wxDrawerWindow::Open(bool show
)
130 static const Boolean kAsynchronous
= true;
131 OSStatus status
= noErr
;
135 const OptionBits preferredEdge
= ::GetDrawerPreferredEdge((WindowRef
)m_macWindow
);
136 status
= ::OpenDrawer((WindowRef
)m_macWindow
, preferredEdge
, kAsynchronous
);
139 status
= ::CloseDrawer((WindowRef
)m_macWindow
, kAsynchronous
);
141 return (noErr
== status
);
144 bool wxDrawerWindow::SetPreferredEdge(wxDirection edge
)
146 const OSStatus status
= ::SetDrawerPreferredEdge((WindowRef
)m_macWindow
,
147 DirectionToWindowEdge(edge
));
148 return (noErr
== status
);
152 OptionBits
DirectionToWindowEdge(wxDirection direction
)
158 edge
= kWindowEdgeTop
;
162 edge
= kWindowEdgeBottom
;
166 edge
= kWindowEdgeRight
;
171 edge
= kWindowEdgeLeft
;
177 wxDirection
WindowEdgeToDirection(OptionBits edge
)
179 wxDirection direction
;
186 case kWindowEdgeBottom
:
187 direction
= wxBOTTOM
;
190 case kWindowEdgeRight
:
194 case kWindowEdgeDefault
: // store current preferred and return that here?
195 case kWindowEdgeLeft
:
204 #endif // defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )