paned.pp 4.7 KB

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