2.5
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 18 Dec 2008 02:56:48 +0000 (02:56 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 18 Dec 2008 02:56:48 +0000 (02:56 +0000)
Context API

This adds the context API as described here. The main practical change
now is that C is not longer directly accessible but has to be accessed
through accessor functions. This basically adds the implementation of
the API and adaption of existing code with some minor changes. The next
task of course is to actually use this design to cleanup of bad level
calls and global access, in blenkernel, blenloader.

http://wiki.blender.org/index.php/BlenderDev/Blender2.5/Context

Error, Warning and Debug Info Reporting

This adds the error reporting API as described here. It should help
clean up error() calls in non-ui code, but eventually can become used
for gathering messages for a console window, and throwing exceptions
in python scripts when an error happens executing something.

http://wiki.blender.org/index.php/BlenderDev/Blender2.5/Reports

67 files changed:
source/blender/blenkernel/BKE_context.h [new file with mode: 0644]
source/blender/blenkernel/BKE_global.h
source/blender/blenkernel/BKE_report.h [new file with mode: 0644]
source/blender/blenkernel/BKE_screen.h
source/blender/blenkernel/SConscript
source/blender/blenkernel/intern/Makefile
source/blender/blenkernel/intern/blender.c
source/blender/blenkernel/intern/context.c [new file with mode: 0644]
source/blender/blenkernel/intern/library.c
source/blender/blenkernel/intern/report.c [new file with mode: 0644]
source/blender/blenloader/intern/writefile.c
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/interface_regions.c
source/blender/editors/interface/view2d.c
source/blender/editors/interface/view2d_ops.c
source/blender/editors/screen/area.c
source/blender/editors/screen/screen_edit.c
source/blender/editors/screen/screen_ops.c
source/blender/editors/space_action/action_header.c
source/blender/editors/space_action/space_action.c
source/blender/editors/space_api/space.c
source/blender/editors/space_api/spacetypes.c
source/blender/editors/space_buttons/buttons_header.c
source/blender/editors/space_buttons/space_buttons.c
source/blender/editors/space_file/file_header.c
source/blender/editors/space_file/filesel.c
source/blender/editors/space_file/space_file.c
source/blender/editors/space_image/image_header.c
source/blender/editors/space_image/space_image.c
source/blender/editors/space_info/info_header.c
source/blender/editors/space_info/space_info.c
source/blender/editors/space_ipo/ipo_header.c
source/blender/editors/space_ipo/space_ipo.c
source/blender/editors/space_nla/nla_header.c
source/blender/editors/space_nla/space_nla.c
source/blender/editors/space_node/node_header.c
source/blender/editors/space_node/space_node.c
source/blender/editors/space_outliner/outliner_header.c
source/blender/editors/space_outliner/space_outliner.c
source/blender/editors/space_script/script_header.c
source/blender/editors/space_script/space_script.c
source/blender/editors/space_sequencer/sequencer_header.c
source/blender/editors/space_sequencer/space_sequencer.c
source/blender/editors/space_sound/sound_header.c
source/blender/editors/space_sound/space_sound.c
source/blender/editors/space_text/space_text.c
source/blender/editors/space_text/text_header.c
source/blender/editors/space_time/space_time.c
source/blender/editors/space_time/time_header.c
source/blender/editors/space_time/time_ops.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/editors/space_view3d/view3d_header.c
source/blender/editors/util/ed_markers.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm.c
source/blender/windowmanager/intern/wm_cursors.c
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_files.c
source/blender/windowmanager/intern/wm_gesture.c
source/blender/windowmanager/intern/wm_init_exit.c
source/blender/windowmanager/intern/wm_keymap.c
source/blender/windowmanager/intern/wm_operators.c
source/blender/windowmanager/intern/wm_report.c [deleted file]
source/blender/windowmanager/intern/wm_subwindow.c
source/blender/windowmanager/intern/wm_window.c
source/creator/creator.c

diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h
new file mode 100644 (file)
index 0000000..90f158c
--- /dev/null
@@ -0,0 +1,154 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * Contributor(s): Blender Foundation (2008).
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef BKE_CONTEXT_H
+#define BKE_CONTEXT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "DNA_listBase.h"
+
+struct ARegion;
+struct bScreen;
+struct EditMesh;
+struct ListBase;
+struct Main;
+struct Object;
+struct PointerRNA;
+struct ReportList;
+struct Scene;
+struct ScrArea;
+struct SpaceLink;
+struct StructRNA;
+struct ToolSettings;
+struct wmWindow;
+struct wmWindowManager;
+
+/* Structs */
+
+struct bContext;
+typedef struct bContext bContext;
+
+struct bContextDataMember;
+typedef struct bContextDataMember bContextDataMember;
+
+extern bContextDataMember CTX_DataMain;
+extern bContextDataMember CTX_DataScene;
+extern bContextDataMember CTX_DataObjects;
+extern bContextDataMember CTX_DataEditObject;
+extern bContextDataMember CTX_DataEditArmature;
+extern bContextDataMember CTX_DataEditMesh;
+
+typedef struct bContextDataIterator {
+       void *data;
+       int valid;
+
+       void (*begin)(bContext *C, struct bContextDataIterator *iter);
+       void (*next)(struct bContextDataIterator *iter);
+       void (*end)(struct bContextDataIterator *iter);
+       void *internal;
+} bContextDataIterator;
+
+typedef struct bContextDataResult {
+       void *pointer;
+       bContextDataIterator iterator;
+} bContextDataResult;
+
+typedef int (*bContextDataCallback)(const bContext *C,
+       const bContextDataMember *member, bContextDataResult *result);
+
+/* Context */
+
+bContext *CTX_create(void);
+void CTX_free(bContext *C);
+
+bContext *CTX_copy(const bContext *C, int thread);
+int CTX_thread(const bContext *C);
+
+/* Context Task and Reports */
+
+typedef enum bContextTask {
+       CTX_DRAWING = 0,
+       CTX_EDITING = 1,
+       CTX_EVALUATING = 2,
+       CTX_UNDEFINED = 3
+} bContextTask;
+
+bContextTask CTX_task(const bContext *C);
+void CTX_task_set(bContext *C, bContextTask task);
+
+struct ReportList *CTX_reports(const bContext *C);
+void CTX_reports_set(bContext *C, struct ReportList *reports);
+
+/* Window Manager Context */
+
+struct wmWindowManager *CTX_wm_manager(const bContext *C);
+struct wmWindow *CTX_wm_window(const bContext *C);
+struct bScreen *CTX_wm_screen(const bContext *C);
+struct ScrArea *CTX_wm_area(const bContext *C);
+struct SpaceLink *CTX_wm_space_data(const bContext *C);
+struct ARegion *CTX_wm_region(const bContext *C);
+void *CTX_wm_region_data(const bContext *C);
+struct uiBlock *CTX_wm_ui_block(const bContext *C);
+
+void CTX_wm_manager_set(bContext *C, struct wmWindowManager *wm);
+void CTX_wm_window_set(bContext *C, struct wmWindow *win);
+void CTX_wm_screen_set(bContext *C, struct bScreen *screen); /* to be removed */
+void CTX_wm_area_set(bContext *C, struct ScrArea *win);
+void CTX_wm_region_set(bContext *C, struct ARegion *win);
+void CTX_wm_ui_block_set(bContext *C, struct uiBlock *block, bContextDataCallback cb);
+
+/* Data Context */
+
+struct Main *CTX_data_main(const bContext *C);
+struct Scene *CTX_data_scene(const bContext *C);
+struct ToolSettings *CTX_data_tool_settings(const bContext *C);
+
+void CTX_data_main_set(bContext *C, struct Main *bmain);
+void CTX_data_scene_set(bContext *C, struct Scene *bmain);
+
+int CTX_data_objects(const bContext *C, bContextDataIterator *iter);
+
+struct Object *CTX_data_edit_object(const bContext *C);
+struct EditMesh *CTX_data_edit_mesh(const bContext *C);
+struct ListBase *CTX_data_edit_armature(const bContext *C);
+
+/* Data Evaluation Context */
+
+float CTX_eval_frame(const bContext *C);
+
+int CTX_eval_render_resolution(const bContext *C);
+void CTX_eval_render_resolution_set(bContext *C, int render);
+
+#ifdef __cplusplus
+}
+#endif
+       
+#endif
+
index 498fd6169b2999a95b16c5f879e62311950147d7..284d41e7891e1c96407a2208d1096db0ed2fa793 100644 (file)
@@ -63,27 +63,6 @@ struct BMF_Font;
 struct EditMesh;
 struct BME_Glob;
 
-/* former global stuff. context is derived, not storage! */
-typedef struct bContext {
-       
-       /* windowmanager tree context */
-       struct wmWindowManager *wm;
-       struct wmWindow *window;
-       struct bScreen *screen;
-       struct ScrArea *area;
-       struct ARegion *region;
-       
-       /* data context */
-       struct Scene *scene;
-       struct Object *obact;
-       struct Object *obedit;
-       
-       /* edit data context */
-       struct EditMesh *editMesh;
-       struct ListBase edbo;                   /* Armature Editmode bones */
-       
-} bContext;
-
 typedef struct Global {
 
        /* active pointers */
diff --git a/source/blender/blenkernel/BKE_report.h b/source/blender/blenkernel/BKE_report.h
new file mode 100644 (file)
index 0000000..39a5076
--- /dev/null
@@ -0,0 +1,83 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * Contributor(s): Blender Foundation (2008).
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef BKE_REPORT_H
+#define BKE_REPORT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "DNA_listBase.h"
+
+/* Reporting Information and Errors */
+
+typedef enum ReportType {
+       RPT_DEBUG                                       = 0,
+       RPT_INFO                                        = 1000,
+       RPT_WARNING                                     = 2000,
+       RPT_ERROR                                       = 3000,
+       RPT_ERROR_INVALID_INPUT         = 3001,
+       RPT_ERROR_INVALID_CONTEXT       = 3002,
+       RPT_ERROR_OUT_OF_MEMORY         = 3003
+} ReportType;
+
+enum ReportListFlags {
+       RPT_PRINT = 1,
+       RPT_STORE = 2
+};
+
+typedef struct Report {
+       struct Report *next, *prev;
+       ReportType type;
+       char *typestr;
+       char *message;
+} Report;
+
+typedef struct ReportList {
+       ListBase list;
+       ReportType level;
+       int flags;
+} ReportList;
+
+void BKE_report_list_init(ReportList *reports, int flag);
+void BKE_report_list_clear(ReportList *reports);
+
+void BKE_report(ReportList *reports, ReportType type, const char *message);
+void BKE_reportf(ReportList *reports, ReportType type, const char *format, ...);
+
+ReportType BKE_report_level(ReportList *reports);
+void BKE_report_level_set(ReportList *reports, ReportType level);
+
+int BKE_report_has_error(ReportList *reports);
+
+#ifdef __cplusplus
+}
+#endif
+       
+#endif
+
index bb3188de5119103fb3b1e79181cea20632943dfb..acb9814b64a89948f4202db7eebc584de2d6e63f 100644 (file)
 #ifndef BKE_SCREEN_H
 #define BKE_SCREEN_H
 
-struct SpaceType;
-struct ScrArea;
-struct bScreen;
 struct ARegion;
+struct bContext;
+struct bContextDataMember;
+struct bContextDataResult;
+struct bScreen;
+struct ListBase;
+struct ScrArea;
+struct SpaceType;
 struct wmNotifier;
-struct wmWindowManager;
 struct wmWindow;
-struct ListBase;
+struct wmWindowManager;
 
 /* spacetype has everything stored to get an editor working, it gets initialized via 
    ED_spacetypes_init() in editors/area/spacetypes.c   */
@@ -73,6 +76,9 @@ typedef struct SpaceType {
        /* sets default cursor per region */
        void            (*cursor)(struct wmWindow *win, struct ARegion *ar);
 
+       /* return context data */
+       int                     (*context)(const struct bContext *, const struct bContextDataMember *, struct bContextDataResult *);
+
        /* region type definitions */
        ListBase        regiontypes;
        
@@ -104,6 +110,9 @@ typedef struct ARegionType {
        /* add own items to keymap */
        void            (*keymap)(struct wmWindowManager *);
        
+       /* return context data */
+       int                     (*context)(const struct bContext *, const struct bContextDataMember *, struct bContextDataResult *);
+
        /* hardcoded constraints, smaller than these values region is not visible */
        int                     minsizex, minsizey;
        /* default keymaps to add */
index 071fd5d82d9e937b00f7d8d9c8690263c72bcb4a..33874d7c881f5ea3a324f9bd9405b2dd578021fc 100644 (file)
@@ -4,7 +4,7 @@ Import ('env')
 sources = env.Glob('intern/*.c')
 
 incs = '. #/intern/guardedalloc ../editors/include ../blenlib ../makesdna'
-incs += ' ../render/extern/include #/intern/decimation/extern'
+incs += ' ../render/extern/include #/intern/decimation/extern ../makesrna'
 incs += ' ../imbuf ../avi #/intern/elbeem/extern ../nodes'
 incs += ' #/intern/iksolver/extern ../blenloader'
 incs += ' #/extern/bullet2/src'
index 4cfc8f91efe8e7f1dce947990b2ca3577ee44525..8919719d64d7e647307241845d93e622ad4c2536 100644 (file)
@@ -43,6 +43,7 @@ CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION)
 CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
 # Reference to the types in makesdna and imbuf
 CPPFLAGS += -I../../makesdna
+CPPFLAGS += -I../../makesrna
 CPPFLAGS += -I../../imbuf
 # This mod uses the BLI and BLO module
 CPPFLAGS += -I../../blenlib
index e5625fa03e049e79e02ddcdd3e67af5b3cf32a48..b891e75a71b9a62b93e2a1be218acc7dccee89d3 100644 (file)
@@ -67,6 +67,7 @@
 
 #include "BKE_action.h"
 #include "BKE_blender.h"
+#include "BKE_context.h"
 #include "BKE_curve.h"
 #include "BKE_depsgraph.h"
 #include "BKE_displist.h"
@@ -324,7 +325,7 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, char *filename)
                SWAP(ListBase, G.main->script, bfd->main->script);
                
                /* we re-use current screen */
-               curscreen= C->screen;
+               curscreen= CTX_wm_screen(C);
                /* but use new Scene pointer */
                curscene= bfd->curscene;
                if(curscene==NULL) curscene= bfd->main->scene.first;
@@ -341,6 +342,7 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, char *filename)
        if(mode!='u') G.save_over = 1;
        
        G.main= bfd->main;
+       CTX_data_main_set(C, G.main);
        
        if (bfd->user) {
                
@@ -356,20 +358,20 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, char *filename)
        
        /* case G_FILE_NO_UI or no screens in file */
        if(mode) {
-               C->screen= curscreen;
-               C->scene= curscene;
+               CTX_wm_screen_set(C, curscreen);
+               CTX_data_scene_set(C, curscene);
        }
        else {
                G.winpos= bfd->winpos;
                G.displaymode= bfd->displaymode;
                G.fileflags= bfd->fileflags;
-               C->screen= bfd->curscreen;
-               C->scene= C->screen->scene;
+               CTX_wm_screen_set(C, bfd->curscreen);
+               CTX_data_scene_set(C, bfd->curscreen->scene);
        }
        /* this can happen when active scene was lib-linked, and doesnt exist anymore */
-       if(C->scene==NULL) {
-               C->scene= G.main->scene.first;
-               C->screen->scene= C->scene;
+       if(CTX_data_scene(C)==NULL) {
+               CTX_data_scene_set(C, G.main->scene.first);
+               CTX_wm_screen(C)->scene= CTX_data_scene(C);
        }
 
        /* special cases, override loaded flags: */
@@ -385,7 +387,7 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, char *filename)
        }
        
        /* baseflags, groups, make depsgraph, etc */
-       set_scene_bg(C->scene);
+       set_scene_bg(CTX_data_scene(C));
 
        /* clear BONE_UNKEYED flags, these are not valid anymore for proxies */
        framechange_poses_clear_unkeyed();
@@ -397,7 +399,7 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, char *filename)
        }
        
        /* now tag update flags, to ensure deformers get calculated on redraw */
