Commit 26bbb85e authored by Jesse van den Kieboom's avatar Jesse van den Kieboom

Make GeditAppX11, GeditAppOSX and GeditAppWin32

This specializes GeditApp for each (native) platform, implemeting
relevant bits specific to each platform.
parent e48b6d9a
......@@ -112,6 +112,8 @@ fi
AC_MSG_RESULT([$os_osx])
AM_CONDITIONAL(OS_OSX, test "$os_osx" = "yes")
AM_CONDITIONAL(GDK_WINDOWING_X11, test "$gdk_windowing" = "x11")
if test "$platform_osx" = "yes"; then
AC_DEFINE([PLATFORM_OSX],[1],[Defined if platform is Mac OSX])
fi
......@@ -520,7 +522,6 @@ docs/Makefile
docs/reference/Makefile
gedit/dialogs/Makefile
gedit/smclient/Makefile
gedit/osx/Makefile
gedit/Makefile
help/Makefile
pixmaps/Makefile
......
## Process this file with automake to produce Makefile.in
SUBDIRS = dialogs smclient
if OS_OSX
SUBDIRS += osx
endif
bin_PROGRAMS = gedit
noinst_LTLIBRARIES = libgedit.la
......@@ -18,18 +14,15 @@ INCLUDES = \
$(WARN_CFLAGS) \
$(DISABLE_DEPRECATED_CFLAGS) \
-DDATADIR=\""$(datadir)"\" \
-DLIBDIR=\""$(libdir)"\"
-DLIBDIR=\""$(libdir)"\"
gedit_SOURCES = \
gedit.c
gedit_LDADD = libgedit.la $(GEDIT_LIBS) $(IGE_MAC_LIBS) $(EGG_SMCLIENT_LIBS)
if PLATFORM_WIN32
gedit_LDFLAGS = -Wl,--export-all-symbols -Wl,--out-implib,libgedit-$(GEDIT_API_VERSION).a
if OS_WIN32
gedit_LDFLAGS += -mwindows
endif
else
gedit_LDFLAGS = -export-dynamic -no-undefined -export-symbols-regex "^[[^_]].*"
endif
......@@ -43,25 +36,60 @@ libgedit_la_LIBADD = \
# GEDIT_LIBS must be the last to ensure correct order on some platforms
libgedit_la_LIBADD += $(GEDIT_LIBS)
# Mac OSX convenience library and ldflags
if OS_OSX
gedit_LDFLAGS += -framework Carbon
libgedit_la_LIBADD += osx/libosx.la
endif
noinst_LTLIBRARIES += libosx.la
BUILT_SOURCES = \
gedit-enum-types.c \
gedit-enum-types.h \
gedit-marshal.c \
gedit-marshal.h
libosx_la_LDFLAGS = -framework Carbon -framework ApplicationServices -framework Cocoa
libosx_la_LIBADD = -lobjc
libosx_la_CFLAGS = -xobjective-c
libosx_la_SOURCES = \
gedit-app-osx.c \
gedit-app-osx.h \
gedit-osx-delegate.m \
gedit-osx-delegate.h
libgedit_la_LIBADD += libosx.la
endif
# Win32 convenience library and ldflags
if OS_WIN32
gedit_LDFLAGS += -mwindows
noinst_LTLIBRARIES += libwin32.la
libwin32_la_SOURCES = \
gedit-app-win32.c \
gedit-app-win32.h
libgedit_la_LIBADD += libwin32.la
gedit-res.o: gedit.rc
$(WINDRES) -i gedit.rc --input-format=rc -o gedit-res.o -O coff
gedit_LDADD += gedit-res.o
endif
# X11 convenience library
if GDK_WINDOWING_X11
noinst_LTLIBRARIES += libx11.la
libx11_la_SOURCES = \
gedit-app-x11.c \
gedit-app-x11.h
libgedit_la_LIBADD += libx11.la
endif
BUILT_SOURCES = \
gedit-enum-types.c \
gedit-enum-types.h \
gedit-marshal.c \
gedit-marshal.h
NOINST_H_FILES = \
gedit-close-button.h \
gedit-dirs.h \
......@@ -99,7 +127,6 @@ INST_H_FILES = \
gedit-encodings.h \
gedit-encodings-combo-box.h \
gedit-file-chooser-dialog.h \
gedit-help.h \
gedit-message-bus.h \
gedit-message-type.h \
gedit-message.h \
......@@ -125,7 +152,6 @@ headerdir = $(prefix)/include/gedit-@GEDIT_API_VERSION@/gedit
header_DATA = \
$(INST_H_FILES)
libgedit_la_SOURCES = \
$(BUILT_SOURCES) \
$(BACON_FILES) \
......@@ -150,7 +176,6 @@ libgedit_la_SOURCES = \
gedit-encodings.c \
gedit-encodings-combo-box.c \
gedit-file-chooser-dialog.c \
gedit-help.c \
gedit-history-entry.c \
gedit-io-error-message-area.c \
gedit-language-manager.c \
......@@ -186,7 +211,7 @@ libgedit_la_SOURCES = \
$(INST_H_FILES)
if !ENABLE_GVFS_METADATA
libgedit_la_SOURCES += gedit-metadata-manager.c
libgedit_la_SOURCES += gedit-metadata-manager.c
endif
gedit-enum-types.h: gedit-enum-types.h.template $(INST_H_FILES) $(GLIB_MKENUMS)
......
......@@ -43,7 +43,6 @@
#include "gedit-prefs-manager.h"
#include "gedit-utils.h"
#include "gedit-debug.h"
#include "gedit-help.h"
#include "gedit-dirs.h"
#define GEDIT_ENCODINGS_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \
......@@ -276,7 +275,11 @@ response_handler (GtkDialog *dialog,
{
if (response_id == GTK_RESPONSE_HELP)
{
gedit_help_display (GTK_WINDOW (dialog), "gedit", NULL);
gedit_app_show_help (gedit_app_get_default(),
GTK_WINDOW (dialog),
"gedit",
NULL);
g_signal_stop_emission_by_name (dialog, "response");
return;
}
......
......@@ -47,7 +47,6 @@
#include "gedit-document.h"
#include "gedit-style-scheme-manager.h"
#include "gedit-plugin-manager.h"
#include "gedit-help.h"
#include "gedit-dirs.h"
/*
......@@ -152,9 +151,10 @@ dialog_response_handler (GtkDialog *dlg,
switch (res_id)
{
case GTK_RESPONSE_HELP:
gedit_help_display (GTK_WINDOW (dlg),
NULL,
"gedit-prefs");
gedit_app_show_help (gedit_app_get_default (),
GTK_WINDOW (dlg),
NULL,
"gedit-prefs");
g_signal_stop_emission_by_name (dlg, "response");
......
#include "gedit-osx.h"
#include "gedit-app-osx.h"
#include <gdk/gdkquartz.h>
#include <Carbon/Carbon.h>
#import "gedit-osx-delegate.h"
void
gedit_osx_set_window_title (GeditWindow *window,
gchar const *title,
GeditDocument *document)
G_DEFINE_TYPE (GeditAppOSX, gedit_app_osx, GEDIT_TYPE_APP)
static void
gedit_app_osx_finalize (GObject *object)
{
G_OBJECT_CLASS (gedit_app_osx_parent_class)->finalize (object);
}
static gboolean
gedit_app_osx_last_window_destroyed_impl (GeditApp *app)
{
if (!GPOINTER_TO_INT (g_object_get_data (G_OBJECT (window), "gedit-is-quitting-all")))
{
/* Create hidden proxy window on OS X to handle the menu */
gedit_app_create_window (app, NULL);
return FALSE;
}
return GEDIT_APP_CLASS (gedit_app_osx_parent_class)->last_window_destroyed (app);
}
static gboolean
gedit_app_osx_show_url (GeditAppOSX *app,
const gchar *url)
{
return [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithUTF8String:url]]];
}
static gboolean
gedit_app_osx_show_help_impl (GeditApp *app,
GtkWindow *parent,
const gchar *name,
const gchar *link_id)
{
gboolean ret = FALSE;
if (name == NULL || strcmp(name, "gedit.xml") == NULL || strcmp(name, "gedit") == 0)
{
gchar *link;
if (link_id)
{
link = g_strdup_printf ("http://library.gnome.org/users/gedit/stable/%s",
link_id);
}
else
{
link = g_strdup ("http://library.gnome.org/users/gedit/stable/");
}
ret = gedit_osx_show_url (link);
g_free (link);
}
return ret;
}
static void
gedit_app_osx_set_window_title_impl (GeditApp *app,
GeditWindow *window,
const gchar *title)
{
NSWindow *native;
GeditDocument *document;
g_return_if_fail (GEDIT_IS_WINDOW (window));
......@@ -19,6 +78,7 @@ gedit_osx_set_window_title (GeditWindow *window,
}
native = gdk_quartz_window_get_nswindow (GTK_WIDGET (window)->window);
document = gedit_app_get_active_document (app);
if (document)
{
......@@ -45,35 +105,19 @@ gedit_osx_set_window_title (GeditWindow *window,
[native setDocumentEdited:false];
}
gtk_window_set_title (GTK_WINDOW (window), title);
}
gboolean
gedit_osx_show_url (const gchar *url)
{
return [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithUTF8String:url]]];
GEDIT_APP (gedit_app_osx_parent_class)->set_window_title (app, window, title);
}
gboolean
gedit_osx_show_help (const gchar *link_id)
static void
gedit_app_osx_class_init (GeditAppOSXClass *klass)
{
gchar *link;
gboolean ret;
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GeditAppClass *app_class = GEDIT_APP_CLASS (klass);
if (link_id)
{
link = g_strdup_printf ("http://library.gnome.org/users/gedit/stable/%s",
link_id);
}
else
{
link = g_strdup ("http://library.gnome.org/users/gedit/stable/");
}
object_class->finalize = gedit_app_osx_finalize;
ret = gedit_osx_show_url (link);
g_free (link);
return ret;
app_class->last_window_destroyed = gedit_app_osx_last_window_destroyed_impl;
app_class->show_help = gedit_app_show_help_impl;
}
static void
......@@ -82,15 +126,17 @@ destroy_delegate (GeditOSXDelegate *delegate)
[delegate dealloc];
}
void
gedit_osx_init(GeditApp *app)
static void
gedit_app_osx_init (GeditAppOSX *self)
{
GeditOSXDelegate *delegate = [[GeditOSXDelegate alloc] init];
g_object_set_data_full (G_OBJECT (app),
"GeditOSXDelegate",
delegate,
(GDestroyNotify)destroy_delegate);
ige_mac_menu_set_global_key_handler_enabled (FALSE);
}
/* ex:ts=8:noet: */
#ifndef __GEDIT_APP_OSX_H__
#define __GEDIT_APP_OSX_H__
#include "gedit-app.h"
#include <ige-mac-integration.h>
G_BEGIN_DECLS
#define GEDIT_TYPE_APP_OSX (gedit_app_osx_get_type ())
#define GEDIT_APP_OSX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_APP_OSX, GeditAppOSX))
#define GEDIT_APP_OSX_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_APP_OSX, GeditAppOSX const))
#define GEDIT_APP_OSX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEDIT_TYPE_APP_OSX, GeditAppOSXClass))
#define GEDIT_IS_APP_OSX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_APP_OSX))
#define GEDIT_IS_APP_OSX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_APP_OSX))
#define GEDIT_APP_OSX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEDIT_TYPE_APP_OSX, GeditAppOSXClass))
typedef struct _GeditAppOSX GeditAppOSX;
typedef struct _GeditAppOSXClass GeditAppOSXClass;
typedef struct _GeditAppOSXPrivate GeditAppOSXPrivate;
struct _GeditAppOSX {
GeditApp parent;
};
struct _GeditAppOSXClass {
GeditAppClass parent_class;
};
GType gedit_app_osx_get_type (void) G_GNUC_CONST;
void gedit_app_osx_set_window_title (GeditAppOSX *app, GeditWindow *window, const gchar *title, GeditDocument *document);
gboolean gedit_app_osx_show_url (GeditAppOSX *app, const gchar *url);
gboolean gedit_app_osx_show_help (GeditAppOSX *app, const gchar *link_id);
G_END_DECLS
#endif /* __GEDIT_APP_OSX_H__ */
/* ex:ts=8:noet: */
#include "gedit-app-win32.h"
#define SAVE_DATADIR DATADIR
#undef DATADIR
#include <io.h>
#include <conio.h>
#define _WIN32_WINNT 0x0500
#include <windows.h>
#define DATADIR SAVE_DATADIR
#undef SAVE_DATADIR
G_DEFINE_TYPE (GeditAppWin32, gedit_app_win32, GEDIT_TYPE_APP)
static void
gedit_app_win32_finalize (GObject *object)
{
G_OBJECT_CLASS (gedit_app_win32_parent_class)->finalize (object);
}
static gchar *
gedit_app_win32_help_link_id_impl (GeditApp *app,
const gchar *name,
const gchar *link_id)
{
if (link_id)
{
return g_strdup_printf ("http://library.gnome.org/users/gedit/stable/%s",
link_id);
}
else
{
return g_strdup ("http://library.gnome.org/users/gedit/stable/");
}
}
static void
gedit_app_win32_class_init (GeditAppWin32Class *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GeditAppClass *app_class = GEDIT_APP_CLASS (klass);
object_class->finalize = gedit_app_win32_finalize;
app_class->help_link_id = gedit_app_win32_help_link_id_impl;
}
static void
setup_path (void)
{
gchar *path;
gchar *installdir;
gchar *bin;
installdir = g_win32_get_package_installation_directory_of_module (NULL);
bin = g_build_filename (installdir, "bin", NULL);
g_free (installdir);
/* Set PATH to include the gedit executable's folder */
path = g_build_path (";", bin, g_getenv ("PATH"), NULL);
g_free (bin);
if (!g_setenv ("PATH", path, TRUE))
{
g_warning ("Could not set PATH for gedit");
}
g_free (path);
}
static void
prep_console (void)
{
/* If we open gedit from a console get the stdout printing */
if (fileno (stdout) != -1 &&
_get_osfhandle (fileno (stdout)) != -1)
{
/* stdout is fine, presumably redirected to a file or pipe */
}
else
{
typedef BOOL (* WINAPI AttachConsole_t) (DWORD);
AttachConsole_t p_AttachConsole =
(AttachConsole_t) GetProcAddress (GetModuleHandle ("kernel32.dll"),
"AttachConsole");
if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS))
{
freopen ("CONOUT$", "w", stdout);
dup2 (fileno (stdout), 1);
freopen ("CONOUT$", "w", stderr);
dup2 (fileno (stderr), 2);
}
}
}
static void
gedit_app_win32_init (GeditAppWin32 *self)
{
setup_path ();
prep_console ();
}
/* ex:ts=8:noet: */
/*
* gedit-win32.h
* This file is part of gedit
*
* Copyright (C) 2010 - Jesse van den Kieboom
*
* gedit is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* gedit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gedit; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef __GEDIT_APP_WIN32_H__
#define __GEDIT_APP_WIN32_H__
#include "gedit-app.h"
G_BEGIN_DECLS
#define GEDIT_TYPE_APP_WIN32 (gedit_app_win32_get_type ())
#define GEDIT_APP_WIN32(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_APP_WIN32, GeditAppWin32))
#define GEDIT_APP_WIN32_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_APP_WIN32, GeditAppWin32 const))
#define GEDIT_APP_WIN32_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEDIT_TYPE_APP_WIN32, GeditAppWin32Class))
#define GEDIT_IS_APP_WIN32(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_APP_WIN32))
#define GEDIT_IS_APP_WIN32_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_APP_WIN32))
#define GEDIT_APP_WIN32_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEDIT_TYPE_APP_WIN32, GeditAppWin32Class))
typedef struct _GeditAppWin32 GeditAppWin32;
typedef struct _GeditAppWin32Class GeditAppWin32Class;
typedef struct _GeditAppWin32Private GeditAppWin32Private;
struct _GeditAppWin32 {
GeditApp parent;
};
struct _GeditAppWin32Class {
GeditAppClass parent_class;
};
GType gedit_app_win32_get_type (void) G_GNUC_CONST;
G_END_DECLS
#endif /* __GEDIT_APP_WIN32_H__ */
/* ex:ts=8:noet: */
#include "gedit-app-x11.h"
#define GEDIT_APP_X11_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GEDIT_TYPE_APP_X11, GeditAppX11Private))
G_DEFINE_TYPE (GeditAppX11, gedit_app_x11, GEDIT_TYPE_APP)
static void
gedit_app_x11_finalize (GObject *object)
{
G_OBJECT_CLASS (gedit_app_x11_parent_class)->finalize (object);
}
static void
gedit_app_x11_class_init (GeditAppX11Class *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gedit_app_x11_finalize;
}
static void
gedit_app_x11_init (GeditAppX11 *self)
{
}
/* ex:ts=8:noet: */
#ifndef __GEDIT_APP_X11_H__
#define __GEDIT_APP_X11_H__
#include "gedit-app.h"
G_BEGIN_DECLS
#define GEDIT_TYPE_APP_X11 (gedit_app_x11_get_type ())
#define GEDIT_APP_X11(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_APP_X11, GeditAppX11))
#define GEDIT_APP_X11_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_APP_X11, GeditAppX11 const))
#define GEDIT_APP_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEDIT_TYPE_APP_X11, GeditAppX11Class))
#define GEDIT_IS_APP_X11(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_APP_X11))
#define GEDIT_IS_APP_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_APP_X11))
#define GEDIT_APP_X11_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEDIT_TYPE_APP_X11, GeditAppX11Class))
typedef struct _GeditAppX11 GeditAppX11;
typedef struct _GeditAppX11Class GeditAppX11Class;
typedef struct _GeditAppX11Private GeditAppX11Private;
struct _GeditAppX11 {
GeditApp parent;
};
struct _GeditAppX11Class {
GeditAppClass parent_class;
};
GType gedit_app_x11_get_type (void) G_GNUC_CONST;
G_END_DECLS
#endif /* __GEDIT_APP_X11_H__ */
/* ex:ts=8:noet: */
......@@ -48,7 +48,13 @@
#include "gseal-gtk-compat.h"
#ifdef OS_OSX
#include <ige-mac-integration.h>
#include "gedit-app-osx.h"
#else
#ifdef OS_WIN32
#include "gedit-app-win32.h"
#else
#include "gedit-app-x11.h"
#endif
#endif
#define GEDIT_PAGE_SETUP_FILE "gedit-page-setup"
......@@ -74,7 +80,7 @@ struct _GeditAppPrivate
GtkPrintSettings *print_settings;
};
G_DEFINE_TYPE(GeditApp, gedit_app, G_TYPE_OBJECT)
G_DEFINE_ABSTRACT_TYPE(GeditApp, gedit_app, G_TYPE_INITIALLY_UNOWNED)
static void
gedit_app_finalize (GObject *object)
......@@ -110,14 +116,135 @@ gedit_app_get_property (GObject *object,
}
}
static void
static void
app_weak_notify (gpointer data,
GObject *where_the_app_was)
{
gtk_main_quit ();
}
static GObject *
gedit_app_constructor (GType gtype,
guint n_construct_params,
GObjectConstructParam *construct_params)
{
static GObject *app = NULL;
if (!app)
{
app = G_OBJECT_CLASS (gedit_app_parent_class)->constructor (gtype,
n_construct_params,
construct_params);
g_object_add_weak_pointer (app, (gpointer *) &app);
g_object_weak_ref (app, app_weak_notify, NULL);
return app;
}
return g_object_ref (app);
}
static gboolean
gedit_app_last_window_destroyed_impl (GeditApp *app)
{
return TRUE;
}
static gchar *
gedit_app_help_link_id_impl (GeditApp *app,
const gchar *name,
const gchar *link_id)
{
if (link_id)
{
return g_strdup_printf ("ghelp:%s?%s", name, link_id);
}
else
{
return g_strdup_printf ("ghelp:%s", name);
}
}
static gboolean
gedit_app_show_help_impl (GeditApp *app,
GtkWindow *parent,
const gchar *name,
const gchar *link_id)
{
GError *error = NULL;
gboolean ret;
gchar *link;
if (name == NULL)
{
name = "gedit";
}
else if (strcmp (name, "gedit.xml") == 0)
{
g_warning ("%s: Using \"gedit.xml\" for the help name is deprecated, use \"gedit\" or simply NULL instead", G_STRFUNC);
name = "gedit";
}
link = GEDIT_APP_GET_CLASS (app)->help_link_id (app, name, link_id);
ret = gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (parent)),
link,
GDK_CURRENT_TIME,
&error);
g_free (link);
if (error != NULL)
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new (parent,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
_("There was an error displaying the help."));
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"%s", error->message);
g_signal_connect (G_OBJECT (dialog),
"response",
G_CALLBACK (gtk_widget_destroy),
NULL);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
gtk_widget_show (dialog);
g_error_free (error);
}
return ret;
}
static void
gedit_app_set_window_title_impl (GeditApp *app,
GeditWindow *window,
const gchar *title)
{
gtk_window_set_title (GTK_WINDOW (window), title);
}
static void
gedit_app_class_init (GeditAppClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gedit_app_finalize;
object_class->get_property = gedit_app_get_property;
object_class->constructor = gedit_app_constructor;
klass->last_window_destroyed = gedit_app_last_window_destroyed_impl;