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.

103 lines
3.3KB

  1. //
  2. // "$Id: Fl_compose.cxx 8626 2011-04-27 11:21:57Z manolo $"
  3. //
  4. // Character compose processing 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. #include <FL/Fl.H>
  28. #include <FL/x.H>
  29. #ifndef FL_DOXYGEN
  30. int Fl::compose_state = 0;
  31. #endif
  32. #if !defined(WIN32) && !defined(__APPLE__)
  33. extern XIC fl_xim_ic;
  34. #endif
  35. /** Any text editing widget should call this for each FL_KEYBOARD event.
  36. Use of this function is very simple.
  37. <p>If <i>true</i> is returned, then it has modified the
  38. Fl::event_text() and Fl::event_length() to a set of <i>bytes</i> to
  39. insert (it may be of zero length!). In will also set the "del"
  40. parameter to the number of <i>bytes</i> to the left of the cursor to
  41. delete, this is used to delete the results of the previous call to
  42. Fl::compose().
  43. <p>If <i>false</i> is returned, the keys should be treated as function
  44. keys, and del is set to zero. You could insert the text anyways, if
  45. you don't know what else to do.
  46. <p>Though the current implementation returns immediately, future
  47. versions may take quite awhile, as they may pop up a window or do
  48. other user-interface things to allow characters to be selected.
  49. */
  50. int Fl::compose(int& del) {
  51. // character composition is now handled by the OS
  52. del = 0;
  53. #if defined(__APPLE__)
  54. // this stuff is to be treated as a function key
  55. if(Fl::e_length == 0 || Fl::e_keysym == FL_Enter || Fl::e_keysym == FL_KP_Enter ||
  56. Fl::e_keysym == FL_Tab || Fl::e_keysym == FL_Escape || Fl::e_state&(FL_META | FL_CTRL) ) {
  57. return 0;
  58. }
  59. #elif defined(WIN32)
  60. unsigned char ascii = (unsigned)e_text[0];
  61. if ((e_state & (FL_ALT | FL_META)) && !(ascii & 128)) return 0;
  62. #else
  63. unsigned char ascii = (unsigned)e_text[0];
  64. if ((e_state & (FL_ALT | FL_META | FL_CTRL)) && !(ascii & 128)) return 0;
  65. #endif
  66. if(Fl::compose_state) {
  67. del = Fl::compose_state;
  68. Fl::compose_state = 0;
  69. #ifndef __APPLE__
  70. } else {
  71. // Only insert non-control characters:
  72. if (! (ascii & ~31 && ascii!=127)) { return 0; }
  73. #endif
  74. }
  75. return 1;
  76. }
  77. /**
  78. If the user moves the cursor, be sure to call Fl::compose_reset().
  79. The next call to Fl::compose() will start out in an initial state. In
  80. particular it will not set "del" to non-zero. This call is very fast
  81. so it is ok to call it many times and in many places.
  82. */
  83. void Fl::compose_reset()
  84. {
  85. Fl::compose_state = 0;
  86. #if !defined(WIN32) && !defined(__APPLE__)
  87. if (fl_xim_ic) XmbResetIC(fl_xim_ic);
  88. #endif
  89. }
  90. //
  91. // End of "$Id: Fl_compose.cxx 8626 2011-04-27 11:21:57Z manolo $"
  92. //