1 /* gobby - A GTKmm driven libobby client
2  * Copyright (C) 2005 0x539 dev group
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this program; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18 
19 #include "togglewindow.hpp"
20 
ToggleWindow(Gtk::Window & parent,const Glib::RefPtr<Gtk::ToggleAction> & action,const Preferences & preferences,Config::ParentEntry & config_entry)21 Gobby::ToggleWindow::ToggleWindow(Gtk::Window& parent,
22                                   const Glib::RefPtr<Gtk::ToggleAction>& action,
23 			          const Preferences& preferences,
24 				  Config::ParentEntry& config_entry):
25 	ToolWindow(parent),
26 	m_action(action),
27 	m_preferences(preferences),
28 	m_config_entry(config_entry)
29 {
30 	action->signal_activate().connect(
31 		sigc::mem_fun(*this, &ToggleWindow::on_activate) );
32 
33 	if(preferences.appearance.remember)
34 	{
35 		// Read the ToggleWindow's last position from config
36 		const int x = config_entry.get_value<int>("x", 0);
37 		const int y = config_entry.get_value<int>("y", 0);
38 		const int w = config_entry.get_value<int>("width", 0);
39 		const int h = config_entry.get_value<int>("height", 0);
40 		bool first_run = (x == 0 && y == 0 && w == 0 && h == 0);
41 
42 		if(!first_run)
43 		{
44 			move(x, y);
45 			resize(w, h);
46 		}
47 
48 		if(config_entry.get_value<bool>("visible", false) )
49 		{
50 			// Show widget after parent has been shown
51 			parent.signal_show().connect(
52 				sigc::mem_fun(*this, &Gtk::Widget::show) );
53 		}
54 	}
55 
56 	set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
57 }
58 
~ToggleWindow()59 Gobby::ToggleWindow::~ToggleWindow()
60 {
61 	if(m_preferences.appearance.remember)
62 	{
63 		int x, y, w, h;
64 		get_position(x, y);
65 		get_size(w, h);
66 
67 		m_config_entry.set_value("x", x);
68 		m_config_entry.set_value("y", y);
69 		m_config_entry.set_value("width", w);
70 		m_config_entry.set_value("height", h);
71 		m_config_entry.set_value("visible", is_visible() );
72 	}
73 }
74 
on_activate()75 void Gobby::ToggleWindow::on_activate()
76 {
77 	if(m_action->get_active() )
78 		show();
79 	else
80 		hide();
81 }
82 
on_show()83 void Gobby::ToggleWindow::on_show()
84 {
85 	m_action->set_active(true);
86 	ToolWindow::on_show();
87 }
88 
on_hide()89 void Gobby::ToggleWindow::on_hide()
90 {
91 	m_action->set_active(false);
92 	ToolWindow::on_hide();
93 }
94