]>
Commit | Line | Data |
---|---|---|
3e17bc3f RN |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: 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. | |
3f16885e RN |
7 | // Author: Jason Bagley & Ryan Norton |
8 | // Modified by: | |
3e17bc3f RN |
9 | // Created: 2004-30-01 |
10 | // RCS-ID: $Id$ | |
11 | // Copyright: (c) Jason Bagley; Art & Logic, Inc. | |
12 | // Licence: wxWindows licence | |
13 | ///////////////////////////////////////////////////////////////////////////// | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma implementation "control.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/defs.h" | |
20 | ||
21 | #include "wx/mac/carbon/drawer.h" | |
22 | #include "wx/mac/private.h" | |
23 | ||
24 | #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 ) | |
25 | ||
3e17bc3f RN |
26 | IMPLEMENT_DYNAMIC_CLASS(wxDrawerWindow, wxWindow) |
27 | ||
28 | // Use consants for now. | |
29 | // These can be made into member variables and set dynamically. | |
30 | const int kLeadingOffset = 20; | |
31 | const int kTrailingOffset = 20; | |
32 | ||
33 | ||
34 | // Converts Mac window edge constants to wxDirections, wxLEFT, wxRIGHT, etc. | |
35 | static wxDirection WindowEdgeToDirection(OptionBits edge); | |
36 | ||
37 | // Convert wxDirections to MAc window edge constants. | |
38 | static OptionBits DirectionToWindowEdge(wxDirection direction); | |
39 | ||
40 | ||
41 | wxDrawerWindow::wxDrawerWindow() | |
42 | { | |
43 | } | |
44 | ||
45 | wxDrawerWindow::~wxDrawerWindow() | |
46 | { | |
47 | m_isBeingDeleted = TRUE; | |
48 | this->Show(FALSE); | |
49 | } | |
50 | ||
51 | bool wxDrawerWindow::Create(wxWindow *parent, | |
52 | wxWindowID id, const wxString& title, | |
53 | wxSize size, wxDirection edge, const wxString& name) | |
54 | { | |
55 | wxASSERT_MSG(NULL != parent, "wxDrawerWindows must be attached to a parent window."); | |
56 | ||
57 | // Constrain the drawer size to the parent window. | |
58 | const wxSize parentSize(parent->GetClientSize()); | |
59 | if (wxLEFT == edge || wxRIGHT == edge) | |
60 | { | |
61 | if (size.GetHeight() > parentSize.GetHeight()) | |
62 | size.SetHeight(parentSize.GetHeight() - (kLeadingOffset + kTrailingOffset)); | |
63 | } | |
64 | else | |
65 | { | |
66 | if (size.GetWidth() > parentSize.GetWidth()) | |
67 | size.SetWidth(parentSize.GetWidth() - (kLeadingOffset + kTrailingOffset)); | |
68 | } | |
69 | ||
70 | // Create the drawer window. | |
71 | const wxPoint pos(0, 0); | |
72 | const wxSize dummySize(0,0); | |
73 | const long style = wxFRAME_DRAWER; | |
74 | ||
75 | bool success = wxWindow::Create(parent, id, pos, dummySize, style, name); | |
76 | if (success) | |
77 | { | |
78 | this->MacCreateRealWindow(title, pos, size, style, name); | |
79 | success = (m_macWindow != NULL); | |
80 | } | |
81 | ||
82 | if (success) | |
83 | { | |
84 | // Use drawer brush. | |
85 | m_macBackgroundBrush.MacSetTheme(kThemeBrushDrawerBackground); | |
86 | ::SetThemeWindowBackground((WindowRef)m_macWindow, | |
87 | m_macBackgroundBrush.MacGetTheme(), false); | |
88 | ||
89 | // Leading and trailing offset are gaps from parent window edges | |
90 | // to where the drawer starts. | |
91 | ::SetDrawerOffsets((WindowRef)m_macWindow, kLeadingOffset, kTrailingOffset); | |
92 | ||
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) | |
97 | { | |
98 | OSStatus status = ::SetDrawerParent((WindowRef)m_macWindow, | |
99 | (WindowRef)tlwParent->MacGetWindowRef()); | |
100 | success = (noErr == status); | |
101 | } | |
102 | else | |
103 | success = false; | |
104 | } | |
105 | ||
106 | return success && SetPreferredEdge(edge); | |
107 | } | |
108 | ||
109 | wxDirection wxDrawerWindow::GetCurrentEdge() const | |
110 | { | |
111 | const OptionBits edge = ::GetDrawerCurrentEdge((WindowRef)m_macWindow); | |
112 | return WindowEdgeToDirection(edge); | |
113 | } | |
114 | ||
115 | wxDirection wxDrawerWindow::GetPreferredEdge() const | |
116 | { | |
117 | const OptionBits edge = ::GetDrawerPreferredEdge((WindowRef)m_macWindow); | |
118 | return WindowEdgeToDirection(edge); | |
119 | } | |
120 | ||
121 | bool wxDrawerWindow::IsOpen() const | |
122 | { | |
123 | WindowDrawerState state = ::GetDrawerState((WindowRef)m_macWindow); | |
124 | return (state == kWindowDrawerOpen || state == kWindowDrawerOpening); | |
125 | } | |
126 | ||
127 | bool wxDrawerWindow::Open(bool show) | |
128 | { | |
129 | static const Boolean kAsynchronous = true; | |
130 | OSStatus status = noErr; | |
131 | ||
132 | if (show) | |
133 | { | |
134 | const OptionBits preferredEdge = ::GetDrawerPreferredEdge((WindowRef)m_macWindow); | |
135 | status = ::OpenDrawer((WindowRef)m_macWindow, preferredEdge, kAsynchronous); | |
136 | } | |
137 | else | |
138 | status = ::CloseDrawer((WindowRef)m_macWindow, kAsynchronous); | |
139 | ||
140 | return (noErr == status); | |
141 | } | |
142 | ||
143 | bool wxDrawerWindow::SetPreferredEdge(wxDirection edge) | |
144 | { | |
145 | const OSStatus status = ::SetDrawerPreferredEdge((WindowRef)m_macWindow, | |
146 | DirectionToWindowEdge(edge)); | |
147 | return (noErr == status); | |
148 | } | |
149 | ||
150 | ||
151 | OptionBits DirectionToWindowEdge(wxDirection direction) | |
152 | { | |
153 | OptionBits edge; | |
154 | switch (direction) | |
155 | { | |
156 | case wxTOP: | |
157 | edge = kWindowEdgeTop; | |
158 | break; | |
159 | ||
160 | case wxBOTTOM: | |
161 | edge = kWindowEdgeBottom; | |
162 | break; | |
163 | ||
164 | case wxRIGHT: | |
165 | edge = kWindowEdgeRight; | |
166 | break; | |
167 | ||
168 | case wxLEFT: | |
169 | default: | |
170 | edge = kWindowEdgeLeft; | |
171 | break; | |
172 | } | |
173 | return edge; | |
174 | } | |
175 | ||
176 | wxDirection WindowEdgeToDirection(OptionBits edge) | |
177 | { | |
178 | wxDirection direction; | |
179 | switch (edge) | |
180 | { | |
181 | case kWindowEdgeTop: | |
182 | direction = wxTOP; | |
183 | break; | |
184 | ||
185 | case kWindowEdgeBottom: | |
186 | direction = wxBOTTOM; | |
187 | break; | |
188 | ||
189 | case kWindowEdgeRight: | |
190 | direction = wxRIGHT; | |
191 | break; | |
192 | ||
193 | case kWindowEdgeDefault: // store current preferred and return that here? | |
194 | case kWindowEdgeLeft: | |
195 | default: | |
196 | direction = wxLEFT; | |
197 | break; | |
198 | } | |
199 | ||
200 | return direction; | |
201 | } | |
202 | ||
203 | #endif // defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 ) | |
204 |