PDA

View Full Version : [SOLVED] GTKmm: Porting to GTK3



fallenshadow
November 2nd, 2011, 12:48 PM
Im currently porting my GTK2 codebase to GTK3 with GTKmm. I tried compiling and reduced my errors from 35 to 22 and now to 11.

I really don't know how to fix this section of code, so I would appreciate some help on it.


app->size_allocate().connect(sigc::mem_fun(*this, &mainWindow::on_size_allocate));

void mainWindow::on_size_allocate(Gtk::Requisition* req)
{
std::cout << "in on_size_request" << std::endl;
int width, height;
app->get_size(width, height);

Gtk::HPaned* pane;
refBuilder->get_widget("hpaned1", pane);
pane->set_position(width - 200);
}


This may be of help: http://developer.gnome.org/gtkmm/stable/deprecated.html


Errors:
mainwindow.cc: In member function ‘Gtk::Window* mainWindow::init()’:
mainwindow.cc:74:21: error: no matching function for call to ‘Gtk::Window::size_allocate()’
mainwindow.cc:74:21: note: candidate is:
/usr/include/gtkmm-3.0/gtkmm/widget.h:460:8: note: void Gtk::Widget::size_allocate(const Allocation&)
/usr/include/gtkmm-3.0/gtkmm/widget.h:460:8: note: candidate expects 1 argument, 0 provided


Im sure its something to do with the function call expecting another parameter and hpaned should be paned. I could use a helping hand on this one.

cgroza
November 2nd, 2011, 11:45 PM
That function expects an Allocation object. I tried to google it and all i had was trash.
It seems to me that you have to create or get an Allocation object somehow.
I would look more careful in the API for methods that return Allocation.

fallenshadow
November 10th, 2011, 03:26 PM
Here is an updated attempt... however I might not need this code anymore as I have partially solved the problem within the Glade file.



app->size_allocate(r).connect(sigc::mem_fun(*this, &mainWindow::on_size_allocate));

void mainWindow::on_size_allocate(Gtk::Allocation& r)
{
set_allocation(r);
int width, height;
app->get_size(width, height);
Gtk::HPaned* pane;
refBuilder->get_widget("hpaned1", pane);
pane->set_position(width - 200);
}


I still would prefer to have this working as it provides alot more control over the width of my hpane.

Error message:


"mainwindow.cc:74:21: error: ‘r’ was not declared in this scope"


If anyone knows what the problem is then please let me know!

crdlb
November 10th, 2011, 06:05 PM
app->size_allocate(r).connect(sigc::mem_fun(*this, &mainWindow::on_size_allocate));



I'm not very familiar with gtkmm, but it seems the signal is 'signal_size_allocate', not just 'size_allocate'

The actual error is probably due to that 'r', which shouldn't be there.

pbrane
November 11th, 2011, 02:28 PM
Here is an updated attempt... however I might not need this code anymore as I have partially solved the problem within the Glade file.



app->size_allocate(r).connect(sigc::mem_fun(*this, &mainWindow::on_size_allocate));

void mainWindow::on_size_allocate(Gtk::Allocation& r)
{
set_allocation(r);
int width, height;
app->get_size(width, height);
Gtk::HPaned* pane;
refBuilder->get_widget("hpaned1", pane);
pane->set_position(width - 200);
}


I still would prefer to have this working as it provides alot more control over the width of my hpane.

Error message:


If anyone knows what the problem is then please let me know!
crdlb is right about the signal name. So... for posterity:



app->signal_size_allocate().connect(sigc::mem_fun(*this , &mainWindow::on_size_allocate));

void mainWindow::on_size_allocate(Gtk::Allocation& allocation)
{
//
// make any changes to the Gtk::Allocation structure here
//
set_allocation(allocation);

Gtk::HPaned* pane;
refBuilder->get_widget("hpaned1", pane);
// use the allocated width
pane->set_position(allocation.get_width() - 200);
}