1 /* 2 * This program is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU General Public License 4 * as published by the Free Software Foundation; either version 2 5 * of the License, or (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software Foundation, 14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 * 16 * The Original Code is Copyright (C) 2007 Blender Foundation. 17 * All rights reserved. 18 */ 19 20 /** \file 21 * \ingroup wm 22 * 23 * 24 * Overview of WM structs 25 * ====================== 26 * 27 * - #wmWindowManager.windows -> #wmWindow <br> 28 * Window manager stores a list of windows. 29 * 30 * - #wmWindow.screen -> #bScreen <br> 31 * Window has an active screen. 32 * 33 * - #bScreen.areabase -> #ScrArea <br> 34 * Link to #ScrArea. 35 * 36 * - #ScrArea.spacedata <br> 37 * Stores multiple spaces via space links. 38 * 39 * - #SpaceLink <br> 40 * Base struct for space data for all different space types. 41 * 42 * - #ScrArea.regionbase -> #ARegion <br> 43 * Stores multiple regions. 44 * 45 * - #bScreen.regionbase -> #ARegion <br> 46 * Global screen level regions, e.g. popups, popovers, menus. 47 * 48 * - #wmWindow.global_areas -> #ScrAreaMap <br> 49 * Global screen via 'areabase', e.g. top-bar & status-bar. 50 * 51 * 52 * Window Layout 53 * ============= 54 * 55 * <pre> 56 * wmWindow -> bScreen 57 * +----------------------------------------------------------+ 58 * |+-----------------------------------------+-------------+ | 59 * ||ScrArea (links to 3D view) |ScrArea | | 60 * ||+-------++----------+-------------------+|(links to | | 61 * |||ARegion|| |ARegion (quad view)|| properties) | | 62 * |||(tools)|| | || | | 63 * ||| || | || | | 64 * ||| || | || | | 65 * ||| || | || | | 66 * ||| |+----------+-------------------+| | | 67 * ||| || | || | | 68 * ||| || | || | | 69 * ||| || | || | | 70 * ||| || | || | | 71 * ||| || | || | | 72 * ||+-------++----------+-------------------+| | | 73 * |+-----------------------------------------+-------------+ | 74 * +----------------------------------------------------------+ 75 * </pre> 76 * 77 * Space Data 78 * ========== 79 * 80 * <pre> 81 * ScrArea's store a list of space data (SpaceLinks), each of unique type. 82 * The first one is the displayed in the UI, others are added as needed. 83 * 84 * +----------------------------+ <-- area->spacedata.first; 85 * | | 86 * | |---+ <-- other inactive SpaceLink's stored. 87 * | | | 88 * | | |---+ 89 * | | | | 90 * | | | | 91 * | | | | 92 * | | | | 93 * +----------------------------+ | | 94 * | | | 95 * +-----------------------------+ | 96 * | | 97 * +------------------------------+ 98 * </pre> 99 * 100 * A common way to get the space from the ScrArea: 101 * \code{.c} 102 * if (area->spacetype == SPACE_VIEW3D) { 103 * View3D *v3d = area->spacedata.first; 104 * ... 105 * } 106 * \endcode 107 */ 108 109 #pragma once 110 111 struct ID; 112 struct ImBuf; 113 struct bContext; 114 struct wmEvent; 115 struct wmOperator; 116 struct wmWindowManager; 117 118 #include "BLI_compiler_attrs.h" 119 #include "DNA_listBase.h" 120 #include "DNA_vec_types.h" 121 #include "RNA_types.h" 122 123 /* exported types for WM */ 124 #include "gizmo/WM_gizmo_types.h" 125 #include "wm_cursors.h" 126 #include "wm_event_types.h" 127 128 /* Include external gizmo API's */ 129 #include "gizmo/WM_gizmo_api.h" 130 131 #ifdef __cplusplus 132 extern "C" { 133 #endif 134 135 typedef struct wmGenericUserData { 136 void *data; 137 /** When NULL, use #MEM_freeN. */ 138 void (*free_fn)(void *data); 139 bool use_free; 140 } wmGenericUserData; 141 142 typedef struct wmGenericCallback { 143 void (*exec)(struct bContext *C, void *user_data); 144 void *user_data; 145 void (*free_user_data)(void *user_data); 146 } wmGenericCallback; 147 148 /* ************** wmOperatorType ************************ */ 149 150 /** #wmOperatorType.flag */ 151 enum { 152 /** Register operators in stack after finishing (needed for redo). */ 153 OPTYPE_REGISTER = (1 << 0), 154 /** Do an undo push after the operator runs. */ 155 OPTYPE_UNDO = (1 << 1), 156 /** Let Blender grab all input from the WM (X11). */ 157 OPTYPE_BLOCKING = (1 << 2), 158 OPTYPE_MACRO = (1 << 3), 159 160 /** Grabs the cursor and optionally enables continuous cursor wrapping. */ 161 OPTYPE_GRAB_CURSOR_XY = (1 << 4), 162 /** Only warp on the X axis. */ 163 OPTYPE_GRAB_CURSOR_X = (1 << 5), 164 /** Only warp on the Y axis. */ 165 OPTYPE_GRAB_CURSOR_Y = (1 << 6), 166 167 /** Show preset menu. */ 168 OPTYPE_PRESET = (1 << 7), 169 170 /** 171 * Some operators are mainly for internal use and don't make sense 172 * to be accessed from the search menu, even if poll() returns true. 173 * Currently only used for the search toolbox. 174 */ 175 OPTYPE_INTERNAL = (1 << 8), 176 177 /** Allow operator to run when interface is locked. */ 178 OPTYPE_LOCK_BYPASS = (1 << 9), 179 /** Special type of undo which doesn't store itself multiple times. */ 180 OPTYPE_UNDO_GROUPED = (1 << 10), 181 }; 182 183 /** For #WM_cursor_grab_enable wrap axis. */ 184 enum { 185 WM_CURSOR_WRAP_NONE = 0, 186 WM_CURSOR_WRAP_X, 187 WM_CURSOR_WRAP_Y, 188 WM_CURSOR_WRAP_XY, 189 }; 190 191 /** 192 * Context to call operator in for #WM_operator_name_call. 193 * rna_ui.c contains EnumPropertyItem's of these, keep in sync. 194 */ 195 enum { 196 /* if there's invoke, call it, otherwise exec */ 197 WM_OP_INVOKE_DEFAULT, 198 WM_OP_INVOKE_REGION_WIN, 199 WM_OP_INVOKE_REGION_CHANNELS, 200 WM_OP_INVOKE_REGION_PREVIEW, 201 WM_OP_INVOKE_AREA, 202 WM_OP_INVOKE_SCREEN, 203 /* only call exec */ 204 WM_OP_EXEC_DEFAULT, 205 WM_OP_EXEC_REGION_WIN, 206 WM_OP_EXEC_REGION_CHANNELS, 207 WM_OP_EXEC_REGION_PREVIEW, 208 WM_OP_EXEC_AREA, 209 WM_OP_EXEC_SCREEN, 210 }; 211 212 /* property tags for RNA_OperatorProperties */ 213 typedef enum eOperatorPropTags { 214 OP_PROP_TAG_ADVANCED = (1 << 0), 215 } eOperatorPropTags; 216 #define OP_PROP_TAG_ADVANCED ((eOperatorPropTags)OP_PROP_TAG_ADVANCED) 217 218 /* ************** wmKeyMap ************************ */ 219 220 /* modifier */ 221 #define KM_SHIFT 1 222 #define KM_CTRL 2 223 #define KM_ALT 4 224 #define KM_OSKEY 8 225 /* means modifier should be pressed 2nd */ 226 #define KM_SHIFT2 16 227 #define KM_CTRL2 32 228 #define KM_ALT2 64 229 #define KM_OSKEY2 128 230 231 /* KM_MOD_ flags for wmKeyMapItem and wmEvent.alt/shift/oskey/ctrl */ 232 /* note that KM_ANY and KM_NOTHING are used with these defines too */ 233 #define KM_MOD_FIRST 1 234 #define KM_MOD_SECOND 2 235 236 /* type: defined in wm_event_types.c */ 237 #define KM_TEXTINPUT -2 238 239 /* val */ 240 #define KM_ANY -1 241 #define KM_NOTHING 0 242 #define KM_PRESS 1 243 #define KM_RELEASE 2 244 #define KM_CLICK 3 245 #define KM_DBL_CLICK 4 246 #define KM_CLICK_DRAG 5 247 248 /* ************** UI Handler ***************** */ 249 250 #define WM_UI_HANDLER_CONTINUE 0 251 #define WM_UI_HANDLER_BREAK 1 252 253 /* ************** Notifiers ****************** */ 254 255 typedef struct wmNotifier { 256 struct wmNotifier *next, *prev; 257 258 const struct wmWindow *window; 259 260 unsigned int category, data, subtype, action; 261 262 void *reference; 263 264 } wmNotifier; 265 266 /* 4 levels 267 * 268 * 0xFF000000; category 269 * 0x00FF0000; data 270 * 0x0000FF00; data subtype (unused?) 271 * 0x000000FF; action 272 */ 273 274 /* category */ 275 #define NOTE_CATEGORY 0xFF000000 276 #define NC_WM (1 << 24) 277 #define NC_WINDOW (2 << 24) 278 #define NC_SCREEN (3 << 24) 279 #define NC_SCENE (4 << 24) 280 #define NC_OBJECT (5 << 24) 281 #define NC_MATERIAL (6 << 24) 282 #define NC_TEXTURE (7 << 24) 283 #define NC_LAMP (8 << 24) 284 #define NC_GROUP (9 << 24) 285 #define NC_IMAGE (10 << 24) 286 #define NC_BRUSH (11 << 24) 287 #define NC_TEXT (12 << 24) 288 #define NC_WORLD (13 << 24) 289 #define NC_ANIMATION (14 << 24) 290 #define NC_SPACE (15 << 24) 291 #define NC_GEOM (16 << 24) 292 #define NC_NODE (17 << 24) 293 #define NC_ID (18 << 24) 294 #define NC_PAINTCURVE (19 << 24) 295 #define NC_MOVIECLIP (20 << 24) 296 #define NC_MASK (21 << 24) 297 #define NC_GPENCIL (22 << 24) 298 #define NC_LINESTYLE (23 << 24) 299 #define NC_CAMERA (24 << 24) 300 #define NC_LIGHTPROBE (25 << 24) 301 302 /* data type, 256 entries is enough, it can overlap */ 303 #define NOTE_DATA 0x00FF0000 304 305 /* NC_WM windowmanager */ 306 #define ND_FILEREAD (1 << 16) 307 #define ND_FILESAVE (2 << 16) 308 #define ND_DATACHANGED (3 << 16) 309 #define ND_HISTORY (4 << 16) 310 #define ND_JOB (5 << 16) 311 #define ND_UNDO (6 << 16) 312 #define ND_XR_DATA_CHANGED (7 << 16) 313 314 /* NC_SCREEN */ 315 #define ND_LAYOUTBROWSE (1 << 16) 316 #define ND_LAYOUTDELETE (2 << 16) 317 #define ND_ANIMPLAY (4 << 16) 318 #define ND_GPENCIL (5 << 16) 319 #define ND_EDITOR_CHANGED (6 << 16) /*sent to new editors after switching to them*/ 320 #define ND_LAYOUTSET (7 << 16) 321 #define ND_SKETCH (8 << 16) 322 #define ND_WORKSPACE_SET (9 << 16) 323 #define ND_WORKSPACE_DELETE (10 << 16) 324 325 /* NC_SCENE Scene */ 326 #define ND_SCENEBROWSE (1 << 16) 327 #define ND_MARKERS (2 << 16) 328 #define ND_FRAME (3 << 16) 329 #define ND_RENDER_OPTIONS (4 << 16) 330 #define ND_NODES (5 << 16) 331 #define ND_SEQUENCER (6 << 16) 332 /* Note: If an object was added, removed, merged/joined, ..., it is not enough to notify with 333 * this. This affects the layer so also send a layer change notifier (e.g. ND_LAYER_CONTENT)! */ 334 #define ND_OB_ACTIVE (7 << 16) 335 /* See comment on ND_OB_ACTIVE. */ 336 #define ND_OB_SELECT (8 << 16) 337 #define ND_OB_VISIBLE (9 << 16) 338 #define ND_OB_RENDER (10 << 16) 339 #define ND_MODE (11 << 16) 340 #define ND_RENDER_RESULT (12 << 16) 341 #define ND_COMPO_RESULT (13 << 16) 342 #define ND_KEYINGSET (14 << 16) 343 #define ND_TOOLSETTINGS (15 << 16) 344 #define ND_LAYER (16 << 16) 345 #define ND_FRAME_RANGE (17 << 16) 346 #define ND_TRANSFORM_DONE (18 << 16) 347 #define ND_WORLD (92 << 16) 348 #define ND_LAYER_CONTENT (101 << 16) 349 350 /* NC_OBJECT Object */ 351 #define ND_TRANSFORM (18 << 16) 352 #define ND_OB_SHADING (19 << 16) 353 #define ND_POSE (20 << 16) 354 #define ND_BONE_ACTIVE (21 << 16) 355 #define ND_BONE_SELECT (22 << 16) 356 #define ND_DRAW (23 << 16) 357 #define ND_MODIFIER (24 << 16) 358 #define ND_KEYS (25 << 16) 359 #define ND_CONSTRAINT (26 << 16) 360 #define ND_PARTICLE (27 << 16) 361 #define ND_POINTCACHE (28 << 16) 362 #define ND_PARENT (29 << 16) 363 #define ND_LOD (30 << 16) 364 #define ND_DRAW_RENDER_VIEWPORT \ 365 (31 << 16) /* for camera & sequencer viewport update, also /w NC_SCENE */ 366 #define ND_SHADERFX (32 << 16) 367 368 /* NC_MATERIAL Material */ 369 #define ND_SHADING (30 << 16) 370 #define ND_SHADING_DRAW (31 << 16) 371 #define ND_SHADING_LINKS (32 << 16) 372 #define ND_SHADING_PREVIEW (33 << 16) 373 374 /* NC_LAMP Light */ 375 #define ND_LIGHTING (40 << 16) 376 #define ND_LIGHTING_DRAW (41 << 16) 377 378 /* NC_WORLD World */ 379 #define ND_WORLD_DRAW (45 << 16) 380 381 /* NC_TEXT Text */ 382 #define ND_CURSOR (50 << 16) 383 #define ND_DISPLAY (51 << 16) 384 385 /* NC_ANIMATION Animato */ 386 #define ND_KEYFRAME (70 << 16) 387 #define ND_KEYFRAME_PROP (71 << 16) 388 #define ND_ANIMCHAN (72 << 16) 389 #define ND_NLA (73 << 16) 390 #define ND_NLA_ACTCHANGE (74 << 16) 391 #define ND_FCURVES_ORDER (75 << 16) 392 393 /* NC_GPENCIL */ 394 #define ND_GPENCIL_EDITMODE (85 << 16) 395 396 /* NC_GEOM Geometry */ 397 /* Mesh, Curve, MetaBall, Armature, .. */ 398 #define ND_SELECT (90 << 16) 399 #define ND_DATA (91 << 16) 400 #define ND_VERTEX_GROUP (92 << 16) 401 402 /* NC_NODE Nodes */ 403 404 /* NC_SPACE */ 405 #define ND_SPACE_CONSOLE (1 << 16) /* general redraw */ 406 #define ND_SPACE_INFO_REPORT (2 << 16) /* update for reports, could specify type */ 407 #define ND_SPACE_INFO (3 << 16) 408 #define ND_SPACE_IMAGE (4 << 16) 409 #define ND_SPACE_FILE_PARAMS (5 << 16) 410 #define ND_SPACE_FILE_LIST (6 << 16) 411 #define ND_SPACE_NODE (7 << 16) 412 #define ND_SPACE_OUTLINER (8 << 16) 413 #define ND_SPACE_VIEW3D (9 << 16) 414 #define ND_SPACE_PROPERTIES (10 << 16) 415 #define ND_SPACE_TEXT (11 << 16) 416 #define ND_SPACE_TIME (12 << 16) 417 #define ND_SPACE_GRAPH (13 << 16) 418 #define ND_SPACE_DOPESHEET (14 << 16) 419 #define ND_SPACE_NLA (15 << 16) 420 #define ND_SPACE_SEQUENCER (16 << 16) 421 #define ND_SPACE_NODE_VIEW (17 << 16) 422 #define ND_SPACE_CHANGED (18 << 16) /*sent to a new editor type after it's replaced an old one*/ 423 #define ND_SPACE_CLIP (19 << 16) 424 #define ND_SPACE_FILE_PREVIEW (20 << 16) 425 426 /* subtype, 256 entries too */ 427 #define NOTE_SUBTYPE 0x0000FF00 428 429 /* subtype scene mode */ 430 #define NS_MODE_OBJECT (1 << 8) 431 432 #define NS_EDITMODE_MESH (2 << 8) 433 #define NS_EDITMODE_CURVE (3 << 8) 434 #define NS_EDITMODE_SURFACE (4 << 8) 435 #define NS_EDITMODE_TEXT (5 << 8) 436 #define NS_EDITMODE_MBALL (6 << 8) 437 #define NS_EDITMODE_LATTICE (7 << 8) 438 #define NS_EDITMODE_ARMATURE (8 << 8) 439 #define NS_MODE_POSE (9 << 8) 440 #define NS_MODE_PARTICLE (10 << 8) 441 442 /* subtype 3d view editing */ 443 #define NS_VIEW3D_GPU (16 << 8) 444 #define NS_VIEW3D_SHADING (17 << 8) 445 446 /* subtype layer editing */ 447 #define NS_LAYER_COLLECTION (24 << 8) 448 449 /* action classification */ 450 #define NOTE_ACTION (0x000000FF) 451 #define NA_EDITED 1 452 #define NA_EVALUATED 2 453 #define NA_ADDED 3 454 #define NA_REMOVED 4 455 #define NA_RENAME 5 456 #define NA_SELECTED 6 457 #define NA_ACTIVATED 7 458 #define NA_PAINTING 8 459 460 /* ************** Gesture Manager data ************** */ 461 462 /* wmGesture->type */ 463 #define WM_GESTURE_TWEAK 0 464 #define WM_GESTURE_LINES 1 465 #define WM_GESTURE_RECT 2 466 #define WM_GESTURE_CROSS_RECT 3 467 #define WM_GESTURE_LASSO 4 468 #define WM_GESTURE_CIRCLE 5 469 #define WM_GESTURE_STRAIGHTLINE 6 470 471 /** 472 * wmGesture is registered to #wmWindow.gesture, handled by operator callbacks. 473 * Tweak gesture is builtin feature. 474 */ 475 typedef struct wmGesture { 476 struct wmGesture *next, *prev; 477 /** #wmEvent.type */ 478 int event_type; 479 /** Gesture type define. */ 480 int type; 481 /** bounds of region to draw gesture within. */ 482 rcti winrct; 483 /** optional, amount of points stored. */ 484 int points; 485 /** optional, maximum amount of points stored. */ 486 int points_alloc; 487 int modal_state; 488 /** optional, draw the active side of the straightline gesture. */ 489 bool draw_active_side; 490 491 /** 492 * For modal operators which may be running idle, waiting for an event to activate the gesture. 493 * Typically this is set when the user is click-dragging the gesture 494 * (box and circle select for eg). 495 */ 496 uint is_active : 1; 497 /** Previous value of is-active (use to detect first run & edge cases). */ 498 uint is_active_prev : 1; 499 /** Use for gestures that support both immediate or delayed activation. */ 500 uint wait_for_input : 1; 501 /** Use for gestures that can be moved, like box selection */ 502 uint move : 1; 503 /** For gestures that support snapping, stores if snapping is enabled using the modal keymap 504 * toggle. */ 505 uint use_snap : 1; 506 /** For gestures that support flip, stores if flip is enabled using the modal keymap 507 * toggle. */ 508 uint use_flip : 1; 509 510 /** 511 * customdata 512 * - for border is a #rcti. 513 * - for circle is recti, (xmin, ymin) is center, xmax radius. 514 * - for lasso is short array. 515 * - for straight line is a recti: (xmin,ymin) is start, (xmax, ymax) is end. 516 */ 517 void *customdata; 518 519 /** Free pointer to use for operator allocs (if set, its freed on exit). */ 520 wmGenericUserData user_data; 521 } wmGesture; 522 523 /* ************** wmEvent ************************ */ 524 525 typedef struct wmTabletData { 526 /** 0=EVT_TABLET_NONE, 1=EVT_TABLET_STYLUS, 2=EVT_TABLET_ERASER. */ 527 int active; 528 /** range 0.0 (not touching) to 1.0 (full pressure). */ 529 float pressure; 530 /** range 0.0 (upright) to 1.0 (tilted fully against the tablet surface). */ 531 float x_tilt; 532 /** as above. */ 533 float y_tilt; 534 /** Interpret mouse motion as absolute as typical for tablets. */ 535 char is_motion_absolute; 536 } wmTabletData; 537 538 /** 539 * Each event should have full modifier state. 540 * event comes from event manager and from keymap. 541 */ 542 typedef struct wmEvent { 543 struct wmEvent *next, *prev; 544 545 /** Event code itself (short, is also in keymap). */ 546 short type; 547 /** Press, release, scrollvalue. */ 548 short val; 549 /** Mouse pointer position, screen coord. */ 550 int x, y; 551 /** Region mouse position, name convention pre 2.5 :). */ 552 int mval[2]; 553 /** 554 * From, ghost if utf8 is enabled for the platform, 555 * #BLI_str_utf8_size() must _always_ be valid, check 556 * when assigning s we don't need to check on every access after. 557 */ 558 char utf8_buf[6]; 559 /** From ghost, fallback if utf8 isn't set. */ 560 char ascii; 561 562 /** 563 * Generated by auto-repeat, note that this must only ever be set for keyboard events 564 * where `ISKEYBOARD(event->type) == true`. 565 * 566 * See #KMI_REPEAT_IGNORE for details on how key-map handling uses this. 567 */ 568 char is_repeat; 569 570 /** Previous state, used for double click and the 'click'. */ 571 short prevtype; 572 short prevval; 573 int prevx, prevy; 574 double prevclicktime; 575 int prevclickx, prevclicky; 576 577 /** Modifier states. */ 578 /** 'oskey' is apple or windows-key, value denotes order of pressed. */ 579 short shift, ctrl, alt, oskey; 580 /** rawkey modifier. */ 581 short keymodifier; 582 583 /** Set in case a #KM_PRESS went by unhandled. */ 584 char check_click; 585 char check_drag; 586 587 /** Tablet info, available for mouse move and button events. */ 588 wmTabletData tablet; 589 590 /* custom data */ 591 /** Custom data type, stylus, 6dof, see wm_event_types.h */ 592 short custom; 593 short customdatafree; 594 int pad2; 595 /** Ascii, unicode, mouse coords, angles, vectors, dragdrop info. */ 596 void *customdata; 597 598 } wmEvent; 599 600 /** 601 * Values below are ignored when detecting if the user intentionally moved the cursor. 602 * Keep this very small since it's used for selection cycling for eg, 603 * where we want intended adjustments to pass this threshold and select new items. 604 * 605 * Always check for <= this value since it may be zero. 606 */ 607 #define WM_EVENT_CURSOR_MOTION_THRESHOLD ((float)U.move_threshold * U.dpi_fac) 608 609 /** Motion progress, for modal handlers. */ 610 typedef enum { 611 P_NOT_STARTED, 612 P_STARTING, /* <-- */ 613 P_IN_PROGRESS, /* <-- only these are sent for NDOF motion. */ 614 P_FINISHING, /* <-- */ 615 P_FINISHED, 616 } wmProgress; 617 618 #ifdef WITH_INPUT_NDOF 619 typedef struct wmNDOFMotionData { 620 /* awfully similar to GHOST_TEventNDOFMotionData... */ 621 /** 622 * Each component normally ranges from -1 to +1, but can exceed that. 623 * These use blender standard view coordinates, 624 * with positive rotations being CCW about the axis. 625 */ 626 /** Translation. */ 627 float tvec[3]; 628 /** Rotation. 629 * <pre> 630 * axis = (rx,ry,rz).normalized. 631 * amount = (rx,ry,rz).magnitude [in revolutions, 1.0 = 360 deg] 632 * </pre> 633 */ 634 float rvec[3]; 635 /** Time since previous NDOF Motion event. */ 636 float dt; 637 /** Is this the first event, the last, or one of many in between? */ 638 wmProgress progress; 639 } wmNDOFMotionData; 640 #endif /* WITH_INPUT_NDOF */ 641 642 /** Timer flags. */ 643 typedef enum { 644 /** Do not attempt to free customdata pointer even if non-NULL. */ 645 WM_TIMER_NO_FREE_CUSTOM_DATA = 1 << 0, 646 } wmTimerFlags; 647 648 typedef struct wmTimer { 649 struct wmTimer *next, *prev; 650 651 /** Window this timer is attached to (optional). */ 652 struct wmWindow *win; 653 654 /** Set by timer user. */ 655 double timestep; 656 /** Set by timer user, goes to event system. */ 657 int event_type; 658 /** Various flags controlling timer options, see below. */ 659 wmTimerFlags flags; 660 /** Set by timer user, to allow custom values. */ 661 void *customdata; 662 663 /** Total running time in seconds. */ 664 double duration; 665 /** Time since previous step in seconds. */ 666 double delta; 667 668 /** Internal, last time timer was activated. */ 669 double ltime; 670 /** Internal, next time we want to activate the timer. */ 671 double ntime; 672 /** Internal, when the timer started. */ 673 double stime; 674 /** Internal, put timers to sleep when needed. */ 675 bool sleep; 676 } wmTimer; 677 678 typedef struct wmOperatorType { 679 /** Text for UI, undo. */ 680 const char *name; 681 /** Unique identifier. */ 682 const char *idname; 683 const char *translation_context; 684 /** Use for tool-tips and Python docs. */ 685 const char *description; 686 /** Identifier to group operators together. */ 687 const char *undo_group; 688 689 /** 690 * This callback executes the operator without any interactive input, 691 * parameters may be provided through operator properties. cannot use 692 * any interface code or input device state. 693 * See defines below for return values. 694 */ 695 int (*exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT; 696 697 /** 698 * This callback executes on a running operator whenever as property 699 * is changed. It can correct its own properties or report errors for 700 * invalid settings in exceptional cases. 701 * Boolean return value, True denotes a change has been made and to redraw. 702 */ 703 bool (*check)(struct bContext *, struct wmOperator *); 704 705 /** 706 * For modal temporary operators, initially invoke is called. then 707 * any further events are handled in modal. if the operation is 708 * canceled due to some external reason, cancel is called 709 * See defines below for return values. 710 */ 711 int (*invoke)(struct bContext *, 712 struct wmOperator *, 713 const struct wmEvent *) ATTR_WARN_UNUSED_RESULT; 714 715 /** 716 * Called when a modal operator is canceled (not used often). 717 * Internal cleanup can be done here if needed. 718 */ 719 void (*cancel)(struct bContext *, struct wmOperator *); 720 721 /** 722 * Modal is used for operators which continuously run, eg: 723 * fly mode, knife tool, circle select are all examples of modal operators. 724 * Modal operators can handle events which would normally access other operators, 725 * they keep running until they don't return `OPERATOR_RUNNING_MODAL`. 726 */ 727 int (*modal)(struct bContext *, 728 struct wmOperator *, 729 const struct wmEvent *) ATTR_WARN_UNUSED_RESULT; 730 731 /** 732 * Verify if the operator can be executed in the current context, note 733 * that the operator might still fail to execute even if this return true. 734 */ 735 bool (*poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT; 736 737 /** 738 * Use to check if properties should be displayed in auto-generated UI. 739 * Use 'check' callback to enforce refreshing. 740 */ 741 bool (*poll_property)(const struct bContext *C, 742 struct wmOperator *op, 743 const PropertyRNA *prop) ATTR_WARN_UNUSED_RESULT; 744 745 /** Optional panel for redo and repeat, auto-generated if not set. */ 746 void (*ui)(struct bContext *, struct wmOperator *); 747 748 /** 749 * Return a different name to use in the user interface, based on property values. 750 * The returned string does not need to be freed. 751 */ 752 const char *(*get_name)(struct wmOperatorType *, struct PointerRNA *); 753 754 /** 755 * Return a different description to use in the user interface, based on property values. 756 * The returned string must be freed by the caller, unless NULL. 757 */ 758 char *(*get_description)(struct bContext *C, struct wmOperatorType *, struct PointerRNA *); 759 760 /** rna for properties */ 761 struct StructRNA *srna; 762 763 /** previous settings - for initializing on re-use */ 764 struct IDProperty *last_properties; 765 766 /** 767 * Default rna property to use for generic invoke functions. 768 * menus, enum search... etc. Example: Enum 'type' for a Delete menu. 769 * 770 * When assigned a string/number property, 771 * immediately edit the value when used in a popup. see: #UI_BUT_ACTIVATE_ON_INIT. 772 */ 773 PropertyRNA *prop; 774 775 /** struct wmOperatorTypeMacro */ 776 ListBase macro; 777 778 /** pointer to modal keymap, do not free! */ 779 struct wmKeyMap *modalkeymap; 780 781 /** python needs the operator type as well */ 782 bool (*pyop_poll)(struct bContext *, struct wmOperatorType *ot) ATTR_WARN_UNUSED_RESULT; 783 784 /** RNA integration */ 785 ExtensionRNA rna_ext; 786 787 /** Flag last for padding */ 788 short flag; 789 790 } wmOperatorType; 791 792 /** 793 * Wrapper to reference a #wmOperatorType together with some set properties and other relevant 794 * information to invoke the operator in a customizable way. 795 */ 796 typedef struct wmOperatorCallParams { 797 struct wmOperatorType *optype; 798 struct PointerRNA *opptr; 799 short opcontext; 800 } wmOperatorCallParams; 801 802 #ifdef WITH_INPUT_IME 803 /* *********** Input Method Editor (IME) *********** */ 804 /** 805 * \note similar to #GHOST_TEventImeData. 806 */ 807 typedef struct wmIMEData { 808 size_t result_len, composite_len; 809 810 /** utf8 encoding */ 811 char *str_result; 812 /** utf8 encoding */ 813 char *str_composite; 814 815 /** Cursor position in the IME composition. */ 816 int cursor_pos; 817 /** Beginning of the selection. */ 818 int sel_start; 819 /** End of the selection. */ 820 int sel_end; 821 822 bool is_ime_composing; 823 } wmIMEData; 824 #endif 825 826 /* **************** Paint Cursor ******************* */ 827 828 typedef void (*wmPaintCursorDraw)(struct bContext *C, int, int, void *customdata); 829 830 /* *************** Drag and drop *************** */ 831 832 #define WM_DRAG_ID 0 833 #define WM_DRAG_RNA 1 834 #define WM_DRAG_PATH 2 835 #define WM_DRAG_NAME 3 836 #define WM_DRAG_VALUE 4 837 #define WM_DRAG_COLOR 5 838 #define WM_DRAG_DATASTACK 6 839 840 typedef enum wmDragFlags { 841 WM_DRAG_NOP = 0, 842 WM_DRAG_FREE_DATA = 1, 843 } wmDragFlags; 844 845 /* note: structs need not exported? */ 846 847 typedef struct wmDragID { 848 struct wmDragID *next, *prev; 849 struct ID *id; 850 struct ID *from_parent; 851 } wmDragID; 852 853 typedef struct wmDrag { 854 struct wmDrag *next, *prev; 855 856 int icon; 857 /** See 'WM_DRAG_' defines above. */ 858 int type; 859 void *poin; 860 char path[1024]; /* FILE_MAX */ 861 double value; 862 863 /** If no icon but imbuf should be drawn around cursor. */ 864 struct ImBuf *imb; 865 float scale; 866 int sx, sy; 867 868 /** If set, draws operator name. */ 869 char opname[200]; 870 unsigned int flags; 871 872 /** List of wmDragIDs, all are guaranteed to have the same ID type. */ 873 ListBase ids; 874 } wmDrag; 875 876 /** 877 * Dropboxes are like keymaps, part of the screen/area/region definition. 878 * Allocation and free is on startup and exit. 879 */ 880 typedef struct wmDropBox { 881 struct wmDropBox *next, *prev; 882 883 /** Test if the dropbox is active, then can print optype name. */ 884 bool (*poll)(struct bContext *, struct wmDrag *, const wmEvent *, const char **); 885 886 /** Before exec, this copies drag info to #wmDrop properties. */ 887 void (*copy)(struct wmDrag *, struct wmDropBox *); 888 889 /** 890 * If poll succeeds, operator is called. 891 * Not saved in file, so can be pointer. 892 */ 893 wmOperatorType *ot; 894 895 /** Operator properties, assigned to ptr->data and can be written to a file. */ 896 struct IDProperty *properties; 897 /** RNA pointer to access properties. */ 898 struct PointerRNA *ptr; 899 900 /** Default invoke. */ 901 short opcontext; 902 903 } wmDropBox; 904 905 /** 906 * Struct to store tool-tip timer and possible creation if the time is reached. 907 * Allows UI code to call #WM_tooltip_timer_init without each user having to handle the timer. 908 */ 909 typedef struct wmTooltipState { 910 /** Create tooltip on this event. */ 911 struct wmTimer *timer; 912 /** The area the tooltip is created in. */ 913 struct ScrArea *area_from; 914 /** The region the tooltip is created in. */ 915 struct ARegion *region_from; 916 /** The tooltip region. */ 917 struct ARegion *region; 918 /** Create the tooltip region (assign to 'region'). */ 919 struct ARegion *(*init)(struct bContext *C, 920 struct ARegion *region, 921 int *pass, 922 double *pass_delay, 923 bool *r_exit_on_event); 924 /** Exit on any event, not needed for buttons since their highlight state is used. */ 925 bool exit_on_event; 926 /** Cursor location at the point of tooltip creation. */ 927 int event_xy[2]; 928 /** Pass, use when we want multiple tips, count down to zero. */ 929 int pass; 930 } wmTooltipState; 931 932 /* *************** migrated stuff, clean later? ************** */ 933 934 typedef struct RecentFile { 935 struct RecentFile *next, *prev; 936 char *filepath; 937 } RecentFile; 938 939 /* Logging */ 940 struct CLG_LogRef; 941 /* wm_init_exit.c */ 942 extern struct CLG_LogRef *WM_LOG_OPERATORS; 943 extern struct CLG_LogRef *WM_LOG_HANDLERS; 944 extern struct CLG_LogRef *WM_LOG_EVENTS; 945 extern struct CLG_LogRef *WM_LOG_KEYMAPS; 946 extern struct CLG_LogRef *WM_LOG_TOOLS; 947 extern struct CLG_LogRef *WM_LOG_MSGBUS_PUB; 948 extern struct CLG_LogRef *WM_LOG_MSGBUS_SUB; 949 950 #ifdef __cplusplus 951 } 952 #endif 953