download bonobo-ui-win32.c
Language: C
Copyright: Copyright 2005 Novell, Inc.
LOC: 120
Project Info
libbonoboui
Server: Gnome
Type: cvs
...onoboui\libbonoboui\bonobo\
   .cvsignore
   bonobo-a11y.c
   bonobo-a11y.h
   bonobo-canvas-component.c
   bonobo-canvas-component.h
   bonobo-canvas-item.c
   bonobo-canvas-item.h
   bonobo-control-frame.c
   bonobo-control-frame.h
   bonobo-control-internal.h
   bonobo-control.c
   bonobo-control.h
   bonobo-dock-band.c
   bonobo-dock-band.h
   bonobo-dock-item-grip.c
   bonobo-dock-item-grip.h
   bonobo-dock-item.c
   bonobo-dock-item.h
   bonobo-dock-layout.c
   bonobo-dock-layout.h
   bonobo-dock.c
   bonobo-dock.h
   ...bo-embeddable-factory.h
   ...bo-file-selector-util.c
   ...bo-file-selector-util.h
   ...bo-insert-component.xpm
   bonobo-plug.c
   bonobo-plug.h
   bonobo-property-control.c
   bonobo-property-control.h
   bonobo-selector-widget.c
   bonobo-selector-widget.h
   bonobo-selector.c
   bonobo-selector.h
   bonobo-socket.c
   bonobo-socket.h
   bonobo-ui-component.c
   bonobo-ui-component.h
   bonobo-ui-config-widget.c
   bonobo-ui-config-widget.h
   bonobo-ui-container.c
   bonobo-ui-container.h
   bonobo-ui-engine-config.c
   bonobo-ui-engine-config.h
   bonobo-ui-engine-private.h
   bonobo-ui-engine.c
   bonobo-ui-engine.h
   bonobo-ui-init-gtk.c
   ...o-ui-internal-toolbar.c
   bonobo-ui-main.c
   bonobo-ui-main.h
   bonobo-ui-marshal-main.c
   bonobo-ui-marshal.list
   bonobo-ui-node-private.h
   bonobo-ui-node.c
   bonobo-ui-node.h
   bonobo-ui-preferences.c
   bonobo-ui-preferences.h
   bonobo-ui-private.h
   bonobo-ui-sync-keys.c
   bonobo-ui-sync-keys.h
   bonobo-ui-sync-menu.c
   bonobo-ui-sync-menu.h
   bonobo-ui-sync-status.c
   bonobo-ui-sync-status.h
   bonobo-ui-sync-toolbar.c
   bonobo-ui-sync-toolbar.h
   bonobo-ui-sync.c
   bonobo-ui-sync.h
   ...i-toolbar-button-item.c
   ...i-toolbar-button-item.h
   ...-toolbar-control-item.c
   ...-toolbar-control-item.h
   bonobo-ui-toolbar-item.c
   bonobo-ui-toolbar-item.h
   ...ui-toolbar-popup-item.c
   ...ui-toolbar-popup-item.h
   ...ar-toggle-button-item.c
   ...ar-toggle-button-item.h
   bonobo-ui-toolbar.c
   bonobo-ui-toolbar.h
   bonobo-ui-util.c
   bonobo-ui-util.h
   bonobo-ui-win32.c
   bonobo-ui-xml.c
   bonobo-ui-xml.h
   bonobo-widget.c
   bonobo-widget.h
   bonobo-window.c
   bonobo-window.h
   bonobo-wrapper.h
   bonobo-zoomable-frame.c
   bonobo-zoomable-frame.h
   bonobo-zoomable.c
   bonobo-zoomable.h
   ...i-2.0-uninstalled.pc.in
   libbonoboui-2.0.pc.in
   Makefile.am

/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/**
 * bonobo-ui-win32.c: Win32-specific code for libbonoboui
 *
 * Author:
 *    Tor Lillqvist  (tml@novell.com)
 *
 * Copyright 2005 Novell, Inc.
 */
#include <config.h>
#include <glib.h>

#ifdef G_OS_WIN32

#ifndef PIC
#error Must build as a DLL
#endif

#include <string.h>
#include <stdio.h>
#include <windows.h>

