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 #include "wx/wxprec.h"
17 #include "wx/mac/private.h"
19 #if defined( __WXMAC__ )
21 #include "wx/mac/carbon/drawer.h"
23 IMPLEMENT_DYNAMIC_CLASS(wxDrawerWindow
, wxWindow
)
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;
31 // Converts Mac window edge constants to wxDirections, wxLEFT, wxRIGHT, etc.
32 static wxDirection
WindowEdgeToDirection(OptionBits edge
);
34 // Convert wxDirections to MAc window edge constants.
35 static OptionBits
DirectionToWindowEdge(wxDirection direction
);
38 wxDrawerWindow::wxDrawerWindow()
42 wxDrawerWindow::~wxDrawerWindow()
44 m_isBeingDeleted
= TRUE
;
48 bool wxDrawerWindow::Create(wxWindow
*parent
,
49 wxWindowID id
, const wxString
& title
,
50 wxSize size
, wxDirection edge
, const wxString
& name
)
52 wxASSERT_MSG(NULL
!= parent
, wxT("wxDrawerWindows must be attached to a parent window."));
54 // Constrain the drawer size to the parent window.
55 const wxSize
parentSize(parent
->GetClientSize());
56 if (wxLEFT
== edge
|| wxRIGHT
== edge
)
58 if (size
.GetHeight() > parentSize
.GetHeight())
59 size
.SetHeight(parentSize
.GetHeight() - (kLeadingOffset
+ kTrailingOffset
));
63 if (size
.GetWidth() > parentSize
.GetWidth())
64 size
.SetWidth(parentSize
.GetWidth() - (kLeadingOffset
+ kTrailingOffset
));
67 // Create the drawer window.
68 const wxPoint
pos(0, 0);
69 const wxSize
dummySize(0,0);
70 const long style
= wxFRAME_DRAWER
;
72 bool success
= wxWindow::Create(parent
, id
, pos
, dummySize
, style
, name
);
75 this->MacCreateRealWindow(pos
, size
, style
, name
);
76 success
= (m_macWindow
!= NULL
);
82 SetBackgroundColour( wxColour( wxMacCreateCGColorFromHITheme( kThemeBrushDrawerBackground
) ) );
83 ::SetThemeWindowBackground((WindowRef
)m_macWindow
, kThemeBrushDrawerBackground
, false);
85 // Leading and trailing offset are gaps from parent window edges
86 // to where the drawer starts.
87 ::SetDrawerOffsets((WindowRef
)m_macWindow
, kLeadingOffset
, kTrailingOffset
);
89 // Set the drawers parent.
90 // Is there a better way to get the parent's WindowRef?
91 wxTopLevelWindow
* tlwParent
= wxDynamicCast(parent
, wxTopLevelWindow
);
92 if (NULL
!= tlwParent
)
94 OSStatus status
= ::SetDrawerParent((WindowRef
)m_macWindow
,
95 (WindowRef
)tlwParent
->MacGetWindowRef());
96 success
= (noErr
== status
);
102 return success
&& SetPreferredEdge(edge
);
105 wxDirection
wxDrawerWindow::GetCurrentEdge() const
107 const OptionBits edge
= ::GetDrawerCurrentEdge((WindowRef
)m_macWindow
);
108 return WindowEdgeToDirection(edge
);
111 wxDirection
wxDrawerWindow::GetPreferredEdge() const
113 const OptionBits edge
= ::GetDrawerPreferredEdge((WindowRef
)m_macWindow
);
114 return WindowEdgeToDirection(edge
);
117 bool wxDrawerWindow::IsOpen() const
119 WindowDrawerState state
= ::GetDrawerState((WindowRef
)m_macWindow
);
120 return (state
== kWindowDrawerOpen
|| state
== kWindowDrawerOpening
);
123 bool wxDrawerWindow::Open(bool show
)
125 static const Boolean kAsynchronous
= true;
126 OSStatus status
= noErr
;
130 const OptionBits preferredEdge
= ::GetDrawerPreferredEdge((WindowRef
)m_macWindow
);
131 status
= ::OpenDrawer((WindowRef
)m_macWindow
, preferredEdge
, kAsynchronous
);
134 status
= ::CloseDrawer((WindowRef
)m_macWindow
, kAsynchronous
);
136 return (noErr
== status
);
139 bool wxDrawerWindow::SetPreferredEdge(wxDirection edge
)
141 const OSStatus status
= ::SetDrawerPreferredEdge((WindowRef
)m_macWindow
,
142 DirectionToWindowEdge(edge
));
143 return (noErr
== status
);
147 OptionBits
DirectionToWindowEdge(wxDirection direction
)
153 edge
= kWindowEdgeTop
;
157 edge
= kWindowEdgeBottom
;
161 edge
= kWindowEdgeRight
;
166 edge
= kWindowEdgeLeft
;
172 wxDirection
WindowEdgeToDirection(OptionBits edge
)
174 wxDirection direction
;
181 case kWindowEdgeBottom
:
182 direction
= wxBOTTOM
;
185 case kWindowEdgeRight
:
189 case kWindowEdgeDefault
: // store current preferred and return that here?
190 case kWindowEdgeLeft
:
199 #endif // defined( __WXMAC__ )