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