Problems with widget focus and key navigation in a hscale widget



Dear all,

I've included in the e-mail a small sample to discuss about problems of
widget focus and key navigation on a hscale widget.

The installed libraries in the system are:
gtk: 2.10.14
gtkmm: 2.10.10

The program at execution, show a windows with 3 widgets:

- Popup button: show a window pop-up button. The popup window consists
only in a label of text. The pop-up window auto-hides after 5 seconds
from the last key pressed event received. The popup window is modal.

- Quit button: closes the application.

- Hscale: does nothing. Simply to test key navigation.

Let's being:

1 - I've detected that gtkmm/gtk have some problems to set the focus
properly on the expected widged. Following theres are four tests:

- When the application runs, the pop-up button could be pressed several
times (each one after the pop-up window has closed) without moving the
mouse from pop-up button. Once the last pop-up window is not shown, move
the button to the quit button, press it and the application quits.
The behavior is OK.

- When the application runs, click on the pop-up button. While the
pop-up window is shown, move the mouse on the quit button, and wait to
disappear the pop-up window. Then when the quit button is pressed, it is
not working, but pop-up button works fine.
Also, to be confident that pressing the quit button it will work, before
pressing it, move out of quit button (for example, on top of the hscale)
and then press it.
It's not working as expected.

- When the application runs, click on the pop-up button. While the
pop-up window is shown, move several times alternatively the mouse from
pop-up button to quit button, and left the mouse on the pop-up button.
Once the pop-up window is closed, if the pop-up button is pressed, the
pop-up window is not shown, but quit button works fine.
It's not working as expected.

- When the application runs, click on the pop-up button. While the
pop-up window is shown, move several times alternatively the mouse from
pop-up button to quit button, and left the mouse on the quit button.
Once the pop-up window is closed, if the quit button is pressed, it
doesn't works but the pop-up button works fine.
It's not working as expected.


2 - I've been tested to run the application using with keys. Everyting
is working fine but, not the hscale widget. It doen't react to any key:
cursor keys, rePag, AvPag, +, -. Could This widget be managed using
keys? Which keys should be used? Is this a bug?

Thanks and Best Regards,

Joaquim Duran

#include <gtkmm/widget.h>
#include <gtkmm/window.h>
#include <gtkmm/label.h>
#include <gtkmm/button.h>
#include <gtkmm/scale.h>
#include <gtkmm/box.h>
#include <gtkmm/main.h>

#include <iostream>

//POPUP WINDOW
class PopupWindow: public Gtk::Window
{
public:
  PopupWindow(Gtk::Widget &wdg, unsigned int tout);
  PopupWindow(unsigned int tout);
  virtual ~PopupWindow();

  void run();


protected:
  bool onTimeOut();

  virtual bool on_key_press_event (GdkEventKey* event);

private:
  unsigned int timeOut;
  sigc::connection conn;

  Gtk::Label label;
};


PopupWindow::PopupWindow(Gtk::Widget &wdg, unsigned int tout):
  Gtk::Window(Gtk::WINDOW_POPUP), timeOut(tout), conn(),
  label("TEST, TEST, TEST")
{
    Gtk::Widget *parent;
    Gtk::Window *win;

    parent = &wdg;
    win = dynamic_cast<Gtk::Window*>(parent);
    while (win == 0)
    {
        parent = parent->get_parent();
        win = dynamic_cast<Gtk::Window*>(parent);
    }
    set_transient_for(*win);
    set_position(Gtk::WIN_POS_CENTER_ON_PARENT);

    set_resizable(false);
    resize(200,200); // Caldrà definir tamany maxim
    set_modal(true);
    set_keep_above(true);

    add(this->label);

    conn = Glib::signal_timeout().connect(sigc::mem_fun(*this,
		      &PopupWindow::onTimeOut),
          timeOut);

    show_all_children();
}


PopupWindow::PopupWindow(unsigned int tout):
  Gtk::Window(Gtk::WINDOW_POPUP), timeOut(tout), conn(),
  label("TEST, TEST, TEST")
{
    set_position(Gtk::WIN_POS_CENTER_ON_PARENT);

    set_resizable(false);
    resize(200,200); //DEBUG
    set_modal(true);
    set_keep_above(true);

    add(this->label);

    show_all_children();
}


PopupWindow::~PopupWindow()
{
}


void PopupWindow::run()
{
    Gtk::Main::run(*this);
}


bool PopupWindow::onTimeOut()
{
    hide();
    return true;
}


bool PopupWindow::on_key_press_event (GdkEventKey* event)
{
    std::cout << "Key press event" << std::endl;

    conn.disconnect();
    conn = Glib::signal_timeout().connect(sigc::mem_fun(*this,
		      &PopupWindow::onTimeOut),
          timeOut);

    return Gtk::Window::on_key_press_event(event);
}


//MAIN WINDOW
class MainWindow: public Gtk::Window
{
public:
  MainWindow();
  virtual ~MainWindow();

protected:
  void onPopupPressed();
  void onQuitPressed();

private:
  Gtk::VBox vbox;
  Gtk::Button popup;
  Gtk::Button quit;
  Gtk::HScale hscale;
};


MainWindow::MainWindow():
  Gtk::Window(), vbox(), popup("Popup"), quit("Quit")
{
  add(vbox);
  vbox.add(popup);
  vbox.add(quit);
  vbox.add(hscale);
  hscale.set_range(0,10);
  hscale.set_value(5);


  popup.signal_clicked().connect( sigc::mem_fun(*this,
		   &MainWindow::onPopupPressed) );
  quit.signal_clicked().connect( sigc::mem_fun(*this,
              &MainWindow::onQuitPressed) );

  resize(300, 300);

  show_all_children();
}


MainWindow::~MainWindow()
{
}


void MainWindow::onPopupPressed()
{
  PopupWindow popup(*this, 5000);
  popup.run();
}


void MainWindow::onQuitPressed()
{
    hide();
}


// MAIN
int main(int argc, char *argv[])
{
  Gtk::Main kit(argc, argv);

  MainWindow mainWin;
  Gtk::Main::run(mainWin);

  return 0;
}


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