You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
4.7KB

  1. //
  2. // "$Id: browser.cxx 7903 2010-11-28 21:06:39Z matt $"
  3. //
  4. // Browser test program for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2010 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. /*
  28. This is a test of how the browser draws lines.
  29. This is a second line.
  30. This is a third.
  31. That was a blank line above this.
  32. @r@_Right justify
  33. @c@_Center justify
  34. @_Left justify
  35. @bBold text
  36. @iItalic text
  37. @b@iBold Italic
  38. @fFixed width
  39. @f@bBold Fixed
  40. @f@iItalic Fixed
  41. @f@i@bBold Italic Fixed
  42. @lLarge
  43. @l@bLarge bold
  44. @sSmall
  45. @s@bSmall bold
  46. @s@iSmall italic
  47. @s@i@bSmall italic bold
  48. @uunderscore
  49. @C1RED
  50. @C2Green
  51. @C4Blue
  52. You should try different browser types:
  53. Fl_Browser
  54. Fl_Select_Browser
  55. Fl_Hold_Browser
  56. Fl_Multi_Browser
  57. */
  58. #include <FL/Fl.H>
  59. #include <FL/Fl_Select_Browser.H>
  60. #include <FL/Fl_Double_Window.H>
  61. #include <FL/Fl_Button.H>
  62. #include <FL/Fl_Int_Input.H>
  63. #include <FL/fl_ask.H>
  64. #include <stdio.h>
  65. #include <string.h>
  66. #include <errno.h>
  67. #include <stdlib.h>
  68. Fl_Select_Browser *browser;
  69. Fl_Button *top,
  70. *bottom,
  71. *middle,
  72. *visible,
  73. *swap,
  74. *sort;
  75. Fl_Int_Input *field;
  76. void b_cb(Fl_Widget* o, void*) {
  77. printf("callback, selection = %d, event_clicks = %d\n",
  78. ((Fl_Browser*)o)->value(), Fl::event_clicks());
  79. }
  80. void show_cb(Fl_Widget *o, void *) {
  81. int line = atoi(field->value());
  82. if (!line) {
  83. fl_alert("Please enter a number in the text field\n"
  84. "before clicking on the buttons.");
  85. return;
  86. }
  87. if (o == top)
  88. browser->topline(line);
  89. else if (o == bottom)
  90. browser->bottomline(line);
  91. else if (o == middle)
  92. browser->middleline(line);
  93. else
  94. browser->make_visible(line);
  95. }
  96. void swap_cb(Fl_Widget *, void *) {
  97. int a = -1, b = -1;
  98. for ( int t=0; t<browser->size(); t++ ) { // find two selected items
  99. if ( browser->selected(t) ) {
  100. if ( a < 0 )
  101. { a = t; }
  102. else
  103. { b = t; break; }
  104. }
  105. }
  106. browser->swap(a, b); // swap them
  107. }
  108. void sort_cb(Fl_Widget *, void *) {
  109. browser->sort(FL_SORT_ASCENDING);
  110. }
  111. int main(int argc, char **argv) {
  112. int i;
  113. if (!Fl::args(argc,argv,i)) Fl::fatal(Fl::help);
  114. const char* fname = (i < argc) ? argv[i] : "browser.cxx";
  115. Fl_Double_Window window(480,400,fname);
  116. browser = new Fl_Select_Browser(0,0,480,350,0);
  117. browser->type(FL_MULTI_BROWSER);
  118. //browser->type(FL_HOLD_BROWSER);
  119. //browser->color(42);
  120. browser->callback(b_cb);
  121. // browser->scrollbar_right();
  122. //browser->has_scrollbar(Fl_Browser::BOTH_ALWAYS);
  123. if (!browser->load(fname)) {
  124. int done = 0;
  125. #ifdef _MSC_VER
  126. // if 'browser' was started from the VisualC environment in Win32,
  127. // the current directory is set to the environment itself,
  128. // so we need to correct the browser file path
  129. if ( i == argc )
  130. {
  131. fname = "../test/browser.cxx";
  132. done = browser->load(fname);
  133. }
  134. #elif defined(USING_XCODE)
  135. if ( i == argc )
  136. {
  137. char buf[2048];
  138. strcpy(buf, argv[0]);
  139. char *slash = strrchr(buf, '/');
  140. if (slash)
  141. strcpy(slash, "/../Resources/browser.cxx");
  142. done = browser->load(buf);
  143. }
  144. #endif
  145. if ( !done )
  146. {
  147. fl_message("Can't load %s, %s\n", fname, strerror(errno));
  148. exit(1);
  149. }
  150. }
  151. browser->position(0);
  152. field = new Fl_Int_Input(50, 350, 430, 25, "Line #:");
  153. field->callback(show_cb);
  154. top = new Fl_Button(0, 375, 80, 25, "Top");
  155. top->callback(show_cb);
  156. bottom = new Fl_Button(80, 375, 80, 25, "Bottom");
  157. bottom->callback(show_cb);
  158. middle = new Fl_Button(160, 375, 80, 25, "Middle");
  159. middle->callback(show_cb);
  160. visible = new Fl_Button(240, 375, 80, 25, "Make Vis.");
  161. visible->callback(show_cb);
  162. swap = new Fl_Button(320, 375, 80, 25, "Swap");
  163. swap->callback(swap_cb);
  164. swap->tooltip("Swaps two selected lines\n(Use CTRL-click to select two lines)");
  165. sort = new Fl_Button(400, 375, 80, 25, "Sort");
  166. sort->callback(sort_cb);
  167. window.resizable(browser);
  168. window.show(argc,argv);
  169. return Fl::run();
  170. }
  171. //
  172. // End of "$Id: browser.cxx 7903 2010-11-28 21:06:39Z matt $".
  173. //