Blender V5.0
wm_dragdrop.cc File Reference
#include <cstring>
#include "AS_asset_representation.hh"
#include "DNA_asset_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_windowmanager_types.h"
#include "MEM_guardedalloc.h"
#include "BLT_translation.hh"
#include "BLI_listbase.h"
#include "BLI_math_color.h"
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BIF_glutil.hh"
#include "BKE_context.hh"
#include "BKE_global.hh"
#include "BKE_idprop.hh"
#include "BKE_idtype.hh"
#include "BKE_lib_id.hh"
#include "BKE_main.hh"
#include "BKE_preview_image.hh"
#include "BKE_screen.hh"
#include "BLO_readfile.hh"
#include "ED_fileselect.hh"
#include "ED_screen.hh"
#include "GPU_shader_builtin.hh"
#include "GPU_state.hh"
#include "IMB_imbuf.hh"
#include "IMB_imbuf_types.hh"
#include "GHOST_Types.h"
#include "UI_interface.hh"
#include "UI_interface_icons.hh"
#include "UI_resources.hh"
#include "RNA_access.hh"
#include "WM_api.hh"
#include "WM_types.hh"
#include "wm_event_system.hh"
#include "wm_window.hh"
#include <fmt/format.h>

Go to the source code of this file.

Classes

struct  wmDropBoxMap

Functions

static void wm_drag_free_asset_data (wmDragAsset **asset_data)
static void wm_drag_free_path_data (wmDragPath **path_data)
static void wm_drop_item_free_data (wmDropBox *drop)
static void wm_drop_item_clear_runtime (wmDropBox *drop)
ListBaseWM_dropboxmap_find (const char *idname, int spaceid, int regionid)
wmDropBoxWM_dropbox_add (ListBase *lb, const char *idname, bool(*poll)(bContext *C, wmDrag *drag, const wmEvent *event), void(*copy)(bContext *C, wmDrag *drag, wmDropBox *drop), void(*cancel)(Main *bmain, wmDrag *drag, wmDropBox *drop), WMDropboxTooltipFunc tooltip)
static void wm_dropbox_item_update_ot (wmDropBox *drop)
void WM_dropbox_update_ot ()
void wm_dropbox_free ()
static void wm_dropbox_invoke (bContext *C, wmDrag *drag)
wmDragWM_drag_data_create (bContext *C, int icon, eWM_DragDataType type, void *poin, uint flags)
void WM_event_start_prepared_drag (bContext *C, wmDrag *drag)
void WM_event_start_drag (bContext *C, int icon, eWM_DragDataType type, void *poin, uint flags)
void wm_drags_exit (wmWindowManager *wm, wmWindow *win)
static std::unique_ptr< bContextStorewm_drop_ui_context_create (const bContext *C)
void WM_event_drag_image (wmDrag *drag, const ImBuf *imb, float scale)
void WM_event_drag_path_override_poin_data_with_space_file_paths (const bContext *C, wmDrag *drag)
void WM_event_drag_preview_icon (wmDrag *drag, int icon_id)
void WM_drag_data_free (eWM_DragDataType dragtype, void *poin)
void WM_drag_free (wmDrag *drag)
void WM_drag_free_list (ListBase *lb)
static std::string dropbox_tooltip (bContext *C, wmDrag *drag, const int xy[2], wmDropBox *drop)
static wmDropBoxdropbox_active (bContext *C, ListBase *handlers, wmDrag *drag, const wmEvent *event)
static wmDropBoxwm_dropbox_active (bContext *C, wmDrag *drag, const wmEvent *event)
static void wm_drop_update_active (bContext *C, wmDrag *drag, const wmEvent *event)
void wm_drop_prepare (bContext *C, wmDrag *drag, wmDropBox *drop)
void wm_drop_end (bContext *C, wmDrag *, wmDropBox *)
void wm_drags_check_ops (bContext *C, const wmEvent *event)
blender::wm::OpCallContext wm_drop_operator_context_get (const wmDropBox *)
void WM_drag_add_local_ID (wmDrag *drag, ID *id, ID *from_parent)
IDWM_drag_get_local_ID (const wmDrag *drag, short idcode)
IDWM_drag_get_local_ID_from_event (const wmEvent *event, short idcode)
bool WM_drag_is_ID_type (const wmDrag *drag, int idcode)
wmDragAssetWM_drag_create_asset_data (const blender::asset_system::AssetRepresentation *asset, const AssetImportSettings &import_settings)
wmDragAssetWM_drag_get_asset_data (const wmDrag *drag, int idcode)
AssetMetaDataWM_drag_get_asset_meta_data (const wmDrag *drag, int idcode)
IDWM_drag_asset_id_import (const bContext *C, wmDragAsset *asset_drag, const int flag_extra)
bool WM_drag_asset_will_import_linked (const wmDrag *drag)
bool WM_drag_asset_will_import_packed (const wmDrag *drag)
IDWM_drag_get_local_ID_or_import_from_asset (const bContext *C, const wmDrag *drag, int idcode)
void WM_drag_free_imported_drag_ID (Main *bmain, wmDrag *drag, wmDropBox *drop)
wmDragAssetCatalogWM_drag_get_asset_catalog_data (const wmDrag *drag)
void WM_drag_add_asset_list_item (wmDrag *drag, const blender::asset_system::AssetRepresentation *asset)
 Free asset ID imported for canceled drop.
