コード例 #1
0
void Application::initialize(std::string name, int argc, char* argv[])
{
  String fallbacks[fallbackResources.size() + 1];
  XtToolkitInitialize();
  context = XtCreateApplicationContext();

  for(unsigned int resourceIndex = 0; resourceIndex < fallbackResources.size(); resourceIndex++)
  {
    fallbacks[resourceIndex] = (char*)fallbackResources.at(resourceIndex).c_str();
  }

  fallbacks[fallbackResources.size()] = NULL;

  XtAppSetFallbackResources(context, fallbacks);
  Application::name = name;

  display = XtOpenDisplay(context, NULL, name.c_str(), name.c_str(), NULL, 0, &argc, argv);

  if(display == NULL)
  {
    throw MotifException("Failed to open display");
  }

  initialized = true;

  widget = XtAppCreateShell(Application::getName().c_str(), Application::getName().c_str(), applicationShellWidgetClass, Application::getDisplay(), NULL, 0);

}
コード例 #2
0
ファイル: nmovie.c プロジェクト: guo2004131/freesurfer
static void XInit(int *argc, char ***argv) {
  XtToolkitInitialize();
  xi.context = XtCreateApplicationContext();
  XtAppSetFallbackResources(xi.context, fallback_resources);
  xi.disp = XtOpenDisplay(xi.context, NULL, "NMovie", "NMovie", NULL, 0,
                          argc, *argv);
  if (!xi.disp)
    ErrorExit(ERROR_BAD_PARM,"Unable to open display");

  shmext = XShmQueryExtension(xi.disp);
  xi.screenno = DefaultScreen(xi.disp);
}
コード例 #3
0
ファイル: kxsconfig.cpp プロジェクト: Fat-Zer/kdeartwork
int main(int argc, char *argv[])
{
  KCmdLineArgs::init(argc, argv, appName, I18N_NOOP("KXSConfig"), description, version);

  KCmdLineArgs::addCmdLineOptions(options);

  KApplication app;

  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
  if(args->count()==0)
    exit(1);

  /* We must read exactly the same resources as xscreensaver.
     That means we must have both the same progclass *and* progname,
     at least as far as the resource database is concerned.  So,
     put "xscreensaver" in argv[0] while initializing Xt.
   */
  const char *dummyargs[] = { "xscreensaver" };
  int dummyargc = 1;
  progname = dummyargs[0];

  // Teach Xt to use the Display that TQt has already opened.
  XtToolkitInitialize ();
  XtAppContext xtApp = XtCreateApplicationContext ();
  Display *dpy = qt_xdisplay();
  XtAppSetFallbackResources (xtApp, const_cast<char**>(defaults));
  XtDisplayInitialize (xtApp, dpy, progname, progclass, 0, 0,
                       &dummyargc,
                       const_cast<char**>(dummyargs));
  Widget toplevel_shell = XtAppCreateShell (progname, progclass,
	  applicationShellWidgetClass,
	  dpy, 0, 0);
  dpy = XtDisplay (toplevel_shell);
  db = XtDatabase (dpy);
  XtGetApplicationNameAndClass (dpy, const_cast<char**>(&progname),
                                const_cast<char**>(&progclass));

  TQString name = TQString::fromLocal8Bit(args->arg(args->count() - 1));
  KXSConfigDialog *dialog=new KXSConfigDialog(args->arg(0), name);
  if ( dialog->create() ) {
      dialog->show();
      app.setMainWidget(dialog);
      app.exec();
  } else {
      KMessageBox::sorry(0,
	      i18n("No configuration available for %1").tqarg(name),
	      name );
  }

  delete dialog;
}
コード例 #4
0
/*!
  Constructs a QApplication and initializes the Xt toolkit.
  The \a appclass, \a options, \a num_options, and \a resources
  arguments are passed on to XtAppSetFallbackResources and
  XtDisplayInitialize.

  Use this constructor when writing a new Qt application which
  needs to use some existing Xt/Motif widgets.
*/
KXtApplication::KXtApplication(int& argc, char** argv,
        const QCString& rAppName, bool allowStyles, bool GUIenabled,
        XrmOptionDescRec *options, int num_options,
        char** resources)
  : KApplication(argc, argv, rAppName, allowStyles, GUIenabled)
{
    my_xt = TRUE;

    XtToolkitInitialize();
    appcon = XtCreateApplicationContext();
    if (resources) XtAppSetFallbackResources(appcon, (char**)resources);
    XtDisplayInitialize(appcon, qt_xdisplay(), name(), rAppName, options,
        num_options, &argc, argv);
    init();
}
コード例 #5
0
ファイル: gtk2xtbin.c プロジェクト: rn10950/RetroZilla
/* Initial Xt plugin */
static void
xt_client_init( XtClient * xtclient, 
                Visual *xtvisual, 
                Colormap xtcolormap,
                int xtdepth)
{
  XtAppContext  app_context;
  char         *mArgv[1];
  int           mArgc = 0;

  /*
   * Initialize Xt stuff
   */
  xtclient->top_widget = NULL;
  xtclient->child_widget = NULL;
  xtclient->xtdisplay  = NULL;
  xtclient->xtvisual   = NULL;
  xtclient->xtcolormap = 0;
  xtclient->xtdepth = 0;

  if (!xt_is_initialized) {
#ifdef DEBUG_XTBIN
    printf("starting up Xt stuff\n");
#endif
    XtToolkitInitialize();
    app_context = XtCreateApplicationContext();
    if (fallback)
      XtAppSetFallbackResources(app_context, fallback);

    xtdisplay = XtOpenDisplay(app_context, gdk_get_display(), NULL, 
                            "Wrapper", NULL, 0, &mArgc, mArgv);
    if (xtdisplay)
      xt_is_initialized = TRUE;
  }
  xtclient->xtdisplay  = xtdisplay;
  xtclient->xtvisual   = xtvisual;
  xtclient->xtcolormap = xtcolormap;
  xtclient->xtdepth    = xtdepth;
}
コード例 #6
0
ファイル: xt_support.c プロジェクト: jocelyn/EiffelStudio
void set_fallback_res (EIF_POINTER w, EIF_OBJ res, EIF_INTEGER count)
{
	int counter = 0;

	if (fallback_list != (String *) 0) {
		String * temp = fallback_list;
		while (temp) eif_rt_xfree (*(temp++));
		eif_rt_xfree (fallback_list);
		fallback_list = (String *) 0;
	}
	if (res != (EIF_OBJ) 0) {
		fallback_list = (String *) cmalloc (count * sizeof (String) + 1);
		while (count > counter) {
			*(fallback_list + counter) = (String) cmalloc (strlen (*((char **)eif_access(res) + counter)) + 1);
			strcpy (*(fallback_list + counter), *((char **)(eif_access (res)) + counter));
			counter++;
		}
		*(fallback_list + counter) = (String) 0;
	}
		
	XtAppSetFallbackResources ((XtAppContext) w, fallback_list);
}
コード例 #7
0
ファイル: i18ninput.c プロジェクト: CPFDSoftware-Tony/gmv
/**************************************************************
 * main:
 **************************************************************/
