Fix:projs/CodeBlocks:win32 native toolbar and added app icon
authorafaber <afaber@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 4 Feb 2008 23:53:13 +0000 (23:53 +0000)
committerafaber <afaber@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 4 Feb 2008 23:53:13 +0000 (23:53 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@840 ffa7fe5e-494d-0410-b361-a75ebd5db220

projs/CodeBlocks/Navit_win32.cbp
projs/CodeBlocks/Win32Extra/navit_win32.c
projs/CodeBlocks/makefile_extra
projs/CodeBlocks/win32gui/resources/navit.ico [new file with mode: 0644]
projs/CodeBlocks/win32gui/resources/resource.h [new file with mode: 0644]
projs/CodeBlocks/win32gui/resources/resource.rc [new file with mode: 0644]
projs/CodeBlocks/win32gui/resources/toolbar.bmp [new file with mode: 0644]
projs/CodeBlocks/win32gui/win32_graphics.c
projs/CodeBlocks/win32gui/win32_gui.c
projs/CodeBlocks/win32gui/win32_gui.h

index b29ecad..160e94f 100644 (file)
                        <Add directory="..\..\src\fib-1.1" />
                        <Add directory="%GTK_DIR%\include\freetype2" />
                </Compiler>
+               <ResourceCompiler>
+                       <Add directory="win32gui\resources" />
+               </ResourceCompiler>
                <Linker>
                        <Add directory="%GTK_DIR%\lib" />
                </Linker>
                <Unit filename="Win32Extra\navit_win32.c">
                        <Option compilerVar="CC" />
                </Unit>
+               <Unit filename="win32gui\resources\resource.h" />
+               <Unit filename="win32gui\resources\resource.rc">
+                       <Option compilerVar="WINDRES" />
+               </Unit>
                <Extensions>
                        <code_completion />
                        <envvars />
index 054d402..b60e792 100644 (file)
@@ -1,9 +1,15 @@
 
+
+extern void module_data_textfile_init(void);
+extern void module_data_binfile_init(void);
+extern void module_data_mg_init(void);
+extern void module_win32_gui_init(void);
+extern void module_data_garmin_init(void);
+extern void module_data_poi_geodownload_init(void);
 extern void module_vehicle_demo_init(void);
 extern void module_vehicle_file_init(void);
-extern void module_win32_gui_init(void);
 extern void module_speech_speech_dispatcher_init(void);
-extern void builtin_init(void);
+
 void builtin_init(void) {
        module_data_textfile_init();
        module_data_binfile_init();
index 258c2a1..98c69c7 100644 (file)
@@ -16,7 +16,14 @@ DST_LIB_PATH = $(DST_PATH)/lib
 DST_MAP_PATH = $(DST_PATH)/maps
 DST_MO_PATH = $(DST_BIN_PATH)/locale
 
-
+WIN32_DLLS =  \
+       iconv.dll \
+       intl.dll \
+       libglib-2.0-0.dll \
+       libgmodule-2.0-0.dll \
+       libgobject-2.0-0.dll \
+       zlib1.dll
+       
 GTK_DLLS =  \
        freetype6.dll \
        iconv.dll \
@@ -39,7 +46,8 @@ GTK_DLLS =  \
        libxml2.dll \
        zlib1.dll
 
-NAVIT_EXES = navit.exe osm2navit.exe
+NAVIT_EXES_GTK = navit_gtk.exe osm2navit.exe
+NAVIT_EXES_W32 = navit_win32.exe osm2navit.exe
 
 
 SAMPLE_MAP=osm_bbox_11.3,47.9,11.7,48.2
@@ -75,12 +83,12 @@ locale: $(POFILES)
 locale_clean:
        rm -Rf locale
 
-distr: $(SAMPLE_MAP).bin $(POFILES)
+distr_gtk: $(SAMPLE_MAP).bin $(POFILES)
        rm -Rf $(DISTR_TARGET_PATH);
        mkdir -p $(DST_BIN_PATH);
        mkdir -p $(DST_ETC_PATH);
        mkdir -p $(DST_LIB_PATH);
-       for i in $(NAVIT_EXES); do \
+       for i in $(NAVIT_EXES_GTK); do \
                cp $(SRC_NAVIT_EXE_PATH)/$$i $(DST_BIN_PATH)/$$i; \
        done;
        for i in $(GTK_DLLS); do \
@@ -100,3 +108,27 @@ distr: $(SAMPLE_MAP).bin $(POFILES)
        mkdir -p $(DST_MO_PATH) ;       
        cp -r $(SRC_MO_PATH)/* $(DST_MO_PATH)/           
 
+distr_win32: $(SAMPLE_MAP).bin $(POFILES)
+       rm -Rf $(DISTR_TARGET_PATH);
+       mkdir -p $(DST_BIN_PATH);
+       mkdir -p $(DST_ETC_PATH);
+       mkdir -p $(DST_LIB_PATH);
+       for i in $(NAVIT_EXES); do \
+               cp $(SRC_NAVIT_EXE_W32_PATH)/$$i $(DST_BIN_PATH)/$$i; \
+       done;
+       for i in $(WIN32_DLLS); do \
+               cp $(SRC_GTK_BIN_PATH)/$$i $(DST_BIN_PATH)/$$i; \
+       done;
+       cp -r $(SRC_GTK_ETC_PATH)/* $(DST_ETC_PATH) ;
+       mkdir -p $(DST_LIB_PATH)/gtk-2.0/2.10.0 ;
+       cp -r $(SRC_GTK_LIB_PATH)/gtk-2.0/2.10.0/* $(DST_LIB_PATH)/gtk-2.0/2.10.0 ;
+       mkdir -p $(DST_LIB_PATH)/pango ;        
+       cp -r $(SRC_GTK_LIB_PATH)/pango/* $(DST_LIB_PATH)/pango ;
+       cp ./navit.xml.distr $(DST_BIN_PATH)/navit.xml ;
+       cp ./*.ttf $(DST_BIN_PATH)/ ;
+       mkdir -p $(DST_MAP_PATH) ;
+       cp $(SAMPLE_MAP).bin $(DST_MAP_PATH)/ ;
+       mkdir -p $(DST_XPM_PATH) ;      
+       cp -r $(SRC_XPM_PATH)/*.xpm $(DST_XPM_PATH)/ ; 
+       mkdir -p $(DST_MO_PATH) ;       
+       cp -r $(SRC_MO_PATH)/* $(DST_MO_PATH)/           
diff --git a/projs/CodeBlocks/win32gui/resources/navit.ico b/projs/CodeBlocks/win32gui/resources/navit.ico
new file mode 100644 (file)
index 0000000..6d7a952
Binary files /dev/null and b/projs/CodeBlocks/win32gui/resources/navit.ico differ
diff --git a/projs/CodeBlocks/win32gui/resources/resource.h b/projs/CodeBlocks/win32gui/resources/resource.h
new file mode 100644 (file)
index 0000000..55bcc2d
--- /dev/null
@@ -0,0 +1,4 @@
+#include <windows.h>
+
+#define IDI_NAVIT 1100
+#define IDB_NAVITTOOLBAR 1101
diff --git a/projs/CodeBlocks/win32gui/resources/resource.rc b/projs/CodeBlocks/win32gui/resources/resource.rc
new file mode 100644 (file)
index 0000000..d31d89c
--- /dev/null
@@ -0,0 +1,14 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// Bitmap
+//
+
+#include "resource.h"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Bitmap
+//
+
+IDB_NAVITTOOLBAR BITMAP  DISCARDABLE "toolbar.bmp"
+IDI_NAVIT ICON    DISCARDABLE     "navit.ico"
diff --git a/projs/CodeBlocks/win32gui/resources/toolbar.bmp b/projs/CodeBlocks/win32gui/resources/toolbar.bmp
new file mode 100644 (file)
index 0000000..17381d8
Binary files /dev/null and b/projs/CodeBlocks/win32gui/resources/toolbar.bmp differ
index 6483b46..06c8a70 100644 (file)
@@ -1,6 +1,9 @@
 #include <windows.h>
 #include <wingdi.h>
 #include <glib.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
 
 #include "config.h"
 #include "debug.h"
 #include "color.h"
 #include "plugin.h"
 #include "win32_gui.h"
-
-#include "xpm2bmp.h";
+#include "xpm2bmp.h"
 
 #ifndef GET_WHEEL_DELTA_WPARAM
        #define GET_WHEEL_DELTA_WPARAM(wParam)  ((short)HIWORD(wParam))
 #endif
 
+
+static GHashTable *image_cache_hash = NULL;
+
+
 HFONT EzCreateFont (HDC hdc, TCHAR * szFaceName, int iDeciPtHeight,
                     int iDeciPtWidth, int iAttributes, BOOL fLogRes) ;
 
@@ -140,7 +146,8 @@ struct graphics_gc_priv {
 };
 
 
-struct graphics_priv *g_gra;
+//struct graphics_priv *g_gra;
+
 static HDC hMemDC;
 static HBITMAP hBitmap;
 static HBITMAP hOldBitmap;
@@ -179,15 +186,15 @@ static void MakeMemoryDC(HANDLE hWnd, HDC hdc )
        }
 }
 
-static void HandleButtonClick( int updown, int button, long lParam )
+static void HandleButtonClick( struct graphics_priv *gra_priv, int updown, int button, long lParam )
 {
        int xPos = LOWORD(lParam);
        int yPos = HIWORD(lParam);
-       // printf( "WM_LBUTTONDOWN: %d %d \n", xPos, yPos );
-       if (g_gra->button_callback )
+
+       if (gra_priv->button_callback )
        {
                struct point pt = {xPos, yPos};
-               (*g_gra->button_callback)(g_gra->button_callback_data, updown, button, &pt);
+               (*gra_priv->button_callback)(gra_priv->button_callback_data, updown, button, &pt);
        }
 }
 
@@ -195,23 +202,18 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
 {
 
 //if ( Message != 15 )
-       // printf( "CHILD %d %d %d \n", Message, wParam, lParam );
+//printf( "CHILD %d %d %d \n", Message, wParam, lParam );
+
+       struct graphics_priv* gra_priv = (struct graphics_priv*)GetWindowLongPtr( hwnd , DWLP_USER );
+
        switch(Message)
        {
                case WM_CREATE:
                {
-                       g_gra->wnd_handle = hwnd;
-                       //if (g_gra->resize_callback)
-                       //      (*g_gra->resize_callback)(g_gra->resize_callback_data, g_gra->width, g_gra->height);
-                       //MoveWindow( hwnd, 0,0, 780, 680, TRUE );
-
-                       {
-                               HDC hdc;
-                               hdc = GetDC( hwnd );
-                               MakeMemoryDC(hwnd, hdc );
-                               ReleaseDC( hwnd, hdc );
-                       }
-                       PostMessage( g_gra->wnd_parent_handle, WM_USER + 1, 0, 0 );
+                       HDC hdc;
+                       hdc = GetDC( hwnd );
+                       MakeMemoryDC(hwnd, hdc );
+                       ReleaseDC( hwnd, hdc );
                }
                break;
                case WM_COMMAND:
@@ -224,12 +226,29 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
                case WM_CLOSE:
                        DestroyWindow(hwnd);
                break;
+               case WM_USER+1:
+                       if ( gra_priv )
+                       {
+                               RECT rc ;
+                               HDC hdc;
+
+                               GetClientRect( hwnd, &rc );
+                               gra_priv->width = rc.right;
+                               gra_priv->height = rc.bottom;
+
+                               hdc = GetDC( hwnd );
+                               MakeMemoryDC(hwnd, hdc );
+                               ReleaseDC( hwnd, hdc );
+                               (*gra_priv->resize_callback)(gra_priv->resize_callback_data, gra_priv->width, gra_priv->height);
+                       }
+               break;
+
                case WM_SIZE:
+               /*
+                       if ( gra_priv )
                        {
                                //graphics = GetWindowLong( hwnd, DWL_USER, 0 );
 
-                               g_gra->width = LOWORD( lParam );
-                               g_gra->height  = HIWORD( lParam );
 
                                {
                                        HDC hdc;
@@ -237,23 +256,31 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
                                        MakeMemoryDC(hwnd, hdc );
                                        ReleaseDC( hwnd, hdc );
                                }
-                               printf( "resize gfx to: %d %d \n", g_gra->width, g_gra->height );
+                               (*gra_priv->resize_callback)(gra_priv->resize_callback_data, gra_priv->width, gra_priv->height);
+
 
                        }
+                       */
+                       if ( gra_priv )
+                       {
+                               gra_priv->width = LOWORD( lParam );
+                               gra_priv->height  = HIWORD( lParam );
+                               printf( "resize gfx to: %d %d \n", gra_priv->width, gra_priv->height );
+                       }
                break;
                case WM_DESTROY:
                        PostQuitMessage(0);
                        exit( 0 );
                break;
                case WM_PAINT:
+                       if ( gra_priv )
                        {
-
-                       HDC hdc = GetDC(hwnd );
-                       if ( hMemDC )
-                       {
-                               BitBlt( hdc, 0, 0, g_gra->width , g_gra->height, hMemDC, 0, 0, SRCCOPY );
-                       }
-                       ReleaseDC( hwnd, hdc );
+                               HDC hdc = GetDC(hwnd );
+                               if ( hMemDC )
+                               {
+                                       BitBlt( hdc, 0, 0, gra_priv->width , gra_priv->height, hMemDC, 0, 0, SRCCOPY );
+                               }
+                               ReleaseDC( hwnd, hdc );
                        }
                break;
                case WM_MOUSEMOVE:
@@ -263,32 +290,24 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
                        struct point pt = {xPos, yPos};
 
                        // printf( "WM_MOUSEMOVE: %d %d \n", xPos, yPos );
-                       (*g_gra->motion_callback)(g_gra->motion_callback_data, &pt);
+                       (*gra_priv->motion_callback)(gra_priv->motion_callback_data, &pt);
                }
 
                break;
 
                case WM_LBUTTONDOWN:
-                       HandleButtonClick( 1, 1,lParam );
+                       HandleButtonClick( gra_priv,1, 1,lParam );
                break;
                case WM_LBUTTONUP:
-                       HandleButtonClick( 0, 1,lParam );
+                       HandleButtonClick( gra_priv, 0, 1,lParam );
                break;
                case WM_RBUTTONDOWN:
-                       HandleButtonClick( 1, 3,lParam );
+                       HandleButtonClick( gra_priv, 1, 3,lParam );
                break;
                case WM_RBUTTONUP:
-                       HandleButtonClick( 0, 3,lParam );
-               break;
-
-               case WM_HSCROLL:
-               case WM_VSCROLL:
-                       printf( "mousewheel delta %d\n", wParam );
+                       HandleButtonClick( gra_priv, 0, 3,lParam );
                break;
-               case WM_MOUSEWHEEL:
-                       printf( "mousewheel delta %d\n", wParam );
 
-               break;
                default:
                        return DefWindowProc(hwnd, Message, wParam, lParam);
        }
