1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
5 * Copyright 2009 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
13 #include "deployment.h"
17 SetObjectType (Type::POPUP
);
18 shutting_down
= false;
20 GetDeployment ()->AddHandler (Deployment::ShuttingDownEvent
, ShuttingDownCallback
, this);
26 if (!shutting_down
&& GetIsOpen ())
28 GetDeployment ()->RemoveHandler (Deployment::ShuttingDownEvent
, ShuttingDownCallback
, this);
29 FrameworkElement::Dispose ();
33 Popup::HitTest (cairo_t
*cr
, Point p
, List
*uielement_list
)
36 FrameworkElement::HitTest (cr
, p
, uielement_list
);
40 Popup::OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
)
42 if (args
->GetProperty ()->GetOwnerType() != Type::POPUP
) {
43 FrameworkElement::OnPropertyChanged (args
, error
);
47 if (args
->GetId () == Popup::IsOpenProperty
) {
48 // we intentionally don't track whether we've added a tick
49 // call (to make sure we only add it once) for this event
50 // because multiple IsOpen changes cause multiple async events
52 if (args
->GetNewValue () && args
->GetNewValue ()->AsBool ()) {
55 EmitAsync (Popup::OpenedEvent
);
60 EmitAsync (Popup::ClosedEvent
);
62 } else if (args
->GetId () == Popup::ChildProperty
) {
63 if (args
->GetOldValue () && !args
->GetOldValue ()->GetIsNull ()) {
64 FrameworkElement
*el
= args
->GetOldValue ()->AsFrameworkElement ();
68 el
->SetLogicalParent (NULL
, error
);
72 if (args
->GetNewValue () && !args
->GetNewValue ()->GetIsNull ()) {
73 FrameworkElement
*el
= args
->GetNewValue ()->AsFrameworkElement ();
74 el
->SetLogicalParent (this, error
);
81 } else if (args
->GetId () == Popup::HorizontalOffsetProperty
82 || args
->GetId () == Popup::VerticalOffsetProperty
) {
83 UIElement
* child
= GetChild ();
85 child
->UpdateTransform ();
87 NotifyListenersOfPropertyChange (args
, error
);
91 Popup::ShuttingDownHandler (Deployment
*sender
, EventArgs
*args
)
97 Popup::Hide (UIElement
*child
)
99 if (!visible
|| !child
)
103 Deployment::GetCurrent ()->GetSurface ()->DetachLayer (child
);
104 // When the popup is closed, we signal the child that its parent
105 // is enabled as it no longer has any parent
106 PropagateIsEnabledState (child
, true);
110 Popup::SetSurface (Surface
*s
)
112 FrameworkElement::SetSurface (s
);
116 Popup::Show (UIElement
*child
)
118 if (visible
|| !child
)
122 Deployment::GetCurrent ()->GetSurface ()->AttachLayer (child
);
123 PropagateIsEnabledState (child
, Control::GetParentEnabledState (this));
127 Popup::PropagateIsEnabledState (UIElement
*child
, bool enabled_parent
)
129 DeepTreeWalker
walker (child
);
130 while (UIElement
*e
= walker
.Step ()) {
131 if (!e
->Is (Type::CONTROL
))
134 Control
*control
= (Control
*) e
;
135 control
->enabled_parent
= enabled_parent
;
136 control
->UpdateEnabled ();
137 walker
.SkipBranch ();