statusbar.pp 2.4 KB

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