示例#1
0
文件: dnd.cpp 项目: madnessw/thesnow
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;
}
示例#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;

    // disabled for now
    g_blockEventsOnDrag = true;

    RegisterWindow();

    m_waiting = true;

    GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) 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];
#ifdef __WXDEBUG__
        wxLogTrace(TRACE_DND, wxT("Drop source: Supported atom %s"), gdk_atom_name( atom ));
#endif
       gtk_target_list_add( target_list, atom, 0, 0 );
    }
    delete[] array;

    int action = GDK_ACTION_COPY;
    if ( flags & wxDrag_AllowMove )
        action |= 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;

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

    m_dragContext = context;

    PrepareIcon( action, context );

    while (m_waiting)
        gtk_main_iteration();

    m_retValue = ConvertFromGTK(context->action);
    if ( m_retValue == wxDragNone )
         m_retValue = wxDragCancel;

    g_blockEventsOnDrag = false;

    UnregisterWindow();

    return m_retValue;
}
示例#3
0
int CSystemImageList::GetIconIndex(enum filetype type, const wxString& fileName /*=_T("")*/, bool physical /*=true*/)
{
#ifdef __WXMSW__
	if (fileName == _T(""))
		physical = false;

	SHFILEINFO shFinfo;
	memset(&shFinfo, 0, sizeof(SHFILEINFO));
	if (SHGetFileInfo(fileName != _T("") ? fileName : _T("{B97D3074-1830-4b4a-9D8A-17A38B074052}"),
		(type != file) ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL,
		&shFinfo,
		sizeof(SHFILEINFO),
		SHGFI_ICON | ((type == opened_dir) ? SHGFI_OPENICON : 0) | ((physical) ? 0 : SHGFI_USEFILEATTRIBUTES) ) )
	{
		int icon = shFinfo.iIcon;
		// we only need the index from the system image list
		DestroyIcon(shFinfo.hIcon);
		return icon;
	}
#else
	int icon;
	switch (type)
	{
	case file:
	default:
		icon = 0;
		break;
	case dir:
		return 1;
	case opened_dir:
		return 2;
	}

	wxFileName fn(fileName);
	wxString ext = fn.GetExt();
	if (ext == _T(""))
		return icon;

	std::map<wxString, int>::iterator cacheIter = m_iconCache.find(ext);
	if (cacheIter != m_iconCache.end())
		return cacheIter->second;

	wxFileType *pType = wxTheMimeTypesManager->GetFileTypeFromExtension(ext);
	if (!pType)
	{
		m_iconCache[ext] = icon;
		return icon;
	}
	
	wxIconLocation loc;
	if (pType->GetIcon(&loc) && loc.IsOk())
	{
		wxLogNull nul;
		wxIcon newIcon(loc);

		if (newIcon.Ok())
		{
			wxBitmap bmp = PrepareIcon(newIcon, wxSize(16, 16));
			int index = m_pImageList->Add(bmp);
			if (index > 0)
				icon = index;
		}
	}
	delete pType;

	m_iconCache[ext] = icon;
	return icon;
#endif
	return -1;
}