Exemplo n.º 1
0
int wxWindowsPrintDialog::ShowModal()
{
    WX_TESTING_SHOW_MODAL_HOOK();

    ConvertToNative( m_printDialogData );

    PRINTDLG *pd = (PRINTDLG*) m_printDlg;

    if (m_dialogParent)
        pd->hwndOwner = (HWND) m_dialogParent->GetHWND();
    else if (wxTheApp->GetTopWindow())
        pd->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND();
    else
        pd->hwndOwner = 0;

    bool ret = (PrintDlg( pd ) != 0);

    pd->hwndOwner = 0;

    if ( ret && (pd->hDC) )
    {
        wxPrinterDC *pdc = new wxPrinterDCFromHDC( (WXHDC) pd->hDC );
        m_printerDC = pdc;
        ConvertFromNative( m_printDialogData );
        return wxID_OK;
    }
    else
    {
        return wxID_CANCEL;
    }
}
Exemplo n.º 2
0
int wxDialog::ShowModal()
{
    WX_TESTING_SHOW_MODAL_HOOK();

    wxASSERT_MSG( !IsModal(), "ShowModal() can't be called twice" );

    // release the mouse if it's currently captured as the window having it
    // will be disabled when this dialog is shown -- but will still keep the
    // capture making it impossible to do anything in the modal dialog itself
    wxWindow * const win = wxWindow::GetCapture();
    if ( win )
        win->GTKReleaseMouseAndNotify();

    wxWindow * const parent = GetParentForModalDialog();
    if ( parent )
    {
        gtk_window_set_transient_for( GTK_WINDOW(m_widget),
                                      GTK_WINDOW(parent->m_widget) );
    }

    wxBusyCursorSuspender cs; // temporarily suppress the busy cursor

#if GTK_CHECK_VERSION(2,10,0)
    unsigned sigId = 0;
    gulong hookId = 0;
#ifndef __WXGTK3__
    // Ubuntu overlay scrollbar uses at least GTK 2.24
    if (gtk_check_version(2,24,0) == NULL)
#endif
    {
        sigId = g_signal_lookup("realize", GTK_TYPE_WIDGET);
        hookId = g_signal_add_emission_hook(sigId, 0, realize_hook, NULL, NULL);
    }
#endif

    Show( true );

    m_modalShowing = true;

    wxOpenModalDialogLocker modalLock;

    // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
    gtk_window_set_modal(GTK_WINDOW(m_widget), TRUE);

    // Run modal dialog event loop.
    {
        wxGUIEventLoopTiedPtr modal(&m_modalLoop, new wxGUIEventLoop());
        m_modalLoop->Run();
    }

#if GTK_CHECK_VERSION(2,10,0)
    if (sigId)
        g_signal_remove_emission_hook(sigId, hookId);
#endif

    gtk_window_set_modal(GTK_WINDOW(m_widget), FALSE);

    return GetReturnCode();
}
Exemplo n.º 3
0
int wxFileDialog::ShowModal()
{
    WX_TESTING_SHOW_MODAL_HOOK();

    CreateExtraControl();

    return wxDialog::ShowModal();
}
Exemplo n.º 4
0
int wxGenericMessageDialog::ShowModal()
{
    WX_TESTING_SHOW_MODAL_HOOK();

    if ( !m_created )
    {
        m_created = true;
        DoCreateMsgdialog();
    }

    return wxMessageDialogBase::ShowModal();
}
Exemplo n.º 5
0
int wxMessageDialog::ShowModal()
{
    WX_TESTING_SHOW_MODAL_HOOK();

    // break the mouse capture as it would interfere with modal dialog (see
    // wxDialog::ShowModal)
    wxWindow * const win = wxWindow::GetCapture();
    if ( win )
        win->GTKReleaseMouseAndNotify();

    if ( !m_widget )
    {
        GTKCreateMsgDialog();
        wxCHECK_MSG( m_widget, wxID_CANCEL,
                     wxT("failed to create GtkMessageDialog") );
    }

    // This should be necessary, but otherwise the
    // parent TLW will disappear..
    if (m_parent)
        gtk_window_present( GTK_WINDOW(m_parent->m_widget) );

    wxOpenModalDialogLocker modalLocker;

    gint result = gtk_dialog_run(GTK_DIALOG(m_widget));
    GTKDisconnect(m_widget);
    gtk_widget_destroy(m_widget);
    g_object_unref(m_widget);
    m_widget = NULL;

    switch (result)
    {
        default:
            wxFAIL_MSG(wxT("unexpected GtkMessageDialog return code"));
            // fall through

        case GTK_RESPONSE_CANCEL:
        case GTK_RESPONSE_DELETE_EVENT:
        case GTK_RESPONSE_CLOSE:
            return wxID_CANCEL;
        case GTK_RESPONSE_OK:
            return wxID_OK;
        case GTK_RESPONSE_YES:
            return wxID_YES;
        case GTK_RESPONSE_NO:
            return wxID_NO;
        case GTK_RESPONSE_HELP:
            return wxID_HELP;
    }
}
Exemplo n.º 6
0
// show dialog modally
int wxDialog::ShowModal()
{
    WX_TESTING_SHOW_MODAL_HOOK();

    wxASSERT_MSG( !IsModal(), wxT("ShowModal() can't be called twice") );

    Show();

    // EndModal may have been called from InitDialog handler (called from
    // inside Show()) and hidden the dialog back again
    if ( IsShown() )
    {
        // enter and run the modal loop
        wxDialogModalDataTiedPtr modalData(&m_modalData,
                                           new wxDialogModalData(this));
        modalData->RunLoop();
    }

    return GetReturnCode();
}
Exemplo n.º 7
0
int wxWindowsPageSetupDialog::ShowModal()
{
    WX_TESTING_SHOW_MODAL_HOOK();

    ConvertToNative( m_pageSetupData );

    PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageDlg;
    if (m_dialogParent)
        pd->hwndOwner = (HWND) m_dialogParent->GetHWND();
    else if (wxTheApp->GetTopWindow())
        pd->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND();
    else
        pd->hwndOwner = 0;
    BOOL retVal = PageSetupDlg( pd ) ;
    pd->hwndOwner = 0;
    if (retVal)
    {
        ConvertFromNative( m_pageSetupData );
        return wxID_OK;
    }
    else
        return wxID_CANCEL;
}
Exemplo n.º 8
0
int wxDialog::ShowModal()
{
    WX_TESTING_SHOW_MODAL_HOOK();

    if ( IsModal() )
    {
       wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
       return GetReturnCode();
    }

    // use the apps top level window as parent if none given unless explicitly
    // forbidden
    wxWindow * const parent = GetParentForModalDialog();
    if ( parent && parent != this )
    {
        m_parent = parent;
    }

    Show(true);

    m_isShowingModal = true;

    wxASSERT_MSG( !m_windowDisabler, wxT("disabling windows twice?") );

#if defined(__WXGTK__)
    wxBusyCursorSuspender suspender;
#endif

    m_windowDisabler = new wxWindowDisabler(this);
    if ( !m_eventLoop )
        m_eventLoop = new wxEventLoop;

    m_eventLoop->Run();

    return GetReturnCode();
}
Exemplo n.º 9
0
int wxDirDialog::ShowModal()
{
    WX_TESTING_SHOW_MODAL_HOOK();

    NavDialogRef dialog = NULL;
    NavDialogCreationOptions options;
    NavReplyRecord reply ;
    bool disposeReply = false ;
    OSStatus err = noErr;

    err = NavGetDefaultDialogCreationOptions(&options);
    options.optionFlags &= ~kNavAllowMultipleFiles;
    if (err == noErr)
    {
        wxCFStringRef message(m_message, GetFont().GetEncoding());
        options.message = message;
        err = NavCreateChooseFolderDialog(&options, sStandardNavEventFilter , NULL,  this , &dialog);
        if (err == noErr)
        {
            wxDialog::OSXBeginModalDialog();
            err = NavDialogRun(dialog);
            wxDialog::OSXEndModalDialog();
            if ( err == noErr )
            {
                err = NavDialogGetReply(dialog, &reply);
                disposeReply = true ;
            }
        }
    }

    if ( err == noErr )
    {
        if ( reply.validRecord )
        {
            FSRef folderInfo;
            AEDesc specDesc ;

            OSErr err = ::AECoerceDesc( &reply.selection , typeFSRef, &specDesc);
            if ( err != noErr )
            {
                m_path = wxEmptyString ;
            }
            else
            {
                folderInfo = **(FSRef**) specDesc.dataHandle;
                m_path = wxMacFSRefToPath( &folderInfo ) ;
                if (specDesc.dataHandle != nil)
                {
                    ::AEDisposeDesc(&specDesc);
                }
            }
        }
        else
        {
            err = paramErr ; // could be any error, only used for giving back wxID_CANCEL
        }
    }

    if ( disposeReply )
        ::NavDisposeReply(&reply);

    // apparently cancelling shouldn't change m_path
    if ( err != noErr && err != userCanceledErr )
        m_path = wxEmptyString ;

    if ( dialog )
        ::NavDialogDispose(dialog);

    return (err == noErr) ? wxID_OK : wxID_CANCEL ;
}
Exemplo n.º 10
0
int wxFontDialog::ShowModal()
{
    WX_TESTING_SHOW_MODAL_HOOK();

    FONTDLG      vFontDlg;
    char         zCurrentFont[FACESIZE];
    HWND         hWndFontDlg;
    FACENAMEDESC vFn;

    memset(&vFontDlg, '\0', sizeof(FONTDLG));
    zCurrentFont[0] = '\0';

    //
    // Set the fontdlg fields
    //
    vFontDlg.cbSize         = sizeof(FONTDLG);
    vFontDlg.hpsScreen      = ::WinGetScreenPS(HWND_DESKTOP);
    vFontDlg.hpsPrinter     = NULL;
    vFontDlg.pszFamilyname  = zCurrentFont;
    vFontDlg.fxPointSize    = MAKEFIXED(12,0);
    vFontDlg.usFamilyBufLen = FACESIZE;
    vFontDlg.fl             = FNTS_CENTER;
    vFontDlg.clrFore        = CLR_BLACK;
    vFontDlg.clrBack        = CLR_WHITE;

    hWndFontDlg = WinFontDlg( HWND_DESKTOP
                             ,GetParent()->GetHWND()
                             ,&vFontDlg
                            );
    if (hWndFontDlg && vFontDlg.lReturn == DID_OK)
    {
        wxColour                    vColour((unsigned long)0x00000000);
        wxNativeFontInfo            vInfo;

        m_fontData.m_fontColour = vColour;

        memset(&vFn, '\0', sizeof(FACENAMEDESC));
        vFn.usSize        = sizeof(FACENAMEDESC);
        vFn.usWeightClass = vFontDlg.usWeight;
        vFn.usWidthClass  = vFontDlg.usWidth;

        memset(&vInfo.fa, '\0', sizeof(FATTRS));
        memcpy(&vInfo.fn, &vFn, sizeof(FACENAMEDESC));

        vInfo.fa.usRecordLength = vFontDlg.fAttrs.usRecordLength;
        strcpy(vInfo.fa.szFacename, vFontDlg.fAttrs.szFacename);
        vInfo.fa.lMatch = vFontDlg.fAttrs.lMatch;

        //
        // Debugging
        //
        wxFont                      vChosenFont(vInfo);

        int                         nPointSize = vFontDlg.fxPointSize >> 16;

        vChosenFont.SetPointSize(nPointSize);
        m_fontData.m_chosenFont = vChosenFont;

        m_fontData.EncodingInfo().facename = (wxChar*)vFontDlg.fAttrs.szFacename;
        m_fontData.EncodingInfo().charset = vFontDlg.fAttrs.usCodePage;

        return wxID_OK;
    }
Exemplo n.º 11
0
int wxMessageDialog::ShowModal()
{
    WX_TESTING_SHOW_MODAL_HOOK();

    HWND                            hWnd = 0;
    ULONG                           ulStyle = MB_OK;
    int                             nAns = wxOK;
    const long                      lStyle = GetMessageDialogStyle();

    if (!wxTheApp->GetTopWindow())
    {
        //
        // when the message box is shown from wxApp::OnInit() (i.e. before the
        // message loop is entered), this must be done or the next message box
        // will never be shown - just try putting 2 calls to wxMessageBox() in
        // OnInit() to see it
        //
        while (wxTheApp->Pending())
            wxTheApp->Dispatch();
    }

    if (m_parent)
        hWnd = (HWND) m_parent->GetHWND();
    else
        hWnd = HWND_DESKTOP;
    if (lStyle & wxYES_NO)
    {
        if (lStyle & wxCANCEL)
            ulStyle = MB_YESNOCANCEL;
        else
            ulStyle = MB_YESNO;

        if (lStyle & wxNO_DEFAULT)
            ulStyle |= MB_DEFBUTTON2;
    }

    if (lStyle & wxOK)
    {
        if (lStyle & wxCANCEL)
            ulStyle = MB_OKCANCEL;
        else
            ulStyle = MB_OK;
    }

    switch ( GetEffectiveIcon() )
    {
        case wxICON_ERROR:
            ulStyle |= MB_ERROR;
            break;

        case wxICON_WARNING:
            ulStyle |= MB_WARNING;
            break;

        case wxICON_QUESTION:
            ulStyle |= MB_QUERY;
            break;

        case wxICON_INFORMATION:
            ulStyle |= MB_INFORMATION;
            break;
    }

    if (hWnd != HWND_DESKTOP)
        ulStyle |= MB_APPLMODAL;
    else
        ulStyle |= MB_SYSTEMMODAL;

    //
    // This little line of code is get message boxes under OS/2 to
    // behve like the other ports.  In OS/2 if the parent is a window
    // it displays, clipped, in the window.  This centers it on the
    // desktop, like the other ports but still allows control over modality
    //
    hWnd = HWND_DESKTOP;

    ULONG                           ulAns = ::WinMessageBox( hWnd
                                                            ,hWnd
                                                            ,GetFullMessage().c_str()
                                                            ,m_caption.c_str()
                                                            ,0L
                                                            ,ulStyle);
    switch (ulAns)
    {
        case MBID_CANCEL:
            nAns = wxID_CANCEL;
            break;
        case MBID_OK:
            nAns = wxID_OK;
            break;
        case MBID_YES:
            nAns = wxID_YES;
            break;
        case MBID_NO:
            nAns = wxID_NO;
            break;
        default:
           nAns = wxID_CANCEL;
    }
    return nAns;
} // end of wxMessageDialog::ShowModal