/* Silence gcc with a prototype */
BOOL WINAPI DllMain (HINSTANCE hinstDLL,
		     DWORD     fdwReason,
		     LPVOID    lpvReserved);

/* Ditto. We can't include bonobo-ui-private.h where the prototypes
 * are in this file.
 */
const char *_bonobo_ui_get_localedir (void);
const char *_bonobo_ui_get_datadir (void);
const char *_bonobo_ui_get_uidir (void);

static HMODULE hmodule;
G_LOCK_DEFINE_STATIC (mutex);

/* Using short filenames, in system codepage */
static char *_bonobo_localedir = NULL;

/* Using long filenames, in UTF-8 */
static char *_bonobo_datadir;
static char *_bonobo_uidir;

/* DllMain used to tuck away the DLL's HMODULE */
BOOL WINAPI
DllMain (HINSTANCE hinstDLL,
	 DWORD     fdwReason,
	 LPVOID    lpvReserved)
{
	switch (fdwReason) {
	case DLL_PROCESS_ATTACH:
		hmodule = hinstDLL;
		break;
	}
	return TRUE;
}

static char *
replace_prefix (const char *runtime_prefix,
		const char *configure_time_path)
{
	if (strncmp (configure_time_path, PREFIX "/", strlen (PREFIX) + 1) == 0) {
		return g_strconcat (runtime_prefix,
				    configure_time_path + strlen (PREFIX),
				    NULL);
	} else
		return g_strdup (configure_time_path);
}

static void
setup (void)
{
	char *full_prefix = NULL;  
	char *short_prefix = NULL; 
	char *p;

	G_LOCK (mutex);
	if (_bonobo_localedir != NULL) {
		G_UNLOCK (mutex);
		return;
	}

	if (GetVersion () < 0x80000000) {
		wchar_t wcbfr[1000];

		if (GetModuleFileNameW (hmodule, wcbfr,
					G_N_ELEMENTS (wcbfr))) {
			full_prefix = g_utf16_to_utf8 (wcbfr, -1,
						       NULL, NULL, NULL);
			if (GetShortPathNameW (wcbfr, wcbfr,
					       G_N_ELEMENTS (wcbfr)))
				short_prefix = g_utf16_to_utf8 (wcbfr, -1,
								NULL, NULL, NULL);
		}
	} else {
		char cpbfr[1000];
		if (GetModuleFileNameA (hmodule, cpbfr, G_N_ELEMENTS (cpbfr)))
			full_prefix = short_prefix =
				g_locale_to_utf8 (cpbfr, -1,
						  NULL, NULL, NULL);
	}

	if (full_prefix != NULL) {
		p = strrchr (full_prefix, '\\');
		if (p != NULL)
			*p = '\0';
		
		p = strrchr (full_prefix, '\\');
		if (p && (g_ascii_strcasecmp (p + 1, "bin") == 0))
			*p = '\0';
	} else {
		full_prefix = "";
	}
		
	if (short_prefix != NULL) {
		p = strrchr (short_prefix, '\\');
		if (p != NULL)
			*p = '\0';
			
		p = strrchr (short_prefix, '\\');
		if (p && (g_ascii_strcasecmp (p + 1, "bin") == 0))
			*p = '\0';
	} else {
		short_prefix = "";
	}

	_bonobo_localedir = replace_prefix (short_prefix, BONOBO_LOCALEDIR);
	p = _bonobo_localedir;
	_bonobo_localedir = g_locale_from_utf8 (_bonobo_localedir, -1,
						NULL, NULL, NULL);
	g_free (p);

	_bonobo_datadir = replace_prefix (full_prefix, BONOBO_DATADIR);
	_bonobo_uidir = replace_prefix (full_prefix, BONOBO_UIDIR);

	G_UNLOCK (mutex);
}

const char *
_bonobo_ui_get_localedir (void)
{
	setup ();
	return _bonobo_localedir;
}

const char *
_bonobo_ui_get_datadir (void)
{
	setup ();
	return _bonobo_datadir;
}

const char *
_bonobo_ui_get_uidir (void)
{
	setup ();
	return _bonobo_uidir;
}

#endif	/* G_OS_WIN32 */

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us