Blender V4.3
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_bitmap.h"
#include "BLI_blenlib.h"
#include "BLI_math_color.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_screen.hh"
#include "GHOST_C-api.h"
#include "BLO_readfile.hh"
#include "ED_asset.hh"
#include "ED_fileselect.hh"
#include "ED_screen.hh"
#include "GPU_shader.hh"
#include "GPU_state.hh"
#include "GPU_viewport.hh"
#include "IMB_imbuf_types.hh"
#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_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)
 
wmOperatorCallContext 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, int import_method)
 
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)
 
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)
 Free asset ID imported for canceled 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)
 
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 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()

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

Definition at line 421 of file wm_dragdrop.cc.

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

Referenced by dropbox_active().

◆ WM_drag_add_asset_list_item()

◆ 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_create_asset_data()

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

Definition at line 649 of file wm_dragdrop.cc.

References wmDragAsset::asset, and wmDragAsset::import_method.

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()

wmDragPath * WM_drag_create_path_data ( blender::Span< const char * > paths)

◆ 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 261 of file wm_dragdrop.cc.

References CTX_data_collection_get(), PointerRNA::data, 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()

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

◆ WM_drag_draw_default_fn()

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

Definition at line 1148 of file wm_dragdrop.cc.

References wm_drag_draw_default(), and xy.

◆ wm_drag_draw_icon()

◆ wm_drag_draw_item_name()

static 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 1066 of file wm_dragdrop.cc.

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

Referenced by view3d_dropboxes().

◆ wm_drag_draw_tooltip()

◆ WM_drag_free()

◆ wm_drag_free_asset_data()

static void wm_drag_free_asset_data ( wmDragAsset ** asset_data)
static

Definition at line 660 of file wm_dragdrop.cc.

Referenced by WM_drag_data_free(), and WM_drag_free().

◆ WM_drag_free_imported_drag_ID()

void WM_drag_free_imported_drag_ID ( Main * bmain,
wmDrag * drag,
wmDropBox * drop )

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.

Definition at line 780 of file wm_dragdrop.cc.

References wmDragAsset::asset, BKE_id_free_us(), blender::asset_system::AssetRepresentation::get_id_type(), id_us_plus(), wmDropBox::ptr, wmDrag::type, WM_DRAG_ASSET, WM_drag_get_asset_data(), and WM_operator_properties_id_lookup_from_name_or_session_uid().

Referenced by ED_dropboxes_ui(), blender::ed::space_node::node_dropboxes(), and view3d_dropboxes().

◆ WM_drag_free_list()

void WM_drag_free_list ( ListBase * lb)

◆ wm_drag_free_path_data()

static void wm_drag_free_path_data ( wmDragPath ** path_data)
static

Definition at line 865 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()

◆ 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 761 of file wm_dragdrop.cc.

References 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 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(), sequencer_drop_copy(), ui_drop_material_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 920 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(), image_drop_poll(), image_drop_preview_poll(), is_movie(), is_sound(), movie_drop_preview_poll(), sound_drop_preview_poll(), blender::tests::TEST(), and text_drop_path_poll().

◆ WM_drag_get_paths()

◆ WM_drag_get_single_path() [1/2]

const char * WM_drag_get_single_path ( const wmDrag * drag)

◆ 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 881 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 937 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 901 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()

static int wm_drag_imbuf_icon_height_get ( const wmDrag * drag)
static

◆ wm_drag_imbuf_icon_width_get()

static int wm_drag_imbuf_icon_width_get ( const wmDrag * drag)
static

◆ WM_drag_is_ID_type()

◆ 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 321 of file wm_dragdrop.cc.

References 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 564 of file wm_dragdrop.cc.

References CTX_store_set().

Referenced by wm_handlers_do_intern().

◆ wm_drop_item_clear_runtime()

static void wm_drop_item_clear_runtime ( wmDropBox * drop)
static

◆ wm_drop_item_free_data()

static void wm_drop_item_free_data ( wmDropBox * drop)
static

◆ wm_drop_operator_context_get()

wmOperatorCallContext 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 WM_OP_INVOKE_DEFAULT.

Definition at line 589 of file wm_dragdrop.cc.

References WM_OP_INVOKE_DEFAULT.

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

◆ wm_drop_operator_draw()

◆ wm_drop_prepare()

◆ wm_drop_redalert_draw()

◆ wm_drop_ui_context_create()

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

Definition at line 341 of file wm_dragdrop.cc.

References 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 208 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 174 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 356 of file wm_dragdrop.cc.

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

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 315 of file wm_dragdrop.cc.

References 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