int main(int argc, char **argv)
{
  Display     * display;
  char          name[132];

  (void) strncpy(name, base(argv[0]), 132);

  /* Initialize the X Intrinsics */
  XtToolkitInitialize();

  /* Set up language environment for X */
  XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL);

  /* Create application context */
  app_context = XtCreateApplicationContext();
  XtAppSetFallbackResources(app_context, fallback_reslist);

  /* open up one display */
  display = XtOpenDisplay(app_context,
                          NULL,
                          name, "XmdI18nInput",
                          (XrmOptionDescRec *)NULL, 0,
                          &argc, argv);
  if (!display) {
    (void) fprintf(stderr, "Unable to open display\n");
    exit(0);
  }

  /* Call init functions. This creates the user interface 
     (placed in input.c) */
  if (dialog_init(&argc, argv, display) != 0)
    exit(1);

  XtAppMainLoop(app_context);

  return 0;    /* make compiler happy */
}
コード例 #8
0
/*
 * ------------------------------------------------------------------------
 * Name: PdmShellCreate
 *
 * Description:
 *
 *     This function creates a top level application shell.
 *
 * Return value:
 *
 *     0 if successful; a PDM_EXIT code if not.
 *
 */
static int
PdmShellCreate(PdmShell* me,
	       const String* fallback_resources,
	       int* argc_in_out, String* argv_in_out)
{
    String app_class;
    String app_name;
    XmPixelSet pixelSets[XmCO_NUM_COLORS];
    XrmClass class_list[3];
    XrmDatabase db;
    XrmName name_list[3];
    XrmRepresentation rep_type;
    XrmValue value;
    int decor;
    int funcs;
    short secondary_id;
    /*
     * create the application context and open the video display
     */
    XtToolkitInitialize();
    XtSetLanguageProc((XtAppContext)NULL, (XtLanguageProc)NULL,
		      (XtPointer)NULL);
    me->app_context = XtCreateApplicationContext();

    XtAppSetFallbackResources(me->app_context, (String*)fallback_resources);

    me->display =
	XtOpenDisplay(me->app_context, (String)NULL,
		      (String)NULL, "Dtpdm",
		      PdmOptions, XtNumber(PdmOptions),
		      argc_in_out, argv_in_out);
    if((Display*)NULL == me->display)
	return PDM_EXIT_VXAUTH;
    XtGetApplicationNameAndClass(me->display, &app_name, &app_class);
    /*
     * the fallback resources are only intended for the video display, so
     * remove them from the application context
     */
    XtAppSetFallbackResources(me->app_context, (String*)NULL);
    /*
     * get the parent video window id from the display's resource database
     */
    db = XtDatabase(me->display);
    name_list[0] = XrmStringToQuark(app_name);
    name_list[1] = XrmStringToQuark("parentWindowStr");
    name_list[2] = NULLQUARK;
    class_list[0] = XrmStringToQuark(app_class);
    class_list[1] = XrmStringToQuark("ParentWindowStr");
    class_list[2] = NULLQUARK;
    XrmQGetResource(db, name_list, class_list, &rep_type, &value);
    if(!value.addr) return PDM_EXIT_ERROR;
    me->parent_window = (Window)strtoul((char*)value.addr, (char**)NULL, 0);
    /*
     * obtain the parent video window's attributes
     */
    if(!XGetWindowAttributes(me->display, me->parent_window, &me->parent_attr))
	return PDM_EXIT_ERROR;
    /*
     * register interest in the DestroyNotify event for the parent window
     */
    XSelectInput(me->display, me->parent_window, StructureNotifyMask);
    /*
     * create the application shell
     */
    decor = MWM_DECOR_ALL | MWM_DECOR_RESIZEH | MWM_DECOR_MINIMIZE
	| MWM_DECOR_MAXIMIZE;
    funcs = MWM_FUNC_ALL | MWM_FUNC_RESIZE | MWM_FUNC_MINIMIZE
	| MWM_FUNC_MAXIMIZE;
    me->widget = 
	XtVaAppCreateShell(app_name, app_class,
			   applicationShellWidgetClass,
			   me->display,
			   XmNdeleteResponse, XmDESTROY,
			   XmNmappedWhenManaged, False,
			   XmNmwmDecorations, decor,
			   XmNmwmFunctions, funcs,
			   XmNmwmInputMode,MWM_INPUT_PRIMARY_APPLICATION_MODAL,
			   XmNscreen, me->parent_attr.screen,
			   XmNtransient, True,
			   NULL);
    /*
     * pick up the secondary color set, so that the PDM presents the same
     * colors as a secondary window. (the XmColorObj is created by the
     * the XmDisplay object, which is created when the app shell is
     * created)
     */
    if(XmeGetColorObjData(XtScreen(me->widget), (int*)NULL,
			  pixelSets, XmCO_NUM_COLORS,
			  (short*)NULL, (short*)NULL, (short*)NULL,
			  &secondary_id, (short*)NULL))
    {
	/*
	 * In the Xrm database, reassign primary color resource values
	 * with the corresponding secondary color values. This will cause
	 * subsequently created widgets that utilize colors from the
	 * primary set to actually present secondary colors.
	 */
	db = XtScreenDatabase(XtScreen(me->widget));
	value.size = sizeof(Pixel);
	value.addr = (char*)&pixelSets[secondary_id].bg;
	XrmPutResource (&db, "*background", "Pixel", &value);
	XrmPutResource (&db, "*frameBackground", "Pixel", &value);
	value.addr = (char*)&pixelSets[secondary_id].fg;
	XrmPutResource (&db, "*foreground", "Pixel", &value);
	XrmPutResource (&db, "*backPageForeground", "Pixel", &value);
	value.addr = (char*)&pixelSets[secondary_id].bs;
	XrmPutResource (&db, "*bottomShadowColor", "Pixel", &value);
	value.addr = (char*)&pixelSets[secondary_id].ts;
	XrmPutResource (&db, "*topShadowColor", "Pixel", &value);
    }
    /*
     * get the application resources
     */
    XtGetApplicationResources(me->widget, me,
			      PdmResources, XtNumber(PdmResources),
			      NULL, 0);
    /*
     * return
     */
    return 0;
}
コード例 #9
0
ファイル: app.cpp プロジェクト: CyberIntelMafia/clamav-devel
bool wxApp::Initialize(int& argc_, wxChar **argv_)
{
#if wxUSE_INTL
    wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
#endif

    if ( !wxAppBase::Initialize(argc_, argv_) )
        return false;

    wxWidgetHashTable = new wxHashTable(wxKEY_INTEGER);

#ifdef __HPUX__
    // under HP-UX creating XmFontSet fails when the system locale is C and
    // we're using a remote DISPLAY, presumably because HP-UX uses its own
    // names for C and ISO locales (roman8 and iso8859n respectively) and so
    // its Motif libraries have troubles with non-HP X server
    //
    // whatever the reason, the fact is that without this hack any wxMotif
    // program crashes on startup because it can't create any font (HP programs
    // still work but they do spit out messages about failing to create font
    // sets and failing back on "fixed" font too)
    //
    // notice that calling setlocale() here is not enough because X(m) init
    // functions call setlocale() later so we really have to change environment
    bool fixAll = false; // tweak LC_ALL (or just LC_CTYPE)?
    const char *loc = getenv("LC_CTYPE");
    if ( !loc )
    {
        loc = getenv("LC_ALL");
        if ( loc )
            fixAll = true;
    }

    if ( !loc ||
            (loc[0] == 'C' && loc[1] == '\0') ||
            strcmp(loc, "POSIX") == 0 )
    {
        // we're using C locale, "fix" it
        wxLogDebug(wxT("HP-UX fontset hack: forcing locale to en_US.iso88591"));
        putenv(fixAll ? "LC_ALL=en_US.iso88591" : "LC_CTYPE=en_US.iso88591");
    }
#endif // __HPUX__

    XtSetLanguageProc(NULL, NULL, NULL);
    XtToolkitInitialize() ;
    wxTheApp->m_appContext = (WXAppContext) XtCreateApplicationContext();

    static char *fallbackResources[] = {
        // better defaults for CDE under Irix
        //
        // TODO: do something similar for the other systems, the hardcoded defaults
        //       below are ugly
#ifdef __SGI__
        wxMOTIF_STR("*sgiMode: True"),
        wxMOTIF_STR("*useSchemes: all"),
#else // !__SGI__
#if !wxMOTIF_USE_RENDER_TABLE
        wxMOTIF_STR("*.fontList: -*-helvetica-medium-r-normal-*-*-120-*-*-*-*-*-*"),
#else
        wxMOTIF_STR("*wxDefaultRendition.fontName: -*-helvetica-medium-r-normal-*-*-120-*-*-*-*-*-*"),
        wxMOTIF_STR("*wxDefaultRendition.fontType: FONT_IS_FONTSET"),
        wxMOTIF_STR("*.renderTable: wxDefaultRendition"),
#endif
        wxMOTIF_STR("*listBox.background: white"),
        wxMOTIF_STR("*text.background: white"),
        wxMOTIF_STR("*comboBox.Text.background: white"),
        wxMOTIF_STR("*comboBox.List.background: white"),
#endif // __SGI__/!__SGI__
        NULL
    };
    XtAppSetFallbackResources((XtAppContext) wxTheApp->m_appContext, fallbackResources);

    // we shouldn't pass empty application/class name as it results in
    // immediate crash inside XOpenIM() (if XIM is used) under IRIX
    wxString appname = wxTheApp->GetAppName();
    if ( appname.empty() )
        appname = wxT("wxapp");
    wxString clsname = wxTheApp->GetClassName();
    if ( clsname.empty() )
        clsname = wxT("wx");

    // FIXME-UTF8: This code is taken from wxGTK and duplicated here. This
    //             is just a temporary fix to make wxX11 compile in Unicode
    //             build, the real fix is to change Initialize()'s signature
    //             to use char* on Unix.
#if wxUSE_UNICODE
    // XtOpenDisplay() wants char*, not wchar_t*, so convert
    int i;
    char **argvX11 = new char *[argc + 1];
    for ( i = 0; i < argc; i++ )
    {
        argvX11[i] = strdup(wxConvLibc.cWX2MB(argv_[i]));
    }

    argvX11[argc] = NULL;

    int argcX11 = argc;

    Display *dpy = XtOpenDisplay((XtAppContext) wxTheApp->m_appContext,
                                 (String)NULL,
                                 appname.c_str(),
                                 clsname.c_str(),
                                 NULL, 0,    // no options
# if XtSpecificationRelease < 5
                                 (Cardinal*) &argcX11,
# else
                                 &argcX11,
# endif
                                 argvX11);

    if ( argcX11 != argc )
    {
        // we have to drop the parameters which were consumed by X11+
        for ( i = 0; i < argcX11; i++ )
        {
            while ( strcmp(wxConvLibc.cWX2MB(argv_[i]), argvX11[i]) != 0 )
            {
                memmove(argv_ + i, argv_ + i + 1, (argc - i)*sizeof(*argv_));
            }
        }

        argc = argcX11;

        // update internal arg[cv] as X11 may have removed processed options:
        argc = argc_;
        argv = argv_;
    }
    //else: XtOpenDisplay() didn't modify our parameters

    // free our copy
    for ( i = 0; i < argcX11; i++ )
    {
        free(argvX11[i]);
    }

    delete [] argvX11;

#else // ANSI

    Display *dpy = XtOpenDisplay((XtAppContext) wxTheApp->m_appContext,
                                 (String)NULL,
                                 appname.c_str(),
                                 clsname.c_str(),
                                 NULL, 0,    // no options
# if XtSpecificationRelease < 5
                                 (Cardinal*) &argc,
# else
                                 &argc,
# endif
                                 argv);

#endif // Unicode/ANSI

    if (!dpy) {
        // if you don't log to stderr, nothing will be shown...
        delete wxLog::SetActiveTarget(new wxLogStderr);
        wxString className(wxTheApp->GetClassName());
        wxLogError(_("wxWidgets could not open display for '%s': exiting."),
                   className.c_str());
        exit(-1);
    }
    m_initialDisplay = (WXDisplay*) dpy;

    // install the X error handler
    gs_pfnXErrorHandler = XSetErrorHandler(wxXErrorHandler);

    // Add general resize proc
    XtActionsRec rec;
    rec.string = wxMOTIF_STR("resize");
    rec.proc = (XtActionProc)wxWidgetResizeProc;
    XtAppAddActions((XtAppContext) wxTheApp->m_appContext, &rec, 1);

    GetMainColormap(dpy);

    wxAddIdleCallback();

    return true;
}