Back to index

unity  6.0.0
SearchBar.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2010 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
00018  */
00019 
00020 #ifndef SEARCH_BAR_H
00021 #define SEARCH_BAR_H
00022 
00023 #include <gtk/gtk.h>
00024 #include <NuxCore/Property.h>
00025 #include <Nux/LayeredLayout.h>
00026 #include <Nux/VLayout.h>
00027 #include <Nux/TextEntry.h>
00028 #include <UnityCore/GLibSignal.h>
00029 #include <UnityCore/GLibSource.h>
00030 
00031 #include "SearchBarSpinner.h"
00032 #include "unity-shared/IconTexture.h"
00033 #include "unity-shared/IMTextEntry.h"
00034 #include "unity-shared/Introspectable.h"
00035 #include "unity-shared/StaticCairoText.h"
00036 
00037 namespace nux
00038 {
00039 class AbstractPaintLayer;
00040 class LinearLayout;
00041 }
00042 
00043 namespace unity
00044 {
00045 
00046 class SearchBar : public unity::debug::Introspectable, public nux::View
00047 {
00048   NUX_DECLARE_OBJECT_TYPE(SearchBar, nux::View);
00049 public:
00050   typedef nux::ObjectPtr<SearchBar> Ptr;
00051   SearchBar(NUX_FILE_LINE_PROTO);
00052   SearchBar(bool show_filter_hint, NUX_FILE_LINE_PROTO);
00053 
00054   void ForceSearchChanged();
00055   void SearchFinished();
00056   nux::TextEntry* text_entry() const;
00057   nux::View* show_filters() const;
00058 
00059   nux::RWProperty<std::string> search_string;
00060   nux::Property<std::string> search_hint;
00061   nux::Property<bool> showing_filters;
00062   nux::Property<bool> can_refine_search;
00063   nux::ROProperty<bool> im_active;
00064   nux::ROProperty<bool> im_preedit;
00065 
00066   sigc::signal<void> activated;
00067   sigc::signal<void, std::string const&> search_changed;
00068   sigc::signal<void, std::string const&> live_search_reached;
00069 
00070 private:
00071 
00072   void Init();
00073 
00074   void OnFontChanged(GtkSettings* settings, GParamSpec* pspec=NULL);
00075   void OnSearchHintChanged();
00076 
00077   void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
00078   void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
00079 
00080   void OnMouseButtonDown(int x, int y, unsigned long button_flags, unsigned long key_flags);
00081   void OnEndKeyFocus();
00082 
00083   void UpdateBackground(bool force);
00084   void OnSearchChanged(nux::TextEntry* text_entry);
00085   void OnClearClicked(int x, int y, unsigned long button_flags, unsigned long key_flags);
00086   void OnEntryActivated();
00087   void OnShowingFiltersChanged(bool is_showing);
00088   bool OnLiveSearchTimeout();
00089   bool OnSpinnerStartCb();
00090 
00091   std::string get_search_string() const;
00092   bool set_search_string(std::string const& string);
00093   bool get_im_active() const;
00094   bool get_im_preedit() const;
00095   bool show_filter_hint_;
00096 
00097   std::string GetName() const;
00098   void AddProperties(GVariantBuilder* builder);
00099   bool AcceptKeyNavFocus();
00100 
00101 private:
00102   bool ShouldBeHighlighted();
00103   
00104   std::unique_ptr<nux::AbstractPaintLayer> bg_layer_;
00105   std::unique_ptr<nux::AbstractPaintLayer> highlight_layer_;
00106   nux::HLayout* layout_;
00107   nux::HLayout* entry_layout_;
00108   nux::LayeredLayout* layered_layout_;
00109   nux::StaticCairoText* hint_;
00110   nux::LinearLayout* expander_layout_;
00111   IMTextEntry* pango_entry_;
00112   nux::View* expander_view_;
00113   nux::HLayout* filter_layout_;
00114   nux::StaticCairoText* show_filters_;
00115   nux::VLayout* arrow_layout_;
00116   nux::SpaceLayout* arrow_top_space_;
00117   nux::SpaceLayout* arrow_bottom_space_;
00118   IconTexture* expand_icon_;
00119 
00120   int last_width_;
00121   int last_height_;
00122 
00123   glib::SignalManager sig_manager_;
00124   glib::Source::UniquePtr live_search_timeout_;
00125   glib::Source::UniquePtr start_spinner_timeout_;
00126 
00127   SearchBarSpinner* spinner_;
00128 };
00129 
00130 }
00131 
00132 #endif