Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2008 Blender Foundation. 00019 * All rights reserved. 00020 * 00021 * 00022 * Contributor(s): Blender Foundation 00023 * 00024 * ***** END GPL LICENSE BLOCK ***** 00025 */ 00026 00032 #include <string.h> 00033 #include <stdio.h> 00034 00035 #include "DNA_text_types.h" 00036 #include "DNA_object_types.h" 00037 00038 #include "MEM_guardedalloc.h" 00039 00040 #include "BLI_blenlib.h" 00041 #include "BLI_math.h" 00042 #include "BLI_rand.h" 00043 #include "BLI_utildefines.h" 00044 00045 #include "BKE_context.h" 00046 #include "BKE_screen.h" 00047 00048 #include "ED_space_api.h" 00049 #include "ED_screen.h" 00050 00051 #include "BIF_gl.h" 00052 00053 #include "WM_api.h" 00054 #include "WM_types.h" 00055 00056 #include "UI_interface.h" 00057 #include "UI_resources.h" 00058 #include "UI_view2d.h" 00059 00060 #include "RNA_access.h" 00061 00062 00063 #include "text_intern.h" // own include 00064 00065 /* ******************** default callbacks for text space ***************** */ 00066 00067 static SpaceLink *text_new(const bContext *UNUSED(C)) 00068 { 00069 ARegion *ar; 00070 SpaceText *stext; 00071 00072 stext= MEM_callocN(sizeof(SpaceText), "inittext"); 00073 stext->spacetype= SPACE_TEXT; 00074 00075 stext->lheight= 12; 00076 stext->tabnumber= 4; 00077 stext->margin_column= 80; 00078 00079 /* header */ 00080 ar= MEM_callocN(sizeof(ARegion), "header for text"); 00081 00082 BLI_addtail(&stext->regionbase, ar); 00083 ar->regiontype= RGN_TYPE_HEADER; 00084 ar->alignment= RGN_ALIGN_BOTTOM; 00085 00086 /* main area */ 00087 ar= MEM_callocN(sizeof(ARegion), "main area for text"); 00088 00089 BLI_addtail(&stext->regionbase, ar); 00090 ar->regiontype= RGN_TYPE_WINDOW; 00091 00092 return (SpaceLink *)stext; 00093 } 00094 00095 /* not spacelink itself */ 00096 static void text_free(SpaceLink *sl) 00097 { 00098 SpaceText *stext= (SpaceText*) sl; 00099 00100 stext->text= NULL; 00101 text_free_caches(stext); 00102 } 00103 00104 00105 /* spacetype; init callback */ 00106 static void text_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa)) 00107 { 00108 00109 } 00110 00111 static SpaceLink *text_duplicate(SpaceLink *sl) 00112 { 00113 SpaceText *stextn= MEM_dupallocN(sl); 00114 00115 /* clear or remove stuff from old */ 00116 00117 stextn->drawcache= NULL; /* space need it's own cache */ 00118 00119 return (SpaceLink *)stextn; 00120 } 00121 00122 static void text_listener(ScrArea *sa, wmNotifier *wmn) 00123 { 00124 SpaceText *st= sa->spacedata.first; 00125 00126 /* context changes */ 00127 switch(wmn->category) { 00128 case NC_TEXT: 00129 /* check if active text was changed, no need to redraw if text isn't active 00130 reference==NULL means text was unlinked, should update anyway for this 00131 case -- no way to know was text active before unlinking or not */ 00132 if(wmn->reference && wmn->reference != st->text) 00133 break; 00134 00135 switch(wmn->data) { 00136 case ND_DISPLAY: 00137 ED_area_tag_redraw(sa); 00138 break; 00139 case ND_CURSOR: 00140 if(st->text && st->text == wmn->reference) 00141 text_scroll_to_cursor(st, sa); 00142 00143 ED_area_tag_redraw(sa); 00144 break; 00145 } 00146 00147 switch(wmn->action) { 00148 case NA_EDITED: 00149 if(st->text) { 00150 text_drawcache_tag_update(st, 1); 00151 text_update_edited(st->text); 00152 } 00153 00154 ED_area_tag_redraw(sa); 00155 /* no break -- fall down to tag redraw */ 00156 case NA_ADDED: 00157 case NA_REMOVED: 00158 ED_area_tag_redraw(sa); 00159 break; 00160 case NA_SELECTED: 00161 if(st->text && st->text == wmn->reference) 00162 text_scroll_to_cursor(st, sa); 00163 00164 break; 00165 } 00166 00167 break; 00168 case NC_SPACE: 00169 if(wmn->data == ND_SPACE_TEXT) 00170 ED_area_tag_redraw(sa); 00171 break; 00172 } 00173 } 00174 00175 static void text_operatortypes(void) 00176 { 00177 WM_operatortype_append(TEXT_OT_new); 00178 WM_operatortype_append(TEXT_OT_open); 00179 WM_operatortype_append(TEXT_OT_reload); 00180 WM_operatortype_append(TEXT_OT_unlink); 00181 WM_operatortype_append(TEXT_OT_save); 00182 WM_operatortype_append(TEXT_OT_save_as); 00183 WM_operatortype_append(TEXT_OT_make_internal); 00184 WM_operatortype_append(TEXT_OT_run_script); 00185 WM_operatortype_append(TEXT_OT_refresh_pyconstraints); 00186 00187 WM_operatortype_append(TEXT_OT_paste); 00188 WM_operatortype_append(TEXT_OT_copy); 00189 WM_operatortype_append(TEXT_OT_cut); 00190 00191 WM_operatortype_append(TEXT_OT_convert_whitespace); 00192 WM_operatortype_append(TEXT_OT_uncomment); 00193 WM_operatortype_append(TEXT_OT_comment); 00194 WM_operatortype_append(TEXT_OT_unindent); 00195 WM_operatortype_append(TEXT_OT_indent); 00196 00197 WM_operatortype_append(TEXT_OT_markers_clear); 00198 WM_operatortype_append(TEXT_OT_next_marker); 00199 WM_operatortype_append(TEXT_OT_previous_marker); 00200 00201 WM_operatortype_append(TEXT_OT_select_line); 00202 WM_operatortype_append(TEXT_OT_select_all); 00203 WM_operatortype_append(TEXT_OT_select_word); 00204 00205 WM_operatortype_append(TEXT_OT_jump); 00206 WM_operatortype_append(TEXT_OT_move); 00207 WM_operatortype_append(TEXT_OT_move_select); 00208 WM_operatortype_append(TEXT_OT_delete); 00209 WM_operatortype_append(TEXT_OT_overwrite_toggle); 00210 00211 WM_operatortype_append(TEXT_OT_selection_set); 00212 WM_operatortype_append(TEXT_OT_cursor_set); 00213 WM_operatortype_append(TEXT_OT_scroll); 00214 WM_operatortype_append(TEXT_OT_scroll_bar); 00215 WM_operatortype_append(TEXT_OT_line_number); 00216 00217 WM_operatortype_append(TEXT_OT_line_break); 00218 WM_operatortype_append(TEXT_OT_insert); 00219 00220 WM_operatortype_append(TEXT_OT_properties); 00221 00222 WM_operatortype_append(TEXT_OT_find); 00223 WM_operatortype_append(TEXT_OT_find_set_selected); 00224 WM_operatortype_append(TEXT_OT_replace); 00225 WM_operatortype_append(TEXT_OT_replace_set_selected); 00226 WM_operatortype_append(TEXT_OT_mark_all); 00227 00228 WM_operatortype_append(TEXT_OT_to_3d_object); 00229 00230 WM_operatortype_append(TEXT_OT_resolve_conflict); 00231 } 00232 00233 static void text_keymap(struct wmKeyConfig *keyconf) 00234 { 00235 wmKeyMap *keymap; 00236 wmKeyMapItem *kmi; 00237 00238 keymap= WM_keymap_find(keyconf, "Text", SPACE_TEXT, 0); 00239 00240 #ifdef __APPLE__ 00241 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", LEFTARROWKEY, KM_PRESS, KM_OSKEY, 0)->ptr, "type", LINE_BEGIN); 00242 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", RIGHTARROWKEY, KM_PRESS, KM_OSKEY, 0)->ptr, "type", LINE_END); 00243 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", LEFTARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "type", PREV_WORD); 00244 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0)->ptr, "type", NEXT_WORD); 00245 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", UPARROWKEY, KM_PRESS, KM_OSKEY, 0)->ptr, "type", FILE_TOP); 00246 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", DOWNARROWKEY, KM_PRESS, KM_OSKEY, 0)->ptr, "type", FILE_BOTTOM); 00247 00248 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0)->ptr, "type", LINE_BEGIN); 00249 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0)->ptr, "type", LINE_END); 00250 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0)->ptr, "type", PREV_WORD); 00251 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0)->ptr, "type", NEXT_WORD); 00252 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", UPARROWKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0)->ptr, "type", FILE_TOP); 00253 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", DOWNARROWKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0)->ptr, "type", FILE_BOTTOM); 00254 00255 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", BACKSPACEKEY, KM_PRESS, KM_ALT, 0)->ptr, "type", DEL_PREV_WORD); 00256 00257 WM_keymap_add_item(keymap, "TEXT_OT_save", SKEY, KM_PRESS, KM_ALT|KM_OSKEY, 0); 00258 WM_keymap_add_item(keymap, "TEXT_OT_save_as", SKEY, KM_PRESS, KM_ALT|KM_SHIFT|KM_OSKEY, 0); 00259 WM_keymap_add_item(keymap, "TEXT_OT_cut", XKEY, KM_PRESS, KM_OSKEY, 0); 00260 WM_keymap_add_item(keymap, "TEXT_OT_copy", CKEY, KM_PRESS, KM_OSKEY, 0); 00261 WM_keymap_add_item(keymap, "TEXT_OT_paste", VKEY, KM_PRESS, KM_OSKEY, 0); 00262 WM_keymap_add_item(keymap, "TEXT_OT_properties", FKEY, KM_PRESS, KM_OSKEY, 0); 00263 WM_keymap_add_item(keymap, "TEXT_OT_find_set_selected", EKEY, KM_PRESS, KM_OSKEY, 0); 00264 WM_keymap_add_item(keymap, "TEXT_OT_find", GKEY, KM_PRESS, KM_OSKEY, 0); 00265 WM_keymap_add_item(keymap, "TEXT_OT_select_all", AKEY, KM_PRESS, KM_OSKEY, 0); 00266 WM_keymap_add_item(keymap, "TEXT_OT_select_line", AKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0); 00267 #endif 00268 00269 kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0); 00270 RNA_string_set(kmi->ptr, "data_path", "space_data.font_size"); 00271 RNA_boolean_set(kmi->ptr, "reverse", FALSE); 00272 00273 kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0); 00274 RNA_string_set(kmi->ptr, "data_path", "space_data.font_size"); 00275 RNA_boolean_set(kmi->ptr, "reverse", TRUE); 00276 00277 kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PADPLUSKEY, KM_PRESS, KM_CTRL, 0); 00278 RNA_string_set(kmi->ptr, "data_path", "space_data.font_size"); 00279 RNA_boolean_set(kmi->ptr, "reverse", FALSE); 00280 00281 kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PADMINUS, KM_PRESS, KM_CTRL, 0); 00282 RNA_string_set(kmi->ptr, "data_path", "space_data.font_size"); 00283 RNA_boolean_set(kmi->ptr, "reverse", TRUE); 00284 00285 WM_keymap_add_item(keymap, "TEXT_OT_new", NKEY, KM_PRESS, KM_CTRL, 0); 00286 WM_keymap_add_item(keymap, "TEXT_OT_open", OKEY, KM_PRESS, KM_ALT, 0); 00287 WM_keymap_add_item(keymap, "TEXT_OT_reload", RKEY, KM_PRESS, KM_ALT, 0); 00288 WM_keymap_add_item(keymap, "TEXT_OT_save", SKEY, KM_PRESS, KM_ALT, 0); 00289 WM_keymap_add_item(keymap, "TEXT_OT_save_as", SKEY, KM_PRESS, KM_ALT|KM_SHIFT|KM_CTRL, 0); 00290 00291 WM_keymap_add_item(keymap, "TEXT_OT_run_script", PKEY, KM_PRESS, KM_ALT, 0); 00292 00293 WM_keymap_add_item(keymap, "TEXT_OT_cut", XKEY, KM_PRESS, KM_CTRL, 0); 00294 WM_keymap_add_item(keymap, "TEXT_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0); 00295 WM_keymap_add_item(keymap, "TEXT_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0); 00296 00297 WM_keymap_add_item(keymap, "TEXT_OT_cut", DELKEY, KM_PRESS, KM_SHIFT, 0); 00298 WM_keymap_add_item(keymap, "TEXT_OT_copy", INSERTKEY, KM_PRESS, KM_CTRL, 0); 00299 WM_keymap_add_item(keymap, "TEXT_OT_paste", INSERTKEY, KM_PRESS, KM_SHIFT, 0); 00300 00301 if(U.uiflag & USER_MMB_PASTE) { // XXX not dynamic 00302 kmi = WM_keymap_add_item(keymap, "TEXT_OT_paste", MIDDLEMOUSE, KM_PRESS, 0, 0); 00303 RNA_boolean_set(kmi->ptr, "selection", TRUE); 00304 } 00305 00306 WM_keymap_add_item(keymap, "TEXT_OT_jump", JKEY, KM_PRESS, KM_CTRL, 0); 00307 WM_keymap_add_item(keymap, "TEXT_OT_find", GKEY, KM_PRESS, KM_CTRL, 0); 00308 00309 WM_keymap_add_item(keymap, "TEXT_OT_properties", FKEY, KM_PRESS, KM_CTRL, 0); 00310 WM_keymap_add_item(keymap, "TEXT_OT_replace", HKEY, KM_PRESS, KM_CTRL, 0); 00311 00312 kmi = WM_keymap_add_item(keymap, "TEXT_OT_to_3d_object", MKEY, KM_PRESS, KM_ALT, 0); 00313 RNA_boolean_set(kmi->ptr, "split_lines", FALSE); 00314 kmi = WM_keymap_add_item(keymap, "TEXT_OT_to_3d_object", MKEY, KM_PRESS, KM_CTRL, 0); 00315 RNA_boolean_set(kmi->ptr, "split_lines", TRUE); 00316 00317 WM_keymap_add_item(keymap, "TEXT_OT_select_all", AKEY, KM_PRESS, KM_CTRL, 0); 00318 WM_keymap_add_item(keymap, "TEXT_OT_select_line", AKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0); 00319 WM_keymap_add_item(keymap, "TEXT_OT_select_word", LEFTMOUSE, KM_DBL_CLICK, 0, 0); 00320 00321 00322 WM_keymap_add_item(keymap, "TEXT_OT_indent", TABKEY, KM_PRESS, 0, 0); 00323 WM_keymap_add_item(keymap, "TEXT_OT_unindent", TABKEY, KM_PRESS, KM_SHIFT, 0); 00324 WM_keymap_add_item(keymap, "TEXT_OT_uncomment", DKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0); 00325 00326 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", HOMEKEY, KM_PRESS, 0, 0)->ptr, "type", LINE_BEGIN); 00327 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", ENDKEY, KM_PRESS, 0, 0)->ptr, "type", LINE_END); 00328 00329 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", EKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", LINE_END); 00330 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", EKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "type", LINE_END); 00331 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", LEFTARROWKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_CHAR); 00332 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", RIGHTARROWKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_CHAR); 00333 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", LEFTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", PREV_WORD); 00334 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", RIGHTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", NEXT_WORD); 00335 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", UPARROWKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_LINE); 00336 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", DOWNARROWKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_LINE); 00337 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", PAGEUPKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_PAGE); 00338 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", PAGEDOWNKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_PAGE); 00339 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", HOMEKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", FILE_TOP); 00340 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", ENDKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", FILE_BOTTOM); 00341 00342 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", HOMEKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", LINE_BEGIN); 00343 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", ENDKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", LINE_END); 00344 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_CHAR); 00345 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_CHAR); 00346 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", PREV_WORD); 00347 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", NEXT_WORD); 00348 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", UPARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_LINE); 00349 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", DOWNARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_LINE); 00350 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", PAGEUPKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_PAGE); 00351 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", PAGEDOWNKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_PAGE); 00352 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", HOMEKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", FILE_TOP); 00353 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", ENDKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", FILE_BOTTOM); 00354 00355 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DELKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_NEXT_CHAR); 00356 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_NEXT_CHAR); 00357 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", BACKSPACEKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_PREV_CHAR); 00358 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", BACKSPACEKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", DEL_PREV_CHAR); /* same as above [#26623] */ 00359 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DELKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_NEXT_WORD); 00360 RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", BACKSPACEKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_PREV_WORD); 00361 00362 WM_keymap_add_item(keymap, "TEXT_OT_overwrite_toggle", INSERTKEY, KM_PRESS, 0, 0); 00363 00364 WM_keymap_add_item(keymap, "TEXT_OT_scroll_bar", LEFTMOUSE, KM_PRESS, 0, 0); 00365 WM_keymap_add_item(keymap, "TEXT_OT_scroll_bar", MIDDLEMOUSE, KM_PRESS, 0, 0); 00366 00367 WM_keymap_add_item(keymap, "TEXT_OT_scroll", MIDDLEMOUSE, KM_PRESS, 0, 0); 00368 WM_keymap_add_item(keymap, "TEXT_OT_scroll", MOUSEPAN, 0, 0, 0); 00369 WM_keymap_add_item(keymap, "TEXT_OT_selection_set", EVT_TWEAK_L, KM_ANY, 0, 0); 00370 WM_keymap_add_item(keymap, "TEXT_OT_cursor_set", LEFTMOUSE, KM_PRESS, 0, 0); 00371 kmi = WM_keymap_add_item(keymap, "TEXT_OT_selection_set", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0); 00372 RNA_boolean_set(kmi->ptr, "select", TRUE); 00373 RNA_int_set(WM_keymap_add_item(keymap, "TEXT_OT_scroll", WHEELUPMOUSE, KM_PRESS, 0, 0)->ptr, "lines", -1); 00374 RNA_int_set(WM_keymap_add_item(keymap, "TEXT_OT_scroll", WHEELDOWNMOUSE, KM_PRESS, 0, 0)->ptr, "lines", 1); 00375 00376 WM_keymap_add_item(keymap, "TEXT_OT_line_break", RETKEY, KM_PRESS, 0, 0); 00377 WM_keymap_add_item(keymap, "TEXT_OT_line_break", PADENTER, KM_PRESS, 0, 0); 00378 00379 WM_keymap_add_menu(keymap, "TEXT_MT_toolbox", RIGHTMOUSE, KM_PRESS, KM_ANY, 0); 00380 00381 WM_keymap_add_item(keymap, "TEXT_OT_line_number", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); 00382 WM_keymap_add_item(keymap, "TEXT_OT_insert", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); // last! 00383 } 00384 00385 const char *text_context_dir[] = {"edit_text", NULL}; 00386 00387 static int text_context(const bContext *C, const char *member, bContextDataResult *result) 00388 { 00389 SpaceText *st= CTX_wm_space_text(C); 00390 00391 if(CTX_data_dir(member)) { 00392 CTX_data_dir_set(result, text_context_dir); 00393 return 1; 00394 } 00395 else if(CTX_data_equals(member, "edit_text")) { 00396 CTX_data_id_pointer_set(result, &st->text->id); 00397 return 1; 00398 } 00399 00400 return 0; 00401 } 00402 00403 /********************* main region ********************/ 00404 00405 /* add handlers, stuff you only do once or on area/region changes */ 00406 static void text_main_area_init(wmWindowManager *wm, ARegion *ar) 00407 { 00408 wmKeyMap *keymap; 00409 ListBase *lb; 00410 00411 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy); 00412 00413 /* own keymap */ 00414 keymap= WM_keymap_find(wm->defaultconf, "Text", SPACE_TEXT, 0); 00415 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); 00416 00417 /* add drop boxes */ 00418 lb = WM_dropboxmap_find("Text", SPACE_TEXT, RGN_TYPE_WINDOW); 00419 00420 WM_event_add_dropbox_handler(&ar->handlers, lb); 00421 } 00422 00423 static void text_main_area_draw(const bContext *C, ARegion *ar) 00424 { 00425 /* draw entirely, view changes should be handled here */ 00426 SpaceText *st= CTX_wm_space_text(C); 00427 //View2D *v2d= &ar->v2d; 00428 00429 /* clear and setup matrix */ 00430 UI_ThemeClearColor(TH_BACK); 00431 glClear(GL_COLOR_BUFFER_BIT); 00432 00433 // UI_view2d_view_ortho(v2d); 00434 00435 /* data... */ 00436 draw_text_main(st, ar); 00437 00438 /* reset view matrix */ 00439 // UI_view2d_view_restore(C); 00440 00441 /* scrollers? */ 00442 } 00443 00444 static void text_cursor(wmWindow *win, ScrArea *UNUSED(sa), ARegion *UNUSED(ar)) 00445 { 00446 WM_cursor_set(win, BC_TEXTEDITCURSOR); 00447 } 00448 00449 00450 00451 /* ************* dropboxes ************* */ 00452 00453 static int text_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUSED(event)) 00454 { 00455 if(drag->type==WM_DRAG_PATH) 00456 if(ELEM(drag->icon, ICON_FILE_SCRIPT, ICON_FILE_BLANK)) /* rule might not work? */ 00457 return 1; 00458 return 0; 00459 } 00460 00461 static void text_drop_copy(wmDrag *drag, wmDropBox *drop) 00462 { 00463 /* copy drag path to properties */ 00464 RNA_string_set(drop->ptr, "filepath", drag->path); 00465 } 00466 00467 /* this region dropbox definition */ 00468 static void text_dropboxes(void) 00469 { 00470 ListBase *lb= WM_dropboxmap_find("Text", SPACE_TEXT, RGN_TYPE_WINDOW); 00471 00472 WM_dropbox_add(lb, "TEXT_OT_open", text_drop_poll, text_drop_copy); 00473 00474 } 00475 00476 /* ************* end drop *********** */ 00477 00478 00479 /****************** header region ******************/ 00480 00481 /* add handlers, stuff you only do once or on area/region changes */ 00482 static void text_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar) 00483 { 00484 ED_region_header_init(ar); 00485 } 00486 00487 static void text_header_area_draw(const bContext *C, ARegion *ar) 00488 { 00489 ED_region_header(C, ar); 00490 } 00491 00492 /****************** properties region ******************/ 00493 00494 /* add handlers, stuff you only do once or on area/region changes */ 00495 static void text_properties_area_init(wmWindowManager *wm, ARegion *ar) 00496 { 00497 ED_region_panels_init(wm, ar); 00498 } 00499 00500 static void text_properties_area_draw(const bContext *C, ARegion *ar) 00501 { 00502 ED_region_panels(C, ar, 1, NULL, -1); 00503 } 00504 00505 /********************* registration ********************/ 00506 00507 /* only called once, from space/spacetypes.c */ 00508 void ED_spacetype_text(void) 00509 { 00510 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype text"); 00511 ARegionType *art; 00512 00513 st->spaceid= SPACE_TEXT; 00514 strncpy(st->name, "Text", BKE_ST_MAXNAME); 00515 00516 st->new= text_new; 00517 st->free= text_free; 00518 st->init= text_init; 00519 st->duplicate= text_duplicate; 00520 st->operatortypes= text_operatortypes; 00521 st->keymap= text_keymap; 00522 st->listener= text_listener; 00523 st->context= text_context; 00524 st->dropboxes = text_dropboxes; 00525 00526 /* regions: main window */ 00527 art= MEM_callocN(sizeof(ARegionType), "spacetype text region"); 00528 art->regionid = RGN_TYPE_WINDOW; 00529 art->init= text_main_area_init; 00530 art->draw= text_main_area_draw; 00531 art->cursor= text_cursor; 00532 00533 BLI_addhead(&st->regiontypes, art); 00534 00535 /* regions: properties */ 00536 art= MEM_callocN(sizeof(ARegionType), "spacetype text region"); 00537 art->regionid = RGN_TYPE_UI; 00538 art->prefsizex= UI_COMPACT_PANEL_WIDTH; 00539 art->keymapflag= ED_KEYMAP_UI; 00540 00541 art->init= text_properties_area_init; 00542 art->draw= text_properties_area_draw; 00543 BLI_addhead(&st->regiontypes, art); 00544 00545 /* regions: header */ 00546 art= MEM_callocN(sizeof(ARegionType), "spacetype text region"); 00547 art->regionid = RGN_TYPE_HEADER; 00548 art->prefsizey= HEADERY; 00549 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER; 00550 00551 art->init= text_header_area_init; 00552 art->draw= text_header_area_draw; 00553 00554 BLI_addhead(&st->regiontypes, art); 00555 00556 BKE_spacetype_register(st); 00557 } 00558