Re: best practice with ArrayHandle



Thanks a lot.

I'm looking forward to C++0x's initializer lists, this will greatly simplify things !

On 21/02/11 19:17, Krzesimir Nowak wrote:
On Mon, 2011-02-21 at 16:53 +0100, Yann Leydier wrote:
Hi,

I'm currently preparing my code to be Windows-friendly. I wrote the
following lines to enable Windows-style buttons ordering in a dialog and
I wondered if there is a simplest way to do it :

dial.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
dial.add_button(Gtk::Stock::ADD, Gtk::RESPONSE_ACCEPT);
int altbut[] = { Gtk::RESPONSE_ACCEPT, Gtk::RESPONSE_CANCEL };
dial.set_alternative_button_order_from_array(Glib::ArrayHandle<int>(altbut,
2, Glib::OWNERSHIP_NONE));


Best practice with ArrayHandle is "Just don't use it explicitly" - it is
just a helper type to handle memory management and is convertible from C
arrays to std::{vector,list,deque} and vice versa. It is meant to be
used only by wrappers like glibmm or gtkmm - not by users of these
wrappers. So your code should look like this:

dial.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
dial.add_button(Gtk::Stock::ADD, Gtk::RESPONSE_ACCEPT);

std::vector<int>  altbut;

altbut.reserve(2);
altbut.push_back(Gtk::RESPONSE_ACCEPT);
altbut.push_back(Gtk::RESPONSE_CANCEL);
dial.set_alternative_button_order_from_array(altbut);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]