Index: navit/graphics/win32/graphics_win32.c =================================================================== --- navit/graphics/win32/graphics_win32.c (revision 4886) +++ navit/graphics/win32/graphics_win32.c (working copy) @@ -545,6 +545,10 @@ 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 +714,9 @@ dbg(0, "Window creation failed: %d\n", GetLastError()); return NULL; } +// TODO: 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 :(. Welcome late binding? + gr->wnd_handle = hwnd; callback_list_call_attr_2(gr->cbl, attr_resize, (void *)gr->width, (void *)gr->height); Index: navit/binding/win32/binding_win32.h =================================================================== --- navit/binding/win32/binding_win32.h (revision 0) +++ navit/binding/win32/binding_win32.h (revision 0) @@ -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 Index: navit/binding/win32/tell_navit.c =================================================================== --- navit/binding/win32/tell_navit.c (revision 0) +++ navit/binding/win32/tell_navit.c (revision 0) @@ -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 +#include +#include +#ifdef HAVE_GETOPT_H +#include +#else +#include +#endif +#include +#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 : 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; +} + + Index: navit/binding/win32/Makefile.am =================================================================== --- navit/binding/win32/Makefile.am (revision 0) +++ navit/binding/win32/Makefile.am (revision 0) @@ -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@ Index: navit/binding/win32/binding_win32.c =================================================================== --- navit/binding/win32/binding_win32.c (revision 0) +++ navit/binding/win32/binding_win32.c (revision 0) @@ -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 +#include +#include +#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=%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); +} + Index: navit/binding/win32/CMakeLists.txt =================================================================== --- navit/binding/win32/CMakeLists.txt (revision 0) +++ navit/binding/win32/CMakeLists.txt (revision 0) @@ -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} ) + Index: navit/binding/Makefile.am =================================================================== --- navit/binding/Makefile.am (revision 4886) +++ navit/binding/Makefile.am (working copy) @@ -6,5 +6,10 @@ SUBDIRS+=dbus endif -DIST_SUBDIRS=python dbus +if BINDING_WIN32 + SUBDIRS+=win32 +endif + +DIST_SUBDIRS=python dbus win32 + Index: navit/attr_def.h =================================================================== --- navit/attr_def.h (revision 4886) +++ navit/attr_def.h (working copy) @@ -443,6 +443,7 @@ ATTR(log_textfile) ATTR(graphics_ready) ATTR(destroy) +ATTR(wm_copydata) ATTR2(0x000bffff,type_callback_end) ATTR2(0x000c0000,type_int64_begin) ATTR(osm_nodeid) Index: configure.in =================================================================== --- configure.in (revision 4886) +++ configure.in (working copy) @@ -39,6 +39,7 @@ 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 @@ 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 @@ 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 @@ 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/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 Index: CMakeLists.txt =================================================================== --- CMakeLists.txt (revision 4886) +++ CMakeLists.txt (working copy) @@ -62,6 +62,7 @@ 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 @@ 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