@@ -298,18 +317,17 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
 
 static const char g_szClassName[] = "NAVGRA";
 
-void CreateGraphicsWindows( struct graphics_priv* gr )
+HANDLE CreateGraphicsWindows( struct graphics_priv* gr )
 {
        WNDCLASSEX wc;
        HWND hwnd;
-       MSG Msg;
     RECT rcParent;
 
        wc.cbSize                = sizeof(WNDCLASSEX);
        wc.style                 = 0;
        wc.lpfnWndProc   = WndProc;
        wc.cbClsExtra    = 0;
-       wc.cbWndExtra    = 0;
+       wc.cbWndExtra    = 64;
        wc.hInstance     = NULL;
        wc.hIcon                 = NULL;
        wc.hCursor               = LoadCursor(NULL, IDC_ARROW);
@@ -346,12 +364,19 @@ void CreateGraphicsWindows( struct graphics_priv* gr )
        if(hwnd == NULL)
        {
                ErrorExit( "Window Creation Failed!" );
-               return 0;
+               return NULL;
        }
 
-       ShowWindow(hwnd, TRUE);
-       UpdateWindow(hwnd);
+       SetWindowLongPtr( hwnd , DWLP_USER, gr );
+
+       ShowWindow( hwnd, TRUE );
+       UpdateWindow( hwnd );
+
        gr->wnd_handle = hwnd;
+
+       PostMessage( gr->wnd_parent_handle, WM_USER + 1, 0, 0 );
+
+       return hwnd;
 }
 
 