const ListBaseWM_drag_asset_list_get (const wmDrag *drag)
wmDragPathWM_drag_create_path_data (blender::Span< const char * > paths)
const char * WM_drag_get_single_path (const wmDrag *drag)
const char * WM_drag_get_single_path (const wmDrag *drag, int file_type)
bool WM_drag_has_path_file_type (const wmDrag *drag, int file_type)
blender::Span< std::string > WM_drag_get_paths (const wmDrag *drag)
int WM_drag_get_path_file_type (const wmDrag *drag)
const std::string & WM_drag_get_string (const wmDrag *drag)
std::string WM_drag_get_string_firstline (const wmDrag *drag)
static void wm_drop_operator_draw (const blender::StringRef name, int x, int y)
static void wm_drop_redalert_draw (const blender::StringRef redalert_str, int x, int y)
const char * WM_drag_get_item_name (wmDrag *drag)
static int wm_drag_imbuf_icon_width_get (const wmDrag *drag)
static int wm_drag_imbuf_icon_height_get (const wmDrag *drag)
static int wm_drag_preview_icon_size_get ()
static void wm_drag_draw_icon (bContext *, wmWindow *, wmDrag *drag, const int xy[2])
static void wm_drag_draw_item_name (wmDrag *drag, const int x, const int y)
void WM_drag_draw_item_name_fn (bContext *, wmWindow *win, wmDrag *drag, const int xy[2])
static void wm_drag_draw_tooltip (bContext *C, wmWindow *win, wmDrag *drag, const int xy[2])
static void wm_drag_draw_default (bContext *C, wmWindow *win, wmDrag *drag, const int xy[2])
void WM_drag_draw_default_fn (bContext *C, wmWindow *win, wmDrag *drag, const int xy[2])
void wm_drags_draw (bContext *C, wmWindow *win)

Variables

static ListBase dropboxes = {nullptr, nullptr}

Detailed Description

Our own drag-and-drop, drag state and drop boxes.

Definition in file wm_dragdrop.cc.

Function Documentation

◆ dropbox_active()

◆ dropbox_tooltip()

std::string dropbox_tooltip ( bContext * C,
wmDrag * drag,
const int xy[2],
wmDropBox * drop )
static

Definition at line 449 of file wm_dragdrop.cc.

References C, wmDropBox::ot, wmDropBox::ptr, wmDropBox::tooltip, WM_operatortype_name(), and xy.

Referenced by dropbox_active().

◆ WM_drag_add_asset_list_item()

void WM_drag_add_asset_list_item ( wmDrag * drag,
const blender::asset_system::AssetRepresentation * asset )

Free asset ID imported for canceled drop.

