Author: manolo
Date: 2012-12-26 07:04:42 -0800 (Wed, 26 Dec 2012)
New Revision: 9778
Log:
Mac OS text input.

Modified:
   branches/branch-3.0/include/fltk3/SecretInput.h
   branches/branch-3.0/include/fltk3/osx.h
   branches/branch-3.0/include/fltk3/run.h
   branches/branch-3.0/src/fltk3/Input.cxx
   branches/branch-3.0/src/fltk3/Input_.cxx
   branches/branch-3.0/src/fltk3/TextDisplay.cxx
   branches/branch-3.0/src/fltk3/TextEditor.cxx
   branches/branch-3.0/src/fltk3/cocoa.mm
   branches/branch-3.0/src/fltk3/compose.cxx
   branches/branch-3.0/test1/device.cxx

Modified: branches/branch-3.0/include/fltk3/SecretInput.h
===================================================================
--- branches/branch-3.0/include/fltk3/SecretInput.h     2012-12-26 14:02:59 UTC 
(rev 9777)
+++ branches/branch-3.0/include/fltk3/SecretInput.h     2012-12-26 15:04:42 UTC 
(rev 9778)
@@ -52,6 +52,7 @@
      Inherited destructor destroys the widget and any value associated with it.
      */
     SecretInput(int X,int Y,int W,int H,const char *l = 0);
+    int handle(int);
   };
   
 }

Modified: branches/branch-3.0/include/fltk3/osx.h
===================================================================
--- branches/branch-3.0/include/fltk3/osx.h     2012-12-26 14:02:59 UTC (rev 
9777)
+++ branches/branch-3.0/include/fltk3/osx.h     2012-12-26 15:04:42 UTC (rev 
9778)
@@ -145,7 +145,8 @@
   static void *get_carbon_function(const char *name);
   static void screen_work_area(int &X, int &Y, int &W, int &H, int n); // 
compute work area of a given screen
   static unsigned short *compute_macKeyLookUp();
-  static void compose_state(int);
+  static int next_marked_length; // next length of marked text after current 
marked text will have been replaced
+  static int insertion_point_location(int *px, int *py); // computes window 
coordinates of insertion point
 private:
   static void relink(fltk3::Window*, fltk3::Window*);
   bool subwindow;

Modified: branches/branch-3.0/include/fltk3/run.h
===================================================================
--- branches/branch-3.0/include/fltk3/run.h     2012-12-26 14:02:59 UTC (rev 
9777)
+++ branches/branch-3.0/include/fltk3/run.h     2012-12-26 15:04:42 UTC (rev 
9778)
@@ -152,7 +152,12 @@
   extern fltk3::Window* grab_;
   extern int compose_state;
   void call_screen_init(); // recompute screen number and dimensions
+#ifdef __APPLE__
+  int marked_text_length(); // returns length of marked text
+  void reset_marked_text(); // resets marked text
+  void insertion_point_location(int x, int y); // sets window coordinates of 
insertion point
 #endif
+#endif
   /**
    If true then flush() will do something.
    */

Modified: branches/branch-3.0/src/fltk3/Input.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Input.cxx     2012-12-26 14:02:59 UTC (rev 
9777)
+++ branches/branch-3.0/src/fltk3/Input.cxx     2012-12-26 15:04:42 UTC (rev 
9778)
@@ -377,6 +377,11 @@
       else replace(position(), del ? position()-del : mark(),
                   fltk3::event_text(), fltk3::event_length());
     }
+#ifdef __APPLE__
+    if (fltk3::marked_text_length()) {
+      this->mark( this->position() - fltk3::marked_text_length() );
+    }
+#endif
     return 1;
   }
   
