Re: problems with scrolled_event()





oedipus wrote:
> 
> I solved the problem with: 
> "double val1 = scrolledwiindow1 -> get_hscrollbar() -> get_value();"
> 

After working a little bit with. All the sudden it didn't work anymore and I
cannot rebuild it. In the class reference it is decribed ther
get_v/hscrollbar() gives acces to the scrollbars of a scrolled window. And
through the Scrollbar there should be the range class accessable, to read
out the current position with get_value(). But with that line of code it
tells me that I invalidly access the scrollbar class and that it is a
forward declaration. How can I access now the scrollbars of a scrolled
window?

I have build a small sample code, basicly it is just a scrolled window,
where I want to read out the current position of the slider in the
scrollbar:
/* file main_window.cc */
#include "config.h"
#include "main_window.hh"

bool main_window::on_drawingarea1_expose_event(GdkEventExpose *ev)
{  
    drawingarea1 -> set_size_request(2000,2000);
    double val = scrolledwindow1 -> get_hscrollbar() -> get_value();
    return 0;
}

bool main_window::quit(GdkEventAny *ev)
{  return 0;
}
/* file main_window.hh*/
#ifndef _MAIN_WINDOW_HH
#  include "main_window_glade.hh"
#  define _MAIN_WINDOW_HH
class main_window : public main_window_glade
{  
        
    bool on_drawingarea1_expose_event(GdkEventExpose *ev);
    bool quit(GdkEventAny *ev);
};
#endif
/* file main_window_glade.cc*/
#if defined __GNUC__ && __GNUC__ < 3
#error This program will crash if compiled with g++ 2.x
// see the dynamic_cast bug in the gtkmm FAQ
#endif //
#include "config.h"
#include <gtkmmconfig.h>
#if GTKMM_MAJOR_VERSION==2 && GTKMM_MINOR_VERSION>2
#include <sigc++/compatibility.h>
#define GMM_GTKMM_22_24(a,b) b
#else //gtkmm 2.2
#define GMM_GTKMM_22_24(a,b) a
#endif //
#include "main_window_glade.hh"
#include <gdk/gdkkeysyms.h>
#include <gtkmm/accelgroup.h>
#include <gtkmm/adjustment.h>

main_window_glade::main_window_glade(
) : Gtk::Window(Gtk::WINDOW_TOPLEVEL)
{  main_window = this;
   gmm_data = new GlademmData(get_accel_group());
   drawingarea1 = Gtk::manage(new class Gtk::DrawingArea());
   viewport1 = Gtk::manage(new class Gtk::Viewport(*manage(new
Gtk::Adjustment(0,0,1)), *manage(new Gtk::Adjustment(0,0,1))));
   scrolledwindow1 = Gtk::manage(new class Gtk::ScrolledWindow());
   viewport1->set_shadow_type(Gtk::SHADOW_IN);
   viewport1->add(*drawingarea1);
   scrolledwindow1->set_flags(Gtk::CAN_FOCUS);
   scrolledwindow1->set_shadow_type(Gtk::SHADOW_NONE);
   scrolledwindow1->set_policy(Gtk::POLICY_ALWAYS, Gtk::POLICY_ALWAYS);
   
scrolledwindow1->property_window_placement().set_value(Gtk::CORNER_TOP_LEFT);
   scrolledwindow1->add(*viewport1);
   main_window->set_size_request(150,150);
   main_window->set_title("projectxx Project");
   main_window->set_modal(false);
   main_window->property_window_position().set_value(Gtk::WIN_POS_CENTER);
   main_window->set_resizable(true);
   main_window->property_destroy_with_parent().set_value(false);
   main_window->add(*scrolledwindow1);
   drawingarea1->show();
   viewport1->show();
   scrolledwindow1->show();
   main_window->show();
   drawingarea1->signal_expose_event().connect(SigC::slot(*this,
&main_window_glade::on_drawingarea1_expose_event), false);
   main_window->signal_delete_event().connect(SigC::slot(*this,
&main_window_glade::quit), false);
}

main_window_glade::~main_window_glade()
{  delete gmm_data;
}
/* file main_window_glade.hh */
#ifndef _MAIN_WINDOW_GLADE_HH
#  define _MAIN_WINDOW_GLADE_HH


#if !defined(GLADEMM_DATA)
#define GLADEMM_DATA
#include <gtkmm/accelgroup.h>

class GlademmData
{  
        
        Glib::RefPtr<Gtk::AccelGroup> accgrp;
public:
        
        GlademmData(Glib::RefPtr<Gtk::AccelGroup> ag) : accgrp(ag)
        {  
        }
        
        Glib::RefPtr<Gtk::AccelGroup>  getAccelGroup()
        {  return accgrp;
        }
};
#endif //GLADEMM_DATA

#include <gtkmm/window.h>
#include <gtkmm/drawingarea.h>
#include <gtkmm/viewport.h>
#include <gtkmm/scrolledwindow.h>

class main_window_glade : public Gtk::Window
{  
        
        GlademmData *gmm_data;
public:
        class Gtk::Window * main_window;
        class Gtk::DrawingArea * drawingarea1;
        class Gtk::Viewport * viewport1;
        class Gtk::ScrolledWindow * scrolledwindow1;
protected:
        
        main_window_glade();
        
        ~main_window_glade();
private:
        virtual bool on_drawingarea1_expose_event(GdkEventExpose *ev) = 0;
        virtual bool quit(GdkEventAny *ev) = 0;
};
#endif
/* main */
#include <config.h>
#include <gtkmm/main.h>

#include "main_window.hh"

int main(int argc, char **argv)
{  
   
    Gtk::Main m(&argc, &argv);

    main_window *main_window = new class main_window();
    m.run(*main_window);
    delete main_window;
    return 0;
}

-- 
View this message in context: http://www.nabble.com/problems-with-scrolled_event%28%29-tf2410356.html#a6770737
Sent from the Gtkmm mailing list archive at Nabble.com.




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