Commits

ryanackley  committed d11c545 Merge
  • Participants
  • Parent commits b62f057, f6124d3

Comments (0)

Files changed (5)

File Win/DialogManagerWin.cpp

     static DialogManagerWin inst;
     return &inst;
 }
+void DialogManagerWin::OpenFileDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb) {
+	_showDialog(FALSE, host, win, cb);
+}
 
 void DialogManagerWin::OpenFolderDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb) {
-    FB::PluginWindowWin* wndWin = dynamic_cast<FB::PluginWindowWin*>(win);
+    _showDialog(TRUE, host, win, cb);
+}
+
+void DialogManagerWin::_showDialog(const BOOL isFolder, const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb) {
+	/*FB::PluginWindowWin* wndWin = dynamic_cast<FB::PluginWindowWin*>(win);
     FB::PluginWindowlessWin* wndlessWin = dynamic_cast<FB::PluginWindowlessWin*>(win);
 
-    HWND browserWindow = wndWin ? wndWin->getBrowserHWND() : wndlessWin->getHWND();
-    boost::thread dlgThread(&DialogManagerWin::_showFolderDialog, this, browserWindow, cb);
+    HWND browserWindow = wndWin ? wndWin->getBrowserHWND() : wndlessWin->getHWND();*/
+	HWND browserWindow = GetForegroundWindow();
+	if(isFolder)
+	{
+		boost::thread dlgThread(&DialogManagerWin::_showFolderDialog, this, browserWindow, cb);
+	}
+	else
+	{
+		boost::thread dlgThread(&DialogManagerWin::_showFileDialog, this, browserWindow, cb);
+	}
 }
 
 void DialogManagerWin::_showFolderDialog(HWND wnd, const PathCallback& cb) {
         cb("");
     }
 }
-void DialogManagerWin::_showFileDialog(HWND wnd, const std::string& path, const std::string& filter, const PathCallback& cb)
+void DialogManagerWin::_showFileDialog(HWND wnd,const PathCallback& cb)
 {
-    wchar_t Filestring[256];
+    wchar_t Filestring[4096];
     std::string out;
 
-    std::wstring wFilter(FB::utf8_to_wstring(filter));
-    std::wstring wPath(FB::utf8_to_wstring(filter));
+    //std::wstring wFilter(FB::utf8_to_wstring(filter));
+    //std::wstring wPath(FB::utf8_to_wstring(filter));
 
     OPENFILENAME opf;
     opf.hwndOwner = wnd;
-    opf.lpstrFilter = wFilter.c_str();
+    opf.lpstrFilter = NULL;
     opf.lpstrCustomFilter = 0;
     opf.nMaxCustFilter = 0L;
     opf.nFilterIndex = 1L;
     opf.lpstrFile = Filestring;
     opf.lpstrFile[0] = '\0';
-    opf.nMaxFile = 256;
+    opf.nMaxFile = 4096;
     opf.lpstrFileTitle = 0;
     opf.nMaxFileTitle=50;
-    opf.lpstrInitialDir = wPath.c_str();
-    opf.lpstrTitle = L"Choose directory to import";
+    opf.lpstrInitialDir = NULL;
+    opf.lpstrTitle = L"Select file";
     opf.nFileOffset = 0;
     opf.nFileExtension = 0;
     opf.lpstrDefExt = L"*.*";

File Win/DialogManagerWin.h

 {
 public:
     void OpenFolderDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb);
+	void OpenFileDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb);
 
 protected:
     DialogManagerWin() {};
     ~DialogManagerWin() {};
-    void _showFileDialog(HWND wnd, const std::string& path, const std::string& filter, const PathCallback& cb);
+    void _showFileDialog(HWND wnd, const PathCallback& cb);
     void _showFolderDialog(HWND wnd, const PathCallback& cb);
+	void _showDialog(const BOOL isFolder, const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb);
     friend class DialogManager;
 };
 #endif // DialogManagerWin_h__

File X11/DialogManagerX11.cpp

 #include <string>
 #include <boost/thread.hpp>
 #include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+
+
 
 #include "DialogManagerX11.h"
 #include "BrowserHost.h"
 
 void DialogManagerX11::OpenFolderDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb)
 {
-    host->ScheduleOnMainThread(boost::shared_ptr<DialogManagerX11>(), boost::bind(&DialogManagerX11::_showFolderDialog, this, win, cb));
+    host->ScheduleOnMainThread(boost::shared_ptr<DialogManagerX11>(), boost::bind(&DialogManagerX11::_showFolderDialog, this,false, win, cb));
+}
+
+void DialogManagerX11::OpenFileDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb)
+{
+	host->ScheduleOnMainThread(boost::shared_ptr<DialogManagerX11>(), boost::bind(&DialogManagerX11::_showFolderDialog, this, true, win, cb));
 }
 
-void DialogManagerX11::_showFolderDialog(FB::PluginWindow* win, const PathCallback& cb)
+Window DialogManagerX11::getActiveWindow()
+{
+	Display* d = XOpenDisplay(NULL);
+	if(d == NULL){
+		return None;
+	}
+	Window w;
+	int revert_to;
+	//printf("getting input focus window ... ");
+	XGetInputFocus(d, &w, &revert_to); // see man
+	if(w == None){
+		return None;
+	}
+
+
+	Window parent = w;
+	Window root = None;
+	Window *children;
+	unsigned int nchildren;
+	Status s;
+
+	//printf("getting top window ... \n");
+	while (parent != root) {
+		w = parent;
+		s = XQueryTree(d, w, &root, &parent, &children, &nchildren); // see man
+
+		if (s)
+			XFree(children);
+	}
+
+	return w;
+}
+
+void DialogManagerX11::_showFolderDialog(bool forFile, FB::PluginWindow* win, const PathCallback& cb)
 {
     std::string out;
     GtkWidget *dialog;
     dialog = gtk_file_chooser_dialog_new ("Open File",
 				      NULL,
-				      GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+				      forFile ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
 				      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 				      GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
 				      NULL);
+    gtk_widget_realize(dialog);
+    GdkWindow* gdk_window = gtk_widget_get_window(dialog);
+    Window w = getActiveWindow();
+    if (w != None)
+    {
+		XSetTransientForHint(GDK_WINDOW_XDISPLAY(gdk_window),
+							   GDK_WINDOW_XID(gdk_window),
+							   w);
+    }
     if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
     {
         char *filename;

File X11/DialogManagerX11.h

 
 #include <boost/noncopyable.hpp>
 #include <string>
+#include <X11/Xlib.h>           // `apt-get install libx11-dev`
+#include <X11/Xmu/WinUtil.h>
 
 #include "../DialogManager.h"
 
 {
 public:
     void OpenFolderDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb);
-    void _showFolderDialog(FB::PluginWindow* win, const PathCallback& cb);
+    void OpenFileDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb);
+    void _showFolderDialog(bool forFile, FB::PluginWindow* win, const PathCallback& cb);
     
 protected:
     DialogManagerX11() {};
     ~DialogManagerX11() {};
     friend class DialogManager;
+private:
+    Window getActiveWindow();
 };
 #endif // DialogManagerX11_h__

File X11/projectDef.cmake

 # add library dependencies here; leave ${PLUGIN_INTERNAL_DEPS} there unless you know what you're doing!
 target_link_libraries(${PROJECT_NAME}
     ${PLUGIN_INTERNAL_DEPS}
+    X11
     )