@@ -604,6 +609,14 @@
   static int dnd_save_position, dnd_save_mark, drag_start = -1, newpos;
   static fltk3::Widget *dnd_save_focus;
   switch (event) {
+#ifdef __APPLE__
+    case fltk3::UNFOCUS:
+      if (fltk3::marked_text_length()) {
+       this->mark( this->position() );
+       fltk3::reset_marked_text();
+      }
+      break;
+#endif
     case fltk3::FOCUS:
       switch (fltk3::event_key()) {
         case fltk3::RightKey:
@@ -636,7 +649,8 @@
           && !fltk3::event_state(fltk3::SHIFT)                 // no shift?
           && !tab_nav()                                        // with tab 
navigation disabled?
          && input_type() == fltk3::MULTILINE_INPUT             // with a 
multiline input?
-          && (mark()==0 && position()==size())) {      // while entire field 
selected?
+         && size() > 0                                 // non-empty field?
+          && ((mark()==0 && position()==size()) || (position()==0 && 
mark()==size()))) {// while entire field selected?
         // Set cursor to the end of the selection...
         if (mark() > position())
           position(mark());
@@ -828,7 +842,17 @@
   type(fltk3::SECRET_INPUT);
 }
 
+int fltk3::SecretInput::handle(int event) {
+  int retval = fltk3::Input::handle(event);
+#ifdef __APPLE__
+  if (event == fltk3::KEYBOARD && fltk3::marked_text_length()) {
+    this->mark( this->position() ); // don't underline marked text
+  }
+#endif
+  return retval;
+}
 
+
 //
 // End of "$Id$".
 //

Modified: branches/branch-3.0/src/fltk3/Input_.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Input_.cxx    2012-12-26 14:02:59 UTC (rev 
9777)
+++ branches/branch-3.0/src/fltk3/Input_.cxx    2012-12-26 15:04:42 UTC (rev 
9778)
@@ -351,8 +351,8 @@
       int offset2;
       if (pp <= e) x2 = xpos + (float)expandpos(p, pp, buf, &offset2);
       else offset2 = (int)strlen(buf);
-#ifdef __APPLE__ // Mac OS: underline marked ( = selected + Fl::compose_state 
!= 0) text 
-      if (fltk3::compose_state) {
+#ifdef __APPLE__ // Mac OS: underline marked ( = selected + 
fltk3::marked_text_length() != 0) text 
+      if (fltk3::marked_text_length()) {
         fltk3::color(textcolor());
       }
       else 
@@ -363,8 +363,8 @@
       fltk3::color(fltk3::contrast(textcolor(), selection_color()));
       }
       fltk3::draw(buf+offset1, offset2-offset1, x1, (float)(Y+ypos+desc));
