| 1 |
/* gtkmm example Copyright (C) 2002 gtkmm development team |
| 2 |
* |
| 3 |
* This program is free software; you can redistribute it and/or modify |
| 4 |
* it under the terms of the GNU General Public License as published by |
| 5 |
* the Free Software Foundation; either version 2 of the License, or |
| 6 |
* (at your option) any later version. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU General Public License along |
| 14 |
* with this program; if not, see <https://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include "examplewindow.h" |
| 18 |
#include <gtkmm/eventcontrollerfocus.h> |
| 19 |
#include <iostream> |
| 20 |
|
| 21 |
ExampleWindow::ExampleWindow() |
| 22 |
: m_Combo(true /* has_entry */) |
| 23 |
{ |
| 24 |
set_title("ComboBoxText example"); |
| 25 |
|
| 26 |
//Fill the combo: |
| 27 |
m_Combo.append("something"); |
| 28 |
m_Combo.append("something else"); |
| 29 |
m_Combo.append("something or other"); |
| 30 |
m_Combo.set_active(0); |
| 31 |
|
| 32 |
set_child(m_Combo); |
| 33 |
|
| 34 |
//Connect signal handlers: |
| 35 |
auto entry = m_Combo.get_entry(); |
| 36 |
// Alternatively you can connect to entry->signal_changed(). |
| 37 |
m_Combo.signal_changed().connect(sigc::mem_fun(*this, |
| 38 |
&ExampleWindow::on_combo_changed) ); |
| 39 |
|
| 40 |
if (entry) |
| 41 |
{ |
| 42 |
#if HAS_SIGNAL_ACTIVATE |
| 43 |
entry->signal_activate().connect(sigc::mem_fun(*this, |
| 44 |
&ExampleWindow::on_entry_activate)); |
| 45 |
#endif |
| 46 |
// The Entry shall receive focus-leave events. |
| 47 |
auto controller = Gtk::EventControllerFocus::create(); |
| 48 |
m_ConnectionFocusLeave = controller->signal_leave().connect( |
| 49 |
sigc::mem_fun(*this, &ExampleWindow::on_entry_focus_leave)); |
| 50 |
entry->add_controller(controller); |
| 51 |
} |
| 52 |
else |
| 53 |
std::cout << "No Entry ???" << std::endl; |
| 54 |
|
| 55 |
m_Combo.property_has_frame() = false; |
| 56 |
} |
| 57 |
|
| 58 |
ExampleWindow::~ExampleWindow() |
| 59 |
{ |
| 60 |
// The focus-leave signal may be emitted while m_Combo is being destructed. |
| 61 |
// The signal handler can generate critical messages, if it's called when |
| 62 |
// m_Combo has been partly destructed. |
| 63 |
m_ConnectionFocusLeave.disconnect(); |
| 64 |
} |
| 65 |
|
| 66 |
void ExampleWindow::on_combo_changed() |
| 67 |
{ |
| 68 |
std::cout << "on_combo_changed(): Row=" << m_Combo.get_active_row_number() |
| 69 |
<< ", Text=" << m_Combo.get_active_text() << std::endl; |
| 70 |
} |
| 71 |
|
| 72 |
#if HAS_SIGNAL_ACTIVATE |
| 73 |
void ExampleWindow::on_entry_activate() |
| 74 |
{ |
| 75 |
std::cout << "on_entry_activate(): Row=" << m_Combo.get_active_row_number() |
| 76 |
<< ", Text=" << m_Combo.get_active_text() << std::endl; |
| 77 |
} |
| 78 |
#endif |
| 79 |
|
| 80 |
void ExampleWindow::on_entry_focus_leave() |
| 81 |
{ |
| 82 |
std::cout << "on_entry_focus_leave(): Row=" << m_Combo.get_active_row_number() |
| 83 |
<< ", Text=" << m_Combo.get_active_text() << std::endl; |
| 84 |
} |