#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) ;
};
-struct graphics_priv *g_gra;
+//struct graphics_priv *g_gra;
+
static HDC hMemDC;
static HBITMAP hBitmap;
static HBITMAP hOldBitmap;
}
}
-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);
}
}
{
//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:
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;
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:
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);
}
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);
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;
}
g_free( gc );
}
-static HPEN line_pen;
-
static void gc_set_linewidth(struct graphics_gc_priv *gc, int w)
{
gc->line_width = w;
{
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 );
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++ )
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 );
}
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)
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 ) ;
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) ;
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;
}
{
struct graphics_priv *this_=g_new0(struct graphics_priv,1);
*meth=graphics_methods;
- g_gra = this_;
this_->mode = -1;
return this_;
}
#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);
-
-
-
-extern struct graphics_priv *g_gra;
+//extern struct graphics_priv *g_gra;
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;
#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:
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:
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))
{
return 1;
}
-struct menu_priv {
- HWND wnd_handle;
- HMENU hMenu;
-};
static struct menu_methods menu_methods;
{
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;
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;
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;