Example #1
0
void ScopeGuardTestCase::BlockExitObj()
{
    Counter count0(1),
            count1(2),
            count2(3);

    {
        wxON_BLOCK_EXIT_OBJ0(count0, Counter::Zero);
        wxON_BLOCK_EXIT_OBJ1(count1, Counter::Set, 17);
        wxON_BLOCK_EXIT_OBJ2(count2, Counter::Sum, 2, 3);

        CPPUNIT_ASSERT_EQUAL( 1, count0.GetCount() );
        CPPUNIT_ASSERT_EQUAL( 2, count1.GetCount() );
        CPPUNIT_ASSERT_EQUAL( 3, count2.GetCount() );
    }

    CPPUNIT_ASSERT_EQUAL( 0, count0.GetCount() );
    CPPUNIT_ASSERT_EQUAL( 17, count1.GetCount() );
    CPPUNIT_ASSERT_EQUAL( 5, count2.GetCount() );
}
Example #2
0
wxDragResult wxDropSource::DoDragDrop(int flags)
{
    wxCHECK_MSG( m_data && m_data->GetFormatCount(), wxDragNone,
                 wxT("Drop source: no data") );

    // still in drag
    if (g_blockEventsOnDrag)
        return wxDragNone;

    // don't start dragging if no button is down
    if (g_lastButtonNumber == 0)
        return wxDragNone;

    // we can only start a drag after a mouse event
    if (g_lastMouseEvent == NULL)
        return wxDragNone;

    GTKConnectDragSignals();
    wxON_BLOCK_EXIT_OBJ0(*this, wxDropSource::GTKDisconnectDragSignals);

    m_waiting = true;

    GtkTargetList *target_list = gtk_target_list_new( NULL, 0 );

    wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ];
    m_data->GetAllFormats( array );
    size_t count = m_data->GetFormatCount();
    for (size_t i = 0; i < count; i++)
    {
        GdkAtom atom = array[i];
        wxLogTrace(TRACE_DND, wxT("Drop source: Supported atom %s"),
                   gdk_atom_name( atom ));
        gtk_target_list_add( target_list, atom, 0, 0 );
    }
    delete[] array;

    int allowed_actions = GDK_ACTION_COPY;
    if ( flags & wxDrag_AllowMove )
        allowed_actions |= GDK_ACTION_MOVE;

    // VZ: as we already use g_blockEventsOnDrag it shouldn't be that bad
    //     to use a global to pass the flags to the drop target but I'd
    //     surely prefer a better way to do it
    gs_flagsForDrag = flags;

    m_retValue = wxDragCancel;

    GdkDragContext *context = gtk_drag_begin( m_widget,
                target_list,
                (GdkDragAction)allowed_actions,
                g_lastButtonNumber,  // number of mouse button which started drag
                (GdkEvent*) g_lastMouseEvent );

    if ( !context )
    {
        // this can happen e.g. if gdk_pointer_grab() failed
        return wxDragError;
    }

    m_dragContext = context;

    PrepareIcon( allowed_actions, context );

    while (m_waiting)
        gtk_main_iteration();

    g_signal_handlers_disconnect_by_func (m_iconWindow,
                                          (gpointer) gtk_dnd_window_configure_callback, this);

    return m_retValue;
}