|
Blender
V2.59
|
00001 /* 00002 * $Id: space_userpref.c 35403 2011-03-08 13:02:26Z ton $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2008 Blender Foundation. 00021 * All rights reserved. 00022 * 00023 * 00024 * Contributor(s): Blender Foundation 00025 * 00026 * ***** END GPL LICENSE BLOCK ***** 00027 */ 00028 00034 #include <string.h> 00035 #include <stdio.h> 00036 00037 00038 #include "MEM_guardedalloc.h" 00039 00040 #include "BLI_blenlib.h" 00041 #include "BLI_utildefines.h" 00042 00043 #include "BKE_context.h" 00044 #include "BKE_screen.h" 00045 00046 #include "ED_screen.h" 00047 #include "ED_space_api.h" 00048 00049 #include "WM_api.h" 00050 #include "WM_types.h" 00051 00052 #include "UI_view2d.h" 00053 00054 #include "userpref_intern.h" // own include 00055 00056 /* ******************** default callbacks for userpref space ***************** */ 00057 00058 static SpaceLink *userpref_new(const bContext *UNUSED(C)) 00059 { 00060 ARegion *ar; 00061 SpaceUserPref *spref; 00062 00063 spref= MEM_callocN(sizeof(SpaceUserPref), "inituserpref"); 00064 spref->spacetype= SPACE_USERPREF; 00065 00066 /* header */ 00067 ar= MEM_callocN(sizeof(ARegion), "header for userpref"); 00068 00069 BLI_addtail(&spref->regionbase, ar); 00070 ar->regiontype= RGN_TYPE_HEADER; 00071 ar->alignment= RGN_ALIGN_BOTTOM; 00072 00073 /* main area */ 00074 ar= MEM_callocN(sizeof(ARegion), "main area for userpref"); 00075 00076 BLI_addtail(&spref->regionbase, ar); 00077 ar->regiontype= RGN_TYPE_WINDOW; 00078 00079 return (SpaceLink *)spref; 00080 } 00081 00082 /* not spacelink itself */ 00083 static void userpref_free(SpaceLink *UNUSED(sl)) 00084 { 00085 // SpaceUserPref *spref= (SpaceUserPref*) sl; 00086 00087 } 00088 00089 00090 /* spacetype; init callback */ 00091 static void userpref_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa)) 00092 { 00093 00094 } 00095 00096 static SpaceLink *userpref_duplicate(SpaceLink *sl) 00097 { 00098 SpaceUserPref *sprefn= MEM_dupallocN(sl); 00099 00100 /* clear or remove stuff from old */ 00101 00102 return (SpaceLink *)sprefn; 00103 } 00104 00105 00106 00107 /* add handlers, stuff you only do once or on area/region changes */ 00108 static void userpref_main_area_init(wmWindowManager *wm, ARegion *ar) 00109 { 00110 ED_region_panels_init(wm, ar); 00111 } 00112 00113 static void userpref_main_area_draw(const bContext *C, ARegion *ar) 00114 { 00115 /* this solves "vibrating UI" bug #25422 */ 00116 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_PANELS_UI, ar->winx, ar->winy); 00117 00118 ED_region_panels(C, ar, 1, NULL, -1); 00119 } 00120 00121 static void userpref_operatortypes(void) 00122 { 00123 } 00124 00125 static void userpref_keymap(struct wmKeyConfig *UNUSED(keyconf)) 00126 { 00127 00128 } 00129 00130 /* add handlers, stuff you only do once or on area/region changes */ 00131 static void userpref_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar) 00132 { 00133 ED_region_header_init(ar); 00134 } 00135 00136 static void userpref_header_area_draw(const bContext *C, ARegion *ar) 00137 { 00138 ED_region_header(C, ar); 00139 } 00140 00141 static void userpref_main_area_listener(ARegion *UNUSED(ar), wmNotifier *UNUSED(wmn)) 00142 { 00143 /* context changes */ 00144 } 00145 00146 static void userpref_header_listener(ARegion *UNUSED(ar), wmNotifier *UNUSED(wmn)) 00147 { 00148 /* context changes */ 00149 #if 0 00150 switch(wmn->category) { 00151 default: 00152 break; 00153 } 00154 #endif 00155 } 00156 00157 /* only called once, from space/spacetypes.c */ 00158 void ED_spacetype_userpref(void) 00159 { 00160 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype userpref"); 00161 ARegionType *art; 00162 00163 st->spaceid= SPACE_USERPREF; 00164 strncpy(st->name, "Userpref", BKE_ST_MAXNAME); 00165 00166 st->new= userpref_new; 00167 st->free= userpref_free; 00168 st->init= userpref_init; 00169 st->duplicate= userpref_duplicate; 00170 st->operatortypes= userpref_operatortypes; 00171 st->keymap= userpref_keymap; 00172 00173 /* regions: main window */ 00174 art= MEM_callocN(sizeof(ARegionType), "spacetype userpref region"); 00175 art->regionid = RGN_TYPE_WINDOW; 00176 art->init= userpref_main_area_init; 00177 art->draw= userpref_main_area_draw; 00178 art->listener= userpref_main_area_listener; 00179 art->keymapflag= ED_KEYMAP_UI; 00180 00181 BLI_addhead(&st->regiontypes, art); 00182 00183 /* regions: header */ 00184 art= MEM_callocN(sizeof(ARegionType), "spacetype userpref region"); 00185 art->regionid = RGN_TYPE_HEADER; 00186 art->prefsizey= HEADERY; 00187 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER; 00188 art->listener= userpref_header_listener; 00189 art->init= userpref_header_area_init; 00190 art->draw= userpref_header_area_draw; 00191 00192 BLI_addhead(&st->regiontypes, art); 00193 00194 00195 BKE_spacetype_register(st); 00196 } 00197