-       DAG_scene_update_flags(C->scene, C->scene->lay);
+       DAG_scene_update_flags(CTX_data_scene(C), CTX_data_scene(C)->lay);
        
        if (G.f & G_DOSCRIPTLINKS) {
                /* there's an onload scriptlink to execute in screenmain */
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
new file mode 100644 (file)
index 0000000..b8633d8
--- /dev/null
@@ -0,0 +1,361 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * Contributor(s): Blender Foundation (2008).
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_listBase.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+#include "DNA_windowmanager_types.h"
+
+#include "RNA_access.h"
+
+#include "BKE_context.h"
+#include "BKE_main.h"
+#include "BKE_report.h"
+#include "BKE_screen.h"
+
+#include <string.h>
+
+/* struct */
+
+struct bContext {
+       bContextTask task;
+       ReportList *reports;
+       int thread;
+
+       /* windowmanager context */
+       struct {
+               struct wmWindowManager *manager;
+               struct wmWindow *window;
+               struct bScreen *screen;
+               struct ScrArea *area;
+               struct ARegion *region;
+               struct uiBlock *block;
+
+               bContextDataCallback manager_cb;
+               bContextDataCallback window_cb;
+               bContextDataCallback screen_cb;
+               bContextDataCallback area_cb;
+               bContextDataCallback region_cb;
+               bContextDataCallback block_cb;
+       } wm;
+       
+       /* data context */
+       struct {
+               struct Main *main;
+               struct Scene *scene;
+       } data;
+       
+       /* data evaluation */
+       struct {
+               int render;
+       } eval;
+};
+
+/* context */
+
+bContext *CTX_create()
+{
+       bContext *C;
+       
+       C= MEM_callocN(sizeof(bContext), "bContext");
+
+       C->task= CTX_UNDEFINED;
+       C->thread= 0;
+
+       return C;
+}
+
+bContext *CTX_copy(const bContext *C, int thread)
+{
+       bContext *newC;
+
+       if(C->task != CTX_UNDEFINED)
+               BKE_report(C->reports, RPT_ERROR_INVALID_CONTEXT, "CTX_copy not allowed for this task");
+       
+       newC= MEM_dupallocN((void*)C);
+       newC->thread= thread;
+
+       return newC;
+}
+
+int CTX_thread(const bContext *C)
+{
+       return C->thread;
+}
+
+void CTX_free(bContext *C)
+{
+       MEM_freeN(C);
+}
+
+/* context task and reports */
+
+bContextTask CTX_task(const bContext *C)
+{
+       return C->task;
+}
+
+void CTX_task_set(bContext *C, bContextTask task)
+{
+       C->task= task;
+}
+
+ReportList *CTX_reports(const bContext *C)
+{
+       return C->reports;
+}
+
+void CTX_reports_set(bContext *C, ReportList *reports)
+{
+       C->reports= reports;
+}
+
+/* window manager context */
+
+wmWindowManager *CTX_wm_manager(const bContext *C)
+{
+       return C->wm.manager;
+}
+
+wmWindow *CTX_wm_window(const bContext *C)
+{
+       return C->wm.window;
+}
+
+bScreen *CTX_wm_screen(const bContext *C)
+{
+       return C->wm.screen;
+}
+
+ScrArea *CTX_wm_area(const bContext *C)
+{
+       return C->wm.area;
+}
+
+SpaceLink *CTX_wm_space_data(const bContext *C)
+{
+       return (C->wm.area)? C->wm.area->spacedata.first: NULL;
+}
+
+ARegion *CTX_wm_region(const bContext *C)
+{
+       return C->wm.region;
+}
+
+void *CTX_wm_region_data(const bContext *C)
+{
+       return (C->wm.region)? C->wm.region->regiondata: NULL;
+}
+
+struct uiBlock *CTX_wm_ui_block(const bContext *C)
+{
+       return C->wm.block;
+}
+
+void CTX_wm_manager_set(bContext *C, wmWindowManager *wm)
+{
+       C->wm.manager= wm;
+}
+
+void CTX_wm_window_set(bContext *C, wmWindow *win)
+{
+       C->wm.window= win;
+       C->wm.screen= (win)? win->screen: NULL;
+       C->data.scene= (C->wm.screen)? C->wm.screen->scene: NULL;
+}
+
+void CTX_wm_screen_set(bContext *C, bScreen *screen)
+{
+       C->wm.screen= screen;
+       C->data.scene= (C->wm.screen)? C->wm.screen->scene: NULL;
+}
+
+void CTX_wm_area_set(bContext *C, ScrArea *area)
+{
+       C->wm.area= area;
+       C->wm.area_cb= (area && area->type)? area->type->context: NULL;
+}
+
+void CTX_wm_region_set(bContext *C, ARegion *region)
+{
+       C->wm.region= region;
+       C->wm.region_cb= (region && region->type)? region->type->context: NULL;
+}
+
+void CTX_wm_ui_block_set(bContext *C, struct uiBlock *block, bContextDataCallback cb)
+{
+       C->wm.block= block;
+       C->wm.block_cb= cb;
+}
+
+/* data context utility functions */
+
+struct bContextDataMember {
+       StructRNA *rna;
+       const char *name;
+       int collection;
+};
+
+bContextDataMember CTX_DataMain = {&RNA_Main, "main", 0};
+bContextDataMember CTX_DataScene = {&RNA_Scene, "scene", 0};
+
+bContextDataMember CTX_DataObjects = {&RNA_Object, "objects", 1};
+
+bContextDataMember CTX_DataEditObject = {&RNA_Object, "edit_object", 0};
+bContextDataMember CTX_DataEditArmature = {NULL, "edit_armature", 0};
+bContextDataMember CTX_DataEditMesh = {NULL, "edit_mesh", 0};
+
+static int ctx_data_get(const bContext *C, const bContextDataMember *member, bContextDataResult *result)
+{
+       if(C->wm.block_cb && C->wm.block_cb(C, member, result)) return 1;
+       if(C->wm.region_cb && C->wm.region_cb(C, member, result)) return 1;
+       if(C->wm.area_cb && C->wm.area_cb(C, member, result)) return 1;
+       if(C->wm.screen_cb && C->wm.screen_cb(C, member, result)) return 1;
+       if(C->wm.window_cb && C->wm.window_cb(C, member, result)) return 1;
+       if(C->wm.manager_cb && C->wm.manager_cb(C, member, result)) return 1;
+
+       return 0;
+}
+
+static void *ctx_data_pointer_get(const bContext *C, const bContextDataMember *member)
+{
+       bContextDataResult result;
+
+       if(ctx_data_get(C, member, &result))
+               return result.pointer;
+
+       return NULL;
+}
+
+static int ctx_data_pointer_verify(const bContext *C, const bContextDataMember *member, void **pointer)
+{
+       bContextDataResult result;
+
+       if(ctx_data_get(C, member, &result)) {
+               *pointer= result.pointer;
+               return 1;
+       }
+       else {
+               *pointer= NULL;
+               return 0;
+       }
+}
+
+static int ctx_data_collection_get(const bContext *C, const bContextDataMember *member, bContextDataIterator *iter)
+{
+       bContextDataResult result;
+
+       if(ctx_data_get(C, member, &result)) {
+               *iter= result.iterator;
+               return 1;
+       }
+
+       return 0;
+}
+
+/* data context */
+
+Main *CTX_data_main(const bContext *C)
+{
+       Main *bmain;
+
+       if(ctx_data_pointer_verify(C, &CTX_DataMain, (void*)&bmain))
+               return bmain;
+       else
+               return C->data.main;
+}
+
+void CTX_data_main_set(bContext *C, Main *bmain)
+{
+       C->data.main= bmain;
+}
+
+Scene *CTX_data_scene(const bContext *C)
+{
+       Scene *scene;
+
+       if(ctx_data_pointer_verify(C, &CTX_DataScene, (void*)&scene))
+               return scene;
+       else
+               return C->data.scene;
+}
+
+void CTX_data_scene_set(bContext *C, Scene *scene)
+{
+       C->data.scene= scene;
+}
+
+ToolSettings *CTX_data_tool_settings(const bContext *C)
+{
+       Scene *scene = CTX_data_scene(C);
+
+       if(scene)
+               return scene->toolsettings;
+       else
+               return NULL;
+}
+
+int CTX_data_objects(const bContext *C, bContextDataIterator *iter)
+{
+       return ctx_data_collection_get(C, &CTX_DataObjects, iter);
+}
+
+struct Object *CTX_data_edit_object(const bContext *C)
+{
+       return ctx_data_pointer_get(C, &CTX_DataEditObject);
+}
+
+struct EditMesh *CTX_data_edit_mesh(const bContext *C)
+{
+       return ctx_data_pointer_get(C, &CTX_DataEditMesh);
+}
+
+ListBase *CTX_data_edit_armature(const bContext *C)
+{
+       return ctx_data_pointer_get(C, &CTX_DataEditArmature);
+}
+
+/* data evaluation */
+
+float CTX_eval_frame(const bContext *C)
+{
+       return (C->data.scene)? C->data.scene->r.cfra: 0.0f;
+}
+
+int CTX_eval_render_resolution(const bContext *C)
+{
+       return C->eval.render;
+}
+
+void CTX_eval_render_resolution_set(bContext *C, int render)
+{
+       C->eval.render= render;
+}
+
index 8e36ea0204ba29097f791c89fd836c21a31a93cb..4fd3680639305ada75bb022f28a04fd3e41453eb 100644 (file)
@@ -83,6 +83,7 @@
 #include "BLI_dynstr.h"
 
 #include "BKE_library.h"
+#include "BKE_context.h"
 #include "BKE_main.h"
 #include "BKE_global.h"
 #include "BKE_sound.h"
diff --git a/source/blender/blenkernel/intern/report.c b/source/blender/blenkernel/intern/report.c
new file mode 100644 (file)
index 0000000..569377a
--- /dev/null
@@ -0,0 +1,186 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * Contributor(s): Blender Foundation (2008).
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_listBase.h"
+
+#include "BLI_blenlib.h"
+
+#include "BKE_report.h"
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+
+#ifdef _WIN32
+#ifndef vsnprintf
+#define vsnprintf _vsnprintf
+#endif
+#endif
+
+static char *report_type_str(int type)
+{
+       switch(type) {
+               case RPT_DEBUG: return "Debug";
+               case RPT_INFO: return "Info";
+               case RPT_WARNING: return "Warning";
+               case RPT_ERROR: return "Error";
+               case RPT_ERROR_INVALID_INPUT: return "Invalid Input Error";
+               case RPT_ERROR_INVALID_CONTEXT: return "Invalid Context Error";
+               case RPT_ERROR_OUT_OF_MEMORY: return "Out Of Memory Error";
+               default: return "Undefined Type";
+       }
+}
+
+void BKE_report_list_init(ReportList *reports, int flags)
+{
+       memset(reports, 0, sizeof(ReportList));
+
+       reports->level= RPT_WARNING;
+       reports->flags= flags;
+}
+
+void BKE_report_list_clear(ReportList *reports)
+{
+       Report *report;
+
+       for(report=reports->list.first; report; report=report->next)
+               MEM_freeN(report->message);
+
+       BLI_freelistN(&reports->list);
+}
+
+void BKE_report(ReportList *reports, ReportType type, const char *message)
+{
+       Report *report;
+       int len;
+
+       if(!reports || type < reports->level)
+               return;
+
+       if(reports->flags & RPT_PRINT) {
+               printf("%s: %s\n", report_type_str(type), message);
+               fflush(stdout); /* this ensures the message is printed before a crash */
+       }
+
+       if(reports->flags & RPT_STORE) {
+               report= MEM_callocN(sizeof(Report), "Report");
+               report->type= type;
+               report->typestr= report_type_str(type);
+
+               len= strlen(message);
+               report->message= MEM_callocN(sizeof(char)*(len+1), "ReportMessage");
+               memcpy(report->message, message, sizeof(char)*(len+1));
+               
+               BLI_addtail(&reports->list, report);
+       }
+}
+
+void BKE_reportf(ReportList *reports, ReportType type, const char *format, ...)
+{
+       Report *report;
+       va_list args;
+       char *message;
+       int len= 256, maxlen= 65536, retval;
+
+       if(!reports || type < reports->level)
+               return;
+
+       if(reports->flags & RPT_PRINT) {
+               va_start(args, format);
+               vprintf(format, args);
+               va_end(args);
+               fflush(stdout); /* this ensures the message is printed before a crash */
+       }
+
+       if(reports->flags & RPT_STORE) {
+               while(1) {
+                       message= MEM_callocN(sizeof(char)*len+1, "ReportMessage");
+
+                       va_start(args, format);
+                       retval= vsnprintf(message, len, format, args);
+                       va_end(args);
+
+                       if(retval == -1) {
+                               /* -1 means not enough space, but on windows it may also mean
+                                * there is a formatting error, so we impose a maximum length */
+                               MEM_freeN(message);
+                               message= NULL;
+
+                               len *= 2;
+                               if(len > maxlen) {
+                                       fprintf(stderr, "BKE_reportf message too long or format error.\n");
+                                       break;
+                               }
+                       }
+                       else if(retval > len) {
+                               /* in C99 the actual length required is returned */
+                               MEM_freeN(message);
+                               message= NULL;
+
+                               len= retval;
+                       }
+                       else
+                               break;
+               }
+
+               if(message) {
+                       report= MEM_callocN(sizeof(Report), "Report");
+                       report->type= type;
+                       report->typestr= report_type_str(type);
+                       report->message= message;
+
+                       BLI_addtail(&reports->list, report);
+               }
+       }
+}
+
+ReportType BKE_report_level(ReportList *reports)
+{
+       return reports->level;
+}
+
+void BKE_report_level_set(ReportList *reports, ReportType level)
+{
+       reports->level= level;
+}
+
+int BKE_report_has_error(ReportList *reports)
+{
+       Report *report;
+
+       if(!reports)
+               return 0;
+
+       for(report=reports->list.first; report; report=report->next)
+               if(report->type >= RPT_ERROR)
+                       return 1;
+       
+       return 0;
+}
+
index b5081888a960790f2663535a71d61396235f009c..d06ffe444657fd8c10252713539f5aeb1d2a2e2f 100644 (file)
@@ -145,6 +145,7 @@ Any case: direct data is ALWAYS after the lib block
 
 #include "BKE_action.h"
 #include "BKE_blender.h"
+#include "BKE_context.h"
 #include "BKE_cloth.h"
 #include "BKE_curve.h"
 #include "BKE_customdata.h"
@@ -483,9 +484,9 @@ static void write_renderinfo(bContext *C, WriteData *wd)            /* for renderdeamon */
        Scene *sce;
        int data[8];
 
-       sce= G.main->scene.first;
+       sce= CTX_data_main(C)->scene.first;
        while(sce) {
-               if(sce->id.lib==0  && ( sce==C->scene || (sce->r.scemode & R_BG_RENDER)) ) {
+               if(sce->id.lib==0  && ( sce==CTX_data_scene(C) || (sce->r.scemode & R_BG_RENDER)) ) {
                        data[0]= sce->r.sfra;
                        data[1]= sce->r.efra;
 
@@ -2019,8 +2020,8 @@ static void write_global(bContext *C, WriteData *wd)
        FileGlobal fg;
        char subvstr[8];
        
-       fg.curscreen= C->screen;
-       fg.curscene= C->scene;
+       fg.curscreen= CTX_wm_screen(C);
+       fg.curscene= CTX_data_scene(C);
        fg.displaymode= G.displaymode;
        fg.winpos= G.winpos;
        fg.fileflags= (G.fileflags & ~G_FILE_NO_UI);    // prevent to save this, is not good convention, and feature with concerns...
index 398a526fbd84009103a2038aa84553c6aa34e0e2..4ac979d3a5cffdac240a09d2be12b9cdb002cd2b 100644 (file)
@@ -41,7 +41,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_dynstr.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_idprop.h"
 #include "BKE_library.h"
 #include "BKE_screen.h"
@@ -1389,7 +1389,7 @@ uiBlock *uiBeginBlock(const bContext *C, ARegion *region, char *name, short dt,
        wmWindow *window;
        int getsizex, getsizey;
 
-       window= C->window;
+       window= CTX_wm_window(C);
        lb= &region->uiblocks;
        
        /* each listbase only has one block with this name, free block
@@ -2196,7 +2196,7 @@ void autocomplete_end(AutoComplete *autocpl, char *autoname)
 static void autocomplete_id(bContext *C, char *str, void *arg_v)
 {
        int blocktype= (intptr_t)arg_v;
-       ListBase *listb= wich_libbase(G.main, blocktype); /* XXX */
+       ListBase *listb= wich_libbase(CTX_data_main(C), blocktype);
        
        if(listb==NULL) return;
        
index 1d1f8cb44b90327b0e54ad3eabe77b4ec9035a9d..f22431ba73d46894cfee608bc2e8e1aadfc08cac 100644 (file)
@@ -41,8 +41,9 @@
 #include "PIL_time.h"
 
 #include "BKE_colortools.h"
+#include "BKE_context.h"
 #include "BKE_idprop.h"
-#include "BKE_global.h"
+#include "BKE_report.h"
 #include "BKE_texture.h"
 #include "BKE_utildefines.h"
 
@@ -345,7 +346,7 @@ static void ui_apply_but_NUM(bContext *C, uiBut *but, uiHandleButtonData *data)
                /* XXX 2.50 missing python api */
 #if 0
                if(BPY_button_eval(data->str, &data->value)) {
-                       WM_report(C, WM_LOG_WARNING, "Invalid Python expression, check console");
+                       BKE_report(CTX_reports(C), RPT_WARNING, "Invalid Python expression, check console");
                        data->value = 0.0f; /* Zero out value on error */
                        
                        if(data->str[0]) {
@@ -2536,14 +2537,14 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, wmEvent *event)
        if(ELEM(event->type, LEFTMOUSE, RETKEY)) {
                if(but->lock) {
                        if(but->lockstr) {
-                               WM_report(C, WM_LOG_WARNING, but->lockstr);
+                               BKE_report(CTX_reports(C), RPT_WARNING, but->lockstr);
                                button_activate_state(C, but, BUTTON_STATE_EXIT);
                                return WM_UI_HANDLER_BREAK;
                        }
                } 
                else if(but->pointype && but->poin==0) {
                        /* there's a pointer needed */
-                       WM_reportf(C, WM_LOG_WARNING, "DoButton pointer error: %s", but->str);
+                       BKE_reportf(CTX_reports(C), RPT_WARNING, "DoButton pointer error: %s", but->str);
                        button_activate_state(C, but, BUTTON_STATE_EXIT);
                        return WM_UI_HANDLER_BREAK;
                }
@@ -2862,7 +2863,7 @@ static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonA
 
        /* setup struct */
        data= MEM_callocN(sizeof(uiHandleButtonData), "uiHandleButtonData");
-       data->window= C->window;
+       data->window= CTX_wm_window(C);
        data->region= ar;
        data->interactive= 0;
        data->state = BUTTON_STATE_INIT;
@@ -3555,7 +3556,7 @@ static int ui_handler_region(bContext *C, wmEvent *event, void *userdata)
        int retval;
 
        /* here we handle buttons at the region level, non-modal */
-       ar= C->region;
+       ar= CTX_wm_region(C);
        retval= WM_UI_HANDLER_CONTINUE;
 
        if(ar==NULL) return retval;
@@ -3584,12 +3585,12 @@ static void ui_handler_remove_region(bContext *C, void *userdata)
        bScreen *sc;
        ARegion *ar;
 
-       ar= C->region;
+       ar= CTX_wm_region(C);
        if(ar == NULL) return;
 
        uiFreeBlocks(C, &ar->uiblocks);
        
-       sc= C->screen;
+       sc= CTX_wm_screen(C);
        if(sc == NULL) return;
 
        /* delayed apply callbacks, but not for screen level regions, those
@@ -3608,7 +3609,7 @@ static int ui_handler_region_menu(bContext *C, wmEvent *event, void *userdata)
 
        /* here we handle buttons at the window level, modal, for example
         * while number sliding, text editing, or when a menu block is open */
-       ar= C->region;
+       ar= CTX_wm_region(C);
        but= ui_but_find_activated(ar);
 
        if(but) {
@@ -3654,7 +3655,7 @@ static int ui_handler_popup(bContext *C, wmEvent *event, void *userdata)
        /* free if done, does not free handle itself */
        if(menu->menuretval) {
                ui_menu_block_free(C, menu);
-               WM_event_remove_ui_handler(&C->window->handlers, ui_handler_popup, ui_handler_remove_popup, menu);
+               WM_event_remove_ui_handler(&CTX_wm_window(C)->handlers, ui_handler_popup, ui_handler_remove_popup, menu);
 
                if(menu->menuretval == UI_RETURN_OK && menu->popup_func)
                        menu->popup_func(C, menu->popup_arg, menu->retvalue);
index a6f411951429be36e1a366b052a2b1ba7060fa73..c60bf374e6dcd8cb2c4cf8c2021c447c73855ac5 100644 (file)
@@ -37,7 +37,7 @@
 #include "BLI_arithb.h"
 #include "BLI_blenlib.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 #include "BKE_utildefines.h"
 
@@ -312,7 +312,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
                return NULL;
 
        /* create area region */
-       ar= ui_add_temporary_region(C->window->screen);
+       ar= ui_add_temporary_region(CTX_wm_screen(C));
 
        memset(&type, 0, sizeof(ARegionType));
        type.draw= ui_tooltip_region_draw;
@@ -353,7 +353,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
                y2 += butregion->winrct.ymin;
        }
 
-       wm_window_get_size(C->window, &winx, &winy);
+       wm_window_get_size(CTX_wm_window(C), &winx, &winy);
 
        if(x2 > winx) {
                /* super size */
@@ -387,7 +387,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
 
 void ui_tooltip_free(bContext *C, ARegion *ar)
 {
-       ui_remove_temporary_region(C, C->window->screen, ar);
+       ui_remove_temporary_region(C, CTX_wm_screen(C), ar);
 
        WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
 }
@@ -617,6 +617,7 @@ static void ui_block_region_draw(const bContext *C, ARegion *ar)
 
 uiMenuBlockHandle *ui_menu_block_create(bContext *C, ARegion *butregion, uiBut *but, uiBlockFuncFP block_func, void *arg)
 {
+       wmWindow *window= CTX_wm_window(C);
        static ARegionType type;
        ARegion *ar;
        uiBlock *block;
@@ -628,7 +629,7 @@ uiMenuBlockHandle *ui_menu_block_create(bContext *C, ARegion *butregion, uiBut *
        handle= MEM_callocN(sizeof(uiMenuBlockHandle), "uiMenuBlockHandle");
 
        /* create area region */
-       ar= ui_add_temporary_region(C->window->screen);
+       ar= ui_add_temporary_region(CTX_wm_screen(C));
 
        memset(&type, 0, sizeof(ARegionType));
        type.draw= ui_block_region_draw;
@@ -657,7 +658,7 @@ uiMenuBlockHandle *ui_menu_block_create(bContext *C, ARegion *butregion, uiBut *
                if(but->flag & UI_MAKE_LEFT) block->direction |= UI_LEFT;
                if(but->flag & UI_MAKE_RIGHT) block->direction |= UI_RIGHT;
 
-               ui_block_position(C->window, butregion, but, block);
+               ui_block_position(window, butregion, but, block);
        }
        else {
                /* keep a list of these, needed for pulldown menus */
@@ -692,8 +693,8 @@ uiMenuBlockHandle *ui_menu_block_create(bContext *C, ARegion *butregion, uiBut *
        ED_region_init(C, ar);
 
        /* get winmat now that we actually have the subwindow */
-       wm_subwindow_set(C->window, ar->swinid);
-       wm_subwindow_getmatrix(C->window, ar->swinid, block->winmat);
+       wm_subwindow_set(window, ar->swinid);
+       wm_subwindow_getmatrix(window, ar->swinid, block->winmat);
        
        /* notify change and redraw */
        ED_region_tag_redraw(ar);
@@ -703,7 +704,7 @@ uiMenuBlockHandle *ui_menu_block_create(bContext *C, ARegion *butregion, uiBut *
 
 void ui_menu_block_free(bContext *C, uiMenuBlockHandle *handle)
 {
-       ui_remove_temporary_region(C, C->window->screen, handle->region);
+       ui_remove_temporary_region(C, CTX_wm_screen(C), handle->region);
        MEM_freeN(handle);
 
        WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
@@ -1355,7 +1356,7 @@ uiBlock *ui_block_func_PUPMENU(bContext *C, uiMenuBlockHandle *handle, void *arg
        width+= 10;
        if (width<50) width=50;
        
-       wm_window_get_size(C->window, &xmax, &ymax);
+       wm_window_get_size(CTX_wm_window(C), &xmax, &ymax);
 
        /* set first item */
        lastselected= 0;
@@ -1527,7 +1528,7 @@ uiBlock *ui_block_func_PUPMENUCOL(bContext *C, uiMenuBlockHandle *handle, void *
        height= rows*MENU_BUTTON_HEIGHT;
        if (md->title) height+= MENU_BUTTON_HEIGHT;
        
-       wm_window_get_size(C->window, &xmax, &ymax);
+       wm_window_get_size(CTX_wm_window(C), &xmax, &ymax);
 
        /* find active item */
        fvalue= handle->retvalue;
@@ -1616,10 +1617,6 @@ uiBlock *ui_block_func_PUPMENUCOL(bContext *C, uiMenuBlockHandle *handle, void *
        
        uiBoundsBlock(block, 1);
        uiEndBlock(C, block);
-
-#if 0
-       event= uiDoBlocks(&listb, 0, 1);
-#endif
        
        menudata_free(md);
        
@@ -1634,19 +1631,20 @@ uiBlock *ui_block_func_PUPMENUCOL(bContext *C, uiMenuBlockHandle *handle, void *
 
 void uiPupmenu(bContext *C, int maxrow, uiPupmenuFunc func, void *arg, char *str, ...)
 {
+       wmWindow *window= CTX_wm_window(C);
        uiPupMenuInfo info;
        uiMenuBlockHandle *menu;
 
        memset(&info, 0, sizeof(info));
-       info.mx= C->window->eventstate->x;
-       info.my= C->window->eventstate->y;
+       info.mx= window->eventstate->x;
+       info.my= window->eventstate->y;
        info.maxrow= maxrow;
        info.instr= str;
 
        menu= ui_menu_block_create(C, NULL, NULL, ui_block_func_PUPMENU, &info);
        menu->popup= 1;
 
-       UI_add_popup_handlers(&C->window->handlers, menu);
+       UI_add_popup_handlers(&window->handlers, menu);
        WM_event_add_mousemove(C);
 
        menu->popup_func= func;
index cacde59145f90f5fade734671141ec831f086e0e..3213e1201355223a30a443dfff20cb7cddd076dd 100644 (file)
@@ -37,6 +37,7 @@
 
 #include "BLI_blenlib.h"
 
+#include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_utildefines.h"
 
@@ -630,16 +631,17 @@ static void view2d_map_cur_using_mask(View2D *v2d, rctf *curmasked)
 
 void UI_view2d_view_ortho(const bContext *C, View2D *v2d)
 {
+       wmWindow *window= CTX_wm_window(C);
        rctf curmasked;
        
        /* set the matrix - pixel offsets (-0.375) for 1:1 correspondance are not applied, 
         * as they were causing some unwanted offsets when drawing 
         */
        view2d_map_cur_using_mask(v2d, &curmasked);
-       wmOrtho2(C->window, curmasked.xmin, curmasked.xmax, curmasked.ymin, curmasked.ymax);
+       wmOrtho2(window, curmasked.xmin, curmasked.xmax, curmasked.ymin, curmasked.ymax);
        
        /* XXX is this necessary? */
-       wmLoadIdentity(C->window);
+       wmLoadIdentity(window);
 }
 
 /* Set view matrices to only use one axis of 'cur' only
@@ -649,7 +651,8 @@ void UI_view2d_view_ortho(const bContext *C, View2D *v2d)
  */
 void UI_view2d_view_orthoSpecial(const bContext *C, View2D *v2d, short xaxis)
 {
-       ARegion *ar= C->region;
+       wmWindow *window= CTX_wm_window(C);
+       ARegion *ar= CTX_wm_region(C);
        rctf curmasked;
        
        /* set the matrix - pixel offsets (-0.375) for 1:1 correspondance are not applied, 
@@ -657,19 +660,19 @@ void UI_view2d_view_orthoSpecial(const bContext *C, View2D *v2d, short xaxis)
         */
        view2d_map_cur_using_mask(v2d, &curmasked);
        if (xaxis)
-               wmOrtho2(C->window, curmasked.xmin, curmasked.xmax, 0, ar->winy);
+               wmOrtho2(window, curmasked.xmin, curmasked.xmax, 0, ar->winy);
        else
-               wmOrtho2(C->window, 0, ar->winx, curmasked.ymin, curmasked.ymax);
+               wmOrtho2(window, 0, ar->winx, curmasked.ymin, curmasked.ymax);
                
        /* XXX is this necessary? */
-       wmLoadIdentity(C->window);
+       wmLoadIdentity(window);
 } 
 
 
 /* Restore view matrices after drawing */
 void UI_view2d_view_restore(const bContext *C)
 {
-       ED_region_pixelspace(C, C->region);
+       ED_region_pixelspace(C, CTX_wm_region(C));
 }
 
 /* *********************************************************************** */
@@ -1490,24 +1493,30 @@ void UI_view2d_to_region_no_clip(View2D *v2d, float x, float y, short *regionx,
 /* View2D data by default resides in region, so get from region stored in context */
 View2D *UI_view2d_fromcontext(const bContext *C)
 {
-       if (C->area == NULL) return NULL;
-       if (C->region == NULL) return NULL;
-       return &(C->region->v2d);
+       ScrArea *area= CTX_wm_area(C);
+       ARegion *region= CTX_wm_region(C);
+
+       if (area == NULL) return NULL;
+       if (region == NULL) return NULL;
+       return &(region->v2d);
 }
 
 /* same as above, but it returns regionwindow. Utility for pulldowns or buttons */
 View2D *UI_view2d_fromcontext_rwin(const bContext *C)
 {
-       if (C->area == NULL) return NULL;
-       if (C->region == NULL) return NULL;
-       if (C->region->regiontype!=RGN_TYPE_WINDOW) {
-               ARegion *ar= C->area->regionbase.first;
+       ScrArea *area= CTX_wm_area(C);
+       ARegion *region= CTX_wm_region(C);
+
+       if (area == NULL) return NULL;
+       if (region == NULL) return NULL;
+       if (region->regiontype!=RGN_TYPE_WINDOW) {
+               ARegion *ar= area->regionbase.first;
                for(; ar; ar= ar->next)
                        if(ar->regiontype==RGN_TYPE_WINDOW)
                                return &(ar->v2d);
                return NULL;
        }
-       return &(C->region->v2d);
+       return &(region->v2d);
 }
 
 
index abf114e8fd9015196b38f4e2baf7a4b73cd6f2a1..5995cccc8742e2dc293ccaf67bd4b54ab5b6cf14 100644 (file)
@@ -37,7 +37,7 @@
 
 #include "BLI_blenlib.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_utildefines.h"
 
 #include "RNA_access.h"
@@ -66,7 +66,7 @@
  */
 static short mouse_in_v2d_scrollers (const bContext *C, View2D *v2d, int x, int y)
 {
-       ARegion *ar= C->region;
+       ARegion *ar= CTX_wm_region(C);
        int co[2];
        
        /* clamp x,y to region-coordinates first */
@@ -115,15 +115,14 @@ typedef struct v2dViewPanData {
 /* initialise panning customdata */
 static int view_pan_init(bContext *C, wmOperator *op)
 {
+       ARegion *ar= CTX_wm_region(C);
        v2dViewPanData *vpd;
-       ARegion *ar;
        View2D *v2d;
        float winx, winy;
        
        /* regions now have v2d-data by default, so check for region */
-       if (C->region == NULL)
+       if (ar == NULL)
                return 0;
-       ar= C->region;
        
        /* set custom-data for operator */
        vpd= MEM_callocN(sizeof(v2dViewPanData), "v2dViewPanData");
@@ -166,8 +165,8 @@ static void view_pan_apply(bContext *C, wmOperator *op)
        UI_view2d_curRect_validate(v2d);
        
        /* request updates to be done... */
-       ED_area_tag_redraw(C->area);
-       UI_view2d_sync(C->screen, v2d, V2D_LOCK_COPY);
+       ED_area_tag_redraw(CTX_wm_area(C));
+       UI_view2d_sync(CTX_wm_screen(C), v2d, V2D_LOCK_COPY);
 }
 
 /* cleanup temp customdata  */
@@ -195,6 +194,7 @@ static int view_pan_exec(bContext *C, wmOperator *op)
 /* set up modal operator and relevant settings */
 static int view_pan_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
+       wmWindow *window= CTX_wm_window(C);
        v2dViewPanData *vpd;
        View2D *v2d;
        
@@ -212,14 +212,14 @@ static int view_pan_invoke(bContext *C, wmOperator *op, wmEvent *event)
        RNA_int_set(op->ptr, "deltay", 0);
        
        if (v2d->keepofs & V2D_LOCKOFS_X)
-               WM_cursor_modal(C->window, BC_NS_SCROLLCURSOR);
+               WM_cursor_modal(window, BC_NS_SCROLLCURSOR);
        else if (v2d->keepofs & V2D_LOCKOFS_Y)
-               WM_cursor_modal(C->window, BC_EW_SCROLLCURSOR);
+               WM_cursor_modal(window, BC_EW_SCROLLCURSOR);
        else
-               WM_cursor_modal(C->window, BC_NSEW_SCROLLCURSOR);
+               WM_cursor_modal(window, BC_NSEW_SCROLLCURSOR);
        
        /* add temp handler */
-       WM_event_add_modal_handler(C, &C->window->handlers, op);
+       WM_event_add_modal_handler(C, &window->handlers, op);
 
        return OPERATOR_RUNNING_MODAL;
 }
@@ -251,7 +251,7 @@ static int view_pan_modal(bContext *C, wmOperator *op, wmEvent *event)
                                RNA_int_set(op->ptr, "deltay", (vpd->starty - vpd->lasty));
                                
                                view_pan_exit(C, op);
-                               WM_cursor_restore(C->window);
+                               WM_cursor_restore(CTX_wm_window(C));
                                
                                return OPERATOR_FINISHED;
                        }
@@ -455,12 +455,13 @@ void ED_View2D_OT_view_scrollup(wmOperatorType *ot)
 /* check if step-zoom can be applied */
 static short view_zoomstep_ok(bContext *C)
 {
+       ARegion *ar= CTX_wm_region(C);
        View2D *v2d;
        
        /* check if there's a region in context to work with */
-       if (C->region == NULL)
+       if (ar == NULL)
                return 0;
-       v2d= &C->region->v2d;
+       v2d= &ar->v2d;
        
        /* check that 2d-view is zoomable */
        if ((v2d->keepzoom & V2D_LOCKZOOM_X) && (v2d->keepzoom & V2D_LOCKZOOM_Y))
@@ -473,7 +474,8 @@ static short view_zoomstep_ok(bContext *C)
 /* apply transform to view (i.e. adjust 'cur' rect) */
 static void view_zoomstep_apply(bContext *C, wmOperator *op)
 {
-       View2D *v2d= &C->region->v2d;
+       ARegion *ar= CTX_wm_region(C);
+       View2D *v2d= &ar->v2d;
        float dx, dy;
        
        /* calculate amount to move view by */
@@ -494,8 +496,8 @@ static void view_zoomstep_apply(bContext *C, wmOperator *op)
        UI_view2d_curRect_validate(v2d);
        
        /* request updates to be done... */
-       ED_area_tag_redraw(C->area);
-       UI_view2d_sync(C->screen, v2d, V2D_LOCK_COPY);
+       ED_area_tag_redraw(CTX_wm_area(C));
+       UI_view2d_sync(CTX_wm_screen(C), v2d, V2D_LOCK_COPY);
 }
 
 /* --------------- Individual Operators ------------------- */
@@ -599,13 +601,14 @@ typedef struct v2dViewZoomData {
 /* initialise panning customdata */
 static int view_zoomdrag_init(bContext *C, wmOperator *op)
 {
+       ARegion *ar= CTX_wm_region(C);
        v2dViewZoomData *vzd;
        View2D *v2d;
        
        /* regions now have v2d-data by default, so check for region */
-       if (C->region == NULL)
+       if (ar == NULL)
                return 0;
-       v2d= &C->region->v2d;
+       v2d= &ar->v2d;
        
        /* check that 2d-view is zoomable */
        if ((v2d->keepzoom & V2D_LOCKZOOM_X) && (v2d->keepzoom & V2D_LOCKZOOM_Y))
@@ -646,8 +649,8 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op)
        UI_view2d_curRect_validate(v2d);
        
        /* request updates to be done... */
-       ED_area_tag_redraw(C->area);
-       UI_view2d_sync(C->screen, v2d, V2D_LOCK_COPY);
+       ED_area_tag_redraw(CTX_wm_area(C));
+       UI_view2d_sync(CTX_wm_screen(C), v2d, V2D_LOCK_COPY);
 }
 
 /* cleanup temp customdata  */
@@ -673,6 +676,7 @@ static int view_zoomdrag_exec(bContext *C, wmOperator *op)
 /* set up modal operator and relevant settings */
 static int view_zoomdrag_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
+       wmWindow *window= CTX_wm_window(C);
        v2dViewZoomData *vzd;
        View2D *v2d;
        
@@ -690,14 +694,14 @@ static int view_zoomdrag_invoke(bContext *C, wmOperator *op, wmEvent *event)
        RNA_float_set(op->ptr, "deltay", 0);
        
        if (v2d->keepofs & V2D_LOCKOFS_X)
-               WM_cursor_modal(C->window, BC_NS_SCROLLCURSOR);
+               WM_cursor_modal(window, BC_NS_SCROLLCURSOR);
        else if (v2d->keepofs & V2D_LOCKOFS_Y)
-               WM_cursor_modal(C->window, BC_EW_SCROLLCURSOR);
+               WM_cursor_modal(window, BC_EW_SCROLLCURSOR);
        else
-               WM_cursor_modal(C->window, BC_NSEW_SCROLLCURSOR);
+               WM_cursor_modal(window, BC_NSEW_SCROLLCURSOR);
        
        /* add temp handler */
-       WM_event_add_modal_handler(C, &C->window->handlers, op);
+       WM_event_add_modal_handler(C, &window->handlers, op);
 
        return OPERATOR_RUNNING_MODAL;
 }
@@ -782,7 +786,7 @@ static int view_zoomdrag_modal(bContext *C, wmOperator *op, wmEvent *event)
                                
                                /* free customdata */
                                view_zoomdrag_exit(C, op);
-                               WM_cursor_restore(C->window);
+                               WM_cursor_restore(CTX_wm_window(C));
                                
                                return OPERATOR_FINISHED;
                        }
@@ -916,7 +920,7 @@ static void scroller_activate_init(bContext *C, wmOperator *op, wmEvent *event,
 {
        v2dScrollerMove *vsm;
        View2DScrollers *scrollers;
-       ARegion *ar= C->region;
+       ARegion *ar= CTX_wm_region(C);
        View2D *v2d= &ar->v2d;
        float mask_size;
        int x, y;
@@ -1026,8 +1030,8 @@ static void scroller_activate_apply(bContext *C, wmOperator *op)
        UI_view2d_curRect_validate(v2d);
        
        /* request updates to be done... */
-       ED_area_tag_redraw(C->area);
-       UI_view2d_sync(C->screen, v2d, V2D_LOCK_COPY);
+       ED_area_tag_redraw(CTX_wm_area(C));
+       UI_view2d_sync(CTX_wm_screen(C), v2d, V2D_LOCK_COPY);
 }
 
 /* handle user input for scrollers - calculations of mouse-movement need to be done here, not in the apply callback! */
@@ -1086,15 +1090,16 @@ static int scroller_activate_modal(bContext *C, wmOperator *op, wmEvent *event)
 /* a click (or click drag in progress) should have occurred, so check if it happened in scrollbar */
 static int scroller_activate_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
+       ARegion *ar= CTX_wm_region(C);
        View2D *v2d= NULL;
        short in_scroller= 0;
        
        /* firstly, check context to see if mouse is actually in region */
        // XXX isn't this the job of poll() callbacks which can't check events, but only context?
-       if (C->region == NULL) 
+       if (ar == NULL) 
                return OPERATOR_CANCELLED;
        else
-               v2d= &C->region->v2d;
+               v2d= &ar->v2d;
                
        /* check if mouse in scrollbars, if they're enabled */
        in_scroller= mouse_in_v2d_scrollers(C, v2d, event->x, event->y);
@@ -1121,7 +1126,7 @@ static int scroller_activate_invoke(bContext *C, wmOperator *op, wmEvent *event)
                }
                
                /* still ok, so can add */
-               WM_event_add_modal_handler(C, &C->window->handlers, op);
+               WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
                return OPERATOR_RUNNING_MODAL;
        }
        else {
index 35b7f21910a8a741f38ea1005e780d1c9bb4ad42..27f70353e39042d536844af0db67e1eccbafb1f1 100644 (file)
@@ -35,7 +35,7 @@
 #include "BLI_arithb.h"
 #include "BLI_rand.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 #include "BKE_utildefines.h"
 
@@ -95,11 +95,12 @@ static void region_draw_emboss(ARegion *ar)
 
 void ED_region_pixelspace(const bContext *C, ARegion *ar)
 {
+       wmWindow *win= CTX_wm_window(C);
        int width= ar->winrct.xmax-ar->winrct.xmin+1;
        int height= ar->winrct.ymax-ar->winrct.ymin+1;
        
-       wmOrtho2(C->window, -0.375, (float)width-0.375, -0.375, (float)height-0.375);
-       wmLoadIdentity(C->window);      
+       wmOrtho2(win, -0.375, (float)width-0.375, -0.375, (float)height-0.375);
+       wmLoadIdentity(win);
 }
 
 void ED_region_do_listen(ARegion *ar, wmNotifier *note)
@@ -122,7 +123,7 @@ void ED_area_overdraw_flush(bContext *C)
 {
        ScrArea *sa;
        
-       for(sa= C->screen->areabase.first; sa; sa= sa->next) {
+       for(sa= CTX_wm_screen(C)->areabase.first; sa; sa= sa->next) {
                ARegion *ar;
                
                for(ar= sa->regionbase.first; ar; ar= ar->next) {
@@ -144,15 +145,17 @@ void ED_area_overdraw_flush(bContext *C)
 
 void ED_area_overdraw(bContext *C)
 {
+       wmWindow *win= CTX_wm_window(C);
+       bScreen *screen= CTX_wm_screen(C);
        ScrArea *sa;
        
        /* Draw AZones, in screenspace */
-       wm_subwindow_set(C->window, C->window->screen->mainwin);
+       wm_subwindow_set(win, screen->mainwin);
 
        glEnable( GL_BLEND );
        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
        
-       for(sa= C->screen->areabase.first; sa; sa= sa->next) {
+       for(sa= screen->areabase.first; sa; sa= sa->next) {
                AZone *az;
                for(az= sa->actionzones.first; az; az= az->next) {
                        if(az->do_draw) {
@@ -170,12 +173,14 @@ void ED_area_overdraw(bContext *C)
 
 void ED_region_do_draw(bContext *C, ARegion *ar)
 {
+       wmWindow *win= CTX_wm_window(C);
+       ScrArea *sa= CTX_wm_area(C);
        ARegionType *at= ar->type;
        
-       wm_subwindow_set(C->window, ar->swinid);
+       wm_subwindow_set(win, ar->swinid);
        
        if(ar->swinid && at->draw) {
-               UI_SetTheme(C->area);
+               UI_SetTheme(sa);
                at->draw(C, ar);
                UI_SetTheme(NULL);
        }
@@ -193,7 +198,7 @@ void ED_region_do_draw(bContext *C, ARegion *ar)
                glRecti(20,  2,  30,  12);
        }
 
-       if(C->area)
+       if(sa)
                region_draw_emboss(ar);
        
        /* XXX test: add convention to end regions always in pixel space, for drawing of borders/gestures etc */
@@ -476,7 +481,7 @@ void ED_region_init(bContext *C, ARegion *ar)
 //     ARegionType *at= ar->type;
        
        /* refresh can be called before window opened */
-       region_subwindow(C->wm, C->window, ar);
+       region_subwindow(CTX_wm_manager(C), CTX_wm_window(C), ar);
        
 }
 
@@ -593,7 +598,7 @@ void area_newspace(bContext *C, ScrArea *sa, int type)
                        }
                }
                
-               ED_area_initialize(C->wm, C->window, sa);
+               ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
                
                /* tell WM to refresh, cursor types etc */
                WM_event_add_mousemove(C);
@@ -640,13 +645,14 @@ static char *windowtype_pup(void)
 
 static void spacefunc(struct bContext *C, void *arg1, void *arg2)
 {
-       area_newspace(C, C->area, C->area->butspacetype);
-       ED_area_tag_redraw(C->area);
+       area_newspace(C, CTX_wm_area(C), CTX_wm_area(C)->butspacetype);
+       ED_area_tag_redraw(CTX_wm_area(C));
 }
 
 /* returns offset for next button in header */
 int ED_area_header_standardbuttons(const bContext *C, uiBlock *block, int yco)
 {
+       ScrArea *sa= CTX_wm_area(C);
        uiBut *but;
        int xco= 8;
        
@@ -655,7 +661,7 @@ int ED_area_header_standardbuttons(const bContext *C, uiBlock *block, int yco)
        
        but= uiDefIconTextButC(block, ICONTEXTROW, 0, ICON_VIEW3D, 
                                                   windowtype_pup(), xco, yco, XIC+10, YIC, 
-                                                  &(C->area->butspacetype), 1.0, SPACEICONMAX, 0, 0, 
+                                                  &(sa->butspacetype), 1.0, SPACEICONMAX, 0, 0, 
                                                   "Displays Current Window Type. "
                                                   "Click for menu of available types.");
        uiButSetFunc(but, spacefunc, NULL, NULL);
@@ -663,18 +669,18 @@ int ED_area_header_standardbuttons(const bContext *C, uiBlock *block, int yco)
        xco += XIC + 14;
        
        uiBlockSetEmboss(block, UI_EMBOSSN);
-       if (C->area->flag & HEADER_NO_PULLDOWN) {
+       if (sa->flag & HEADER_NO_PULLDOWN) {
                uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0, 
                                                 ICON_DISCLOSURE_TRI_RIGHT,
                                                 xco,yco,XIC,YIC-2,
-                                                &(C->area->flag), 0, 0, 0, 0, 
+                                                &(sa->flag), 0, 0, 0, 0, 
                                                 "Show pulldown menus");
        }
        else {
                uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, 0, 
                                                 ICON_DISCLOSURE_TRI_DOWN,
                                                 xco,yco,XIC,YIC-2,
-                                                &(C->area->flag), 0, 0, 0, 0, 
+                                                &(sa->flag), 0, 0, 0, 0, 
                                                 "Hide pulldown menus");
        }
        xco+=XIC;
index fbcd27cf263af3db5c3271743cc87b85e571943d..b88290bd64ebd8f28d6fbc68575b573343fcb381 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "BLI_blenlib.h"
 
+#include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
@@ -1015,33 +1016,33 @@ void ED_screens_initialize(wmWindowManager *wm)
 
 void ED_region_exit(bContext *C, ARegion *ar)
 {
-       ARegion *prevar= C->region;
+       ARegion *prevar= CTX_wm_region(C);
 
-       C->region= ar;
+       CTX_wm_region_set(C, ar);
        WM_event_remove_handlers(C, &ar->handlers);
-       C->region= prevar;
+       CTX_wm_region_set(C, prevar);
 }
 
 void ED_area_exit(bContext *C, ScrArea *sa)
 {
-       ScrArea *prevsa= C->area;
+       ScrArea *prevsa= CTX_wm_area(C);
        ARegion *ar;
 
-       C->area= sa;
+       CTX_wm_area_set(C, sa);
        for(ar= sa->regionbase.first; ar; ar= ar->next)
                ED_region_exit(C, ar);
 
        WM_event_remove_handlers(C, &sa->handlers);
-       C->area= prevsa;
+       CTX_wm_area_set(C, prevsa);
 }
 
 void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
 {
-       wmWindow *prevwin= C?C->window:NULL;
+       wmWindow *prevwin= CTX_wm_window(C);
        ScrArea *sa;
        ARegion *ar;
 
-       C->window= window;
+       CTX_wm_window_set(C, window);
        
        for(ar= screen->regionbase.first; ar; ar= ar->next)
                ED_region_exit(C, ar);
@@ -1049,7 +1050,7 @@ void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
        for(sa= screen->areabase.first; sa; sa= sa->next)
                ED_area_exit(C, sa);
 
-       C->window= prevwin;
+       CTX_wm_window_set(C, prevwin);
 }
 
 /* case when on area-edge or in azones, or outside window */
@@ -1144,11 +1145,13 @@ void ED_screen_set_subwinactive(wmWindow *win, wmEvent *event)
 
 int ED_screen_area_active(const bContext *C)
 {
+       bScreen *sc= CTX_wm_screen(C);
+       ScrArea *sa= CTX_wm_area(C);
 
-       if(C->screen && C->area) {
+       if(sc && sa) {
                ARegion *ar;
-               for(ar= C->area->regionbase.first; ar; ar= ar->next)
-                       if(ar->swinid == C->screen->subwinactive)
+               for(ar= sa->regionbase.first; ar; ar= ar->next)
+                       if(ar->swinid == sc->subwinactive)
                                return 1;
        }       
        return 0;
@@ -1158,7 +1161,6 @@ int ED_screen_area_active(const bContext *C)
 /* Do NOT call in area/region queues! */
 void ed_screen_set(bContext *C, bScreen *sc)
 {
-       
        if(sc->full) {                          /* find associated full */
                bScreen *sc1;
                for(sc1= G.main->screen.first; sc1; sc1= sc1->id.next) {
@@ -1171,12 +1173,11 @@ void ed_screen_set(bContext *C, bScreen *sc)
                if(sc1==NULL) printf("set screen error\n");
        }
        
-       if (C->screen != sc) {
-               ED_screen_exit(C, C->window, C->screen);
-               C->window->screen= sc;
-               C->screen= sc;
+       if (CTX_wm_screen(C) != sc) {
+               ED_screen_exit(C, CTX_wm_window(C), CTX_wm_screen(C));
+               CTX_wm_window(C)->screen= sc;
                
-               ED_screen_refresh(C->wm, C->window);
+               ED_screen_refresh(CTX_wm_manager(C), CTX_wm_window(C));
                WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
        }
 }
@@ -1188,9 +1189,9 @@ void ed_screen_fullarea(bContext *C)
        ScrArea *newa, *old;
        short fulltype;
        
-       if(C->area->full) {
-               sc= C->area->full;              /* the old screen to restore */
-               oldscreen= C->screen;   /* the one disappearing */
+       if(CTX_wm_area(C)->full) {
+               sc= CTX_wm_area(C)->full;               /* the old screen to restore */
+               oldscreen= CTX_wm_screen(C);    /* the one disappearing */
                
                fulltype = sc->full;
                
@@ -1211,7 +1212,7 @@ void ed_screen_fullarea(bContext *C)
                                // in autoplay screens the headers are disabled by 
                                // default. So use the old headertype instead
                        
-                       area_copy_data(old, C->area, 1);        /*  1 = swap spacelist */
+                       area_copy_data(old, CTX_wm_area(C), 1); /*  1 = swap spacelist */
                        
                        old->full= NULL;
                        
@@ -1222,33 +1223,33 @@ void ed_screen_fullarea(bContext *C)
                }
        }
        else {
+               oldscreen= CTX_wm_screen(C);
+
                /* is there only 1 area? */
-               if(C->screen->areabase.first==C->screen->areabase.last) return;
-               if(C->area->spacetype==SPACE_INFO) return;
+               if(oldscreen->areabase.first==CTX_wm_screen(C)->areabase.last) return;
+               if(CTX_wm_area(C)->spacetype==SPACE_INFO) return;
                
-               C->screen->full = SCREENFULL;
+               oldscreen->full = SCREENFULL;
                
-               oldscreen= C->screen;
-               sc= screen_add(C->window, "temp");
+               sc= screen_add(CTX_wm_window(C), "temp");
                
                /* returns the top small area */
-               newa= area_split(C->window, sc, (ScrArea *)sc->areabase.first, 'h', 0.99f);
+               newa= area_split(CTX_wm_window(C), sc, (ScrArea *)sc->areabase.first, 'h', 0.99f);
                area_newspace(C, newa, SPACE_INFO);
 
                /* copy area */
                newa= newa->prev;
-               area_copy_data(newa, C->area, 1);       /* 1 = swap spacelist */
+               area_copy_data(newa, CTX_wm_area(C), 1);        /* 1 = swap spacelist */
 
-               C->area->full= oldscreen;
+               CTX_wm_area(C)->full= oldscreen;
                newa->full= oldscreen;
                newa->next->full= oldscreen;
 
-               C->screen= oldscreen;
                ed_screen_set(C, sc);
        }
 
        /* XXX bad code: setscreen() ends with first area active. fullscreen render assumes this too */
-       C->area= sc->areabase.first;
+       CTX_wm_area_set(C, sc->areabase.first);
 
        /* XXX retopo_force_update(); */
 
index c4011550a0707a03fceea0157956ae500f58d273..4514d54e317cf51dbe330a325b3b1b349da5ee30 100644 (file)
@@ -29,7 +29,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_arithb.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_screen.h"
 
 int ED_operator_areaactive(bContext *C)
 {
-       if(C->window==NULL) return 0;
-       if(C->screen==NULL) return 0;
-       if(C->area==NULL) return 0;
+       if(CTX_wm_window(C)==NULL) return 0;
+       if(CTX_wm_screen(C)==NULL) return 0;
+       if(CTX_wm_area(C)==NULL) return 0;
        return 1;
 }
 
 int ED_operator_screenactive(bContext *C)
 {
-       if(C->window==NULL) return 0;
-       if(C->screen==NULL) return 0;
+       if(CTX_wm_window(C)==NULL) return 0;
+       if(CTX_wm_screen(C)==NULL) return 0;
        return 1;
 }
 
 /* when mouse is over area-edge */
 int ED_operator_screen_mainwinactive(bContext *C)
 {
-       if(C->window==NULL) return 0;
-       if(C->screen==NULL) return 0;
-       if (C->screen->subwinactive!=C->screen->mainwin) return 0;
+       if(CTX_wm_window(C)==NULL) return 0;
+       if(CTX_wm_screen(C)==NULL) return 0;
+       if (CTX_wm_screen(C)->subwinactive!=CTX_wm_screen(C)->mainwin) return 0;
        return 1;
 }
 
@@ -141,7 +141,7 @@ AZone *is_in_area_actionzone(ScrArea *sa, int x, int y)
 
 static int actionzone_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
-       AZone *az= is_in_area_actionzone(C->area, event->x, event->y);
+       AZone *az= is_in_area_actionzone(CTX_wm_area(C), event->x, event->y);
        sActionzoneData *sad;
        
        /* quick escape */
@@ -150,12 +150,12 @@ static int actionzone_invoke(bContext *C, wmOperator *op, wmEvent *event)
        
        /* ok we do the actionzone */
        sad= op->customdata= MEM_callocN(sizeof(sActionzoneData), "sActionzoneData");
-       sad->sa1= C->area;
+       sad->sa1= CTX_wm_area(C);
        sad->az= az;
        sad->x= event->x; sad->y= event->y;
        
        /* add modal handler */
-       WM_event_add_modal_handler(C, &C->window->handlers, op);
+       WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
        
        return OPERATOR_RUNNING_MODAL;
 }
@@ -171,14 +171,15 @@ static void actionzone_exit(bContext *C, wmOperator *op)
 static void actionzone_apply(bContext *C, wmOperator *op)
 {
        wmEvent event;
+       wmWindow *win= CTX_wm_window(C);
        
-       event= *(C->window->eventstate);        /* XXX huh huh? make api call */
+       event= *(win->eventstate);      /* XXX huh huh? make api call */
        event.type= EVT_ACTIONZONE;
        event.customdata= op->customdata;
        event.customdatafree= TRUE;
        op->customdata= NULL;
        
-       wm_event_add(C->window, &event);
+       wm_event_add(win, &event);
 }
 
 static int actionzone_modal(bContext *C, wmOperator *op, wmEvent *event)
@@ -205,7 +206,7 @@ static int actionzone_modal(bContext *C, wmOperator *op, wmEvent *event)
                        if(ABS(deltax) > 12 || ABS(deltay) > 12) {
                                
                                /* second area, for join */
-                               sad->sa2= screen_areahascursor(C->screen, event->x, event->y);
+                               sad->sa2= screen_areahascursor(CTX_wm_screen(C), event->x, event->y);
                                /* apply sends event */
                                actionzone_apply(C, op);
                                actionzone_exit(C, op);
@@ -243,25 +244,30 @@ void ED_SCR_OT_actionzone(wmOperatorType *ot)
 conventions: 'atomic' and 'dont think for user' :) */
 static int screen_area_rip_op(bContext *C, wmOperator *op)
 {
-       wmWindow *win;
-       bScreen *newsc;
+       wmWindow *newwin, *win;
+       bScreen *newsc, *sc;
+       ScrArea *sa;
        rcti rect;
        
+       win= CTX_wm_window(C);
+       sc= CTX_wm_screen(C);
+       sa= CTX_wm_area(C);
+
        /*  poll() checks area context, but we don't accept full-area windows */
-       if(C->screen->full != SCREENNORMAL) 
+       if(sc->full != SCREENNORMAL) 
                return OPERATOR_CANCELLED;
        
        /* adds window to WM */
-       rect= C->area->totrct;
-       BLI_translate_rcti(&rect, C->window->posx, C->window->posy);
-       win= WM_window_open(C, &rect);
+       rect= sa->totrct;
+       BLI_translate_rcti(&rect, win->posx, win->posy);
+       newwin= WM_window_open(C, &rect);
        
        /* allocs new screen and adds to newly created window, using window size */
-       newsc= screen_add(win, C->screen->id.name+2);
+       newsc= screen_add(newwin, sc->id.name+2);
        win->screen= newsc;
        
        /* copy area to new screen */
-       area_copy_data((ScrArea *)newsc->areabase.first, C->area, 0);
+       area_copy_data((ScrArea *)newsc->areabase.first, sa, 0);
        
        /* screen, areas init */
        WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
@@ -350,6 +356,7 @@ static void area_move_set_limits(bScreen *sc, int dir, int *bigger, int *smaller
 /* return 0: init failed */
 static int area_move_init (bContext *C, wmOperator *op)
 {
+       bScreen *sc= CTX_wm_screen(C);
        ScrEdge *actedge;
        sAreaMoveData *md;
        int x, y;
@@ -359,7 +366,7 @@ static int area_move_init (bContext *C, wmOperator *op)
        y= RNA_int_get(op->ptr, "y");
 
        /* setup */
-       actedge= screen_find_active_scredge(C->screen, x, y);
+       actedge= screen_find_active_scredge(sc, x, y);
        if(actedge==NULL) return 0;
 
        md= MEM_callocN(sizeof(sAreaMoveData), "sAreaMoveData");
@@ -369,10 +376,10 @@ static int area_move_init (bContext *C, wmOperator *op)
        if(md->dir=='h') md->origval= actedge->v1->vec.y;
        else md->origval= actedge->v1->vec.x;
        
-       select_connected_scredge(C->screen, actedge);
+       select_connected_scredge(sc, actedge);
        /* now all vertices with 'flag==1' are the ones that can be moved. */
 
-       area_move_set_limits(C->screen, md->dir, &md->bigger, &md->smaller);
+       area_move_set_limits(sc, md->dir, &md->bigger, &md->smaller);
        
        return 1;
 }
@@ -380,26 +387,28 @@ static int area_move_init (bContext *C, wmOperator *op)
 /* moves selected screen edge amount of delta, used by split & move */
 static void area_move_apply_do(bContext *C, int origval, int delta, int dir, int bigger, int smaller)
 {
+       wmWindow *win= CTX_wm_window(C);
+       bScreen *sc= CTX_wm_screen(C);
        ScrVert *v1;
        
        delta= CLAMPIS(delta, -smaller, bigger);
        
-       for (v1= C->screen->vertbase.first; v1; v1= v1->next) {
+       for (v1= sc->vertbase.first; v1; v1= v1->next) {
                if (v1->flag) {
                        /* that way a nice AREAGRID  */
-                       if((dir=='v') && v1->vec.x>0 && v1->vec.x<C->window->sizex-1) {
+                       if((dir=='v') && v1->vec.x>0 && v1->vec.x<win->sizex-1) {
                                v1->vec.x= origval + delta;
                                if(delta != bigger && delta != -smaller) v1->vec.x-= (v1->vec.x % AREAGRID);
                        }
-                       if((dir=='h') && v1->vec.y>0 && v1->vec.y<C->window->sizey-1) {
+                       if((dir=='h') && v1->vec.y>0 && v1->vec.y<win->sizey-1) {
                                v1->vec.y= origval + delta;
 
                                v1->vec.y+= AREAGRID-1;
                                v1->vec.y-= (v1->vec.y % AREAGRID);
                                
                                /* prevent too small top header */
-                               if(v1->vec.y > C->window->sizey-AREAMINY)
-                                       v1->vec.y= C->window->sizey-AREAMINY;
+                               if(v1->vec.y > win->sizey-AREAMINY)
+                                       v1->vec.y= win->sizey-AREAMINY;
                        }
                }
        }
@@ -423,8 +432,8 @@ static void area_move_exit(bContext *C, wmOperator *op)
        op->customdata= NULL;
        
        /* this makes sure aligned edges will result in aligned grabbing */
-       removedouble_scrverts(C->screen);
-       removedouble_scredges(C->screen);
+       removedouble_scrverts(CTX_wm_screen(C));
+       removedouble_scredges(CTX_wm_screen(C));
 }
 
 static int area_move_exec(bContext *C, wmOperator *op)
@@ -448,7 +457,7 @@ static int area_move_invoke(bContext *C, wmOperator *op, wmEvent *event)
                return OPERATOR_PASS_THROUGH;
        
        /* add temp handler */
-       WM_event_add_modal_handler(C, &C->window->handlers, op);
+       WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
        
        return OPERATOR_RUNNING_MODAL;
 }
@@ -575,26 +584,27 @@ typedef struct sAreaSplitData
 /* generic init, no UI stuff here */
 static int area_split_init(bContext *C, wmOperator *op)
 {
+       ScrArea *sa= CTX_wm_area(C);
        sAreaSplitData *sd;
        int dir;
        
        /* required context */
-       if(C->area==NULL) return 0;
+       if(sa==NULL) return 0;
        
        /* required properties */
        dir= RNA_enum_get(op->ptr, "dir");
        
        /* minimal size */
-       if(dir=='v' && C->area->winx < 2*AREAMINX) return 0;
-       if(dir=='h' && C->area->winy < 2*AREAMINY) return 0;
+       if(dir=='v' && sa->winx < 2*AREAMINX) return 0;
+       if(dir=='h' && sa->winy < 2*AREAMINY) return 0;
           
        /* custom data */
        sd= (sAreaSplitData*)MEM_callocN(sizeof (sAreaSplitData), "op_area_split");
        op->customdata= sd;
        
-       sd->sarea= C->area;
-       sd->origsize= dir=='v' ? C->area->winx:C->area->winy;
-       sd->origmin = dir=='v' ? C->area->totrct.xmin:C->area->totrct.ymin;
+       sd->sarea= sa;
+       sd->origsize= dir=='v' ? sa->winx:sa->winy;
+       sd->origmin = dir=='v' ? sa->totrct.xmin:sa->totrct.ymin;
        
        return 1;
 }
@@ -632,6 +642,7 @@ static ScrEdge *area_findsharededge(bScreen *screen, ScrArea *sa, ScrArea *sb)
 /* do the split, return success */
 static int area_split_apply(bContext *C, wmOperator *op)
 {
+       bScreen *sc= CTX_wm_screen(C);
        sAreaSplitData *sd= (sAreaSplitData *)op->customdata;
        float fac;
        int dir;
@@ -639,15 +650,15 @@ static int area_split_apply(bContext *C, wmOperator *op)
        fac= RNA_float_get(op->ptr, "fac");
        dir= RNA_enum_get(op->ptr, "dir");
 
-       sd->narea= area_split(C->window, C->screen, sd->sarea, dir, fac);
+       sd->narea= area_split(CTX_wm_window(C), sc, sd->sarea, dir, fac);
        
        if(sd->narea) {
                ScrVert *sv;
                
-               sd->nedge= area_findsharededge(C->screen, sd->sarea, sd->narea);
+               sd->nedge= area_findsharededge(sc, sd->sarea, sd->narea);
        
                /* select newly created edge, prepare for moving edge */
-               for(sv= C->screen->vertbase.first; sv; sv= sv->next)
+               for(sv= sc->vertbase.first; sv; sv= sv->next)
                        sv->flag = 0;
                
                sd->nedge->v1->flag= 1;
@@ -674,8 +685,8 @@ static void area_split_exit(bContext *C, wmOperator *op)
        WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
 
        /* this makes sure aligned edges will result in aligned grabbing */
-       removedouble_scrverts(C->screen);
-       removedouble_scredges(C->screen);
+       removedouble_scrverts(CTX_wm_screen(C));
+       removedouble_scredges(CTX_wm_screen(C));
 }
 
 
@@ -693,7 +704,7 @@ static int area_split_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        return OPERATOR_PASS_THROUGH;
                
                /* is this our *sad? if areas not equal it should be passed on */
-               if(C->area!=sad->sa1 || sad->sa1!=sad->sa2)
+               if(CTX_wm_area(C)!=sad->sa1 || sad->sa1!=sad->sa2)
                        return OPERATOR_PASS_THROUGH;
                
                /* prepare operator state vars */
@@ -718,10 +729,10 @@ static int area_split_invoke(bContext *C, wmOperator *op, wmEvent *event)
                
                /* do the split */
                if(area_split_apply(C, op)) {
-                       area_move_set_limits(C->screen, dir, &sd->bigger, &sd->smaller);
+                       area_move_set_limits(CTX_wm_screen(C), dir, &sd->bigger, &sd->smaller);
                        
                        /* add temp handler for edge move or cancel */
-                       WM_event_add_modal_handler(C, &C->window->handlers, op);
+                       WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
                        
                        return OPERATOR_RUNNING_MODAL;
                }
@@ -753,9 +764,9 @@ static int area_split_cancel(bContext *C, wmOperator *op)
 {
        sAreaSplitData *sd= (sAreaSplitData *)op->customdata;
 
-       if (screen_area_join(C, C->screen, sd->sarea, sd->narea)) {
-               if (C->area == sd->narea) {
-                       C->area = NULL;
+       if (screen_area_join(C, CTX_wm_screen(C), sd->sarea, sd->narea)) {
+               if (CTX_wm_area(C) == sd->narea) {
+                       CTX_wm_area_set(C, NULL);
                }
                sd->narea = NULL;
        }
@@ -837,7 +848,7 @@ static int frame_offset_exec(bContext *C, wmOperator *op)
 
        delta = RNA_int_get(op->ptr, "delta");
 
-       C->scene->r.cfra += delta;
+       CTX_data_scene(C)->r.cfra += delta;
        WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
        /* XXX: add WM_NOTE_TIME_CHANGED? */
 
@@ -864,20 +875,20 @@ void ED_SCR_OT_frame_offset(wmOperatorType *ot)
 /* function to be called outside UI context, or for redo */
 static int screen_set_exec(bContext *C, wmOperator *op)
 {
-       bScreen *screen= C->screen;
+       bScreen *screen= CTX_wm_screen(C);
        int delta= RNA_int_get(op->ptr, "delta");
        
        /* this screen is 'fake', solve later XXX */
-       if(C->area->full)
+       if(CTX_wm_area(C)->full)
                return OPERATOR_CANCELLED;
        
        if(delta==1) {
                screen= screen->id.next;
-               if(screen==NULL) screen= G.main->screen.first;
+               if(screen==NULL) screen= CTX_data_main(C)->screen.first;
        }
        else if(delta== -1) {
                screen= screen->id.prev;
-               if(screen==NULL) screen= G.main->screen.last;
+               if(screen==NULL) screen= CTX_data_main(C)->screen.last;
        }
        else {
                screen= NULL;
@@ -979,8 +990,8 @@ static int area_join_init(bContext *C, wmOperator *op)
        x2= RNA_int_get(op->ptr, "x2");
        y2= RNA_int_get(op->ptr, "y2");
        
-       sa1 = screen_areahascursor(C->screen, x1, y1);
-       sa2 = screen_areahascursor(C->screen, x2, y2);
+       sa1 = screen_areahascursor(CTX_wm_screen(C), x1, y1);
+       sa2 = screen_areahascursor(CTX_wm_screen(C), x2, y2);
        if(sa1==NULL || sa2==NULL || sa1==sa2)
                return 0;
 
@@ -1002,11 +1013,11 @@ static int area_join_apply(bContext *C, wmOperator *op)
        sAreaJoinData *jd = (sAreaJoinData *)op->customdata;
        if (!jd) return 0;
 
-       if(!screen_area_join(C, C->screen, jd->sa1, jd->sa2)){
+       if(!screen_area_join(C, CTX_wm_screen(C), jd->sa1, jd->sa2)){
                return 0;
        }
-       if (C->area == jd->sa2) {
-               C->area = NULL;
+       if (CTX_wm_area(C) == jd->sa2) {
+               CTX_wm_area_set(C, NULL);
        }
 
        return 1;
@@ -1021,9 +1032,9 @@ static void area_join_exit(bContext *C, wmOperator *op)
        }
 
        /* this makes sure aligned edges will result in aligned grabbing */
-       removedouble_scredges(C->screen);
-       removenotused_scredges(C->screen);
-       removenotused_scrverts(C->screen);
+       removedouble_scredges(CTX_wm_screen(C));
+       removenotused_scredges(CTX_wm_screen(C));
+       removenotused_scrverts(CTX_wm_screen(C));
 }
 
 static int area_join_exec(bContext *C, wmOperator *op)
@@ -1062,7 +1073,7 @@ static int area_join_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        return OPERATOR_PASS_THROUGH;
        
                /* add temp handler */
-               WM_event_add_modal_handler(C, &C->window->handlers, op);
+               WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
        
                return OPERATOR_RUNNING_MODAL;
        }
@@ -1093,6 +1104,7 @@ static int area_join_cancel(bContext *C, wmOperator *op)
 /* modal callback while selecting area (space) that will be removed */
 static int area_join_modal(bContext *C, wmOperator *op, wmEvent *event)
 {
+       bScreen *sc= CTX_wm_screen(C);
        sAreaJoinData *jd = (sAreaJoinData *)op->customdata;
        
        /* execute the events */
@@ -1100,12 +1112,12 @@ static int area_join_modal(bContext *C, wmOperator *op, wmEvent *event)
                        
                case MOUSEMOVE: 
                        {
-                               ScrArea *sa = screen_areahascursor(C->screen, event->x, event->y);
+                               ScrArea *sa = screen_areahascursor(sc, event->x, event->y);
                                int dir;
                                
                                if (sa) {                                       
                                        if (jd->sa1 != sa) {
-                                               dir = area_getorientation(C->screen, jd->sa1, sa);
+                                               dir = area_getorientation(sc, jd->sa1, sa);
                                                if (dir >= 0) {
                                                        if (jd->sa2) jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
                                                        jd->sa2 = sa;
@@ -1116,7 +1128,7 @@ static int area_join_modal(bContext *C, wmOperator *op, wmEvent *event)
                                                           we check if area has common border with the one marked for removal
                                                           in this case we can swap areas.
                                                        */
-                                                       dir = area_getorientation(C->screen, sa, jd->sa2);
+                                                       dir = area_getorientation(sc, sa, jd->sa2);
                                                        if (dir >= 0) {
                                                                if (jd->sa1) jd->sa1->flag &= ~AREA_FLAG_DRAWJOINFROM;
                                                                if (jd->sa2) jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
@@ -1142,13 +1154,13 @@ static int area_join_modal(bContext *C, wmOperator *op, wmEvent *event)
                                                        jd->sa2 = sa;
                                                        if (jd->sa1) jd->sa1->flag |= AREA_FLAG_DRAWJOINFROM;
                                                        if (jd->sa2) jd->sa2->flag |= AREA_FLAG_DRAWJOINTO;
-                                                       dir = area_getorientation(C->screen, jd->sa1, jd->sa2);
+                                                       dir = area_getorientation(sc, jd->sa1, jd->sa2);
                                                        if (dir < 0) {
                                                                printf("oops, didn't expect that!\n");
                                                        }
                                                } 
                                                else {
-                                                       dir = area_getorientation(C->screen, jd->sa1, sa);
+                                                       dir = area_getorientation(sc, jd->sa1, sa);
                                                        if (dir >= 0) {
                                                                if (jd->sa2) jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
                                                                jd->sa2 = sa;
@@ -1207,7 +1219,7 @@ void ED_SCR_OT_area_join(wmOperatorType *ot)
 
 static int repeat_last_exec(bContext *C, wmOperator *op)
 {
-       wmOperator *lastop= C->wm->operators.last;
+       wmOperator *lastop= CTX_wm_manager(C)->operators.last;
        
        if(lastop) {
                printf("repeat %s\n", lastop->type->idname);
@@ -1236,17 +1248,19 @@ void ED_SCR_OT_repeat_last(wmOperatorType *ot)
 /* insert a region in the area region list */
 static int region_split_exec(bContext *C, wmOperator *op)
 {
-       ARegion *newar= BKE_area_region_copy(C->region);
+       ScrArea *sa= CTX_wm_area(C);
+       ARegion *ar= CTX_wm_region(C);
+       ARegion *newar= BKE_area_region_copy(ar);
        int dir= RNA_enum_get(op->ptr, "dir");
        
-       BLI_insertlinkafter(&C->area->regionbase, C->region, newar);
+       BLI_insertlinkafter(&sa->regionbase, CTX_wm_region(C), newar);
        
-       newar->alignment= C->region->alignment;
+       newar->alignment= ar->alignment;
        
        if(dir=='h')
-               C->region->alignment= RGN_ALIGN_HSPLIT;
+               ar->alignment= RGN_ALIGN_HSPLIT;
        else
-               C->region->alignment= RGN_ALIGN_VSPLIT;
+               ar->alignment= RGN_ALIGN_VSPLIT;
        
        WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
        
@@ -1276,14 +1290,16 @@ void ED_SCR_OT_region_split(wmOperatorType *ot)
 /* flip a region alignment */
 static int region_flip_exec(bContext *C, wmOperator *op)
 {
-       if(C->region->alignment==RGN_ALIGN_TOP)
-               C->region->alignment= RGN_ALIGN_BOTTOM;
-       else if(C->region->alignment==RGN_ALIGN_BOTTOM)
-               C->region->alignment= RGN_ALIGN_TOP;
-       else if(C->region->alignment==RGN_ALIGN_LEFT)
-               C->region->alignment= RGN_ALIGN_RIGHT;
-       else if(C->region->alignment==RGN_ALIGN_RIGHT)
-               C->region->alignment= RGN_ALIGN_LEFT;
+       ARegion *ar= CTX_wm_region(C);
+
+       if(ar->alignment==RGN_ALIGN_TOP)
+               ar->alignment= RGN_ALIGN_BOTTOM;
+       else if(ar->alignment==RGN_ALIGN_BOTTOM)
+               ar->alignment= RGN_ALIGN_TOP;
+       else if(ar->alignment==RGN_ALIGN_LEFT)
+               ar->alignment= RGN_ALIGN_RIGHT;
+       else if(ar->alignment==RGN_ALIGN_RIGHT)
+               ar->alignment= RGN_ALIGN_LEFT;
        
        WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
        
index beca0f077488506d64b77493a5de390405d3a6b2..fc0299b0851dec43815f2da2a6f85801accea5d0 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "BLI_blenlib.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_screen.h"
@@ -66,7 +66,7 @@ static void do_viewmenu(bContext *C, void *arg, int event)
 
 static uiBlock *dummy_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
-       ScrArea *curarea= C->area;
+       ScrArea *curarea= CTX_wm_area(C);
        uiBlock *block;
        short yco= 0, menuwidth=120;
        
@@ -99,7 +99,7 @@ static void do_action_buttons(bContext *C, void *arg, int event)
 
 void action_header_buttons(const bContext *C, ARegion *ar)
 {
-       ScrArea *sa= C->area;
+       ScrArea *sa= CTX_wm_area(C);
        uiBlock *block;
        int xco, yco= 3;
        
@@ -115,7 +115,7 @@ void action_header_buttons(const bContext *C, ARegion *ar)
                uiBlockSetEmboss(block, UI_EMBOSSP);
                
                xmax= GetButStringLength("View");
-               uiDefPulldownBut(block, dummy_viewmenu, C->area
+               uiDefPulldownBut(block, dummy_viewmenu, CTX_wm_area(C)
                                                 "View", xco, yco-2, xmax-3, 24, "");
                xco+=XIC+xmax;
        }
index 26c99734d2d40538647f8b330c45c7c8f94dc234..35b5d5926376b3de04a46596f1de80b7ff252d79 100644 (file)
@@ -42,7 +42,7 @@
 #include "BLI_rand.h"
 
 #include "BKE_colortools.h"
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_space_api.h"
@@ -159,7 +159,7 @@ static void action_main_area_init(wmWindowManager *wm, ARegion *ar)
 static void action_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
-       // SpaceAction *saction= C->area->spacedata.first;
+       // SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
        View2D *v2d= &ar->v2d;
        float col[3];
        
index 1d9e3ac97ff6068aa817b90d53fda333be00a460..3112cfffb22fb24fc450f3625be3f3ac9b2a051d 100644 (file)
@@ -34,7 +34,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_arithb.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_screen.h"
index 59198aaf3baec4bf1ce7976fc2f6aff8bb061cc2..2e958a4d6dc0c08f7b2ab1a9282a57f7217f0a79 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "DNA_windowmanager_types.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "UI_interface.h"
index 9ffcc107753f59e3872f187fa6fa4061ae3cb03c..74e062f5888d0fdd192948feeb6ec70a1421b34d 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "BLI_blenlib.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_screen.h"
@@ -66,7 +66,7 @@ static void do_viewmenu(bContext *C, void *arg, int event)
 
 static uiBlock *dummy_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
-       ScrArea *curarea= C->area;
+       ScrArea *curarea= CTX_wm_area(C);
        uiBlock *block;
        short yco= 0, menuwidth=120;
        
@@ -106,8 +106,8 @@ static void do_buttons_buttons(bContext *C, void *arg, int event)
 
 void buttons_header_buttons(const bContext *C, ARegion *ar)
 {
-       ScrArea *sa= C->area;
-       SpaceButs *sbuts= sa->spacedata.first;
+       ScrArea *sa= CTX_wm_area(C);
+       SpaceButs *sbuts= (SpaceButs*)CTX_wm_space_data(C);
        uiBlock *block;
        int xco, yco= 3;
        
@@ -123,7 +123,7 @@ void buttons_header_buttons(const bContext *C, ARegion *ar)
                uiBlockSetEmboss(block, UI_EMBOSSP);
                
                xmax= GetButStringLength("View");
-               uiDefPulldownBut(block, dummy_viewmenu, C->area
+               uiDefPulldownBut(block, dummy_viewmenu, CTX_wm_area(C)
                                                 "View", xco, yco-2, xmax-3, 24, "");
                
                xco+=XIC+xmax;
@@ -182,7 +182,7 @@ void buttons_header_buttons(const bContext *C, ARegion *ar)
        uiBlockEndAlign(block);
        
        xco+=XIC;
-       uiDefButI(block, NUM, B_NEWFRAME, "",   (xco+20),yco,60,YIC, &(C->scene->r.cfra), 1.0, MAXFRAMEF, 0, 0, "Displays Current Frame of animation. Click to change.");
+       uiDefButI(block, NUM, B_NEWFRAME, "",   (xco+20),yco,60,YIC, &(CTX_data_scene(C)->r.cfra), 1.0, MAXFRAMEF, 0, 0, "Displays Current Frame of animation. Click to change.");
        xco+= 80;
        
 // XXX buttons_active_id(&id, &idfrom);
index 9ed56afec1867e23c3037c32711a630e64f786f5..6819a28406d71ee7b2da41f6f7a5d06a17ba00d2 100644 (file)
@@ -41,7 +41,7 @@
 #include "BLI_rand.h"
 
 #include "BKE_colortools.h"
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_space_api.h"
@@ -158,7 +158,7 @@ static void buttons_main_area_init(wmWindowManager *wm, ARegion *ar)
 static void buttons_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
-       // SpaceButs *sbuts= C->area->spacedata.first;
+       // SpaceButs *sbuts= (SpaceButs*)CTX_wm_space_data(C);
        View2D *v2d= &ar->v2d;
        float col[3], fac;
        
index c1dd69de1beae6c31e14a6a8b8c6f4d29233a192..3669249648f2a7efe73f0e4f84fa93db9a7f31e3 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "BLI_blenlib.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_screen.h"
@@ -66,7 +66,7 @@ static void do_viewmenu(bContext *C, void *arg, int event)
 
 static uiBlock *dummy_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
-       ScrArea *curarea= C->area;
+       ScrArea *curarea= CTX_wm_area(C);
        uiBlock *block;
        short yco= 0, menuwidth=120;
        
@@ -100,7 +100,7 @@ static void do_file_buttons(bContext *C, void *arg, int event)
 
 void file_header_buttons(const bContext *C, ARegion *ar)
 {
-       ScrArea *sa= C->area;
+       ScrArea *sa= CTX_wm_area(C);
        uiBlock *block;
        int xco, yco= 3;
        
@@ -116,7 +116,7 @@ void file_header_buttons(const bContext *C, ARegion *ar)
                uiBlockSetEmboss(block, UI_EMBOSSP);
                
                xmax= GetButStringLength("View");
-               uiDefPulldownBut(block, dummy_viewmenu, C->area
+               uiDefPulldownBut(block, dummy_viewmenu, CTX_wm_area(C)
                                                 "View", xco, yco-2, xmax-3, 24, "");
                xco+=XIC+xmax;
        }
index 36e2bae133b26947027df8168f06f2d55b561e47..ea20758884db922a281260f749c4519d4ebba054 100644 (file)
@@ -54,7 +54,7 @@
 #include "BLI_storage_types.h"
 #include "BLI_dynstr.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_screen.h"
index b8bc573e2cda7b08007be64c8869b3c6d890cdb2..5e19a993b732c38c3ba34aa77af1b79d5fb87c76 100644 (file)
@@ -43,7 +43,7 @@
 #include "BLI_rand.h"
 
 #include "BKE_colortools.h"
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_space_api.h"
@@ -141,7 +141,7 @@ static void file_main_area_init(wmWindowManager *wm, ARegion *ar)
 static void file_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
-       // SpaceFile *sfile= C->area->spacedata.first;
+       // SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
        View2D *v2d= &ar->v2d;
        float col[3];
        
index a9cf0e03fe8d623d73c5228ec87ec9929bd913a1..f741a7d44c0f63ab1f891517c43b1a81f32a395c 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "BLI_blenlib.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_screen.h"
@@ -66,7 +66,7 @@ static void do_viewmenu(bContext *C, void *arg, int event)
 
 static uiBlock *dummy_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
-       ScrArea *curarea= C->area;
+       ScrArea *curarea= CTX_wm_area(C);
        uiBlock *block;
        short yco= 0, menuwidth=120;
        
@@ -99,7 +99,7 @@ static void do_image_buttons(bContext *C, void *arg, int event)
 
 void image_header_buttons(const bContext *C, ARegion *ar)
 {
-       ScrArea *sa= C->area;
+       ScrArea *sa= CTX_wm_area(C);
        uiBlock *block;
        int xco, yco= 3;
        
@@ -115,7 +115,7 @@ void image_header_buttons(const bContext *C, ARegion *ar)
                uiBlockSetEmboss(block, UI_EMBOSSP);
                
                xmax= GetButStringLength("View");
-               uiDefPulldownBut(block, dummy_viewmenu, C->area
+               uiDefPulldownBut(block, dummy_viewmenu, CTX_wm_area(C)
                                                 "View", xco, yco-2, xmax-3, 24, "");
                xco+=XIC+xmax;
        }
index 7a96fb0622ca83b6d1f07c6e51afcc60e4195049..ca642072829575f512fd2310869adfc3e35573ef 100644 (file)
@@ -42,7 +42,7 @@
 #include "BLI_rand.h"
 
 #include "BKE_colortools.h"
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_space_api.h"
@@ -141,7 +141,7 @@ static void image_main_area_init(wmWindowManager *wm, ARegion *ar)
 static void image_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
-       // SpaceImage *simage= C->area->spacedata.first;
+       // SpaceImage *simage= (SpaceImage*)CTX_wm_space_data(C);
        View2D *v2d= &ar->v2d;
        float col[3];
        
index efaae1afb2e7a71f51ea9ad9d830ca3a9a6d3bb5..9d6c7be9898a8bade6e97e2d0da99c7408d12f0e 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "BLI_blenlib.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_screen.h"
@@ -66,7 +66,7 @@ static void do_viewmenu(bContext *C, void *arg, int event)
 
 static uiBlock *dummy_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
-       ScrArea *curarea= C->area;
+       ScrArea *curarea= CTX_wm_area(C);
        uiBlock *block;
        short yco= 0, menuwidth=120;
        
@@ -100,7 +100,7 @@ static void do_info_buttons(bContext *C, void *arg, int event)
 
 void info_header_buttons(const bContext *C, ARegion *ar)
 {
-       ScrArea *sa= C->area;
+       ScrArea *sa= CTX_wm_area(C);
        uiBlock *block;
        int xco, yco= 3;
        
@@ -116,23 +116,23 @@ void info_header_buttons(const bContext *C, ARegion *ar)
                uiBlockSetEmboss(block, UI_EMBOSSP);
                
                xmax= GetButStringLength("File");
-               uiDefPulldownBut(block, dummy_viewmenu, C->area, "File",        xco, yco, xmax-3, 22, "");
+               uiDefPulldownBut(block, dummy_viewmenu, sa, "File",     xco, yco, xmax-3, 22, "");
                xco+= xmax;
                
                xmax= GetButStringLength("Add");
-               uiDefPulldownBut(block, dummy_viewmenu, C->area, "Add", xco, yco, xmax-3, 22, "");
+               uiDefPulldownBut(block, dummy_viewmenu, sa, "Add",      xco, yco, xmax-3, 22, "");
                xco+= xmax;
                
                xmax= GetButStringLength("Timeline");
-               uiDefPulldownBut(block, dummy_viewmenu, C->area, "Timeline",    xco, yco, xmax-3, 22, "");
+               uiDefPulldownBut(block, dummy_viewmenu, sa, "Timeline", xco, yco, xmax-3, 22, "");
                xco+= xmax;
                
                xmax= GetButStringLength("Game");
-               uiDefPulldownBut(block, dummy_viewmenu, C->area, "Game",        xco, yco, xmax-3, 22, "");
+               uiDefPulldownBut(block, dummy_viewmenu, sa, "Game",     xco, yco, xmax-3, 22, "");
                xco+= xmax;
                
                xmax= GetButStringLength("Render");
-               uiDefPulldownBut(block, dummy_viewmenu, C->area, "Render",      xco, yco, xmax-3, 22, "");
+               uiDefPulldownBut(block, dummy_viewmenu, sa, "Render",   xco, yco, xmax-3, 22, "");
                xco+= xmax;
                
                xmax= GetButStringLength("Help");
index 7ef08495ae1341f71f9df8fd411ea3033316fbdc..ae6b4333150d08727cb2fb6ea9519e8843c74002 100644 (file)
@@ -40,8 +40,8 @@
 #include "BLI_arithb.h"
 #include "BLI_rand.h"
 
+#include "BKE_context.h"
 #include "BKE_colortools.h"
-#include "BKE_global.h"
 #include "BKE_screen.h"
 
 #include "ED_space_api.h"
@@ -129,7 +129,7 @@ static void info_main_area_init(wmWindowManager *wm, ARegion *ar)
 static void info_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
-       // SpaceInfo *sinfo= C->area->spacedata.first;
+       // SpaceInfo *sinfo= (SpaceInfo*)CTX_wm_space_data(C);
        View2D *v2d= &ar->v2d;
        float col[3];
        
index 61f7b80f70327c4e45ba5211311563d45fecc4cb..bf088cb700e11254241f44a9442bd9f852a19695 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "BLI_blenlib.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_screen.h"
@@ -66,7 +66,7 @@ static void do_viewmenu(bContext *C, void *arg, int event)
 
 static uiBlock *dummy_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
-       ScrArea *curarea= C->area;
+       ScrArea *curarea= CTX_wm_area(C);
        uiBlock *block;
        short yco= 0, menuwidth=120;
        
@@ -99,7 +99,7 @@ static void do_ipo_buttons(bContext *C, void *arg, int event)
 
 void ipo_header_buttons(const bContext *C, ARegion *ar)
 {
-       ScrArea *sa= C->area;
+       ScrArea *sa= CTX_wm_area(C);
        uiBlock *block;
        int xco, yco= 3;
        
@@ -115,7 +115,7 @@ void ipo_header_buttons(const bContext *C, ARegion *ar)
                uiBlockSetEmboss(block, UI_EMBOSSP);
                
                xmax= GetButStringLength("View");
-               uiDefPulldownBut(block, dummy_viewmenu, C->area
+               uiDefPulldownBut(block, dummy_viewmenu, CTX_wm_area(C)
                                                 "View", xco, yco-2, xmax-3, 24, "");
        }
        
index 325d14120aeaf944aa1bdf389d43fa6627cc07eb..1c1c5997ee7fe58c9787e73d6bee90edbbd8434a 100644 (file)
@@ -41,7 +41,7 @@
 #include "BLI_arithb.h"
 #include "BLI_rand.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_space_api.h"
@@ -149,7 +149,7 @@ static SpaceLink *ipo_duplicate(SpaceLink *sl)
 // XXX this should be defined in some general lib for anim editors...
 static void draw_cfra(const bContext *C, SpaceIpo *sipo, View2D *v2d)
 {
-       Scene *scene= C->scene;
+       Scene *scene= CTX_data_scene(C);
        float vec[2];
        
        //vec[0] = get_ipo_cfra_from_cfra(sipo, scene->r.cfra);
@@ -168,7 +168,7 @@ static void draw_cfra(const bContext *C, SpaceIpo *sipo, View2D *v2d)
        
 #if 0
        if(sipo->blocktype==ID_OB) {
-               ob= (G.scene->basact) ? (G.scene->basact->object) : 0;
+               ob= (scene->basact) ? (scene->basact->object) : 0;
                if (ob && (ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)!=0.0)) { 
                        vec[0]-= give_timeoffset(ob);
                        
@@ -204,7 +204,7 @@ static void ipo_main_area_init(wmWindowManager *wm, ARegion *ar)
 static void ipo_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
-       SpaceIpo *sipo= C->area->spacedata.first;
+       SpaceIpo *sipo= (SpaceIpo*)CTX_wm_space_data(C);
        View2D *v2d= &ar->v2d;
        View2DGrid *grid;
        View2DScrollers *scrollers;
index 5fee33b8aa57e6dae28c1c2f30d8dbe3eb509b6f..a2069b1aa997f36b1dcb4a90e50189a9b43eff03 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "BLI_blenlib.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_screen.h"
@@ -66,7 +66,7 @@ static void do_viewmenu(bContext *C, void *arg, int event)
 
 static uiBlock *dummy_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
-       ScrArea *curarea= C->area;
+       ScrArea *curarea= CTX_wm_area(C);
        uiBlock *block;
        short yco= 0, menuwidth=120;
        
@@ -99,7 +99,7 @@ static void do_nla_buttons(bContext *C, void *arg, int event)
 
 void nla_header_buttons(const bContext *C, ARegion *ar)
 {
-       ScrArea *sa= C->area;
+       ScrArea *sa= CTX_wm_area(C);
        uiBlock *block;
        int xco, yco= 3;
        
@@ -115,7 +115,7 @@ void nla_header_buttons(const bContext *C, ARegion *ar)
                uiBlockSetEmboss(block, UI_EMBOSSP);
                
                xmax= GetButStringLength("View");
-               uiDefPulldownBut(block, dummy_viewmenu, C->area
+               uiDefPulldownBut(block, dummy_viewmenu, CTX_wm_area(C)
                                                 "View", xco, yco-2, xmax-3, 24, "");
                xco+=XIC+xmax;
        }
index 71c5a8c0fe4f3c34d1fffac9db20bd037ec39fd4..6bb4252724153439d8aef5b2ac26006b9f99a979 100644 (file)
@@ -42,7 +42,7 @@
 #include "BLI_rand.h"
 
 #include "BKE_colortools.h"
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_space_api.h"
@@ -158,7 +158,7 @@ static void nla_main_area_init(wmWindowManager *wm, ARegion *ar)
 static void nla_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
-       // SpaceNla *snla= C->area->spacedata.first;
+       // SpaceNla *snla= (SpaceNla*)CTX_wm_space_data(C);
        View2D *v2d= &ar->v2d;
        float col[3];
        
index 4252a36e4c9c29df0b7f9bc3e2c1f93a9bd87a4f..5614f643578933a17fb8fc94a1dff23f5ccbf5d5 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "BLI_blenlib.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_screen.h"
@@ -66,7 +66,7 @@ static void do_viewmenu(bContext *C, void *arg, int event)
 
 static uiBlock *dummy_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
-       ScrArea *curarea= C->area;
+       ScrArea *curarea= CTX_wm_area(C);
        uiBlock *block;
        short yco= 0, menuwidth=120;
        
@@ -99,7 +99,7 @@ static void do_node_buttons(bContext *C, void *arg, int event)
 
 void node_header_buttons(const bContext *C, ARegion *ar)
 {
-       ScrArea *sa= C->area;
+       ScrArea *sa= CTX_wm_area(C);
        uiBlock *block;
        int xco, yco= 3;
        
@@ -115,7 +115,7 @@ void node_header_buttons(const bContext *C, ARegion *ar)
                uiBlockSetEmboss(block, UI_EMBOSSP);
                
                xmax= GetButStringLength("View");
-               uiDefPulldownBut(block, dummy_viewmenu, C->area
+               uiDefPulldownBut(block, dummy_viewmenu, CTX_wm_area(C)
                                                 "View", xco, yco-2, xmax-3, 24, "");
        }
        
index ba460900bf2e0b94f630848f209b6a0b0671354b..642fe92d29b332c9d723a4c078ae05e6de03009d 100644 (file)
@@ -42,7 +42,7 @@
 #include "BLI_rand.h"
 
 #include "BKE_colortools.h"
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_space_api.h"
@@ -152,7 +152,7 @@ static void node_main_area_init(wmWindowManager *wm, ARegion *ar)
 static void node_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
-       // SpaceNode *snode= C->area->spacedata.first;
+       // SpaceNode *snode= (SpaceNode*)CTX_wm_space_data(C);
        View2D *v2d= &ar->v2d;
        //View2DGrid *grid;
        float col[3];
index 5a56e8ef0f1fb8e0edc5077fa3139728f7edef30..fd2f6fc7576e9862b14ab01635bbba6d6c18a7bc 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "BLI_blenlib.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_screen.h"
@@ -66,7 +66,7 @@ static void do_viewmenu(bContext *C, void *arg, int event)
 
 static uiBlock *dummy_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
-       ScrArea *curarea= C->area;
+       ScrArea *curarea= CTX_wm_area(C);
        uiBlock *block;
        short yco= 0, menuwidth=120;
        
@@ -99,8 +99,8 @@ static void do_outliner_buttons(bContext *C, void *arg, int event)
 
 void outliner_header_buttons(const bContext *C, ARegion *ar)
 {
-       ScrArea *sa= C->area;
-       SpaceOops *soutliner= sa->spacedata.first;
+       ScrArea *sa= CTX_wm_area(C);
+       SpaceOops *soutliner= (SpaceOops*)CTX_wm_space_data(C);
        uiBlock *block;
        int xco, yco= 3;
        char *path;
@@ -117,7 +117,7 @@ void outliner_header_buttons(const bContext *C, ARegion *ar)
                uiBlockSetEmboss(block, UI_EMBOSSP);
                
                xmax= GetButStringLength("View");
-               uiDefPulldownBut(block, dummy_viewmenu, C->area
+               uiDefPulldownBut(block, dummy_viewmenu, CTX_wm_area(C)
                                                 "View", xco, yco-2, xmax-3, 24, ""); 
                xco += xmax;
                
index 36afb206ab685fef40b0e420babc4ca7f2ead71b..4fa10adcd9132ff7235437623554f9f56469577f 100644 (file)
@@ -47,7 +47,7 @@
 #include "BLI_rand.h"
 
 #include "BKE_colortools.h"
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 #include "BKE_texture.h"
 #include "BKE_utildefines.h"
@@ -108,15 +108,16 @@ void UI_table_free(uiTable *table)
 
 void UI_table_draw(const bContext *C, uiTable *table)
 {
+       ARegion *ar= CTX_wm_region(C);
        uiBlock *block;
        View2D *v2d;
        rcti *rct, cellrct;
        int y, row, col;
        
-       v2d= &C->region->v2d;
+       v2d= &ar->v2d;
        rct= &table->rct;
        
-       block= uiBeginBlock(C, C->region, "table outliner", UI_EMBOSST, UI_HELV);
+       block= uiBeginBlock(C, ar, "table outliner", UI_EMBOSST, UI_HELV);
        
        for(y=rct->ymax, row=0; y>rct->ymin; y-=ROW_HEIGHT, row++) {
                if(row%2 == 0) {
@@ -161,7 +162,7 @@ typedef struct CellRNA {
 
 static void rna_back_cb(bContext *C, void *arg_unused, void *arg_unused2)
 {
-       SpaceOops *soutliner= C->area->spacedata.first;
+       SpaceOops *soutliner= (SpaceOops*)CTX_wm_space_data(C);
        char *newpath;
 
        newpath= RNA_path_back(soutliner->rnapath);
@@ -172,7 +173,7 @@ static void rna_back_cb(bContext *C, void *arg_unused, void *arg_unused2)
 
 static void rna_pointer_cb(bContext *C, void *arg_prop, void *arg_index)
 {
-       SpaceOops *soutliner= C->area->spacedata.first;
+       SpaceOops *soutliner= (SpaceOops*)CTX_wm_space_data(C);
        PropertyRNA *prop= arg_prop;
        char *newpath;
        int index= GET_INT_FROM_POINTER(arg_index);;
@@ -406,7 +407,7 @@ static void outliner_main_area_draw(const bContext *C, ARegion *ar)
        PointerRNA newptr;
        float col[3];
        int rows, cols, awidth, aheight, width, height;
-       SpaceOops *soutliner= C->area->spacedata.first;
+       SpaceOops *soutliner= (SpaceOops*)CTX_wm_space_data(C);
        View2D *v2d= &ar->v2d;
        View2DScrollers *scrollers;
 
@@ -421,7 +422,7 @@ static void outliner_main_area_draw(const bContext *C, ARegion *ar)
        /* create table */
        cell.space= soutliner;
        cell.lastrow= -1;
-       RNA_main_pointer_create(G.main, &cell.ptr);
+       RNA_main_pointer_create(CTX_data_main(C), &cell.ptr);
        cell.prop= NULL;
 
        /* solve RNA path or reset if fails */
index 8cc3966fdf1cda7e1b4aca1711255b2888f19daf..7f18f4bbbeb45b942d32736b26991f6e29e5f2af 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "BLI_blenlib.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_screen.h"
@@ -66,7 +66,7 @@ static void do_viewmenu(bContext *C, void *arg, int event)
 
 static uiBlock *dummy_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
-       ScrArea *curarea= C->area;
+       ScrArea *curarea= CTX_wm_area(C);
        uiBlock *block;
        short yco= 0, menuwidth=120;
        
@@ -99,7 +99,7 @@ static void do_script_buttons(bContext *C, void *arg, int event)
 
 void script_header_buttons(const bContext *C, ARegion *ar)
 {
-       ScrArea *sa= C->area;
+       ScrArea *sa= CTX_wm_area(C);
        uiBlock *block;
        int xco, yco= 3;
        
@@ -115,7 +115,7 @@ void script_header_buttons(const bContext *C, ARegion *ar)
                uiBlockSetEmboss(block, UI_EMBOSSP);
                
                xmax= GetButStringLength("View");
-               uiDefPulldownBut(block, dummy_viewmenu, C->area
+               uiDefPulldownBut(block, dummy_viewmenu, CTX_wm_area(C)
                                                 "View", xco, yco-2, xmax-3, 24, "");
                xco+=XIC+xmax;
        }
index 8b9196ac506cfe3490b0d805fa4028765a6c4988..6693d71b507ef43e89b50bbd9d87497eff7038cd 100644 (file)
@@ -41,7 +41,7 @@
 #include "BLI_rand.h"
 
 #include "BKE_colortools.h"
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_space_api.h"
@@ -139,7 +139,7 @@ static void script_main_area_init(wmWindowManager *wm, ARegion *ar)
 static void script_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
-       // SpaceScript *sscript= C->area->spacedata.first;
+       // SpaceScript *sscript= (SpaceScript*)CTX_wm_space_data(C);
        View2D *v2d= &ar->v2d;
        float col[3];
        
index 0787920670bc74e4e2d12159cc7bb3725a57498e..26e92e67c77459a6b4e5e0e0629b57a6dd03f2c7 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "BLI_blenlib.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_screen.h"
@@ -66,7 +66,7 @@ static void do_viewmenu(bContext *C, void *arg, int event)
 
 static uiBlock *dummy_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
-       ScrArea *curarea= C->area;
+       ScrArea *curarea= CTX_wm_area(C);
        uiBlock *block;
        short yco= 0, menuwidth=120;
        
@@ -99,7 +99,7 @@ static void do_sequencer_buttons(bContext *C, void *arg, int event)
 
 void sequencer_header_buttons(const bContext *C, ARegion *ar)
 {
-       ScrArea *sa= C->area;
+       ScrArea *sa= CTX_wm_area(C);
        uiBlock *block;
        int xco, yco= 3;
        
@@ -115,7 +115,7 @@ void sequencer_header_buttons(const bContext *C, ARegion *ar)
                uiBlockSetEmboss(block, UI_EMBOSSP);
                
                xmax= GetButStringLength("View");
-               uiDefPulldownBut(block, dummy_viewmenu, C->area
+               uiDefPulldownBut(block, dummy_viewmenu, CTX_wm_area(C)
                                                 "View", xco, yco-2, xmax-3, 24, "");
                xco+=XIC+xmax;
        }
index 20618b6ab9bec7bbca8f1e663f7f61130694654b..2452b103a56a6e83ff9c7c720b7c988d273ba5d0 100644 (file)
@@ -41,7 +41,7 @@
 #include "BLI_rand.h"
 
 #include "BKE_colortools.h"
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_space_api.h"
@@ -158,7 +158,7 @@ static void sequencer_main_area_init(wmWindowManager *wm, ARegion *ar)
 static void sequencer_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
-       // SpaceSeq *sseq= C->area->spacedata.first;
+       // SpaceSeq *sseq= (SpaceSeq*)CTX_wm_space_data(C);
        View2D *v2d= &ar->v2d;
        float col[3];
        
index 8a566de4b5a81462f4d67f815b90fc03beb43481..1702b3e06a0b5f7072decf81f753863776745300 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "BLI_blenlib.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_screen.h"
@@ -66,7 +66,7 @@ static void do_viewmenu(bContext *C, void *arg, int event)
 
 static uiBlock *dummy_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
-       ScrArea *curarea= C->area;
+       ScrArea *curarea= CTX_wm_area(C);
        uiBlock *block;
        short yco= 0, menuwidth=120;
        
@@ -99,7 +99,7 @@ static void do_sound_buttons(bContext *C, void *arg, int event)
 
 void sound_header_buttons(const bContext *C, ARegion *ar)
 {
-       ScrArea *sa= C->area;
+       ScrArea *sa= CTX_wm_area(C);
        uiBlock *block;
        int xco, yco= 3;
        
@@ -115,7 +115,7 @@ void sound_header_buttons(const bContext *C, ARegion *ar)
                uiBlockSetEmboss(block, UI_EMBOSSP);
                
                xmax= GetButStringLength("View");
-               uiDefPulldownBut(block, dummy_viewmenu, C->area
+               uiDefPulldownBut(block, dummy_viewmenu, CTX_wm_area(C)
                                                 "View", xco, yco-2, xmax-3, 24, "");
                xco+=XIC+xmax;
        }
index 712e4f27192c3b0fe17a95967d110afb7e9ac1c7..82ed6082a38c98b8d9987c982b798d06080815d0 100644 (file)
@@ -42,7 +42,7 @@
 #include "BLI_rand.h"
 
 #include "BKE_colortools.h"
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_space_api.h"
@@ -154,7 +154,7 @@ static void sound_main_area_init(wmWindowManager *wm, ARegion *ar)
 static void sound_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
-       // SpaceSound *ssound= C->area->spacedata.first;
+       // SpaceSound *ssound= (SpaceSound*)CTX_wm_space_data(C);
        View2D *v2d= &ar->v2d;
        float col[3];
        
index e37dbdc613e6b0d9a4083d866e4d2dd13b3b2177..bab9ce3c143fbd1eb0525a83783655060e47b633 100644 (file)
@@ -42,7 +42,7 @@
 #include "BLI_rand.h"
 
 #include "BKE_colortools.h"
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_space_api.h"
@@ -132,7 +132,7 @@ static void text_main_area_init(wmWindowManager *wm, ARegion *ar)
 static void text_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
-       // SpaceText *stext= C->area->spacedata.first;
+       // SpaceText *stext= (SpaceText*)CTX_wm_space_data(C);
        View2D *v2d= &ar->v2d;
        float col[3];
        
index d43f33117df6e20ef5d22daa279f9925b343c0f4..47c408f0044c69edc75ffafbca55ef5b861e71d4 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "BLI_blenlib.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_screen.h"
@@ -66,7 +66,7 @@ static void do_viewmenu(bContext *C, void *arg, int event)
 
 static uiBlock *dummy_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
-       ScrArea *curarea= C->area;
+       ScrArea *curarea= CTX_wm_area(C);
        uiBlock *block;
        short yco= 0, menuwidth=120;
        
@@ -99,7 +99,7 @@ static void do_text_buttons(bContext *C, void *arg, int event)
 
 void text_header_buttons(const bContext *C, ARegion *ar)
 {
-       ScrArea *sa= C->area;
+       ScrArea *sa= CTX_wm_area(C);
        uiBlock *block;
        int xco, yco= 3;
        
@@ -115,7 +115,7 @@ void text_header_buttons(const bContext *C, ARegion *ar)
                uiBlockSetEmboss(block, UI_EMBOSSP);
                
                xmax= GetButStringLength("View");
-               uiDefPulldownBut(block, dummy_viewmenu, C->area
+               uiDefPulldownBut(block, dummy_viewmenu, CTX_wm_area(C)
                                                 "View", xco, yco-2, xmax-3, 24, "");
                xco+=XIC+xmax;
        }
index 3c4152366ee5ece999a7cfa573f64da5b613e2a2..e89a64faf94a31df68e9f0427a4a00a59ee6d48b 100644 (file)
@@ -38,6 +38,7 @@
 
 #include "BLI_blenlib.h"
 
+#include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_screen.h"
 
@@ -64,7 +65,7 @@
 /* draws a current frame indicator for the TimeLine */
 static void time_draw_cfra_time(const bContext *C, SpaceTime *stime, ARegion *ar)
 {
-       Scene *scene= C->scene;
+       Scene *scene= CTX_data_scene(C);
        float vec[2];
        
        vec[0]= scene->r.cfra*scene->r.framelen;
@@ -120,7 +121,7 @@ static void time_main_area_init(wmWindowManager *wm, ARegion *ar)
 static void time_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
-       SpaceTime *stime= C->area->spacedata.first;
+       SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
        View2D *v2d= &ar->v2d;
        View2DGrid *grid;
        View2DScrollers *scrollers;
index cc8ac6d1e7325e0248e5d1fc0337d312b1ccf857..5faacb29654cad61716c416e95aa84f4ce4fab31 100644 (file)
@@ -39,6 +39,7 @@
 
 #include "BLI_blenlib.h"
 
+#include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_screen.h"
 
@@ -65,7 +66,7 @@
 
 static void do_time_redrawmenu(bContext *C, void *arg, int event)
 {
-       SpaceTime *stime= C->area->spacedata.first;
+       SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
        
        if(event < 1001) {
                
@@ -76,7 +77,7 @@ static void do_time_redrawmenu(bContext *C, void *arg, int event)
        }
        else {
                if(event==1001) {
-//                     button(&C->scene->r.frs_sec,1,120,"FPS:");
+//                     button(&CTX_data_scene(C)->r.frs_sec,1,120,"FPS:");
                }
        }
 }
@@ -84,8 +85,9 @@ static void do_time_redrawmenu(bContext *C, void *arg, int event)
 
 static uiBlock *time_redrawmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
-       ScrArea *curarea= C->area;
-       SpaceTime *stime= curarea->spacedata.first;
+       ScrArea *curarea= CTX_wm_area(C);
+       SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
+       Scene *scene= CTX_data_scene(C);
        uiBlock *block;
        short yco= 0, menuwidth=120, icon;
        char str[32];
@@ -120,7 +122,7 @@ static uiBlock *time_redrawmenu(bContext *C, uiMenuBlockHandle *handle, void *ar
        
        uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
        
-       sprintf(str, "Set Frames/Sec (%d/%f)", C->scene->r.frs_sec, C->scene->r.frs_sec_base);
+       sprintf(str, "Set Frames/Sec (%d/%f)", scene->r.frs_sec, scene->r.frs_sec_base);
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, str,       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1001, "");
        
        uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
@@ -146,9 +148,10 @@ static uiBlock *time_redrawmenu(bContext *C, uiMenuBlockHandle *handle, void *ar
 
 static void do_time_viewmenu(bContext *C, void *arg, int event)
 {
-       ScrArea *curarea= C->area;
-       SpaceTime *stime= curarea->spacedata.first;
+       ScrArea *curarea= CTX_wm_area(C);
+       SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
        View2D *v2d= UI_view2d_fromcontext_rwin(C);
+       Scene *scene= CTX_data_scene(C);
        int first;
        
        switch(event) {
@@ -158,12 +161,12 @@ static void do_time_viewmenu(bContext *C, void *arg, int event)
                        break;
                case 3: /* View All */
                        if(v2d) {
-                               first= C->scene->r.sfra;
-                               if(first >= C->scene->r.efra) first= C->scene->r.efra;
+                               first= scene->r.sfra;
+                               if(first >= scene->r.efra) first= scene->r.efra;
                                        v2d->cur.xmin=v2d->tot.xmin= (float)first-2;
-                               v2d->cur.xmax=v2d->tot.xmax= (float)C->scene->r.efra+2;
+                               v2d->cur.xmax=v2d->tot.xmax= (float)scene->r.efra+2;
                        
-                               ED_area_tag_redraw(C->area);
+                               ED_area_tag_redraw(curarea);
                        }
                        break;
                case 4: /* Maximize Window */
@@ -171,7 +174,7 @@ static void do_time_viewmenu(bContext *C, void *arg, int event)
                        break;
                case 5: /* show time or frames */
                        stime->flag ^= TIME_DRAWFRAMES;
-                       ED_area_tag_redraw(C->area);
+                       ED_area_tag_redraw(curarea);
                        break;
                case 6:
                        //nextprev_marker(1);
@@ -191,20 +194,20 @@ static void do_time_viewmenu(bContext *C, void *arg, int event)
                case 11:
                        if(v2d) {
                                v2d->flag ^= V2D_VIEWSYNC_X;
-                               UI_view2d_sync(C->screen, v2d, V2D_LOCK_SET);
+                               UI_view2d_sync(CTX_wm_screen(C), v2d, V2D_LOCK_SET);
                        }
                        break;
                case 12: /* only show keyframes from selected data */
                        stime->flag ^= TIME_ONLYACTSEL;
-                       ED_area_tag_redraw(C->area);
+                       ED_area_tag_redraw(curarea);
                        break;
        }
 }
 
 static uiBlock *time_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
-       ScrArea *curarea= C->area;
-       SpaceTime *stime= curarea->spacedata.first;
+       ScrArea *curarea= CTX_wm_area(C);
+       SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
        View2D *v2d= UI_view2d_fromcontext_rwin(C);
        uiBlock *block;
        short yco= 0, menuwidth=120;
@@ -260,25 +263,27 @@ static uiBlock *time_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_
 
 static void do_time_framemenu(bContext *C, void *arg, int event)
 {
+       Scene *scene= CTX_data_scene(C);
+
        switch(event) {
                case 1: /*Set as Start */
-                       if (C->scene->r.psfra) {
-                               if (C->scene->r.pefra < CFRA)
-                                       C->scene->r.pefra= CFRA;
-                               C->scene->r.psfra= CFRA;
+                       if (scene->r.psfra) {
+                               if (scene->r.pefra < scene->r.cfra)
+                                       scene->r.pefra= scene->r.cfra;
+                               scene->r.psfra= scene->r.cfra;
                        }                               
                        else
-                               C->scene->r.sfra = CFRA;
+                               scene->r.sfra = scene->r.cfra;
                        WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
                        break;
                case 2: /* Set as End */
-                       if (C->scene->r.psfra) {
-                               if (CFRA < C->scene->r.psfra)
-                                       C->scene->r.psfra= CFRA;
-                               C->scene->r.pefra= CFRA;
+                       if (scene->r.psfra) {
+                               if (scene->r.cfra < scene->r.psfra)
+                                       scene->r.psfra= scene->r.cfra;
+                               scene->r.pefra= scene->r.cfra;
                        }                               
                        else
-                               C->scene->r.efra = CFRA;
+                               scene->r.efra = scene->r.cfra;
                        WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
                        break;
                case 3: /* Rename Marker */
@@ -289,7 +294,7 @@ static void do_time_framemenu(bContext *C, void *arg, int event)
 
 static uiBlock *time_framemenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
-       ScrArea *curarea= C->area;
+       ScrArea *curarea= CTX_wm_area(C);
        uiBlock *block;
        short yco= 0, menuwidth=120;
        
@@ -368,14 +373,15 @@ static void end_animated_screen(SpaceTime *stime)
 
 void do_time_buttons(bContext *C, void *arg, int event)
 {
-       SpaceTime *stime= C->area->spacedata.first;
+       SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
+       Scene *scene= CTX_data_scene(C);
        
        switch(event) {
                case B_REDRAWALL:
                        WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
                        break;
                case B_TL_REW:
-                       CFRA= PSFRA;
+                       scene->r.cfra= PSFRA;
                        //update_for_newframe();
                        break;
                case B_TL_PLAY:
@@ -387,7 +393,7 @@ void do_time_buttons(bContext *C, void *arg, int event)
                        break;
                case B_TL_FF:
                        /* end frame */
-                       CFRA= PEFRA;
+                       scene->r.cfra= PEFRA;
                        //update_for_newframe();
                        break;
                case B_TL_PREVKEY:
@@ -400,15 +406,15 @@ void do_time_buttons(bContext *C, void *arg, int event)
                        break;
                        
                case B_TL_PREVIEWON:
-                       if (C->scene->r.psfra) {
+                       if (scene->r.psfra) {
                                /* turn on preview range */
-                               C->scene->r.psfra= C->scene->r.sfra;
-                               C->scene->r.pefra= C->scene->r.efra;
+                               scene->r.psfra= scene->r.sfra;
+                               scene->r.pefra= scene->r.efra;
                        }
                        else {
                                /* turn off preview range */
-                               C->scene->r.psfra= 0;
-                               C->scene->r.pefra= 0;
+                               scene->r.psfra= 0;
+                               scene->r.pefra= 0;
                        }
                        //BIF_undo_push("Set anim-preview range");
                        WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
@@ -430,8 +436,9 @@ void do_time_buttons(bContext *C, void *arg, int event)
 
 void time_header_buttons(const bContext *C, ARegion *ar)
 {
-       ScrArea *sa= C->area;
-       SpaceTime *stime= sa->spacedata.first;
+       ScrArea *sa= CTX_wm_area(C);
+       SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
+       Scene *scene= CTX_data_scene(C);
        uiBlock *block;
        int xco, yco= 3;
        
@@ -447,16 +454,16 @@ void time_header_buttons(const bContext *C, ARegion *ar)
                uiBlockSetEmboss(block, UI_EMBOSSP);
                
                xmax= GetButStringLength("View");
-               uiDefPulldownBut(block, time_viewmenu, C->area, 
+               uiDefPulldownBut(block, time_viewmenu, sa, 
                                                 "View", xco, yco-2, xmax-3, 24, "");
                xco+= xmax;
                xmax= GetButStringLength("Frame");
-               uiDefPulldownBut(block, time_framemenu, C->area, 
+               uiDefPulldownBut(block, time_framemenu, sa, 
                                                 "Frame", xco, yco-2, xmax-3, 24, "");
                xco+= xmax;
                
                xmax= GetButStringLength("Playback");
-               uiDefPulldownBut(block, time_redrawmenu, C->area, 
+               uiDefPulldownBut(block, time_redrawmenu, sa, 
                                                 "Playback", xco, yco-2, xmax-3, 24, "");
                xco+= xmax;
        }
@@ -467,35 +474,35 @@ void time_header_buttons(const bContext *C, ARegion *ar)
        
        uiDefButI(block, TOG, B_TL_PREVIEWON,"Preview", 
                          xco,yco, XIC, YIC,
-                         &C->scene->r.psfra,0, 1, 0, 0,
+                         &scene->r.psfra,0, 1, 0, 0,
                          "Show settings for frame range of animation preview");
        
        xco += XIC;
        
-       if (C->scene->r.psfra) {
+       if (scene->r.psfra) {
                uiDefButI(block, NUM, B_REDRAWALL,"Start:",     
                                  xco,yco, 4.5*XIC, YIC,
-                                 &C->scene->r.psfra,MINFRAMEF, MAXFRAMEF, 0, 0,
+                                 &scene->r.psfra,MINFRAMEF, MAXFRAMEF, 0, 0,
                                  "The start frame of the animation preview (inclusive)");
                
                xco += (short)(4.5*XIC);
                
                uiDefButI(block, NUM, B_REDRAWALL,"End:",       
                                  xco,yco,4.5*XIC,YIC,
-                                 &C->scene->r.pefra,PSFRA,MAXFRAMEF, 0, 0,
+                                 &scene->r.pefra,PSFRA,MAXFRAMEF, 0, 0,
                                  "The end frame of the animation preview (inclusive)");
        }
        else {
                uiDefButI(block, NUM, B_REDRAWALL,"Start:",     
                                  xco,yco, 4.5*XIC, YIC,
-                                 &C->scene->r.sfra,MINFRAMEF, MAXFRAMEF, 0, 0,
+                                 &scene->r.sfra,MINFRAMEF, MAXFRAMEF, 0, 0,
                                  "The start frame of the animation (inclusive)");
                
                xco += (short)(4.5*XIC);
                
                uiDefButI(block, NUM, B_REDRAWALL,"End:",       
                                  xco,yco,4.5*XIC,YIC,
-                                 &C->scene->r.efra,(float)SFRA,MAXFRAMEF, 0, 0,
+                                 &scene->r.efra,(float)SFRA,MAXFRAMEF, 0, 0,
                                  "The end frame of the animation (inclusive)");
        }
        uiBlockEndAlign(block);
@@ -504,7 +511,7 @@ void time_header_buttons(const bContext *C, ARegion *ar)
        
        uiDefButI(block, NUM, B_NEWFRAME, "",
                          xco,yco,3.5*XIC,YIC,
-                         &(C->scene->r.cfra), MINFRAMEF, MAXFRAMEF, 0, 0,
+                         &(scene->r.cfra), MINFRAMEF, MAXFRAMEF, 0, 0,
                          "Displays Current Frame of animation");
        
        xco += (short)(3.5 * XIC + 16);
@@ -532,12 +539,12 @@ void time_header_buttons(const bContext *C, ARegion *ar)
        xco+= XIC+8;
        
        uiDefIconButBitS(block, TOG, AUTOKEY_ON, REDRAWINFO, ICON_REC,
-                                        xco, yco, XIC, YIC, &(C->scene->autokey_mode), 0, 0, 0, 0, "Automatic keyframe insertion for Objects and Bones");
+                                        xco, yco, XIC, YIC, &(scene->autokey_mode), 0, 0, 0, 0, "Automatic keyframe insertion for Objects and Bones");
        xco+= XIC;
-       if (C->scene->autokey_mode & AUTOKEY_ON) {
+       if (scene->autokey_mode & AUTOKEY_ON) {
                uiDefButS(block, MENU, REDRAWINFO, 
                                  "Auto-Keying Mode %t|Add/Replace Keys%x3|Replace Keys %x5", 
-                                 xco, yco, 3.5*XIC, YIC, &(C->scene->autokey_mode), 0, 1, 0, 0, 
+                                 xco, yco, 3.5*XIC, YIC, &(scene->autokey_mode), 0, 1, 0, 0, 
                                  "Mode of automatic keyframe insertion for Objects and Bones");
                xco+= (4*XIC);
        }
index 599594a3ec0d446e9707623391763b0465e77c9e..30b0e808e053b245a2876fa27389fb6c688596ce 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "BLI_blenlib.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_utildefines.h"
 
 #include "UI_interface.h"
@@ -56,7 +56,7 @@
 
 static int change_frame_init(bContext *C, wmOperator *op)
 {
-       SpaceTime *stime= C->area->spacedata.first;
+       SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
 
        stime->flag |= TIME_CFRA_NUM;
        
@@ -65,6 +65,7 @@ static int change_frame_init(bContext *C, wmOperator *op)
 
 static void change_frame_apply(bContext *C, wmOperator *op)
 {
+       Scene *scene= CTX_data_scene(C);
        int cfra;
 
        cfra= RNA_int_get(op->ptr, "frame");
@@ -83,8 +84,8 @@ static void change_frame_apply(bContext *C, wmOperator *op)
        else PIL_sleep_ms(30);
 #endif
 
-       if(cfra!=CFRA)
-               CFRA= cfra;
+       if(cfra!=scene->r.cfra)
+               scene->r.cfra= cfra;
        
        WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
        /* XXX: add WM_NOTE_TIME_CHANGED? */
@@ -92,7 +93,7 @@ static void change_frame_apply(bContext *C, wmOperator *op)
 
 static void change_frame_exit(bContext *C, wmOperator *op)
 {
-       SpaceTime *stime= C->area->spacedata.first;
+       SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
 
        stime->flag &= ~TIME_CFRA_NUM;
 }
@@ -109,7 +110,7 @@ static int change_frame_exec(bContext *C, wmOperator *op)
 
 static int frame_from_event(bContext *C, wmEvent *event)
 {
-       ARegion *region= C->region;
+       ARegion *region= CTX_wm_region(C);
        int x, y;
        float viewx;
        
@@ -127,7 +128,7 @@ static int change_frame_invoke(bContext *C, wmOperator *op, wmEvent *event)
        change_frame_apply(C, op);
 
        /* add temp handler */
-       WM_event_add_modal_handler(C, &C->window->handlers, op);
+       WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
 
        return OPERATOR_RUNNING_MODAL;
 }
@@ -182,12 +183,12 @@ static int toggle_time_exec(bContext *C, wmOperator *op)
 {
        SpaceTime *stime;
        
-       if (ELEM(NULL, C->area, C->area->spacedata.first))
+       if (ELEM(NULL, CTX_wm_area(C), CTX_wm_space_data(C)))
                return OPERATOR_CANCELLED;
        
        /* simply toggle draw frames flag for now */
        // XXX in past, this displayed menu to choose... (for later!)
-       stime= C->area->spacedata.first;
+       stime= (SpaceTime*)CTX_wm_space_data(C);
        stime->flag ^= TIME_DRAWFRAMES;
        
        return OPERATOR_FINISHED;
index d98b59ac2c6163686ad78579b037a052b098dd13..3f30d1cbd79e901c61aeda0c1247ea4cf531f94d 100644 (file)
@@ -41,6 +41,7 @@
 #include "BLI_arithb.h"
 #include "BLI_rand.h"
 
+#include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_screen.h"
 
index 337874074c35c97169e00d3e3586c47b9309ab6e..aa950b872382254fa00b6f3c8d7c0d7740181073 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "BLI_blenlib.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
 #include "ED_screen.h"
@@ -66,7 +66,7 @@ static void do_viewmenu(bContext *C, void *arg, int event)
 
 static uiBlock *dummy_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
 {
-       ScrArea *curarea= C->area;
+       ScrArea *curarea= CTX_wm_area(C);
        uiBlock *block;
        short yco= 0, menuwidth=120;
        
@@ -100,7 +100,7 @@ static void do_view3d_buttons(bContext *C, void *arg, int event)
 
 void view3d_header_buttons(const bContext *C, ARegion *ar)
 {
-       ScrArea *sa= C->area;
+       ScrArea *sa= CTX_wm_area(C);
        uiBlock *block;
        int xco, yco= 3;
        
@@ -116,7 +116,7 @@ void view3d_header_buttons(const bContext *C, ARegion *ar)
                uiBlockSetEmboss(block, UI_EMBOSSP);
                
                xmax= GetButStringLength("View");
-               uiDefPulldownBut(block, dummy_viewmenu, C->area
+               uiDefPulldownBut(block, dummy_viewmenu, CTX_wm_area(C)
                                                 "View", xco, yco-2, xmax-3, 24, "");
        }
        
index 843a81e708635c81ba7a0381c530f0b9dd674e0c..96f7f15f8c966e820f719de8838258b9070bdf74 100644 (file)
@@ -43,6 +43,7 @@
 
 #include "BLI_blenlib.h"
 
+#include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_utildefines.h"
 
@@ -79,7 +80,7 @@ static ListBase *context_get_markers(const bContext *C)
        else
 #endif
        
-       return &C->scene->markers;
+       return &CTX_data_scene(C)->markers;
 }
 
 /* ************* Marker Drawing ************ */
@@ -162,12 +163,12 @@ void draw_markers_time(const bContext *C, int flag)
        
        /* unselected markers are drawn at the first time */
        for (marker= markers->first; marker; marker= marker->next) {
-               if (!(marker->flag & SELECT)) draw_marker(v2d, marker, C->scene->r.cfra, flag);
+               if (!(marker->flag & SELECT)) draw_marker(v2d, marker, CTX_data_scene(C)->r.cfra, flag);
        }
        
        /* selected markers are drawn later */
        for (marker= markers->first; marker; marker= marker->next) {
-               if (marker->flag & SELECT) draw_marker(v2d, marker, C->scene->r.cfra, flag);
+               if (marker->flag & SELECT) draw_marker(v2d, marker, CTX_data_scene(C)->r.cfra, flag);
        }
 }
 
@@ -180,7 +181,7 @@ static int ed_marker_add(bContext *C, wmOperator *op)
 {
        ListBase *markers= context_get_markers(C);
        TimeMarker *marker;
-       int frame= C->scene->r.cfra;
+       int frame= CTX_data_scene(C)->r.cfra;
        
        /* two markers can't be at the same place */
        for(marker= markers->first; marker; marker= marker->next)
@@ -264,7 +265,7 @@ static int ed_marker_move_init(bContext *C, wmOperator *op)
        if (totmark==0) return 0;
        
        op->customdata= mm= MEM_callocN(sizeof(MarkerMove), "Markermove");
-       mm->slink= C->area->spacedata.first;
+       mm->slink= CTX_wm_space_data(C);
        mm->markers= markers;
        mm->oldframe= MEM_callocN(totmark*sizeof(int), "MarkerMove oldframe");
        
@@ -298,7 +299,7 @@ static int ed_marker_move_invoke(bContext *C, wmOperator *op, wmEvent *evt)
                mm->event_type= evt->type;
                
                /* add temp handler */
-               WM_event_add_modal_handler(C, &C->window->handlers, op);
+               WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
                
                /* reset frs delta */
                RNA_int_set(op->ptr, "frs", 0);
@@ -563,12 +564,12 @@ static void ED_MARKER_OT_duplicate(wmOperatorType *ot)
 /* ************************** selection ************************************/
 
 /* select/deselect TimeMarker at current frame */
-static void select_timeline_marker_frame(int frame, unsigned char shift)
+static void select_timeline_marker_frame(ListBase *markers, int frame, unsigned char shift)
 {
        TimeMarker *marker;
        int select=0;
        
-       for(marker= G.scene->markers.first; marker; marker= marker->next) {
+       for(marker= markers->first; marker; marker= marker->next) {
                /* if Shift is not set, then deselect Markers */
                if(!shift) marker->flag &= ~SELECT;
                /* this way a not-shift select will allways give 1 selected marker */
@@ -607,17 +608,17 @@ static int ed_marker_select(bContext *C, wmEvent *evt, int extend)
        float viewx;
        int x, y, cfra;
        
-       x= evt->x - C->region->winrct.xmin;
-       y= evt->y - C->region->winrct.ymin;
+       x= evt->x - CTX_wm_region(C)->winrct.xmin;
+       y= evt->y - CTX_wm_region(C)->winrct.ymin;
        
        UI_view2d_region_to_view(v2d, x, y, &viewx, NULL);      
        
        cfra= find_nearest_marker_time(markers, viewx);
        
        if (extend)
-               select_timeline_marker_frame(cfra, 1);
+               select_timeline_marker_frame(markers, cfra, 1);
        else
-               select_timeline_marker_frame(cfra, 0);
+               select_timeline_marker_frame(markers, cfra, 0);
        
        WM_event_add_notifier(C, WM_NOTE_MARKERS_CHANGED, 0, NULL);
 
index ded0cb854b993172b858b21823a98c6877453304..3c8628c5fbb86c91b1242405601deaba7336d97d 100644 (file)
@@ -126,10 +126,6 @@ void               WM_OT_tweak_gesture(wmOperatorType *ot);
 struct wmGesture *WM_gesture_new(struct bContext *C, struct wmEvent *event, int type);
 void           WM_gesture_end(struct bContext *C, struct wmGesture *gesture);
 
-                       /* Reporting information and errors */
-void           WM_report(struct bContext *C, int type, const char *message);
-void           WM_reportf(struct bContext *C, int type, const char *format, ...);
-
                        /* OpenGL wrappers, mimicing opengl syntax */
 void           wmLoadMatrix            (wmWindow *win, float mat[][4]);
 void           wmGetMatrix                     (wmWindow *win, float mat[][4]);
index d37857ebfa0f08a7bd38b08edc6243fce831d0ba..5e89ad11de24f9b0b574eb6079b2f815fa16b076 100644 (file)
@@ -33,7 +33,7 @@
 #include "BLI_blenlib.h"
 
 #include "BKE_blender.h"
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_idprop.h"
@@ -90,36 +90,40 @@ void wm_operator_register(wmWindowManager *wm, wmOperator *op)
 
 void wm_check(bContext *C)
 {
+       wmWindowManager *wm= CTX_wm_manager(C);
        
        /* wm context */
-       if(C->wm==NULL) C->wm= G.main->wm.first;
-       if(C->wm==NULL) return;
-       if(C->wm->windows.first==NULL) return;
+       if(CTX_wm_manager(C)==NULL) {
+               wm= CTX_data_main(C)->wm.first;
+               CTX_wm_manager_set(C, wm);
+       }
+       if(wm==NULL) return;
+       if(wm->windows.first==NULL) return;
        
        /* case: no open windows at all, for old file reads */
-       wm_window_add_ghostwindows(C->wm);
+       wm_window_add_ghostwindows(wm);
        
        /* case: fileread */
-       if(C->wm->initialized==0) {
+       if(wm->initialized==0) {
                
-               wm_window_keymap(C->wm);
-               ED_spacetypes_keymap(C->wm);
+               wm_window_keymap(wm);
+               ED_spacetypes_keymap(wm);
                
-               ED_screens_initialize(C->wm);
-               C->wm->initialized= 1;
+               ED_screens_initialize(wm);
+               wm->initialized= 1;
        }
 }
 
 /* on startup, it adds all data, for matching */
 void wm_add_default(bContext *C)
 {
-       wmWindowManager *wm= alloc_libblock(&G.main->wm, ID_WM, "WinMan");
+       wmWindowManager *wm= alloc_libblock(&CTX_data_main(C)->wm, ID_WM, "WinMan");
        wmWindow *win;
        
-       C->wm= wm;
+       CTX_wm_manager_set(C, wm);
        
        win= wm_window_new(C);
-       win->screen= C->screen;
+       win->screen= CTX_wm_screen(C); /* XXX from window? */
        wm->winactive= win;
        wm_window_make_drawable(C, win); 
 }
@@ -130,7 +134,6 @@ void wm_close_and_free(bContext *C, wmWindowManager *wm)
 {
        wmWindow *win;
        wmOperator *op;
-       wmReport *report;
        wmKeyMap *km;
        wmKeymapItem *kmi;
        
@@ -144,11 +147,6 @@ void wm_close_and_free(bContext *C, wmWindowManager *wm)
                wm_operator_free(op);
        }
 
-       while((report= wm->reports.first)) {
-               BLI_remlink(&wm->reports, report);
-               wm_report_free(report);
-       }
-
        while((km= wm->keymaps.first)) {
                for(kmi=km->keymap.first; kmi; kmi=kmi->next) {
                        if(kmi->ptr)
@@ -167,7 +165,7 @@ void wm_close_and_free(bContext *C, wmWindowManager *wm)
        
        BLI_freelistN(&wm->queue);
        
-       if(C && C->wm==wm) C->wm= NULL;
+       if(C && CTX_wm_manager(C)==wm) CTX_wm_manager_set(C, NULL);
 }
 
 void wm_close_and_free_all(bContext *C, ListBase *wmlist)
index 8b4ddd786e0baf8195e278df9edc8da73030cca7..3afc9cc884b5beb1f3d7e962d0e5a9270b4e3ec7 100644 (file)
@@ -35,7 +35,7 @@
 #include "DNA_listBase.h"
 #include "DNA_userdef_types.h" 
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 
 #include "WM_api.h"
 #include "wm_cursors.h"
index 5cc28ec45d88151b84174257fd955d13c1d2c34d..72ad5d8c4ace1f670fcea38868206bf6e4fb1ff3 100644 (file)
@@ -41,6 +41,7 @@
 #include "BLI_blenlib.h"
 
 #include "BKE_blender.h"
+#include "BKE_context.h"
 #include "BKE_idprop.h"
 #include "BKE_global.h"
 
@@ -98,11 +99,11 @@ void WM_event_add_notifier(bContext *C, int type, int value, void *data)
 {
        wmNotifier *note= MEM_callocN(sizeof(wmNotifier), "notifier");
        
-       BLI_addtail(&C->wm->queue, note);
+       BLI_addtail(&CTX_wm_manager(C)->queue, note);
        
-       note->window= C->window;
-       if(C->region)
-               note->swinid= C->region->swinid;
+       note->window= CTX_wm_window(C);
+       if(CTX_wm_region(C))
+               note->swinid= CTX_wm_region(C)->swinid;
        note->type= type;
        note->value= value;
        note->data= data;
@@ -119,17 +120,18 @@ static wmNotifier *wm_notifier_next(wmWindowManager *wm)
 /* called in mainloop */
 void wm_event_do_notifiers(bContext *C)
 {
+       wmWindowManager *wm= CTX_wm_manager(C);
        wmNotifier *note;
        
-       while( (note=wm_notifier_next(C->wm)) ) {
+       while( (note=wm_notifier_next(wm)) ) {
                wmWindow *win;
                
-               for(win= C->wm->windows.first; win; win= win->next) {
+               for(win= wm->windows.first; win; win= win->next) {
                        ScrArea *sa;
                        ARegion *ar;
 
-                       C->window= win;
-                       C->screen= win->screen; /* XXX context in notifiers? */
+                       /* XXX context in notifiers? */
+                       CTX_wm_window_set(C, win);
 
                        /* printf("notifier win %d screen %s\n", win->winid, win->screen->id.name+2); */
                        ED_screen_do_listen(win, note);
@@ -144,8 +146,7 @@ void wm_event_do_notifiers(bContext *C)
                                }
                        }
 
-                       C->window= NULL;
-                       C->screen= NULL;
+                       CTX_wm_window_set(C, NULL);
                }
                
                MEM_freeN(note);
@@ -170,11 +171,12 @@ static void wm_flush_regions(bScreen *screen, rcti *dirty)
 static void wm_flush_draw_update(bContext *C)
 {
        ARegion *ar;
+       bScreen *screen= CTX_wm_screen(C);
        
        /* flush redraws of screen regions (menus) down */
-       for(ar= C->screen->regionbase.first; ar; ar= ar->next) {
+       for(ar= screen->regionbase.first; ar; ar= ar->next) {
                if(ar->swinid && ar->do_draw) {
-                       wm_flush_regions(C->screen, &ar->winrct);
+                       wm_flush_regions(screen, &ar->winrct);
                }
        }
        
@@ -209,40 +211,40 @@ static int wm_draw_update_test_window(wmWindow *win)
 
 void wm_draw_update(bContext *C)
 {
+       wmWindowManager *wm= CTX_wm_manager(C);
        wmWindow *win;
        
-       for(win= C->wm->windows.first; win; win= win->next) {
+       for(win= wm->windows.first; win; win= win->next) {
                if(wm_draw_update_test_window(win)) {
                        ScrArea *sa;
                        ARegion *ar;
 
-                       C->window= win;
-                       C->screen= win->screen;
+                       CTX_wm_window_set(C, win);
                        
                        /* sets context window+screen */
                        wm_window_make_drawable(C, win);
                        
                        /* notifiers for screen redraw */
                        if(win->screen->do_refresh)
-                               ED_screen_refresh(C->wm, win);
+                               ED_screen_refresh(wm, win);
                        
                        /* flush draw updates for multiple layers */
                        wm_flush_draw_update(C);
 
                        for(sa= win->screen->areabase.first; sa; sa= sa->next) {
                                
-                               C->area= sa;
+                               CTX_wm_area_set(C, sa);
                                
                                for(ar=sa->regionbase.first; ar; ar= ar->next) {
-                                       C->region= ar;
+                                       CTX_wm_region_set(C, ar);
                                        
                                        if(ar->swinid && ar->do_draw)
                                                ED_region_do_draw(C, ar);
                                        
-                                       C->region= NULL;
+                                       CTX_wm_region_set(C, NULL);
                                }
                                
-                               C->area = NULL;
+                               CTX_wm_area_set(C, NULL);
                        }
                        
                        /* move this here so we can do area 'overlay' drawing */
@@ -253,12 +255,12 @@ void wm_draw_update(bContext *C)
 
                        /* regions are menus here */
                        for(ar=win->screen->regionbase.first; ar; ar= ar->next) {
-                               C->region= ar;
+                               CTX_wm_region_set(C, ar);
                                
                                if(ar->swinid && ar->do_draw)
                                        ED_region_do_draw(C, ar);
 
-                               C->region= NULL;
+                               CTX_wm_region_set(C, NULL);
                        }
                        
                        if(win->screen->do_gesture)
@@ -266,8 +268,7 @@ void wm_draw_update(bContext *C)
 
                        wm_window_swap_buffers(win);
 
-                       C->window= NULL;
-                       C->screen= NULL;
+                       CTX_wm_window_set(C, NULL);
                }
        }
 }
@@ -277,6 +278,7 @@ void wm_draw_update(bContext *C)
 
 static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, IDProperty *properties)
 {
+       wmWindowManager *wm= CTX_wm_manager(C);
        int retval= OPERATOR_PASS_THROUGH;
 
        if(ot->poll==NULL || ot->poll(C)) {
@@ -290,7 +292,7 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, I
                BLI_strncpy(op->idname, ot->idname, OP_MAX_TYPENAME);
                
                op->ptr= MEM_callocN(sizeof(PointerRNA), "wmOperatorPtrRNA");
-               RNA_pointer_create(&RNA_WindowManager, &C->wm->id, ot->srna, &op->properties, op->ptr);
+               RNA_pointer_create(&RNA_WindowManager, &wm->id, ot->srna, &op->properties, op->ptr);
 
                if(op->type->invoke)
                        retval= (*op->type->invoke)(C, op, event);
@@ -298,7 +300,7 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, I
                        retval= op->type->exec(C, op);
 
                if((retval & OPERATOR_FINISHED) && (ot->flag & OPTYPE_REGISTER)) {
-                       wm_operator_register(C->wm, op);
+                       wm_operator_register(wm, op);
                }
                else if(!(retval & OPERATOR_RUNNING_MODAL)) {
                        wm_operator_free(op);
@@ -312,55 +314,57 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, I
 int WM_operator_call(bContext *C, const char *opstring, int context, IDProperty *properties)
 {
        wmOperatorType *ot= WM_operatortype_find(opstring);
+       wmWindow *window= CTX_wm_window(C);
        int retval;
 
        /* dummie test */
-       if(ot && C && C->window) {
+       if(ot && C && window) {
                if(context == WM_OP_REGION_WIN) {
                        /* forces event to go to the region window, for header menus */
-                       ARegion *ar= C->region;
+                       ARegion *ar= CTX_wm_region(C);
+                       ScrArea *area= CTX_wm_area(C);
                        
-                       if(C->area) {
-                               ARegion *ar1= C->area->regionbase.first;
+                       if(area) {
+                               ARegion *ar1= area->regionbase.first;
                                for(; ar1; ar1= ar1->next)
                                        if(ar1->regiontype==RGN_TYPE_WINDOW)
                                                break;
                                if(ar1)
-                                       C->region= ar1;
+                                       CTX_wm_region_set(C, ar1);
                        }
                        
-                       retval= wm_operator_invoke(C, ot, C->window->eventstate, properties);
+                       retval= wm_operator_invoke(C, ot, window->eventstate, properties);
                        
                        /* set region back */
-                       C->region= ar;
+                       CTX_wm_region_set(C, ar);
                        
                        return retval;
                }
                else if(context == WM_OP_AREA) {
                        /* remove region from context */
-                       ARegion *ar= C->region;
+                       ARegion *ar= CTX_wm_region(C);
 
-                       C->region= NULL;
-                       retval= wm_operator_invoke(C, ot, C->window->eventstate, properties);
-                       C->region= ar;
+                       CTX_wm_region_set(C, NULL);
+                       retval= wm_operator_invoke(C, ot, window->eventstate, properties);
+                       CTX_wm_region_set(C, ar);
 
                        return retval;
                }
                else if(context == WM_OP_SCREEN) {
                        /* remove region + area from context */
-                       ARegion *ar= C->region;
-                       ScrArea *area= C->area;
+                       ARegion *ar= CTX_wm_region(C);
+                       ScrArea *area= CTX_wm_area(C);
 
-                       C->region= NULL;
-                       C->area= NULL;
-                       retval= wm_operator_invoke(C, ot, C->window->eventstate, properties);
-                       C->region= ar;
-                       C->area= area;
+                       CTX_wm_region_set(C, NULL);
+                       CTX_wm_area_set(C, NULL);
+                       retval= wm_operator_invoke(C, ot, window->eventstate, properties);
+                       CTX_wm_region_set(C, ar);
+                       CTX_wm_area_set(C, area);
 
                        return retval;
                }
                else
-                       return wm_operator_invoke(C, ot, C->window->eventstate, properties);
+                       return wm_operator_invoke(C, ot, window->eventstate, properties);
        }
        
        return 0;
@@ -386,31 +390,31 @@ void WM_event_remove_handlers(bContext *C, ListBase *handlers)
                
                if(handler->op) {
                        if(handler->op->type->cancel) {
-                               ScrArea *area= C->area;
-                               ARegion *region= C->region;
+                               ScrArea *area= CTX_wm_area(C);
+                               ARegion *region= CTX_wm_region(C);
                                
-                               C->area= handler->op_area;
-                               C->region= handler->op_region;
+                               CTX_wm_area_set(C, handler->op_area);
+                               CTX_wm_region_set(C, handler->op_region);
 
                                handler->op->type->cancel(C, handler->op);
 
-                               C->area= area;
-                               C->region= region;
+                               CTX_wm_area_set(C, area);
+                               CTX_wm_region_set(C, region);
                        }
 
                        wm_operator_free(handler->op);
                }
                else if(handler->ui_remove) {
-                       ScrArea *area= C->area;
-                       ARegion *region= C->region;
+                       ScrArea *area= CTX_wm_area(C);
+                       ARegion *region= CTX_wm_region(C);
                        
-                       if(handler->ui_area) C->area= handler->ui_area;
-                       if(handler->ui_region) C->region= handler->ui_region;
+                       if(handler->ui_area) CTX_wm_area_set(C, handler->ui_area);
+                       if(handler->ui_region) CTX_wm_region_set(C, handler->ui_region);
 
                        handler->ui_remove(C, handler->ui_userdata);
 
-                       C->area= area;
-                       C->region= region;
+                       CTX_wm_area_set(C, area);
+                       CTX_wm_region_set(C, region);
                }
 
                wm_event_free_handler(handler);
@@ -449,20 +453,20 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand
 
                if(ot->modal) {
                        /* we set context to where modal handler came from */
-                       ScrArea *area= C->area;
-                       ARegion *region= C->region;
+                       ScrArea *area= CTX_wm_area(C);
+                       ARegion *region= CTX_wm_region(C);
                        
-                       C->area= handler->op_area;
-                       C->region= handler->op_region;
+                       CTX_wm_area_set(C, handler->op_area);
+                       CTX_wm_region_set(C, handler->op_region);
                        
                        retval= ot->modal(C, op, event);
 
                        /* putting back screen context */
-                       C->area= area;
-                       C->region= region;
+                       CTX_wm_area_set(C, area);
+                       CTX_wm_region_set(C, region);
                        
                        if((retval & OPERATOR_FINISHED) && (ot->flag & OPTYPE_REGISTER)) {
-                               wm_operator_register(C->wm, op);
+                               wm_operator_register(CTX_wm_manager(C), op);
                                handler->op= NULL;
                        }
                        else if(retval & (OPERATOR_CANCELLED|OPERATOR_FINISHED)) {
@@ -500,19 +504,19 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand
 
 static int wm_handler_ui_call(bContext *C, wmEventHandler *handler, wmEvent *event)
 {
-       ScrArea *area= C->area;
-       ARegion *region= C->region;
+       ScrArea *area= CTX_wm_area(C);
+       ARegion *region= CTX_wm_region(C);
        int retval;
                        
        /* we set context to where ui handler came from */
-       if(handler->ui_area) C->area= handler->ui_area;
-       if(handler->ui_region) C->region= handler->ui_region;
+       if(handler->ui_area) CTX_wm_area_set(C, handler->ui_area);
+       if(handler->ui_region) CTX_wm_region_set(C, handler->ui_region);
 
        retval= handler->ui_handle(C, event, handler->ui_userdata);
 
        /* putting back screen context */
-       C->area= area;
-       C->region= region;
+       CTX_wm_area_set(C, area);
+       CTX_wm_region_set(C, region);
 
        if(retval == WM_UI_HANDLER_BREAK)
                return WM_HANDLER_BREAK;
@@ -564,7 +568,7 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers)
                                for(kmi= handler->keymap->first; kmi; kmi= kmi->next) {
                                        if(wm_eventmatch(event, kmi)) {
                                                if((G.f & G_DEBUG) && event->type!=MOUSEMOVE)
-                                                       printf("handle evt %d win %d op %s\n", event->type, C->window->winid, kmi->idname); 
+                                                       printf("handle evt %d win %d op %s\n", event->type, CTX_wm_window(C)->winid, kmi->idname); 
                                                
                                                event->keymap_idname= kmi->idname;      /* weak, but allows interactive callback to not use rawkey */
                                                
@@ -610,10 +614,11 @@ static int wm_event_prev_inside_i(wmEvent *event, rcti *rect)
 
 static ScrArea *area_event_inside(bContext *C, wmEvent *event)
 {
+       bScreen *screen= CTX_wm_screen(C);
        ScrArea *sa;
        
-       if(C->screen)
-               for(sa= C->screen->areabase.first; sa; sa= sa->next)
+       if(screen)
+               for(sa= screen->areabase.first; sa; sa= sa->next)
                        if(BLI_in_rcti(&sa->totrct, event->x, event->y))
                                return sa;
        return NULL;
@@ -621,10 +626,12 @@ static ScrArea *area_event_inside(bContext *C, wmEvent *event)
 
 static ARegion *region_event_inside(bContext *C, wmEvent *event)
 {
+       bScreen *screen= CTX_wm_screen(C);
+       ScrArea *area= CTX_wm_area(C);
        ARegion *ar;
        
-       if(C->screen && C->area)
-               for(ar= C->area->regionbase.first; ar; ar= ar->next)
+       if(screen && area)
+               for(ar= area->regionbase.first; ar; ar= ar->next)
                        if(BLI_in_rcti(&ar->winrct, event->x, event->y))
                                return ar;
        return NULL;
@@ -637,7 +644,7 @@ void wm_event_do_handlers(bContext *C)
 {
        wmWindow *win;
 
-       for(win= C->wm->windows.first; win; win= win->next) {
+       for(win= CTX_wm_manager(C)->windows.first; win; win= win->next) {
                wmEvent *event;
                
                if( win->screen==NULL )
@@ -646,10 +653,9 @@ void wm_event_do_handlers(bContext *C)
                while( (event=wm_event_next(win)) ) {
                        int action;
 
-                       C->window= win;
-                       C->screen= win->screen;
-                       C->area= area_event_inside(C, event);
-                       C->region= region_event_inside(C, event);
+                       CTX_wm_window_set(C, win);
+                       CTX_wm_area_set(C, area_event_inside(C, event));
+                       CTX_wm_region_set(C, region_event_inside(C, event));
                        
                        /* MVC demands to not draw in event handlers... for now we leave it */
                        wm_window_make_drawable(C, win);
@@ -668,15 +674,15 @@ void wm_event_do_handlers(bContext *C)
                                for(sa= win->screen->areabase.first; sa; sa= sa->next) {
                                        if(wm_event_always_pass(event) || wm_event_prev_inside_i(event, &sa->totrct)) {
                                                doit= 1;
-                                               C->area= sa;
+                                               CTX_wm_area_set(C, sa);
                                                action= wm_handlers_do(C, event, &sa->handlers);
 
                                                if(wm_event_always_pass(event) || action==WM_HANDLER_CONTINUE) {
                                                        for(ar=sa->regionbase.first; ar; ar= ar->next) {
                                                                if(wm_event_always_pass(event) || wm_event_inside_i(event, &ar->winrct) || wm_event_prev_inside_i(event, &ar->winrct)) {
-                                                                       C->region= ar;
+                                                                       CTX_wm_region_set(C, ar);
                                                                        action= wm_handlers_do(C, event, &ar->handlers);
-                                                                       C->region= NULL;
+                                                                       CTX_wm_region_set(C, NULL);
 
                                                                        if(!wm_event_always_pass(event)) {
                                                                                if(action==WM_HANDLER_BREAK)
@@ -686,21 +692,20 @@ void wm_event_do_handlers(bContext *C)
                                                        }
                                                }
 
-                                               C->area= NULL;
+                                               CTX_wm_area_set(C, NULL);
                                                /* NOTE: do not escape on WM_HANDLER_BREAK, mousemove needs handled for previous area */
                                        }
                                }
                                /* XXX hrmf, this gives reliable previous mouse coord for area change, feels bad? 
                                   doing it on ghost queue gives errors when mousemoves go over area borders */
                                if(doit) {
-                                       C->window->eventstate->prevx= event->x;
-                                       C->window->eventstate->prevy= event->y;
+                                       CTX_wm_window(C)->eventstate->prevx= event->x;
+                                       CTX_wm_window(C)->eventstate->prevy= event->y;
                                }
                        }
                        wm_event_free(event);
                        
-                       C->window= NULL;
-                       C->screen= NULL;
+                       CTX_wm_window_set(C, NULL);
                }
        }
 }
@@ -715,8 +720,8 @@ wmEventHandler *WM_event_add_modal_handler(bContext *C, ListBase *handlers, wmOp
 {
        wmEventHandler *handler= MEM_callocN(sizeof(wmEventHandler), "event modal handler");
        handler->op= op;
-       handler->op_area= C->area;              /* means frozen screen context for modal handlers! */
-       handler->op_region= C->region;
+       handler->op_area= CTX_wm_area(C);               /* means frozen screen context for modal handlers! */
+       handler->op_region= CTX_wm_region(C);
        
        BLI_addhead(handlers, handler);
 
@@ -768,8 +773,8 @@ wmEventHandler *WM_event_add_ui_handler(bContext *C, ListBase *handlers, wmUIHan
        handler->ui_handle= func;
        handler->ui_remove= remove;
        handler->ui_userdata= userdata;
-       handler->ui_area= (C)? C->area: NULL;
-       handler->ui_region= (C)? C->region: NULL;
+       handler->ui_area= (C)? CTX_wm_area(C): NULL;
+       handler->ui_region= (C)? CTX_wm_region(C): NULL;
        
        BLI_addhead(handlers, handler);
        
@@ -792,11 +797,12 @@ void WM_event_remove_ui_handler(ListBase *handlers, wmUIHandlerFunc func, wmUIHa
 
 void WM_event_add_mousemove(bContext *C)
 {
-       wmEvent event= *(C->window->eventstate);
+       wmWindow *window= CTX_wm_window(C);
+       wmEvent event= *(window->eventstate);
        event.type= MOUSEMOVE;
        event.prevx= event.x;
        event.prevy= event.y;
-       wm_event_add(C->window, &event);
+       wm_event_add(window, &event);
 }
 
 /* ********************* ghost stuff *************** */
index 75306dc75d84aa60e2b55dcb9b9ef2530d429f07..b6d8ea59a48e5157ad3c82a40db96365a01b6cbe 100644 (file)
@@ -57,6 +57,7 @@
 #include "DNA_windowmanager_types.h"
 
 #include "BKE_blender.h"
+#include "BKE_context.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_exotic.h"
 #include "BKE_font.h"
@@ -373,7 +374,7 @@ return;
        /* we take apart the used screens from non-active window */
        for(win= wm->windows.first; win; win= win->next) {
                BLI_strncpy(win->screenname, win->screen->id.name, MAX_ID_NAME);
-               if(win!=C->wm->winactive) {
+               if(win!=wm->winactive) {
                        BLI_remlink(&G.main->screen, win->screen);
                        //BLI_addtail(screenbase, win->screen);
                }
@@ -410,7 +411,7 @@ static void wm_window_match_do(bContext *C, ListBase *wmlist)
                                        win->screen= (bScreen *)find_id("SR", win->screenname);
 
                                        if(win->screen==NULL)
-                                               win->screen= ED_screen_duplicate(win, C->screen); /* active screen */
+                                               win->screen= ED_screen_duplicate(win, CTX_wm_screen(C)); /* active screen */
                                                        
                                        if(win->screen->winid==0)
                                                win->screen->winid= win->winid;
@@ -807,7 +808,7 @@ void WM_write_file(bContext *C, char *target)
        }
  
        /* send the OnSave event */
-// XXX if (G.f & G_DOSCRIPTLINKS) BPY_do_pyscript(&C->scene->id, SCRIPT_ONSAVE);
+// XXX if (G.f & G_DOSCRIPTLINKS) BPY_do_pyscript(&CTX_data_scene(C)->id, SCRIPT_ONSAVE);
 
        for (li= G.main->library.first; li; li= li->id.next) {
                if (BLI_streq(li->name, target)) {
index ba8da93495c4d59bc497bd63129407ea207dbe21..e6e5186f8b146eee24df33bd0073e43ca6dec404 100644 (file)
@@ -37,7 +37,7 @@
 
 #include "BLI_blenlib.h"
 
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_utildefines.h"
 
 #include "WM_api.h"
 wmGesture *WM_gesture_new(bContext *C, wmEvent *event, int type)
 {
        wmGesture *gesture= MEM_callocN(sizeof(wmGesture), "new gesture");
+       wmWindow *window= CTX_wm_window(C);
+       bScreen *screen= CTX_wm_screen(C);
        int sx, sy;
        
-       BLI_addtail(&C->window->gesture, gesture);
+       BLI_addtail(&window->gesture, gesture);
        
        gesture->type= type;
        gesture->event_type= event->type;
-       gesture->swinid= C->screen->subwinactive;       /* means only in area-region context! */
+       gesture->swinid= screen->subwinactive;  /* means only in area-region context! */
        
-       wm_subwindow_getorigin(C->window, gesture->swinid, &sx, &sy);
+       wm_subwindow_getorigin(window, gesture->swinid, &sx, &sy);
        
        if( ELEM3(type, WM_GESTURE_RECT, WM_GESTURE_CROSS_RECT, WM_GESTURE_TWEAK)) {
                rcti *rect= MEM_callocN(sizeof(rcti), "gesture rect new");
@@ -79,7 +81,7 @@ wmGesture *WM_gesture_new(bContext *C, wmEvent *event, int type)
 
 void WM_gesture_end(bContext *C, wmGesture *gesture)
 {
-       BLI_remlink(&C->window->gesture, gesture);
+       BLI_remlink(&CTX_wm_window(C)->gesture, gesture);
        MEM_freeN(gesture->customdata);
        MEM_freeN(gesture);
 }
index 8727a9cadfe030fc9c2b1ada552739ee2bbb6812..ae84ac269793723e67cc81f54045875905392073 100644 (file)
@@ -43,6 +43,7 @@
 #include "DNA_windowmanager_types.h"
 
 #include "BKE_blender.h"
+#include "BKE_context.h"
 #include "BKE_curve.h"
 #include "BKE_displist.h"
 #include "BKE_DerivedMesh.h"
@@ -165,10 +166,10 @@ void WM_exit(bContext *C)
        
        /* first wrap up running stuff, we assume only the active WM is running */
        /* modal handlers are on window level freed, others too? */
-       if(C && C->wm) {
-               for(win= C->wm->windows.first; win; win= win->next) {
+       if(C && CTX_wm_manager(C)) {
+               for(win= CTX_wm_manager(C)->windows.first; win; win= win->next) {
                        
-                       C->window= win; /* needed by operator close callbacks */
+                       CTX_wm_window_set(C, win);      /* needed by operator close callbacks */
                        WM_event_remove_handlers(C, &win->handlers);
                        ED_screen_exit(C, win, win->screen);
                }
@@ -258,7 +259,7 @@ void WM_exit(bContext *C)
 
        RNA_exit();
        
-       MEM_freeN(C);
+       CTX_free(C);
        
        if(MEM_get_memory_blocks_in_use()!=0) {
                printf("Error Totblock: %d\n", MEM_get_memory_blocks_in_use());
index 139fff45b483ecfcde521f04e3567eb9a71b202f..a7ce67aeeba8e1be3252157e10b906690ff0aad2 100644 (file)
@@ -36,7 +36,7 @@
 #include "BLI_blenlib.h"
 
 #include "BKE_blender.h"
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 
@@ -515,8 +515,8 @@ char *WM_key_event_operator_string(bContext *C, char *opname, int opcontext, cha
 
        /* find right handler list based on specified context */
        if(opcontext == WM_OP_REGION_WIN) {
-               if(C->area) {
-                       ARegion *ar= C->area->regionbase.first;
+               if(CTX_wm_area(C)) {
+                       ARegion *ar= CTX_wm_area(C)->regionbase.first;
                        for(; ar; ar= ar->next)
                                if(ar->regiontype==RGN_TYPE_WINDOW)
                                        break;
@@ -526,16 +526,16 @@ char *WM_key_event_operator_string(bContext *C, char *opname, int opcontext, cha
                }
        }
        else if(opcontext == WM_OP_AREA) {
-               if(C->area)
-                       handlers= &C->area->handlers;
+               if(CTX_wm_area(C))
+                       handlers= &CTX_wm_area(C)->handlers;
        }
        else if(opcontext == WM_OP_SCREEN) {
-               if(C->window)
-                       handlers= &C->window->handlers;
+               if(CTX_wm_window(C))
+                       handlers= &CTX_wm_window(C)->handlers;
        }
        else {
-               if(C->region)
-                       handlers= &C->region->handlers;
+               if(CTX_wm_region(C))
+                       handlers= &CTX_wm_region(C)->handlers;
        }
 
        if(!handlers)
index 262052c442aa11a7a74c18c9c451c79cd8bb5238..6f5b09d7d95db29dfd2f656569c54335f71aedae 100644 (file)
@@ -37,7 +37,7 @@
 #include "BLI_blenlib.h"
 
 #include "BKE_blender.h"
-#include "BKE_global.h"
+#include "BKE_context.h"
 #include "BKE_idprop.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
@@ -109,7 +109,7 @@ int WM_operator_confirm(bContext *C, wmOperator *op, wmEvent *event)
 
 int WM_operator_winactive(bContext *C)
 {
-       if(C->window==NULL) return 0;
+       if(CTX_wm_window(C)==NULL) return 0;
        return 1;
 }
 
@@ -199,7 +199,7 @@ static void border_select_end(bContext *C, wmOperator *op)
        WM_gesture_end(C, gesture);     /* frees gesture itself, and unregisters from window */
        op->customdata= NULL;
 
-       ED_area_tag_redraw(C->area);
+       ED_area_tag_redraw(CTX_wm_area(C));
        
 }
 
@@ -208,7 +208,7 @@ int WM_border_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
        op->customdata= WM_gesture_new(C, event, WM_GESTURE_CROSS_RECT);
 
        /* add modal handler */
-       WM_event_add_modal_handler(C, &C->window->handlers, op);
+       WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
        
        WM_event_add_notifier(C, WM_NOTE_GESTURE_REDRAW, 0, NULL);
 
@@ -224,7 +224,7 @@ int WM_border_select_modal(bContext *C, wmOperator *op, wmEvent *event)
        switch(event->type) {
                case MOUSEMOVE:
                        
-                       wm_subwindow_getorigin(C->window, gesture->swinid, &sx, &sy);
+                       wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
                        
                        if(gesture->type==WM_GESTURE_CROSS_RECT && gesture->mode==0) {
                                rect->xmin= rect->xmax= event->x - sx;
@@ -268,7 +268,7 @@ static int tweak_gesture_invoke(bContext *C, wmOperator *op, wmEvent *event)
        op->customdata= WM_gesture_new(C, event, WM_GESTURE_TWEAK);
        
        /* add modal handler */
-       WM_event_add_modal_handler(C, &C->window->handlers, op);
+       WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
        
        WM_event_add_notifier(C, WM_NOTE_GESTURE_REDRAW, 0, NULL);
        
@@ -282,12 +282,13 @@ static void tweak_gesture_end(bContext *C, wmOperator *op)
        WM_gesture_end(C, gesture);     /* frees gesture itself, and unregisters from window */
        op->customdata= NULL;
 
-       ED_area_tag_redraw(C->area);
+       ED_area_tag_redraw(CTX_wm_area(C));
        
 }
 
 static int tweak_gesture_modal(bContext *C, wmOperator *op, wmEvent *event)
 {
+       wmWindow *window= CTX_wm_window(C);
        wmGesture *gesture= op->customdata;
        rcti *rect= gesture->customdata;
        int sx, sy, val;
@@ -295,7 +296,7 @@ static int tweak_gesture_modal(bContext *C, wmOperator *op, wmEvent *event)
        switch(event->type) {
                case MOUSEMOVE:
                        
-                       wm_subwindow_getorigin(C->window, gesture->swinid, &sx, &sy);
+                       wm_subwindow_getorigin(window, gesture->swinid, &sx, &sy);
                        
                        rect->xmax= event->x - sx;
                        rect->ymax= event->y - sy;
@@ -303,7 +304,7 @@ static int tweak_gesture_modal(bContext *C, wmOperator *op, wmEvent *event)
                        if((val= wm_gesture_evaluate(C, gesture))) {
                                wmEvent event;
                                        
-                               event= *(C->window->eventstate);
+                               event= *(window->eventstate);
                                if(gesture->event_type==LEFTMOUSE)
                                        event.type= EVT_TWEAK_L;
                                else if(gesture->event_type==RIGHTMOUSE)
@@ -312,7 +313,7 @@ static int tweak_gesture_modal(bContext *C, wmOperator *op, wmEvent *event)
                                        event.type= EVT_TWEAK_M;
                                event.val= val;
                                /* mouse coords! */
-                               wm_event_add(C->window, &event);
+                               wm_event_add(window, &event);
                                
                                tweak_gesture_end(C, op);
                                return OPERATOR_FINISHED;
diff --git a/source/blender/windowmanager/intern/wm_report.c b/source/blender/windowmanager/intern/wm_report.c
deleted file mode 100644 (file)
index 3be991e..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-
-#include "MEM_guardedalloc.h"
-
-#include "DNA_windowmanager_types.h"
-
-#include "BLI_blenlib.h"
-
-#include "BKE_global.h"
-
-#include "WM_api.h"
-#include "WM_types.h"
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-
-#ifdef _WIN32
-#ifndef vsnprintf
-#define vsnprintf _vsnprintf
-#endif
-#endif
-
-static int wmReportLevel= WM_LOG_INFO;
-static int wmReportPrint= 0;
-
-static const char *wm_report_type_str(int type)
-{
-       switch(type) {
-               case WM_LOG_DEBUG: return "Debug";
-               case WM_LOG_INFO: return "Info";
-               case WM_LOG_WARNING: return "Warning";
-               case WM_ERROR_UNDEFINED: return "Error";
-               case WM_ERROR_INVALID_INPUT: return "Invalid Input Error";
-               case WM_ERROR_INVALID_CONTEXT: return "Invalid Context Error";
-               case WM_ERROR_OUT_OF_MEMORY: return "Out Of Memory Error";
-               default: return "Undefined Type";
-       }
-}
-
-static void wm_print_report(wmReport *report)
-{
-       printf("%s: %s\n", report->typestr, report->message);
-       fflush(stdout); /* this ensures the message is printed before a crash */
-}
-
-void WM_report(bContext *C, int type, const char *message)
-{
-       wmReport *report;
-       int len;
-
-       if(!C->wm) {
-               fprintf(stderr, "WM_report: can't report without windowmanager.\n");
-               return;
-       }
-       if(type < wmReportLevel)
-               return;
-
-       report= MEM_callocN(sizeof(wmReport), "wmReport");
-       report->type= type;
-       report->typestr= wm_report_type_str(type);
-
-       len= strlen(message);
-       report->message= MEM_callocN(sizeof(char)*(len+1), "wmReportMessage");
-       memcpy(report->message, message, sizeof(char)*(len+1));
-
-       if(wmReportPrint)
-               wm_print_report(report);
-       
-       BLI_addtail(&C->wm->reports, report);
-}
-
-void WM_reportf(bContext *C, int type, const char *format, ...)
-{
-       wmReport *report;
-       va_list args;
-       char *message;
-       int len= 256, maxlen= 65536, retval;
-
-       if(!C->wm) {
-               fprintf(stderr, "WM_report: can't report without windowmanager.\n");
-               return;
-       }
-       if(type < wmReportLevel)
-               return;
-
-       while(1) {
-               message= MEM_callocN(sizeof(char)*len+1, "wmReportMessage");
-
-               va_start(args, format);
-               retval= vsnprintf(message, len, format, args);
-               va_end(args);
-
-               if(retval == -1) {
-                       /* -1 means not enough space, but on windows it may also mean
-                        * there is a formatting error, so we impose a maximum length */
-                       MEM_freeN(message);
-                       message= NULL;
-
-                       len *= 2;
-                       if(len > maxlen) {
-                               fprintf(stderr, "WM_report message too long or format error.\n");
-                               break;
-                       }
-               }
-               else if(retval > len) {
-                       /* in C99 the actual length required is returned */
-                       MEM_freeN(message);
-                       message= NULL;
-
-                       len= retval;
-               }
-               else
-                       break;
-       }
-
-       if(message) {
-               report= MEM_callocN(sizeof(wmReport), "wmReport");
-               report->type= type;
-               report->typestr= wm_report_type_str(type);
-               report->message= message;
-
-               if(wmReportPrint)
-                       wm_print_report(report);
-
-               BLI_addtail(&C->wm->reports, report);
-       }
-}
-
-void wm_report_free(wmReport *report)
-{
-       MEM_freeN(report->message);
-       MEM_freeN(report);
-}
-
index cfd111d355c849fa84ed4dde4d77d9bc8d974678..56574829b535c3c47146153808aebeef8edf48ac 100644 (file)
@@ -40,6 +40,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_arithb.h"
 
+#include "BKE_context.h"
 #include "BKE_global.h"
 
 #include "BIF_gl.h"
index 84c003c8a00225ad91894a8e77d3093374d7d2d3..f3c5f626f48d738ea3e3dacff2f46e0e943df4e7 100644 (file)
@@ -40,6 +40,7 @@
 #include "BLI_blenlib.h"
 
 #include "BKE_blender.h"
+#include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_utildefines.h"
 
@@ -88,14 +89,14 @@ void wm_window_free(bContext *C, wmWindow *win)
 {
        /* update context */
        if(C) {
-               if(C->wm->windrawable==win)
-                       C->wm->windrawable= NULL;
-               if(C->wm->winactive==win)
-                       C->wm->winactive= NULL;
-               if(C->window==win)
-                       C->window= NULL;
-               if(C->screen==win->screen)
-                       C->screen= NULL;
+               wmWindowManager *wm= CTX_wm_manager(C);
+
+               if(wm->windrawable==win)
+                       wm->windrawable= NULL;
+               if(wm->winactive==win)
+                       wm->winactive= NULL;
+               if(CTX_wm_window(C)==win)
+                       CTX_wm_window_set(C, NULL);
        }       
        
        if(win->eventstate) MEM_freeN(win->eventstate);
@@ -123,10 +124,11 @@ static int find_free_winid(wmWindowManager *wm)
 /* dont change context itself */
 wmWindow *wm_window_new(bContext *C)
 {
+       wmWindowManager *wm= CTX_wm_manager(C);
        wmWindow *win= MEM_callocN(sizeof(wmWindow), "window");
        
-       BLI_addtail(&C->wm->windows, win);
-       win->winid= find_free_winid(C->wm);
+       BLI_addtail(&wm->windows, win);
+       win->winid= find_free_winid(wm);
 
        return win;
 }
@@ -152,12 +154,13 @@ wmWindow *wm_window_copy(bContext *C, wmWindow *winorig)
 /* this is event from ghost */
 static void wm_window_close(bContext *C, wmWindow *win)
 {
-       BLI_remlink(&C->wm->windows, win);
+       wmWindowManager *wm= CTX_wm_manager(C);
+       BLI_remlink(&wm->windows, win);
        
        ED_screen_exit(C, win, win->screen);
        wm_window_free(C, win);
        
-       if(C->wm->windows.first==NULL)
+       if(wm->windows.first==NULL)
                WM_exit(C);
 }
 
@@ -256,6 +259,7 @@ void wm_window_add_ghostwindows(wmWindowManager *wm)
 /* area-rip calls this */
 wmWindow *WM_window_open(bContext *C, rcti *rect)
 {
+       wmWindowManager *wm= CTX_wm_manager(C);
        wmWindow *win= wm_window_new(C);
        
        win->posx= rect->xmin;
@@ -263,7 +267,7 @@ wmWindow *WM_window_open(bContext *C, rcti *rect)
        win->sizex= rect->xmax - rect->xmin;
        win->sizey= rect->ymax - rect->ymin;
        
-       wm_window_add_ghostwindow(C->wm, "Blender", win);
+       wm_window_add_ghostwindow(wm, "Blender", win);
        
        return win;
 }
@@ -274,7 +278,7 @@ wmWindow *WM_window_open(bContext *C, rcti *rect)
 /* operator callback */
 int wm_window_duplicate_op(bContext *C, wmOperator *op)
 {
-       wm_window_copy(C, C->window);
+       wm_window_copy(C, CTX_wm_window(C));
        wm_check(C);
        
        return OPERATOR_FINISHED;
@@ -284,11 +288,12 @@ int wm_window_duplicate_op(bContext *C, wmOperator *op)
 /* fullscreen operator callback */
 int wm_window_fullscreen_toggle_op(bContext *C, wmOperator *op)
 {
-       GHOST_TWindowState state = GHOST_GetWindowState(C->window->ghostwin);
+       wmWindow *window= CTX_wm_window(C);
+       GHOST_TWindowState state = GHOST_GetWindowState(window->ghostwin);
        if(state!=GHOST_kWindowStateFullScreen)
-               GHOST_SetWindowState(C->window->ghostwin, GHOST_kWindowStateFullScreen);
+               GHOST_SetWindowState(window->ghostwin, GHOST_kWindowStateFullScreen);
        else
-               GHOST_SetWindowState(C->window->ghostwin, GHOST_kWindowStateNormal);
+               GHOST_SetWindowState(window->ghostwin, GHOST_kWindowStateNormal);
 
        return OPERATOR_FINISHED;
        
@@ -298,7 +303,9 @@ int wm_window_fullscreen_toggle_op(bContext *C, wmOperator *op)
 /* exit blender */
 int wm_exit_blender_op(bContext *C, wmOperator *op)
 {
-       wmWindow *win= C->wm->windows.first;
+       wmWindowManager *wm= CTX_wm_manager(C);
+       wmWindow *win= wm->windows.first;
+
        while(win) {
                wm_window_close(C, win);
                win= win->next;
@@ -337,10 +344,12 @@ static int query_qual(char qual)
 
 void wm_window_make_drawable(bContext *C, wmWindow *win) 
 {
-       if (win != C->wm->windrawable && win->ghostwin) {
+       wmWindowManager *wm= CTX_wm_manager(C);
+
+       if (win != wm->windrawable && win->ghostwin) {
 //             win->lmbut= 0;  /* keeps hanging when mousepressed while other window opened */
                
-               C->wm->windrawable= win;
+               wm->windrawable= win;
                if(G.f & G_DEBUG) printf("set drawable %d\n", win->winid);
                GHOST_ActivateWindowDrawingContext(win->ghostwin);
        }
@@ -382,7 +391,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private)
                                GHOST_TEventKeyData kdata;
                                int cx, cy, wx, wy;
                                
-                               C->wm->winactive= win; /* no context change! c->wm->windrawable is drawable, or for area queues */
+                               CTX_wm_manager(C)->winactive= win; /* no context change! c->wm->windrawable is drawable, or for area queues */
                                
                                win->active= 1;
 //                             window_handle(win, INPUTCHANGE, win->active);
index 8cb436f4d6d7a1556cab9c94357b28e5ccf9e117..f96edf99029dde87a690c117dfa1d0a55d7b64d6 100644 (file)
@@ -53,6 +53,7 @@
 
 #include "BKE_utildefines.h"
 #include "BKE_blender.h"
+#include "BKE_context.h"
 #include "BKE_font.h"
 #include "BKE_global.h"
 #include "BKE_main.h"
@@ -261,7 +262,7 @@ double PIL_check_seconds_timer(void);
 int main(int argc, char **argv)
 {
        SYS_SystemHandle syshandle;
-       bContext *C= MEM_callocN(sizeof(bContext), "creator.c context");
+       bContext *C= CTX_create();
        int a, i, stax, stay, sizx, sizy /*XXX, scr_init = 0*/;
 
 #if defined(WIN32) || defined (__linux__)