1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/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)
10 // Copyright: (c) Jason Bagley; Art & Logic, Inc.
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
14 #include "wx/wxprec.h"
16 #include "wx/osx/private.h"
18 #if defined( __WXMAC__ )
20 #include "wx/osx/carbon/drawer.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxDrawerWindow
, wxWindow
)
24 // Use constants for now.
25 // These can be made into member variables and set dynamically.
26 const int kLeadingOffset
= 20;
27 const int kTrailingOffset
= 20;
30 // Converts Mac window edge constants to wxDirections, wxLEFT, wxRIGHT, etc.
31 static wxDirection
WindowEdgeToDirection(OptionBits edge
);
33 // Convert wxDirections to MAc window edge constants.
34 static OptionBits
DirectionToWindowEdge(wxDirection direction
);
37 wxDrawerWindow::wxDrawerWindow()
41 wxDrawerWindow::~wxDrawerWindow()
47 bool wxDrawerWindow::Create(wxWindow
*parent
,
48 wxWindowID id
, const wxString
& WXUNUSED(title
),
49 wxSize size
, wxDirection edge
, const wxString
& name
)
51 wxASSERT_MSG(NULL
!= parent
, wxT("wxDrawerWindows must be attached to a parent window."));
53 // Constrain the drawer size to the parent window.
54 const wxSize
parentSize(parent
->GetClientSize());
55 if (wxLEFT
== edge
|| wxRIGHT
== edge
)
57 if (size
.GetHeight() > parentSize
.GetHeight())
58 size
.SetHeight(parentSize
.GetHeight() - (kLeadingOffset
+ kTrailingOffset
));
62 if (size
.GetWidth() > parentSize
.GetWidth())
63 size
.SetWidth(parentSize
.GetWidth() - (kLeadingOffset
+ kTrailingOffset
));
66 // Create the drawer window.
67 const wxPoint
pos(0, 0);
68 const wxSize
dummySize(0,0);
69 const long style
= wxFRAME_DRAWER
;
71 bool success
= wxNonOwnedWindow::Create(parent
, id
, pos
, size
, style
, name
);
74 // this->MacCreateRealWindow(pos, size, style, name);
75 success
= (GetWXWindow() != NULL
);
81 SetBackgroundColour( wxColour( wxMacCreateCGColorFromHITheme( kThemeBrushDrawerBackground
) ) );
82 ::SetThemeWindowBackground((WindowRef
)GetWXWindow(), kThemeBrushDrawerBackground
, false);
84 // Leading and trailing offset are gaps from parent window edges
85 // to where the drawer starts.
86 ::SetDrawerOffsets((WindowRef
)GetWXWindow() , kLeadingOffset
, kTrailingOffset
);
88 // Set the drawers parent.
89 // Is there a better way to get the parent's WindowRef?
90 wxTopLevelWindow
* tlwParent
= wxDynamicCast(parent
, wxTopLevelWindow
);
91 if (NULL
!= tlwParent
)
93 OSStatus status
= ::SetDrawerParent((WindowRef
) GetWXWindow(),
94 (WindowRef
)tlwParent
->GetWXWindow());
95 success
= (noErr
== status
);
101 return success
&& SetPreferredEdge(edge
);
104 wxDirection
wxDrawerWindow::GetCurrentEdge() const
106 const OptionBits edge
= ::GetDrawerCurrentEdge((WindowRef
)GetWXWindow());
107 return WindowEdgeToDirection(edge
);
110 wxDirection
wxDrawerWindow::GetPreferredEdge() const
112 const OptionBits edge
= ::GetDrawerPreferredEdge((WindowRef
)GetWXWindow());
113 return WindowEdgeToDirection(edge
);
116 bool wxDrawerWindow::IsOpen() const
118 WindowDrawerState state
= ::GetDrawerState((WindowRef
)GetWXWindow());
119 return (state
== kWindowDrawerOpen
|| state
== kWindowDrawerOpening
);
122 bool wxDrawerWindow::Open(bool show
)
124 static const Boolean kAsynchronous
= true;
125 OSStatus status
= noErr
;
129 const OptionBits preferredEdge
= ::GetDrawerPreferredEdge((WindowRef
)GetWXWindow());
130 status
= ::OpenDrawer((WindowRef
)GetWXWindow(), preferredEdge
, kAsynchronous
);
133 status
= ::CloseDrawer((WindowRef
)GetWXWindow(), kAsynchronous
);
135 return (noErr
== status
);
138 bool wxDrawerWindow::SetPreferredEdge(wxDirection edge
)
140 const OSStatus status
= ::SetDrawerPreferredEdge((WindowRef
)GetWXWindow(),
141 DirectionToWindowEdge(edge
));
142 return (noErr
== status
);
146 OptionBits
DirectionToWindowEdge(wxDirection direction
)
152 edge
= kWindowEdgeTop
;
156 edge
= kWindowEdgeBottom
;
160 edge
= kWindowEdgeRight
;
165 edge
= kWindowEdgeLeft
;
171 wxDirection
WindowEdgeToDirection(OptionBits edge
)
173 wxDirection direction
;
180 case kWindowEdgeBottom
:
181 direction
= wxBOTTOM
;
184 case kWindowEdgeRight
:
188 case kWindowEdgeDefault
: // store current preferred and return that here?
189 case kWindowEdgeLeft
:
198 #endif // defined( __WXMAC__ )