From: <hba...@us...> - 2010-01-20 02:21:27
|
Revision: 10758 http://plplot.svn.sourceforge.net/plplot/?rev=10758&view=rev Author: hbabcock Date: 2010-01-20 02:21:19 +0000 (Wed, 20 Jan 2010) Log Message: ----------- Initial commit of a very basic (but working) Windows Cairo driver. Move the cairo devices to the 100+ range so that they can be sequentially numbered and not overlap with the Qt devices. Changes have not been styled. Modified Paths: -------------- trunk/cmake/modules/cairo.cmake trunk/cmake/modules/drivers-init.cmake trunk/drivers/cairo.c trunk/drivers/cairo.rc.in trunk/examples/plplot_configure.cmake_installed_examples.in trunk/include/drivers.h trunk/include/plDevs.h.cmake trunk/include/plcore.h trunk/plplot_test/plplot-test.sh.cmake Modified: trunk/cmake/modules/cairo.cmake =================================================================== --- trunk/cmake/modules/cairo.cmake 2010-01-19 00:11:03 UTC (rev 10757) +++ trunk/cmake/modules/cairo.cmake 2010-01-20 02:21:19 UTC (rev 10758) @@ -29,6 +29,7 @@ # PLD_pscairo - ON means the pscairo device is enabled. # PLD_svgcairo - ON means the svgcairo device is enabled. # PLD_xcairo - ON means the xcairo device is enabled. +# PLD_wincairo - ON means the wincairo device is enabled. # cairo_COMPILE_FLAGS - Blank-delimited COMPILE_FLAGS required to # compile cairo device drivers. # cairo_LINK_FLAGS - list of full path names of libraries and @@ -55,6 +56,7 @@ OR PLD_svgcairo OR PLD_xcairo OR PLD_extcairo +OR PLD_wincairo ) if(NOT PKG_CONFIG_EXECUTABLE) message(STATUS @@ -67,6 +69,7 @@ set(PLD_svgcairo OFF CACHE BOOL "Enable svgcairo device" FORCE) set(PLD_xcairo OFF CACHE BOOL "Enable xcairo device" FORCE) set(PLD_extcairo OFF CACHE BOOL "Enable extcairo device" FORCE) + set(PLD_wincairo OFF CACHE BOOL "Enable wincairo device" FORCE) endif(NOT PKG_CONFIG_EXECUTABLE) endif( PLD_memcairo @@ -76,6 +79,7 @@ OR PLD_svgcairo OR PLD_xcairo OR PLD_extcairo +OR PLD_wincairo ) if( @@ -86,6 +90,7 @@ OR PLD_svgcairo OR PLD_xcairo OR PLD_extcairo +OR PLD_wincairo ) pkg_check_pkgconfig( pangocairo @@ -145,6 +150,7 @@ set(PLD_svgcairo OFF CACHE BOOL "Enable svgcairo device" FORCE) set(PLD_xcairo OFF CACHE BOOL "Enable xcairo device" FORCE) set(PLD_extcairo OFF CACHE BOOL "Enable extcairo device" FORCE) + set(PLD_wincairo OFF CACHE BOOL "Enable wincairo device" FORCE) endif(linkflags) endif( PLD_memcairo @@ -154,6 +160,7 @@ OR PLD_svgcairo OR PLD_xcairo OR PLD_extcairo +OR PLD_wincairo ) if(NOT PLD_xcairo) @@ -163,3 +170,10 @@ if(NOT PLD_extcairo) set(extcairo_true "#") endif(NOT PLD_extcairo) + +if(NOT WIN32) + message(STATUS + "WARNING: Not a Windows Computer. Setting wincairo driver to OFF." + ) + set(PLD_wincairo OFF CACHE BOOL "Enable wincairo device" FORCE) +endif(NOT WIN32) Modified: trunk/cmake/modules/drivers-init.cmake =================================================================== --- trunk/cmake/modules/drivers-init.cmake 2010-01-19 00:11:03 UTC (rev 10757) +++ trunk/cmake/modules/drivers-init.cmake 2010-01-20 02:21:19 UTC (rev 10758) @@ -136,6 +136,7 @@ "pscairo:cairo:ON:F:OFF" "svgcairo:cairo:ON:F:ON" "xcairo:cairo:ON:I:OFF" + "wincairo:cairo:ON:I:OFF" # new example 16 shows severe valgrind issues with this device. "cgm:cgm:OFF:F:OFF" # This unmaintained device driver builds but does not actually work Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2010-01-19 00:11:03 UTC (rev 10757) +++ trunk/drivers/cairo.c 2010-01-20 02:21:19 UTC (rev 10758) @@ -57,8 +57,10 @@ #if defined ( PLD_svgcairo ) #include <cairo-svg.h> #endif +#if defined ( PLD_wincairo ) +#include <windows.h> +#endif - /*--------------------------------------------------------------------- * Constants & global (to this file) variables * ---------------------------------------------------------------------*/ @@ -113,30 +115,40 @@ unsigned char *cairo_format_memory; char bigendian; #endif +#if defined ( PLD_wincairo ) + WNDCLASSEX wndclass; + HWND hwnd; + MSG msg; + HDC hdc; + HDC SCRN_hdc; +#endif } PLCairo; PLDLLIMPEXP_DRIVER const char* plD_DEVICE_INFO_cairo = #if defined ( PLD_xcairo ) - "xcairo:Cairo X Windows Driver:1:cairo:59:xcairo\n" + "xcairo:Cairo X Windows Driver:1:cairo:100:xcairo\n" #endif #if defined ( PLD_pdfcairo ) - "pdfcairo:Cairo PDF Driver:0:cairo:60:pdfcairo\n" + "pdfcairo:Cairo PDF Driver:0:cairo:101:pdfcairo\n" #endif #if defined ( PLD_pscairo ) - "pscairo:Cairo PS Driver:0:cairo:61:pscairo\n" + "pscairo:Cairo PS Driver:0:cairo:102:pscairo\n" #endif #if defined ( PLD_svgcairo ) - "svgcairo:Cairo SVG Driver:0:cairo:62:svgcairo\n" + "svgcairo:Cairo SVG Driver:0:cairo:103:svgcairo\n" #endif #if defined ( PLD_pngcairo ) - "pngcairo:Cairo PNG Driver:0:cairo:63:pngcairo\n" + "pngcairo:Cairo PNG Driver:0:cairo:104:pngcairo\n" #endif #if defined ( PLD_memcairo ) - "memcairo:Cairo Memory Driver:0:cairo:64:memcairo\n" + "memcairo:Cairo Memory Driver:0:cairo:105:memcairo\n" #endif #if defined ( PLD_extcairo ) - "extcairo:Cairo External Context Driver:0:cairo:65:extcairo\n" + "extcairo:Cairo External Context Driver:0:cairo:106:extcairo\n" #endif +#if defined ( PLD_wincairo ) + "wincairo:Cairo Microscoft Windows Driver:0:cairo:107:wincairo\n" +#endif ; /* @@ -2553,3 +2565,314 @@ } #endif + + +/*--------------------------------------------------------------------- + * --------------------------------------------------------------------- + * + * That which is specific to the cairo microsoft windows driver. + * + * Much of the Windows specific code here was lifted from the wingcc + * driver. + * + * --------------------------------------------------------------------- + * ---------------------------------------------------------------------*/ + +#if defined ( PLD_wincairo ) + +static char* szWndClass = "PLplot WinCairo"; + +void plD_dispatch_init_wincairo( PLDispatchTable *pdt ); +void plD_init_wincairo( PLStream * ); +//void plD_bop_extcairo( PLStream * ); +void plD_eop_wincairo( PLStream * ); +//void plD_esc_extcairo( PLStream *, PLINT, void * ); +void plD_tidy_wincairo( PLStream * ); + +/*--------------------------------------------------------------------------*\ + * This is the window function for the plot window. Whenever a message is + * dispatched using DispatchMessage (or sent with SendMessage) this function + * gets called with the contents of the message. + \*--------------------------------------------------------------------------*/ + +LRESULT CALLBACK PlplotCairoWndProc( HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam ) +{ + PLStream *pls = NULL; + PLCairo *dev = NULL; + +/* + * The window carries a 32bit user defined pointer which points to the + * plplot stream (pls). This is used for tracking the window. + * Unfortunately, this is "attached" to the window AFTER it is created + * so we can not initialise PLStream or wingcc_Dev "blindly" because + * they may not yet have been initialised. + * WM_CREATE is called before we get to initialise those variables, so + * we wont try to set them. + */ + + if ( nMsg == WM_CREATE ) + { + return ( 0 ); + } + else + { + pls = (PLStream *) GetWindowLong( hwnd, GWL_USERDATA ); /* Try to get the address to pls for this window */ + if ( pls ) /* If we got it, then we will initialise this windows plplot private data area */ + { + dev = (PLCairo *) pls->dev; + } + } + +/* + * Process the windows messages + * + * Everything except WM_CREATE is done here and it is generally hoped that + * pls and dev are defined already by this stage. + * That will be true MOST of the time. Some times WM_PAINT will be called + * before we get to initialise the user data area of the window with the + * pointer to the windows plplot stream + */ + + switch ( nMsg ) + { + case WM_DESTROY: + // if ( dev ) + // Debug( "WM_DESTROY\t" ); + PostQuitMessage( 0 ); + return ( 0 ); + break; + + case WM_PAINT: + return ( 1 ); + break; + + case WM_SIZE: + return ( 0 ); + break; + + case WM_ENTERSIZEMOVE: + return ( 0 ); + break; + + case WM_EXITSIZEMOVE: + return ( 0 ); + break; + + case WM_ERASEBKGND: + return ( 0 ); + break; + + case WM_COMMAND: + return ( 0 ); + break; + } + + /* If we don't handle a message completely we hand it to the system + * provided default window function. */ + return DefWindowProc( hwnd, nMsg, wParam, lParam ); +} + +/*--------------------------------------------------------------------- + * dispatch_init_init() + * + * Initialize device dispatch table + * ----------------------------------------------------------------------*/ + +/* extcairo */ +void plD_dispatch_init_wincairo( PLDispatchTable *pdt ) +{ +#ifndef ENABLE_DYNDRIVERS + pdt->pl_MenuStr = "Cairo Microsoft Windows driver"; + pdt->pl_DevName = "wincairo"; +#endif + pdt->pl_type = plDevType_FileOriented; + pdt->pl_seq = 65; + pdt->pl_init = (plD_init_fp) plD_init_wincairo; + pdt->pl_line = (plD_line_fp) plD_line_cairo; + pdt->pl_polyline = (plD_polyline_fp) plD_polyline_cairo; + pdt->pl_bop = (plD_bop_fp) plD_bop_cairo; + pdt->pl_eop = (plD_eop_fp) plD_eop_wincairo; + pdt->pl_tidy = (plD_tidy_fp) plD_tidy_wincairo; + pdt->pl_state = (plD_state_fp) plD_state_cairo; + pdt->pl_esc = (plD_esc_fp) plD_esc_cairo; +} + +/*--------------------------------------------------------------------- + * plD_init_wincairo() + * + * Initialize Cairo Microsoft Windows driver. + * ----------------------------------------------------------------------*/ + +void plD_init_wincairo( PLStream *pls ) +{ + PLCairo *aStream; + + /* Setup the PLStream and the font lookup table */ + aStream = stream_and_font_setup( pls, 0 ); + + /* Save the pointer to the structure in the PLplot stream */ + pls->dev = aStream; + + /* Create window */ + memset( &aStream->wndclass, 0, sizeof ( WNDCLASSEX )); + + /* This class is called WinTestWin */ + aStream->wndclass.lpszClassName = szWndClass; + + /* cbSize gives the size of the structure for extensibility. */ + aStream->wndclass.cbSize = sizeof ( WNDCLASSEX ); + + /* All windows of this class redraw when resized. */ + aStream->wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC | CS_PARENTDC; + + /* All windows of this class use the PlplotCairoWndProc window function. */ + aStream->wndclass.lpfnWndProc = PlplotCairoWndProc; + + /* This class is used with the current program instance. */ + + aStream->wndclass.hInstance = GetModuleHandle( NULL ); + + /* Use standard application icon and arrow cursor provided by the OS */ + aStream->wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION ); + aStream->wndclass.hIconSm = LoadIcon( NULL, IDI_APPLICATION ); + aStream->wndclass.hCursor = LoadCursor( NULL, IDC_ARROW ); + /* Color the background white */ + aStream->wndclass.hbrBackground = NULL; + + aStream->wndclass.cbWndExtra = sizeof ( pls ); + + + /* + * Now register the window class for use. + */ + + RegisterClassEx( &aStream->wndclass ); + + /* + * Create our main window using that window class. + */ + aStream->hwnd = CreateWindowEx( WS_EX_WINDOWEDGE + WS_EX_LEFT, + szWndClass, /* Class name */ + pls->program, /* Caption */ + WS_OVERLAPPEDWINDOW, /* Style */ + pls->xoffset, /* Initial x (use default) */ + pls->yoffset, /* Initial y (use default) */ + /* This is a little lame since the window border size might change. */ + pls->xlength+5, /* Initial x size (use default) */ + pls->ylength+30, /* Initial y size (use default) */ + NULL, /* No parent window */ + NULL, /* No menu */ + aStream->wndclass.hInstance, /* This program instance */ + NULL /* Creation parameters */ + ); + + +/* + * Attach a pointer to the stream to the window's user area + * this pointer will be used by the windows call back for + * process this window + */ + + SetWindowLong( aStream->hwnd, GWL_USERDATA, (long) pls ); + aStream->SCRN_hdc = aStream->hdc = GetDC( aStream->hwnd ); + +/* + * Setup the popup menu + */ + +/* + dev->PopupMenu = CreatePopupMenu(); + AppendMenu( dev->PopupMenu, MF_STRING, PopupPrint, "Print" ); + AppendMenu( dev->PopupMenu, MF_STRING, PopupNextPage, "Next Page" ); + AppendMenu( dev->PopupMenu, MF_STRING, PopupQuit, "Quit" ); +*/ + + // plD_state_wingcc( pls, PLSTATE_COLOR0 ); + /* + * Display the window which we just created (using the nShow + * passed by the OS, which allows for start minimized and that + * sort of thing). + */ + ShowWindow( aStream->hwnd, SW_SHOWDEFAULT ); + SetForegroundWindow( aStream->hwnd ); + +/* + * Now we have to find out, from windows, just how big our drawing area is + * when we specified the page size earlier on, that includes the borders, + * title bar etc... so now that windows has done all its initialisations, + * we will ask how big the drawing area is, and tell plplot + */ + +/* + GetClientRect( dev->hwnd, &dev->rect ); + dev->width = dev->rect.right; + dev->height = dev->rect.bottom; +*/ + +/* + * Initialize Cairo Surface using the windows hdc. + */ + + aStream->cairoSurface = (cairo_surface_t *)cairo_win32_surface_create(aStream->hdc); + aStream->cairoContext = cairo_create(aStream->cairoSurface); + + /* Invert the surface so that the graphs are drawn right side up. */ + rotate_cairo_surface( pls, 1.0, 0.0, 0.0, -1.0, 0.0, pls->ylength ); + + /* Set graphics aliasing */ + cairo_set_antialias( aStream->cairoContext, aStream->graphics_anti_aliasing ); +} + +/*--------------------------------------------------------------------- + * plD_eop_wincairo() + * + * Clean up Cairo Microsoft Windows driver. + * ---------------------------------------------------------------------*/ + +void +plD_eop_wincairo( PLStream *pls ) +{ + PLCairo *aStream = (PLCairo *) pls->dev; + + if ( !pls->nopause ) + { + while ( GetMessage( &aStream->msg, NULL, 0, 0 )) + { + TranslateMessage( &aStream->msg ); + switch ((int) aStream->msg.message ) + { + case WM_CHAR: + if (((TCHAR) ( aStream->msg.wParam ) == 13 ) || + ((TCHAR) ( aStream->msg.wParam ) == 'q' ) || + ((TCHAR) ( aStream->msg.wParam ) == 'Q' )) + { + PostQuitMessage( 0 ); + } + break; + + default: + DispatchMessage( &aStream->msg ); + break; + } + } + } +} + +/*--------------------------------------------------------------------- + * plD_tidy_wincairo() + * + * Clean up Cairo Microsoft Windows driver. + * ---------------------------------------------------------------------*/ + +void plD_tidy_wincairo( PLStream *pls ) +{ + PLCairo *aStream = (PLCairo *) pls->dev; + + if ( aStream != NULL ) + { + if ( aStream->hdc != NULL ) ReleaseDC( aStream->hwnd, aStream->hdc ); + free_mem( pls->dev ); + } +} + +#endif Modified: trunk/drivers/cairo.rc.in =================================================================== --- trunk/drivers/cairo.rc.in 2010-01-19 00:11:03 UTC (rev 10757) +++ trunk/drivers/cairo.rc.in 2010-01-20 02:21:19 UTC (rev 10758) @@ -1,7 +1,8 @@ -xcairo:Cairo X Windows Driver:1:cairo:59:xcairo -pdfcairo:Cairo PDF Driver:0:cairo:60:pdfcairo -pscairo:Cairo PS Driver:0:cairo:61:pscairo -svgcairo:Cairo SVG Driver:0:cairo:62:svgcairo -pngcairo:Cairo PNG Driver:0:cairo:63:pngcairo -memcairo:Cairo Memory Driver:0:cairo:64:memcairo -extcairo:Cairo External Context Driver:0:cairo:65:extcairo +xcairo:Cairo X Windows Driver:1:cairo:100:xcairo +pdfcairo:Cairo PDF Driver:0:cairo:101:pdfcairo +pscairo:Cairo PS Driver:0:cairo:102:pscairo +svgcairo:Cairo SVG Driver:0:cairo:103:svgcairo +pngcairo:Cairo PNG Driver:0:cairo:104:pngcairo +memcairo:Cairo Memory Driver:0:cairo:105:memcairo +extcairo:Cairo External Context Driver:0:cairo:106:extcairo +wincairo:Cairo Microscoft Windows Driver:0:cairo:107:wincairo \ No newline at end of file Modified: trunk/examples/plplot_configure.cmake_installed_examples.in =================================================================== --- trunk/examples/plplot_configure.cmake_installed_examples.in 2010-01-19 00:11:03 UTC (rev 10757) +++ trunk/examples/plplot_configure.cmake_installed_examples.in 2010-01-20 02:21:19 UTC (rev 10758) @@ -198,6 +198,7 @@ set(PLD_ntk @PLD_ntk@) set(PLD_qtwidget @PLD_qtwidget@) set(PLD_tk @PLD_tk@) +set(PLD_wincairo @PLD_wincairo@) set(PLD_wingcc @PLD_wingcc@) set(PLD_wxwidgets @PLD_wxwidgets@) set(PLD_xcairo @PLD_xcairo@) Modified: trunk/include/drivers.h =================================================================== --- trunk/include/drivers.h 2010-01-19 00:11:03 UTC (rev 10757) +++ trunk/include/drivers.h 2010-01-20 02:21:19 UTC (rev 10758) @@ -97,6 +97,7 @@ PLDLLIMPEXP_DRIVER void plD_dispatch_init_pngcairo( PLDispatchTable *pdt ); PLDLLIMPEXP_DRIVER void plD_dispatch_init_memcairo( PLDispatchTable *pdt ); PLDLLIMPEXP_DRIVER void plD_dispatch_init_extcairo( PLDispatchTable *pdt ); +PLDLLIMPEXP_DRIVER void plD_dispatch_init_wincairo( PLDispatchTable *pdt ); PLDLLIMPEXP_DRIVER void plD_dispatch_init_bmpqt( PLDispatchTable *pdt ); PLDLLIMPEXP_DRIVER void plD_dispatch_init_jpgqt( PLDispatchTable *pdt ); PLDLLIMPEXP_DRIVER void plD_dispatch_init_pngqt( PLDispatchTable *pdt ); Modified: trunk/include/plDevs.h.cmake =================================================================== --- trunk/include/plDevs.h.cmake 2010-01-19 00:11:03 UTC (rev 10757) +++ trunk/include/plDevs.h.cmake 2010-01-20 02:21:19 UTC (rev 10758) @@ -85,6 +85,7 @@ #cmakedefine PLD_pngcairo #cmakedefine PLD_memcairo #cmakedefine PLD_extcairo +#cmakedefine PLD_wincairo #cmakedefine PLD_bmpqt #cmakedefine PLD_jpgqt #cmakedefine PLD_pngqt Modified: trunk/include/plcore.h =================================================================== --- trunk/include/plcore.h 2010-01-19 00:11:03 UTC (rev 10757) +++ trunk/include/plcore.h 2010-01-20 02:21:19 UTC (rev 10758) @@ -297,6 +297,9 @@ #if defined ( PLD_extcairo ) && !defined ( ENABLE_DYNDRIVERS ) plD_dispatch_init_extcairo, #endif +#if defined ( PLD_wincairo ) && !defined ( ENABLE_DYNDRIVERS ) + plD_dispatch_init_wincairo, +#endif #if defined ( PLD_bmpqt ) && !defined ( ENABLE_DYNDRIVERS ) plD_dispatch_init_bmpqt, #endif Modified: trunk/plplot_test/plplot-test.sh.cmake =================================================================== --- trunk/plplot_test/plplot-test.sh.cmake 2010-01-19 00:11:03 UTC (rev 10757) +++ trunk/plplot_test/plplot-test.sh.cmake 2010-01-20 02:21:19 UTC (rev 10758) @@ -305,6 +305,7 @@ #interactive PLD_tkwin=@PLD_tkwin@ PLD_versaterm=@PLD_versaterm@ PLD_vlt=@PLD_vlt@ +#interactive PLD_wincairo=@PLD_wincairo@ #interactive PLD_wingcc=@PLD_wingcc@ PLD_wxpng=@PLD_wxpng@ #interactive PLD_wxwidgets=@PLD_wxwidgets@ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |