Blender V5.0
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#include "BLI_string_utf8.h"
16
17#include "BKE_context.hh"
18#include "BKE_screen.hh"
19
20#include "ED_screen.hh"
21#include "ED_space_api.hh"
22
23#include "RNA_access.hh"
24#include "RNA_enum_types.hh"
25
26#include "WM_types.hh"
27
28#include "UI_interface.hh"
29
30#include "BLO_read_write.hh"
31
32/* ******************** default callbacks for userpref space ***************** */
33
34static SpaceLink *userpref_create(const ScrArea *area, const Scene * /*scene*/)
35{
36 ARegion *region;
37 SpaceUserPref *spref;
38
39 spref = MEM_callocN<SpaceUserPref>("inituserpref");
41
42 /* header */
43 region = BKE_area_region_new();
44
45 BLI_addtail(&spref->regionbase, region);
47 /* Ignore user preference "USER_HEADER_BOTTOM" here (always show bottom for new types). */
49
50 /* navigation region */
51 region = BKE_area_region_new();
52
53 BLI_addtail(&spref->regionbase, region);
54 region->regiontype = RGN_TYPE_UI;
55 region->alignment = RGN_ALIGN_LEFT;
56 region->flag &= ~RGN_FLAG_HIDDEN;
57
58 /* Use smaller size when opened in area like properties editor. */
59 if (area->winx && area->winx < 3.0f * UI_NAVIGATION_REGION_WIDTH * UI_SCALE_FAC) {
61 }
62
63 /* execution region */
64 region = BKE_area_region_new();
65
66 BLI_addtail(&spref->regionbase, region);
70
71 /* main region */
72 region = BKE_area_region_new();
73
74 BLI_addtail(&spref->regionbase, region);
76
77 return (SpaceLink *)spref;
78}
79
80/* Doesn't free the space-link itself. */
81static void userpref_free(SpaceLink * /*sl*/)
82{
83 // SpaceUserPref *spref = (SpaceUserPref *)sl;
84}
85
86/* spacetype; init callback */
87static void userpref_init(wmWindowManager * /*wm*/, ScrArea * /*area*/) {}
88
90{
91 SpaceUserPref *sprefn = static_cast<SpaceUserPref *>(MEM_dupallocN(sl));
92
93 /* clear or remove stuff from old */
94
95 return (SpaceLink *)sprefn;
96}
97
98/* add handlers, stuff you only do once or on area/region changes */
100{
101 /* do not use here, the properties changed in user-preferences do a system-wide refresh,
102 * then scroller jumps back */
103 // region->v2d.flag &= ~V2D_IS_INIT;
104
106
107 ED_region_panels_init(wm, region);
108}
109
110static void userpref_main_region_layout(const bContext *C, ARegion *region)
111{
112 char id_lower[64];
113 const char *contexts[2] = {id_lower, nullptr};
114
116
117 /* Avoid duplicating identifiers, use existing RNA enum. */
118 {
120 int i = RNA_enum_from_value(items, U.space_data.section_active);
121 /* File is from the future. */
122 if (i == -1) {
123 i = 0;
124 }
125 const char *id = items[i].identifier;
126 BLI_assert(strlen(id) < sizeof(id_lower));
127 STRNCPY_UTF8(id_lower, id);
128 BLI_str_tolower_ascii(id_lower, strlen(id_lower));
129 }
130
132 region,
133 &region->runtime->type->paneltypes,
135 contexts,
136 nullptr);
137}
138
140
141static void userpref_keymap(wmKeyConfig * /*keyconf*/) {}
142
143/* add handlers, stuff you only do once or on area/region changes */
145{
146 ED_region_header_init(region);
147}
148
149static void userpref_header_region_draw(const bContext *C, ARegion *region)
150{
151 ED_region_header(C, region);
152}
153
154/* add handlers, stuff you only do once or on area/region changes */
162
164{
165 ED_region_panels(C, region);
166}
167
169{
170 const ARegion *region_header = BKE_area_find_region_type(params->area, RGN_TYPE_HEADER);
171 return !region_header->runtime->visible;
172}
173
174/* add handlers, stuff you only do once or on area/region changes */
176{
177 ED_region_panels_init(wm, region);
179}
180
182
183static void userpref_header_listener(const wmRegionListenerParams * /*params*/) {}
184
186
188
190{
191 BLO_write_struct(writer, SpaceUserPref, sl);
192}
193
195{
196 std::unique_ptr<SpaceType> st = std::make_unique<SpaceType>();
197 ARegionType *art;
198
199 st->spaceid = SPACE_USERPREF;
200 STRNCPY_UTF8(st->name, "Userpref");
201
202 st->create = userpref_create;
203 st->free = userpref_free;
204 st->init = userpref_init;
205 st->duplicate = userpref_duplicate;
206 st->operatortypes = userpref_operatortypes;
207 st->keymap = userpref_keymap;
208 st->blend_write = userpref_space_blend_write;
209
210 /* regions: main window */
211 art = MEM_callocN<ARegionType>("spacetype userpref region");
218
219 BLI_addhead(&st->regiontypes, art);
220
221 /* regions: header */
222 art = MEM_callocN<ARegionType>("spacetype userpref region");
224 art->prefsizey = HEADERY;
229
230 BLI_addhead(&st->regiontypes, art);
231
232 /* regions: navigation window */
233 art = MEM_callocN<ARegionType>("spacetype userpref region");
234 art->regionid = RGN_TYPE_UI;
240
241 BLI_addhead(&st->regiontypes, art);
242
243 /* regions: execution window */
244 art = MEM_callocN<ARegionType>("spacetype userpref region");
246 art->prefsizey = HEADERY;
253
254 BLI_addhead(&st->regiontypes, art);
255
256 BKE_spacetype_register(std::move(st));
257}
void BKE_spacetype_register(std::unique_ptr< SpaceType > st)
Definition screen.cc:282
ARegion * BKE_area_region_new()
Definition screen.cc:387
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:846
#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
void BLI_str_tolower_ascii(char *str, size_t len) ATTR_NONNULL(1)
Definition string.cc:956
#define STRNCPY_UTF8(dst, src)
#define BLO_write_struct(writer, struct_name, data_ptr)
#define HEADERY
@ RGN_ALIGN_BOTTOM
@ RGN_ALIGN_LEFT
@ RGN_SPLIT_PREV
@ RGN_TYPE_EXECUTE
@ RGN_TYPE_UI
@ RGN_TYPE_WINDOW
@ RGN_TYPE_HEADER
@ RGN_FLAG_DYNAMIC_SIZE
@ RGN_FLAG_HIDDEN
@ RGN_FLAG_NO_USER_RESIZE
@ RGN_FLAG_INDICATE_OVERFLOW
@ SPACE_USERPREF
#define UI_SCALE_FAC
@ V2D_LOCKZOOM_X
@ V2D_LOCKZOOM_Y
@ V2D_SCROLL_VERTICAL_HIDE
@ V2D_SCROLL_RIGHT
void ED_region_panels(const bContext *C, ARegion *region)
Definition area.cc:3609
void ED_region_header(const bContext *C, ARegion *region)
Definition area.cc:3935
void ED_region_header_init(ARegion *region)
Definition area.cc:3950
void ED_region_panels_layout(const bContext *C, ARegion *region)
Definition area.cc:3519
void ED_region_panels_init(wmWindowManager *wm, ARegion *region)
Definition area.cc:3616
void ED_region_panels_layout_ex(const bContext *C, ARegion *region, ListBase *paneltypes, blender::wm::OpCallContext op_context, const char *contexts[], const char *category_override)
Definition area.cc:3233
@ ED_KEYMAP_NAVBAR
Definition ED_screen.hh:767
@ ED_KEYMAP_UI
Definition ED_screen.hh:758
@ ED_KEYMAP_HEADER
Definition ED_screen.hh:764
@ ED_KEYMAP_VIEW2D
Definition ED_screen.hh:761
void ED_region_panels_draw(const bContext *C, ARegion *region)
Definition area.cc:3529
Read Guarded memory(de)allocation.
#define C
Definition RandGen.cpp:29
#define UI_NAVIGATION_REGION_WIDTH
#define UI_NARROW_NAVIGATION_REGION_WIDTH
#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:657
short keepzoom
i
Definition text_draw.cc:230