8b46617d55edc177c1a3d32fd4230aadfa174d72
[blender.git] / source / blender / editors / space_text / space_text.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31
32 #include "DNA_text_types.h"
33 #include "DNA_object_types.h"
34
35 #include "MEM_guardedalloc.h"
36
37 #include "BLI_blenlib.h"
38 #include "BLI_math.h"
39 #include "BLI_rand.h"
40
41 #include "BKE_colortools.h"
42 #include "BKE_context.h"
43 #include "BKE_screen.h"
44
45 #include "ED_screen.h"
46
47 #include "BIF_gl.h"
48
49 #include "WM_api.h"
50 #include "WM_types.h"
51
52 #include "UI_interface.h"
53 #include "UI_resources.h"
54 #include "UI_view2d.h"
55
56 #include "RNA_access.h"
57
58
59 #include "text_intern.h"        // own include
60
61 /* ******************** default callbacks for text space ***************** */
62
63 static SpaceLink *text_new(const bContext *C)
64 {
65         ARegion *ar;
66         SpaceText *stext;
67         
68         stext= MEM_callocN(sizeof(SpaceText), "inittext");
69         stext->spacetype= SPACE_TEXT;
70
71         stext->lheight= 12;
72         stext->tabnumber= 4;
73         
74         /* header */
75         ar= MEM_callocN(sizeof(ARegion), "header for text");
76         
77         BLI_addtail(&stext->regionbase, ar);
78         ar->regiontype= RGN_TYPE_HEADER;
79         ar->alignment= RGN_ALIGN_BOTTOM;
80         
81         /* main area */
82         ar= MEM_callocN(sizeof(ARegion), "main area for text");
83         
84         BLI_addtail(&stext->regionbase, ar);
85         ar->regiontype= RGN_TYPE_WINDOW;
86         
87         return (SpaceLink *)stext;
88 }
89
90 /* not spacelink itself */
91 static void text_free(SpaceLink *sl)
92 {       
93         SpaceText *stext= (SpaceText*) sl;
94         
95         stext->text= NULL;
96 }
97
98
99 /* spacetype; init callback */
100 static void text_init(struct wmWindowManager *wm, ScrArea *sa)
101 {
102
103 }
104
105 static SpaceLink *text_duplicate(SpaceLink *sl)
106 {
107         SpaceText *stextn= MEM_dupallocN(sl);
108         
109         /* clear or remove stuff from old */
110         
111         return (SpaceLink *)stextn;
112 }
113
114 static void text_listener(ScrArea *sa, wmNotifier *wmn)
115 {
116         SpaceText *st= sa->spacedata.first;
117
118         /* context changes */
119         switch(wmn->category) {
120                 case NC_TEXT:
121                         if(!wmn->reference || wmn->reference == st->text) {
122                                 ED_area_tag_redraw(sa);
123
124                                 if(wmn->action == NA_EDITED)
125                                         if(st->text)
126                                                 text_update_edited(st->text);
127                         }
128                         else if(wmn->data == ND_DISPLAY)
129                                 ED_area_tag_redraw(sa);
130
131                         break;
132                 case NC_SPACE:
133                         if(wmn->data == ND_SPACE_TEXT)
134                                 ED_area_tag_redraw(sa);
135                         break;
136         }
137 }
138
139 static void text_operatortypes(void)
140 {
141         WM_operatortype_append(TEXT_OT_new);
142         WM_operatortype_append(TEXT_OT_open);
143         WM_operatortype_append(TEXT_OT_reload);
144         WM_operatortype_append(TEXT_OT_unlink);
145         WM_operatortype_append(TEXT_OT_save);
146         WM_operatortype_append(TEXT_OT_save_as);
147         WM_operatortype_append(TEXT_OT_make_internal);
148         WM_operatortype_append(TEXT_OT_run_script);
149         WM_operatortype_append(TEXT_OT_refresh_pyconstraints);
150
151         WM_operatortype_append(TEXT_OT_paste);
152         WM_operatortype_append(TEXT_OT_copy);
153         WM_operatortype_append(TEXT_OT_cut);
154
155         WM_operatortype_append(TEXT_OT_convert_whitespace);
156         WM_operatortype_append(TEXT_OT_uncomment);
157         WM_operatortype_append(TEXT_OT_comment);
158         WM_operatortype_append(TEXT_OT_unindent);
159         WM_operatortype_append(TEXT_OT_indent);
160
161         WM_operatortype_append(TEXT_OT_markers_clear);
162         WM_operatortype_append(TEXT_OT_next_marker);
163         WM_operatortype_append(TEXT_OT_previous_marker);
164
165         WM_operatortype_append(TEXT_OT_select_line);
166         WM_operatortype_append(TEXT_OT_select_all);
167
168         WM_operatortype_append(TEXT_OT_jump);
169         WM_operatortype_append(TEXT_OT_move);
170         WM_operatortype_append(TEXT_OT_move_select);
171         WM_operatortype_append(TEXT_OT_delete);
172         WM_operatortype_append(TEXT_OT_overwrite_toggle);
173
174         WM_operatortype_append(TEXT_OT_cursor_set);
175         WM_operatortype_append(TEXT_OT_scroll);
176         WM_operatortype_append(TEXT_OT_scroll_bar);
177         WM_operatortype_append(TEXT_OT_line_number);
178
179         WM_operatortype_append(TEXT_OT_line_break);
180         WM_operatortype_append(TEXT_OT_insert);
181
182         WM_operatortype_append(TEXT_OT_properties);
183
184         WM_operatortype_append(TEXT_OT_find);
185         WM_operatortype_append(TEXT_OT_find_set_selected);
186         WM_operatortype_append(TEXT_OT_replace);
187         WM_operatortype_append(TEXT_OT_replace_set_selected);
188         WM_operatortype_append(TEXT_OT_mark_all);
189
190         WM_operatortype_append(TEXT_OT_to_3d_object);
191
192         WM_operatortype_append(TEXT_OT_resolve_conflict);
193 }
194
195 static void text_keymap(struct wmKeyConfig *keyconf)
196 {
197         wmKeyMap *keymap;
198         wmKeyMapItem *kmi;
199         
200         keymap= WM_keymap_find(keyconf, "Text", SPACE_TEXT, 0);
201         
202         #ifdef __APPLE__
203         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", LEFTARROWKEY, KM_PRESS, KM_OSKEY, 0)->ptr, "type", LINE_BEGIN);
204         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", RIGHTARROWKEY, KM_PRESS, KM_OSKEY, 0)->ptr, "type", LINE_BEGIN);
205         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0)->ptr, "type", LINE_BEGIN);
206         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0)->ptr, "type", LINE_BEGIN);
207         WM_keymap_add_item(keymap, "TEXT_OT_save", SKEY, KM_PRESS, KM_ALT|KM_OSKEY, 0);
208         WM_keymap_add_item(keymap, "TEXT_OT_save_as", SKEY, KM_PRESS, KM_ALT|KM_SHIFT|KM_OSKEY, 0);
209         WM_keymap_add_item(keymap, "TEXT_OT_cut", XKEY, KM_PRESS, KM_OSKEY, 0);
210         WM_keymap_add_item(keymap, "TEXT_OT_copy", CKEY, KM_PRESS, KM_OSKEY, 0); 
211         WM_keymap_add_item(keymap, "TEXT_OT_paste", VKEY, KM_PRESS, KM_OSKEY, 0);
212         WM_keymap_add_item(keymap, "TEXT_OT_properties", FKEY, KM_PRESS, KM_OSKEY, 0);
213         WM_keymap_add_item(keymap, "TEXT_OT_find_set_selected", EKEY, KM_PRESS, KM_OSKEY, 0);
214         WM_keymap_add_item(keymap, "TEXT_OT_find", GKEY, KM_PRESS, KM_OSKEY, 0);
215         WM_keymap_add_item(keymap, "TEXT_OT_select_all", AKEY, KM_PRESS, KM_OSKEY, 0);
216         WM_keymap_add_item(keymap, "TEXT_OT_select_line", AKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0);
217         #endif
218         
219         kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0);
220         RNA_string_set(kmi->ptr, "path", "space_data.font_size");
221         RNA_boolean_set(kmi->ptr, "reverse", 0);
222         
223         kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0);
224         RNA_string_set(kmi->ptr, "path", "space_data.font_size");
225         RNA_boolean_set(kmi->ptr, "reverse", 1);
226
227         kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
228         RNA_string_set(kmi->ptr, "path", "space_data.font_size");
229         RNA_boolean_set(kmi->ptr, "reverse", 0);
230         
231         kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PADMINUS, KM_PRESS, KM_CTRL, 0);
232         RNA_string_set(kmi->ptr, "path", "space_data.font_size");
233         RNA_boolean_set(kmi->ptr, "reverse", 1);
234         
235         WM_keymap_add_item(keymap, "TEXT_OT_new", NKEY, KM_PRESS, KM_ALT, 0);
236         WM_keymap_add_item(keymap, "TEXT_OT_open", OKEY, KM_PRESS, KM_ALT, 0);
237         WM_keymap_add_item(keymap, "TEXT_OT_reload", RKEY, KM_PRESS, KM_ALT, 0);
238         WM_keymap_add_item(keymap, "TEXT_OT_save", SKEY, KM_PRESS, KM_ALT, 0);
239         WM_keymap_add_item(keymap, "TEXT_OT_save_as", SKEY, KM_PRESS, KM_ALT|KM_SHIFT|KM_CTRL, 0);
240
241         WM_keymap_add_item(keymap, "TEXT_OT_run_script", PKEY, KM_PRESS, KM_ALT, 0);
242         
243         WM_keymap_add_item(keymap, "TEXT_OT_cut", XKEY, KM_PRESS, KM_CTRL, 0);
244         WM_keymap_add_item(keymap, "TEXT_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
245         WM_keymap_add_item(keymap, "TEXT_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
246
247         if(U.uiflag & USER_MMB_PASTE) // XXX not dynamic
248                 RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_paste", MIDDLEMOUSE, KM_PRESS, 0, 0)->ptr, "selection", 1);
249
250         WM_keymap_add_item(keymap, "TEXT_OT_jump", JKEY, KM_PRESS, KM_CTRL, 0);
251         WM_keymap_add_item(keymap, "TEXT_OT_find", GKEY, KM_PRESS, KM_CTRL, 0);
252         
253         WM_keymap_add_item(keymap, "TEXT_OT_properties", FKEY, KM_PRESS, KM_CTRL, 0);
254         WM_keymap_add_item(keymap, "TEXT_OT_replace", HKEY, KM_PRESS, KM_CTRL, 0);
255
256         WM_keymap_add_item(keymap, "TEXT_OT_to_3d_object", MKEY, KM_PRESS, KM_ALT, 0);
257
258         WM_keymap_add_item(keymap, "TEXT_OT_select_all", AKEY, KM_PRESS, KM_CTRL, 0);
259         WM_keymap_add_item(keymap, "TEXT_OT_select_line", AKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
260         
261
262         WM_keymap_add_item(keymap, "TEXT_OT_indent", TABKEY, KM_PRESS, 0, 0);
263         WM_keymap_add_item(keymap, "TEXT_OT_unindent", TABKEY, KM_PRESS, KM_SHIFT, 0);
264         WM_keymap_add_item(keymap, "TEXT_OT_uncomment", DKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
265
266         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", HOMEKEY, KM_PRESS, 0, 0)->ptr, "type", LINE_BEGIN);
267         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", ENDKEY, KM_PRESS, 0, 0)->ptr, "type", LINE_END);
268         
269         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", EKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", LINE_END);
270         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", EKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "type", LINE_END);
271         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", LEFTARROWKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_CHAR);
272         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", RIGHTARROWKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_CHAR);
273         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", LEFTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", PREV_WORD);
274         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", RIGHTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", NEXT_WORD);
275         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", UPARROWKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_LINE);
276         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", DOWNARROWKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_LINE);
277         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", PAGEUPKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_PAGE);
278         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", PAGEDOWNKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_PAGE);
279
280         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", HOMEKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", LINE_BEGIN);
281         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", ENDKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", LINE_END);
282         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_CHAR);
283         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_CHAR);
284         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", PREV_WORD);
285         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", NEXT_WORD);
286         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", UPARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_LINE);
287         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", DOWNARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_LINE);
288         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", PAGEUPKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_PAGE);
289         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", PAGEDOWNKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_PAGE);
290
291         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DELKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_NEXT_CHAR);
292         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_NEXT_CHAR);
293         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", BACKSPACEKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_PREV_CHAR);
294         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DELKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_NEXT_WORD);
295         RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", BACKSPACEKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_PREV_WORD);
296
297         WM_keymap_add_item(keymap, "TEXT_OT_overwrite_toggle", INSERTKEY, KM_PRESS, 0, 0);
298
299         WM_keymap_add_item(keymap, "TEXT_OT_scroll", MIDDLEMOUSE, KM_PRESS, 0, 0);
300         WM_keymap_add_item(keymap, "TEXT_OT_scroll", MOUSEPAN, 0, 0, 0);
301         WM_keymap_add_item(keymap, "TEXT_OT_scroll_bar", LEFTMOUSE, KM_PRESS, 0, 0);
302         WM_keymap_add_item(keymap, "TEXT_OT_cursor_set", LEFTMOUSE, KM_PRESS, 0, 0);
303         RNA_boolean_set(WM_keymap_add_item(keymap, "TEXT_OT_cursor_set", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "select", 1);
304         RNA_int_set(WM_keymap_add_item(keymap, "TEXT_OT_scroll", WHEELUPMOUSE, KM_PRESS, 0, 0)->ptr, "lines", -1);
305         RNA_int_set(WM_keymap_add_item(keymap, "TEXT_OT_scroll", WHEELDOWNMOUSE, KM_PRESS, 0, 0)->ptr, "lines", 1);
306
307         WM_keymap_add_item(keymap, "TEXT_OT_line_break", RETKEY, KM_PRESS, 0, 0);
308         WM_keymap_add_item(keymap, "TEXT_OT_line_break", PADENTER, KM_PRESS, 0, 0);
309
310         WM_keymap_add_item(keymap, "TEXT_OT_line_number", KM_TEXTINPUT, KM_ANY, KM_ANY, 0);
311         WM_keymap_add_item(keymap, "TEXT_OT_insert", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); // last!
312 }
313
314 static int text_context(const bContext *C, const char *member, bContextDataResult *result)
315 {
316         SpaceText *st= CTX_wm_space_text(C);
317
318         if(CTX_data_dir(member)) {
319                 static const char *dir[] = {"edit_text", NULL};
320                 CTX_data_dir_set(result, dir);
321                 return 1;
322         }
323         else if(CTX_data_equals(member, "edit_text")) {
324                 CTX_data_id_pointer_set(result, &st->text->id);
325                 return 1;
326         }
327
328         return 0;
329 }
330
331 /********************* main region ********************/
332
333 /* add handlers, stuff you only do once or on area/region changes */
334 static void text_main_area_init(wmWindowManager *wm, ARegion *ar)
335 {
336         wmKeyMap *keymap;
337         
338         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
339         
340         /* own keymap */
341         keymap= WM_keymap_find(wm->defaultconf, "Text", SPACE_TEXT, 0);
342         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
343 }
344
345 static void text_main_area_draw(const bContext *C, ARegion *ar)
346 {
347         /* draw entirely, view changes should be handled here */
348         SpaceText *st= CTX_wm_space_text(C);
349         //View2D *v2d= &ar->v2d;
350         
351         /* clear and setup matrix */
352         UI_ThemeClearColor(TH_BACK);
353         glClear(GL_COLOR_BUFFER_BIT);
354         
355         // UI_view2d_view_ortho(C, v2d);
356                 
357         /* data... */
358         draw_text_main(st, ar);
359         
360         /* reset view matrix */
361         // UI_view2d_view_restore(C);
362         
363         /* scrollers? */
364 }
365
366 static void text_cursor(wmWindow *win, ScrArea *sa, ARegion *ar)
367 {
368         WM_cursor_set(win, BC_TEXTEDITCURSOR);
369 }
370
371
372
373 /* ************* dropboxes ************* */
374
375 static int text_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
376 {
377         if(drag->type==WM_DRAG_PATH)
378                 if(ELEM(drag->icon, 0, ICON_FILE_BLANK))        /* rule might not work? */
379                         return 1;
380         return 0;
381 }
382
383 static void text_drop_copy(wmDrag *drag, wmDropBox *drop)
384 {
385         /* copy drag path to properties */
386         RNA_string_set(drop->ptr, "path", drag->path);
387 }
388
389 /* this region dropbox definition */
390 static void text_dropboxes(void)
391 {
392         ListBase *lb= WM_dropboxmap_find("Text", SPACE_TEXT, RGN_TYPE_WINDOW);
393         
394         WM_dropbox_add(lb, "TEXT_OT_open", text_drop_poll, text_drop_copy);
395
396 }
397
398 /* ************* end drop *********** */
399
400
401 /****************** header region ******************/
402
403 /* add handlers, stuff you only do once or on area/region changes */
404 static void text_header_area_init(wmWindowManager *wm, ARegion *ar)
405 {
406         ED_region_header_init(ar);
407 }
408
409 static void text_header_area_draw(const bContext *C, ARegion *ar)
410 {
411         ED_region_header(C, ar);
412 }
413
414 /****************** properties region ******************/
415
416 /* add handlers, stuff you only do once or on area/region changes */
417 static void text_properties_area_init(wmWindowManager *wm, ARegion *ar)
418 {
419         ED_region_panels_init(wm, ar);
420 }
421
422 static void text_properties_area_draw(const bContext *C, ARegion *ar)
423 {
424         ED_region_panels(C, ar, 1, NULL, -1);
425 }
426
427 /********************* registration ********************/
428
429 /* only called once, from space/spacetypes.c */
430 void ED_spacetype_text(void)
431 {
432         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype text");
433         ARegionType *art;
434         
435         st->spaceid= SPACE_TEXT;
436         strncpy(st->name, "Text", BKE_ST_MAXNAME);
437         
438         st->new= text_new;
439         st->free= text_free;
440         st->init= text_init;
441         st->duplicate= text_duplicate;
442         st->operatortypes= text_operatortypes;
443         st->keymap= text_keymap;
444         st->listener= text_listener;
445         st->context= text_context;
446         st->dropboxes = text_dropboxes;
447         
448         /* regions: main window */
449         art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
450         art->regionid = RGN_TYPE_WINDOW;
451         art->init= text_main_area_init;
452         art->draw= text_main_area_draw;
453         art->cursor= text_cursor;
454
455         BLI_addhead(&st->regiontypes, art);
456         
457         /* regions: properties */
458         art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
459         art->regionid = RGN_TYPE_UI;
460         art->prefsizex= UI_COMPACT_PANEL_WIDTH;
461         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
462         
463         art->init= text_properties_area_init;
464         art->draw= text_properties_area_draw;
465         BLI_addhead(&st->regiontypes, art);
466
467         /* regions: header */
468         art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
469         art->regionid = RGN_TYPE_HEADER;
470         art->prefsizey= HEADERY;
471         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER;
472         
473         art->init= text_header_area_init;
474         art->draw= text_header_area_draw;
475
476         BLI_addhead(&st->regiontypes, art);
477
478         BKE_spacetype_register(st);
479 }
480