From ddb75b40b3cc2d8e43cf1bf4ec537d0fec172a9e Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Thu, 30 Sep 2004 02:26:57 +0000
Subject: [PATCH] slightly better solution for the file picker focus

---
 Fltk/File_Picker.h | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/Fltk/File_Picker.h b/Fltk/File_Picker.h
index 83ed328e17..c4003094ce 100644
--- a/Fltk/File_Picker.h
+++ b/Fltk/File_Picker.h
@@ -22,26 +22,38 @@
 
 #include <FL/Fl_File_Chooser.H>
 #include <FL/Fl_Window.H>
+#include <FL/Fl_File_Input.H>
 
 // The FLTK team doesn't want to add a position() method to the file
 // chooser, so we have to derive our own. To make things worse, the 
 // original file chooser doesn't expose its window to the world, so
-// we need to use a cheap hack to get to it. Even worse, there is no
-// way we can call get_focus() on the file input widget, which is also
-// private. Sigh...
+// we need to use a cheap hack to get to it. Even worse is the hack
+// used to get the focus on the file input widget. Sigh...
 
 class File_Picker : public Fl_File_Chooser {
 private:
   Fl_Window *_win;
+  Fl_File_Input *_in;
 public:
   File_Picker(const char *d, const char *p, int t, const char *title)
     : Fl_File_Chooser(d, p, t, title) { 
-    _win = (Fl_Window*)newButton->parent()->parent(); 
+    _win = dynamic_cast<Fl_Window*>(newButton->parent()->parent()); 
+    _in = dynamic_cast<Fl_File_Input *>(previewButton->parent()->parent()->resizable());
   }
-  void show(){ _win->show(); _win->take_focus();}
-  void position(int x, int y){ _win->position(x,y);}
-  int x(){ return _win->x();}
-  int y(){ return _win->y();}
+  void show(){
+    if(_win){
+      _win->show();
+      if(_in)
+	_in->take_focus();
+      else
+	_win->take_focus();	
+    }
+    else
+      Fl_File_Chooser::show();
+  }
+  void position(int x, int y){ if(_win) _win->position(x,y); }
+  int x(){ if(_win) return _win->x(); else return 100; }
+  int y(){ if(_win) return _win->y(); else return 100; }
 };
 
 #endif
-- 
GitLab