-#ifdef __APPLE__ // Mac OS: underline marked ( = selected + Fl::compose_state 
!= 0) text
-      if (fltk3::compose_state) {
+#ifdef __APPLE__ // Mac OS: underline marked ( = selected + 
fltk3::marked_text_length() != 0) text
+      if (fltk3::marked_text_length()) {
         fltk3::color( fltk3::color_average(textcolor(), color(), 0.6) );
         float width = fltk3::width(buf+offset1, offset2-offset1);
         fltk3::line(x1, Y+ypos+height-1, x1+width, Y+ypos+height-1);
@@ -384,7 +384,11 @@
 
   CONTINUE2:
     // draw the cursor:
-    if (fltk3::focus() == this && (fltk3::compose_state || selstart == selend) 
&&
+    if (fltk3::focus() == this && (
+#ifdef __APPLE__
+                               fltk3::marked_text_length() || 
+#endif
+                               selstart == selend) &&
        position() >= p-value() && position() <= e-value()) {
       fltk3::color(cursor_color());
       // cursor position may need to be recomputed (see STR #2486)

Modified: branches/branch-3.0/src/fltk3/TextDisplay.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/TextDisplay.cxx       2012-12-26 14:02:59 UTC 
(rev 9777)
+++ branches/branch-3.0/src/fltk3/TextDisplay.cxx       2012-12-26 15:04:42 UTC 
(rev 9778)
@@ -1952,7 +1952,7 @@
     if (style & PRIMARY_MASK) {
       if (fltk3::focus() == (fltk3::Widget*)this) {
 #ifdef __APPLE__
-       if (fltk3::compose_state) background = color();// Mac OS: underline 
marked text
+       if (fltk3::marked_text_length()) background = color();// Mac OS: 
underline marked text
        else 
 #endif
          background = selection_color();
@@ -1988,8 +1988,8 @@
     fltk3::push_clip(X, Y, toX - X, mMaxsize);
 #endif
     fltk3::draw( string, nChars, X, Y + mMaxsize - fltk3::descent());
-#ifdef __APPLE__ // Mac OS: underline marked (= selected + Fl::compose_state 
!= 0) text
-    if (fltk3::compose_state && (style & PRIMARY_MASK)) {
+#ifdef __APPLE__ // Mac OS: underline marked (= selected + 
fltk3::marked_text_length() != 0) text
+    if (fltk3::marked_text_length() && (style & PRIMARY_MASK)) {
       fltk3::color( fltk3::color_average(foreground, background, 0.6) );
       fltk3::line(X, Y + mMaxsize - 1, X + fltk3::width(string, nChars), Y + 
mMaxsize - 1);
     }
@@ -3479,7 +3479,11 @@
   
   // draw the text cursor
   if (damage() & (fltk3::DAMAGE_ALL | fltk3::DAMAGE_SCROLL | 
fltk3::DAMAGE_EXPOSE)
-      && (fltk3::compose_state || !buffer()->primary_selection()->selected()) 
&&
+      && (
+#ifdef __APPLE__
+         fltk3::marked_text_length() ||
+#endif
+         !buffer()->primary_selection()->selected()) &&
       mCursorOn && fltk3::focus() == (fltk3::Widget*)this ) {
     fltk3::push_clip(text_area.x-LEFT_MARGIN,
                  text_area.y,

Modified: branches/branch-3.0/src/fltk3/TextEditor.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/TextEditor.cxx        2012-12-26 14:02:59 UTC 
(rev 9777)
+++ branches/branch-3.0/src/fltk3/TextEditor.cxx        2012-12-26 15:04:42 UTC 
(rev 9778)
@@ -536,6 +536,16 @@
       if (insert_mode()) insert(fltk3::event_text());
       else overstrike(fltk3::event_text());
     }
+#ifdef __APPLE__
+    if (fltk3::marked_text_length()) {
+      int x, y;
+      int pos = this->insert_position();
+      this->buffer()->select(pos - fltk3::marked_text_length(), pos);
+      this->position_to_xy( this->insert_position(), &x, &y);
+      y += this->textsize();
+      fltk3::insertion_point_location(x, y);
+    }
+#endif
     show_insert_position();
     set_changed();
     if (when()&fltk3::WHEN_CHANGED) do_callback();
@@ -573,6 +583,13 @@
 
     case fltk3::UNFOCUS:
       show_cursor(mCursorOn); // redraws the cursor
+#ifdef __APPLE__
+      if (buffer()->selected() && fltk3::marked_text_length()) {
+       int pos = insert_position();
+       buffer()->select(pos, pos);
+       fltk3::reset_marked_text();
+      }
+#endif
       if (buffer()->selected()) redraw(); // Redraw selections...
     case fltk3::HIDE:
       if (when() & fltk3::WHEN_RELEASE) maybe_do_callback();

Modified: branches/branch-3.0/src/fltk3/cocoa.mm
===================================================================
--- branches/branch-3.0/src/fltk3/cocoa.mm      2012-12-26 14:02:59 UTC (rev 
9777)
+++ branches/branch-3.0/src/fltk3/cocoa.mm      2012-12-26 15:04:42 UTC (rev 
9778)
@@ -1682,6 +1682,7 @@
 }
 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent
 {   
+  int handled = 1;
   //NSLog(@"performKeyEquivalent:");
   fl_lock_function();
   cocoaKeyboardHandler(theEvent);
@@ -1692,7 +1693,15 @@
     s = [s uppercaseString]; // US keyboards return lowercase letter in s if 
cmd-shift-key is hit
   }
   if ([s length] >= 1) [FLView prepareEtext:s];
-  int handled = fltk3::handle(fltk3::KEYBOARD, window);
+  if ( (mods & NSControlKeyMask) || (mods & NSCommandKeyMask) ) {
+    handled = fltk3::handle(fltk3::KEYBOARD, window);
+  }
+  else {
+    in_key_event = YES;
+    NSText *edit = [[theEvent window]  fieldEditor:YES forObject:nil];
+    [edit interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
+    in_key_event = NO;
+  }
   fl_unlock_function();
   return (handled ? YES : NO);
 }
@@ -1908,15 +1917,15 @@
   } else {
     received = (NSString*)aString;
   }
-  //NSLog(@"insertText: received=%@ fltk3::compose_state=%d",received, 
fltk3::compose_state);
+  //NSLog(@"insertText: received=%@ fltk3::marked_text_length()=%d",received, 
fltk3::marked_text_length());
 
   fl_lock_function();
   [FLView prepareEtext:received];
   // We can get called outside of key events (e.g., from the character 
palette, from CJK text input). 
   // Transform character palette actions to FL_PASTE events.
   fltk3::Window *target = [(FLWindow*)[self window] getFl_Window];