@@ -367,8 +392,6 @@ static void gc_destroy(struct graphics_gc_priv *gc)
        g_free( gc );
 }
 
-static HPEN line_pen;
-
 static void gc_set_linewidth(struct graphics_gc_priv *gc, int w)
 {
        gc->line_width = w;
@@ -413,7 +436,7 @@ static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics
 {
        struct graphics_gc_priv *gc=g_new(struct graphics_gc_priv, 1);
        *meth=gc_methods;
-       gc->hwnd = g_gra->wnd_handle;
+       gc->hwnd = gr->wnd_handle;
        gc->line_width = 1;
        gc->fg_color = RGB( 0,0,0 );
        gc->bg_color = RGB( 255,255,255 );
@@ -424,17 +447,13 @@ static struct graphics_gc_priv *gc_new(struct graphics_priv *gr, struct graphics
 static void draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
 {
        int i;
-       HANDLE hndl = gr->wnd_handle;
-
-       HDC dc = hMemDC;
-
        HPEN holdpen;
        HPEN hpen;
 
        hpen = CreatePen( PS_SOLID, gc->line_width, gc->fg_color );
-       holdpen = SelectObject( dc, hpen );
+       holdpen = SelectObject( hMemDC, hpen );
 
-       SetBkColor( dc, gc->bg_color );
+       SetBkColor( hMemDC, gc->bg_color );
 
        int first = 1;
        for ( i = 0; i< count; i++ )
@@ -442,15 +461,15 @@ static void draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, st
                if ( first )
                {
                        first = 0;
-                       MoveToEx( dc, p[0].x, p[0].y, NULL );
+                       MoveToEx( hMemDC, p[0].x, p[0].y, NULL );
                }
                else
                {
-                       LineTo( dc, p[i].x, p[i].y );
+                       LineTo( hMemDC, p[i].x, p[i].y );
                }
        }
 
-       SelectObject( dc, holdpen );
+       SelectObject( hMemDC, holdpen );
        DeleteObject( hpen );
 }
 
@@ -512,7 +531,7 @@ static void draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, s
 
 static void draw_restore(struct graphics_priv *gr, struct point *p, int w, int h)
 {
-       InvalidateRect( gr->wnd_handle, NULL, TRUE );
+       InvalidateRect( gr->wnd_handle, NULL, FALSE );
 }
 
 static void draw_mode(struct graphics_priv *gr, enum draw_mode_num mode)
@@ -607,35 +626,13 @@ static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, str
 
        if ( NULL == font->hfont )
        {
-               int size = font->size;
-               long lfHeight = -MulDiv(font->size, GetDeviceCaps(hMemDC, LOGPIXELSY), 72);
-
-               font->hfont = EzCreateFont (hMemDC, TEXT ("Arial"), size/2, 0, 0, TRUE) ;
+               font->hfont = EzCreateFont (hMemDC, TEXT ("Arial"), font->size/2, 0, 0, TRUE) ;
                GetObject ( font->hfont, sizeof (LOGFONT), &font->lf) ;
-
-/*
-               font->hfont = CreateFont(       lfHeight,
-                                                                       0,
-                                                                       0,
-                                                                       0,
-                                                                       0,
-                                                                       TRUE,
-                                                                       0,
-                                                                       0,
-                                                                       DEFAULT_CHARSET,
-                                                                       0,
-                                                                       0,
-                                                                       0,
-                                                                       0,
-                                                                       "Arial");
-                                                                       */
        }
 
 
-//     RECT rc = { p->x, p->y, 800, 800 };
-//     DrawText(hMemDC, text, -1, &rc, DT_NOCLIP | DT_CALCRECT| DT_SINGLELINE);
        double angle = -atan2( dy, dx ) * 180 / 3.14159 ;
-// printf( "dx %d , dy %d angle %6.3f %s\n", dx, dy, angle, text);
+
        SetTextAlign (hMemDC, TA_BASELINE) ;
        SetViewportOrgEx (hMemDC, p->x, p->y, NULL) ;
        font->lf.lfEscapement = font->lf.lfOrientation = ( angle * 10 ) ;
@@ -644,7 +641,13 @@ static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, str
        font->hfont = CreateFontIndirect (&font->lf);
        HFONT hOldFont = SelectObject(hMemDC, font->hfont );
 
-       TextOut(hMemDC, 0,0, text, strlen( text ) );
+       gunichar2* utf16 = NULL;
+       glong utf16_len = 0;
+
+       utf16 = g_utf8_to_utf16( text, -1, NULL, &utf16_len, NULL );
+       TextOutW(hMemDC, 0,0, utf16, (size_t)utf16_len );
+       g_free( utf16 );
+
 
        SelectObject(hMemDC, hOldFont);
        DeleteObject (font->hfont) ;
@@ -682,14 +685,48 @@ static struct graphics_font_priv *font_new(struct graphics_priv *gr, struct grap
        return font;
 }
 
+
+void image_cache_hash_add( const char* key, struct graphics_image_priv* val_ptr)
+{
+       char* key_ptr = NULL;
+
+       if ( image_cache_hash == NULL ) {
+               image_cache_hash = g_hash_table_new(g_str_hash, g_str_equal);
+       }
+
+       if ( g_hash_table_lookup(image_cache_hash, key ) == NULL )
+       {
+               g_hash_table_insert(image_cache_hash, g_strdup( key ),  (gpointer)val_ptr );
+       }
+
+}
+
+struct graphics_image_priv* image_cache_hash_lookup( const char* key )
+{
+       struct graphics_image_priv* val_ptr = NULL;
+
+       if ( image_cache_hash != NULL )
+       {
+               val_ptr = g_hash_table_lookup(image_cache_hash, key );
+       }
+       return val_ptr;
+}
+
+
+
 static struct graphics_image_priv *image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *name, int *w, int *h, struct point *hot)
 {
        struct graphics_image_priv* ret;
 
-       ret = g_new( struct graphics_image_priv, 1 );
-       printf( "loading image '%s'\n", name );
-       ret->pxpm = Xpm2bmp_new();
-       Xpm2bmp_load( ret->pxpm, name );
+       if ( NULL == ( ret = image_cache_hash_lookup( name ) ) )
+       {
+               ret = g_new( struct graphics_image_priv, 1 );
+               printf( "loading image '%s'\n", name );
+               ret->pxpm = Xpm2bmp_new();
+               Xpm2bmp_load( ret->pxpm, name );
+               image_cache_hash_add( name, ret );
+       }
+
        return ret;
 }
 
@@ -728,7 +765,6 @@ static struct graphics_priv * graphics_win32_drawing_area_new_helper(struct grap
 {
        struct graphics_priv *this_=g_new0(struct graphics_priv,1);
        *meth=graphics_methods;
-       g_gra = this_;
        this_->mode = -1;
        return this_;
 }
index 2e4456f..949da63 100644 (file)
@@ -8,18 +8,42 @@
 #include "win32_gui.h"
 #include "point.h"
 #include "menu.h"
+#include "callback.h"
+#include <commctrl.h>
 
 
+//static GHashTable *popup_callback_hash = NULL;
+static GArray *popup_menu_array;
+
 const char g_szClassName[] = "navit_gui_class";
 
 
 static menu_id = 0;
 static POINT menu_pt;
+static gunichar2* g_utf16 = NULL;
+
+static gunichar2* Utf8ToUtf16( const char* str )
+{
+       if ( g_utf16 )
+       {
+               g_free( g_utf16 );
+       }
+       g_utf16 = g_utf8_to_utf16( str, -1, NULL, NULL, NULL );
+       return g_utf16;
+}
+
+static gunichar2* Utf8ToUtf16_nd( const char* str )
+{
+       gunichar2* utf16= g_utf8_to_utf16( str, -1, NULL, NULL, NULL );
+       return utf16;
+}
 
 gboolean message_pump( gpointer data )
 {
     MSG messages;
 
+       Sleep( 1 );
+
     if (GetMessage (&messages, NULL, 0, 0))
     {
         TranslateMessage(&messages);
@@ -33,10 +57,7 @@ gboolean message_pump( gpointer data )
 
 
 
-
-
-
-extern struct graphics_priv *g_gra;
+//extern struct graphics_priv *g_gra;
 
 BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam)
 {
@@ -50,7 +71,7 @@ BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam)
                rcParent = (LPRECT) lParam;
 
                MoveWindow( hwndChild,  0, 0, rcParent->right, rcParent->bottom, TRUE );
-               (*g_gra->resize_callback)(g_gra->resize_callback_data, rcParent->right, rcParent->bottom);
+               PostMessage( hwndChild, WM_USER+1, 0, 0 );
        }
 
     return TRUE;
@@ -60,69 +81,224 @@ BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam)
        #define GET_WHEEL_DELTA_WPARAM(wParam)  ((short)HIWORD(wParam))
 #endif
 
+/*
+TBBUTTON toolbutton [] =
+{
+       {STD_FILENEW,    IDM_NEW,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+       {STD_FILEOPEN,   IDM_LOAD,       TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+       {STD_PRINT,      IDM_PRINT,      TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+       {STD_FILESAVE,   IDM_SAVE,       TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+       {STD_COPY,       IDM_COPY,       TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+       {STD_DELETE,     IDM_DELETE,     TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+       {STD_PASTE,      IDM_PASTE,      TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+       {STD_CUT,        IDM_CUT,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+       {STD_FIND,       IDM_FIND,       TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+       {STD_HELP,       IDM_HELP,       TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+       {STD_PRINTPRE ,  IDM_PRINTVIEW,  TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+       {STD_PROPERTIES, IDM_PROPERTY,   TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+       {STD_REDOW,      IDM_REDOW,      TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+       {STD_REPLACE,    IDM_REPLACE,    TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+       {STD_UNDO,       IDM_UNDO,       TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+       {IDB_BITMAP1,    IDM_CONSOLE,    TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+};
+*/
+
+static void AddToolbarBitmaps( HWND toolbar )
+{
+//    TBADDBITMAP mybit;
+//    memset (&mybit, 0, sizeof (TBADDBITMAP));
+ //   mybit.hInst = instance;
+  //  mybit.nID = IDB_STD_SMALL_COLOR  ;
+
+    TBADDBITMAP dabit;
+    HBITMAP mybitmap = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_NAVITTOOLBAR));
+
+    memset (&dabit, 0, sizeof (TBADDBITMAP));
+    dabit.hInst = NULL;
+    dabit.nID = (UINT) mybitmap;
+
+
+    //int n = SendMessage (toolbar, TB_ADDBITMAP, 0, (LPARAM) &mybit);
+    int n = SendMessage (toolbar, TB_ADDBITMAP, 10, (LPARAM) &dabit);
+}
+
+static void CreateToolBar(HWND hwnd)
+{
+       // Create Toolbar
+       HWND hTool;
+       TBBUTTON tbb[8];
+       TBADDBITMAP tbab;
+
+       hTool = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
+               hwnd, (HMENU)ID_CHILD_TOOLBAR, GetModuleHandle(NULL), NULL);
+       if(hTool == NULL)
+               MessageBox(hwnd, "Could not create tool bar.", "Error", MB_OK | MB_ICONERROR);
+
+       // Send the TB_BUTTONSTRUCTSIZE message, which is required for
+       // backward compatibility.
+       SendMessage(hTool, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
+
+// AddToolbarBitmaps( hTool );
+// LoadBitmap(GetModuleHandle(NULL), );
+
+int  inst = GetModuleHandle(NULL);
+       tbab.hInst = inst;
+       tbab.nID = IDB_NAVITTOOLBAR;
+       int iImageOffset = SendMessage(hTool, TB_ADDBITMAP, 10, (LPARAM) &tbab); /* Bitmap contains 5 icons */
+
+       int iStr;
+
+       // tbab.hInst = HINST_COMMCTRL;
+       //tbab.nID = IDB_STD_SMALL_COLOR;
+       // SendMessage(hTool, TB_ADDBITMAP, 0, (LPARAM)&tbab);
+
+       ZeroMemory(tbb, sizeof(tbb));
+
+       tbb[0].iBitmap = iImageOffset;
+       tbb[0].fsState = TBSTATE_ENABLED;
+       tbb[0].fsStyle = TBSTYLE_BUTTON;
+       tbb[0].idCommand = ID_DISPLAY_ZOOMIN;
+       iStr = SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM)  Utf8ToUtf16( _("ZoomIn" ) ) );
+       tbb[0].iString = iStr;
+
+       tbb[1].iBitmap = iImageOffset+1;
+       tbb[1].fsState = TBSTATE_ENABLED;
+       tbb[1].fsStyle = TBSTYLE_BUTTON;
+       tbb[1].idCommand = ID_DISPLAY_ZOOMOUT;
+       iStr = SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM)  Utf8ToUtf16( _("ZoomOut" ) ) );
+       tbb[1].iString = iStr;
+
+       tbb[2].iBitmap = iImageOffset+4;
+       tbb[2].fsState = TBSTATE_ENABLED;
+       tbb[2].fsStyle = TBSTYLE_BUTTON;
+       tbb[2].idCommand = ID_DISPLAY_ZOOMIN;
+       iStr = SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM)  Utf8ToUtf16( _("Refresh" ) ) );
+       tbb[2].iString = iStr;
+
+       tbb[3].iBitmap = iImageOffset+2;
+       tbb[3].fsState = TBSTATE_ENABLED;
+       tbb[3].fsStyle = TBSTYLE_BUTTON;
+       tbb[3].idCommand = ID_DISPLAY_ZOOMIN;
+       iStr = SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM)  Utf8ToUtf16( _("Cursor" ) ) );
+       tbb[3].iString = iStr;
+
+       tbb[4].iBitmap = iImageOffset+5;
+       tbb[4].fsState = TBSTATE_ENABLED;
+       tbb[4].fsStyle = TBSTYLE_BUTTON;
+       tbb[4].idCommand = ID_DISPLAY_ZOOMIN;
+       iStr = SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM)  Utf8ToUtf16( _("Orientation" ) ) );
+       tbb[4].iString = iStr;
+
+       tbb[5].iBitmap = iImageOffset+8;
+       tbb[5].fsState = TBSTATE_ENABLED;
+       tbb[5].fsStyle = TBSTYLE_BUTTON;
+       tbb[5].idCommand = ID_DISPLAY_ZOOMIN;
+       iStr= SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM)  Utf8ToUtf16( _("Destination" ) ) );
+       tbb[5].iString = iStr;
+
+       tbb[6].iBitmap = iImageOffset+3;
+       tbb[6].fsState = TBSTATE_ENABLED;
+       tbb[6].fsStyle = TBSTYLE_BUTTON;
+       tbb[6].idCommand = ID_DISPLAY_ZOOMIN;
+       iStr= SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM)  Utf8ToUtf16( _("Roadbook" ) ) );
+       tbb[6].iString = iStr;
+
+       tbb[7].iBitmap = iImageOffset+9;
+       tbb[7].fsState = TBSTATE_ENABLED;
+       tbb[7].fsStyle = TBSTYLE_BUTTON;
+       tbb[7].idCommand = ID_FILE_EXIT;
+       iStr= SendMessage(hTool, TB_ADDSTRINGW, 0, (LPARAM)  Utf8ToUtf16( _("_Quit" ) ) );
+       tbb[7].iString = iStr;
+
+       SendMessage(hTool, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);
+       HWND hChild = GetDlgItem(hwnd, ID_CHILD_TOOLBAR);
+       hChild = hChild;
+}
+
+static void window_layout( HWND hwnd )
+{
+       RECT rcClient;
+       RECT rcTool;
+       int iToolHeight;
+
+       HWND hChild = GetDlgItem(hwnd, ID_CHILD_TOOLBAR);
+       SendMessage(hChild, TB_AUTOSIZE, 0, 0);
+
+       GetWindowRect(hChild, &rcTool);
+       iToolHeight = rcTool.bottom - rcTool.top;
+
+       GetClientRect(hwnd, &rcClient);
+       //printf( "BEFORE resize gui to: %d %d %d %d \n", rcClient.left, rcClient.right, rcClient.top, rcClient.bottom );
+
+       rcClient.top += iToolHeight;
+
+       printf( "resize gui to: %d %d %d %d \n", rcClient.left, rcClient.right, rcClient.top, rcClient.bottom );
+
+
+       hChild = GetDlgItem(hwnd, ID_CHILD_GFX);
+       if ( hChild )
+       {
+               MoveWindow( hChild,  rcClient.left, rcClient.top, rcClient.right- rcClient.left, rcClient.bottom - rcClient.top, TRUE );
+               PostMessage( hChild, WM_USER+1, 0, 0 );
+       }
+}
+
 static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
 {
     RECT rcClient;
 
-       //printf( "PARENT %d %d %d \n", Message, wParam, lParam );
+//     printf( "PARENT %d %d %d \n", Message, wParam, lParam );
 
        switch(Message)
        {
                case WM_CREATE:
                {
                        HMENU hMenu, hSubMenu;
-                       HICON hIcon, hIconSm;
+
+                       CreateToolBar( hwnd );
 
                        hMenu = CreateMenu();
                        // g_this_->hwnd = hwnd;
 
                        hSubMenu = CreatePopupMenu();
 
-                       gunichar2* utf16 = NULL;
-
-                       utf16 = g_utf8_to_utf16( _( "_Quit" ), -1, NULL, NULL, NULL );
-                       AppendMenuW(hSubMenu, MF_STRING, ID_FILE_EXIT, utf16 );
-                       g_free( utf16 );
-
-                       utf16 = g_utf8_to_utf16( _( "Zoom in" ), -1, NULL, NULL, NULL );
-                       AppendMenuW(hSubMenu, MF_STRING, ID_DISPLAY_ZOOMIN, utf16 );
-                       g_free( utf16 );
-
-                       utf16 = g_utf8_to_utf16( _( "Zoom out" ), -1, NULL, NULL, NULL );
-                       AppendMenuW(hSubMenu, MF_STRING, ID_DISPLAY_ZOOMOUT, utf16 );
-                       g_free( utf16 );
-
-                       utf16 = g_utf8_to_utf16( _( "Display" ), -1, NULL, NULL, NULL );
-                       AppendMenuW(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, utf16 );
-                       g_free( utf16 );
+                       AppendMenuW(hSubMenu, MF_STRING, ID_DISPLAY_ZOOMIN, Utf8ToUtf16( _( "ZoomIn" ) ) );
+                       AppendMenuW(hSubMenu, MF_STRING, ID_DISPLAY_ZOOMOUT, Utf8ToUtf16( _( "ZoomOut" ) ) );
+                       AppendMenuW(hSubMenu, MF_STRING, ID_DISPLAY_REFRESH, Utf8ToUtf16( _( "Refresh" ) ) );
+                       AppendMenuW(hSubMenu, MF_SEPARATOR, 0, NULL );
+                       AppendMenuW(hSubMenu, MF_STRING, ID_FILE_EXIT, Utf8ToUtf16( _( "_Quit" ) ) );
 
+                       AppendMenuW(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, Utf8ToUtf16( _( "Display" ) ) );
                        hSubMenu = CreatePopupMenu();
                        AppendMenu(hSubMenu, MF_STRING, ID_STUFF_GO, "&Go");
                        AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Stuff");
 
                        SetMenu(hwnd, hMenu);
 
-#if 0
-                       hIcon = LoadImage(NULL, "menu_two.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
-                       if(hIcon)
-                               SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
-                       else
-                               MessageBox(hwnd, "Could not load large icon!", "Error", MB_OK | MB_ICONERROR);
-
-                       hIconSm = LoadImage(NULL, "menu_two.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
-                       if(hIconSm)
-                               SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm);
-                       else
-                               MessageBox(hwnd, "Could not load small icon!", "Error", MB_OK | MB_ICONERROR);
-
-#endif
+                       window_layout( hwnd );
 
                }
                break;
                case WM_COMMAND:
                {
+                       printf( "WM_COMMAND %d\n", LOWORD(wParam) );
                        struct gui_priv* gui = (struct gui_priv*)GetWindowLongPtr( hwnd , DWLP_USER );
 
+                       if ( popup_menu_array )
+                       {
+                               struct menu_priv* priv = (struct menu_priv*)g_array_index( popup_menu_array, gint, LOWORD(wParam) - POPUP_MENU_OFFSET );
+
+                               if ( priv )
+                               {
+                                       struct callback* cb = priv->cb;
+                                       if ( priv->cb )
+                                       {
+                                               callback_call_0( priv->cb );
+                                               return 0;
+                                       }
+                               }
+                       }
+
                        switch(LOWORD(wParam))
                        {
                                case ID_DISPLAY_ZOOMIN:
@@ -134,27 +310,23 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
                                case ID_FILE_EXIT:
                                        PostMessage(hwnd, WM_CLOSE, 0, 0);
                                break;
-                               case ID_STUFF_GO:
-                                                                       (*g_gra->resize_callback)(g_gra->resize_callback_data, g_gra->width, g_gra->height);
-
-//                                     navit_draw(gui->nav);
-                                       // MessageBox(hwnd, "You clicked Go!", "Woo!", MB_OK);
-                               break;
                        }
+                       return 0;
                }
                break;
                case WM_USER+ 1:
-                       printf( "wm_user \n" );
-                       (*g_gra->resize_callback)( g_gra->resize_callback_data, g_gra->width, g_gra->height );
+            GetClientRect(hwnd, &rcClient);
+                       printf( "resize gui to: %d %d \n", rcClient.right, rcClient.bottom );
+
+                       window_layout( hwnd );
+            //EnumChildWindows(hwnd, EnumChildProc, (LPARAM) &rcClient);
+            return 0;
                break;
                case WM_CLOSE:
                        DestroyWindow(hwnd);
                break;
                case WM_SIZE:
-            GetClientRect(hwnd, &rcClient);
-                       printf( "resize gui to: %d %d \n", rcClient.right, rcClient.bottom );
-
-            EnumChildWindows(hwnd, EnumChildProc, (LPARAM) &rcClient);
+                       window_layout( hwnd );
             return 0;
                break;
                case WM_DESTROY:
@@ -195,12 +367,12 @@ HANDLE CreateWin32Window( void )
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 32;
        wc.hInstance     = NULL;
-       wc.hIcon                 = NULL;
        wc.hCursor               = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
        wc.lpszMenuName  = NULL;
        wc.lpszClassName = g_szClassName;
-       wc.hIconSm               = NULL;
+       wc.hIconSm               = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_NAVIT));
+       wc.hIcon                 = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_NAVIT));
 
        if(!RegisterClassEx(&wc))
        {
@@ -251,10 +423,6 @@ static int win32_gui_add_bookmark(struct gui_priv *gui, struct pcoord *c, char *
        return 1;
 }
 
-struct menu_priv {
-       HWND wnd_handle;
-       HMENU hMenu;
-};
 
 static struct menu_methods menu_methods;
 
@@ -283,6 +451,12 @@ static struct menu_priv *add_menu( struct menu_priv *menu,
        {
                AppendMenu( menu->hMenu, MF_STRING, menu_id, name );
        }
+
+       // g_hash_table_insert( popup_callback_hash, GINT_TO_POINTER( menu_id ),  (gpointer)cb );
+       g_array_append_val( popup_menu_array, ret );
+
+       ret->cb = cb;
+
        menu_id++;
 
        return ret;
@@ -308,17 +482,22 @@ static struct menu_methods menu_methods = {
 
 static void popup_activate(struct menu_priv *menu)
 {
-       POINT menu_pt = { 200,200 };
-       POINT pnt = menu_pt;
-
-       ClientToScreen(menu->wnd_handle, (LPPOINT) &pnt);
+       POINT pnt;
+       GetCursorPos( &pnt );
 
        if (menu->hMenu)
        {
-               TrackPopupMenu (menu->hMenu, 0, pnt.x, pnt.y, 0, menu->wnd_handle, NULL);
+               TrackPopupMenu( menu->hMenu, 0, pnt.x, pnt.y, 0, menu->wnd_handle, NULL );
+               DestroyMenu( menu->hMenu );
        }
 }
 
+
+static void popup_deactivate( struct menu_priv *menu )
+{
+       DestroyMenu( menu->hMenu );
+}
+
 struct menu_priv* win32_gui_popup_new(struct gui_priv *this_, struct menu_methods *meth)
 {
        struct menu_priv* ret = NULL;
@@ -326,8 +505,17 @@ struct menu_priv* win32_gui_popup_new(struct gui_priv *this_, struct menu_method
        ret = g_new0(struct menu_priv, 1);
        *meth = menu_methods;
 
-       menu_id = 4000;
+       menu_id = POPUP_MENU_OFFSET;
+
+       if ( popup_menu_array )
+       {
+               g_array_free (popup_menu_array, TRUE);
+               popup_menu_array = NULL;
+       }
+
+       popup_menu_array = g_array_new (FALSE, FALSE, sizeof (gint));
 
+       ret->cb = NULL;
        ret->hMenu = CreatePopupMenu();
        ret->wnd_handle = this_->hwnd;
        meth->popup=popup_activate;
index 8c763b1..977bb41 100644 (file)
@@ -1,23 +1,28 @@
 #ifndef WIN32_GUI_INCLUDED
 #define WIN32_GUI_INCLUDED
 
+#include "resources\resource.h"
 #include "coord.h"
 #include "point.h"
 #include "graphics.h"
 
-#define ID_CHILD_GFX 2000
-#define ID_CHILD_1 2001
-#define ID_CHILD_2 ID_CHILD_1 + 1
-#define ID_CHILD_3 ID_CHILD_2 + 1
-#define ID_CHILD_4 ID_CHILD_4 + 1
-#define ID_DISPLAY_ZOOMIN 8000
-#define ID_DISPLAY_ZOOMOUT 8001
+#define ID_CHILD_GFX 100
+#define ID_CHILD_TOOLBAR (ID_CHILD_GFX + 1)
+#define ID_CHILD_1 (ID_CHILD_TOOLBAR + 1)
+#define ID_CHILD_2 (ID_CHILD_1 + 1)
+#define ID_CHILD_3 (ID_CHILD_2 + 1)
+#define ID_CHILD_4 (ID_CHILD_4 + 1)
 
-#define ID_FILE_EXIT 9001
-#define ID_STUFF_GO 9002
+#define ID_DISPLAY_ZOOMIN              200
+#define ID_DISPLAY_ZOOMOUT             201
+#define ID_DISPLAY_REFRESH             202
+
+#define ID_FILE_EXIT           9001
+#define ID_STUFF_GO            9002
 
 #define _(text) gettext(text)
 
+#define POPUP_MENU_OFFSET  4000
 
 struct statusbar_methods;
 struct menu_methods;
@@ -25,6 +30,13 @@ struct datawindow_methods;
 struct navit;
 struct callback;
 
+
+struct menu_priv {
+       HWND wnd_handle;
+       HMENU hMenu;
+       struct callback* cb;
+};
+
 struct gui_priv {
        struct navit *nav;
        HANDLE  hwnd;