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