statusbar.pp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. {
  2. $Id$
  3. Converted from C to Pascal by Artur Bac with liitle additions changes
  4. <[email protected]>
  5. Reda Poland
  6. }
  7. {$MODE objfpc}
  8. {$H+}
  9. {$S+}
  10. {$HINTS ON}
  11. {$ifdef win32}
  12. {$define extdecl := stdcall;}
  13. {$APPTYPE GUI}
  14. {$endif}
  15. {$ifdef unix}
  16. {$define extdecl := cdecl;}
  17. {$endif}
  18. Program statusbar;
  19. Uses glib,gtk;
  20. Type
  21. PGInt = ^gint;
  22. Var
  23. status_bar : PGtkWidget;
  24. count : longint;
  25. Procedure push_item( widget : PGtkWidget;
  26. data : PGInt); cdecl;
  27. Var
  28. buff : ansistring;
  29. ptr_buff : PGChar;
  30. Begin
  31. Inc(count);
  32. Str(count,buff);
  33. buff := 'Item ' + buff;
  34. Ptr_buff := PChar(buff); //changing type from ansistring to PGChar == PChar
  35. gtk_statusbar_push(GTK_STATUSBAR(status_bar), data^, Ptr_buff);
  36. End;
  37. Procedure pop_item( widget : PGtkWidget;
  38. data : PGint); cdecl; //i used pointer to gint , not gpointer becouse we can
  39. // read value directly from an adress specified in data
  40. Begin
  41. gtk_statusbar_pop( GTK_STATUSBAR(status_bar), data^);
  42. End;
  43. Var
  44. window,
  45. vbox,
  46. button1,button2 : PGtkWidget;
  47. context_id : gint;
  48. Begin
  49. gtk_set_locale ();
  50. gtk_init (@argc, @argv);
  51. gtk_rc_init;
  52. count:=1;
  53. //* create a new window
  54. window := gtk_window_new(GTK_WINDOW_TOPLEVEL);
  55. gtk_widget_set_usize( GTK_WIDGET (window), 200, 100); // GTK_WIDGET == PGtkWidget
  56. gtk_window_set_title(GTK_WINDOW (window), 'GTK Statusbar Example');
  57. vbox := gtk_vbox_new(FALSE, 1);
  58. gtk_container_add(GTK_CONTAINER(window), vbox);
  59. status_bar := gtk_statusbar_new();
  60. gtk_box_pack_start (GTK_BOX (vbox), status_bar, TRUE, TRUE, 0);
  61. context_id := gtk_statusbar_get_context_id(
  62. GTK_STATUSBAR(status_bar), 'Statusbar example');
  63. button1 := gtk_button_new_with_label('push item');
  64. gtk_box_pack_start(GTK_BOX(vbox), button1, TRUE, TRUE, 2);
  65. button2 := gtk_button_new_with_label('pop last item');
  66. gtk_box_pack_start(GTK_BOX(vbox), button2, TRUE, TRUE, 2);
  67. gtk_signal_connect(GTK_OBJECT (window), 'delete_event',
  68. Gtk_Signal_Func (@gtk_exit), NULL);
  69. gtk_signal_connect(GTK_OBJECT(button1), 'clicked',
  70. GTK_SIGNAL_FUNC (@push_item), @context_id );
  71. gtk_signal_connect(GTK_OBJECT(button2), 'clicked',
  72. GTK_SIGNAL_FUNC (@pop_item), @context_id );
  73. gtk_widget_show_all (window);
  74. gtk_main ();
  75. End.