A.28. Status Bar

statusbar_counter = 1;

function statusbar_push(statusbar)
{
  local text;
  text = string("something ", statusbar_counter++);
  statusbar.push(1, text);
}

function statusbar_pop(statusbar)
{
  statusbar.pop(1);
}

function statusbar_steal(statusbar)
{
  statusbar.remove(1,4);
}

function statusbar_dump_stack(statusbar)
{
  with msg in (statusbar.get_messages()) do
    princ(format("context_id: %d, message_id: %d, status_text: \"%s\"\n",
		 msg.context_id,
		 msg.message_id,
		 msg.text));
}


function statusbar_contexts(statusbar)
{
  local strg;
  
  stringlist = list("any context", "idle messages", "some text",
		    "hit the mouse", "hit the mouse2");
  with strg in stringlist do
    {
      princ("GtkStatusBar: context=\"", strg, "\", context_id=",
	    statusbar.get_context_id(strg),"\n");
    }
}


function statusbar_popped(statusbar)
{
  if (!statusbar.get_messages())
    statusbar_counter = 1;
}


function create_statusbar ()
{
  local box1, box2, button, separator, statusbar;
  
  win_statusbar = new (GtkWindow);
  win_statusbar.signal ("destroy", #win_statusbar = nil);
  win_statusbar.title = "statusbar";
  win_statusbar.border_width = 0;
  
  box1 = new(GtkVBox);
  win_statusbar.add(box1);
  
  box2 = new(GtkVBox);
  box2.spacing = 10;
  box2.border_width = 10;
  box1.pack_start(box2, TRUE, TRUE, 0);
  
  statusbar = new(GtkStatusbar);
  box1.pack_end(statusbar, TRUE, TRUE, 0);
  statusbar.signal("text_popped", `statusbar_popped(@statusbar));
  
  button = new(GtkButton);
  button.label = "push something";
  button.visible = TRUE;
  button.parent = box2;
  button.signal("clicked", `statusbar_push(@statusbar));
  
  button = new(GtkButton);
  button.label = "pop";
  button.visible = TRUE;
  button.parent = box2;
  button.signal("clicked", `statusbar_pop(@statusbar));
  
  button = new(GtkButton);
  button.label = "steal #4";
  button.visible = TRUE;
  button.parent = box2;
  button.signal("clicked", `statusbar_steal(@statusbar));
  
  button = new(GtkButton);
  button.label = "dump stack";
  button.visible = TRUE;
  button.parent = box2;
  button.signal("clicked", `statusbar_dump_stack(@statusbar));
  
  button = new(GtkButton);
  button.label = "test contexts";
  button.visible = TRUE;
  button.parent = box2;
  button.signal("clicked", `statusbar_contexts(@statusbar));
  
  separator = new(GtkHSeparator);
  box1.pack_start(separator, FALSE, TRUE, 0);
  
  box2 = new (GtkVBox);
  box2.border_width = 10;
  box1.pack_start (box2, FALSE, TRUE, 0);
  
  button = new (GtkButton);
  button.label = "close";
  button.signal ("clicked", `(@win_statusbar).destroy());
  box2.pack_start (button, TRUE, TRUE, 0);
  button.can_default = TRUE;
  button.grab_default();
  
  win_statusbar.show_all();
  win_statusbar;
}

function main ()
{
  local window, win_statusbar;
  TRUE=1;
  FALSE=0;
  window = create_statusbar ();
  window.signal ("destroy", #exit_program(0));
  init_ipc("statusbar", "statusbarq");
  gtk_main ();
}