If the asset was imported (linked/appended) using WM_drag_get_local_ID_or_import_from_asset()` (typically via a wmDropBox.copy() callback), we want the ID to be removed again if the drop operator cancels. This is for use as wmDropBox.cancel() callback. */ void WM_drag_free_imported_drag_ID(Main *bmain, wmDrag *drag, wmDropBox *drop);

wmDragAssetCatalog *WM_drag_get_asset_catalog_data(const wmDrag *drag);

/**

Note
Does not store asset in any way, so it's fine to pass a temporary.

Definition at line 866 of file wm_dragdrop.cc.

References wmDragAssetListItem::asset_data, ASSET_IMPORT_APPEND, wmDrag::asset_items, BLI_addtail(), BLI_assert, wmDragAssetListItem::external_info, wmDragAssetListItem::is_external, blender::asset_system::AssetRepresentation::local_id(), wmDragAssetListItem::local_id, MEM_callocN(), AssetImportSettings::method, wmDrag::type, AssetImportSettings::use_instance_collections, WM_DRAG_ASSET_LIST, and WM_drag_create_asset_data().

Referenced by WM_drag_data_create().

◆ WM_drag_add_local_ID()

void WM_drag_add_local_ID ( wmDrag * drag,
ID * id,
ID * from_parent )

◆ WM_drag_asset_id_import()

◆ WM_drag_asset_list_get()

◆ WM_drag_asset_will_import_linked()

bool WM_drag_asset_will_import_linked ( const wmDrag * drag)

◆ WM_drag_asset_will_import_packed()

◆ WM_drag_create_asset_data()

wmDragAsset * WM_drag_create_asset_data ( const blender::asset_system::AssetRepresentation * asset,
const AssetImportSettings & import_settings )
Note
Does not store asset in any way, so it's fine to pass a temporary.

Definition at line 677 of file wm_dragdrop.cc.

References wmDragAsset::asset, and wmDragAsset::import_settings.

Referenced by blender::ed::asset::shelf::AssetDragController::create_drag_data(), UI_but_drag_set_asset(), and WM_drag_add_asset_list_item().

◆ WM_drag_create_path_data()

◆ WM_drag_data_create()

wmDrag * WM_drag_data_create ( bContext * C,
int icon,
eWM_DragDataType type,
void * poin,
unsigned int flags )

Create and fill the dragging data, but don't start dragging just yet (unlike WM_event_start_drag()). Must be followed up by WM_event_start_prepared_drag(), otherwise the returned pointer will leak memory.

Note that poin should be valid allocated and not on stack.

Definition at line 263 of file wm_dragdrop.cc.

References C, CTX_data_collection_get(), wmDrag::flags, wmDrag::icon, wmDrag::poin, ptr, wmDrag::type, WM_drag_add_asset_list_item(), WM_drag_add_local_ID(), WM_DRAG_ASSET, WM_DRAG_ASSET_CATALOG, WM_DRAG_ASSET_LIST, WM_DRAG_FREE_DATA, WM_DRAG_GREASE_PENCIL_LAYER, WM_DRAG_ID, and WM_DRAG_PATH.

Referenced by blender::ed::outliner::outliner_item_drag_drop_invoke(), ui_but_drag_start(), and WM_event_start_drag().

◆ WM_drag_data_free()

◆ wm_drag_draw_default()

◆ WM_drag_draw_default_fn()

void WM_drag_draw_default_fn ( bContext * C,
wmWindow * win,
wmDrag * drag,
const int xy[2] )

Definition at line 1259 of file wm_dragdrop.cc.

References C, wm_drag_draw_default(), and xy.

◆ wm_drag_draw_icon()

◆ wm_drag_draw_item_name()

void wm_drag_draw_item_name ( wmDrag * drag,
const int x,
const int y )
static

◆ WM_drag_draw_item_name_fn()

void WM_drag_draw_item_name_fn ( bContext * C,
wmWindow * win,
wmDrag * drag,
const int xy[2] )

Definition at line 1147 of file wm_dragdrop.cc.

References UI_SCALE_FAC, wm_drag_draw_item_name(), wmWindowViewport_ex(), x, xy, and y.

Referenced by view3d_dropboxes().

◆ wm_drag_draw_tooltip()

◆ WM_drag_free()

◆ wm_drag_free_asset_data()

void wm_drag_free_asset_data ( wmDragAsset ** asset_data)
static

Definition at line 688 of file wm_dragdrop.cc.

Referenced by WM_drag_data_free(), and WM_drag_free().

◆ WM_drag_free_imported_drag_ID()

◆ WM_drag_free_list()

◆ wm_drag_free_path_data()

void wm_drag_free_path_data ( wmDragPath ** path_data)
static

Definition at line 923 of file wm_dragdrop.cc.

Referenced by WM_drag_data_free().

◆ WM_drag_get_asset_catalog_data()

◆ WM_drag_get_asset_data()

◆ WM_drag_get_asset_meta_data()

AssetMetaData * WM_drag_get_asset_meta_data ( const wmDrag * drag,
int idcode )

◆ WM_drag_get_item_name()

◆ WM_drag_get_local_ID()

◆ WM_drag_get_local_ID_from_event()

◆ WM_drag_get_local_ID_or_import_from_asset()

ID * WM_drag_get_local_ID_or_import_from_asset ( const bContext * C,
const wmDrag * drag,
int idcode )

When dragging a local ID, return that. Otherwise, if dragging an asset-handle, link or append that depending on what was chosen by the drag-box (currently append only in fact).

Use WM_drag_free_imported_drag_ID() as cancel callback of the drop-box, so that the asset import is rolled back if the drop operator fails.

Definition at line 813 of file wm_dragdrop.cc.

References C, ELEM, wmDrag::type, WM_DRAG_ASSET, WM_drag_asset_id_import(), WM_drag_get_asset_data(), WM_drag_get_local_ID(), and WM_DRAG_ID.

Referenced by blender::ed::vse::get_drag_path(), blender::ed::space_node::node_group_drop_copy(), blender::ed::space_node::node_id_drop_copy(), blender::ed::space_node::node_id_im_drop_copy(), screen_drop_scene_copy(), blender::ed::vse::sequencer_drop_copy(), ui_drop_material_copy(), ui_drop_name_copy(), view3d_id_drop_copy(), view3d_id_drop_copy_with_type(), and view3d_id_path_drop_copy().

◆ WM_drag_get_path_file_type()

int WM_drag_get_path_file_type ( const wmDrag * drag)

Note that even though the enum return type uses bit-flags, this should never have multiple type-bits set, so ELEM() like comparison is possible. To check all paths or to do a bit-flag check use WM_drag_has_path_file_type(drag, file_type) instead.

Definition at line 978 of file wm_dragdrop.cc.

References wmDragPath::file_types, wmDrag::poin, wmDrag::type, and WM_DRAG_PATH.

Referenced by blend_file_drop_poll(), clip_drop_poll(), blender::ed::vse::image_drop_poll(), blender::ed::vse::image_drop_preview_poll(), blender::ed::vse::is_movie(), blender::ed::vse::is_sound(), blender::ed::vse::movie_drop_preview_poll(), blender::ed::vse::sound_drop_preview_poll(), blender::tests::TEST(), and text_drop_path_poll().

◆ WM_drag_get_paths()

◆ WM_drag_get_single_path() [1/2]

◆ WM_drag_get_single_path() [2/2]

const char * WM_drag_get_single_path ( const wmDrag * drag,
int file_type )

If drag contains path data, returns the first path in the path list that matches a a file_type.

Parameters
dragThe drag that could contain drag path data.
file_typeeFileSel_File_Types bit flag.

Definition at line 939 of file wm_dragdrop.cc.

References blender::Span< T >::begin(), blender::Span< T >::end(), wmDragPath::file_types, wmDragPath::paths, wmDrag::poin, wmDrag::type, and WM_DRAG_PATH.

◆ WM_drag_get_string()

const std::string & WM_drag_get_string ( const wmDrag * drag)

◆ WM_drag_get_string_firstline()

std::string WM_drag_get_string_firstline ( const wmDrag * drag)

Definition at line 995 of file wm_dragdrop.cc.

References BLI_assert, wmDrag::poin, str, wmDrag::type, and WM_DRAG_STRING.

Referenced by console_drop_string_copy().

◆ WM_drag_has_path_file_type()

bool WM_drag_has_path_file_type ( const wmDrag * drag,
int file_type )

If drag contains path data, returns if any file path match a file_type.

Parameters
dragThe drag that could contain drag path data.
file_typeeFileSel_File_Types bit flag.

Definition at line 959 of file wm_dragdrop.cc.

References wmDragPath::file_types_bit_flag, wmDrag::poin, wmDrag::type, and WM_DRAG_PATH.

Referenced by blender::tests::TEST().

◆ wm_drag_imbuf_icon_height_get()

int wm_drag_imbuf_icon_height_get ( const wmDrag * drag)
static

◆ wm_drag_imbuf_icon_width_get()

int wm_drag_imbuf_icon_width_get ( const wmDrag * drag)
static

◆ WM_drag_is_ID_type()

◆ wm_drag_preview_icon_size_get()

int wm_drag_preview_icon_size_get ( )
static

◆ wm_drags_check_ops()

◆ wm_drags_draw()

◆ wm_drags_exit()

void wm_drags_exit ( wmWindowManager * wm,
wmWindow * win )

Additional work to cleanly end dragging. Additional because this doesn't actually remove the drag items. Should be called whenever dragging is stopped (successful or not, also when canceled).

Definition at line 323 of file wm_dragdrop.cc.

References bScreen::active_region, ED_region_tag_redraw_no_rebuild(), wmWindow::eventstate, LISTBASE_FOREACH, wmWindow::tag_cursor_refresh, wmWindowManager::windows, WM_cursor_modal_restore(), WM_event_add_mousemove(), WM_window_find_under_cursor(), WM_window_get_active_screen(), and wmEvent::xy.

Referenced by wm_drop_prepare(), wm_event_drag_and_drop_test(), and wm_handlers_do_intern().

◆ wm_drop_end()

void wm_drop_end ( bContext * C,
wmDrag * drag,
wmDropBox * drop )

Definition at line 592 of file wm_dragdrop.cc.

References C, and CTX_store_set().

Referenced by wm_handlers_do_intern().

◆ wm_drop_item_clear_runtime()

void wm_drop_item_clear_runtime ( wmDropBox * drop)
static

◆ wm_drop_item_free_data()

void wm_drop_item_free_data ( wmDropBox * drop)
static

◆ wm_drop_operator_context_get()

blender::wm::OpCallContext wm_drop_operator_context_get ( const wmDropBox * drop)

The operator of a dropbox should always be executed in the context determined by the mouse coordinates. The dropbox poll should check the context area and region as needed. So this always returns blender::wm::OpCallContext::InvokeDefault.

Definition at line 617 of file wm_dragdrop.cc.

References blender::wm::InvokeDefault.

Referenced by dropbox_active(), wm_drop_prepare(), and wm_handlers_do_intern().

◆ wm_drop_operator_draw()

void wm_drop_operator_draw ( const blender::StringRef name,
int x,
int y )
static

◆ wm_drop_prepare()

◆ wm_drop_redalert_draw()

void wm_drop_redalert_draw ( const blender::StringRef redalert_str,
int x,
int y )
static

◆ wm_drop_ui_context_create()

std::unique_ptr< bContextStore > wm_drop_ui_context_create ( const bContext * C)
static

Definition at line 343 of file wm_dragdrop.cc.

References C, CTX_wm_region(), UI_but_context_get(), and UI_region_active_but_get().

Referenced by wm_drop_update_active().

◆ wm_drop_update_active()

◆ wm_dropbox_active()

◆ WM_dropbox_add()

◆ wm_dropbox_free()

void wm_dropbox_free ( )

Definition at line 210 of file wm_dragdrop.cc.

References BLI_freelistN(), dropboxes, LISTBASE_FOREACH, and wm_drop_item_free_data().

Referenced by WM_exit_ex().

◆ wm_dropbox_invoke()

◆ wm_dropbox_item_update_ot()

◆ WM_dropbox_update_ot()

void WM_dropbox_update_ot ( )

Ensure operator pointers & properties are valid after operators have been added/removed.

Definition at line 176 of file wm_dragdrop.cc.

References dropboxes, LISTBASE_FOREACH, and wm_dropbox_item_update_ot().

Referenced by WM_keyconfig_update_ex().

◆ WM_dropboxmap_find()

◆ WM_event_drag_image()

void WM_event_drag_image ( wmDrag * drag,
const ImBuf * imb,
float scale )

Definition at line 358 of file wm_dragdrop.cc.

References wmDrag::imb, and wmDrag::imbuf_scale.

Referenced by ui_but_drag_start().

◆ WM_event_drag_path_override_poin_data_with_space_file_paths()

void WM_event_drag_path_override_poin_data_with_space_file_paths ( const bContext * C,
wmDrag * drag )

◆ WM_event_drag_preview_icon()

void WM_event_drag_preview_icon ( wmDrag * drag,
int icon_id )

Definition at line 384 of file wm_dragdrop.cc.

References BLI_assert_msg, wmDrag::imb, and wmDrag::preview_icon_id.

Referenced by ui_but_drag_start().

◆ WM_event_start_drag()

void WM_event_start_drag ( bContext * C,
int icon,
eWM_DragDataType type,
void * poin,
unsigned int flags )

Start dragging immediately with the given data. Note that poin should be valid allocated and not on stack.

Definition at line 317 of file wm_dragdrop.cc.

References C, WM_drag_data_create(), and WM_event_start_prepared_drag().

Referenced by ghost_event_proc(), ui_but_drag_init(), ui_but_drag_start(), and UI_view_item_drag_start().

◆ WM_event_start_prepared_drag()

void WM_event_start_prepared_drag ( bContext * C,
wmDrag * drag )

Variable Documentation

◆ dropboxes