2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2007 Blender Foundation.
19 * All rights reserved.
22 * Contributor(s): Blender Foundation
24 * ***** END GPL LICENSE BLOCK *****
27 /** \file blender/windowmanager/WM_types.h
31 #ifndef __WM_TYPES_H__
32 #define __WM_TYPES_H__
35 * Overview of WM structs
36 * ======================
39 * > wmWindowManager (window manager stores a list of windows)
40 * > > wmWindow (window has an active screen)
41 * > > > bScreen (link to ScrAreas via 'areabase')
42 * > > > > ScrArea (stores multiple spaces via space links via 'spacedata')
43 * > > > > > SpaceLink (base struct for space data for all different space types)
44 * > > > > ScrArea (stores multiple regions via 'regionbase')
53 * +----------------------------------------------------------+
54 * |+-----------------------------------------+-------------+ |
55 * ||ScrArea (links to 3D view) |ScrArea | |
56 * ||+-------++----------+-------------------+|(links to | |
57 * |||ARegion|| |ARegion (quad view)|| properties) | |
58 * |||(tools)|| | || | |
62 * ||| |+----------+-------------------+| | |
68 * ||+-------++----------+-------------------+| | |
69 * |+-----------------------------------------+-------------+ |
70 * +----------------------------------------------------------+
77 * ScrArea's store a list of space data (SpaceLinks), each of unique type.
78 * The first one is the displayed in the UI, others are added as needed.
80 * +----------------------------+ <-- sa->spacedata.first;
82 * | |---+ <-- other inactive SpaceLink's stored.
89 * +----------------------------+ | |
91 * +-----------------------------+ |
93 * +------------------------------+
96 * A common way to get the space from the ScrArea:
98 * if (sa->spacetype == SPACE_VIEW3D) {
99 * View3D *v3d = sa->spacedata.first;
111 struct wmWindowManager;
115 #include "RNA_types.h"
116 #include "DNA_listBase.h"
117 #include "BLI_compiler_attrs.h"
119 /* exported types for WM */
120 #include "wm_cursors.h"
121 #include "wm_event_types.h"
123 /* ************** wmOperatorType ************************ */
127 OPTYPE_REGISTER = (1 << 0), /* register operators in stack after finishing */
128 OPTYPE_UNDO = (1 << 1), /* do undo push after after */
129 OPTYPE_BLOCKING = (1 << 2), /* let blender grab all input from the WM (X11) */
130 OPTYPE_MACRO = (1 << 3),
131 OPTYPE_GRAB_CURSOR = (1 << 4), /* grabs the cursor and optionally enables continuous cursor wrapping */
132 OPTYPE_PRESET = (1 << 5), /* show preset menu */
134 /* some operators are mainly for internal use
135 * and don't make sense to be accessed from the
136 * search menu, even if poll() returns true.
137 * currently only used for the search toolbox */
138 OPTYPE_INTERNAL = (1 << 6),
140 OPTYPE_LOCK_BYPASS = (1 << 7), /* Allow operator to run when interface is locked */
141 OPTYPE_UNDO_GROUPED = (1 << 8), /* Special type of undo which doesn't store itself multiple times */
144 /* context to call operator in for WM_operator_name_call */
145 /* rna_ui.c contains EnumPropertyItem's of these, keep in sync */
147 /* if there's invoke, call it, otherwise exec */
148 WM_OP_INVOKE_DEFAULT,
149 WM_OP_INVOKE_REGION_WIN,
150 WM_OP_INVOKE_REGION_CHANNELS,
151 WM_OP_INVOKE_REGION_PREVIEW,
156 WM_OP_EXEC_REGION_WIN,
157 WM_OP_EXEC_REGION_CHANNELS,
158 WM_OP_EXEC_REGION_PREVIEW,
163 /* ************** wmKeyMap ************************ */
170 /* means modifier should be pressed 2nd */
174 #define KM_OSKEY2 128
176 /* KM_MOD_ flags for wmKeyMapItem and wmEvent.alt/shift/oskey/ctrl */
177 /* note that KM_ANY and KM_NOTHING are used with these defines too */
178 #define KM_MOD_FIRST 1
179 #define KM_MOD_SECOND 2
181 /* type: defined in wm_event_types.c */
182 #define KM_TEXTINPUT -2
190 #define KM_DBL_CLICK 4
193 /* ************** UI Handler ***************** */
195 #define WM_UI_HANDLER_CONTINUE 0
196 #define WM_UI_HANDLER_BREAK 1
198 /* ************** Notifiers ****************** */
200 typedef struct wmNotifier {
201 struct wmNotifier *next, *prev;
203 struct wmWindowManager *wm;
204 struct wmWindow *window;
206 int swinid; /* can't rely on this, notifiers can be added without context, swinid of 0 */
207 unsigned int category, data, subtype, action;
216 * 0xFF000000; category
218 * 0x0000FF00; data subtype (unused?)
223 #define NOTE_CATEGORY 0xFF000000
224 #define NC_WM (1<<24)
225 #define NC_WINDOW (2<<24)
226 #define NC_SCREEN (3<<24)
227 #define NC_SCENE (4<<24)
228 #define NC_OBJECT (5<<24)
229 #define NC_MATERIAL (6<<24)
230 #define NC_TEXTURE (7<<24)
231 #define NC_LAMP (8<<24)
232 #define NC_GROUP (9<<24)
233 #define NC_IMAGE (10<<24)
234 #define NC_BRUSH (11<<24)
235 #define NC_TEXT (12<<24)
236 #define NC_WORLD (13<<24)
237 #define NC_ANIMATION (14<<24)
238 #define NC_SPACE (15<<24)
239 #define NC_GEOM (16<<24)
240 #define NC_NODE (17<<24)
241 #define NC_ID (18<<24)
242 #define NC_LOGIC (19<<24)
243 #define NC_MOVIECLIP (20<<24)
244 #define NC_MASK (21<<24)
245 #define NC_GPENCIL (22<<24)
246 #define NC_LINESTYLE (23<<24)
247 #define NC_CAMERA (24<<24)
249 /* data type, 256 entries is enough, it can overlap */
250 #define NOTE_DATA 0x00FF0000
252 /* NC_WM windowmanager */
253 #define ND_FILEREAD (1<<16)
254 #define ND_FILESAVE (2<<16)
255 #define ND_DATACHANGED (3<<16)
256 #define ND_HISTORY (4<<16)
257 #define ND_JOB (5<<16)
258 #define ND_UNDO (6<<16)
260 /* NC_SCREEN screen */
261 #define ND_SCREENBROWSE (1<<16)
262 #define ND_SCREENDELETE (2<<16)
263 #define ND_SCREENCAST (3<<16)
264 #define ND_ANIMPLAY (4<<16)
265 #define ND_GPENCIL (5<<16)
266 #define ND_EDITOR_CHANGED (6<<16) /*sent to new editors after switching to them*/
267 #define ND_SCREENSET (7<<16)
268 #define ND_SKETCH (8<<16)
271 #define ND_SCENEBROWSE (1<<16)
272 #define ND_MARKERS (2<<16)
273 #define ND_FRAME (3<<16)
274 #define ND_RENDER_OPTIONS (4<<16)
275 #define ND_NODES (5<<16)
276 #define ND_SEQUENCER (6<<16)
277 #define ND_OB_ACTIVE (7<<16)
278 #define ND_OB_SELECT (8<<16)
279 #define ND_OB_VISIBLE (9<<16)
280 #define ND_OB_RENDER (10<<16)
281 #define ND_MODE (11<<16)
282 #define ND_RENDER_RESULT (12<<16)
283 #define ND_COMPO_RESULT (13<<16)
284 #define ND_KEYINGSET (14<<16)
285 #define ND_TOOLSETTINGS (15<<16)
286 #define ND_LAYER (16<<16)
287 #define ND_FRAME_RANGE (17<<16)
288 #define ND_TRANSFORM_DONE (18<<16)
289 #define ND_WORLD (92<<16)
290 #define ND_LAYER_CONTENT (101<<16)
292 /* NC_OBJECT Object */
293 #define ND_TRANSFORM (18<<16)
294 #define ND_OB_SHADING (19<<16)
295 #define ND_POSE (20<<16)
296 #define ND_BONE_ACTIVE (21<<16)
297 #define ND_BONE_SELECT (22<<16)
298 #define ND_DRAW (23<<16)
299 #define ND_MODIFIER (24<<16)
300 #define ND_KEYS (25<<16)
301 #define ND_CONSTRAINT (26<<16)
302 #define ND_PARTICLE (27<<16)
303 #define ND_POINTCACHE (28<<16)
304 #define ND_PARENT (29<<16)
305 #define ND_LOD (30<<16)
306 #define ND_DRAW_RENDER_VIEWPORT (31<<16) /* for camera & sequencer viewport update, also /w NC_SCENE */
308 /* NC_MATERIAL Material */
309 #define ND_SHADING (30<<16)
310 #define ND_SHADING_DRAW (31<<16)
311 #define ND_SHADING_LINKS (32<<16)
312 #define ND_SHADING_PREVIEW (33<<16)
315 #define ND_LIGHTING (40<<16)
316 #define ND_LIGHTING_DRAW (41<<16)
317 #define ND_SKY (42<<16)
320 #define ND_WORLD_DRAW (45<<16)
323 #define ND_CURSOR (50<<16)
324 #define ND_DISPLAY (51<<16)
326 /* NC_ANIMATION Animato */
327 #define ND_KEYFRAME (70<<16)
328 #define ND_KEYFRAME_PROP (71<<16)
329 #define ND_ANIMCHAN (72<<16)
330 #define ND_NLA (73<<16)
331 #define ND_NLA_ACTCHANGE (74<<16)
332 #define ND_FCURVES_ORDER (75<<16)
335 #define ND_GPENCIL_EDITMODE (85<<16)
337 /* NC_GEOM Geometry */
338 /* Mesh, Curve, MetaBall, Armature, .. */
339 #define ND_SELECT (90<<16)
340 #define ND_DATA (91<<16)
341 #define ND_VERTEX_GROUP (92<<16)
346 #define ND_SPACE_CONSOLE (1<<16) /* general redraw */
347 #define ND_SPACE_INFO_REPORT (2<<16) /* update for reports, could specify type */
348 #define ND_SPACE_INFO (3<<16)
349 #define ND_SPACE_IMAGE (4<<16)
350 #define ND_SPACE_FILE_PARAMS (5<<16)
351 #define ND_SPACE_FILE_LIST (6<<16)
352 #define ND_SPACE_NODE (7<<16)
353 #define ND_SPACE_OUTLINER (8<<16)
354 #define ND_SPACE_VIEW3D (9<<16)
355 #define ND_SPACE_PROPERTIES (10<<16)
356 #define ND_SPACE_TEXT (11<<16)
357 #define ND_SPACE_TIME (12<<16)
358 #define ND_SPACE_GRAPH (13<<16)
359 #define ND_SPACE_DOPESHEET (14<<16)
360 #define ND_SPACE_NLA (15<<16)
361 #define ND_SPACE_SEQUENCER (16<<16)
362 #define ND_SPACE_NODE_VIEW (17<<16)
363 #define ND_SPACE_CHANGED (18<<16) /*sent to a new editor type after it's replaced an old one*/
364 #define ND_SPACE_CLIP (19<<16)
365 #define ND_SPACE_FILE_PREVIEW (20<<16)
367 /* subtype, 256 entries too */
368 #define NOTE_SUBTYPE 0x0000FF00
370 /* subtype scene mode */
371 #define NS_MODE_OBJECT (1<<8)
373 #define NS_EDITMODE_MESH (2<<8)
374 #define NS_EDITMODE_CURVE (3<<8)
375 #define NS_EDITMODE_SURFACE (4<<8)
376 #define NS_EDITMODE_TEXT (5<<8)
377 #define NS_EDITMODE_MBALL (6<<8)
378 #define NS_EDITMODE_LATTICE (7<<8)
379 #define NS_EDITMODE_ARMATURE (8<<8)
380 #define NS_MODE_POSE (9<<8)
381 #define NS_MODE_PARTICLE (10<<8)
383 /* subtype 3d view editing */
384 #define NS_VIEW3D_GPU (16<<8)
386 /* action classification */
387 #define NOTE_ACTION (0x000000FF)
389 #define NA_EVALUATED 2
393 #define NA_SELECTED 6
394 #define NA_PAINTING 7
396 /* ************** Gesture Manager data ************** */
398 /* wmGesture->type */
399 #define WM_GESTURE_TWEAK 0
400 #define WM_GESTURE_LINES 1
401 #define WM_GESTURE_RECT 2
402 #define WM_GESTURE_CROSS_RECT 3
403 #define WM_GESTURE_LASSO 4
404 #define WM_GESTURE_CIRCLE 5
405 #define WM_GESTURE_STRAIGHTLINE 6
407 /* wmGesture is registered to window listbase, handled by operator callbacks */
408 /* tweak gesture is builtin feature */
409 typedef struct wmGesture {
410 struct wmGesture *next, *prev;
411 int event_type; /* event->type */
412 int type; /* gesture type define */
413 int swinid; /* initial subwindow id where it started */
414 int points; /* optional, amount of points stored */
415 int points_alloc; /* optional, maximum amount of points stored */
418 /* For modal operators which may be running idle, waiting for an event to activate the gesture.
419 * Typically this is set when the user is click-dragging the gesture (border and circle select for eg). */
421 /* Use for gestures that support both immediate or delayed activation. */
422 uint wait_for_input : 1;
425 /* customdata for border is a recti */
426 /* customdata for circle is recti, (xmin, ymin) is center, xmax radius */
427 /* customdata for lasso is short array */
428 /* customdata for straight line is a recti: (xmin,ymin) is start, (xmax, ymax) is end */
430 /* free pointer to use for operator allocs (if set, its freed on exit)*/
435 /* ************** wmEvent ************************ */
437 /* each event should have full modifier state */
438 /* event comes from eventmanager and from keymap */
439 typedef struct wmEvent {
440 struct wmEvent *next, *prev;
442 short type; /* event code itself (short, is also in keymap) */
443 short val; /* press, release, scrollvalue */
444 int x, y; /* mouse pointer position, screen coord */
445 int mval[2]; /* region mouse position, name convention pre 2.5 :) */
446 char utf8_buf[6]; /* from, ghost if utf8 is enabled for the platform,
447 * BLI_str_utf8_size() must _always_ be valid, check
448 * when assigning s we don't need to check on every access after */
449 char ascii; /* from ghost, fallback if utf8 isn't set */
452 /* previous state, used for double click and the 'click' */
456 double prevclicktime;
457 int prevclickx, prevclicky;
459 /* modifier states */
460 short shift, ctrl, alt, oskey; /* oskey is apple or windowskey, value denotes order of pressed */
461 short keymodifier; /* rawkey modifier */
463 /* set in case a KM_PRESS went by unhandled */
465 char is_motion_absolute;
467 /* keymap item, set by handler (weak?) */
468 const char *keymap_idname;
470 /* tablet info, only use when the tablet is active */
471 const struct wmTabletData *tablet_data;
474 short custom; /* custom data type, stylus, 6dof, see wm_event_types.h */
475 short customdatafree;
477 void *customdata; /* ascii, unicode, mouse coords, angles, vectors, dragdrop info */
481 /* ************** custom wmEvent data ************** */
482 typedef struct wmTabletData {
483 int Active; /* 0=EVT_TABLET_NONE, 1=EVT_TABLET_STYLUS, 2=EVT_TABLET_ERASER */
484 float Pressure; /* range 0.0 (not touching) to 1.0 (full pressure) */
485 float Xtilt; /* range 0.0 (upright) to 1.0 (tilted fully against the tablet surface) */
486 float Ytilt; /* as above */
489 typedef enum { /* motion progress, for modal handlers */
491 P_STARTING, /* <-- */
492 P_IN_PROGRESS, /* <-- only these are sent for NDOF motion*/
493 P_FINISHING, /* <-- */
497 #ifdef WITH_INPUT_NDOF
498 typedef struct wmNDOFMotionData {
499 /* awfully similar to GHOST_TEventNDOFMotionData... */
500 /* Each component normally ranges from -1 to +1, but can exceed that.
501 * These use blender standard view coordinates, with positive rotations being CCW about the axis. */
502 float tvec[3]; /* translation */
503 float rvec[3]; /* rotation: */
504 /* axis = (rx,ry,rz).normalized */
505 /* amount = (rx,ry,rz).magnitude [in revolutions, 1.0 = 360 deg] */
506 float dt; /* time since previous NDOF Motion event */
507 wmProgress progress; /* is this the first event, the last, or one of many in between? */
509 #endif /* WITH_INPUT_NDOF */
511 typedef enum { /* Timer flags */
512 WM_TIMER_NO_FREE_CUSTOM_DATA = 1 << 0, /* Do not attempt to free customdata pointer even if non-NULL. */
515 typedef struct wmTimer {
516 struct wmTimer *next, *prev;
518 struct wmWindow *win; /* window this timer is attached to (optional) */
520 double timestep; /* set by timer user */
521 int event_type; /* set by timer user, goes to event system */
522 wmTimerFlags flags; /* Various flags controlling timer options, see below. */
523 void *customdata; /* set by timer user, to allow custom values */
525 double duration; /* total running time in seconds */
526 double delta; /* time since previous step in seconds */
528 double ltime; /* internal, last time timer was activated */
529 double ntime; /* internal, next time we want to activate the timer */
530 double stime; /* internal, when the timer started */
531 bool sleep; /* internal, put timers to sleep when needed */
534 typedef struct wmOperatorType {
535 const char *name; /* text for ui, undo */
536 const char *idname; /* unique identifier */
537 const char *translation_context;
538 const char *description; /* tooltips and python docs */
539 const char *undo_group; /* identifier to group operators together */
541 /* this callback executes the operator without any interactive input,
542 * parameters may be provided through operator properties. cannot use
543 * any interface code or input device state.
544 * - see defines below for return values */
545 int (*exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT;
547 /* this callback executes on a running operator whenever as property
548 * is changed. It can correct its own properties or report errors for
549 * invalid settings in exceptional cases.
550 * Boolean return value, True denotes a change has been made and to redraw */
551 bool (*check)(struct bContext *, struct wmOperator *);
553 /* for modal temporary operators, initially invoke is called. then
554 * any further events are handled in modal. if the operation is
555 * canceled due to some external reason, cancel is called
556 * - see defines below for return values */
557 int (*invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT;
559 /* Called when a modal operator is canceled (not used often).
560 * Internal cleanup can be done here if needed. */
561 void (*cancel)(struct bContext *, struct wmOperator *);
563 /* Modal is used for operators which continuously run, eg:
564 * fly mode, knife tool, circle select are all examples of modal operators.
565 * Modal operators can handle events which would normally access other operators,
566 * they keep running until they don't return `OPERATOR_RUNNING_MODAL`. */
567 int (*modal)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT;
569 /* verify if the operator can be executed in the current context, note
570 * that the operator might still fail to execute even if this return true */
571 int (*poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT;
573 /* optional panel for redo and repeat, autogenerated if not set */
574 void (*ui)(struct bContext *, struct wmOperator *);
576 /* rna for properties */
577 struct StructRNA *srna;
579 /* previous settings - for initializing on re-use */
580 struct IDProperty *last_properties;
582 /* Default rna property to use for generic invoke functions.
583 * menus, enum search... etc. Example: Enum 'type' for a Delete menu */
586 /* struct wmOperatorTypeMacro */
589 /* pointer to modal keymap, do not free! */
590 struct wmKeyMap *modalkeymap;
592 /* python needs the operator type as well */
593 int (*pyop_poll)(struct bContext *, struct wmOperatorType *ot) ATTR_WARN_UNUSED_RESULT;
595 /* RNA integration */
598 /* Flag last for padding */
603 #ifdef WITH_INPUT_IME
604 /* *********** Input Method Editor (IME) *********** */
606 /* similar to GHOST_TEventImeData */
607 typedef struct wmIMEData {
608 size_t result_len, composite_len;
610 char *str_result; /* utf8 encoding */
611 char *str_composite; /* utf8 encoding */
613 int cursor_pos; /* cursor position in the IME composition. */
614 int sel_start; /* beginning of the selection */
615 int sel_end; /* end of the selection */
617 bool is_ime_composing;
621 /* **************** Paint Cursor ******************* */
623 typedef void (*wmPaintCursorDraw)(struct bContext *C, int, int, void *customdata);
625 /* *************** Drag and drop *************** */
628 #define WM_DRAG_RNA 1
629 #define WM_DRAG_PATH 2
630 #define WM_DRAG_NAME 3
631 #define WM_DRAG_VALUE 4
632 #define WM_DRAG_COLOR 5
634 typedef enum wmDragFlags {
636 WM_DRAG_FREE_DATA = 1,
639 /* note: structs need not exported? */
641 typedef struct wmDrag {
642 struct wmDrag *next, *prev;
644 int icon, type; /* type, see WM_DRAG defines above */
646 char path[1024]; /* FILE_MAX */
649 struct ImBuf *imb; /* if no icon but imbuf should be drawn around cursor */
653 char opname[200]; /* if set, draws operator name*/
657 /* dropboxes are like keymaps, part of the screen/area/region definition */
658 /* allocation and free is on startup and exit */
659 typedef struct wmDropBox {
660 struct wmDropBox *next, *prev;
662 /* test if the dropbox is active, then can print optype name */
663 int (*poll)(struct bContext *, struct wmDrag *, const wmEvent *);
665 /* before exec, this copies drag info to wmDrop properties */
666 void (*copy)(struct wmDrag *, struct wmDropBox *);
668 /* if poll survives, operator is called */
669 wmOperatorType *ot; /* not saved in file, so can be pointer */
671 struct IDProperty *properties; /* operator properties, assigned to ptr->data and can be written to a file */
672 struct PointerRNA *ptr; /* rna pointer to access properties */
674 short opcontext; /* default invoke */
679 * Struct to store tool-tip timer and possible creation if the time is reached.
680 * Allows UI code to call #WM_tooltip_timer_init without each user having to handle the timer.
682 typedef struct wmTooltipState {
683 /** Create tooltip on this event. */
684 struct wmTimer *timer;
685 /** The region the tooltip is created in. */
686 struct ARegion *region_from;
687 /** The tooltip region. */
688 struct ARegion *region;
689 /** Create the tooltip region (assign to 'region'). */
690 struct ARegion *(*init)(struct bContext *, struct ARegion *, bool *r_exit_on_event);
691 /** Exit on any event, not needed for buttons since their highlight state is used. */
695 /* *************** migrated stuff, clean later? ************** */
697 typedef struct RecentFile {
698 struct RecentFile *next, *prev;
705 extern struct CLG_LogRef *WM_LOG_OPERATORS;
706 extern struct CLG_LogRef *WM_LOG_HANDLERS;
707 extern struct CLG_LogRef *WM_LOG_EVENTS;
708 extern struct CLG_LogRef *WM_LOG_KEYMAPS;
715 #endif /* __WM_TYPES_H__ */