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