diff options
author | Pixel <pixel@nobis-crew.org> | 2009-11-04 11:56:41 -0800 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2009-11-04 11:59:33 -0800 |
commit | d577d991b97ae2b5ee1af23641bcffc3f83af5b2 (patch) | |
tree | 590639d50205d1bcfaff2a7d2dc6ebf3f373c7ed /iup/src/mot/iupmot_open.c |
Initial import. Contains the im, cd and iup librairies, and a "working" Makefile for them under linux.
Diffstat (limited to 'iup/src/mot/iupmot_open.c')
-rwxr-xr-x | iup/src/mot/iupmot_open.c | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/iup/src/mot/iupmot_open.c b/iup/src/mot/iupmot_open.c new file mode 100755 index 0000000..a59dbff --- /dev/null +++ b/iup/src/mot/iupmot_open.c @@ -0,0 +1,141 @@ +/** \file + * \brief Motif Open/Close + * + * See Copyright Notice in "iup.h" + */ + +#include <stdlib.h> +#include <stdio.h> +#include <locale.h> +#include <string.h> + +#include <Xm/Xm.h> + +#include "iup.h" + +#include "iup_object.h" +#include "iup_str.h" +#include "iup_drv.h" +#include "iup_globalattrib.h" + +#include "iupmot_drv.h" +#include "iupmot_color.h" + + +/* global variables */ +Widget iupmot_appshell = 0; +Display* iupmot_display = 0; +int iupmot_screen = 0; +Visual* iupmot_visual = 0; +XtAppContext iupmot_appcontext = 0; + +void* iupdrvGetDisplay(void) +{ + return iupmot_display; +} + +void iupmotSetGlobalColorAttrib(Widget w, const char* xmname, const char* name) +{ + unsigned char r, g, b; + Pixel color; + + XtVaGetValues(w, xmname, &color, NULL); + iupmotColorGetRGB(color, &r, &g, &b); + + iupGlobalSetDefaultColorAttrib(name, r, g, b); +} + +int iupdrvOpen(int *argc, char ***argv) +{ + IupSetGlobal("DRIVER", "Motif"); + + /* XtSetLanguageProc(NULL, NULL, NULL); + Removed to avoid invalid locale in modern Linux that set LANG=en_US.UTF-8 */ + + /* We do NOT use XtVaOpenApplication because it crashes when using internal dummy argc and argv. + iupmot_appshell = XtVaOpenApplication(&iupmot_appcontext, "Iup", NULL, 0, argc, *argv, NULL, + sessionShellWidgetClass, NULL); */ + + XtToolkitInitialize(); + + iupmot_appcontext = XtCreateApplicationContext(); + + iupmot_display = XtOpenDisplay(iupmot_appcontext, NULL, NULL, "Iup", NULL, 0, argc, *argv); + if (!iupmot_display) + { + fprintf (stderr, "IUP error: cannot open display.\n"); + return IUP_ERROR; + } + + iupmot_appshell = XtAppCreateShell(NULL, "Iup", sessionShellWidgetClass, iupmot_display, NULL, 0); + if (!iupmot_appshell) + { + fprintf(stderr, "IUP error: cannot create shell.\n"); + return IUP_ERROR; + } + IupSetGlobal("APPSHELL", (char*)iupmot_appshell); + + IupStoreGlobal("SYSTEMLANGUAGE", setlocale(LC_ALL, NULL)); + + iupmot_screen = XDefaultScreen(iupmot_display); + + IupSetGlobal("XDISPLAY", (char*)iupmot_display); + IupSetGlobal("XSCREEN", (char*)iupmot_screen); + + /* screen depth can be 8bpp, but canvas can be 24bpp */ + { + XVisualInfo vinfo; + if (XMatchVisualInfo(iupmot_display, iupmot_screen, 24, TrueColor, &vinfo) || + XMatchVisualInfo(iupmot_display, iupmot_screen, 16, TrueColor, &vinfo)) + { + iupmot_visual = vinfo.visual; + IupSetGlobal("TRUECOLORCANVAS", "YES"); + } + else + { + iupmot_visual = DefaultVisual(iupmot_display, iupmot_screen); + IupSetGlobal("TRUECOLORCANVAS", "NO"); + } + } + + /* driver system version */ + { + int major = xmUseVersion/1000; + int minor = xmUseVersion - major * 1000; + IupSetfAttribute(NULL, "MOTIFVERSION", "%d.%d", major, minor); + IupSetfAttribute(NULL, "MOTIFNUMBER", "%d", (XmVERSION * 1000 + XmREVISION * 100 + XmUPDATE_LEVEL)); + + IupSetGlobal("XSERVERVENDOR", ServerVendor(iupmot_display)); + IupSetfAttribute(NULL, "XVENDORRELEASE", "%d", VendorRelease(iupmot_display)); + } + + iupmotColorInit(); + + /* dialog background color */ + { + iupmotSetGlobalColorAttrib(iupmot_appshell, XmNbackground, "DLGBGCOLOR"); + iupGlobalSetDefaultColorAttrib("DLGFGCOLOR", 0, 0, 0); + IupSetGlobal("_IUP_RESET_DLGBGCOLOR", "YES"); /* will update the DLGFGCOLOR when the first dialog is mapped */ + + iupGlobalSetDefaultColorAttrib("TXTBGCOLOR", 255, 255, 255); + iupGlobalSetDefaultColorAttrib("TXTFGCOLOR", 0, 0, 0); + IupSetGlobal("_IUP_RESET_TXTCOLORS", "YES"); /* will update the TXTCOLORS when the first text or list is mapped */ + } + + if (getenv("IUP_DEBUG")) + XSynchronize(iupmot_display, 1); + + return IUP_NOERROR; +} + +void iupdrvClose(void) +{ + iupmotColorFinish(); + iupmotTipsFinish(); + + if (iupmot_appshell) + XtDestroyWidget(iupmot_appshell); + + if (iupmot_appcontext) + XtDestroyApplicationContext(iupmot_appcontext); +} |