Blender  V2.93
space_userpref.c
Go to the documentation of this file.
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) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include <stdio.h>
25 #include <string.h>
26 
27 #include "MEM_guardedalloc.h"
28 
29 #include "BLI_blenlib.h"
30 #include "BLI_utildefines.h"
31 
32 #include "BKE_context.h"
33 #include "BKE_screen.h"
34 
35 #include "ED_screen.h"
36 #include "ED_space_api.h"
37 
38 #include "RNA_access.h"
39 #include "RNA_enum_types.h"
40 
41 #include "WM_api.h"
42 #include "WM_types.h"
43 
44 #include "UI_interface.h"
45 
46 /* ******************** default callbacks for userpref space ***************** */
47 
49 {
50  ARegion *region;
51  SpaceUserPref *spref;
52 
53  spref = MEM_callocN(sizeof(SpaceUserPref), "inituserpref");
54  spref->spacetype = SPACE_USERPREF;
55 
56  /* header */
57  region = MEM_callocN(sizeof(ARegion), "header for userpref");
58 
59  BLI_addtail(&spref->regionbase, region);
60  region->regiontype = RGN_TYPE_HEADER;
61  /* Ignore user preference "USER_HEADER_BOTTOM" here (always show bottom for new types). */
62  region->alignment = RGN_ALIGN_BOTTOM;
63 
64  /* navigation region */
65  region = MEM_callocN(sizeof(ARegion), "navigation region for userpref");
66 
67  BLI_addtail(&spref->regionbase, region);
68  region->regiontype = RGN_TYPE_NAV_BAR;
69  region->alignment = RGN_ALIGN_LEFT;
70 
71  /* Use smaller size when opened in area like properties editor. */
72  if (area->winx && area->winx < 3.0f * UI_NAVIGATION_REGION_WIDTH * UI_DPI_FAC) {
74  }
75 
76  /* execution region */
77  region = MEM_callocN(sizeof(ARegion), "execution region for userpref");
78 
79  BLI_addtail(&spref->regionbase, region);
80  region->regiontype = RGN_TYPE_EXECUTE;
83 
84  /* main region */
85  region = MEM_callocN(sizeof(ARegion), "main region for userpref");
86 
87  BLI_addtail(&spref->regionbase, region);
88  region->regiontype = RGN_TYPE_WINDOW;
89 
90  return (SpaceLink *)spref;
91 }
92 
93 /* not spacelink itself */
94 static void userpref_free(SpaceLink *UNUSED(sl))
95 {
96  // SpaceUserPref *spref = (SpaceUserPref *)sl;
97 }
98 
99 /* spacetype; init callback */
101 {
102 }
103 
105 {
106  SpaceUserPref *sprefn = MEM_dupallocN(sl);
107 
108  /* clear or remove stuff from old */
109 
110  return (SpaceLink *)sprefn;
111 }
112 
113 /* add handlers, stuff you only do once or on area/region changes */
115 {
116  /* do not use here, the properties changed in userprefs do a system-wide refresh,
117  * then scroller jumps back */
118  /* region->v2d.flag &= ~V2D_IS_INIT; */
119 
121 
122  ED_region_panels_init(wm, region);
123 }
124 
125 static void userpref_main_region_layout(const bContext *C, ARegion *region)
126 {
127  char id_lower[64];
128  const char *contexts[2] = {id_lower, NULL};
129 
130  /* Avoid duplicating identifiers, use existing RNA enum. */
131  {
133  int i = RNA_enum_from_value(items, U.space_data.section_active);
134  /* File is from the future. */
135  if (i == -1) {
136  i = 0;
137  }
138  const char *id = items[i].identifier;
139  BLI_assert(strlen(id) < sizeof(id_lower));
140  STRNCPY(id_lower, id);
141  BLI_str_tolower_ascii(id_lower, strlen(id_lower));
142  }
143 
144  ED_region_panels_layout_ex(C, region, &region->type->paneltypes, contexts, NULL);
145 }
146 
147 static void userpref_operatortypes(void)
148 {
149 }
150 
151 static void userpref_keymap(struct wmKeyConfig *UNUSED(keyconf))
152 {
153 }
154 
155 /* add handlers, stuff you only do once or on area/region changes */
157 {
158  ED_region_header_init(region);
159 }
160 
161 static void userpref_header_region_draw(const bContext *C, ARegion *region)
162 {
163  ED_region_header(C, region);
164 }
165 
166 /* add handlers, stuff you only do once or on area/region changes */
168 {
170 
171  ED_region_panels_init(wm, region);
172 }
173 
174 static void userpref_navigation_region_draw(const bContext *C, ARegion *region)
175 {
176  ED_region_panels(C, region);
177 }
178 
179 /* add handlers, stuff you only do once or on area/region changes */
181 {
182  ED_region_panels_init(wm, region);
184 }
185 
187 {
188 }
189 
191 {
192 }
193 
195 {
196 }
197 
199 {
200 }
201 
202 /* only called once, from space/spacetypes.c */
204 {
205  SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype userpref");
206  ARegionType *art;
207 
208  st->spaceid = SPACE_USERPREF;
209  strncpy(st->name, "Userpref", BKE_ST_MAXNAME);
210 
211  st->create = userpref_create;
212  st->free = userpref_free;
213  st->init = userpref_init;
216  st->keymap = userpref_keymap;
217 
218  /* regions: main window */
219  art = MEM_callocN(sizeof(ARegionType), "spacetype userpref region");
220  art->regionid = RGN_TYPE_WINDOW;
225  art->keymapflag = ED_KEYMAP_UI;
226 
227  BLI_addhead(&st->regiontypes, art);
228 
229  /* regions: header */
230  art = MEM_callocN(sizeof(ARegionType), "spacetype userpref region");
231  art->regionid = RGN_TYPE_HEADER;
232  art->prefsizey = HEADERY;
237 
238  BLI_addhead(&st->regiontypes, art);
239 
240  /* regions: navigation window */
241  art = MEM_callocN(sizeof(ARegionType), "spacetype userpref region");
242  art->regionid = RGN_TYPE_NAV_BAR;
248 
249  BLI_addhead(&st->regiontypes, art);
250 
251  /* regions: execution window */
252  art = MEM_callocN(sizeof(ARegionType), "spacetype userpref region");
253  art->regionid = RGN_TYPE_EXECUTE;
254  art->prefsizey = HEADERY;
259  art->keymapflag = ED_KEYMAP_UI;
260 
261  BLI_addhead(&st->regiontypes, art);
262 
264 }
#define BKE_ST_MAXNAME
Definition: BKE_screen.h:68
void BKE_spacetype_register(struct SpaceType *st)
Definition: screen.c:420
#define BLI_assert(a)
Definition: BLI_assert.h:58
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:87
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
#define STRNCPY(dst, src)
Definition: BLI_string.h:163
void BLI_str_tolower_ascii(char *str, const size_t len) ATTR_NONNULL()
Definition: string.c:890
#define UNUSED(x)
#define HEADERY
@ RGN_ALIGN_BOTTOM
@ RGN_ALIGN_LEFT
@ RGN_SPLIT_PREV
@ RGN_FLAG_DYNAMIC_SIZE
@ RGN_FLAG_HIDDEN
@ RGN_TYPE_EXECUTE
@ RGN_TYPE_WINDOW
@ RGN_TYPE_NAV_BAR
@ RGN_TYPE_HEADER
@ SPACE_USERPREF
@ V2D_SCROLL_VERTICAL_HIDE
@ V2D_SCROLL_RIGHT
@ V2D_LOCKZOOM_X
@ V2D_LOCKZOOM_Y
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:3090
void ED_region_header_init(struct ARegion *region)
Definition: area.c:3358
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)
@ ED_KEYMAP_NAVBAR
Definition: ED_screen.h:449
@ ED_KEYMAP_UI
Definition: ED_screen.h:440
@ ED_KEYMAP_HEADER
Definition: ED_screen.h:446
@ ED_KEYMAP_VIEW2D
Definition: ED_screen.h:443
Read Guarded memory(de)allocation.
#define C
Definition: RandGen.cpp:39
#define UI_NAVIGATION_REGION_WIDTH
Definition: UI_interface.h:246
#define UI_DPI_FAC
Definition: UI_interface.h:309
#define UI_NARROW_NAVIGATION_REGION_WIDTH
Definition: UI_interface.h:247
unsigned int U
Definition: btGjkEpa3.h:78
Scene scene
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:42
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
static void area(int d1, int d2, int e1, int e2, float weights[2])
int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
Definition: rna_access.c:1902
const EnumPropertyItem rna_enum_preference_section_items[]
Definition: rna_userdef.c:72
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:169
void(* listener)(const wmRegionListenerParams *params)
Definition: BKE_screen.h:183
int keymapflag
Definition: BKE_screen.h:226
void(* layout)(const struct bContext *C, struct ARegion *region)
Definition: BKE_screen.h:179
void(* init)(struct wmWindowManager *wm, struct ARegion *region)
Definition: BKE_screen.h:165
ListBase paneltypes
Definition: BKE_screen.h:216
short alignment
short regiontype
struct ARegionType * type
const char * identifier
Definition: RNA_types.h:446
struct SpaceLink *(* duplicate)(struct SpaceLink *sl)
Definition: BKE_screen.h:104
ListBase regiontypes
Definition: BKE_screen.h:130
void(* keymap)(struct wmKeyConfig *keyconf)
Definition: BKE_screen.h:109
void(* operatortypes)(void)
Definition: BKE_screen.h:107
void(* free)(struct SpaceLink *sl)
Definition: BKE_screen.h:88
struct SpaceLink *(* create)(const struct ScrArea *area, const struct Scene *scene)
Definition: BKE_screen.h:86
void(* init)(struct wmWindowManager *wm, struct ScrArea *area)
Definition: BKE_screen.h:91
int spaceid
Definition: BKE_screen.h:81
char name[BKE_ST_MAXNAME]
Definition: BKE_screen.h:80
short keepzoom
short scroll