[Aptitude-svn-commit] r3727 - in branches/aptitude-0.3/aptitude: .
src/vscreen
Daniel Burrows
dburrows at costa.debian.org
Mon Aug 8 15:53:48 UTC 2005
Author: dburrows
Date: Mon Aug 8 15:53:44 2005
New Revision: 3727
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/vscreen/ref_ptr.h
branches/aptitude-0.3/aptitude/src/vscreen/testvscreen.cc
branches/aptitude-0.3/aptitude/src/vscreen/vs_bin.cc
branches/aptitude-0.3/aptitude/src/vscreen/vs_bin.h
branches/aptitude-0.3/aptitude/src/vscreen/vs_container.cc
branches/aptitude-0.3/aptitude/src/vscreen/vs_container.h
branches/aptitude-0.3/aptitude/src/vscreen/vs_frame.cc
branches/aptitude-0.3/aptitude/src/vscreen/vs_menubar.cc
branches/aptitude-0.3/aptitude/src/vscreen/vs_menubar.h
branches/aptitude-0.3/aptitude/src/vscreen/vs_multiplex.cc
branches/aptitude-0.3/aptitude/src/vscreen/vs_multiplex.h
branches/aptitude-0.3/aptitude/src/vscreen/vs_radiogroup.cc
branches/aptitude-0.3/aptitude/src/vscreen/vs_radiogroup.h
branches/aptitude-0.3/aptitude/src/vscreen/vs_stacked.cc
branches/aptitude-0.3/aptitude/src/vscreen/vs_stacked.h
branches/aptitude-0.3/aptitude/src/vscreen/vs_table.cc
branches/aptitude-0.3/aptitude/src/vscreen/vs_table.h
branches/aptitude-0.3/aptitude/src/vscreen/vs_util.cc
branches/aptitude-0.3/aptitude/src/vscreen/vs_util.h
Log:
Fix memory handling errors in testvscreen by binding weak references
instead of refcounted pointers.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Mon Aug 8 15:53:44 2005
@@ -1,3 +1,15 @@
+2005-08-08 Daniel Burrows <dburrows at debian.org>
+
+ * src/vscreen/ref_ptr.h, src/vscreen/testvscreen.cc, src/vscreen/vs_bin.cc, src/vscreen/vs_bin.h, src/vscreen/vs_container.cc, src/vscreen/vs_container.h, src/vscreen/vs_frame.cc, src/vscreen/vs_menubar.cc, src/vscreen/vs_menubar.h, src/vscreen/vs_multiplex.cc, src/vscreen/vs_multiplex.h, src/vscreen/vs_radiogroup.cc, src/vscreen/vs_radiogroup.h, src/vscreen/vs_stacked.cc, src/vscreen/vs_stacked.h, src/vscreen/vs_table.cc, src/vscreen/vs_table.h, src/vscreen/vs_util.cc, src/vscreen/vs_util.h:
+
+ Binding references as slot arguments causes weird and painful
+ problems. Instead, use sigc++ weak references (sigc::ref);
+ since I want to be able to easily connect signals to public
+ methods, adopt the convention of providing a (non-virtual) _bare
+ variant of methods that take a refcounted pointer as an
+ argument; the variant accepts a reference to the underlying type
+ and wraps it in a ref_ptr before handing it to the real method.
+
2005-08-06 Rubén Porras <nahoo at inicia.es>
* updated po/es.po
Modified: branches/aptitude-0.3/aptitude/src/vscreen/ref_ptr.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/ref_ptr.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/ref_ptr.h Mon Aug 8 15:53:44 2005
@@ -7,6 +7,10 @@
#ifndef REF_PTR_H
#define REF_PTR_H
+#include <sigc++/reference_wrapper.h>
+
+#include <assert.h>
+
template<class T>
class ref_ptr
{
@@ -59,6 +63,13 @@
return *this;
}
+ const sigc::reference_wrapper<T> weak_ref() const
+ {
+ assert(ref != 0);
+
+ return sigc::ref(*ref);
+ }
+
// If S is assignment-compatible with T and both have
// reference-counting methods, perform this assignment.
//
Modified: branches/aptitude-0.3/aptitude/src/vscreen/testvscreen.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/testvscreen.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/testvscreen.cc Mon Aug 8 15:53:44 2005
@@ -117,9 +117,9 @@
const wchar_t *label() {return txt.c_str();}
};
-void do_toggle_hierarchical(const vs_tree_ref &tree)
+void do_toggle_hierarchical(vs_tree &tree)
{
- tree->set_hierarchical(!tree->get_hierarchical());
+ tree.set_hierarchical(!tree.get_hierarchical());
}
vs_widget_ref make_test_treewidget()
@@ -176,7 +176,8 @@
tree->set_root(root, true);
tree->connect_key("ToggleHier", &global_bindings,
- sigc::bind(sigc::ptr_fun(do_toggle_hierarchical), tree));
+ sigc::bind(sigc::ptr_fun(do_toggle_hierarchical),
+ tree.weak_ref()));
return tree;
}
@@ -227,12 +228,12 @@
VS_MENU_END
};
-void radio_button_selected(int id, const vs_label_ref &l)
+void radio_button_selected(int id, vs_label &l)
{
char buf[128];
snprintf(buf, 128, "You have selected button %i", id);
- l->set_text(buf);
+ l.set_text(buf);
}
vs_widget_ref button_mania()
@@ -249,7 +250,8 @@
if(i==3)
{
g=new vs_radiogroup;
- g->item_selected.connect(sigc::bind(sigc::ptr_fun(&radio_button_selected), label));
+ g->item_selected.connect(sigc::bind(sigc::ptr_fun(&radio_button_selected),
+ label.weak_ref()));
}
for(int j=0; j<4; j++)
{
@@ -282,9 +284,9 @@
return rval;
}
-static void do_load_file(wstring s, const vs_editline_ref &p)
+static void do_load_file(wstring s, vs_editline &p)
{
- p->set_text(L"");
+ p.set_text(L"");
}
vs_widget_ref pager_test()
@@ -299,7 +301,7 @@
tbl->add_widget_opts(pager, 1, 0, 1, 1, vs_table::SHRINK, vs_table::EXPAND | vs_table::FILL);
tbl->add_widget_opts(scrl, 1, 1, 1, 1, vs_table::ALIGN_LEFT, vs_table::EXPAND | vs_table::FILL);
- ln->entered.connect(sigc::bind(sigc::ptr_fun(&do_load_file), ln));
+ ln->entered.connect(sigc::bind(sigc::ptr_fun(&do_load_file), ln.weak_ref()));
ln->entered.connect(sigc::mem_fun(*pager.unsafe_get_ref(), (void (vs_file_pager::*)(const std::wstring &)) &vs_file_pager::load_file));
pager->line_changed.connect(sigc::mem_fun(*scrl.unsafe_get_ref(), &vs_scrollbar::set_slider));
pager->do_line_signal();
@@ -308,23 +310,23 @@
return tbl;
}
-void update_menu_status(const vs_menu_item *item, const vs_label_ref &label)
+void update_menu_status(const vs_menu_item *item, vs_label &label)
{
if(item)
{
- label->show();
- label->set_text(item->get_description(),
- get_style("Status"));
+ label.show();
+ label.set_text(item->get_description(),
+ get_style("Status"));
}
else
- label->hide();
+ label.hide();
}
-void do_editline_history(std::wstring s, const vs_editline_ref &l)
+void do_editline_history(std::wstring s, vs_editline &l)
{
- l->add_to_history(s);
- l->reset_history();
- l->set_text("");
+ l.add_to_history(s);
+ l.reset_history();
+ l.set_text("");
}
fragment *dickens_fragment()
@@ -414,17 +416,17 @@
vs_menu_ref menu(vs_menu::create(0, 0, 0, test_file_menu));
menubar->append_item(L"File", menu);
menu->item_highlighted.connect(sigc::bind(sigc::ptr_fun(&update_menu_status),
- menu_display));
+ menu_display.weak_ref()));
menu=vs_menu::create(0, 0, 0, test_test_menu);
menubar->append_item(L"Test", menu);
menu->item_highlighted.connect(sigc::bind(sigc::ptr_fun(&update_menu_status),
- menu_display));
+ menu_display.weak_ref()));
menu=vs_menu::create(0, 0, 0, test_help_menu);
menubar->append_item(L"Help", menu);
menu->item_highlighted.connect(sigc::bind(sigc::ptr_fun(&update_menu_status),
- menu_display));
+ menu_display.weak_ref()));
vs_minibuf_win_ref toplevel=vs_minibuf_win::create();
@@ -464,7 +466,7 @@
vs_editline::history_list h;
vs_editline_ref l=vs_editline::create(20, "Input: ", "Pane 3", &h);
l->entered.connect(sigc::bind(sigc::ptr_fun(&do_editline_history),
- l));
+ l.weak_ref()));
w=vs_frame::create(vs_center::create(l));
table->add_widget(w, 1, 1);
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_bin.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_bin.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_bin.cc Mon Aug 8 15:53:44 2005
@@ -20,8 +20,10 @@
vs_widget_ref vs_bin::get_focus()
{
- if(subwidget.valid() && subwidget->get_visible())
- return subwidget;
+ vs_widget_ref w = subwidget;
+
+ if(w.valid() && w->get_visible())
+ return w;
else
return NULL;
}
@@ -41,8 +43,8 @@
if(w.valid())
{
- show_conn = w->shown_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_bin::show_widget), w));
- hide_conn = w->hidden_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_bin::hide_widget), w));
+ show_conn = w->shown_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_bin::show_widget_bare), w.weak_ref()));
+ hide_conn = w->hidden_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_bin::hide_widget_bare), w.weak_ref()));
w->set_owner(this);
if(get_isfocussed())
w->focussed();
@@ -93,12 +95,22 @@
show();
}
+void vs_bin::show_widget_bare(vscreen_widget &w)
+{
+ show_widget(vs_widget_ref(&w));
+}
+
void vs_bin::hide_widget(const vs_widget_ref &w)
{
assert(w==subwidget);
hide();
}
+void vs_bin::hide_widget_bare(vscreen_widget &w)
+{
+ hide_widget(vs_widget_ref(&w));
+}
+
void vs_bin::paint(const style &st)
{
if(subwidget.valid() && subwidget->get_visible())
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_bin.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_bin.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_bin.h Mon Aug 8 15:53:44 2005
@@ -22,6 +22,9 @@
void show_widget(const vs_widget_ref &w);
void hide_widget(const vs_widget_ref &w);
+ void show_widget_bare(vscreen_widget &w);
+ void hide_widget_bare(vscreen_widget &w);
+
protected:
vs_bin();
@@ -29,6 +32,11 @@
virtual ~vs_bin();
void set_subwidget(const ref_ptr<vscreen_widget> &w);
+ void set_subwidget(vscreen_widget &w)
+ {
+ set_subwidget(ref_ptr<vscreen_widget>(&w));
+ }
+
vs_widget_ref get_subwidget() {return subwidget;}
virtual void show_all();
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_container.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_container.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_container.cc Mon Aug 8 15:53:44 2005
@@ -1,4 +1,22 @@
// vs_container.cc
+//
+// Copyright (C) 2000 Daniel Burrows
+//
+// 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; see the file COPYING. If not, write to
+// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
#include "vs_container.h"
vs_container::~vs_container()
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_container.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_container.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_container.h Mon Aug 8 15:53:44 2005
@@ -1,8 +1,25 @@
// vs_container.h -*-c++-*-
//
-// A generic representation of a vscreen_widget that can hold other widgets.
-// I thought about actually including the storage facilities here, but decided
-// against it; this just provides an interface to write to.
+//
+// Copyright (C) 2000, 2005 Daniel Burrows
+//
+// 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; see the file COPYING. If not, write to
+// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+//
+// A generic interface for a vscreen_widget that can hold other
+// widgets.
#ifndef VS_CONTAINER_H
#define VS_CONTAINER_H
@@ -16,12 +33,28 @@
~vs_container();
virtual void add_widget(const vs_widget_ref &)=0;
- // To make it easier to add anonymous widgets:
- // (NOTE: C++ is evil!! I should be able to call this "add_widget"..grrr..)
void add_visible_widget(const vs_widget_ref &, bool visible);
virtual void rem_widget(const vs_widget_ref &)=0;
- // Abstract so I don't forget to implement it in a subclass..
+ // Variants of the above that take a bare reference; used for weak
+ // slot connections.
+ void add_widget_bare(vscreen_widget &w)
+ {
+ add_widget(vs_widget_ref(&w));
+ }
+
+ void add_visible_widget_bare(vscreen_widget &w, bool visible)
+ {
+ add_visible_widget(vs_widget_ref(&w), visible);
+ }
+
+ void rem_widget_bare(vscreen_widget &w)
+ {
+ rem_widget(vs_widget_ref(&w));
+ }
+
+
+ /** Display this widget and all its subwidgets. */
virtual void show_all()=0;
};
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_frame.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_frame.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_frame.cc Mon Aug 8 15:53:44 2005
@@ -28,10 +28,15 @@
{
if(width<2)
return 0;
- else if(get_subwidget().valid() && get_subwidget()->get_visible())
- return get_subwidget()->height_request(width-2)+2;
else
- return 2;
+ {
+ vs_widget_ref subwidget = get_subwidget();
+
+ if(subwidget.valid() && subwidget->get_visible())
+ return subwidget->height_request(width-2)+2;
+ else
+ return 2;
+ }
}
void vs_frame::layout_me()
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_menubar.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_menubar.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_menubar.cc Mon Aug 8 15:53:44 2005
@@ -108,8 +108,8 @@
{
items.push_back(item(L' '+title+L' ', menu));
- menu->shown_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_menubar::show_menu), menu));
- menu->hidden_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_menubar::hide_menu), menu));
+ menu->shown_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_menubar::show_menu_bare), menu.weak_ref()));
+ menu->hidden_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_menubar::hide_menu_bare), menu.weak_ref()));
menu->menus_goaway.connect(sigc::mem_fun(*this, &vs_menubar::disappear));
menu->set_owner(this);
@@ -305,6 +305,16 @@
}
}
+void vs_menubar::hide_menu_bare(vs_menu &w)
+{
+ hide_menu(vs_menu_ref(&w));
+}
+
+void vs_menubar::show_menu_bare(vs_menu &w)
+{
+ show_menu(vs_menu_ref(&w));
+}
+
void vs_menubar::appear()
{
if(!active)
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_menubar.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_menubar.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_menubar.h Mon Aug 8 15:53:44 2005
@@ -54,7 +54,10 @@
// Show/hide menus
void show_menu(const vs_menu_ref &w);
+ void show_menu_bare(vs_menu &w);
+
void hide_menu(const vs_menu_ref &w);
+ void hide_menu_bare(vs_menu &w);
void appear();
void disappear();
@@ -84,6 +87,10 @@
void set_subwidget(const vs_widget_ref &w);
void append_item(const std::wstring &title, const vs_menu_ref &menu);
+ void append_item(const std::wstring &title, vs_menu &menu)
+ {
+ append_item(title, vs_menu_ref(&menu));
+ }
void show_all();
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_multiplex.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_multiplex.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_multiplex.cc Mon Aug 8 15:53:44 2005
@@ -318,6 +318,16 @@
vscreen_update();
}
+void vs_multiplex::show_widget_bare(vscreen_widget &w)
+{
+ show_widget(vs_widget_ref(&w));
+}
+
+void vs_multiplex::hide_widget_bare(vscreen_widget &w)
+{
+ hide_widget(vs_widget_ref(&w));
+}
+
vs_widget_ref vs_multiplex::get_focus()
{
return visible_child==children.end()?NULL:visible_child->w;
@@ -358,8 +368,8 @@
void vs_multiplex::add_widget(const vs_widget_ref &w,
const wstring &title)
{
- w->shown_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_multiplex::show_widget), w));
- w->hidden_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_multiplex::hide_widget), w));
+ w->shown_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_multiplex::show_widget_bare), w.weak_ref()));
+ w->hidden_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_multiplex::hide_widget_bare), w.weak_ref()));
children.push_back(child_info(w, title));
w->set_owner(this);
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_multiplex.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_multiplex.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_multiplex.h Mon Aug 8 15:53:44 2005
@@ -72,6 +72,9 @@
void hide_widget(const vs_widget_ref &widget);
// Used to hide a widget
+ void show_widget_bare(vscreen_widget &widget);
+ void hide_widget_bare(vscreen_widget &widget);
+
void got_focus();
void lost_focus();
protected:
@@ -111,11 +114,34 @@
*/
void add_widget(const vs_widget_ref &widget);
void add_widget(const vs_widget_ref &widget, const std::wstring &title);
+ void add_widget_bare(vscreen_widget &widget, const std::wstring &title)
+ {
+ add_widget(vs_widget_ref(&widget), title);
+ }
+
void add_widget_after(const vs_widget_ref &widget,
const vs_widget_ref &after);
+
+ void add_widget_after_bare(vscreen_widget &widget,
+ vscreen_widget &after)
+ {
+ add_widget_after(vs_widget_ref(&widget), vs_widget_ref(&after));
+ }
+
+
void add_widget_after(const vs_widget_ref &widget,
const vs_widget_ref &after,
const std::wstring &title);
+
+
+ void add_widget_after_bare(vscreen_widget &widget,
+ vscreen_widget &after,
+ const std::wstring &title)
+ {
+ add_widget_after(vs_widget_ref(&widget), vs_widget_ref(&after), title);
+ }
+
+
void rem_widget(const vs_widget_ref &widget);
// These cycle forward and backwards through the list of visible items.
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_radiogroup.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_radiogroup.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_radiogroup.cc Mon Aug 8 15:53:44 2005
@@ -48,7 +48,9 @@
for(itemlist::iterator i=items.begin(); i!=items.end(); i++)
assert(i->b!=b);
- items.push_back(item(b, id, b->destroyed.connect(sigc::bind(sigc::mem_fun(*this, &vs_radiogroup::rem_button), b)), b->pressed.connect(sigc::bind(sigc::mem_fun(*this, &vs_radiogroup::button_pressed), items.size()))));
+ items.push_back(item(b, id,
+ b->destroyed.connect(sigc::bind(sigc::mem_fun(*this, &vs_radiogroup::rem_button_bare), b.weak_ref())),
+ b->pressed.connect(sigc::bind(sigc::mem_fun(*this, &vs_radiogroup::button_pressed), items.size()))));
if(selected==items.max_size() || b->get_checked())
button_pressed(items.size()-1);
@@ -80,6 +82,11 @@
}
}
+void vs_radiogroup::rem_button_bare(vs_togglebutton &b)
+{
+ rem_button(vs_togglebutton_ref(&b));
+}
+
void vs_radiogroup::select(int id)
{
for(itemlist::size_type i=0; i<items.size(); i++)
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_radiogroup.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_radiogroup.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_radiogroup.h Mon Aug 8 15:53:44 2005
@@ -64,6 +64,8 @@
void add_button(const ref_ptr<vs_togglebutton> &b, int id);
void rem_button(const ref_ptr<vs_togglebutton> &b);
+ void rem_button_bare(vs_togglebutton &b);
+
/** \return \b true if a button is selected. */
bool selection_valid();
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_stacked.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_stacked.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_stacked.cc Mon Aug 8 15:53:44 2005
@@ -14,7 +14,7 @@
void vs_stacked::add_widget(const vs_widget_ref &w)
{
- sigc::connection shown_conn=w->shown_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_stacked::raise_widget), w));
+ sigc::connection shown_conn=w->shown_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_stacked::raise_widget_bare), w.weak_ref()));
sigc::connection hidden_conn=w->hidden_sig.connect(sigc::mem_fun(*this, &vs_stacked::hide_widget));
defocus();
@@ -144,7 +144,7 @@
i->w->show_all();
- i->shown_conn=i->w->shown_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_stacked::raise_widget), i->w));
+ i->shown_conn=i->w->shown_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_stacked::raise_widget_bare), i->w.weak_ref()));
}
refocus();
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_stacked.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_stacked.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_stacked.h Mon Aug 8 15:53:44 2005
@@ -58,6 +58,15 @@
void raise_widget(const vs_widget_ref &w);
void lower_widget(const vs_widget_ref &w);
+ void raise_widget_bare(vscreen_widget &w)
+ {
+ raise_widget(vs_widget_ref(&w));
+ }
+ void lower_widget_bare(vscreen_widget &w)
+ {
+ lower_widget(vs_widget_ref(&w));
+ }
+
void dispatch_mouse(short id, int x, int y, int z, mmask_t bstate);
vs_widget_ref vs_stacked::get_focus();
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_table.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_table.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_table.cc Mon Aug 8 15:53:44 2005
@@ -104,6 +104,12 @@
w->unfocussed();
}
+void vs_table::add_widget_bare(vscreen_widget &w, int row_start, int col_start, int row_span, int col_span, bool expand, bool shrink)
+{
+ add_widget(vs_widget_ref(&w), row_start, col_start,
+ row_span, col_span, expand, shrink);
+}
+
void vs_table::add_widget(const vs_widget_ref &w, int row_start, int col_start, int row_span, int col_span, bool expand, bool shrink)
{
int opts=ALIGN_CENTER;
@@ -115,6 +121,12 @@
add_widget_opts(w, row_start, col_start, row_span, col_span, opts, opts);
}
+void vs_table::add_widget_opts_bare(vscreen_widget &w, int row_start, int col_start, int row_span, int col_span, int xopts, int yopts)
+{
+ add_widget_opts(vs_widget_ref(&w), row_start, col_start,
+ row_span, col_span, xopts, yopts);
+}
+
void vs_table::add_widget_opts(const vs_widget_ref &w, int row_start, int col_start, int row_span, int col_span, int xopts, int yopts)
{
// sanity check
@@ -123,8 +135,8 @@
// FIXME: throw something/print a nasty error message?
abort();
- sigc::connection shown_conn=w->shown_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_table::show_widget), w));
- sigc::connection hidden_conn=w->hidden_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_table::hide_widget), w));
+ sigc::connection shown_conn=w->shown_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_table::show_widget_bare), w.weak_ref()));
+ sigc::connection hidden_conn=w->hidden_sig.connect(sigc::bind(sigc::mem_fun(*this, &vs_table::hide_widget_bare), w.weak_ref()));
children.push_back(child_info(w, row_start, col_start, row_span, col_span, xopts, yopts, shown_conn, hidden_conn));
@@ -145,6 +157,11 @@
vscreen_queuelayout();
}
+void vs_table::hide_widget_bare(vscreen_widget &w)
+{
+ hide_widget(vs_widget_ref(&w));
+}
+
void vs_table::hide_widget(const vs_widget_ref &w)
{
if(focus!=children.end() && w==focus->w)
@@ -172,6 +189,11 @@
vscreen_queuelayout();
}
+void vs_table::show_widget_bare(vscreen_widget &w)
+{
+ show_widget(vs_widget_ref(&w));
+}
+
void vs_table::show_widget(const vs_widget_ref &w)
{
if(w->focus_me() && focus==children.end())
@@ -478,7 +500,9 @@
{
if(focus!=children.end())
{
- if(focus->w->dispatch_key(k))
+ vs_widget_ref w = focus->w;
+
+ if(w->dispatch_key(k))
return true;
else if(bindings->key_matches(k, "Cycle"))
{
@@ -1318,13 +1342,15 @@
{
for(childlist::iterator i=children.begin(); i!=children.end(); ++i)
{
- if(i->w->get_visible() && i->w->enclose(y, x))
+ vs_widget_ref w = i->w;
+
+ if(w->get_visible() && w->enclose(y, x))
{
- if(i->w->focus_me())
- focus_widget(i->w);
+ if(w->focus_me())
+ focus_widget(w);
- i->w->dispatch_mouse(id, x-i->w->get_startx(), y-i->w->get_starty(),
- z, bstate);
+ w->dispatch_mouse(id, x-w->get_startx(), y-w->get_starty(),
+ z, bstate);
return;
}
}
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_table.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_table.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_table.h Mon Aug 8 15:53:44 2005
@@ -105,7 +105,9 @@
// Focus-handling stuff
vs_widget_ref get_focus();
void hide_widget(const vs_widget_ref &w);
+ void hide_widget_bare(vscreen_widget &w);
void show_widget(const vs_widget_ref &w);
+ void show_widget_bare(vscreen_widget &w);
/** Populates the given vector with lists of the widgets in each
* row.
@@ -154,15 +156,17 @@
~vs_table();
void add_widget_opts(const vs_widget_ref &w, int row_start, int col_start, int row_span, int col_span, int xopts, int yopts);
- // eww. C++ overloading is annoying..
+ void add_widget_opts_bare(vscreen_widget &w, int row_start, int col_start, int row_span, int col_span, int xopts, int yopts);
+
void add_widget(const vs_widget_ref &w, int row_start, int col_start, int row_span=1, int col_span=1, bool expand=true, bool shrink=true);
- // This form uses the same options for X and Y
+ void add_widget_bare(vscreen_widget &w, int row_start, int col_start, int row_span=1, int col_span=1, bool expand=true, bool shrink=true);
void add_widget(const vs_widget_ref &w);
void rem_widget(const vs_widget_ref &w);
void focus_widget(const vs_widget_ref &w);
+ void focus_widget_bare(const vscreen_widget &w);
/** Set the separation between adjacent rows to the given number of
* characters.
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_util.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_util.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_util.cc Mon Aug 8 15:53:44 2005
@@ -242,10 +242,10 @@
return vs_dialog_yesno(w, yesslot, yeslabel, noslot, nolabel, st, deflt);
}
-vs_widget_ref vs_dialog_fileview(string fn,
+vs_widget_ref vs_dialog_fileview(const string &fn,
slot0arg okslot,
- slotarg<sigc::slot1<void, vs_pager_ref> > search_slot,
- slotarg<sigc::slot1<void, vs_pager_ref> > repeat_search_slot,
+ slotarg<sigc::slot1<void, vs_pager &> > search_slot,
+ slotarg<sigc::slot1<void, vs_pager &> > repeat_search_slot,
const style &st,
const char *encoding)
{
@@ -267,18 +267,18 @@
scrollbar->scrollbar_interaction.connect(sigc::mem_fun(*p.unsafe_get_ref(), &vs_pager::scroll_page));
if(search_slot)
- p->connect_key("Search", &global_bindings, sigc::bind(*search_slot, p));
+ p->connect_key("Search", &global_bindings, sigc::bind(*search_slot, p.weak_ref()));
if(repeat_search_slot)
- p->connect_key("ReSearch", &global_bindings, sigc::bind(*repeat_search_slot, p));
+ p->connect_key("ReSearch", &global_bindings, sigc::bind(*repeat_search_slot, p.weak_ref()));
return vs_dialog_ok(t, okslot, transcode(_("Ok")), st);
}
vs_widget_ref vs_dialog_fileview(string fn,
slot0arg okslot,
- slotarg<sigc::slot1<void, vs_pager_ref> > search_slot,
- slotarg<sigc::slot1<void, vs_pager_ref> > repeat_search_slot,
+ slotarg<sigc::slot1<void, vs_pager &> > search_slot,
+ slotarg<sigc::slot1<void, vs_pager &> > repeat_search_slot,
const char *encoding)
{
return vs_dialog_fileview(fn, okslot, search_slot, repeat_search_slot,
@@ -292,11 +292,11 @@
realslot();
}
-static void also_do_dialog_string(const vs_editline_ref &e,
+static void also_do_dialog_string(vs_editline &e,
sigc::slot1<void, wstring> thestrslot)
{
- e->add_to_history(e->get_text());
- thestrslot(e->get_text());
+ e.add_to_history(e.get_text());
+ thestrslot(e.get_text());
}
vs_widget_ref vs_dialog_string(const vs_widget_ref &msg,
@@ -336,7 +336,7 @@
bok->pressed.connect(sigc::mem_fun(*c.unsafe_get_ref(), &vscreen_widget::destroy));
if(slot)
bok->pressed.connect(sigc::bind(sigc::ptr_fun(also_do_dialog_string),
- e, *slot));
+ e.weak_ref(), *slot));
bcancel->pressed.connect(sigc::mem_fun(*c.unsafe_get_ref(), &vscreen_widget::destroy));
if(cancel_slot)
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_util.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_util.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_util.h Mon Aug 8 15:53:44 2005
@@ -114,13 +114,13 @@
vs_widget_ref vs_dialog_fileview(const std::string &fn,
slot0arg okslot=NULL,
- slotarg<sigc::slot1<void, vs_pager *> > search_slot=NULL,
- slotarg<sigc::slot1<void, vs_pager *> > repeat_search_slot=NULL,
+ slotarg<sigc::slot1<void, vs_pager &> > search_slot=NULL,
+ slotarg<sigc::slot1<void, vs_pager &> > repeat_search_slot=NULL,
const char *encoding=NULL);
vs_widget_ref vs_dialog_fileview(const std::string &fn,
slot0arg okslot,
- slotarg<sigc::slot1<void, vs_pager *> > search_slot,
- slotarg<sigc::slot1<void, vs_pager *> > repeat_search_slot,
+ slotarg<sigc::slot1<void, vs_pager &> > search_slot,
+ slotarg<sigc::slot1<void, vs_pager &> > repeat_search_slot,
const style &st,
const char *encoding=NULL);
More information about the Aptitude-svn-commit
mailing list