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 
17 /** \file
18  * \ingroup spstatusbar
19  */
20 
21 #include <stdio.h>
22 #include <string.h>
23 
24 #include "MEM_guardedalloc.h"
25 
26 #include "BLI_blenlib.h"
27 
28 #include "BKE_context.h"
29 #include "BKE_screen.h"
30 
31 #include "ED_screen.h"
32 #include "ED_space_api.h"
33 
34 #include "RNA_access.h"
35 
36 #include "UI_interface.h"
37 #include "UI_view2d.h"
38 
39 #include "WM_api.h"
40 #include "WM_message.h"
41 #include "WM_types.h"
42 
43 /* ******************** default callbacks for statusbar space ********************  */
44 
statusbar_create(const ScrArea * UNUSED (area),const Scene * UNUSED (scene))45 static SpaceLink *statusbar_create(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
46 {
47   ARegion *region;
48   SpaceStatusBar *sstatusbar;
49 
50   sstatusbar = MEM_callocN(sizeof(*sstatusbar), "init statusbar");
51   sstatusbar->spacetype = SPACE_STATUSBAR;
52 
53   /* header region */
54   region = MEM_callocN(sizeof(*region), "header for statusbar");
55   BLI_addtail(&sstatusbar->regionbase, region);
56   region->regiontype = RGN_TYPE_HEADER;
57   region->alignment = RGN_ALIGN_NONE;
58 
59   return (SpaceLink *)sstatusbar;
60 }
61 
62 /* not spacelink itself */
statusbar_free(SpaceLink * UNUSED (sl))63 static void statusbar_free(SpaceLink *UNUSED(sl))
64 {
65 }
66 
67 /* spacetype; init callback */
statusbar_init(struct wmWindowManager * UNUSED (wm),ScrArea * UNUSED (area))68 static void statusbar_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(area))
69 {
70 }
71 
statusbar_duplicate(SpaceLink * sl)72 static SpaceLink *statusbar_duplicate(SpaceLink *sl)
73 {
74   SpaceStatusBar *sstatusbarn = MEM_dupallocN(sl);
75 
76   /* clear or remove stuff from old */
77 
78   return (SpaceLink *)sstatusbarn;
79 }
80 
81 /* add handlers, stuff you only do once or on area/region changes */
statusbar_header_region_init(wmWindowManager * UNUSED (wm),ARegion * region)82 static void statusbar_header_region_init(wmWindowManager *UNUSED(wm), ARegion *region)
83 {
84   if (ELEM(RGN_ALIGN_ENUM_FROM_MASK(region->alignment), RGN_ALIGN_RIGHT)) {
85     region->flag |= RGN_FLAG_DYNAMIC_SIZE;
86   }
87   ED_region_header_init(region);
88 }
89 
statusbar_operatortypes(void)90 static void statusbar_operatortypes(void)
91 {
92 }
93 
statusbar_keymap(struct wmKeyConfig * UNUSED (keyconf))94 static void statusbar_keymap(struct wmKeyConfig *UNUSED(keyconf))
95 {
96 }
97 
statusbar_header_region_listener(wmWindow * UNUSED (win),ScrArea * UNUSED (area),ARegion * region,wmNotifier * wmn,const Scene * UNUSED (scene))98 static void statusbar_header_region_listener(wmWindow *UNUSED(win),
99                                              ScrArea *UNUSED(area),
100                                              ARegion *region,
101                                              wmNotifier *wmn,
102                                              const Scene *UNUSED(scene))
103 {
104   /* context changes */
105   switch (wmn->category) {
106     case NC_SCREEN:
107       if (ELEM(wmn->data, ND_LAYER, ND_ANIMPLAY)) {
108         ED_region_tag_redraw(region);
109       }
110       break;
111     case NC_WM:
112       if (wmn->data == ND_JOB) {
113         ED_region_tag_redraw(region);
114       }
115       break;
116     case NC_SCENE:
117       if (wmn->data == ND_RENDER_RESULT) {
118         ED_region_tag_redraw(region);
119       }
120       break;
121     case NC_SPACE:
122       if (wmn->data == ND_SPACE_INFO) {
123         ED_region_tag_redraw(region);
124       }
125       break;
126     case NC_ID:
127       if (wmn->action == NA_RENAME) {
128         ED_region_tag_redraw(region);
129       }
130       break;
131   }
132 }
133 
statusbar_header_region_message_subscribe(const bContext * UNUSED (C),WorkSpace * UNUSED (workspace),Scene * UNUSED (scene),bScreen * UNUSED (screen),ScrArea * UNUSED (area),ARegion * region,struct wmMsgBus * mbus)134 static void statusbar_header_region_message_subscribe(const bContext *UNUSED(C),
135                                                       WorkSpace *UNUSED(workspace),
136                                                       Scene *UNUSED(scene),
137                                                       bScreen *UNUSED(screen),
138                                                       ScrArea *UNUSED(area),
139                                                       ARegion *region,
140                                                       struct wmMsgBus *mbus)
141 {
142   wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
143       .owner = region,
144       .user_data = region,
145       .notify = ED_region_do_msg_notify_tag_redraw,
146   };
147 
148   WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw);
149   WM_msg_subscribe_rna_anon_prop(mbus, ViewLayer, name, &msg_sub_value_region_tag_redraw);
150 }
151 
152 /* only called once, from space/spacetypes.c */
ED_spacetype_statusbar(void)153 void ED_spacetype_statusbar(void)
154 {
155   SpaceType *st = MEM_callocN(sizeof(*st), "spacetype statusbar");
156   ARegionType *art;
157 
158   st->spaceid = SPACE_STATUSBAR;
159   strncpy(st->name, "Status Bar", BKE_ST_MAXNAME);
160 
161   st->create = statusbar_create;
162   st->free = statusbar_free;
163   st->init = statusbar_init;
164   st->duplicate = statusbar_duplicate;
165   st->operatortypes = statusbar_operatortypes;
166   st->keymap = statusbar_keymap;
167 
168   /* regions: header window */
169   art = MEM_callocN(sizeof(*art), "spacetype statusbar header region");
170   art->regionid = RGN_TYPE_HEADER;
171   art->prefsizey = 0.8f * HEADERY;
172   art->prefsizex = UI_UNIT_X * 5; /* Mainly to avoid glitches */
173   art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;
174   art->init = statusbar_header_region_init;
175   art->layout = ED_region_header_layout;
176   art->draw = ED_region_header_draw;
177   art->listener = statusbar_header_region_listener;
178   art->message_subscribe = statusbar_header_region_message_subscribe;
179   BLI_addhead(&st->regiontypes, art);
180 
181   BKE_spacetype_register(st);
182 }
183