diff --git a/lib/framework/Makefile.am b/lib/framework/Makefile.am index 35ccb793f..2541ed0bb 100644 --- a/lib/framework/Makefile.am +++ b/lib/framework/Makefile.am @@ -4,7 +4,8 @@ AM_CXXFLAGS = $(WZ_CXXFLAGS) $(QT4_CFLAGS) AM_LFLAGS = $(FLEX_FLAGS) AM_YFLAGS = -d -MOCHEADER = wzapp.h wzconfig.h +MOCHEADER = \ + wzconfig.h MOCEDFILES = $(MOCHEADER:%.h=%_moc.cpp) %_moc.cpp: %.h @@ -23,7 +24,6 @@ EXTRA_DIST = \ noinst_LIBRARIES = libframework.a noinst_HEADERS = \ $(MOCHEADER) \ - wzapp_c.h \ crc.h \ cursors.h \ debug.h \ @@ -59,11 +59,9 @@ noinst_HEADERS = \ wzglobal.h nodist_libframework_a_SOURCES = \ - wzapp_moc.cpp \ wzconfig_moc.cpp libframework_a_SOURCES = \ - wzapp.cpp \ wzconfig.cpp \ resource_lexer.lpp \ resource_parser.ypp \ diff --git a/lib/framework/wzapp_c.h b/lib/framework/wzapp_c.h index 15f2894d3..609d1ddf9 100644 --- a/lib/framework/wzapp_c.h +++ b/lib/framework/wzapp_c.h @@ -21,6 +21,10 @@ #ifndef __INCLUDED_WZAPP_C_H__ #define __INCLUDED_WZAPP_C_H__ +#include "frame.h" + +#include + struct _wzThread; struct _wzMutex; struct _wzSemaphore; @@ -29,6 +33,9 @@ typedef struct _wzThread WZ_THREAD; typedef struct _wzMutex WZ_MUTEX; typedef struct _wzSemaphore WZ_SEMAPHORE; +void wzMain(int &argc, char **argv); +bool wzMain2(); +void wzMain3(); void wzQuit(void); ///< Quit game void wzSetCursor(CURSOR index); void wzScreenFlip(void); ///< Swap the graphics buffers @@ -38,6 +45,9 @@ void wzReleaseMouse(void); ///< Undo the wzGrabMouse operation bool wzActiveWindow(void); ///< Whether application currently has the mouse pointer over it int wzGetTicks(void); ///< Milliseconds since start of game void wzFatalDialog(const char *text); ///< Throw up a modal warning dialog +QList wzAvailableResolutions(); ///< Get list of available resolutions. +void wzSetSwapInterval(bool swap); +bool wzGetSwapInterval(); // Thread related WZ_THREAD *wzThreadCreate(int (*threadFunc)(void *), void *data); diff --git a/lib/qtgame/Makefile.am b/lib/qtgame/Makefile.am index f28b222f7..4f4306a06 100644 --- a/lib/qtgame/Makefile.am +++ b/lib/qtgame/Makefile.am @@ -2,7 +2,9 @@ AM_CPPFLAGS = $(WZ_CPPFLAGS) $(QT4_CFLAGS) $(GLEW_CFLAGS) AM_CFLAGS = $(WZ_CFLAGS) AM_CXXFLAGS = $(WZ_CXXFLAGS) $(QT4_CFLAGS) -MOCHEADER = qtgame.h +MOCHEADER = \ + qtgame.h \ + wzapp_qt.h MOCEDFILES = $(MOCHEADER:%.h=%_moc.cpp) %_moc.cpp: %.h @@ -15,11 +17,17 @@ EXTRA_DIST = \ macosx_screen_resolutions.h macosx_screen_resolutions.cpp noinst_LIBRARIES = libqtgame.a -noinst_HEADERS = qtgame.h swapinterval.h $(MOCHEADER) +noinst_HEADERS = \ + $(MOCHEADER) \ + qtgame.h \ + swapinterval.h nodist_libqtgame_a_SOURCES = \ - qtgame_moc.cpp + qtgame_moc.cpp \ + wzapp_qt_moc.cpp libqtgame_a_SOURCES = \ + main_qt.cpp \ qtgame.cpp \ - swapinterval.cpp + swapinterval.cpp \ + wzapp_qt.cpp diff --git a/lib/qtgame/main_qt.cpp b/lib/qtgame/main_qt.cpp new file mode 100644 index 000000000..d075153c3 --- /dev/null +++ b/lib/qtgame/main_qt.cpp @@ -0,0 +1,95 @@ +#include + +#include "lib/framework/frame.h" +#include "lib/ivis_opengl/pieclip.h" +#include "src/warzoneconfig.h" +#include "lib/framework/frameint.h" +#include "wzapp_qt.h" + + +QApplication *appPtr; +WzMainWindow *mainWindowPtr; + +void wzMain(int &argc, char **argv) +{ + appPtr = new QApplication(argc, argv); +} + +bool wzMain2() +{ + debug(LOG_MAIN, "Qt initialization"); + QGL::setPreferredPaintEngine(QPaintEngine::OpenGL); // Workaround for incorrect text rendering on nany platforms. + + // Setting up OpenGL + QGLFormat format; + format.setDoubleBuffer(true); + format.setAlpha(true); + int w = pie_GetVideoBufferWidth(); + int h = pie_GetVideoBufferHeight(); + + if (war_getFSAA()) + { + format.setSampleBuffers(true); + format.setSamples(war_getFSAA()); + } + mainWindowPtr = new WzMainWindow(QSize(w, h), format); + WzMainWindow &mainwindow = *mainWindowPtr; + mainwindow.setMinimumResolution(QSize(800, 600)); + if (!mainwindow.context()->isValid()) + { + QMessageBox::critical(NULL, "Oops!", "Warzone2100 failed to create an OpenGL context. This probably means that your graphics drivers are out of date. Try updating them!"); + return false; + } + + screenWidth = w; + screenHeight = h; + if (war_getFullscreen()) + { + mainwindow.resize(w,h); + mainwindow.showFullScreen(); + if(w>mainwindow.width()) { + w = mainwindow.width(); + } + if(h>mainwindow.height()) { + h = mainwindow.height(); + } + pie_SetVideoBufferWidth(w); + pie_SetVideoBufferHeight(h); + } + else + { + mainwindow.show(); + mainwindow.setMinimumSize(w, h); + mainwindow.setMaximumSize(w, h); + } + + mainwindow.setSwapInterval(war_GetVsync()); + war_SetVsync(mainwindow.swapInterval() > 0); + + mainwindow.setReadyToPaint(); + + return true; +} + +void wzMain3() +{ + QApplication &app = *appPtr; + WzMainWindow &mainwindow = *mainWindowPtr; + mainwindow.update(); // kick off painting, needed on macosx + app.exec(); +} + +QList wzAvailableResolutions() +{ + return WzMainWindow::instance()->availableResolutions(); +} + +void wzSetSwapInterval(bool swap) +{ + WzMainWindow::instance()->setSwapInterval(swap); +} + +bool wzGetSwapInterval() +{ + return WzMainWindow::instance()->swapInterval() > 0; +} diff --git a/lib/framework/wzapp.cpp b/lib/qtgame/wzapp_qt.cpp similarity index 99% rename from lib/framework/wzapp.cpp rename to lib/qtgame/wzapp_qt.cpp index 92a59d309..08d7edf33 100644 --- a/lib/framework/wzapp.cpp +++ b/lib/qtgame/wzapp_qt.cpp @@ -31,18 +31,18 @@ // Get platform defines before checking for them. // Qt headers MUST come before platform specific stuff! -#include "wzapp.h" +#include "wzapp_qt.h" #if defined(WZ_CC_MSVC) #include "wzapp.h.moc" // this is generated on the pre-build event. #endif #include "lib/exceptionhandler/dumpinfo.h" -#include "file.h" +#include "lib/framework/file.h" #include "lib/ivis_opengl/piestate.h" #include "lib/ivis_opengl/pieclip.h" #include "lib/ivis_opengl/screen.h" -#include "wzapp_c.h" +#include "lib/framework/wzapp_c.h" #include "src/main.h" #include "src/configuration.h" #include "lib/gamelib/gtime.h" diff --git a/lib/framework/wzapp.h b/lib/qtgame/wzapp_qt.h similarity index 98% rename from lib/framework/wzapp.h rename to lib/qtgame/wzapp_qt.h index b908495b4..e4cf020a6 100644 --- a/lib/framework/wzapp.h +++ b/lib/qtgame/wzapp_qt.h @@ -30,14 +30,14 @@ #include #include -#include "lib/qtgame/qtgame.h" +#include "qtgame.h" // Get platform defines before checking for them. // Qt headers MUST come before platform specific stuff! #include "lib/framework/frame.h" #include "lib/framework/cursors.h" #include "lib/ivis_opengl/textdraw.h" -#include "input.h" +#include "lib/framework/input.h" class WzMainWindow : public QtGameWidget { diff --git a/lib/sdl/Makefile.am b/lib/sdl/Makefile.am new file mode 100644 index 000000000..5734c1902 --- /dev/null +++ b/lib/sdl/Makefile.am @@ -0,0 +1,10 @@ +AM_CPPFLAGS = -DYY_NO_INPUT $(WZ_CPPFLAGS) +AM_CFLAGS = $(WZ_CFLAGS) +AM_CXXFLAGS = $(WZ_CXXFLAGS) + +noinst_LIBRARIES = libsdl.a +noinst_HEADERS = \ + scrap.h + +libframework_a_SOURCES = \ + scrap.cpp diff --git a/lib/sdl/main_sdl.cpp b/lib/sdl/main_sdl.cpp new file mode 100644 index 000000000..93c33caa0 --- /dev/null +++ b/lib/sdl/main_sdl.cpp @@ -0,0 +1,17 @@ +#include + + +void wzMain(int &argc, char **argv) +{ + QCoreApplication app(argc, argv); // For Qt-script. +} + +bool wzMain2() +{ + return true; +} + +void wzMain3() +{ + mainLoop(); +} diff --git a/lib/sdl/scrap.cpp b/lib/sdl/scrap.cpp new file mode 100644 index 000000000..c23b70e15 --- /dev/null +++ b/lib/sdl/scrap.cpp @@ -0,0 +1,645 @@ +/* + This file is part of Warzone 2100. + Copyright (C) 1999-2004 Eidos Interactive + Copyright (C) 2005-2011 Warzone 2100 Project + + Warzone 2100 is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + Warzone 2100 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 Warzone 2100; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +/** @file + * Handle clipboard text and data in arbitrary formats + */ + +#include "lib/framework/frame.h" + +#include +#include + +#include "scrap.h" + +/* System dependent data types */ +#if defined(WZ_WS_X11) +/* * */ +typedef Atom scrap_type; + +#elif defined(WZ_WS_WIN) +/* * */ +typedef UDWORD scrap_type; + +#elif defined(WZ_WS_QNX) +/* * */ +typedef uint32_t scrap_type; +#define Ph_CL_TEXT T('T', 'E', 'X', 'T') + +#elif defined(WZ_WS_MAC) +/* * */ +typedef uint32_t scrap_type; /* FIXME */ + +#endif /* scrap type */ + +/* System dependent variables */ +#if defined(WZ_WS_X11) +/* * */ +static Display *SDL_Display; +static Window SDL_Window; +static void (*Lock_Display)(void); +static void (*Unlock_Display)(void); + +#elif defined(WZ_WS_WIN) +/* * */ +static HWND SDL_Window; + +#elif defined(WZ_WS_QNX) +/* * */ +static unsigned short InputGroup; + +#endif /* scrap type */ + +#define FORMAT_PREFIX "SDL_scrap_0x" + +static scrap_type +convert_format(int type) +{ +switch (type) + { + + case T('T', 'E', 'X', 'T'): +#if defined(WZ_WS_X11) +/* * */ + return XA_STRING; + +#elif defined(WZ_WS_WIN) +/* * */ + return CF_TEXT; + +#elif defined(WZ_WS_QNX) +/* * */ + return Ph_CL_TEXT; + +#endif /* scrap type */ + + default: + { + char format[sizeof(FORMAT_PREFIX)+8+1]; + + snprintf(format, sizeof(format), "%s%08lx", FORMAT_PREFIX, (unsigned long)type); + +#if defined(WZ_WS_X11) +/* * */ + return XInternAtom(SDL_Display, format, False); + +#elif defined(WZ_WS_WIN) +/* * */ + return RegisterClipboardFormatA(format); + +#elif defined(WZ_WS_MAC) +/* * */ + // Meaningless value to prevent "control reaches end of non-void function" warning + return 0; + +#endif /* scrap type */ + } + } +} + +/* Convert internal data to scrap format */ +static int +convert_data(int type, char *dst, char *src, int srclen) +{ + int dstlen; + + dstlen = 0; + switch (type) + { + case T('T', 'E', 'X', 'T'): + if ( dst ) + { + while ( --srclen >= 0 ) + { +#if defined(__unix__) + if ( *src == '\r' ) + { + *dst++ = '\n'; + ++dstlen; + } + else +#elif defined(__WIN32__) + if ( *src == '\r' ) + { + *dst++ = '\r'; + ++dstlen; + *dst++ = '\n'; + ++dstlen; + } + else +#endif + { + *dst++ = *src; + ++dstlen; + } + ++src; + } + *dst = '\0'; + ++dstlen; + } + else + { + while ( --srclen >= 0 ) + { +#if defined(__unix__) + if ( *src == '\r' ) + { + ++dstlen; + } + else +#elif defined(__WIN32__) + if ( *src == '\r' ) + { + ++dstlen; + ++dstlen; + } + else +#endif + { + ++dstlen; + } + ++src; + } + ++dstlen; + } + break; + + default: + if ( dst ) + { + *(int *)dst = srclen; + dst += sizeof(int); + memcpy(dst, src, srclen); + } + dstlen = sizeof(int)+srclen; + break; + } + return(dstlen); +} + +/* Convert scrap data to internal format */ +#if (defined(WZ_WS_X11) || defined(WZ_WS_WIN) || defined(WZ_WS_QNX)) +static int +convert_scrap(int type, char *dst, char *src, int srclen) +{ +int dstlen; + +dstlen = 0; +switch (type) + { + case T('T', 'E', 'X', 'T'): + { + if ( srclen == 0 ) + srclen = strlen(src); + if ( dst ) + { + while ( --srclen >= 0 ) + { +#if defined(__WIN32__) + if ( *src == '\r' ) + /* drop extraneous '\r' */; + else +#endif + if ( *src == '\n' ) + { + *dst++ = '\r'; + ++dstlen; + } + else + { + *dst++ = *src; + ++dstlen; + } + ++src; + } + *dst = '\0'; + ++dstlen; + } + else + { + while ( --srclen >= 0 ) + { +#if defined(__WIN32__) + if ( *src == '\r' ) + /* drop extraneous '\r' */; + else +#endif + ++dstlen; + ++src; + } + ++dstlen; + } + } + break; + + default: + dstlen = *(int *)src; + if ( dst ) + { + if ( srclen == 0 ) + memcpy(dst, src+sizeof(int), dstlen); + else + memcpy(dst, src+sizeof(int), srclen-sizeof(int)); + } + break; + } +return dstlen; +} +#endif + +#if defined(WZ_WS_X11) +/* The system message filter function -- handle clipboard messages */ +static int clipboard_filter(const SDL_Event *event); +#endif + +int +init_scrap(void) +{ +SDL_SysWMinfo info; +int retval; + +/* Grab the window manager specific information */ +retval = -1; +SDL_SetError("SDL is not running on known window manager"); + +SDL_VERSION(&info.version); +if ( SDL_GetWMInfo(&info) ) + { + /* Save the information for later use */ +#if defined(WZ_WS_X11) +/* * */ + if ( info.subsystem == SDL_SYSWM_X11 ) + { + SDL_Display = info.info.x11.display; + SDL_Window = info.info.x11.window; + Lock_Display = info.info.x11.lock_func; + Unlock_Display = info.info.x11.unlock_func; + + /* Enable the special window hook events */ + SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); + SDL_SetEventFilter(clipboard_filter); + + retval = 0; + } + else + { + SDL_SetError("SDL is not running on X11"); + } + +#elif defined(WZ_WS_WIN) +/* * */ + SDL_Window = info.window; + retval = 0; + +#elif defined(WZ_WS_QNX) +/* * */ + InputGroup=PhInputGroup(NULL); + retval = 0; + +#endif /* scrap type */ + } +return(retval); +} + +int lost_scrap(void) +{ + int retval = 0; + +#if defined(WZ_WS_X11) + Lock_Display(); + retval = ( XGetSelectionOwner(SDL_Display, XA_PRIMARY) != SDL_Window ); + Unlock_Display(); +#elif defined(WZ_WS_WIN) + retval = ( GetClipboardOwner() != SDL_Window ); +#elif defined(WZ_WS_QNX) + retval = ( PhInputGroup(NULL) != InputGroup ); +#endif /* scrap type */ + return(retval); +} + +void +put_scrap(int type, int srclen, char *src) +{ + scrap_type format; + int dstlen; +#if (defined(WZ_WS_X11) || defined(WZ_WS_WIN) || defined(WZ_WS_QNX)) + char *dst; +#endif + + format = convert_format(type); + dstlen = convert_data(type, NULL, src, srclen); + +#if defined(WZ_WS_X11) + dst = (char *)malloc(dstlen); + if ( dst != NULL ) + { + Lock_Display(); + convert_data(type, dst, src, srclen); + XChangeProperty(SDL_Display, DefaultRootWindow(SDL_Display), + XA_CUT_BUFFER0, format, 8, PropModeReplace, (unsigned char *)dst, dstlen); + free(dst); + if ( lost_scrap() ) + XSetSelectionOwner(SDL_Display, XA_PRIMARY, SDL_Window, CurrentTime); + Unlock_Display(); + } + +#elif defined(WZ_WS_WIN) +/* * */ +if ( OpenClipboard(SDL_Window) ) + { + HANDLE hMem; + + hMem = GlobalAlloc((GMEM_MOVEABLE|GMEM_DDESHARE), dstlen); + if ( hMem != NULL ) + { + dst = (char *)GlobalLock(hMem); + convert_data(type, dst, src, srclen); + GlobalUnlock(hMem); + EmptyClipboard(); + SetClipboardData(format, hMem); + } + CloseClipboard(); + } + +#elif defined(WZ_WS_QNX) +/* * */ +#if (_NTO_VERSION < 620) /* before 6.2.0 releases */ +{ + PhClipHeader clheader={Ph_CLIPBOARD_TYPE_TEXT, 0, NULL}; + int* cldata; + int status; + + dst = (char *)malloc(dstlen+4); + if (dst != NULL) + { + cldata=(int*)dst; + *cldata=type; + convert_data(type, dst+4, src, srclen); + clheader.data=dst; + if (dstlen>65535) + { + clheader.length=65535; /* maximum photon clipboard size :( */ + } + else + { + clheader.length=dstlen+4; + } + status=PhClipboardCopy(InputGroup, 1, &clheader); + if (status==-1) + { + fprintf(stderr, "Photon: copy to clipboard was failed !\n"); + } + free(dst); + } +} +#else /* 6.2.0 and 6.2.1 and future releases */ +{ + PhClipboardHdr clheader={Ph_CLIPBOARD_TYPE_TEXT, 0, NULL}; + int* cldata; + int status; + + dst = (char *)malloc(dstlen+4); + if (dst != NULL) + { + cldata=(int*)dst; + *cldata=type; + convert_data(type, dst+4, src, srclen); + clheader.data=dst; + clheader.length=dstlen+4; + status=PhClipboardWrite(InputGroup, 1, &clheader); + if (status==-1) + { + fprintf(stderr, "Photon: copy to clipboard was failed !\n"); + } + free(dst); + } +} +#endif +#endif /* scrap type */ +} + +void +get_scrap(int type, int *dstlen, char **dst) +{ + scrap_type format; + + *dstlen = 0; + format = convert_format(type); + +#if defined(WZ_WS_X11) +/* * */ +{ + Window owner; + Atom selection; + Atom seln_type; + int seln_format; + unsigned long nbytes; + unsigned long overflow; + unsigned char * src; + + Lock_Display(); + owner = XGetSelectionOwner(SDL_Display, XA_PRIMARY); + Unlock_Display(); + if ( (owner == None) || (owner == SDL_Window) ) + { + owner = DefaultRootWindow(SDL_Display); + selection = XA_CUT_BUFFER0; + } + else + { + int selection_response = 0; + SDL_Event event; + + owner = SDL_Window; + Lock_Display(); + selection = XInternAtom(SDL_Display, "SDL_SELECTION", False); + XConvertSelection(SDL_Display, XA_PRIMARY, format, + selection, owner, CurrentTime); + Unlock_Display(); + while ( ! selection_response ) + { + SDL_WaitEvent(&event); + if ( event.type == SDL_SYSWMEVENT ) + { + XEvent xevent = event.syswm.msg->event.xevent; + + if ( (xevent.type == SelectionNotify) && + (xevent.xselection.requestor == owner) ) + selection_response = 1; + } + } + } + Lock_Display(); + if ( XGetWindowProperty(SDL_Display, owner, selection, 0, INT_MAX/4, + False, format, &seln_type, &seln_format, + &nbytes, &overflow, &src) == Success ) + { + if ( seln_type == format ) + { + *dstlen = convert_scrap(type, NULL, (char*)src, nbytes); + *dst = (char *)realloc(*dst, *dstlen); + if ( *dst == NULL ) + *dstlen = 0; + else + convert_scrap(type, *dst, (char*)src, nbytes); + } + XFree(src); + } + Unlock_Display(); +} + +#elif defined(WZ_WS_WIN) +/* * */ + if ( IsClipboardFormatAvailable(format) && OpenClipboard(SDL_Window) ) + { + HANDLE hMem; + char *src; + + hMem = GetClipboardData(format); + if ( hMem != NULL ) + { + src = (char *)GlobalLock(hMem); + *dstlen = convert_scrap(type, NULL, src, 0); + *dst = (char *)realloc(*dst, *dstlen); + if ( *dst == NULL ) + *dstlen = 0; + else + convert_scrap(type, *dst, src, 0); + GlobalUnlock(hMem); + } + CloseClipboard(); + } +#elif defined(WZ_WS_QNX) +/* * */ +#if (_NTO_VERSION < 620) /* before 6.2.0 releases */ +{ + void* clhandle; + PhClipHeader* clheader; + int* cldata; + + clhandle=PhClipboardPasteStart(InputGroup); + if (clhandle!=NULL) + { + clheader=PhClipboardPasteType(clhandle, Ph_CLIPBOARD_TYPE_TEXT); + if (clheader!=NULL) + { + cldata=clheader->data; + if ((clheader->length>4) && (*cldata==type)) + { + *dstlen = convert_scrap(type, NULL, (char*)clheader->data+4, clheader->length-4); + *dst = (char *)realloc(*dst, *dstlen); + if (*dst == NULL) + { + *dstlen = 0; + } + else + { + convert_scrap(type, *dst, (char*)clheader->data+4, clheader->length-4); + } + } + } + PhClipboardPasteFinish(clhandle); + } +} +#else /* 6.2.0 and 6.2.1 and future releases */ +{ + void* clhandle; + PhClipboardHdr* clheader; + int* cldata; + + clheader=PhClipboardRead(InputGroup, Ph_CLIPBOARD_TYPE_TEXT); + if (clheader!=NULL) + { + cldata=clheader->data; + if ((clheader->length>4) && (*cldata==type)) + { + *dstlen = convert_scrap(type, NULL, (char*)clheader->data+4, clheader->length-4); + *dst = (char *)realloc(*dst, *dstlen); + if (*dst == NULL) + { + *dstlen = 0; + } + else + { + convert_scrap(type, *dst, (char*)clheader->data+4, clheader->length-4); + } + } + } +} +#endif +#endif /* scrap type */ +} + +#if defined(WZ_WS_X11) +static int clipboard_filter(const SDL_Event *event) +{ + /* Post all non-window manager specific events */ + if (event->type != SDL_SYSWMEVENT) + { + return(1); + } + + /* Handle window-manager specific clipboard events */ + switch (event->syswm.msg->event.xevent.type) { + /* Copy the selection from XA_CUT_BUFFER0 to the requested property */ + case SelectionRequest: { + XSelectionRequestEvent *req; + XEvent sevent; + int seln_format; + unsigned long nbytes; + unsigned long overflow; + unsigned char *seln_data; + + req = &event->syswm.msg->event.xevent.xselectionrequest; + sevent.xselection.type = SelectionNotify; + sevent.xselection.display = req->display; + sevent.xselection.selection = req->selection; + sevent.xselection.target = None; + sevent.xselection.property = None; + sevent.xselection.requestor = req->requestor; + sevent.xselection.time = req->time; + if ( XGetWindowProperty(SDL_Display, DefaultRootWindow(SDL_Display), + XA_CUT_BUFFER0, 0, INT_MAX/4, False, req->target, + &sevent.xselection.target, &seln_format, + &nbytes, &overflow, &seln_data) == Success ) + { + if ( sevent.xselection.target == req->target ) + { + if ( sevent.xselection.target == XA_STRING ) + { + if ( seln_data[nbytes-1] == '\0' ) + --nbytes; + } + XChangeProperty(SDL_Display, req->requestor, req->property, + sevent.xselection.target, seln_format, PropModeReplace, + seln_data, nbytes); + sevent.xselection.property = req->property; + } + XFree(seln_data); + } + XSendEvent(SDL_Display,req->requestor,False,0,&sevent); + XSync(SDL_Display, False); + } + break; +} + +/* Post the event for X11 clipboard reading above */ +return(1); +} +#endif /* WZ_WS_X11 */ diff --git a/lib/sdl/scrap.h b/lib/sdl/scrap.h new file mode 100644 index 000000000..1ae8e12f3 --- /dev/null +++ b/lib/sdl/scrap.h @@ -0,0 +1,35 @@ +/* + This file is part of Warzone 2100. + Copyright (C) 1999-2004 Eidos Interactive + Copyright (C) 2005-2011 Warzone 2100 Project + + Warzone 2100 is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + Warzone 2100 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 Warzone 2100; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +/** @file + * Handle clipboard text and data in arbitrary formats + */ + +#ifndef __INCLUDED_LIB_WIDGET_SCRAP_H__ +#define __INCLUDED_LIB_WIDGET_SCRAP_H__ + +/* Miscellaneous defines */ +#define T(A, B, C, D) (int)((A<<24)|(B<<16)|(C<<8)|(D<<0)) + +extern int init_scrap(void); +extern int lost_scrap(void); +extern void put_scrap(int type, int srclen, char *src); +extern void get_scrap(int type, int *dstlen, char **dst); + +#endif // __INCLUDED_LIB_WIDGET_SCRAP_H__ diff --git a/src/configuration.cpp b/src/configuration.cpp index 4ea044d51..ab7fb431b 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -24,12 +24,13 @@ */ #include -#include "lib/framework/wzapp.h" +#include "lib/framework/wzapp_c.h" #include "lib/framework/wzconfig.h" #include "lib/framework/input.h" #include "lib/netplay/netplay.h" #include "lib/sound/mixer.h" #include "lib/ivis_opengl/screen.h" +#include "lib/framework/opengl.h" #include "advvis.h" #include "ai.h" diff --git a/src/effects.cpp b/src/effects.cpp index 3ccd4ad27..55b9ae12e 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -35,7 +35,7 @@ * STILL NEED TO REMOVE SOME MAGIC NUMBERS INTO #DEFINES!!! * ************************************************************ */ -#include "lib/framework/wzapp.h" +#include "lib/framework/wzapp_c.h" #include "lib/framework/wzconfig.h" #include "lib/framework/frameresource.h" #include "lib/framework/input.h" diff --git a/src/frontend.cpp b/src/frontend.cpp index cf71945d0..1683dafcc 100644 --- a/src/frontend.cpp +++ b/src/frontend.cpp @@ -24,7 +24,7 @@ * Alex Lee. Pumpkin Studios. Eidos PLC 98, */ -#include "lib/framework/wzapp.h" +#include "lib/framework/wzapp_c.h" #if defined(WZ_OS_WIN) # include /* For ShellExecute */ @@ -798,7 +798,7 @@ static bool startVideoOptionsMenu(void) bool runVideoOptionsMenu(void) { - QList modes = WzMainWindow::instance()->availableResolutions(); + QList modes = wzAvailableResolutions(); UDWORD id = widgRunScreen(psWScreen); int level; @@ -934,8 +934,8 @@ bool runVideoOptionsMenu(void) case FRONTEND_VSYNC: case FRONTEND_VSYNC_R: { - WzMainWindow::instance()->setSwapInterval(!war_GetVsync()); - war_SetVsync(WzMainWindow::instance()->swapInterval() > 0); + wzSetSwapInterval(!war_GetVsync()); + war_SetVsync(wzGetSwapInterval()); if (war_GetVsync()) { widgSetString(psWScreen, FRONTEND_VSYNC_R, _("On")); diff --git a/src/game.cpp b/src/game.cpp index 376a936f7..d00332511 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -17,7 +17,7 @@ along with Warzone 2100; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "lib/framework/wzapp.h" +#include "lib/framework/wzapp_c.h" #include /* Standard library headers */ diff --git a/src/main.cpp b/src/main.cpp index 8b13860f4..f975bddfa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,7 +22,7 @@ */ // Get platform defines before checking for them! -#include "lib/framework/wzapp.h" +#include "lib/framework/wzapp_c.h" #include #include #include @@ -1067,7 +1067,7 @@ bool getUTF8CmdLine(int* const utfargc, const char*** const utfargv) // explicit int main(int argc, char *argv[]) { - QApplication app(argc, argv); + wzMain(argc, argv); int utfargc = argc; const char** utfargv = (const char**)argv; @@ -1255,55 +1255,12 @@ int main(int argc, char *argv[]) } } - debug(LOG_MAIN, "Qt initialization"); - QGL::setPreferredPaintEngine(QPaintEngine::OpenGL); // Workaround for incorrect text rendering on nany platforms. - - // Setting up OpenGL - QGLFormat format; - format.setDoubleBuffer(true); - format.setAlpha(true); - int w = pie_GetVideoBufferWidth(); - int h = pie_GetVideoBufferHeight(); - - if (war_getFSAA()) + if (!wzMain2()) { - format.setSampleBuffers(true); - format.setSamples(war_getFSAA()); - } - WzMainWindow mainwindow(QSize(w, h), format); - mainwindow.setMinimumResolution(QSize(800, 600)); - if (!mainwindow.context()->isValid()) - { - QMessageBox::critical(NULL, "Oops!", "Warzone2100 failed to create an OpenGL context. This probably means that your graphics drivers are out of date. Try updating them!"); return EXIT_FAILURE; } - - screenWidth = w; - screenHeight = h; - if (war_getFullscreen()) - { - mainwindow.resize(w,h); - mainwindow.showFullScreen(); - if(w>mainwindow.width()) { - w = mainwindow.width(); - } - if(h>mainwindow.height()) { - h = mainwindow.height(); - } - pie_SetVideoBufferWidth(w); - pie_SetVideoBufferHeight(h); - } - else - { - mainwindow.show(); - mainwindow.setMinimumSize(w, h); - mainwindow.setMaximumSize(w, h); - } - - mainwindow.setSwapInterval(war_GetVsync()); - war_SetVsync(mainwindow.swapInterval() > 0); - - mainwindow.setReadyToPaint(); + int w = pie_GetVideoBufferWidth(); + int h = pie_GetVideoBufferHeight(); char buf[256]; ssprintf(buf, "Video Mode %d x %d (%s)", w, h, war_getFullscreen() ? "fullscreen" : "window"); @@ -1369,8 +1326,7 @@ int main(int argc, char *argv[]) debug_MEMSTATS(); #endif debug(LOG_MAIN, "Entering main loop"); - mainwindow.update(); // kick off painting, needed on macosx - app.exec(); + wzMain3(); saveConfig(); systemShutdown(); debug(LOG_MAIN, "Completed shutting down Warzone 2100"); diff --git a/src/multiint.cpp b/src/multiint.cpp index dd2f5f0ee..2baddcc5a 100644 --- a/src/multiint.cpp +++ b/src/multiint.cpp @@ -26,7 +26,7 @@ */ #include "lib/framework/frame.h" // LEAVE THIS ALONE, it *must* be first for compiler specific fixes. -#include "lib/framework/wzapp.h" +#include "lib/framework/wzapp_c.h" #include "lib/framework/wzconfig.h" #include diff --git a/src/qtscript.cpp b/src/qtscript.cpp index 2773ef13f..d9a918f0c 100644 --- a/src/qtscript.cpp +++ b/src/qtscript.cpp @@ -34,7 +34,7 @@ #include #include -#include "lib/framework/wzapp.h" +#include "lib/framework/wzapp_c.h" #include "lib/framework/wzconfig.h" #include "lib/framework/file.h" #include "lib/gamelib/gtime.h" diff --git a/src/qtscriptfuncs.cpp b/src/qtscriptfuncs.cpp index 1e45e9c1c..9b62121af 100644 --- a/src/qtscriptfuncs.cpp +++ b/src/qtscriptfuncs.cpp @@ -22,7 +22,7 @@ * New scripting system -- script functions */ -#include "lib/framework/wzapp.h" +#include "lib/framework/wzapp_c.h" #include "lib/framework/wzconfig.h" #include "lib/sound/audio.h" #include "lib/netplay/netplay.h" diff --git a/src/scores.cpp b/src/scores.cpp index 769c68739..b01842c65 100644 --- a/src/scores.cpp +++ b/src/scores.cpp @@ -27,7 +27,7 @@ #include // -------------------------------------------------------------------- -#include "lib/framework/wzapp.h" +#include "lib/framework/wzapp_c.h" #include "lib/framework/wzconfig.h" #include "lib/framework/math_ext.h" #include "lib/framework/strres.h" diff --git a/src/scriptfuncs.cpp b/src/scriptfuncs.cpp index 659011488..fb231ee42 100644 --- a/src/scriptfuncs.cpp +++ b/src/scriptfuncs.cpp @@ -24,7 +24,7 @@ * */ -#include "lib/framework/wzapp.h" +#include "lib/framework/wzapp_c.h" #include "lib/framework/strres.h" #include "lib/framework/stdio_ext.h" #include "lib/widget/widget.h" diff --git a/src/scriptobj.cpp b/src/scriptobj.cpp index 36c4d921b..2a0e064ea 100644 --- a/src/scriptobj.cpp +++ b/src/scriptobj.cpp @@ -25,7 +25,7 @@ */ #include -#include "lib/framework/wzapp.h" +#include "lib/framework/wzapp_c.h" #include "lib/framework/wzconfig.h" #include "lib/framework/endian_hack.h" #include "lib/framework/strres.h"