Add a little RMB context menu to text editor
[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_menu(keymap, "TEXT_MT_toolbox", RIGHTMOUSE, KM_PRESS, KM_ANY, 0);
311         
312         WM_keymap_add_item(keymap, "TEXT_OT_line_number", KM_TEXTINPUT, KM_ANY, KM_ANY, 0);
313         WM_keymap_add_item(keymap, "TEXT_OT_insert", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); // last!
314 }
315
316 static int text_context(const bContext *C, const char *member, bContextDataResult *result)
317 {
318         SpaceText *st= CTX_wm_space_text(C);
319
320         if(CTX_data_dir(member)) {
321                 static const char *dir[] = {"edit_text", NULL};
322                 CTX_data_dir_set(result, dir);
323                 return 1;
324         }
325         else if(CTX_data_equals(member, "edit_text")) {
326                 CTX_data_id_pointer_set(result, &st->text->id);
327                 return 1;
328         }
329
330         return 0;
331 }
332
333 /********************* main region ********************/
334
335 /* add handlers, stuff you only do once or on area/region changes */
336 static void text_main_area_init(wmWindowManager *wm, ARegion *ar)
337 {
338         wmKeyMap *keymap;
339         ListBase *lb;
340         
341         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
342         
343         /* own keymap */
344         keymap= WM_keymap_find(wm->defaultconf, "Text", SPACE_TEXT, 0);
345         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
346         
347         /* add drop boxes */
348         lb = WM_dropboxmap_find("Text", SPACE_TEXT, RGN_TYPE_WINDOW);
349         
350         WM_event_add_dropbox_handler(&ar->handlers, lb);
351 }
352
353 static void text_main_area_draw(const bContext *C, ARegion *ar)
354 {
355         /* draw entirely, view changes should be handled here */
356         SpaceText *st= CTX_wm_space_text(C);
357         //View2D *v2d= &ar->v2d;
358         
359         /* clear and setup matrix */
360         UI_ThemeClearColor(TH_BACK);
361         glClear(GL_COLOR_BUFFER_BIT);
362         
363         // UI_view2d_view_ortho(C, v2d);
364                 
365         /* data... */
366         draw_text_main(st, ar);
367         
368         /* reset view matrix */
369         // UI_view2d_view_restore(C);
370         
371         /* scrollers? */
372 }
373
374 static void text_cursor(wmWindow *win, ScrArea *sa, ARegion *ar)
375 {
376         WM_cursor_set(win, BC_TEXTEDITCURSOR);
377 }
378
379
380
381 /* ************* dropboxes ************* */
382
383 static int text_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
384 {
385         if(drag->type==WM_DRAG_PATH)
386                 if(ELEM(drag->icon, 0, ICON_FILE_BLANK))        /* rule might not work? */
387                         return 1;
388         return 0;
389 }
390
391 static void text_drop_copy(wmDrag *drag, wmDropBox *drop)
392 {
393         /* copy drag path to properties */
394         RNA_string_set(drop->ptr, "path", drag->path);
395 }
396
397 /* this region dropbox definition */
398 static void text_dropboxes(void)
399 {
400         ListBase *lb= WM_dropboxmap_find("Text", SPACE_TEXT, RGN_TYPE_WINDOW);
401         
402         WM_dropbox_add(lb, "TEXT_OT_open", text_drop_poll, text_drop_copy);
403
404 }
405
406 /* ************* end drop *********** */
407
408
409 /****************** header region ******************/
410
411 /* add handlers, stuff you only do once or on area/region changes */
412 static void text_header_area_init(wmWindowManager *wm, ARegion *ar)
413 {
414         ED_region_header_init(ar);
415 }
416
417 static void text_header_area_draw(const bContext *C, ARegion *ar)
418 {
419         ED_region_header(C, ar);
420 }
421
422 /****************** properties region ******************/
423
424 /* add handlers, stuff you only do once or on area/region changes */
425 static void text_properties_area_init(wmWindowManager *wm, ARegion *ar)
426 {
427         ED_region_panels_init(wm, ar);
428 }
429
430 static void text_properties_area_draw(const bContext *C, ARegion *ar)
431 {
432         ED_region_panels(C, ar, 1, NULL, -1);
433 }
434
435 /********************* registration ********************/
436
437 /* only called once, from space/spacetypes.c */
438 void ED_spacetype_text(void)
439 {
440         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype text");
441         ARegionType *art;
442         
443         st->spaceid= SPACE_TEXT;
444         strncpy(st->name, "Text", BKE_ST_MAXNAME);
445         
446         st->new= text_new;
447         st->free= text_free;
448         st->init= text_init;
449         st->duplicate= text_duplicate;
450         st->operatortypes= text_operatortypes;
451         st->keymap= text_keymap;
452         st->listener= text_listener;
453         st->context= text_context;
454         st->dropboxes = text_dropboxes;
455         
456         /* regions: main window */
457         art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
458         art->regionid = RGN_TYPE_WINDOW;
459         art->init= text_main_area_init;
460         art->draw= text_main_area_draw;
461         art->cursor= text_cursor;
462
463         BLI_addhead(&st->regiontypes, art);
464         
465         /* regions: properties */
466         art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
467         art->regionid = RGN_TYPE_UI;
468         art->prefsizex= UI_COMPACT_PANEL_WIDTH;
469         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
470         
471         art->init= text_properties_area_init;
472         art->draw= text_properties_area_draw;
473         BLI_addhead(&st->regiontypes, art);
474
475         /* regions: header */
476         art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
477         art->regionid = RGN_TYPE_HEADER;
478         art->prefsizey= HEADERY;
479         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER;
480         
481         art->init= text_header_area_init;
482         art->draw= text_header_area_draw;
483
484         BLI_addhead(&st->regiontypes, art);
485
486         BKE_spacetype_register(st);
487 }
488