This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/blenkernel/intern/screen.c

275 lines
5.8 KiB
C
Raw Normal View History

/*
2002-10-12 11:37:38 +00:00
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
2002-10-12 11:37:38 +00:00
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
2002-10-12 11:37:38 +00:00
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
2002-10-12 11:37:38 +00:00
*/
#include <string.h>
#include <stdio.h>
#include <math.h>
#include "MEM_guardedalloc.h"
2002-10-12 11:37:38 +00:00
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
2002-10-12 11:37:38 +00:00
#include "BLI_blenlib.h"
#include "BKE_screen.h"
2008-11-24 21:57:58 +00:00
#ifndef DISABLE_PYTHON
#include "BPY_extern.h"
2008-11-24 21:57:58 +00:00
#endif
/* ************ Spacetype/regiontype handling ************** */
/* keep global; this has to be accessible outside of windowmanager */
static ListBase spacetypes= {NULL, NULL};
/* not SpaceType itself */
static void spacetype_free(SpaceType *st)
{
ARegionType *art;
for(art= st->regiontypes.first; art; art= art->next)
BLI_freelistN(&art->drawcalls);
BLI_freelistN(&st->regiontypes);
}
void BKE_spacetypes_free(void)
{
SpaceType *st;
for(st= spacetypes.first; st; st= st->next) {
spacetype_free(st);
}
BLI_freelistN(&spacetypes);
}
SpaceType *BKE_spacetype_from_id(int spaceid)
{
SpaceType *st;
for(st= spacetypes.first; st; st= st->next) {
if(st->spaceid==spaceid)
return st;
}
return NULL;
}
ARegionType *BKE_regiontype_from_id(SpaceType *st, int regionid)
{
ARegionType *art;
for(art= st->regiontypes.first; art; art= art->next)
if(art->regionid==regionid)
return art;
printf("Error, region type missing in %s\n", st->name);
return st->regiontypes.first;
}
2.5 Branch ========== * Changed wmOperatorType, removing init/exit callbacks and adding cancel callback, removed default storage in favor of properties. Defined return values for exec/invoke/modal/cancel. * Don't allocate operator on the stack, and removed operator copy for handlers. Now it frees based on return values from callbacks, and just keeps a wmOperator on the heap. Also it now registers after the operator is fully finished, to get the correct final properties. * Changed OP_get_* functions to return 1 if the property is found and 0 otherwise, gives more readable code in my opinion. Added OP_verify_* functions to quickly check if the property is available and set if it's not, that's common for exec/invoke. * Removed WM_operatortypelist_append in favor of WM_operatortype_append which takes a function pointer instead of a list, avoids macro's and duplicating code. * Fix a crash where the handler would still be used while it was freed by the operator. * Spacetypes now have operatortypes() and keymap() callbacks to abstract them a bit more. * Renamed C->curarea to C->area for consistency. Removed View3D/View2D/ SpaceIpo from bContext, seems bad to keep these. * Set context variables like window/screen/area/region to NULL again when leaving that context, instead of leaving the pointers there. * Added if(G.f & G_DEBUG) for many of the prints, makes output a bit cleaner and easier to debug. * Fixed priority of the editors/interface module in scons, would otherwise give link errors. * Added start of generic view2d api. * Added space_time with some basic drawing and a single operator to change the frame.
2008-06-11 10:10:31 +00:00
const ListBase *BKE_spacetypes_list()
{
return &spacetypes;
}
void BKE_spacetype_register(SpaceType *st)
{
SpaceType *stype;
/* sanity check */
stype= BKE_spacetype_from_id(st->spaceid);
if(stype) {
printf("error: redefinition of spacetype %s\n", stype->name);
spacetype_free(stype);
MEM_freeN(stype);
}
BLI_addtail(&spacetypes, st);
}
/* ***************** Space handling ********************** */
void BKE_spacedata_freelist(ListBase *lb)
{
SpaceLink *sl;
ARegion *ar;
for (sl= lb->first; sl; sl= sl->next) {
SpaceType *st= BKE_spacetype_from_id(sl->spacetype);
/* free regions for pushed spaces */
for(ar=sl->regionbase.first; ar; ar=ar->next)
BKE_area_region_free(st, ar);
BLI_freelistN(&sl->regionbase);
if(st && st->free)
st->free(sl);
}
BLI_freelistN(lb);
}
ARegion *BKE_area_region_copy(SpaceType *st, ARegion *ar)
{
ARegion *newar= MEM_dupallocN(ar);
Panel *pa, *newpa, *patab;
newar->prev= newar->next= NULL;
newar->handlers.first= newar->handlers.last= NULL;
newar->uiblocks.first= newar->uiblocks.last= NULL;
newar->swinid= 0;
/* use optional regiondata callback */
if(ar->regiondata) {
ARegionType *art= BKE_regiontype_from_id(st, ar->regiontype);
if(art && art->duplicate)
newar->regiondata= art->duplicate(ar->regiondata);
else
newar->regiondata= MEM_dupallocN(ar->regiondata);
}
newar->panels.first= newar->panels.last= NULL;
BLI_duplicatelist(&newar->panels, &ar->panels);
/* copy panel pointers */
for(newpa= newar->panels.first; newpa; newpa= newpa->next) {
patab= newar->panels.first;
pa= ar->panels.first;
while(patab) {
if(newpa->paneltab == pa) {
newpa->paneltab = patab;
break;
}
patab= patab->next;
pa= pa->next;
}
}
return newar;
}
/* from lb2 to lb1, lb1 is supposed to be free'd */
static void region_copylist(SpaceType *st, ListBase *lb1, ListBase *lb2)
{
ARegion *ar;
/* to be sure */
lb1->first= lb1->last= NULL;
for(ar= lb2->first; ar; ar= ar->next) {
ARegion *arnew= BKE_area_region_copy(st, ar);
BLI_addtail(lb1, arnew);
}
}
/* lb1 should be empty */
void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2)
{
SpaceLink *sl;
lb1->first= lb2->last= NULL; /* to be sure */
for (sl= lb2->first; sl; sl= sl->next) {
SpaceType *st= BKE_spacetype_from_id(sl->spacetype);
if(st && st->duplicate) {
SpaceLink *slnew= st->duplicate(sl);
BLI_addtail(lb1, slnew);
region_copylist(st, &slnew->regionbase, &sl->regionbase);
}
}
}
Various changes made in the process of working on the UI code: * Added functions to generate Timer events. There was some unfinished code to create one timer per window, this replaces that with a way to let operators or other handlers add/remove their own timers as needed. This is currently delivered as an event with the timer handle, perhaps this should be a notifier instead? Also includes some fixes in ghost for timer events that were not delivered in time, due to passing negative timeout. * Added a Message event, which is a generic event that can be added by any operator. This is used in the UI code to communicate the results of opened blocks. Again, this may be better as a notifier. * These two events should not be blocked as they are intended for a specific operator or handler, so there were exceptions added for this, which is one of the reasons they might work better as notifiers, but currently these things can't listen to notifier yet. * Added an option to events to indicate if the customdata should be freed or not. * Added a free() callback for area regions, and added a free function for area regions in blenkernel since it was already there for screens and areas. * Added ED_screen/area/region_exit functions to clean up things like operators and handlers when they are closed. * Added screen level regions, these will draw over areas boundaries, with the last created region on top. These are useful for tooltips, menus, etc, and are not saved to file. It's using the same ARegion struct as areas to avoid code duplication, but perhaps that should be renamed then. Note that redraws currently go correct, because only full window redraws are used, for partial redraws without any frontbuffer drawing, the window manager needs to get support for compositing subwindows. * Minor changes in the subwindow code to retrieve the matrix, and moved setlinestyle to glutil.c. * Reversed argument order in WM_event_add/remove_keymap_handler to be consistent with modal_handler. * Operators can now block events but not necessarily cancel/finish. * Modal operators are now stored in a list in the window/area/region they were created in. This means for example that when a transform operator is invoked from a region but registers a handler at the window level (since mouse motion across areas should work), it will still get removed when the region is closed while the operator is running.
2008-11-11 15:18:21 +00:00
/* not region itself */
void BKE_area_region_free(SpaceType *st, ARegion *ar)
Various changes made in the process of working on the UI code: * Added functions to generate Timer events. There was some unfinished code to create one timer per window, this replaces that with a way to let operators or other handlers add/remove their own timers as needed. This is currently delivered as an event with the timer handle, perhaps this should be a notifier instead? Also includes some fixes in ghost for timer events that were not delivered in time, due to passing negative timeout. * Added a Message event, which is a generic event that can be added by any operator. This is used in the UI code to communicate the results of opened blocks. Again, this may be better as a notifier. * These two events should not be blocked as they are intended for a specific operator or handler, so there were exceptions added for this, which is one of the reasons they might work better as notifiers, but currently these things can't listen to notifier yet. * Added an option to events to indicate if the customdata should be freed or not. * Added a free() callback for area regions, and added a free function for area regions in blenkernel since it was already there for screens and areas. * Added ED_screen/area/region_exit functions to clean up things like operators and handlers when they are closed. * Added screen level regions, these will draw over areas boundaries, with the last created region on top. These are useful for tooltips, menus, etc, and are not saved to file. It's using the same ARegion struct as areas to avoid code duplication, but perhaps that should be renamed then. Note that redraws currently go correct, because only full window redraws are used, for partial redraws without any frontbuffer drawing, the window manager needs to get support for compositing subwindows. * Minor changes in the subwindow code to retrieve the matrix, and moved setlinestyle to glutil.c. * Reversed argument order in WM_event_add/remove_keymap_handler to be consistent with modal_handler. * Operators can now block events but not necessarily cancel/finish. * Modal operators are now stored in a list in the window/area/region they were created in. This means for example that when a transform operator is invoked from a region but registers a handler at the window level (since mouse motion across areas should work), it will still get removed when the region is closed while the operator is running.
2008-11-11 15:18:21 +00:00
{
if(st) {
ARegionType *art= BKE_regiontype_from_id(st, ar->regiontype);
if(art && art->free)
art->free(ar);
}
if(ar) {
2009-01-22 14:59:49 +00:00
if(ar->regiondata)
printf("regiondata free error\n");
BLI_freelistN(&ar->panels);
}
Various changes made in the process of working on the UI code: * Added functions to generate Timer events. There was some unfinished code to create one timer per window, this replaces that with a way to let operators or other handlers add/remove their own timers as needed. This is currently delivered as an event with the timer handle, perhaps this should be a notifier instead? Also includes some fixes in ghost for timer events that were not delivered in time, due to passing negative timeout. * Added a Message event, which is a generic event that can be added by any operator. This is used in the UI code to communicate the results of opened blocks. Again, this may be better as a notifier. * These two events should not be blocked as they are intended for a specific operator or handler, so there were exceptions added for this, which is one of the reasons they might work better as notifiers, but currently these things can't listen to notifier yet. * Added an option to events to indicate if the customdata should be freed or not. * Added a free() callback for area regions, and added a free function for area regions in blenkernel since it was already there for screens and areas. * Added ED_screen/area/region_exit functions to clean up things like operators and handlers when they are closed. * Added screen level regions, these will draw over areas boundaries, with the last created region on top. These are useful for tooltips, menus, etc, and are not saved to file. It's using the same ARegion struct as areas to avoid code duplication, but perhaps that should be renamed then. Note that redraws currently go correct, because only full window redraws are used, for partial redraws without any frontbuffer drawing, the window manager needs to get support for compositing subwindows. * Minor changes in the subwindow code to retrieve the matrix, and moved setlinestyle to glutil.c. * Reversed argument order in WM_event_add/remove_keymap_handler to be consistent with modal_handler. * Operators can now block events but not necessarily cancel/finish. * Modal operators are now stored in a list in the window/area/region they were created in. This means for example that when a transform operator is invoked from a region but registers a handler at the window level (since mouse motion across areas should work), it will still get removed when the region is closed while the operator is running.
2008-11-11 15:18:21 +00:00
}
/* not area itself */
void BKE_screen_area_free(ScrArea *sa)
{
SpaceType *st= BKE_spacetype_from_id(sa->spacetype);
ARegion *ar;
for(ar=sa->regionbase.first; ar; ar=ar->next)
BKE_area_region_free(st, ar);
Various changes made in the process of working on the UI code: * Added functions to generate Timer events. There was some unfinished code to create one timer per window, this replaces that with a way to let operators or other handlers add/remove their own timers as needed. This is currently delivered as an event with the timer handle, perhaps this should be a notifier instead? Also includes some fixes in ghost for timer events that were not delivered in time, due to passing negative timeout. * Added a Message event, which is a generic event that can be added by any operator. This is used in the UI code to communicate the results of opened blocks. Again, this may be better as a notifier. * These two events should not be blocked as they are intended for a specific operator or handler, so there were exceptions added for this, which is one of the reasons they might work better as notifiers, but currently these things can't listen to notifier yet. * Added an option to events to indicate if the customdata should be freed or not. * Added a free() callback for area regions, and added a free function for area regions in blenkernel since it was already there for screens and areas. * Added ED_screen/area/region_exit functions to clean up things like operators and handlers when they are closed. * Added screen level regions, these will draw over areas boundaries, with the last created region on top. These are useful for tooltips, menus, etc, and are not saved to file. It's using the same ARegion struct as areas to avoid code duplication, but perhaps that should be renamed then. Note that redraws currently go correct, because only full window redraws are used, for partial redraws without any frontbuffer drawing, the window manager needs to get support for compositing subwindows. * Minor changes in the subwindow code to retrieve the matrix, and moved setlinestyle to glutil.c. * Reversed argument order in WM_event_add/remove_keymap_handler to be consistent with modal_handler. * Operators can now block events but not necessarily cancel/finish. * Modal operators are now stored in a list in the window/area/region they were created in. This means for example that when a transform operator is invoked from a region but registers a handler at the window level (since mouse motion across areas should work), it will still get removed when the region is closed while the operator is running.
2008-11-11 15:18:21 +00:00
BLI_freelistN(&sa->regionbase);
BKE_spacedata_freelist(&sa->spacedata);
BLI_freelistN(&sa->actionzones);
2008-11-24 21:57:58 +00:00
#ifndef DISABLE_PYTHON
BPY_free_scriptlink(&sa->scriptlink);
2008-11-24 21:57:58 +00:00
#endif
}
2002-10-12 11:37:38 +00:00
/* don't free screen itself */
void free_screen(bScreen *sc)
{
ScrArea *sa, *san;
ARegion *ar;
Lots of stuff; couldn't commit in parts because of refactor work. * Changes in interface/ module This commit brings back the way how buttons/menus work under control of WM event system. The previous implementation extended usage of handlers and operators in an interesting but confusing way. Better to try it first according the design specs. :) Most obviously: - modal-handler operators are not stored anymore in regions/areas/windows. such modal handlers own their operator, and should remove it themselves. - removed code to move handlers from one queue to another. (needs review with brecht!) - WM fix: the API call to remove a modal handler got removed. This was a dangerous thing anyway, and you should leave that to the event system. Now, if a handler modal() call gets a cancel/finish return, it frees itself in event system. WM_event_remove_modal_handler was a confusing call anyway! Todo: - allow button-activate to refresh after using button - re-enable arrow keys for menus (do both after commit) - review return values of operator callbacks in interface_ops.c * Fixes in WM system - Freeing areas/regions/windows, also on quit, now correctly closes running modal handlers - On starting a modal handler, the handler now stores previous area and region context, so they send proper notifiers etc. * Other fixes - Area-split operator had bug, wrong minimal size checking. This solves error when trying to split a very narrow area. - removed DNA_USHORT_FIX from screen_types.h, gave warning - operators didn't get ID name copied when activated, needed for later re-use or saving.
2008-12-02 14:22:52 +00:00
for(ar=sc->regionbase.first; ar; ar=ar->next)
BKE_area_region_free(NULL, ar);
Lots of stuff; couldn't commit in parts because of refactor work. * Changes in interface/ module This commit brings back the way how buttons/menus work under control of WM event system. The previous implementation extended usage of handlers and operators in an interesting but confusing way. Better to try it first according the design specs. :) Most obviously: - modal-handler operators are not stored anymore in regions/areas/windows. such modal handlers own their operator, and should remove it themselves. - removed code to move handlers from one queue to another. (needs review with brecht!) - WM fix: the API call to remove a modal handler got removed. This was a dangerous thing anyway, and you should leave that to the event system. Now, if a handler modal() call gets a cancel/finish return, it frees itself in event system. WM_event_remove_modal_handler was a confusing call anyway! Todo: - allow button-activate to refresh after using button - re-enable arrow keys for menus (do both after commit) - review return values of operator callbacks in interface_ops.c * Fixes in WM system - Freeing areas/regions/windows, also on quit, now correctly closes running modal handlers - On starting a modal handler, the handler now stores previous area and region context, so they send proper notifiers etc. * Other fixes - Area-split operator had bug, wrong minimal size checking. This solves error when trying to split a very narrow area. - removed DNA_USHORT_FIX from screen_types.h, gave warning - operators didn't get ID name copied when activated, needed for later re-use or saving.
2008-12-02 14:22:52 +00:00
BLI_freelistN(&sc->regionbase);
for(sa= sc->areabase.first; sa; sa= san) {
san= sa->next;
BKE_screen_area_free(sa);
}
2002-10-12 11:37:38 +00:00
BLI_freelistN(&sc->vertbase);
BLI_freelistN(&sc->edgebase);
BLI_freelistN(&sc->areabase);
}