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