summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xCMakeLists.txt2
-rw-r--r--configure.in11
-rw-r--r--navit/attr_def.h1
-rw-r--r--navit/binding/Makefile.am7
-rw-r--r--navit/binding/win32/CMakeLists.txt9
-rw-r--r--navit/binding/win32/Makefile.am12
-rw-r--r--navit/binding/win32/binding_win32.c143
-rw-r--r--navit/binding/win32/binding_win32.h37
-rw-r--r--navit/binding/win32/tell_navit.c176
-rw-r--r--navit/graphics/win32/graphics_win32.c21
10 files changed, 418 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b82367c4..83cad502 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -62,6 +62,7 @@ add_module(gui/gtk "GTK libs not found" FALSE)
add_module(vehicle/gpsd "gpsd lib not found" FALSE)
add_module(vehicle/gypsy "gypsy lib not found" FALSE)
add_module(vehicle/maemo "Default" FALSE)
+add_module(binding/win32 "Default" FALSE)
add_module(binding/dbus "dbus-glib-1 not found" FALSE)
add_module(speech/dbus "dbus-glib-1 not found" FALSE)
add_module(speech/cmdline "neither system() nor CreateProcess() found" FALSE)
@@ -388,6 +389,7 @@ if(WIN32 OR WINCE)
set_with_reason(support/ezxml "Windows detected" TRUE)
set_with_reason(speech/espeak "Windows detected" TRUE)
set_with_reason(support/espeak "Windows detected" TRUE)
+ set_with_reason(binding/win32 "Windows detected" TRUE)
# vehicle_file is broken for windows. use vehicle_wince instead
# whicle_wince isn't buildable on non-CE windows ssytems
diff --git a/configure.in b/configure.in
index 5889831d..8ddc83cf 100644
--- a/configure.in
+++ b/configure.in
@@ -39,6 +39,7 @@ samplemap=yes; samplemap_reason=default
binding_dbus=yes; binding_dbus_reason=default
binding_dbus_use_system_bus=no
binding_python=yes; binding_python_reason=default
+binding_win32=no; binding_win32_reason=default
font_freetype=yes; font_freetype_reason=default
fontconfig=yes; fontconfig_reason=default
fribidi=yes; fribidi_reason=default
@@ -96,6 +97,7 @@ wince|mingw32ce|cegcc)
AC_DEFINE(HAVE_API_WIN32_BASE, 1, [Have Windows Base API])
AC_DEFINE(HAVE_API_WIN32_CE, 1, [Have Windows CE API])
AC_DEFINE(HAVE_PRAGMA_PACK, 1, [Have pragma pack])
+ binding_win32=yes; binding_win32_reason="host_os is wince"
gui_win32=yes; gui_win32_reason="host_os is wince"
graphics_win32=yes; graphics_win32_reason="host_os is wince"
vehicle_wince=yes; vehcile_wince_reason="host_os is wince"
@@ -107,6 +109,7 @@ mingw32)
win32=yes
AC_DEFINE(HAVE_API_WIN32_BASE, 1, [Have Windows Base API])
AC_DEFINE(HAVE_API_WIN32, 1, [Have Windows API])
+ binding_win32=yes; binding_win32_reason="host_os is mingw32"
gui_win32=yes; gui_win32_reason="host_os is mingw32"
graphics_win32=yes; graphics_win32_reason="host_os is mingw32"
speech_espeak=yes; speech_espeak_reason="host_os is mingw32"
@@ -683,6 +686,13 @@ AM_CONDITIONAL(SPEECH_DBUS, test "x${speech_dbus}" = "xyes")
AC_ARG_WITH(dbus-service-dir, [ --with-dbus-service-dir specify where the dbus service dir resides], DBUS_SERVICE_DIR=$withval, DBUS_SERVICE_DIR="$datarootdir/dbus-1/services")
AC_SUBST(DBUS_SERVICE_DIR)
+# win32 binding
+AC_ARG_ENABLE(binding-win32, [ --disable-binding-win32 don't create binding win32], binding_win32=$enableval;binding_win32_reason="configure parameter")
+if test "x${binding_win32}" = "xyes" ; then
+ AC_DEFINE(USE_BINDING_WIN32, 1, [Build with binding win32])
+fi
+AM_CONDITIONAL(BINDING_WIN32, test "x${binding_win32}" = "xyes")
+
# svg
AC_ARG_ENABLE(svg, [ --disable-svg disable Scalable Vector Graphics], enable_svg=$enableval, enable_svg=yes)
AC_ARG_ENABLE(svg2png, [ --disable-svg2png disable conversion of svgs to pngs], enable_svg2png=$enableval, enable_svg2png=yes)
@@ -1127,6 +1137,7 @@ navit/autoload/osso/Makefile
navit/binding/Makefile
navit/binding/python/Makefile
navit/binding/dbus/Makefile
+navit/binding/win32/Makefile
navit/map/Makefile
navit/map/mg/Makefile
navit/map/textfile/Makefile
diff --git a/navit/attr_def.h b/navit/attr_def.h
index eade6fbc..7e7704b1 100644
--- a/navit/attr_def.h
+++ b/navit/attr_def.h
@@ -443,6 +443,7 @@ ATTR(log_gpx)
ATTR(log_textfile)
ATTR(graphics_ready)
ATTR(destroy)
+ATTR(wm_copydata)
ATTR2(0x000bffff,type_callback_end)
ATTR2(0x000c0000,type_int64_begin)
ATTR(osm_nodeid)
diff --git a/navit/binding/Makefile.am b/navit/binding/Makefile.am
index 48e0a8d6..6b782b48 100644
--- a/navit/binding/Makefile.am
+++ b/navit/binding/Makefile.am
@@ -6,5 +6,10 @@ if BINDING_DBUS
SUBDIRS+=dbus
endif
-DIST_SUBDIRS=python dbus
+if BINDING_WIN32
+ SUBDIRS+=win32
+endif
+
+
+DIST_SUBDIRS=python dbus win32
diff --git a/navit/binding/win32/CMakeLists.txt b/navit/binding/win32/CMakeLists.txt
new file mode 100644
index 00000000..792a8ff4
--- /dev/null
+++ b/navit/binding/win32/CMakeLists.txt
@@ -0,0 +1,9 @@
+if (USE_LIBGNUINTL AND NOT HAVE_GLIB)
+ ADD_DEPENDENCIES(support_glib intl_cmake)
+endif()
+
+module_add_library(binding_win32 binding_win32.c)
+
+add_executable(tell_navit tell_navit.c)
+target_link_libraries(tell_navit ${MODULES_NAME} ${NAVIT_SUPPORT_LIBS} fib ${NAVIT_LIBS} )
+install(TARGETS tell_navit DESTINATION ${BIN_DIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
diff --git a/navit/binding/win32/Makefile.am b/navit/binding/win32/Makefile.am
new file mode 100644
index 00000000..23ec1dea
--- /dev/null
+++ b/navit/binding/win32/Makefile.am
@@ -0,0 +1,12 @@
+include $(top_srcdir)/Makefile.inc
+AM_CPPFLAGS = -I$(top_srcdir)/navit -I$(top_srcdir)/navit/binding/win32 @NAVIT_CFLAGS@ -DMODULE=binding_win32
+if PLUGINS
+modulebinding_LTLIBRARIES = libbinding_win32.la
+else
+noinst_LTLIBRARIES = libbinding_win32.la
+endif
+libbinding_win32_la_SOURCES = binding_win32.c binding_win32.h
+libbinding_win32_la_LIBADD =
+libbinding_win32_la_LDFLAGS = -module -avoid-version
+bin_PROGRAMS=tell_navit
+tell_navit_LDADD = @NAVIT_LIBS@
diff --git a/navit/binding/win32/binding_win32.c b/navit/binding/win32/binding_win32.c
new file mode 100644
index 00000000..ed6c19db
--- /dev/null
+++ b/navit/binding/win32/binding_win32.c
@@ -0,0 +1,143 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program 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 this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <string.h>
+#include <glib.h>
+#include <windows.h>
+#include "config.h"
+#include "config_.h"
+#include "navit.h"
+#include "coord.h"
+#include "point.h"
+#include "plugin.h"
+#include "debug.h"
+#include "item.h"
+#include "attr.h"
+#include "layout.h"
+#include "navigation.h"
+#include "command.h"
+#include "callback.h"
+#include "graphics.h"
+#include "track.h"
+#include "vehicle.h"
+#include "vehicleprofile.h"
+#include "map.h"
+#include "mapset.h"
+#include "osd.h"
+#include "route.h"
+#include "search.h"
+#include "callback.h"
+#include "gui.h"
+#include "util.h"
+#include "binding_win32.h"
+
+struct win32_binding_private {
+ struct navit* navit;
+};
+
+
+
+/* TODO: do something meaningful here
+ *
+ */
+static int
+win32_cmd_send_signal(struct navit *navit, char *command, struct attr **in, struct attr ***out)
+{
+ dbg(0,"this function is a stub\n");
+ if (in) {
+ while (*in) {
+ dbg(0,"another attribute to be sent\n");
+ in++;
+ }
+ }
+ return 0;
+}
+
+
+static struct command_table commands[] = {
+ {"win32_send",command_cast(win32_cmd_send_signal)},
+};
+
+
+static void
+win32_wm_copydata(struct win32_binding_private *this, int *hwndSender, COPYDATASTRUCT *cpd)
+{
+ struct attr navit;
+ struct navit_binding_w32_msg *msg;
+ navit.type=attr_navit;
+ navit.u.navit=this->navit;
+ if(cpd->dwData!=NAVIT_BINDING_W32_DWDATA) {
+ dbg(0,"COPYDATA message came with wrong DWDATA value, expected %d, got %d.\n",NAVIT_BINDING_W32_DWDATA,cpd->dwData);
+ return;
+ }
+ if(cpd->cbData<sizeof(*msg)) {
+ dbg(0,"COPYDATA message too short, expected >=%d, got %d.\n",sizeof(*msg),cpd->cbData);
+ return;
+ }
+ msg=cpd->lpData;
+ if(cpd->dwData!=NAVIT_BINDING_W32_VERSION) {
+ dbg(0,"Got request with wrong version number, expected %d, got %d.\n",NAVIT_BINDING_W32_VERSION,msg->version);
+ return;
+ }
+ if(strcmp(NAVIT_BINDING_W32_MAGIC,msg->magic)) {
+ dbg(0,"Got request with wrong MAGIC, expected %s, got %*s.\n",NAVIT_BINDING_W32_MAGIC, msg->magic,sizeof(msg->magic));
+ return;
+ }
+ dbg(0,"Running command %s\n", msg->text);
+ command_evaluate(&navit, msg->text);
+}
+
+static void
+win32_cb_graphics_ready(struct win32_binding_private *this, struct navit *navit)
+{
+ struct graphics *gra;
+ struct callback *gcb;
+
+ gcb=callback_new_attr_1(callback_cast(win32_wm_copydata),attr_wm_copydata, this);
+ gra=navit_get_graphics(navit);
+ dbg_assert(gra);
+ graphics_add_callback(gra, gcb);
+}
+
+static void
+win32_main_navit(struct win32_binding_private *this, struct navit *navit, int added)
+{
+ struct attr attr;
+ dbg(0,"enter");
+ if (added==1) {
+ dbg(0,"enter2");
+ this->navit=navit;
+ command_add_table_attr(commands, sizeof(commands)/sizeof(struct command_table), navit, &attr);
+ navit_add_attr(navit, &attr);
+ navit_add_callback(navit,callback_new_attr_1(callback_cast(win32_cb_graphics_ready),attr_graphics_ready, this));
+ }
+
+}
+
+
+
+void plugin_init(void)
+{
+ struct attr callback;
+ struct win32_binding_private *this=g_new0(struct win32_binding_private,1);
+ callback.type=attr_callback;
+ callback.u.callback=callback_new_attr_1(callback_cast(win32_main_navit),attr_navit,this);
+ config_add_attr(config, &callback);
+}
+
diff --git a/navit/binding/win32/binding_win32.h b/navit/binding/win32/binding_win32.h
new file mode 100644
index 00000000..79fe1eb1
--- /dev/null
+++ b/navit/binding/win32/binding_win32.h
@@ -0,0 +1,37 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program 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 this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef BINDING_WIN32_H
+#define BINDING_WIN32_H
+
+#define NAVIT_BINDING_W32_DWDATA 1
+#define NAVIT_BINDING_W32_MAGIC "NavIt"
+#define NAVIT_BINDING_W32_VERSION 1
+
+struct navit_binding_w32_msg {
+ /* Structure version number, should be equal to NAVIT_BINDING_W32_VERSION */
+ int version;
+ /* Magic code to filter out packets directed to other applications and [mistakely] sent to us or broadcasted.
+ * should be equal to NAVIT_BINDING_W32_MAGIC */
+ char magic[6];
+ /* Command to be executed by Navit */
+ char text[1];
+};
+
+#endif
diff --git a/navit/binding/win32/tell_navit.c b/navit/binding/win32/tell_navit.c
new file mode 100644
index 00000000..86f407e0
--- /dev/null
+++ b/navit/binding/win32/tell_navit.c
@@ -0,0 +1,176 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program 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 this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include <windows.h>
+#include <stdio.h>
+#include <stdarg.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+#include <XGetopt.h>
+#endif
+#include <glib.h>
+#include "binding_win32.h"
+
+static LRESULT CALLBACK message_handler( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
+{
+ switch(uMsg) {
+ case WM_CREATE:
+ return 0;
+ }
+ return TRUE;
+}
+
+int errormode=1;
+
+void err(char *fmt, ...)
+{
+ va_list ap;
+ char buf[1024];
+ va_start(ap, fmt);
+ vsnprintf(buf, sizeof(buf), fmt, ap);
+ va_end(ap);
+ switch(errormode) {
+ case 0: /* be silent */
+ break;
+ case 1:
+ MessageBox(NULL, buf, "tell_navit", MB_ICONERROR|MB_OK);
+ break;
+ case 2:
+ fprintf(stderr,"%s",buf);
+ break;
+ }
+}
+
+void print_usage(void)
+{
+ err(
+ "tell_navit usage:\n"
+ "tell_navit [options] navit_command\n"
+ "\t-h this help\n"
+ "\t-e <way>: set way to report error messages:\n"
+ "\t\t0 - suppress messages\n"
+ "\t\t1 - use messagebox (default)\n"
+ "\t\t2 - print to stderr\n"
+ );
+}
+
+int main(int argc, char **argv)
+{
+ HWND navitWindow;
+ COPYDATASTRUCT cd;
+ char opt;
+
+ TCHAR *g_szClassName = TEXT("TellNavitWND");
+ WNDCLASS wc;
+ HWND hwnd;
+ HWND hWndParent=NULL;
+
+
+ if(argc>0) {
+ while((opt = getopt(argc, argv, ":hvc:d:e:s:")) != -1) {
+ switch(opt){
+ case 'h':
+ print_usage();
+ exit(0);
+ break;
+ case 'e':
+ errormode=atoi(optarg);
+ break;
+ default:
+ err("Unknown option %c\n", opt);
+ exit(1);
+ break;
+ }
+ }
+ } else {
+ print_usage();
+ exit(1);
+ }
+ if(optind==argc) {
+ err("Navit command to execute is needed.");
+ exit(1);
+ }
+
+
+ memset(&wc, 0 , sizeof(WNDCLASS));
+ wc.lpfnWndProc = message_handler;
+ wc.hInstance = GetModuleHandle(NULL);
+ wc.lpszClassName = g_szClassName;
+
+ if (!RegisterClass(&wc))
+ {
+ err(TEXT("Window class registration failed\n"));
+ return 1;
+ } else {
+ hwnd = CreateWindow(
+ g_szClassName,
+ TEXT("Tell Navit"),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ hWndParent,
+ NULL,
+ GetModuleHandle(NULL),
+ NULL);
+ if(!hwnd) {
+ err(TEXT("Can't create hidden window\n"));
+ UnregisterClass(g_szClassName,NULL);
+ return 1;
+ }
+ }
+
+ navitWindow=FindWindow( TEXT("NAVGRA"), NULL );
+ if(!navitWindow) {
+ err(TEXT("Navit window not found\n"));
+ DestroyWindow(hwnd);
+ UnregisterClass(g_szClassName,NULL);
+ return 1;
+ } else {
+ int rv;
+ char *command=g_strjoinv(" ",argv+optind);
+ struct navit_binding_w32_msg *msg;
+ int sz=sizeof(*msg)+strlen(command);
+
+ cd.dwData=NAVIT_BINDING_W32_DWDATA;
+ msg=g_malloc0(sz);
+ msg->version=NAVIT_BINDING_W32_VERSION;
+ g_strlcpy(msg->magic,NAVIT_BINDING_W32_MAGIC,sizeof(msg->magic));
+ g_strlcpy(msg->text,command,sz-sizeof(*msg)+1);
+ cd.cbData=sz;
+ cd.lpData=msg;
+ rv=SendMessage( navitWindow, WM_COPYDATA, (WPARAM)hwnd, (LPARAM) (LPVOID) &cd );
+ g_free(command);
+ g_free(msg);
+ if(rv!=0) {
+ err(TEXT("Error %d sending message, SendMessage return value is %d\n"), GetLastError(), rv);
+ DestroyWindow(hwnd);
+ UnregisterClass(g_szClassName,NULL);
+ return 1;
+ }
+ }
+ DestroyWindow(hwnd);
+ UnregisterClass(g_szClassName,NULL);
+ return 0;
+}
+
+
diff --git a/navit/graphics/win32/graphics_win32.c b/navit/graphics/win32/graphics_win32.c
index a84aa479..20f7e427 100644
--- a/navit/graphics/win32/graphics_win32.c
+++ b/navit/graphics/win32/graphics_win32.c
@@ -79,6 +79,8 @@ struct graphics_priv
FP_AlphaBlend AlphaBlend;
HANDLE hCoreDll;
GHashTable *image_cache_hash;
+ BOOL WINAPI (*ChangeWindowMessageFilter)(UINT message, DWORD dwFlag);
+ BOOL WINAPI (*ChangeWindowMessageFilterEx)( HWND hWnd, UINT message, DWORD action, void *pChangeFilterStruct);
};
struct window_priv
@@ -545,6 +547,10 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
case WM_KEYDOWN:
HandleKeyDown( gra_priv, wParam);
break;
+ case WM_COPYDATA:
+ dbg(0,"got WM_COPYDATA\n");
+ callback_list_call_attr_2(gra_priv->cbl, attr_wm_copydata, (void *)wParam, (void*)lParam);
+ break;
#ifdef HAVE_API_WIN32_CE
case WM_SETFOCUS:
if (fullscr) {
@@ -710,6 +716,14 @@ static HANDLE CreateGraphicsWindows( struct graphics_priv* gr, HMENU hMenu )
dbg(0, "Window creation failed: %d\n", GetLastError());
return NULL;
}
+ /* For Vista, we need here ChangeWindowMessageFilter(WM_COPYDATA,MSGFLT_ADD); since Win7 we need above one or ChangeWindowMessageFilterEx (MSDN), both are
+ not avail for earlier Win and not present in my mingw :(. ChangeWindowMessageFilter may not be present in later Win versions. Welcome late binding!
+ */
+ if(gr->ChangeWindowMessageFilter)
+ gr->ChangeWindowMessageFilter(WM_COPYDATA,1 /*MSGFLT_ADD*/);
+ else if(gr->ChangeWindowMessageFilterEx)
+ gr->ChangeWindowMessageFilterEx(hwnd,WM_COPYDATA,1 /*MSGFLT_ALLOW*/,NULL);
+
gr->wnd_handle = hwnd;
callback_list_call_attr_2(gr->cbl, attr_resize, (void *)gr->width, (void *)gr->height);
@@ -1533,6 +1547,7 @@ static struct graphics_priv*
struct attr *attr;
struct graphics_priv* this_;
+ HMODULE user32;
if (!event_request_system("win32","graphics_win32"))
return NULL;
this_=graphics_win32_new_helper(meth);
@@ -1549,6 +1564,12 @@ static struct graphics_priv*
this_->window.priv = NULL;
this_->image_cache_hash = g_hash_table_new(g_str_hash, g_str_equal);
set_alphablend(this_);
+
+ user32=GetModuleHandle("user32.dll");
+ if(user32) {
+ this_->ChangeWindowMessageFilterEx=GetProcAddress(user32,"ChangeWindowMessageFilterEx");
+ this_->ChangeWindowMessageFilter=GetProcAddress(user32,"ChangeWindowMessageFilter");
+ }
return this_;
}