paned.pp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. {
  2. Converted from C to Pascal by Artur Bac
  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 panned;
  18. uses glib,gtk;
  19. Function create_list : PGtkWidget; cdecl;
  20. Var
  21. scrolled_window : PGtkWidget;
  22. list : PGtkWidget;
  23. list_item : PGtkWidget;
  24. i : longint;
  25. buffer : ansistring;
  26. Ptr_Buffer : PChar ;
  27. Begin
  28. // Create a new scrolled window, with scrollbars only if needed
  29. scrolled_window := gtk_scrolled_window_new (NULL, NULL);
  30. gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
  31. GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
  32. // Create a new list and put it in the scrolled window
  33. list := gtk_list_new ();
  34. gtk_scrolled_window_add_with_viewport (
  35. GTK_SCROLLED_WINDOW (scrolled_window), list);
  36. gtk_widget_show (list);
  37. // Add some messages to the window
  38. for i:=0 to 10 do Begin
  39. Str (i,buffer);
  40. buffer := 'Message #' + buffer;
  41. Ptr_buffer := PChar (buffer);
  42. list_item := gtk_list_item_new_with_label (Ptr_buffer);
  43. gtk_container_add (GTK_CONTAINER(list), list_item);
  44. gtk_widget_show (list_item);
  45. End;
  46. create_list := scrolled_window;
  47. End;
  48. { Add some text_ to our text_ widget - this is a callback that is invoked
  49. when our window is realized. We could also force our window to be
  50. realized with gtk_widget_realize, but it would have to be part of
  51. a hierarchy first }
  52. Procedure realize_text( text_ : PGtkWidget ;
  53. data : gpointer); cdecl;
  54. Var
  55. style : PGtkStyle;
  56. Begin
  57. gtk_text_freeze (GTK_text (text_));
  58. style := gtk_widget_get_style (text_);
  59. gtk_text_insert (GTK_text (text_), NULL, @style^.black, NULL,
  60. 'From: [email protected]'+#10+
  61. 'To: [email protected]'+#10+
  62. 'Subject: Made it!'+#10+
  63. +#10+
  64. 'We just got in this morning. The weather has been'+#10+
  65. 'great - clear but cold, and there are lots of fun sights.'+#10+
  66. 'Sojourner says hi. See you soon.'+#10+
  67. ' -Path'+#10, -1);
  68. gtk_text_thaw (GTK_text (text_));
  69. End;
  70. { Create a scrolled text area that displays a 'message' }
  71. Function create_text : PGtkWidget; cdecl;
  72. Var
  73. table,
  74. text_,
  75. hscrollbar,
  76. vscrollbar : PGtkWidget;
  77. Begin
  78. { Create a table to hold the text_ widget and scrollbars }
  79. table:= gtk_table_new (2, 2, FALSE);
  80. { Put a text_ widget in the upper left hand corner. Note the use of
  81. GTK_SHRINK in the y direction }
  82. text_ := gtk_text_new (NULL, NULL);
  83. gtk_table_attach (GTK_TABLE (table), text_, 0, 1, 0, 1,
  84. GTK_FILL OR GTK_EXPAND,
  85. GTK_FILL OR GTK_EXPAND OR GTK_SHRINK, 0, 0);
  86. gtk_widget_show (text_);
  87. { Put a HScrollbar in the lower left hand corner }
  88. hscrollbar := gtk_hscrollbar_new (GTK_text (text_)^.hadj);
  89. gtk_table_attach (GTK_TABLE (table), hscrollbar, 0, 1, 1, 2,
  90. GTK_EXPAND OR GTK_FILL, GTK_FILL, 0, 0);
  91. gtk_widget_show (hscrollbar);
  92. { And a VScrollbar in the upper right }
  93. vscrollbar := gtk_vscrollbar_new (GTK_text (text_)^.vadj);
  94. gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
  95. GTK_FILL, GTK_EXPAND OR GTK_FILL OR GTK_SHRINK, 0, 0);
  96. gtk_widget_show (vscrollbar);
  97. { Add a handler to put a message in the text_ widget when it is realized }
  98. gtk_signal_connect (GTK_OBJECT (text_), 'realize',
  99. GTK_SIGNAL_FUNC (@realize_text), NULL);
  100. create_text := table;
  101. End;
  102. Var
  103. window,
  104. vpaned,
  105. list,
  106. text_ : PGtkWidget;
  107. Begin
  108. gtk_set_locale ();
  109. gtk_init (@argc, @argv);
  110. gtk_rc_init;
  111. window := gtk_window_new (GTK_WINDOW_TOPLEVEL);
  112. gtk_window_set_title (GTK_WINDOW (window), 'Paned Windows');
  113. gtk_signal_connect (GTK_OBJECT (window), 'destroy',
  114. GTK_SIGNAL_FUNC (@gtk_main_quit), NULL);
  115. gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  116. gtk_widget_set_usize (GTK_WIDGET(window), 450, 400);
  117. { create a vpaned widget and add it to our toplevel window }
  118. vpaned := gtk_vpaned_new ();
  119. gtk_container_add (GTK_CONTAINER(window), vpaned);
  120. gtk_paned_set_handle_size (GTK_PANED(vpaned),
  121. 10);
  122. // gtk_paned_set_gutter_size (GTK_PANED(vpaned), 15);
  123. gtk_widget_show (vpaned);
  124. { Now create the contents of the two halves of the window }
  125. list := create_list ();
  126. gtk_paned_add1 (GTK_PANED(vpaned), list);
  127. gtk_widget_show (list);
  128. text_ := create_text ();
  129. gtk_paned_add2 (GTK_PANED(vpaned), text_);
  130. gtk_widget_show (text_);
  131. gtk_widget_show (window);
  132. gtk_main ();
  133. End.