]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/gtkmisc.cpp
apply misc fixes from Markus Fischer and Rambetter
[xonotic/netradiant.git] / radiant / gtkmisc.cpp
index d8353fc620317be73b287d9342ab0dbf23b4a24f..6b54918018de2cdd0b2c8f6743426e6dda325b05 100644 (file)
@@ -81,7 +81,6 @@ void save_window_pos (GtkWidget *wnd, window_position_t& pos)
 #ifdef _WIN32
 void win32_get_window_pos(GtkWidget *widget, gint *x, gint *y)
 {
-  // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=913
   if ( g_PrefsDlg.m_bStartOnPrimMon ) {
     RECT rc;
     POINT point;
@@ -860,7 +859,7 @@ void dialog_button_callback( GtkWidget *widget, gpointer data ) {
   ret = (int*)g_object_get_data( G_OBJECT( parent ), "ret" );
 
   *loop = 0;
-  *ret = (int)data;
+  *ret = GPOINTER_TO_INT (data);
 }
 
 gint dialog_delete_callback (GtkWidget *widget, GdkEvent* event, gpointer data)
@@ -925,7 +924,7 @@ int WINAPI gtk_MessageBox (void *parent, const char* lpText, const char* lpCapti
 
   if (mode == MB_OK)
   {
-    w = gtk_button_new_with_label ("Ok");
+    w = gtk_button_new_with_label (_("Ok"));
     gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
     gtk_signal_connect (GTK_OBJECT (w), "clicked",
                         GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDOK));
@@ -938,7 +937,7 @@ int WINAPI gtk_MessageBox (void *parent, const char* lpText, const char* lpCapti
   }
   else if (mode ==  MB_OKCANCEL)
   {
-    w = gtk_button_new_with_label ("Ok");
+    w = gtk_button_new_with_label (_("Ok"));
     gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
     gtk_signal_connect (GTK_OBJECT (w), "clicked",
                         GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDOK));
@@ -947,7 +946,7 @@ int WINAPI gtk_MessageBox (void *parent, const char* lpText, const char* lpCapti
     gtk_widget_grab_default (w);
     gtk_widget_show (w);
 
-    w = gtk_button_new_with_label ("Cancel");
+    w = gtk_button_new_with_label (_("Cancel"));
     gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
     gtk_signal_connect (GTK_OBJECT (w), "clicked",
                         GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDCANCEL));
@@ -957,7 +956,7 @@ int WINAPI gtk_MessageBox (void *parent, const char* lpText, const char* lpCapti
   }
   else if (mode == MB_YESNOCANCEL)
   {
-    w = gtk_button_new_with_label ("Yes");
+    w = gtk_button_new_with_label (_("Yes"));
     gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
     gtk_signal_connect (GTK_OBJECT (w), "clicked",
                         GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDYES));
@@ -965,13 +964,13 @@ int WINAPI gtk_MessageBox (void *parent, const char* lpText, const char* lpCapti
     gtk_widget_grab_default (w);
     gtk_widget_show (w);
 
-    w = gtk_button_new_with_label ("No");
+    w = gtk_button_new_with_label (_("No"));
     gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
     gtk_signal_connect (GTK_OBJECT (w), "clicked",
                         GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDNO));
     gtk_widget_show (w);
 
-    w = gtk_button_new_with_label ("Cancel");
+    w = gtk_button_new_with_label (_("Cancel"));
     gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
     gtk_signal_connect (GTK_OBJECT (w), "clicked",
                         GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDCANCEL));
@@ -980,7 +979,7 @@ int WINAPI gtk_MessageBox (void *parent, const char* lpText, const char* lpCapti
   }
   else /* if (mode == MB_YESNO) */
   {
-    w = gtk_button_new_with_label ("Yes");
+    w = gtk_button_new_with_label (_("Yes"));
     gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
     gtk_signal_connect (GTK_OBJECT (w), "clicked",
                         GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDYES));
@@ -988,7 +987,7 @@ int WINAPI gtk_MessageBox (void *parent, const char* lpText, const char* lpCapti
     gtk_widget_grab_default (w);
     gtk_widget_show (w);
 
-    w = gtk_button_new_with_label ("No");
+    w = gtk_button_new_with_label (_("No"));
     gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
     gtk_signal_connect (GTK_OBJECT (w), "clicked",
                         GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDNO));
@@ -998,7 +997,7 @@ int WINAPI gtk_MessageBox (void *parent, const char* lpText, const char* lpCapti
 
   if (URL)
   {
-    w = gtk_button_new_with_label ("Go to URL");
+    w = gtk_button_new_with_label (_("Go to URL"));
     gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
     gtk_signal_connect (GTK_OBJECT (w), "clicked",
                         GTK_SIGNAL_FUNC (dialog_url_callback), NULL);
@@ -1038,7 +1037,7 @@ static void file_sel_callback (GtkWidget *widget, gpointer data)
   loop = (int*)g_object_get_data (G_OBJECT (parent), "loop");
   success = (bool*)g_object_get_data (G_OBJECT (parent), "success");
 
-  if ((int)data == IDOK)
+  if (GPOINTER_TO_INT (data) == IDOK)
     *success = true;
 
 #ifdef FILEDLG_DBG
@@ -1197,7 +1196,10 @@ private:
 
 };
 
-const char* file_dialog (void *parent, gboolean open, const char* title, const char* path, const char* pattern)
+/**
+ * @param[in] baseSubDir should have a trailing slash if not @c NULL
+ */
+const char* file_dialog (void *parent, gboolean open, const char* title, const char* path, const char* pattern, const char *baseSubDir)
 {
   // Gtk dialog
   GtkWidget* file_sel;
@@ -1290,6 +1292,7 @@ const char* file_dialog (void *parent, gboolean open, const char* title, const c
   else
   {
 #endif
+       char buf[PATH_MAX];
     // do that the Gtk way
     if (title == NULL)
       title = open ? _("Open File") : _("Save File");
@@ -1300,14 +1303,13 @@ const char* file_dialog (void *parent, gboolean open, const char* title, const c
     // we expect an actual path below, if the path is NULL we might crash
     if (!path || path[0] == '\0')
     {
-#ifdef _WIN32
-      path = "C:\\";
-#elif defined (__linux__) || defined (__APPLE__)
-      path = "/";
-#else
-      path = "/";
-#endif
-    }
+               strcpy(buf, g_pGameDescription->mEnginePath.GetBuffer());
+               strcat(buf, g_pGameDescription->mBaseGame.GetBuffer());
+               strcat(buf, "/");
+               if (baseSubDir)
+                       strcat(buf, baseSubDir);
+               path = buf;
+       }
 
     // alloc new path with extra char for dir separator
     new_path = new char[strlen(path)+1+1];
@@ -1320,16 +1322,13 @@ const char* file_dialog (void *parent, gboolean open, const char* title, const c
     *w = '\0';
 
 #ifdef FILEDLG_DBG
-    Sys_Printf("Done.\n");
-    Sys_Printf("Calling gtk_file_selection_new with title: %s...", title);
+       Sys_Printf("Done.\n");
+       Sys_Printf("Calling gtk_file_selection_new with title: %s...", title);
 #endif
-
     file_sel = gtk_file_selection_new (title);
-       gtk_file_selection_set_filename(GTK_FILE_SELECTION(file_sel), "/home/mattn/dev/ufoai/trunk/base/maps/");
-
 #ifdef FILEDLG_DBG
-    Sys_Printf("Done.\n");
-    Sys_Printf("Set the masks...");
+       Sys_Printf("Done.\n");
+       Sys_Printf("Set the masks...");
 #endif
 
 #if 0 //!\todo Add masks to GtkFileSelection in gtk-2.0
@@ -1380,7 +1379,7 @@ const char* file_dialog (void *parent, gboolean open, const char* title, const c
     if (new_path != NULL)
     {
 #ifdef FILEDLG_DBG
-      Sys_Printf("gtk_file_selection_set_filename... %p", file_sel);
+      Sys_Printf("gtk_file_selection_set_filename... %p (%s)", file_sel, new_path);
 #endif
       gtk_file_selection_set_filename (GTK_FILE_SELECTION (file_sel), new_path);
       delete[] new_path;
@@ -1475,8 +1474,9 @@ char* WINAPI dir_dialog (void *parent, const char* title, const char* path)
                       GTK_SIGNAL_FUNC (dialog_delete_callback), NULL);
   gtk_file_selection_hide_fileop_buttons (GTK_FILE_SELECTION (file_sel));
 
-  if (parent != NULL)
-    gtk_window_set_transient_for (GTK_WINDOW (file_sel), GTK_WINDOW (parent));
+       if ( parent != NULL ) {
+               gtk_window_set_transient_for( GTK_WINDOW( file_sel ), GTK_WINDOW( parent ) );
+       }
 
   gtk_widget_hide (GTK_FILE_SELECTION (file_sel)->file_list->parent);
 
@@ -1492,10 +1492,10 @@ char* WINAPI dir_dialog (void *parent, const char* title, const char* path)
   while (loop)
     gtk_main_iteration ();
 
-  filename = g_strdup(gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_sel)));
+  filename = g_strdup( gtk_file_selection_get_filename( GTK_FILE_SELECTION( file_sel ) ) );
 
-  gtk_grab_remove (file_sel);
-  gtk_widget_destroy (file_sel);
+  gtk_grab_remove( file_sel );
+  gtk_widget_destroy( file_sel );
 
   return filename;
 }