Пример #1
0
bool wxApp::Initialize(int& argC, wxChar **argV)
{
#if !wxUSE_NANOX
    // install the X error handler
    gs_pfnXErrorHandler = XSetErrorHandler( wxXErrorHandler );
#endif

    wxString displayName;
    bool syncDisplay = false;

    int argCOrig = argC;
    for ( int i = 0; i < argCOrig; i++ )
    {
        if (wxStrcmp( argV[i], wxT("-display") ) == 0)
        {
            if (i < (argCOrig - 1))
            {
                argV[i++] = NULL;

                displayName = argV[i];

                argV[i] = NULL;
                argC -= 2;
            }
        }
        else if (wxStrcmp( argV[i], wxT("-geometry") ) == 0)
        {
            if (i < (argCOrig - 1))
            {
                argV[i++] = NULL;

                int w, h;
                if (wxSscanf(argV[i], wxT("%dx%d"), &w, &h) != 2)
                {
                    wxLogError( _("Invalid geometry specification '%s'"),
                                wxString(argV[i]).c_str() );
                }
                else
                {
                    g_initialSize = wxSize(w, h);
                }

                argV[i] = NULL;
                argC -= 2;
            }
        }
        else if (wxStrcmp( argV[i], wxT("-sync") ) == 0)
        {
            syncDisplay = true;

            argV[i] = NULL;
            argC--;
        }
        else if (wxStrcmp( argV[i], wxT("-iconic") ) == 0)
        {
            g_showIconic = true;

            argV[i] = NULL;
            argC--;
        }
    }

    if ( argC != argCOrig )
    {
        // remove the arguments we consumed
        for ( int i = 0; i < argC; i++ )
        {
            while ( !argV[i] )
            {
                memmove(argV + i, argV + i + 1, (argCOrig - i)*sizeof(wxChar *));
            }
        }
    }

    // open and set up the X11 display
    if ( !wxSetDisplay(displayName) )
    {
        wxLogError(_("wxWidgets could not open display. Exiting."));
        return false;
    }

    Display *dpy = wxGlobalDisplay();
    if (syncDisplay)
        XSynchronize(dpy, True);

    XSelectInput(dpy, XDefaultRootWindow(dpy), PropertyChangeMask);

    wxSetDetectableAutoRepeat( true );


    if ( !wxAppBase::Initialize(argC, argV) )
        return false;

#if wxUSE_UNICODE
    // Glib's type system required by Pango
    g_type_init();
#endif

#if wxUSE_INTL
    wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
#endif

    wxWidgetHashTable = new wxWindowHash;
    wxClientWidgetHashTable = new wxWindowHash;

    return true;
}
Пример #2
0
bool wxApp::Initialize(int& argc, wxChar **argv)
{
    bool init_result;

#if wxUSE_THREADS
    if (!g_thread_supported())
        g_thread_init(NULL);

    wxgs_poll_func = g_main_context_get_poll_func(NULL);
    g_main_context_set_poll_func(NULL, wxapp_poll_func);
#endif // wxUSE_THREADS

    gtk_set_locale();

    // We should have the wxUSE_WCHAR_T test on the _outside_
#if wxUSE_WCHAR_T
    // gtk+ 2.0 supports Unicode through UTF-8 strings
    wxConvCurrent = &wxConvUTF8;
#else // !wxUSE_WCHAR_T
    if (!wxOKlibc())
        wxConvCurrent = (wxMBConv*) NULL;
#endif // wxUSE_WCHAR_T/!wxUSE_WCHAR_T

    // decide which conversion to use for the file names

    // (1) this variable exists for the sole purpose of specifying the encoding
    //     of the filenames for GTK+ programs, so use it if it is set
    wxString encName(wxGetenv(_T("G_FILENAME_ENCODING")));
    encName = encName.BeforeFirst(_T(','));
    if (encName.CmpNoCase(_T("@locale")) == 0)
        encName.clear();
    encName.MakeUpper();
#if wxUSE_INTL
    if (encName.empty())
    {
        // (2) if a non default locale is set, assume that the user wants his
        //     filenames in this locale too
        encName = wxLocale::GetSystemEncodingName().Upper();
        // (3) finally use UTF-8 by default
        if (encName.empty() || encName == _T("US-ASCII"))
            encName = _T("UTF-8");
        wxSetEnv(_T("G_FILENAME_ENCODING"), encName);
    }
#else
    if (encName.empty())
        encName = _T("UTF-8");
#endif // wxUSE_INTL

#if wxUSE_WCHAR_T
    static wxConvBrokenFileNames fileconv(encName);
    wxConvFileName = &fileconv;
#endif // wxUSE_WCHAR_T

#if wxUSE_UNICODE
    // gtk_init() wants UTF-8, not wchar_t, so convert
    int i;
    char **argvGTK = new char *[argc + 1];
    for ( i = 0; i < argc; i++ )
    {
        argvGTK[i] = wxStrdupA(wxConvUTF8.cWX2MB(argv[i]));
    }

    argvGTK[argc] = NULL;

    int argcGTK = argc;

#ifdef __WXGPE__
    init_result = true;  // is there a _check() version of this?
    gpe_application_init( &argcGTK, &argvGTK );
#else
    init_result = gtk_init_check( &argcGTK, &argvGTK );
#endif

    if ( argcGTK != argc )
    {
        // we have to drop the parameters which were consumed by GTK+
        for ( i = 0; i < argcGTK; i++ )
        {
            while ( strcmp(wxConvUTF8.cWX2MB(argv[i]), argvGTK[i]) != 0 )
            {
                memmove(argv + i, argv + i + 1, (argc - i)*sizeof(*argv));
            }
        }

        argc = argcGTK;
    }
    //else: gtk_init() didn't modify our parameters

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

    delete [] argvGTK;
#else // !wxUSE_UNICODE
    // gtk_init() shouldn't actually change argv itself (just its contents) so
    // it's ok to pass pointer to it
    init_result = gtk_init_check( &argc, &argv );
#endif // wxUSE_UNICODE/!wxUSE_UNICODE

    if (!init_result) {
        wxLogError(wxT("Unable to initialize gtk, is DISPLAY set properly?"));
        return false;
    }

    // update internal arg[cv] as GTK+ may have removed processed options:
    this->argc = argc;
    this->argv = argv;

    // we can not enter threads before gtk_init is done
    gdk_threads_enter();

    if ( !wxAppBase::Initialize(argc, argv) )
    {
        gdk_threads_leave();

        return false;
    }

    wxSetDetectableAutoRepeat( true );

#if wxUSE_INTL
    wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
#endif

    return true;
}