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