Restrict the keyboard focus to one widget



Dear all,

We're developing an application in which the client is interested to see
transparent pop-up windows. As we are not using any composite window
manager, to provide transparencies between windows, we could simulate
transparent pop-up windows using a container widget. To implement it, I
was thinking in placing the application window and the pop-up window in
a Fixed panel.

I've done some prototype and it works quite fine. Among other problems
I've found, while showing the pop-up window, the focus chain is not
restricted to pop-up window: it includes all widgets shown in the
screen. I'm interested to restrict the focus chain to pop-up window
while it is shown.

Reading the documentation, I've found that the widgets can capture the
events to the rest of widgets by calling to 'add_modal_grab()':

http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1Widget.html#ac16e0fc4bc802b9d894ddf693875c90

I've written a small prototype program to test it (included in this
e-mail) but it looks like it is not working. When the 'add_modal_grab()'
should be called?


Also, How can I configure a widget to be displayed non grayed when it is
set to no sensitive?

Thanks and Best Regards,
Joaquim Duran
/*
 * Demo per a comprovar si en 2 fixes passen el focus d'un a l'altre o no
 */

#include <vector>
#include <gtkmm/fixed.h>
#include <gtkmm/button.h>
#include <gtkmm/window.h>
#include <gtkmm/fixed.h>
#include <gtkmm/main.h>

#include <iostream>

class Popup : public Gtk::Fixed
{
public:
  Popup();
  ~Popup();
};

  Popup::Popup():Gtk::Fixed()
{
}

Popup::~Popup()
{
}


class FocusPanel : public Gtk::Fixed
{
public:
  FocusPanel();
  virtual ~FocusPanel();

private:
  Gtk::Fixed fixed1;
  Popup fixed2;
  Gtk::Button b1, b2, b3, b4, b5, b6;
};


FocusPanel::FocusPanel():
  Gtk::Fixed(), fixed1(), fixed2(),
  b1("Button 1"), b2("Button 2"), b3("Button 3"), b4("Button 4"),
  b5("Button 5"), b6("Button 6")
{
    set_size_request(800, 480);
    fixed1.set_size_request(400, 200);
    fixed2.set_size_request(400, 200);

    put(this->fixed1, 0, 0);
    put(this->fixed2, 300, 300);

    this->fixed1.put(this->b1, 0, 0);
    this->fixed1.put(this->b2, 0, 50);
    this->fixed1.put(this->b3, 0, 100);

    this->fixed2.put(this->b4, 0, 0);
    this->fixed2.put(this->b5, 0, 50);
    this->fixed2.put(this->b6, 0, 100);

    //this->fixed1.set_sensitive(false);
    //this->fixed1.add_modal_grab();
    show_all();
    this->fixed1.add_modal_grab();
}


FocusPanel::~FocusPanel()
{
}


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

  Gtk::Window window;
  FocusPanel panel;
  window.add(panel);
  Gtk::Main::run(window);

  return 0;
}



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