"Fossies" - the Fresh Open Source Software Archive

Member "google-gadgets-for-linux-0.11.2/ggadget/object_element.cc" (12 May 2009, 3616 Bytes) of package /linux/misc/old/google-gadgets-for-linux-0.11.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2   Copyright 2008 Google Inc.
    3 
    4   Licensed under the Apache License, Version 2.0 (the "License");
    5   you may not use this file except in compliance with the License.
    6   You may obtain a copy of the License at
    7 
    8        http://www.apache.org/licenses/LICENSE-2.0
    9 
   10   Unless required by applicable law or agreed to in writing, software
   11   distributed under the License is distributed on an "AS IS" BASIS,
   12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13   See the License for the specific language governing permissions and
   14   limitations under the License.
   15 */
   16 
   17 #include "object_element.h"
   18 
   19 #include <string>
   20 
   21 #include "canvas_interface.h"
   22 #include "elements.h"
   23 #include "element_factory.h"
   24 #include "view.h"
   25 #include "small_object.h"
   26 
   27 namespace ggadget {
   28 
   29 class ObjectElement::Impl : public SmallObject<> {
   30  public:
   31   Impl() : object_(NULL) { }
   32   ~Impl() { delete object_; }
   33 
   34   BasicElement *object_;
   35   std::string classid_;
   36 };
   37 
   38 ObjectElement::ObjectElement(View *view, const char *name)
   39     : BasicElement(view, "object", name, false),
   40       impl_(new Impl()) {
   41   SetEnabled(true);
   42 }
   43 
   44 ObjectElement::~ObjectElement() {
   45   delete impl_;
   46 }
   47 
   48 void ObjectElement::DoClassRegister() {
   49   BasicElement::DoClassRegister();
   50   RegisterProperty("classId",
   51                    NewSlot(&ObjectElement::GetObjectClassId),
   52                    NewSlot(&ObjectElement::SetObjectClassId));
   53   RegisterProperty("object", NewSlot(&ObjectElement::GetObject), NULL);
   54 }
   55 
   56 BasicElement *ObjectElement::CreateInstance(View *view, const char *name) {
   57   return new ObjectElement(view, name);
   58 }
   59 
   60 BasicElement *ObjectElement::GetObject() {
   61   return impl_->object_;
   62 }
   63 
   64 const std::string& ObjectElement::GetObjectClassId() const {
   65   return impl_->classid_;
   66 }
   67 
   68 void ObjectElement::SetObjectClassId(const std::string& classid) {
   69   ASSERT(!impl_->object_);
   70   if (impl_->object_) {
   71     LOG("Object already had a classId: %s", impl_->classid_.c_str());
   72   } else {
   73     impl_->object_ = GetView()->GetElementFactory()->CreateElement(
   74         classid.c_str(), GetView(), GetName().c_str());
   75     if (!impl_->object_) {
   76       LOG("Failed to get the object with classid: %s.", classid.c_str());
   77       return;
   78     }
   79     impl_->object_->SetParentElement(this);
   80     // Trigger property registration.
   81     impl_->object_->GetProperty("");
   82     impl_->classid_ = classid;
   83   }
   84 }
   85 
   86 void ObjectElement::Layout() {
   87   BasicElement::Layout();
   88   if (impl_->object_)
   89     impl_->object_->Layout();
   90 }
   91 
   92 void ObjectElement::DoDraw(CanvasInterface *canvas) {
   93   if (impl_->object_)
   94     impl_->object_->Draw(canvas);
   95 }
   96 
   97 EventResult ObjectElement::HandleMouseEvent(const MouseEvent &event) {
   98   BasicElement *fired, *in;
   99   ViewInterface::HitTest hittest;
  100   return impl_->object_ ?
  101       impl_->object_->OnMouseEvent(event, true, &fired, &in, &hittest) :
  102       EVENT_RESULT_UNHANDLED;
  103 }
  104 
  105 EventResult ObjectElement::HandleDragEvent(const DragEvent &event) {
  106   BasicElement *fired;
  107   return impl_->object_ ?
  108       impl_->object_->OnDragEvent(event, true, &fired) :
  109       EVENT_RESULT_UNHANDLED;
  110 }
  111 
  112 EventResult ObjectElement::HandleKeyEvent(const KeyboardEvent &event) {
  113   return impl_->object_ ? impl_->object_->OnKeyEvent(event) :
  114       EVENT_RESULT_UNHANDLED;
  115 }
  116 
  117 EventResult ObjectElement::HandleOtherEvent(const Event &event) {
  118   return impl_->object_ ? impl_->object_->OnOtherEvent(event) :
  119       EVENT_RESULT_UNHANDLED;
  120 }
  121 
  122 void ObjectElement::AggregateMoreClipRegion(const Rectangle &boundary,
  123                                             ClipRegion *region) {
  124   if (impl_->object_)
  125     impl_->object_->AggregateClipRegion(boundary, region);
  126 }
  127 
  128 } // namespace ggadget