File: listbox.h

package info (click to toggle)
mysql-workbench 6.3.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 113,932 kB
  • ctags: 87,814
  • sloc: ansic: 955,521; cpp: 427,465; python: 59,728; yacc: 59,129; xml: 54,204; sql: 7,091; objc: 965; makefile: 638; sh: 613; java: 237; perl: 30; ruby: 6; php: 1
file content (115 lines) | stat: -rw-r--r-- 3,633 bytes parent folder | download
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
/* 
 * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
 *
 * 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; version 2 of the
 * License.
 * 
 * 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., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#pragma once

#include <mforms/view.h>

#include <vector>

namespace mforms {
  class ListBox;

#ifndef DOXYGEN_SHOULD_SKIP_THIS
#ifndef SWIG
  struct ListBoxImplPtrs
  {
    bool (*create)(ListBox *self, bool multi_select);
    void (*clear)(ListBox *self);
    void (*set_heading)(ListBox *self, const std::string &text);
    void (*add_items)(ListBox *self, const std::list<std::string> &items);
    size_t(*add_item)(ListBox *self, const std::string &item);
    void(*remove_indexes)(ListBox *self, const std::vector<size_t> &indexes);
    void(*remove_index)(ListBox *self, size_t index);
    std::string (*get_text)(ListBox *self);
    void(*set_index)(ListBox *self, ssize_t index);
    ssize_t(*get_index)(ListBox *self);
    std::vector<size_t>(*get_selected_indices)(ListBox* self);
    size_t(*get_count)(ListBox* self);
    std::string (*get_string_value_from_index)(ListBox* self, size_t index);
  };
#endif
#endif

  /** A list control with a single column and multiple rows. */
  class MFORMS_EXPORT ListBox : public View
  {
  public:
    /** Constructor.
     
     @param multi - whether multiple selection is allowed. 
     */
    ListBox(bool multi);

    /** Clear rows from the list. */
    void clear();
    /** Sets a text for the control heading. */
    void set_heading(const std::string &text);
    
    /** Add an item in a new row to the list. */
    size_t add_item(const std::string &item);
    
    /** Quickly add multiple items to the list. */
    void add_items(const std::list<std::string> &items);

    /** Remove the item at the given index. */
    void remove_index(size_t index);

    /** Quickly remove multiple items from the list.
     *  Note: it is assumed that the indices are sorted in increasing order! */
    void remove_indexes(const std::vector<size_t> &indexes);

    /** Sets the selected row in the list. */
    void set_selected(ssize_t index);

    /** Gets the text of the selected row in the list. */
    virtual std::string get_string_value();
    
    /** Gets the index of the selected row in the list */
    ssize_t get_selected_index();
    
    /** Gets the list of selected indexes in the list */
    std::vector<size_t> get_selected_indices(); // For multi selection lists.

    /** Gets the number of rows in the list */
    size_t get_count();
    
    /** Gets the string value from the "index" position */
    std::string get_string_value_from_index(size_t index);
    
#ifndef SWIG
    /** Signal emitted when the selection changes. 
     
     In Python use add_changed_callback()
     */
    boost::signals2::signal<void ()>* signal_changed() { return &_signal_changed; }

#ifndef DOXYGEN_SHOULD_SKIP_THIS
  public:
    void selection_changed();
#endif
#endif
  protected:
    ListBoxImplPtrs *_listbox_impl;

    boost::signals2::signal<void ()> _signal_changed;
    
    bool _updating;
  };
};