"Fossies" - the Fresh Open Source Software Archive

Member "google-gadgets-for-linux-0.11.2/ggadget/details_view_decorator.cc" (15 Mar 2009, 5105 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 "details_view_decorator.h"
   18 
   19 #include <string>
   20 #include <algorithm>
   21 #include "logger.h"
   22 #include "common.h"
   23 #include "gadget_consts.h"
   24 #include "gadget.h"
   25 #include "signals.h"
   26 #include "slot.h"
   27 #include "view.h"
   28 #include "view_host_interface.h"
   29 #include "button_element.h"
   30 #include "img_element.h"
   31 #include "label_element.h"
   32 #include "text_frame.h"
   33 #include "messages.h"
   34 #include "small_object.h"
   35 
   36 namespace ggadget {
   37 static const double kVDDetailsButtonHeight = 22;
   38 
   39 class DetailsViewDecorator::Impl : public SmallObject<> {
   40  public:
   41   Impl(DetailsViewDecorator *owner)
   42     : owner_(owner),
   43       feedback_handler_(NULL),
   44       flags_(0) {
   45   }
   46   ~Impl() {
   47     delete feedback_handler_;
   48   }
   49 
   50   void OnRemoveButtonClicked() {
   51     flags_ = ViewInterface::DETAILS_VIEW_FLAG_REMOVE_BUTTON;
   52     owner_->PostCloseSignal();
   53   }
   54 
   55   void OnRemoveButtonMouseOver(ButtonElement *remove_button) {
   56     remove_button->SetIconImage(Variant(kVDDetailsButtonNegfbOver));
   57   }
   58 
   59   void OnRemoveButtonMouseOut(ButtonElement *remove_button) {
   60     remove_button->SetIconImage(Variant(kVDDetailsButtonNegfbNormal));
   61   }
   62 
   63   void OnNegativeButtonClicked() {
   64     flags_ = ViewInterface::DETAILS_VIEW_FLAG_NEGATIVE_FEEDBACK;
   65     owner_->PostCloseSignal();
   66   }
   67 
   68  public:
   69   DetailsViewDecorator *owner_;
   70   Slot1<bool, int> *feedback_handler_;
   71   int flags_;
   72 };
   73 
   74 DetailsViewDecorator::DetailsViewDecorator(ViewHostInterface *host)
   75   : FramedViewDecoratorBase(host, "details_view"),
   76     impl_(new Impl(this)) {
   77   SetCaptionWordWrap(true);
   78 }
   79 
   80 DetailsViewDecorator::~DetailsViewDecorator() {
   81   delete impl_;
   82   impl_ = NULL;
   83 }
   84 
   85 bool DetailsViewDecorator::ShowDecoratedView(
   86     bool modal, int flags, Slot1<bool, int> *feedback_handler) {
   87   delete impl_->feedback_handler_;
   88   impl_->feedback_handler_ = feedback_handler;
   89   RemoveActionElements();
   90   if (flags & DETAILS_VIEW_FLAG_NO_FRAME) {
   91     SetFrameVisible(false);
   92   } else {
   93     SetFrameVisible(true);
   94     if (flags & DETAILS_VIEW_FLAG_TOOLBAR_OPEN) {
   95       SetCaptionClickable(true);
   96     }
   97     if (flags & DETAILS_VIEW_FLAG_NEGATIVE_FEEDBACK) {
   98       ButtonElement *negative_button = new ButtonElement(this, NULL);
   99       negative_button->SetImage(Variant(kVDDetailsButtonBkgndNormal));
  100       negative_button->SetOverImage(Variant(kVDDetailsButtonBkgndOver));
  101       negative_button->SetDownImage(Variant(kVDDetailsButtonBkgndClick));
  102       negative_button->SetStretchMiddle(true);
  103       negative_button->SetPixelHeight(kVDDetailsButtonHeight);
  104       negative_button->SetVisible(true);
  105       negative_button->GetTextFrame()->SetText(GMS_("DONT_SHOW_CONTENT_ITEM"));
  106       negative_button->ConnectOnClickEvent(
  107           NewSlot(impl_, &Impl::OnNegativeButtonClicked));
  108       AddActionElement(negative_button);
  109     }
  110     if (flags & DETAILS_VIEW_FLAG_REMOVE_BUTTON) {
  111       ButtonElement *remove_button = new ButtonElement(this, NULL);
  112       remove_button->SetImage(Variant(kVDDetailsButtonBkgndNormal));
  113       remove_button->SetOverImage(Variant(kVDDetailsButtonBkgndOver));
  114       remove_button->SetDownImage(Variant(kVDDetailsButtonBkgndClick));
  115       remove_button->SetStretchMiddle(true);
  116       remove_button->GetTextFrame()->SetText(GMS_("REMOVE_CONTENT_ITEM"));
  117       remove_button->SetPixelHeight(kVDDetailsButtonHeight);
  118       remove_button->SetIconImage(Variant(kVDDetailsButtonNegfbNormal));
  119       remove_button->SetIconPosition(ButtonElement::ICON_RIGHT);
  120       remove_button->ConnectOnClickEvent(
  121           NewSlot(impl_, &Impl::OnRemoveButtonClicked));
  122       remove_button->ConnectOnMouseOverEvent(
  123           NewSlot(impl_, &Impl::OnRemoveButtonMouseOver, remove_button));
  124       remove_button->ConnectOnMouseOutEvent(
  125           NewSlot(impl_, &Impl::OnRemoveButtonMouseOut, remove_button));
  126       AddActionElement(remove_button);
  127     }
  128   }
  129 
  130   return FramedViewDecoratorBase::ShowDecoratedView(modal, 0, NULL);
  131 }
  132 
  133 void DetailsViewDecorator::CloseDecoratedView() {
  134   if (impl_->feedback_handler_) {
  135     // To make sure that openUrl can work.
  136     bool old_interaction = false;
  137     Gadget *gadget = GetGadget();
  138     if (gadget)
  139       old_interaction = gadget->SetInUserInteraction(true);
  140 
  141     (*impl_->feedback_handler_)(impl_->flags_);
  142     delete impl_->feedback_handler_;
  143     impl_->feedback_handler_ = NULL;
  144 
  145     if (gadget)
  146       gadget->SetInUserInteraction(old_interaction);
  147   }
  148   ViewDecoratorBase::CloseDecoratedView();
  149 }
  150 
  151 void DetailsViewDecorator::OnCaptionClicked() {
  152   impl_->flags_ = ViewInterface::DETAILS_VIEW_FLAG_TOOLBAR_OPEN;
  153   PostCloseSignal();
  154 }
  155 
  156 } // namespace ggadget