Blender  V3.3
space_userpref.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2008 Blender Foundation. All rights reserved. */
3 
8 #include <stdio.h>
9 #include <string.h>
10 
11 #include "MEM_guardedalloc.h"
12 
13 #include "BLI_blenlib.h"
14 #include "BLI_utildefines.h"
15 
16 #include "BKE_context.h"
17 #include "BKE_screen.h"
18 
19 #include "ED_screen.h"
20 #include "ED_space_api.h"
21 
22 #include "RNA_access.h"
23 #include "RNA_enum_types.h"
24 
25 #include "WM_api.h"
26 #include "WM_types.h"
27 
28 #include "UI_interface.h"
29 
30 /* ******************** default callbacks for userpref space ***************** */
31 
33 {
34  ARegion *region;
35  SpaceUserPref *spref;
36 
37  spref = MEM_callocN(sizeof(SpaceUserPref), "inituserpref");
38  spref->spacetype = SPACE_USERPREF;
39 
40  /* header */
41  region = MEM_callocN(sizeof(ARegion), "header for userpref");
42 
43  BLI_addtail(&spref->regionbase, region);
44  region->regiontype = RGN_TYPE_HEADER;
45  /* Ignore user preference "USER_HEADER_BOTTOM" here (always show bottom for new types). */
46  region->alignment = RGN_ALIGN_BOTTOM;
47 
48  /* navigation region */
49  region = MEM_callocN(sizeof(ARegion), "navigation region for userpref");
50 
51  BLI_addtail(&spref->regionbase, region);
52  region->regiontype = RGN_TYPE_NAV_BAR;
53  region->alignment = RGN_ALIGN_LEFT;
54 
55  /* Use smaller size when opened in area like properties editor. */
56  if (area->winx && area->winx < 3.0f * UI_NAVIGATION_REGION_WIDTH * UI_DPI_FAC) {
58  }
59 
60  /* execution region */
61  region = MEM_callocN(sizeof(ARegion), "execution region for userpref");
62 
63  BLI_addtail(&spref->regionbase, region);
64  region->regiontype = RGN_TYPE_EXECUTE;
67 
68  /* main region */
69  region = MEM_callocN(sizeof(ARegion), "main region for userpref");
70 
71  BLI_addtail(&spref->regionbase, region);
72  region->regiontype = RGN_TYPE_WINDOW;
73 
74  return (SpaceLink *)spref;
75 }
76 
77 /* not spacelink itself */
78 static void userpref_free(SpaceLink *UNUSED(sl))
79 {
80  // SpaceUserPref *spref = (SpaceUserPref *)sl;
81 }
82 
83 /* spacetype; init callback */
85 {
86 }
87 
89 {
90  SpaceUserPref *sprefn = MEM_dupallocN(sl);
91 
92  /* clear or remove stuff from old */
93 
94  return (SpaceLink *)sprefn;
95 }
96 
97 /* add handlers, stuff you only do once or on area/region changes */
99 {
100  /* do not use here, the properties changed in user-preferences do a system-wide refresh,
101  * then scroller jumps back */
102  // region->v2d.flag &= ~V2D_IS_INIT;
103 
105 
106  ED_region_panels_init(wm, region);
107 }
108 
109 static void userpref_main_region_layout(const bContext *C, ARegion *region)
110 {
111  char id_lower[64];
112  const char *contexts[2] = {id_lower, NULL};
113 
114  /* Avoid duplicating identifiers, use existing RNA enum. */
115  {
117  int i = RNA_enum_from_value(items, U.space_data.section_active);
118  /* File is from the future. */
119  if (i == -1) {
120  i = 0;
121  }
122  const char *id = items[i].identifier;
123  BLI_assert(strlen(id) < sizeof(id_lower));
124  STRNCPY(id_lower, id);
125  BLI_str_tolower_ascii(id_lower, strlen(id_lower));
126  }
127 
128  ED_region_panels_layout_ex(C, region, &region->type->paneltypes, contexts, NULL);
129 }
130 
131 static void userpref_operatortypes(void)
132 {
133 }
134 
135 static void userpref_keymap(struct wmKeyConfig *UNUSED(keyconf))
136 {
137 }
138 
139 /* add handlers, stuff you only do once or on area/region changes */
141 {
142  ED_region_header_init(region);
143 }
144 
145 static void userpref_header_region_draw(const bContext *C, ARegion *region)
146 {
147  ED_region_header(C, region);
148 }
149 
150 /* add handlers, stuff you only do once or on area/region changes */
152 {
154 
155  ED_region_panels_init(wm, region);
156 }
157 
158 static void userpref_navigation_region_draw(const bContext *C, ARegion *region)
159 {
160  ED_region_panels(C, region);
161 }
162 
163 /* add handlers, stuff you only do once or on area/region changes */
165 {
166  ED_region_panels_init(wm, region);
168 }
169 
171 {
172 }
173 
175 {
176 }
177 
179 {
180 }
181 
183 {
184 }
185 
187 {
188  SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype userpref");
189  ARegionType *art;
190 
191  st->spaceid = SPACE_USERPREF;
192  strncpy(st->name, "Userpref", BKE_ST_MAXNAME);
193 
194  st->create = userpref_create;
195  st->free = userpref_free;
196  st->init = userpref_init;
197  st->duplicate = userpref_duplicate;
198  st->operatortypes = userpref_operatortypes;
199  st->keymap = userpref_keymap;
200 
201  /* regions: main window */
202  art = MEM_callocN(sizeof(ARegionType), "spacetype userpref region");
203  art->regionid = RGN_TYPE_WINDOW;
208  art->keymapflag = ED_KEYMAP_UI;
209 
210  BLI_addhead(&st->regiontypes, art);
211 
212  /* regions: header */
213  art = MEM_callocN(sizeof(ARegionType), "spacetype userpref region");
214  art->regionid = RGN_TYPE_HEADER;
215  art->prefsizey = HEADERY;
220 
221  BLI_addhead(&st->regiontypes, art);
222 
223  /* regions: navigation window */
224  art = MEM_callocN(sizeof(ARegionType), "spacetype userpref region");
225  art->regionid = RGN_TYPE_NAV_BAR;
231 
232  BLI_addhead(&st->regiontypes, art);
233 
234  /* regions: execution window */
235  art = MEM_callocN(sizeof(ARegionType), "spacetype userpref region");
236  art->regionid = RGN_TYPE_EXECUTE;
237  art->prefsizey = HEADERY;
242  art->keymapflag = ED_KEYMAP_UI;
243 
244  BLI_addhead(&st->regiontypes, art);
245 
247 }
#define BKE_ST_MAXNAME
Definition: BKE_screen.h:53
void BKE_spacetype_register(struct SpaceType *st)
Definition: screen.c:391
#define BLI_assert(a)
Definition: BLI_assert.h:46
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:60
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:80
#define STRNCPY(dst, src)
Definition: BLI_string.h:483
void BLI_str_tolower_ascii(char *str, size_t len) ATTR_NONNULL()
Definition: string.c:927
#define UNUSED(x)
#define HEADERY
@ RGN_FLAG_DYNAMIC_SIZE
@ RGN_FLAG_HIDDEN
@ RGN_TYPE_EXECUTE
@ RGN_TYPE_WINDOW
@ RGN_TYPE_NAV_BAR
@ RGN_TYPE_HEADER
@ RGN_ALIGN_BOTTOM
@ RGN_ALIGN_LEFT
@ RGN_SPLIT_PREV
@ SPACE_USERPREF
@ V2D_LOCKZOOM_X
@ V2D_LOCKZOOM_Y
@ V2D_SCROLL_VERTICAL_HIDE
@ V2D_SCROLL_RIGHT
@ ED_KEYMAP_NAVBAR
Definition: ED_screen.h:700
@ ED_KEYMAP_UI
Definition: ED_screen.h:691
@ ED_KEYMAP_HEADER
Definition: ED_screen.h:697
@ ED_KEYMAP_VIEW2D
Definition: ED_screen.h:694
void ED_region_header(const struct bContext *C, struct ARegion *region)
void ED_region_panels(const struct bContext *C, struct ARegion *region)
void ED_region_panels_draw(const struct bContext *C, struct ARegion *region)
void ED_region_panels_init(struct wmWindowManager *wm, struct ARegion *region)
Definition: area.c:3153
void ED_region_header_init(struct ARegion *region)
Definition: area.c:3417
void ED_region_panels_layout_ex(const struct bContext *C, struct ARegion *region, struct ListBase *paneltypes, const char *contexts[], const char *category_override)
void ED_region_panels_layout(const struct bContext *C, struct ARegion *region)
Read Guarded memory(de)allocation.
#define C
Definition: RandGen.cpp:25
#define UI_NAVIGATION_REGION_WIDTH
Definition: UI_interface.h:243
#define UI_DPI_FAC
Definition: UI_interface.h:305
#define UI_NARROW_NAVIGATION_REGION_WIDTH
Definition: UI_interface.h:244
unsigned int U
Definition: btGjkEpa3.h:78
Scene scene
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:28
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
static void area(int d1, int d2, int e1, int e2, float weights[2])
static const pxr::TfToken st("st", pxr::TfToken::Immortal)
int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
Definition: rna_access.c:1736
const EnumPropertyItem rna_enum_preference_section_items[]
Definition: rna_userdef.c:41
static SpaceLink * userpref_duplicate(SpaceLink *sl)
static void userpref_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(area))
static SpaceLink * userpref_create(const ScrArea *area, const Scene *UNUSED(scene))
static void userpref_execute_region_listener(const wmRegionListenerParams *UNUSED(params))
static void userpref_navigation_region_listener(const wmRegionListenerParams *UNUSED(params))
static void userpref_operatortypes(void)
static void userpref_header_listener(const wmRegionListenerParams *UNUSED(params))
static void userpref_header_region_init(wmWindowManager *UNUSED(wm), ARegion *region)
static void userpref_keymap(struct wmKeyConfig *UNUSED(keyconf))
static void userpref_main_region_listener(const wmRegionListenerParams *UNUSED(params))
static void userpref_execute_region_init(wmWindowManager *wm, ARegion *region)
static void userpref_main_region_layout(const bContext *C, ARegion *region)
static void userpref_main_region_init(wmWindowManager *wm, ARegion *region)
static void userpref_free(SpaceLink *UNUSED(sl))
static void userpref_header_region_draw(const bContext *C, ARegion *region)
void ED_spacetype_userpref(void)
static void userpref_navigation_region_draw(const bContext *C, ARegion *region)
static void userpref_navigation_region_init(wmWindowManager *wm, ARegion *region)
void(* draw)(const struct bContext *C, struct ARegion *region)
Definition: BKE_screen.h:151
void(* listener)(const wmRegionListenerParams *params)
Definition: BKE_screen.h:165
int keymapflag
Definition: BKE_screen.h:208
void(* layout)(const struct bContext *C, struct ARegion *region)
Definition: BKE_screen.h:161
void(* init)(struct wmWindowManager *wm, struct ARegion *region)
Definition: BKE_screen.h:147
ListBase paneltypes
Definition: BKE_screen.h:198
short alignment
short regiontype
struct ARegionType * type
const char * identifier
Definition: RNA_types.h:461
short keepzoom
short scroll