-  fltk3::handle( (in_key_event || fltk3::compose_state) ? fltk3::KEYBOARD : 
fltk3::PASTE, target);
-  Fl_X::compose_state(0);
+  Fl_X::next_marked_length = 0;
+  fltk3::handle( (in_key_event || fltk3::marked_text_length()) ? 
fltk3::KEYBOARD : fltk3::PASTE, target);
 
   // for some reason, with the palette, the window does not redraw until the 
next mouse move or button push
   // sending a 'redraw()' or 'awake()' does not solve the issue!
@@ -1935,17 +1944,17 @@
   // This code creates the OS X behaviour of seeing dead keys as things
   // are being composed.
   [FLView prepareEtext:received];
-  /*NSLog(@"setMarkedText:%@ %d %d fltk3::compose_state=%d 
fltk3::e_length=%d", 
-   received, newSelection.location, newSelection.length, fltk3::compose_state, 
fltk3::e_length);*/
+  /*NSLog(@"setMarkedText:%@ %d %d fltk3::marked_text_length()=%d 
fltk3::e_length=%d", 
+   received, newSelection.location, newSelection.length, 
fltk3::marked_text_length(), fltk3::e_length);*/
   fltk3::Window *target = [(FLWindow*)[self window] getFl_Window];
+  Fl_X::next_marked_length = fltk3::e_length;
   fltk3::handle(fltk3::KEYBOARD, target);
-  Fl_X::compose_state(fltk3::e_length);
   fl_unlock_function();
 }
 
 - (void)unmarkText {
   fl_lock_function();
-  Fl_X::compose_state(0);
+  fltk3::reset_marked_text();
   fl_unlock_function();
   //NSLog(@"unmarkText");
 }
