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.

274 lines
11KB

  1. /**
  2. <!-- Warning: \p .fd does not work but <tt>.fd</tt> does -->
  3. \page forms Forms Compatibility
  4. This appendix describes the Forms compatibility included with FLTK.
  5. <center>
  6. <table border="1" width="90%" bgcolor="#cccccc">
  7. <tr>
  8. <th align="center">
  9. Warning: The Forms compatility is deprecated and no longer maintained in FLTK1,
  10. and is likely to be removed completely after the next official release.
  11. </th>
  12. </tr>
  13. </table>
  14. </center>
  15. \section forms_importing Importing Forms Layout Files
  16. \ref fluid "FLUID"
  17. can read the <tt>.fd</tt> files put out by
  18. all versions of Forms and XForms fdesign. However, it will mangle them
  19. a bit, but it prints a warning message about anything it does not
  20. understand. FLUID cannot write fdesign files, so you should save to a
  21. new name so you don't write over the old one.
  22. You will need to edit your main code considerably to get it to link
  23. with the output from FLUID. If you are not interested in this you may
  24. have more immediate luck with the forms compatibility header, <FL/forms.H>.
  25. \section forms_using Using the Compatibility Header File
  26. You should be able to compile existing Forms or XForms source code by
  27. changing the include directory switch to your compiler so that the
  28. \c forms.h file supplied with FLTK is included.
  29. The \c forms.h file simply pulls in <FL/forms.H> so you don't need to
  30. change your source code.
  31. Take a look at <FL/forms.H> to see how it works, but the basic trick
  32. is lots of inline functions. Most of the XForms demo programs work
  33. without changes.
  34. You will also have to compile your Forms or XForms program using a
  35. C++ compiler. The FLTK library does not provide C bindings or header
  36. files.
  37. Although FLTK was designed to be compatible with the GL Forms
  38. library (version 0.3 or so), XForms has bloated severely and it's
  39. interface is X-specific. Therefore, XForms compatibility is no longer
  40. a goal of FLTK. Compatibility was limited to things that were free, or
  41. that would add code that would not be linked in if the feature is
  42. unused, or that was not X-specific.
  43. To use any new features of FLTK, you should rewrite your code to not
  44. use the inline functions and instead use "pure" FLTK. This will make
  45. it a lot cleaner and make it easier to figure out how to call the FLTK
  46. functions. Unfortunately this conversion is harder than expected and
  47. even Digital Domain's inhouse code still uses <tt>forms.H</tt> a lot.
  48. \section forms_problems Problems You Will Encounter
  49. Many parts of XForms use X-specific structures like \c XEvent
  50. in their interface. I did not emulate these! Unfortunately these
  51. features (such as the "canvas" widget) are needed by most large
  52. programs. You will need to rewrite these to use FLTK subclasses.
  53. Fl_Free widgets emulate the \e old Forms "free" widget.
  54. It may be useful for porting programs that change the \c handle()
  55. function on widgets, but you will still need to rewrite things.
  56. Fl_Timer widgets are
  57. provided to emulate the XForms timer. These work, but are quite
  58. inefficient and inaccurate compared to using Fl::add_timeout().
  59. <I>All instance variables are hidden.</I> If you directly refer to
  60. the \p x, \p y, \p w, \p h, \p label, or other fields of your Forms
  61. widgets you will have to add empty parenthesis after each reference.
  62. The easiest way to do this is to globally replace <tt>"->x"</tt>
  63. with <tt>"->x()"</tt>, etc.
  64. Replace <tt>"boxtype"</tt> with <tt>"box()"</tt>.
  65. <tt>const char *</tt> arguments to most FLTK methods are simply
  66. stored, while Forms would \c strdup() the passed string. This is
  67. most noticable with the label of widgets. Your program must always
  68. pass static data such as a string constant or malloc'd buffer to
  69. \c label(). If you are using labels to display program output you
  70. may want to try the Fl_Output widget.
  71. The default fonts and sizes are matched to the older GL version of
  72. Forms, so all labels will draw somewhat larger than an XForms program
  73. does.
  74. fdesign outputs a setting of a "fdui" instance variable to the main
  75. window. I did not emulate this because I wanted all instance variables
  76. to be hidden. You can store the same information in the \c user_data()
  77. field of a window. To do this, search through the fdesign output for all
  78. occurances of <tt>"->fdui"</tt> and edit to use <tt>"->user_data()"</tt>
  79. instead. This will require casts and is not trivial.
  80. The prototype for the functions passed to \c fl_add_timeout()
  81. and \c fl_set_idle_callback() callback are different.
  82. <B>All the following XForms calls are missing:</B>
  83. \li \c FL_REVISION, \c fl_library_version()
  84. \li \c FL_RETURN_DBLCLICK (use Fl::event_clicks())
  85. \li \c fl_add_signal_callback()
  86. \li \c fl_set_form_atactivate() \c fl_set_form_atdeactivate()
  87. \li \c fl_set_form_property()
  88. \li \c fl_set_app_mainform(), \c fl_get_app_mainform()
  89. \li \c fl_set_form_minsize(), \c fl_set_form_maxsize()
  90. \li \c fl_set_form_event_cmask(), \c fl_get_form_event_cmask()
  91. \li \c fl_set_form_dblbuffer(), \c fl_set_object_dblbuffer()
  92. (use an Fl_Double_Window instead)
  93. \li \c fl_adjust_form_size()
  94. \li \c fl_register_raw_callback()
  95. \li \c fl_set_object_bw(), \c fl_set_border_width()
  96. \li \c fl_set_object_resize(), \c fl_set_object_gravity()
  97. \li \c fl_set_object_shortcutkey()
  98. \li \c fl_set_object_automatic()
  99. \li \c fl_get_object_bbox() (maybe FLTK should do this)
  100. \li \c fl_set_object_prehandler(), \c fl_set_object_posthandler()
  101. \li \c fl_enumerate_fonts()
  102. \li Most drawing functions
  103. \li \c fl_set_coordunit() (FLTK uses pixels all the time)
  104. \li \c fl_ringbell()
  105. \li \c fl_gettime()
  106. \li \c fl_win*() (all these functions)
  107. \li \c fl_initialize(argc,argv,x,y,z) ignores last 3 arguments
  108. \li \c fl_read_bitmapfile(), \c fl_read_pixmapfile()
  109. \li \c fl_addto_browser_chars()
  110. \li \c FL_MENU_BUTTON just draws normally
  111. \li \c fl_set_bitmapbutton_file(), \c fl_set_pixmapbutton_file()
  112. \li \c FL_CANVAS objects
  113. \li \c FL_DIGITAL_CLOCK (comes out analog)
  114. \li \c fl_create_bitmap_cursor(), \c fl_set_cursor_color()
  115. \li \c fl_set_dial_angles()
  116. \li \c fl_show_oneliner()
  117. \li \c fl_set_choice_shortcut(a,b,c)
  118. \li command log
  119. \li Only some of file selector is emulated
  120. \li \c FL_DATE_INPUT
  121. \li \c fl_pup*() (all these functions)
  122. \li textbox object (should be easy but I had no sample programs)
  123. \li xyplot object
  124. \section forms_notes Additional Notes
  125. These notes were written for porting programs written with the older
  126. IRISGL version of Forms. Most of these problems are the same ones
  127. encountered when going from old Forms to XForms:
  128. \par Does Not Run In Background
  129. The IRISGL library always forked when you created the first window,
  130. unless "foreground()" was called. FLTK acts like "foreground()" is
  131. called all the time. If you really want the fork behavior do "if
  132. (fork()) exit(0)" right at the start of your program.
  133. \par You Cannot Use IRISGL Windows or fl_queue
  134. If a Forms (not XForms) program if you wanted your own window for
  135. displaying things you would create a IRISGL window and draw in it,
  136. periodically calling Forms to check if the user hit buttons on the
  137. panels. If the user did things to the IRISGL window, you would find
  138. this out by having the value FL_EVENT returned from the call to Forms.
  139. None of this works with FLTK. Nor will it compile, the necessary
  140. calls are not in the interface.
  141. You have to make a subclass of Fl_Gl_Window and write a \c draw() method
  142. and \c handle() method. This may require anywhere from a trivial to a
  143. major rewrite.
  144. If you draw into the overlay planes you will have to also write a
  145. \c draw_overlay() method and call \c redraw_overlay() on the
  146. OpenGL window.
  147. One easy way to hack your program so it works is to make the \c draw()
  148. and \c handle() methods on your window set some static variables, storing
  149. what event happened. Then in the main loop of your program, call
  150. Fl::wait() and then check these variables, acting on them as though
  151. they are events read from \c fl_queue.
  152. \par You Must Use OpenGL to Draw Everything
  153. The file <FL/gl.h> defines replacements for a lot of IRISGL
  154. calls, translating them to OpenGL. There are much better translators
  155. available that you might want to investigate.
  156. \par You Cannot Make Forms Subclasses
  157. Programs that call \c fl_make_object or directly setting the
  158. handle routine will not compile. You have to rewrite them to use a
  159. subclass of Fl_Widget. It is important to note that the \c handle()
  160. method is not exactly the same as the \c handle() function of Forms.
  161. Where a Forms \c handle() returned non-zero, your \c handle() must
  162. call \c do_callback(). And your \c handle() must return non-zero
  163. if it "understood" the event.
  164. An attempt has been made to emulate the "free" widget. This appears
  165. to work quite well. It may be quicker to modify your subclass into a
  166. "free" widget, since the "handle" functions match.
  167. If your subclass draws into the overlay you are in trouble and will
  168. have to rewrite things a lot.
  169. \par You Cannot Use <device.h>
  170. If you have written your own "free" widgets you will probably get a
  171. lot of errors about "getvaluator". You should substitute:
  172. <CENTER>
  173. <TABLE border=1 WIDTH=90% summary="Mapping of Forms valuators to FLTK.">
  174. <TR><TH align=center>Forms</TH><TH align=center>FLTK</TH></TR>
  175. <TR><TD>MOUSE_X</TD><TD>Fl::event_x_root()</TD></TR>
  176. <TR><TD>MOUSE_Y</TD><TD>Fl::event_y_root()</TD></TR>
  177. <TR><TD>LEFTSHIFTKEY,RIGHTSHIFTKEY</TD><TD>Fl::event_shift()</TD></TR>
  178. <TR><TD>CAPSLOCKKEY</TD><TD>Fl::event_capslock()</TD></TR>
  179. <TR><TD>LEFTCTRLKEY,RIGHTCTRLKEY</TD><TD>Fl::event_ctrl()</TD></TR>
  180. <TR><TD>LEFTALTKEY,RIGHTALTKEY</TD><TD>Fl::event_alt()</TD></TR>
  181. <TR><TD>MOUSE1,RIGHTMOUSE</TD><TD>Fl::event_state()</TD></TR>
  182. <TR><TD>MOUSE2,MIDDLEMOUSE</TD><TD>Fl::event_state()</TD></TR>
  183. <TR><TD>MOUSE3,LEFTMOUSE</TD><TD>Fl::event_state()</TD></TR>
  184. </TABLE>
  185. </CENTER>
  186. Anything else in \c getvaluator and you are on your own...
  187. \par Font Numbers Are Different
  188. The "style" numbers have been changed because I wanted to insert
  189. bold-italic versions of the normal fonts. If you use Times, Courier,
  190. or Bookman to display any text you will get a different font out of
  191. FLTK. If you are really desperate to fix this use the following code:
  192. \code
  193. fl_font_name(3,"*courier-medium-r-no*");
  194. fl_font_name(4,"*courier-bold-r-no*");
  195. fl_font_name(5,"*courier-medium-o-no*");
  196. fl_font_name(6,"*times-medium-r-no*");
  197. fl_font_name(7,"*times-bold-r-no*");
  198. fl_font_name(8,"*times-medium-i-no*");
  199. fl_font_name(9,"*bookman-light-r-no*");
  200. fl_font_name(10,"*bookman-demi-r-no*");
  201. fl_font_name(11,"*bookman-light-i-no*");
  202. \endcode
  203. \htmlonly
  204. <hr>
  205. <table summary="navigation bar" width="100%" border="0">
  206. <tr>
  207. <td width="45%" align="LEFT">
  208. <a class="el" href="glut.html">
  209. [Prev]
  210. GLUT Compatibility
  211. </a>
  212. </td>
  213. <td width="10%" align="CENTER">
  214. <a class="el" href="index.html">[Index]</a>
  215. </td>
  216. <td width="45%" align="RIGHT">
  217. <a class="el" href="osissues.html">
  218. Operating System Issues
  219. [Next]
  220. </a>
  221. </td>
  222. </tr>
  223. </table>
  224. \endhtmlonly
  225. */