Blender V4.5
space_userpref.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstring>
10
11#include "MEM_guardedalloc.h"
12
13#include "BLI_listbase.h"
14#include "BLI_string.h"
15
16#include "BKE_context.hh"
17#include "BKE_screen.hh"
18
19#include "ED_screen.hh"
20#include "ED_space_api.hh"
21
22#include "RNA_access.hh"
23#include "RNA_enum_types.hh"
24
25#include "WM_types.hh"
26
27#include "UI_interface.hh"
28
29#include "BLO_read_write.hh"
30
31/* ******************** default callbacks for userpref space ***************** */
32
33static SpaceLink *userpref_create(const ScrArea *area, const Scene * /*scene*/)
34{
35 ARegion *region;
36 SpaceUserPref *spref;
37
38 spref = MEM_callocN<SpaceUserPref>("inituserpref");
40
41 /* header */
42 region = BKE_area_region_new();
43
44 BLI_addtail(&spref->regionbase, region);
46 /* Ignore user preference "USER_HEADER_BOTTOM" here (always show bottom for new types). */
48
49 /* navigation region */
50 region = BKE_area_region_new();
51
52 BLI_addtail(&spref->regionbase, region);
54 region->alignment = RGN_ALIGN_LEFT;
55
56 /* Use smaller size when opened in area like properties editor. */
57 if (area->winx && area->winx < 3.0f * UI_NAVIGATION_REGION_WIDTH * UI_SCALE_FAC) {
59 }
60
61 /* execution region */
62 region = BKE_area_region_new();
63
64 BLI_addtail(&spref->regionbase, region);
68
69 /* main region */
70 region = BKE_area_region_new();
71
72 BLI_addtail(&spref->regionbase, region);
74
75 return (SpaceLink *)spref;
76}
77
78/* Doesn't free the space-link itself. */
79static void userpref_free(SpaceLink * /*sl*/)
80{
81 // SpaceUserPref *spref = (SpaceUserPref *)sl;
82}
83
84/* spacetype; init callback */
85static void userpref_init(wmWindowManager * /*wm*/, ScrArea * /*area*/) {}
86
88{
89 SpaceUserPref *sprefn = static_cast<SpaceUserPref *>(MEM_dupallocN(sl));
90
91 /* clear or remove stuff from old */
92
93 return (SpaceLink *)sprefn;
94}
95
96/* add handlers, stuff you only do once or on area/region changes */
98{
99 /* do not use here, the properties changed in user-preferences do a system-wide refresh,
100 * then scroller jumps back */
101 // region->v2d.flag &= ~V2D_IS_INIT;
102
104
105 ED_region_panels_init(wm, region);
106}
107
108static void userpref_main_region_layout(const bContext *C, ARegion *region)
109{
110 char id_lower[64];
111 const char *contexts[2] = {id_lower, nullptr};
112
113 /* Avoid duplicating identifiers, use existing RNA enum. */
114 {
116 int i = RNA_enum_from_value(items, U.space_data.section_active);
117 /* File is from the future. */
118 if (i == -1) {
119 i = 0;
120 }
121 const char *id = items[i].identifier;
122 BLI_assert(strlen(id) < sizeof(id_lower));
123 STRNCPY(id_lower, id);
124 BLI_str_tolower_ascii(id_lower, strlen(id_lower));
125 }
126
128 C, region, &region->runtime->type->paneltypes, WM_OP_INVOKE_REGION_WIN, contexts, nullptr);
129}
130
132
133static void userpref_keymap(wmKeyConfig * /*keyconf*/) {}
134
135/* add handlers, stuff you only do once or on area/region changes */
137{
138 ED_region_header_init(region);
139}
140
141static void userpref_header_region_draw(const bContext *C, ARegion *region)
142{
143 ED_region_header(C, region);
144}
145
146/* add handlers, stuff you only do once or on area/region changes */
153
155{
156 ED_region_panels(C, region);
157}
158
160{
161 const ARegion *region_header = BKE_area_find_region_type(params->area, RGN_TYPE_HEADER);
162 return !region_header->runtime->visible;
163}
164
165/* add handlers, stuff you only do once or on area/region changes */
167{
168 ED_region_panels_init(wm, region);
170}
171
173
174static void userpref_header_listener(const wmRegionListenerParams * /*params*/) {}
175
177
179
181{
182 BLO_write_struct(writer, SpaceUserPref, sl);
183}
184
186{
187 std::unique_ptr<SpaceType> st = std::make_unique<SpaceType>();
188 ARegionType *art;
189
190 st->spaceid = SPACE_USERPREF;
191 STRNCPY(st->name, "Userpref");
192
193 st->create = userpref_create;
194 st->free = userpref_free;
195 st->init = userpref_init;
196 st->duplicate = userpref_duplicate;
197 st->operatortypes = userpref_operatortypes;
198 st->keymap = userpref_keymap;
199 st->blend_write = userpref_space_blend_write;
200
201 /* regions: main window */
202 art = MEM_callocN<ARegionType>("spacetype userpref region");
209
210 BLI_addhead(&st->regiontypes, art);
211
212 /* regions: header */
213 art = MEM_callocN<ARegionType>("spacetype userpref region");
215 art->prefsizey = HEADERY;
220
221 BLI_addhead(&st->regiontypes, art);
222
223 /* regions: navigation window */
224 art = MEM_callocN<ARegionType>("spacetype userpref region");
231
232 BLI_addhead(&st->regiontypes, art);
233
234 /* regions: execution window */
235 art = MEM_callocN<ARegionType>("spacetype userpref region");
237 art->prefsizey = HEADERY;
244
245 BLI_addhead(&st->regiontypes, art);
246
247 BKE_spacetype_register(std::move(st));
248}
void BKE_spacetype_register(std::unique_ptr< SpaceType > st)
Definition screen.cc:276
ARegion * BKE_area_region_new()
Definition screen.cc:381
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:840
#define BLI_assert(a)
Definition BLI_assert.h:46
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:111
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:91
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:688
void BLI_str_tolower_ascii(char *str, size_t len) ATTR_NONNULL(1)
Definition string.cc:966
#define BLO_write_struct(writer, struct_name, data_ptr)
#define HEADERY
@ RGN_TYPE_EXECUTE
@ RGN_TYPE_WINDOW
@ RGN_TYPE_NAV_BAR
@ RGN_TYPE_HEADER
@ RGN_FLAG_DYNAMIC_SIZE
@ RGN_FLAG_NO_USER_RESIZE
@ RGN_ALIGN_BOTTOM
@ RGN_ALIGN_LEFT
@ RGN_SPLIT_PREV
@ SPACE_USERPREF
#define UI_SCALE_FAC
@ V2D_SCROLL_VERTICAL_HIDE
@ V2D_SCROLL_RIGHT
@ V2D_LOCKZOOM_X
@ V2D_LOCKZOOM_Y
@ ED_KEYMAP_NAVBAR
Definition ED_screen.hh:749
@ ED_KEYMAP_UI
Definition ED_screen.hh:740
@ ED_KEYMAP_HEADER
Definition ED_screen.hh:746
@ ED_KEYMAP_VIEW2D
Definition ED_screen.hh:743
void ED_region_panels(const bContext *C, ARegion *region)
Definition area.cc:3466
void ED_region_header(const bContext *C, ARegion *region)
Definition area.cc:3754
void ED_region_header_init(ARegion *region)
Definition area.cc:3769
void ED_region_panels_layout_ex(const bContext *C, ARegion *region, ListBase *paneltypes, wmOperatorCallContext op_context, const char *contexts[], const char *category_override)
Definition area.cc:3219
void ED_region_panels_layout(const bContext *C, ARegion *region)
Definition area.cc:3403
void ED_region_panels_init(wmWindowManager *wm, ARegion *region)
Definition area.cc:3473
void ED_region_panels_draw(const bContext *C, ARegion *region)
Definition area.cc:3409
Read Guarded memory(de)allocation.
#define C
Definition RandGen.cpp:29
#define UI_NAVIGATION_REGION_WIDTH
#define UI_NARROW_NAVIGATION_REGION_WIDTH
@ WM_OP_INVOKE_REGION_WIN
Definition WM_types.hh:239
#define U
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void * MEM_dupallocN(const void *vmemh)
Definition mallocn.cc:143
int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
const EnumPropertyItem rna_enum_preference_section_items[]
static void userpref_main_region_listener(const wmRegionListenerParams *)
void ED_spacetype_userpref()
static void userpref_keymap(wmKeyConfig *)
static void userpref_operatortypes()
static void userpref_init(wmWindowManager *, ScrArea *)
static bool userpref_execute_region_poll(const RegionPollParams *params)
static void userpref_execute_region_listener(const wmRegionListenerParams *)
static SpaceLink * userpref_create(const ScrArea *area, const Scene *)
static void userpref_navigation_region_listener(const wmRegionListenerParams *)
static void userpref_free(SpaceLink *)
static void userpref_execute_region_init(wmWindowManager *wm, ARegion *region)
static void userpref_space_blend_write(BlendWriter *writer, SpaceLink *sl)
static void userpref_main_region_layout(const bContext *C, ARegion *region)
static void userpref_header_listener(const wmRegionListenerParams *)
static void userpref_main_region_init(wmWindowManager *wm, ARegion *region)
static SpaceLink * userpref_duplicate(SpaceLink *sl)
static void userpref_header_region_draw(const bContext *C, ARegion *region)
static void userpref_header_region_init(wmWindowManager *, ARegion *region)
static void userpref_navigation_region_draw(const bContext *C, ARegion *region)
static void userpref_navigation_region_init(wmWindowManager *wm, ARegion *region)
bool(* poll)(const RegionPollParams *params)
void(* listener)(const wmRegionListenerParams *params)
void(* draw)(const bContext *C, ARegion *region)
void(* layout)(const bContext *C, ARegion *region)
void(* init)(wmWindowManager *wm, ARegion *region)
ARegionRuntimeHandle * runtime
const char * identifier
Definition RNA_types.hh:623
short keepzoom
i
Definition text_draw.cc:230