~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/editors/space_text/text_python.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * $Id: text_python.c 27676 2010-03-23 14:09:09Z campbellbarton $
3
 
 *
 
1
/*
4
2
 * ***** BEGIN GPL LICENSE BLOCK *****
5
3
 *
6
4
 * This program is free software; you can redistribute it and/or
26
24
 * ***** END GPL LICENSE BLOCK *****
27
25
 */
28
26
 
 
27
/** \file blender/editors/space_text/text_python.c
 
28
 *  \ingroup sptext
 
29
 */
 
30
 
 
31
 
29
32
#include <ctype.h>
30
33
#include <stdio.h>
31
34
#include <stdlib.h>
38
41
#include "BKE_text.h"
39
42
 
40
43
#include "BLI_blenlib.h"
 
44
#include "BLI_utildefines.h"
41
45
 
42
46
#include "WM_types.h"
43
47
 
45
49
 
46
50
int text_do_suggest_select(SpaceText *st, ARegion *ar)
47
51
{
48
 
        SuggItem *item, *first, *last, *sel;
 
52
        SuggItem *item, *first, *last /* , *sel */ /* UNUSED */;
49
53
        TextLine *tmp;
50
54
        int l, x, y, w, h, i;
51
55
        int tgti, *top;
52
 
        short mval[2] = {0, 0};
 
56
        int mval[2] = {0, 0};
53
57
        
54
 
        if(!st || !st->text) return 0;
55
 
        if(!texttool_text_is_active(st->text)) return 0;
 
58
        if (!st || !st->text) return 0;
 
59
        if (!texttool_text_is_active(st->text)) return 0;
56
60
 
57
61
        first = texttool_suggest_first();
58
62
        last = texttool_suggest_last();
59
 
        sel = texttool_suggest_selected();
 
63
        /* sel = texttool_suggest_selected(); */ /* UNUSED */
60
64
        top = texttool_suggest_top();
61
65
 
62
 
        if(!last || !first)
 
66
        if (!last || !first)
63
67
                return 0;
64
68
 
65
69
        /* Count the visible lines to the cursor */
66
 
        for(tmp=st->text->curl, l=-st->top; tmp; tmp=tmp->prev, l++);
67
 
        if(l<0) return 0;
 
70
        for (tmp = st->text->curl, l = -st->top; tmp; tmp = tmp->prev, l++) ;
 
71
        if (l < 0) return 0;
68
72
 
69
73
        text_update_character_width(st);
70
74
        
71
 
        if(st->showlinenrs) {
72
 
                x = st->cwidth*(st->text->curc-st->left) + TXT_OFFSET + TEXTXLOC - 4;
 
75
        if (st->showlinenrs) {
 
76
                x = st->cwidth * (st->text->curc - st->left) + TXT_OFFSET + TEXTXLOC - 4;
73
77
        }
74
78
        else {
75
 
                x = st->cwidth*(st->text->curc-st->left) + TXT_OFFSET - 4;
 
79
                x = st->cwidth * (st->text->curc - st->left) + TXT_OFFSET - 4;
76
80
        }
77
 
        y = ar->winy - st->lheight*l - 2;
 
81
        y = ar->winy - st->lheight * l - 2;
78
82
 
79
 
        w = SUGG_LIST_WIDTH*st->cwidth + 20;
80
 
        h = SUGG_LIST_SIZE*st->lheight + 8;
 
83
        w = SUGG_LIST_WIDTH * st->cwidth + 20;
 
84
        h = SUGG_LIST_SIZE * st->lheight + 8;
81
85
 
82
86
        // XXX getmouseco_areawin(mval);
83
87
 
84
 
        if(mval[0]<x || x+w<mval[0] || mval[1]<y-h || y<mval[1])
 
88
        if (mval[0] < x || x + w < mval[0] || mval[1] < y - h || y < mval[1])
85
89
                return 0;
86
90
 
87
91
        /* Work out which of the items is at the top of the visible list */
88
 
        for(i=0, item=first; i<*top && item->next; i++, item=item->next);
 
92
        for (i = 0, item = first; i < *top && item->next; i++, item = item->next) ;
89
93
 
90
94
        /* Work out the target item index in the visible list */
91
 
        tgti = (y-mval[1]-4) / st->lheight;
92
 
        if(tgti<0 || tgti>SUGG_LIST_SIZE)
 
95
        tgti = (y - mval[1] - 4) / st->lheight;
 
96
        if (tgti < 0 || tgti > SUGG_LIST_SIZE)
93
97
                return 1;
94
98
 
95
 
        for(i=tgti; i>0 && item->next; i--, item=item->next);
96
 
        if(item)
 
99
        for (i = tgti; i > 0 && item->next; i--, item = item->next) ;
 
100
        if (item)
97
101
                texttool_suggest_select(item);
98
102
        return 1;
99
103
}
100
104
 
101
 
void text_pop_suggest_list()
 
105
void text_pop_suggest_list(void)
102
106
{
103
107
        SuggItem *item, *sel;
104
108
        int *top, i;
105
109
 
106
 
        item= texttool_suggest_first();
107
 
        sel= texttool_suggest_selected();
108
 
        top= texttool_suggest_top();
 
110
        item = texttool_suggest_first();
 
111
        sel = texttool_suggest_selected();
 
112
        top = texttool_suggest_top();
109
113
 
110
 
        i= 0;
111
 
        while(item && item != sel) {
112
 
                item= item->next;
 
114
        i = 0;
 
115
        while (item && item != sel) {
 
116
                item = item->next;
113
117
                i++;
114
118
        }
115
 
        if(i > *top+SUGG_LIST_SIZE-1)
116
 
                *top= i-SUGG_LIST_SIZE+1;
117
 
        else if(i < *top)
118
 
                *top= i;
 
119
        if (i > *top + SUGG_LIST_SIZE - 1)
 
120
                *top = i - SUGG_LIST_SIZE + 1;
 
121
        else if (i < *top)
 
122
                *top = i;
119
123
}
120
124
 
121
125
static void get_suggest_prefix(Text *text, int offset)
123
127
        int i, len;
124
128
        char *line, tmp[256];
125
129
 
126
 
        if(!text) return;
127
 
        if(!texttool_text_is_active(text)) return;
 
130
        if (!text) return;
 
131
        if (!texttool_text_is_active(text)) return;
128
132
 
129
 
        line= text->curl->line;
130
 
        for(i=text->curc-1+offset; i>=0; i--)
131
 
                if(!text_check_identifier(line[i]))
 
133
        line = text->curl->line;
 
134
        for (i = text->curc - 1 + offset; i >= 0; i--)
 
135
                if (!text_check_identifier(line[i]))
132
136
                        break;
133
137
        i++;
134
 
        len= text->curc-i+offset;
135
 
        if(len > 255) {
 
138
        len = text->curc - i + offset;
 
139
        if (len > 255) {
136
140
                printf("Suggestion prefix too long\n");
137
141
                len = 255;
138
142
        }
139
 
        BLI_strncpy(tmp, line+i, len);
140
 
        tmp[len]= '\0';
 
143
        BLI_strncpy(tmp, line + i, len);
 
144
        tmp[len] = '\0';
141
145
        texttool_suggest_prefix(tmp);
142
146
}
143
147
 
144
148
static void confirm_suggestion(Text *text, int skipleft)
145
149
{
146
150
        SuggItem *sel;
147
 
        int i, over=0;
 
151
        int i, over = 0;
148
152
        char *line;
149
153
 
150
 
        if(!text) return;
151
 
        if(!texttool_text_is_active(text)) return;
 
154
        if (!text) return;
 
155
        if (!texttool_text_is_active(text)) return;
152
156
 
153
157
        sel = texttool_suggest_selected();
154
 
        if(!sel) return;
 
158
        if (!sel) return;
155
159
 
156
 
        line= text->curl->line;
157
 
        i=text->curc-skipleft-1;
158
 
        while(i>=0) {
159
 
                if(!text_check_identifier(line[i]))
 
160
        line = text->curl->line;
 
161
        i = text->curc - skipleft - 1;
 
162
        while (i >= 0) {
 
163
                if (!text_check_identifier(line[i]))
160
164
                        break;
161
165
                over++;
162
166
                i--;
163
167
        }
164
168
 
165
 
        for(i=0; i<skipleft; i++)
 
169
        for (i = 0; i < skipleft; i++)
166
170
                txt_move_left(text, 0);
167
 
        for(i=0; i<over; i++)
 
171
        for (i = 0; i < over; i++)
168
172
                txt_move_left(text, 1);
169
173
 
170
174
        txt_insert_buf(text, sel->name);
171
175
        
172
 
        for(i=0; i<skipleft; i++)
 
176
        for (i = 0; i < skipleft; i++)
173
177
                txt_move_right(text, 0);
174
178
 
175
179
        texttool_text_clear();
182
186
#define LR_SHIFTKEY 0
183
187
#define LR_ALTKEY 0
184
188
#define LR_CTRLKEY 0
185
 
#define LR_COMMANDKEY 0
 
189
#define LR_OSKEY 0
186
190
 
187
191
// XXX
188
 
static int doc_scroll= 0;
 
192
static int doc_scroll = 0;
189
193
 
190
 
short do_texttools(SpaceText *st, char ascii, unsigned short evnt, short val)
 
194
static short UNUSED_FUNCTION(do_texttools) (SpaceText * st, char ascii, unsigned short evnt, short val)
191
195
{
192
 
        ARegion *ar= NULL; // XXX
193
 
        int qual= 0; // XXX
194
 
        int draw=0, tools=0, swallow=0, scroll=1;
195
 
        if(!texttool_text_is_active(st->text)) return 0;
196
 
        if(!st->text || st->text->id.lib) return 0;
 
196
        ARegion *ar = NULL; // XXX
 
197
        int qual = 0; // XXX
 
198
        int draw = 0, tools = 0, swallow = 0, scroll = 1;
 
199
        if (!texttool_text_is_active(st->text)) return 0;
 
200
        if (!st->text || st->text->id.lib) return 0;
197
201
 
198
 
        if(st->doplugins && texttool_text_is_active(st->text)) {
199
 
                if(texttool_suggest_first()) tools |= TOOL_SUGG_LIST;
200
 
                if(texttool_docs_get()) tools |= TOOL_DOCUMENT;
 
202
        if (st->doplugins && texttool_text_is_active(st->text)) {
 
203
                if (texttool_suggest_first()) tools |= TOOL_SUGG_LIST;
 
204
                if (texttool_docs_get()) tools |= TOOL_DOCUMENT;
201
205
        }
202
206
 
203
 
        if(ascii) {
204
 
                if(tools & TOOL_SUGG_LIST) {
205
 
                        if((ascii != '_' && ascii != '*' && ispunct(ascii)) || text_check_whitespace(ascii)) {
 
207
        if (ascii) {
 
208
                if (tools & TOOL_SUGG_LIST) {
 
209
                        if ((ascii != '_' && ascii != '*' && ispunct(ascii)) || text_check_whitespace(ascii)) {
206
210
                                confirm_suggestion(st->text, 0);
207
 
                                text_update_line_edited(st->text, st->text->curl);
 
211
                                text_update_line_edited(st->text->curl);
208
212
                        }
209
 
                        else if((st->overwrite && txt_replace_char(st->text, ascii)) || txt_add_char(st->text, ascii)) {
 
213
                        else if ((st->overwrite && txt_replace_char(st->text, ascii)) || txt_add_char(st->text, ascii)) {
210
214
                                get_suggest_prefix(st->text, 0);
211
215
                                text_pop_suggest_list();
212
 
                                swallow= 1;
213
 
                                draw= 1;
 
216
                                swallow = 1;
 
217
                                draw = 1;
214
218
                        }
215
219
                }
216
 
                if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
 
220
                if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0, draw = 1;
217
221
 
218
222
        }
219
 
        else if(val==1 && evnt) {
 
223
        else if (val == 1 && evnt) {
220
224
                switch (evnt) {
221
225
                        case LEFTMOUSE:
222
 
                                if(text_do_suggest_select(st, ar))
223
 
                                        swallow= 1;
 
226
                                if (text_do_suggest_select(st, ar))
 
227
                                        swallow = 1;
224
228
                                else {
225
 
                                        if(tools & TOOL_SUGG_LIST) texttool_suggest_clear();
226
 
                                        if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
 
229
                                        if (tools & TOOL_SUGG_LIST) texttool_suggest_clear();
 
230
                                        if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0;
227
231
                                }
228
 
                                draw= 1;
 
232
                                draw = 1;
229
233
                                break;
230
234
                        case MIDDLEMOUSE:
231
 
                                if(text_do_suggest_select(st, ar)) {
 
235
                                if (text_do_suggest_select(st, ar)) {
232
236
                                        confirm_suggestion(st->text, 0);
233
 
                                        text_update_line_edited(st->text, st->text->curl);
234
 
                                        swallow= 1;
 
237
                                        text_update_line_edited(st->text->curl);
 
238
                                        swallow = 1;
235
239
                                }
236
240
                                else {
237
 
                                        if(tools & TOOL_SUGG_LIST) texttool_suggest_clear();
238
 
                                        if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
 
241
                                        if (tools & TOOL_SUGG_LIST) texttool_suggest_clear();
 
242
                                        if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0;
239
243
                                }
240
 
                                draw= 1;
 
244
                                draw = 1;
241
245
                                break;
242
246
                        case ESCKEY:
243
 
                                draw= swallow= 1;
244
 
                                if(tools & TOOL_SUGG_LIST) texttool_suggest_clear();
245
 
                                else if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
246
 
                                else draw= swallow= 0;
 
247
                                draw = swallow = 1;
 
248
                                if (tools & TOOL_SUGG_LIST) texttool_suggest_clear();
 
249
                                else if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0;
 
250
                                else draw = swallow = 0;
247
251
                                break;
248
252
                        case RETKEY:
249
 
                                if(tools & TOOL_SUGG_LIST) {
 
253
                                if (tools & TOOL_SUGG_LIST) {
250
254
                                        confirm_suggestion(st->text, 0);
251
 
                                        text_update_line_edited(st->text, st->text->curl);
252
 
                                        swallow= 1;
253
 
                                        draw= 1;
 
255
                                        text_update_line_edited(st->text->curl);
 
256
                                        swallow = 1;
 
257
                                        draw = 1;
254
258
                                }
255
 
                                if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
 
259
                                if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0, draw = 1;
256
260
                                break;
257
261
                        case LEFTARROWKEY:
258
262
                        case BACKSPACEKEY:
259
 
                                if(tools & TOOL_SUGG_LIST) {
260
 
                                        if(qual)
 
263
                                if (tools & TOOL_SUGG_LIST) {
 
264
                                        if (qual)
261
265
                                                texttool_suggest_clear();
262
266
                                        else {
263
267
                                                /* Work out which char we are about to delete/pass */
264
 
                                                if(st->text->curl && st->text->curc > 0) {
265
 
                                                        char ch= st->text->curl->line[st->text->curc-1];
266
 
                                                        if((ch=='_' || !ispunct(ch)) && !text_check_whitespace(ch)) {
 
268
                                                if (st->text->curl && st->text->curc > 0) {
 
269
                                                        char ch = st->text->curl->line[st->text->curc - 1];
 
270
                                                        if ((ch == '_' || !ispunct(ch)) && !text_check_whitespace(ch)) {
267
271
                                                                get_suggest_prefix(st->text, -1);
268
272
                                                                text_pop_suggest_list();
269
273
                                                        }
274
278
                                                        texttool_suggest_clear();
275
279
                                        }
276
280
                                }
277
 
                                if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
 
281
                                if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0;
278
282
                                break;
279
283
                        case RIGHTARROWKEY:
280
 
                                if(tools & TOOL_SUGG_LIST) {
281
 
                                        if(qual)
 
284
                                if (tools & TOOL_SUGG_LIST) {
 
285
                                        if (qual)
282
286
                                                texttool_suggest_clear();
283
287
                                        else {
284
288
                                                /* Work out which char we are about to pass */
285
 
                                                if(st->text->curl && st->text->curc < st->text->curl->len) {
286
 
                                                        char ch= st->text->curl->line[st->text->curc+1];
287
 
                                                        if((ch=='_' || !ispunct(ch)) && !text_check_whitespace(ch)) {
 
289
                                                if (st->text->curl && st->text->curc < st->text->curl->len) {
 
290
                                                        char ch = st->text->curl->line[st->text->curc + 1];
 
291
                                                        if ((ch == '_' || !ispunct(ch)) && !text_check_whitespace(ch)) {
288
292
                                                                get_suggest_prefix(st->text, 1);
289
293
                                                                text_pop_suggest_list();
290
294
                                                        }
295
299
                                                        texttool_suggest_clear();
296
300
                                        }
297
301
                                }
298
 
                                if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
 
302
                                if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0;
299
303
                                break;
300
304
                        case PAGEDOWNKEY:
301
 
                                scroll= SUGG_LIST_SIZE-1;
 
305
                                scroll = SUGG_LIST_SIZE - 1;
302
306
                        case WHEELDOWNMOUSE:
303
307
                        case DOWNARROWKEY:
304
 
                                if(tools & TOOL_DOCUMENT) {
 
308
                                if (tools & TOOL_DOCUMENT) {
305
309
                                        doc_scroll++;
306
 
                                        swallow= 1;
307
 
                                        draw= 1;
 
310
                                        swallow = 1;
 
311
                                        draw = 1;
308
312
                                        break;
309
313
                                }
310
 
                                else if(tools & TOOL_SUGG_LIST) {
 
314
                                else if (tools & TOOL_SUGG_LIST) {
311
315
                                        SuggItem *sel = texttool_suggest_selected();
312
 
                                        if(!sel) {
 
316
                                        if (!sel) {
313
317
                                                texttool_suggest_select(texttool_suggest_first());
314
318
                                        }
315
 
                                        else while(sel && sel!=texttool_suggest_last() && sel->next && scroll--) {
316
 
                                                texttool_suggest_select(sel->next);
317
 
                                                sel= sel->next;
 
319
                                        else {
 
320
                                                while (sel && sel != texttool_suggest_last() && sel->next && scroll--) {
 
321
                                                        texttool_suggest_select(sel->next);
 
322
                                                        sel = sel->next;
 
323
                                                }
318
324
                                        }
319
325
                                        text_pop_suggest_list();
320
 
                                        swallow= 1;
321
 
                                        draw= 1;
 
326
                                        swallow = 1;
 
327
                                        draw = 1;
322
328
                                        break;
323
329
                                }
324
330
                        case PAGEUPKEY:
325
 
                                scroll= SUGG_LIST_SIZE-1;
 
331
                                scroll = SUGG_LIST_SIZE - 1;
326
332
                        case WHEELUPMOUSE:
327
333
                        case UPARROWKEY:
328
 
                                if(tools & TOOL_DOCUMENT) {
329
 
                                        if(doc_scroll>0) doc_scroll--;
330
 
                                        swallow= 1;
331
 
                                        draw= 1;
 
334
                                if (tools & TOOL_DOCUMENT) {
 
335
                                        if (doc_scroll > 0) doc_scroll--;
 
336
                                        swallow = 1;
 
337
                                        draw = 1;
332
338
                                        break;
333
339
                                }
334
 
                                else if(tools & TOOL_SUGG_LIST) {
 
340
                                else if (tools & TOOL_SUGG_LIST) {
335
341
                                        SuggItem *sel = texttool_suggest_selected();
336
 
                                        while(sel && sel!=texttool_suggest_first() && sel->prev && scroll--) {
 
342
                                        while (sel && sel != texttool_suggest_first() && sel->prev && scroll--) {
337
343
                                                texttool_suggest_select(sel->prev);
338
 
                                                sel= sel->prev;
 
344
                                                sel = sel->prev;
339
345
                                        }
340
346
                                        text_pop_suggest_list();
341
 
                                        swallow= 1;
342
 
                                        draw= 1;
 
347
                                        swallow = 1;
 
348
                                        draw = 1;
343
349
                                        break;
344
350
                                }
345
351
                        case RIGHTSHIFTKEY:
346
352
                        case LEFTSHIFTKEY:
347
353
                                break;
348
354
                        default:
349
 
                                if(tools & TOOL_SUGG_LIST) texttool_suggest_clear(), draw= 1;
350
 
                                if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
 
355
                                if (tools & TOOL_SUGG_LIST) texttool_suggest_clear(), draw = 1;
 
356
                                if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0, draw = 1;
351
357
                }
352
358
        }
353
359
 
354
 
        if(draw)
355
 
                {}; // XXX redraw_alltext();
356
 
        
 
360
        if (draw) {
 
361
                // XXX redraw_alltext();
 
362
        }
 
363
 
357
364
        return swallow;
358
365
}
359
366
 
360
367
#if 0
361
 
#ifndef DISABLE_PYTHON  
362
 
        /* Run text plugin scripts if enabled */
363
 
        if(st->doplugins && event && val) {
364
 
                if(BPY_menu_do_shortcut(PYMENU_TEXTPLUGIN, event, qual)) {
365
 
                        do_draw= 1;
366
 
                }
 
368
#ifdef WITH_PYTHON      
 
369
/* Run text plugin scripts if enabled */
 
370
if (st->doplugins && event && val)
 
371
{
 
372
        if (BPY_menu_do_shortcut(PYMENU_TEXTPLUGIN, event, qual)) {
 
373
                do_draw = 1;
367
374
        }
 
375
}
368
376
#endif
369
 
        if(do_draw)
370
 
                ; // XXX redraw_alltext();
 
377
if (do_draw)
 
378
        ;     // XXX redraw_alltext();
371
379
#endif
372
380
 
373
 
short do_textmarkers(SpaceText *st, char ascii, unsigned short evnt, short val)
 
381
static short UNUSED_FUNCTION(do_textmarkers) (SpaceText * st, char ascii, unsigned short evnt, short val)
374
382
{
375
383
        Text *text;
376
384
        TextMarker *marker, *mrk, *nxt;
377
 
        int c, s, draw=0, swallow=0;
378
 
        int qual= 0; // XXX
379
 
 
380
 
        text= st->text;
381
 
        if(!text || text->id.lib || text->curl != text->sell) return 0;
382
 
 
383
 
        marker= txt_find_marker(text, text->sell, text->selc, 0, 0);
384
 
        if(marker && (marker->start > text->curc || marker->end < text->curc))
385
 
                marker= NULL;
386
 
 
387
 
        if(!marker) {
 
385
        int c, s, draw = 0, swallow = 0;
 
386
        int qual = 0; // XXX
 
387
 
 
388
        text = st->text;
 
389
        if (!text || text->id.lib || text->curl != text->sell) return 0;
 
390
 
 
391
        marker = txt_find_marker(text, text->sell, text->selc, 0, 0);
 
392
        if (marker && (marker->start > text->curc || marker->end < text->curc))
 
393
                marker = NULL;
 
394
 
 
395
        if (!marker) {
388
396
                /* Find the next temporary marker */
389
 
                if(evnt==TABKEY) {
390
 
                        int lineno= txt_get_span(text->lines.first, text->curl);
391
 
                        TextMarker *mrk= text->markers.first;
392
 
                        while(mrk) {
393
 
                                if(!marker && (mrk->flags & TMARK_TEMP)) marker= mrk;
394
 
                                if((mrk->flags & TMARK_TEMP) && (mrk->lineno > lineno || (mrk->lineno==lineno && mrk->end > text->curc))) {
395
 
                                        marker= mrk;
 
397
                if (evnt == TABKEY) {
 
398
                        int lineno = txt_get_span(text->lines.first, text->curl);
 
399
                        mrk = text->markers.first;
 
400
                        while (mrk) {
 
401
                                if (!marker && (mrk->flags & TMARK_TEMP)) marker = mrk;
 
402
                                if ((mrk->flags & TMARK_TEMP) && (mrk->lineno > lineno || (mrk->lineno == lineno && mrk->end > text->curc))) {
 
403
                                        marker = mrk;
396
404
                                        break;
397
405
                                }
398
 
                                mrk= mrk->next;
 
406
                                mrk = mrk->next;
399
407
                        }
400
 
                        if(marker) {
 
408
                        if (marker) {
401
409
                                txt_move_to(text, marker->lineno, marker->start, 0);
402
410
                                txt_move_to(text, marker->lineno, marker->end, 1);
403
411
                                // XXX text_update_cursor_moved(C);
404
412
                                // XXX WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text);
405
 
                                evnt= ascii= val= 0;
406
 
                                draw= 1;
407
 
                                swallow= 1;
 
413
                                evnt = ascii = val = 0;
 
414
                                draw = 1;
 
415
                                swallow = 1;
408
416
                        }
409
417
                }
410
 
                else if(evnt==ESCKEY) {
411
 
                        if(txt_clear_markers(text, 0, TMARK_TEMP)) swallow= 1;
412
 
                        else if(txt_clear_markers(text, 0, 0)) swallow= 1;
 
418
                else if (evnt == ESCKEY) {
 
419
                        if (txt_clear_markers(text, 0, TMARK_TEMP)) swallow = 1;
 
420
                        else if (txt_clear_markers(text, 0, 0)) swallow = 1;
413
421
                        else return 0;
414
 
                        evnt= ascii= val= 0;
415
 
                        draw= 1;
 
422
                        evnt = ascii = val = 0;
 
423
                        draw = 1;
416
424
                }
417
 
                if(!swallow) return 0;
 
425
                if (!swallow) return 0;
418
426
        }
419
427
 
420
 
        if(ascii) {
421
 
                if(marker->flags & TMARK_EDITALL) {
422
 
                        c= text->curc-marker->start;
423
 
                        s= text->selc-marker->start;
424
 
                        if(s<0 || s>marker->end-marker->start) return 0;
 
428
        if (ascii) {
 
429
                if (marker->flags & TMARK_EDITALL) {
 
430
                        c = text->curc - marker->start;
 
431
                        s = text->selc - marker->start;
 
432
                        if (s < 0 || s > marker->end - marker->start) return 0;
425
433
 
426
 
                        mrk= txt_next_marker(text, marker);
427
 
                        while(mrk) {
428
 
                                nxt=txt_next_marker(text, mrk); /* mrk may become invalid */
429
 
                                txt_move_to(text, mrk->lineno, mrk->start+c, 0);
430
 
                                if(s!=c) txt_move_to(text, mrk->lineno, mrk->start+s, 1);
431
 
                                if(st->overwrite) {
432
 
                                        if(txt_replace_char(text, ascii))
433
 
                                                text_update_line_edited(st->text, st->text->curl);
 
434
                        mrk = txt_next_marker(text, marker);
 
435
                        while (mrk) {
 
436
                                nxt = txt_next_marker(text, mrk); /* mrk may become invalid */
 
437
                                txt_move_to(text, mrk->lineno, mrk->start + c, 0);
 
438
                                if (s != c) txt_move_to(text, mrk->lineno, mrk->start + s, 1);
 
439
                                if (st->overwrite) {
 
440
                                        if (txt_replace_char(text, ascii))
 
441
                                                text_update_line_edited(st->text->curl);
434
442
                                }
435
443
                                else {
436
 
                                        if(txt_add_char(text, ascii)) {
437
 
                                                text_update_line_edited(st->text, st->text->curl);
 
444
                                        if (txt_add_char(text, ascii)) {
 
445
                                                text_update_line_edited(st->text->curl);
438
446
                                        }
439
447
                                }
440
448
 
441
 
                                if(mrk==marker || mrk==nxt) break;
442
 
                                mrk=nxt;
 
449
                                if (mrk == marker || mrk == nxt) break;
 
450
                                mrk = nxt;
443
451
                        }
444
 
                        swallow= 1;
445
 
                        draw= 1;
 
452
                        swallow = 1;
 
453
                        draw = 1;
446
454
                }
447
455
        }
448
 
        else if(val) {
449
 
                switch(evnt) {
 
456
        else if (val) {
 
457
                switch (evnt) {
450
458
                        case BACKSPACEKEY:
451
 
                                if(marker->flags & TMARK_EDITALL) {
452
 
                                        c= text->curc-marker->start;
453
 
                                        s= text->selc-marker->start;
454
 
                                        if(s<0 || s>marker->end-marker->start) return 0;
 
459
                                if (marker->flags & TMARK_EDITALL) {
 
460
                                        c = text->curc - marker->start;
 
461
                                        s = text->selc - marker->start;
 
462
                                        if (s < 0 || s > marker->end - marker->start) return 0;
455
463
                                        
456
 
                                        mrk= txt_next_marker(text, marker);
457
 
                                        while(mrk) {
458
 
                                                nxt= txt_next_marker(text, mrk); /* mrk may become invalid */
459
 
                                                txt_move_to(text, mrk->lineno, mrk->start+c, 0);
460
 
                                                if(s!=c) txt_move_to(text, mrk->lineno, mrk->start+s, 1);
 
464
                                        mrk = txt_next_marker(text, marker);
 
465
                                        while (mrk) {
 
466
                                                nxt = txt_next_marker(text, mrk); /* mrk may become invalid */
 
467
                                                txt_move_to(text, mrk->lineno, mrk->start + c, 0);
 
468
                                                if (s != c) txt_move_to(text, mrk->lineno, mrk->start + s, 1);
461
469
                                                txt_backspace_char(text);
462
 
                                                text_update_line_edited(st->text, st->text->curl);
463
 
                                                if(mrk==marker || mrk==nxt) break;
464
 
                                                mrk= nxt;
 
470
                                                text_update_line_edited(st->text->curl);
 
471
                                                if (mrk == marker || mrk == nxt) break;
 
472
                                                mrk = nxt;
465
473
                                        }
466
 
                                        swallow= 1;
467
 
                                        draw= 1;
 
474
                                        swallow = 1;
 
475
                                        draw = 1;
468
476
                                }
469
477
                                break;
470
478
                        case DELKEY:
471
 
                                if(marker->flags & TMARK_EDITALL) {
472
 
                                        c= text->curc-marker->start;
473
 
                                        s= text->selc-marker->start;
474
 
                                        if(s<0 || s>marker->end-marker->start) return 0;
 
479
                                if (marker->flags & TMARK_EDITALL) {
 
480
                                        c = text->curc - marker->start;
 
481
                                        s = text->selc - marker->start;
 
482
                                        if (s < 0 || s > marker->end - marker->start) return 0;
475
483
                                        
476
 
                                        mrk= txt_next_marker(text, marker);
477
 
                                        while(mrk) {
478
 
                                                nxt= txt_next_marker(text, mrk); /* mrk may become invalid */
479
 
                                                txt_move_to(text, mrk->lineno, mrk->start+c, 0);
480
 
                                                if(s!=c) txt_move_to(text, mrk->lineno, mrk->start+s, 1);
 
484
                                        mrk = txt_next_marker(text, marker);
 
485
                                        while (mrk) {
 
486
                                                nxt = txt_next_marker(text, mrk); /* mrk may become invalid */
 
487
                                                txt_move_to(text, mrk->lineno, mrk->start + c, 0);
 
488
                                                if (s != c) txt_move_to(text, mrk->lineno, mrk->start + s, 1);
481
489
                                                txt_delete_char(text);
482
 
                                                text_update_line_edited(st->text, st->text->curl);
483
 
                                                if(mrk==marker || mrk==nxt) break;
484
 
                                                mrk= nxt;
 
490
                                                text_update_line_edited(st->text->curl);
 
491
                                                if (mrk == marker || mrk == nxt) break;
 
492
                                                mrk = nxt;
485
493
                                        }
486
 
                                        swallow= 1;
487
 
                                        draw= 1;
 
494
                                        swallow = 1;
 
495
                                        draw = 1;
488
496
                                }
489
497
                                break;
490
498
                        case TABKEY:
491
 
                                if(qual & LR_SHIFTKEY) {
492
 
                                        nxt= marker->prev;
493
 
                                        if(!nxt) nxt= text->markers.last;
 
499
                                if (qual & LR_SHIFTKEY) {
 
500
                                        nxt = marker->prev;
 
501
                                        if (!nxt) nxt = text->markers.last;
494
502
                                }
495
503
                                else {
496
 
                                        nxt= marker->next;
497
 
                                        if(!nxt) nxt= text->markers.first;
 
504
                                        nxt = marker->next;
 
505
                                        if (!nxt) nxt = text->markers.first;
498
506
                                }
499
 
                                if(marker->flags & TMARK_TEMP) {
500
 
                                        if(nxt==marker) nxt= NULL;
 
507
                                if (marker->flags & TMARK_TEMP) {
 
508
                                        if (nxt == marker) nxt = NULL;
501
509
                                        BLI_freelinkN(&text->markers, marker);
502
510
                                }
503
 
                                mrk= nxt;
504
 
                                if(mrk) {
 
511
                                mrk = nxt;
 
512
                                if (mrk) {
505
513
                                        txt_move_to(text, mrk->lineno, mrk->start, 0);
506
514
                                        txt_move_to(text, mrk->lineno, mrk->end, 1);
507
515
                                        // XXX text_update_cursor_moved(C);
508
516
                                        // XXX WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text);
509
517
                                }
510
 
                                swallow= 1;
511
 
                                draw= 1;
 
518
                                swallow = 1;
 
519
                                draw = 1;
512
520
                                break;
513
521
 
514
522
                        /* Events that should clear markers */
515
 
                        case UKEY: if(!(qual & LR_ALTKEY)) break;
516
 
                        case ZKEY: if(evnt==ZKEY && !(qual & LR_CTRLKEY)) break;
 
523
                        case UKEY: if (!(qual & LR_ALTKEY)) break;
 
524
                        case ZKEY: if (evnt == ZKEY && !(qual & LR_CTRLKEY)) break;
517
525
                        case RETKEY:
518
526
                        case ESCKEY:
519
 
                                if(marker->flags & (TMARK_EDITALL | TMARK_TEMP))
 
527
                                if (marker->flags & (TMARK_EDITALL | TMARK_TEMP))
520
528
                                        txt_clear_markers(text, marker->group, 0);
521
529
                                else
522
530
                                        BLI_freelinkN(&text->markers, marker);
523
 
                                swallow= 1;
524
 
                                draw= 1;
 
531
                                swallow = 1;
 
532
                                draw = 1;
525
533
                                break;
526
534
                        case RIGHTMOUSE: /* Marker context menu? */
527
535
                        case LEFTMOUSE:
528
536
                                break;
529
537
                        case FKEY: /* Allow find */
530
 
                                if(qual & LR_SHIFTKEY) swallow= 1;
 
538
                                if (qual & LR_SHIFTKEY) swallow = 1;
531
539
                                break;
532
540
 
533
541
                        default:
534
 
                                if(qual!=0 && qual!=LR_SHIFTKEY)
535
 
                                        swallow= 1; /* Swallow all other shortcut events */
 
542
                                if (qual != 0 && qual != LR_SHIFTKEY)
 
543
                                        swallow = 1;  /* Swallow all other shortcut events */
536
544
                }
537
545
        }
538
546
        
539
 
        if(draw)
540
 
                {}; // XXX redraw_alltext();
 
547
        if (draw) {
 
548
                // XXX redraw_alltext();
 
549
        }
541
550
        
542
551
        return swallow;
543
552
}