Tutorial

Inti Logo

« Rulers
Text Entries »

Statusbars

Statusbars are simple widgets used to display a text message. They keep a stack of the messages pushed onto them, so that popping the current message will re-display the previous text message.

In order to allow different parts of an application to use the same statusbar to display messages, the statusbar widget issues Context Identifiers which are used to identify different "users". The message on top of the stack is the one displayed, no matter what context it is in. Messages are stacked in last-in-first-out order, not context identifier order.

A statusbar is created with the constructor:

Statusbar();

A new Context Identifier is requested using a call to the following method with a short textual description of the context:

unsigned int get_context_id(const String& context_description) const;

There are three methods that can operate on statusbars:

unsigned int push(const String& text, unsigned int context_id = 0);
 
void pop(unsigned int context_id = 0);

void remove(unsigned int message_id, unsigned int context_id = 0);

The first, Gtk::Statusbar::push(), is used to add a new message to the statusbar. It returns a Message Identifier, which can be passed later to the function Gtk::Statusbar::remove() to remove the message with the given Message and Context Identifiers from the statusbar's stack.

The Gtk::Statusbar::pop() method removes the message highest in the stack with the given Context Identifier.

In addition to messages, statusbars may also display a resize grip, which can be dragged with the mouse to resize the toplevel window containing the statusbar, similar to dragging the window frame. The following methods control the display of the resize grip.

void set_has_resize_grip(bool setting);

bool get_has_resize_grip() const;


The following example creates a statusbar and two buttons, one for pushing items onto the statusbar, and one for popping the last item back off.

Statusbar Example

The header file for Inti Statusbar Example is statusbar.h:

#include<inti/main.h>
#include <inti/core.h>
#include <inti/gtk/statusbar.h>

using namespace Inti;

class StatusbarWindow : public Gtk::Window
{
    Gtk::Statusbar *status_bar;

protected:
    void on_push_item(int context_id);
    void on_pop_item(int context_id);

public:
    StatusbarWindow();
    ~StatusbarWindow();
};


and the source file is statusbar.cc:

#include"statusbar.h"
#include <inti/gtk/button.h>
#include <inti/bind.h>


StatusbarWindow::StatusbarWindow()
{
    set_title("Inti Statusbar Example");
    set_size_request(200, 100);

    Gtk::VBox *vbox = new Gtk::VBox(false, 1);
    add(*vbox);
    vbox->show();

    status_bar = new Gtk::Statusbar;
    vbox->pack_start(*status_bar);
    status_bar->show();

    int context_id = status_bar->get_context_id("Statusbar example");

    Gtk::Button *button = new Gtk::Button("push item");
    button->sig_clicked().connect(bind(slot(this, &StatusbarWindow::on_push_item), context_id));
    vbox->pack_start(*button, true,true, 2);
    button->show();

    button = new Gtk::Button("pop last item");
    button->sig_clicked().connect(bind(slot(this, &StatusbarWindow::on_pop_item), context_id));
    vbox->pack_start(*button, true,true, 2);
    button->show();

    // Always display the window as the last step so it all splashes on the screen at once.
    show();
}

StatusbarWindow::~StatusbarWindow()
{
}

void
StatusbarWindow::on_push_item(int context_id)
{
    static int count = 1;
    String text = String::format("Item %d", count++);
    status_bar->push(text, context_id);
}

void
StatusbarWindow::on_pop_item(int context_id)
{
    status_bar->pop(context_id);
}

int main (int argc, char *argv[])
{
    using namespace Main;

    init(&argc, &argv);

    StatusbarWindow window;
    window.sig_destroy().connect(slot(&Inti::Main::quit));

    run();
    return 0;
}




« Rulers Index
Miscellaneous Widgets
Top
 Text Entries »