~ubuntu-branches/debian/squeeze/stella/squeeze

« back to all changes in this revision

Viewing changes to src/gui/EditableWidget.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna, Franczen Attila, Luca Falavigna
  • Date: 2008-11-08 12:04:12 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20081108120412-w6xq87vzgokstfey
Tags: 2.6.1-0ubuntu1
[ Franczen Attila ]
* New upstream release (LP: #183571).
* Updated policy to 3.8.0.

[ Luca Falavigna ]
* debian/patches/gcc-4.3: fix FTBFS with gcc-4.3 compiler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
//  SS  SS   tt   ee      ll   ll  aa  aa
9
9
//   SSSS     ttt  eeeee llll llll  aaaaa
10
10
//
11
 
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
 
11
// Copyright (c) 1995-2008 by Bradford W. Mott and the Stella team
12
12
//
13
13
// See the file "license" for information on usage and redistribution of
14
14
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
15
15
//
16
 
// $Id: EditableWidget.cxx,v 1.17 2006/03/25 00:34:17 stephena Exp $
 
16
// $Id: EditableWidget.cxx,v 1.27 2008/02/06 13:45:23 stephena Exp $
17
17
//
18
18
//   Based on code from ScummVM - Scumm Interpreter
19
19
//   Copyright (C) 2002-2004 The ScummVM project
36
36
  _caretInverse = false;
37
37
 
38
38
  _editScrollOffset = 0;
 
39
 
 
40
  _bgcolor = kWidColor;
 
41
  _bgcolorhi = kWidColor;
 
42
  _textcolor = kTextColor;
 
43
  _textcolorhi = kTextColor;
39
44
}
40
45
 
41
46
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
58
63
  // Make sure the new string is seen onscreen
59
64
  setDirty(); draw();
60
65
}
 
66
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
67
void EditableWidget::setEditable(bool editable)
 
68
{
 
69
  _editable = editable;
 
70
  if(_editable)
 
71
    setFlags(WIDGET_WANTS_RAWDATA|WIDGET_RETAIN_FOCUS);
 
72
  else
 
73
    clearFlags(WIDGET_WANTS_RAWDATA|WIDGET_RETAIN_FOCUS);
 
74
}
61
75
 
62
76
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63
77
bool EditableWidget::tryInsertChar(char c, int pos)
83
97
  bool handled = true;
84
98
  bool dirty = false;
85
99
 
86
 
  switch (ascii)
 
100
  switch (keycode)
87
101
  {
88
102
    case '\n':  // enter/return
89
103
    case '\r':
108
122
      break;
109
123
 
110
124
    case 256 + 20:  // left arrow
111
 
                if (_caretPos > 0)
112
 
          dirty = setCaretPos(_caretPos - 1);
113
 
        break;
 
125
      if(instance()->eventHandler().kbdControl(modifiers))
 
126
        dirty = specialKeys(keycode);
 
127
      else if(_caretPos > 0)
 
128
        dirty = setCaretPos(_caretPos - 1);
 
129
      break;
114
130
 
115
131
    case 256 + 19:  // right arrow
116
 
      if (_caretPos < (int)_editString.size())
 
132
      if(instance()->eventHandler().kbdControl(modifiers))
 
133
        dirty = specialKeys(keycode);
 
134
      else if(_caretPos < (int)_editString.size())
117
135
        dirty = setCaretPos(_caretPos + 1);
118
136
      break;
119
137
 
180
198
  y += _y;
181
199
 
182
200
  FrameBuffer& fb = _boss->instance()->frameBuffer();
183
 
  fb.vLine(x, y+2, y + editRect.height() - 2, color);
 
201
  fb.vLine(x, y+2, y + editRect.height() - 3, color);
184
202
}
185
203
 
186
204
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
240
258
      setCaretPos(0);
241
259
      break;
242
260
 
 
261
    case 'c':
 
262
      copySelectedText();
 
263
      break;
 
264
 
243
265
    case 'e':
244
266
      setCaretPos(_editString.size());
245
267
      break;
256
278
      handled = killLine(-1);
257
279
      break;
258
280
 
 
281
    case 'v':
 
282
      pasteSelectedText();
 
283
      break;
 
284
 
259
285
    case 'w':
260
286
      handled = killLastWord();
261
287
      break;
262
288
 
 
289
    case 256 + 20:  // left arrow
 
290
      handled = moveWord(-1);
 
291
      break;
 
292
 
 
293
    case 256 + 19:  // right arrow
 
294
      handled = moveWord(+1);
 
295
      break;
 
296
 
263
297
    default:
264
298
      handled = false;
265
299
  }
351
385
 
352
386
  return handled;
353
387
}
 
388
 
 
389
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
390
bool EditableWidget::moveWord(int direction)
 
391
{
 
392
  bool handled = false;
 
393
  bool space = true;
 
394
  int currentPos = _caretPos;
 
395
 
 
396
  if(direction == -1)  // move to first character of previous word
 
397
  {
 
398
    while (currentPos > 0)
 
399
    {
 
400
      if (_editString[currentPos - 1] == ' ')
 
401
      {
 
402
        if (!space)
 
403
          break;
 
404
      }
 
405
      else
 
406
        space = false;
 
407
 
 
408
      currentPos--;
 
409
    }
 
410
    _caretPos = currentPos;
 
411
    handled = true;
 
412
  }
 
413
  else if(direction == +1)  // move to first character of next word
 
414
  {
 
415
    while (currentPos < (int)_editString.size())
 
416
    {
 
417
      if (_editString[currentPos - 1] == ' ')
 
418
      {
 
419
        if (!space)
 
420
          break;
 
421
      }
 
422
      else
 
423
        space = false;
 
424
 
 
425
      currentPos++;
 
426
    }
 
427
    _caretPos = currentPos;
 
428
    handled = true;
 
429
  }
 
430
 
 
431
  return handled;
 
432
}
 
433
 
 
434
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
435
void EditableWidget::copySelectedText()
 
436
{
 
437
  _clippedText = _editString;
 
438
}
 
439
 
 
440
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
441
void EditableWidget::pasteSelectedText()
 
442
{
 
443
  _editString = _clippedText;
 
444
}
 
445
 
 
446
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
447
string EditableWidget::_clippedText = "";