File: MGBrowserList.h

package info (click to toggle)
mysql-gui-tools 5.0r12-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 105,540 kB
  • ctags: 50,897
  • sloc: sql: 348,439; pascal: 285,780; cpp: 94,578; ansic: 90,768; objc: 33,761; sh: 25,629; xml: 10,924; yacc: 10,755; java: 9,986; php: 2,806; python: 2,068; makefile: 1,945; perl: 3
file content (122 lines) | stat: -rw-r--r-- 3,969 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* Copyright (C) 2003, 2004 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */



#ifndef _MGBROWSERLIST_H_
#define _MGBROWSERLIST_H_


#include <gtkmm.h>
#include <map>


class MGBrowserList : public Gtk::VBox {
  public:
    typedef sigc::signal<bool,MGBrowserList*,const Gtk::TreeIter&> SelectionChangeDelegate;

    typedef sigc::signal<void,MGBrowserList*,const Gtk::TreeIter&> SelectionSignal;

  protected:
    class CustomTreeView : public Gtk::TreeView {        
      protected:
        virtual bool on_button_press_event(GdkEventButton *ev);
      public:
        CustomTreeView() : Gtk::TreeView(), popup(0) {};
        Gtk::Menu *popup;
    };

  private:
    void menu_activate_handler(int index);
    bool popup_handler(GdkEventButton *event);
    void entry_changed_handler();
    //void list_row_expanded_handler(const Gtk::TreeIter &iter,
    //                               const Gtk::TreePath &path);
        
    void open_popup(GdkEventButton *event);

    bool emit_when_idle();
  protected:
    SelectionSignal _selection_signal;
    SelectionChangeDelegate _selection_change_delegate;

    Gtk::Entry *_entry;
    Gtk::Menu *_menu;
    
    CustomTreeView *_tree;
    Glib::RefPtr<Gtk::TreeStore> _store;

    bool _refreshing;
    bool _selkluge;
    
    bool _queued_idle_selection;
    
    int _selected_menu_item;

    Gtk::Widget *create_search_entry(bool with_popup);

    virtual void refresh_list(const Glib::ustring &filter)=0;

    virtual bool list_selection_function(const Glib::RefPtr<Gtk::TreeModel> &model,
                                         const Gtk::TreeModel::Path &path,
                                         bool path_currently_selected);
    
    void list_selection_changed();
  public:
    MGBrowserList(bool with_popup, const Glib::ustring &caption);
    ~MGBrowserList();

//    void set_allow_multiple_selection(bool flag);

    virtual void clear();

    void refresh();

    void set_popup_menu(Gtk::Menu *menu);

    void set_store(const Glib::RefPtr<Gtk::TreeStore> &store);
    void set_menu_items(std::vector<Glib::ustring> &items);

    void unselect();
    Gtk::TreeIter get_selected();
    void set_selection(const Gtk::TreeIter &iter);
    
    Gtk::TreeIter get_iter(const Gtk::TreePath &path);

    bool find_node(const Gtk::TreeIter &parent, const Glib::ustring &text,
                   const Gtk::TreeModelColumn<Glib::ustring>& column,
                   Gtk::TreeIter &node_ret);

    bool find_node(const Glib::ustring &text,
                   const Gtk::TreeModelColumn<Glib::ustring>& column,
                   Gtk::TreeIter &node_ret);

    void mark_node(const Gtk::TreeIter &node,
                   const Gtk::TreeModelColumn<Gdk::Color>& column,
                   bool flag, bool follow_parents);

    void expand_node(const Gtk::TreeIter &node);

    Gtk::TreeView *get_tree() { return _tree; };
    
    void clear_filter() { _entry->set_text(Glib::ustring("")); refresh_list(Glib::ustring("")); }

  public:
    SelectionSignal signal_selected();
    SelectionChangeDelegate signal_selection_will_change() { return _selection_change_delegate; };
};

#endif /* _MGBROWSERLIST_H_ */