in plugin/:
[moon.git] / src / popup.cpp
blob41b4d3427b5f9b25f0fe8e25b798483eb73ca6f2
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * popup.cpp
5 * Copyright 2009 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
8 *
9 */
11 #include "popup.h"
12 #include "runtime.h"
14 Popup::Popup ()
16 SetObjectType (Type::POPUP);
17 shutting_down = false;
18 visible = false;
19 GetDeployment ()->AddHandler (Deployment::ShuttingDownEvent, ShuttingDownCallback, this);
22 void
23 Popup::Dispose ()
25 if (!shutting_down && GetIsOpen ())
26 Hide (GetChild ());
27 GetDeployment ()->RemoveHandler (Deployment::ShuttingDownEvent, ShuttingDownCallback, this);
28 FrameworkElement::Dispose ();
31 void
32 Popup::HitTest (cairo_t *cr, Point p, List *uielement_list)
34 if (visible)
35 FrameworkElement::HitTest (cr, p, uielement_list);
38 void
39 Popup::OnPropertyChanged (PropertyChangedEventArgs *args, MoonError *error)
41 if (args->GetProperty ()->GetOwnerType() != Type::POPUP) {
42 FrameworkElement::OnPropertyChanged (args, error);
43 return;
46 if (args->GetId () == Popup::IsOpenProperty) {
47 // we intentionally don't track whether we've added a tick
48 // call (to make sure we only add it once) for this event
49 // because multiple IsOpen changes cause multiple async events
50 // in SL.
51 if (args->GetNewValue () && args->GetNewValue ()->AsBool ()) {
52 Show (GetChild ());
54 EmitAsync (Popup::OpenedEvent);
56 else {
57 Hide (GetChild ());
59 EmitAsync (Popup::ClosedEvent);
61 } else if (args->GetId () == Popup::ChildProperty) {
62 if (args->GetOldValue () && !args->GetOldValue ()->GetIsNull ()) {
63 FrameworkElement *el = args->GetOldValue ()->AsFrameworkElement ();
64 if (GetIsOpen ())
65 Hide (el);
67 el->SetLogicalParent (NULL, error);
68 if (error->number)
69 return;
71 if (args->GetNewValue () && !args->GetNewValue ()->GetIsNull ()) {
72 FrameworkElement *el = args->GetNewValue ()->AsFrameworkElement ();
73 args->GetNewValue ()->AsFrameworkElement ()->SetLogicalParent (this, error);
74 if (error->number)
75 return;
77 if (GetIsOpen ())
78 Show (el);
80 } else if (args->GetId () == Popup::HorizontalOffsetProperty
81 || args->GetId () == Popup::VerticalOffsetProperty) {
82 UIElement * child = GetChild ();
83 if (child)
84 child->UpdateTransform ();
86 NotifyListenersOfPropertyChange (args, error);
89 void
90 Popup::ShuttingDownHandler (Deployment *sender, EventArgs *args)
92 shutting_down = true;
95 void
96 Popup::Hide (UIElement *child)
98 if (!visible || !child)
99 return;
101 visible = false;
102 Deployment::GetCurrent ()->GetSurface ()->DetachLayer (child);
105 void
106 Popup::SetSurface (Surface *s)
108 FrameworkElement::SetSurface (s);
111 void
112 Popup::Show (UIElement *child)
114 if (visible || !child)
115 return;
117 visible = true;
118 Deployment::GetCurrent ()->GetSurface ()->AttachLayer (child);