@@ -1955,13 +1964,13 @@
 }
 
 - (NSRange)markedRange {
-  //NSLog(@"markedRange=%d %d", fltk3::compose_state > 0?0:NSNotFound, 
fltk3::compose_state);
-  return NSMakeRange(fltk3::compose_state > 0?0:NSNotFound, 
fltk3::compose_state);
+  //NSLog(@"markedRange=%d %d", fltk3::marked_text_length() > 0?0:NSNotFound, 
fltk3::marked_text_length());
+  return NSMakeRange(fltk3::marked_text_length() > 0?0:NSNotFound, 
fltk3::marked_text_length());
 }
 
 - (BOOL)hasMarkedText {
-  //NSLog(@"hasMarkedText %s", fltk3::compose_state > 0?"YES":"NO");
-  return (fltk3::compose_state > 0);
+  //NSLog(@"hasMarkedText %s", fltk3::marked_text_length() > 0?"YES":"NO");
+  return (fltk3::marked_text_length() > 0);
 }
 
 - (NSAttributedString *)attributedSubstringFromRange:(NSRange)aRange {
@@ -1982,23 +1991,20 @@
   if (!focus) focus = wfocus;
   glyphRect.size.width = 0;
   
-  fltk3::TextDisplay *current = dynamic_cast<fltk3::TextDisplay*>(focus);
-  if (current) {
-    int x, y;
-    current->position_to_xy( current->insert_position(), &x, &y );
+  int x, y;
+  if (Fl_X::insertion_point_location(&x, &y)) {
     glyphRect.origin.x = (CGFloat)x;
-    glyphRect.origin.y = (CGFloat)y + current->textsize();
-    glyphRect.size.height = current->textsize();
+    glyphRect.origin.y = (CGFloat)y;
   } else {
     glyphRect.origin.x = 0;
     glyphRect.origin.y = focus->h();
-    glyphRect.size.height = 12;
   }
-  fltk3::Widget *w = focus;
-  while (w->parent()) {
-    glyphRect.origin.x += w->x();
-    glyphRect.origin.y += w->y();
-    w = w->parent();
+  glyphRect.size.height = 12;
+  fltk3::Widget *win = focus;
+  while (win != NULL && win != wfocus) {
+    glyphRect.origin.x += win->x();
+    glyphRect.origin.y += win->y();
+    win = win->parent();
   }
   // Convert the rect to screen coordinates
   glyphRect.origin.y = wfocus->h() - glyphRect.origin.y;
@@ -2017,25 +2023,6 @@
 
 @end
 
-void Fl_X::compose_state(int new_val)
-{ // select marked text in text widgets
-  if (fltk3::compose_state == 0 && new_val == 0) return;
-  fltk3::compose_state = new_val;
-  fltk3::Widget *widget = fltk3::focus();
-  if (!widget) return;
-  
-  fltk3::Input_* input = dynamic_cast<fltk3::Input_*>(widget);
-  fltk3::TextDisplay* text;
-  if (input) {
-    if ( ! dynamic_cast<fltk3::SecretInput*>(input) ) 
-      input->mark( input->position() - fltk3::compose_state );
-  }
-  else if ( (text = dynamic_cast<fltk3::TextDisplay*>(widget)) ) {
-    int pos = text->insert_position();
-    text->buffer()->select(pos - fltk3::compose_state, pos);
-  }
-}
-
 void fltk3::Window::fullscreen_x() {
   _set_fullscreen();
   /* On OS X < 10.6, it is necessary to recreate the window. This is done

Modified: branches/branch-3.0/src/fltk3/compose.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/compose.cxx   2012-12-26 14:02:59 UTC (rev 
9777)
+++ branches/branch-3.0/src/fltk3/compose.cxx   2012-12-26 15:04:42 UTC (rev 
9778)
@@ -30,7 +30,10 @@
 
 #ifndef FLTK3_DOXYGEN
 int fltk3::compose_state = 0;
+#ifdef __APPLE__
+int Fl_X::next_marked_length = 0;
 #endif
+#endif
 
 #if !defined(WIN32) && !defined(__APPLE__)
 extern XIC fl_xim_ic;
@@ -50,6 +53,23 @@
  keys, and del is set to zero. You could insert the text anyways, if
  you don't know what else to do.
  
+ <p>On the Mac OS platform, text editing widgets should preferentially signal
+ marked text, that is, temporary text replaced by other text during the text 
+ input process. Such signaling is usually done underlining marked text. 
Widgets can call
+ <tt>int fltk3::marked_text_length()</tt> <i>after</i> having called 
fltk3::compose(int&)
+ to obtain the length in bytes of marked text that always finishes at the
+ current insertion point. It's the widget's task to underline marked text.
+ Widgets should also call <tt>void fltk3::reset_marked_text()</tt> when 
processing FL_UNFOCUS events.
+ Optionally, widgets can also call
+ <tt>void fltk3::insertion_point_location(int x, int y)</tt> to indicate the 
window 
+ coordinates of the bottom of the current insertion point. 
+ This way, auxiliary windows that help choosing among alternative characters 
+ appear just below the insertion point. If widgets don't do that, 
+ auxiliary windows appear at the widget's bottom. The
+ fltk3::Input and fltk3::TextEditor widgets signal marked text underlining it.
+ If none of this is done by a user-defined text editing widget, complex
+ (e.g., CJK) text input will work, but will not signal to the user what text 
is marked. 
+ 
  <p>Though the current implementation returns immediately, future
  versions may take quite awhile, as they may pop up a window or do
  other user-interface things to allow characters to be selected.
@@ -68,11 +88,13 @@
   condition = (e_state & (fltk3::ALT | fltk3::META)) && !(ascii & 128) ;
 #else
   condition = (e_state & (fltk3::ALT | fltk3::META | fltk3::CTRL)) && !(ascii 
& 128) ;
-#endif
-#endif
+#endif // WIN32
+#endif // __APPLE__
   if (condition) { del = 0; return 0;} // this stuff is to be treated as a 
function key
   del = fltk3::compose_state;
-#ifndef __APPLE__
+#ifdef __APPLE__
+  fltk3::compose_state = Fl_X::next_marked_length;
+#else
   fltk3::compose_state = 0;
   // Only insert non-control characters:
   if ( (!fltk3::compose_state) && ! (ascii & ~31 && ascii!=127)) { return 0; }
@@ -80,6 +102,35 @@
   return 1;
 }
 
+#ifdef __APPLE__
+int fltk3::marked_text_length() {
+  return (fltk3::compose_state ? fltk3::compose_state : 
Fl_X::next_marked_length);
+}
+
+static int insertion_point_x = 0;
+static int insertion_point_y = 0;
+static bool insertion_point_location_is_valid = false;
+
+void fltk3::reset_marked_text() {
+  fltk3::compose_state = 0;
+  Fl_X::next_marked_length = 0;
+  insertion_point_location_is_valid = false;
+}
+int Fl_X::insertion_point_location(int *px, int *py) 
+// return true if the current coordinates of the insertion point are available
+{
+  if ( ! insertion_point_location_is_valid ) return false;
+  *px = insertion_point_x;
+  *py = insertion_point_y;
+  return true;
+}
+void fltk3::insertion_point_location(int x, int y) {
+  insertion_point_location_is_valid = true;
+  insertion_point_x = x;
+  insertion_point_y = y;
+}
+#endif // __APPLE__
+
 /**
  If the user moves the cursor, be sure to call fltk3::compose_reset().
  The next call to fltk3::compose() will start out in an initial state. In
@@ -88,14 +139,10 @@
  */
 void fltk3::compose_reset()
 {
-#ifdef __APPLE__
-  Fl_X::compose_state(0);
-#else
   fltk3::compose_state = 0;
-#if !defined(WIN32)
+#if !defined(WIN32) && !defined(__APPLE__)
   if (fl_xim_ic) XmbResetIC(fl_xim_ic);
 #endif
-#endif
 }
 
 //

Modified: branches/branch-3.0/test1/device.cxx
===================================================================
--- branches/branch-3.0/test1/device.cxx        2012-12-26 14:02:59 UTC (rev 
9777)
+++ branches/branch-3.0/test1/device.cxx        2012-12-26 15:04:42 UTC (rev 
9778)
@@ -594,12 +594,19 @@
   }
 }
 
+#ifndef NO_PDF
+#include "pdf_or_ps.h"
+#endif
 
 void print(Fl_Widget *, void *w) {
     Fl_Widget * g = (Fl_Widget *)w;
- 
+#ifdef NO_PDF
   Fl_Printer * p = new Fl_Printer();
   if (!p->start_job(1)) {
+#else
+  Fl_PDF_File_Device* p = new Fl_PDF_File_Device();
+  if (!p->begin_document("/Users/mgouy/Desktop/test.pdf")) {
+#endif
     p->start_page();
     p->print_window(g->window());
     p->end_page();

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to