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

« back to all changes in this revision

Viewing changes to src/debugger/gui/RomListWidget.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Kitt
  • Date: 2010-07-12 23:49:36 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100712234936-juawrr3etzhr2qpv
Tags: 3.1.2-1
* New maintainer (closes: #532039).
* New upstream version (closes: #461121):
  - includes launcher (closes: #396058).
* Fix the reference to the X Window System in the description (closes:
  #411815).
* Move to main, DFSG-free ROMs are available (see README.Debian).
* Enhance the package description.
* Drop the libslang2-dev dependency (closes: #560274).
* Remove the Encoding entry from stella.desktop.
* Avoid ignoring errors when cleaning.
* Add ${misc:Depends} to the package dependencies.
* Provide a doc-base file to install the documentation using doc-base.
* Switch to debhelper 7 with a simplified rules file.
* Use autotools-dev to provide updated configuration files.
* Update to Standards-Version 3.9.0:
  - Move to menu section Applications/Emulators.
  - Move the homepage declaration.
* Re-write the manpage.

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-2008 by Bradford W. Mott and the Stella team
 
11
// Copyright (c) 1995-2010 by Bradford W. Mott, Stephen Anthony
 
12
// and the Stella Team
12
13
//
13
 
// See the file "license" for information on usage and redistribution of
 
14
// See the file "License.txt" for information on usage and redistribution of
14
15
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
15
16
//
16
 
// $Id: RomListWidget.cxx,v 1.12 2008/05/11 21:18:34 stephena Exp $
 
17
// $Id: RomListWidget.cxx 2001 2010-04-10 21:37:23Z stephena $
17
18
//
18
19
//   Based on code from ScummVM - Scumm Interpreter
19
20
//   Copyright (C) 2002-2004 The ScummVM project
20
21
//============================================================================
21
22
 
22
23
#include "bspf.hxx"
 
24
#include "Debugger.hxx"
23
25
#include "ContextMenu.hxx"
 
26
#include "Widget.hxx"
 
27
#include "ScrollBarWidget.hxx"
24
28
#include "RomListWidget.hxx"
25
29
 
26
30
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
27
31
RomListWidget::RomListWidget(GuiObject* boss, const GUI::Font& font,
28
32
                             int x, int y, int w, int h)
29
 
  : CheckListWidget(boss, font, x, y, w, h),
 
33
  : EditableWidget(boss, font, x, y, 16, 16),
30
34
    myMenu(NULL),
31
 
    myHighlightedItem(-1)
 
35
    _rows(0),
 
36
    _cols(0),
 
37
    _currentPos(0),
 
38
    _selectedItem(-1),
 
39
    _highlightedItem(-1),
 
40
    _currentKeyDown(0),
 
41
    _editMode(false)
32
42
{
 
43
  _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS;
33
44
  _type = kRomListWidget;
34
 
 
35
 
  myMenu = new ContextMenu(this, font);
36
 
 
37
 
  StringList l;
 
45
  _bgcolor = kWidColor;
 
46
  _bgcolorhi = kWidColor;
 
47
  _textcolor = kTextColor;
 
48
  _textcolorhi = kTextColor;
 
49
 
 
50
  _cols = w / _fontWidth;
 
51
  _rows = h / _fontHeight;
 
52
 
 
53
  // Set real dimensions
 
54
  _w = w - kScrollBarWidth;
 
55
  _h = h + 2;
 
56
 
 
57
  // Create scrollbar and attach to the list
 
58
  myScrollBar = new ScrollBarWidget(boss, font, _x + _w, _y, kScrollBarWidth, _h);
 
59
  myScrollBar->setTarget(this);
 
60
 
 
61
  // Add context menu
 
62
  StringMap l;
38
63
//  l.push_back("Add bookmark");
39
 
  l.push_back("Save ROM");
40
 
  l.push_back("Set PC");
41
 
 
42
 
  myMenu->setList(l);
 
64
  l.push_back("Save ROM", "saverom");
 
65
  l.push_back("Set PC", "setpc");
 
66
  l.push_back("RunTo PC", "runtopc");
 
67
  myMenu = new ContextMenu(this, font, l);
43
68
 
44
69
  // Take advantage of a wide debugger window when possible
45
70
  const int fontWidth = font.getMaxCharWidth(),
46
71
            numchars = w / fontWidth;
47
72
 
48
 
  myLabelWidth = BSPF_max(20, int(0.35 * (numchars - 12))) * fontWidth;
49
 
  myBytesWidth = 12 * fontWidth;
 
73
  _labelWidth = BSPF_max(16, int(0.35 * (numchars - 12))) * fontWidth;
 
74
  _bytesWidth = 12 * fontWidth;
 
75
 
 
76
  //////////////////////////////////////////////////////
 
77
  // Add checkboxes
 
78
  int ypos = _y + 2;
 
79
 
 
80
  // rowheight is determined by largest item on a line,
 
81
  // possibly meaning that number of rows will change
 
82
  _fontHeight = BSPF_max(_fontHeight, CheckboxWidget::boxSize());
 
83
  _rows = h / _fontHeight;
 
84
 
 
85
  // Create a CheckboxWidget for each row in the list
 
86
  CheckboxWidget* t;
 
87
  for(int i = 0; i < _rows; ++i)
 
88
  {
 
89
    t = new CheckboxWidget(boss, font, _x + 2, ypos, "", kCheckActionCmd);
 
90
    t->setTarget(this);
 
91
    t->setID(i);
 
92
    t->drawBox(false);
 
93
    t->setFill(true);
 
94
    t->setTextColor(kTextColorEm);
 
95
    ypos += _fontHeight;
 
96
 
 
97
    myCheckList.push_back(t);
 
98
  }
50
99
}
51
100
 
52
101
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
56
105
}
57
106
 
58
107
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
59
 
void RomListWidget::setList(StringList& label, StringList& bytes, StringList& disasm,
60
 
                            BoolArray& state)
61
 
{
62
 
  myLabel  = label;
63
 
  myDisasm = disasm;
64
 
 
65
 
  CheckListWidget::setList(bytes, state);
 
108
void RomListWidget::setList(const CartDebug::DisassemblyList& list,
 
109
                            const PackedBitArray& state)
 
110
{
 
111
  myList = &list;
 
112
  myBPState = &state;
 
113
 
 
114
  // Enable all checkboxes
 
115
  for(int i = 0; i < _rows; ++i)
 
116
    myCheckList[i]->setFlags(WIDGET_ENABLED);
 
117
 
 
118
  // Then turn off any extras
 
119
  if((int)myList->size() < _rows)
 
120
    for(int i = myList->size(); i < _rows; ++i)
 
121
      myCheckList[i]->clearFlags(WIDGET_ENABLED);
 
122
 
 
123
  recalc();
 
124
}
 
125
 
 
126
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
127
void RomListWidget::setHighlighted(int item)
 
128
{
 
129
  if(item < -1 || item >= (int)myList->size())
 
130
    return;
 
131
 
 
132
  if(isEnabled())
 
133
  {
 
134
    if(_editMode)
 
135
      abortEditMode();
 
136
 
 
137
    _highlightedItem = item;
 
138
 
 
139
    // Only scroll the list if we're about to pass the page boundary
 
140
    if(_currentPos == 0)
 
141
      _currentPos = _highlightedItem;
 
142
    else if(_highlightedItem == _currentPos + _rows)
 
143
      _currentPos += _rows;
 
144
 
 
145
    scrollToHighlighted();
 
146
  }
 
147
}
 
148
 
 
149
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
150
const string& RomListWidget::getEditString() const
 
151
{
 
152
  if(_selectedItem < -1 || _selectedItem >= (int)myList->size())
 
153
    return EmptyString;
 
154
  else
 
155
    return _editString;
 
156
}
 
157
 
 
158
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
159
int RomListWidget::findItem(int x, int y) const
 
160
{
 
161
  return (y - 1) / _fontHeight + _currentPos;
 
162
}
 
163
 
 
164
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
165
void RomListWidget::recalc()
 
166
{
 
167
  int size = myList->size();
 
168
 
 
169
  if (_currentPos >= size)
 
170
    _currentPos = size - 1;
 
171
  if (_currentPos < 0)
 
172
    _currentPos = 0;
 
173
 
 
174
  if(_selectedItem < 0 || _selectedItem >= size)
 
175
    _selectedItem = 0;
 
176
 
 
177
  _editMode = false;
 
178
 
 
179
  myScrollBar->_numEntries     = myList->size();
 
180
  myScrollBar->_entriesPerPage = _rows;
 
181
 
 
182
  // Reset to normal data entry
 
183
  abortEditMode();
 
184
}
 
185
 
 
186
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
187
void RomListWidget::scrollToCurrent(int item)
 
188
{
 
189
  // Only do something if the current item is not in our view port
 
190
  if (item < _currentPos)
 
191
  {
 
192
    // it's above our view
 
193
    _currentPos = item;
 
194
  }
 
195
  else if (item >= _currentPos + _rows )
 
196
  {
 
197
    // it's below our view
 
198
    _currentPos = item - _rows + 1;
 
199
  }
 
200
 
 
201
  if (_currentPos < 0 || _rows > (int)myList->size())
 
202
    _currentPos = 0;
 
203
  else if (_currentPos + _rows > (int)myList->size())
 
204
    _currentPos = myList->size() - _rows;
 
205
 
 
206
  myScrollBar->_currentPos = _currentPos;
 
207
  myScrollBar->recalc();
 
208
 
 
209
  setDirty(); draw();
66
210
}
67
211
 
68
212
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
69
213
void RomListWidget::handleMouseDown(int x, int y, int button, int clickCount)
70
214
{
71
 
  // Grab right mouse button for context menu, send left to base class
 
215
  if (!isEnabled())
 
216
    return;
 
217
 
 
218
  // Grab right mouse button for context menu, left for selection/edit mode
72
219
  if(button == 2)
73
220
  {
74
 
    myMenu->setPos(x + getAbsX(), y + getAbsY());
75
 
    myMenu->show();
76
 
  }
77
 
 
78
 
  ListWidget::handleMouseDown(x, y, button, clickCount);
 
221
    // Set selected and add menu at current x,y mouse location
 
222
    _selectedItem = findItem(x, y);
 
223
    scrollToSelected();
 
224
    myMenu->show(x + getAbsX(), y + getAbsY());
 
225
  }
 
226
  else
 
227
  {
 
228
    // First check whether the selection changed
 
229
    int newSelectedItem;
 
230
    newSelectedItem = findItem(x, y);
 
231
    if (newSelectedItem > (int)myList->size() - 1)
 
232
      newSelectedItem = -1;
 
233
 
 
234
    if (_selectedItem != newSelectedItem)
 
235
    {
 
236
      if (_editMode)
 
237
        abortEditMode();
 
238
      _selectedItem = newSelectedItem;
 
239
      setDirty(); draw();
 
240
    }
 
241
  }
 
242
}
 
243
 
 
244
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
245
void RomListWidget::handleMouseUp(int x, int y, int button, int clickCount)
 
246
{
 
247
  // If this was a double click and the mouse is still over the selected item,
 
248
  // send the double click command
 
249
  if (clickCount == 2 && (_selectedItem == findItem(x, y)))
 
250
  {
 
251
    // Start edit mode
 
252
    if(_editable && !_editMode)
 
253
      startEditMode();
 
254
  }
 
255
}
 
256
 
 
257
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
258
void RomListWidget::handleMouseWheel(int x, int y, int direction)
 
259
{
 
260
  myScrollBar->handleMouseWheel(x, y, direction);
 
261
}
 
262
 
 
263
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
264
bool RomListWidget::handleKeyDown(int ascii, int keycode, int modifiers)
 
265
{
 
266
  // Ignore all Alt-mod keys
 
267
  if(instance().eventHandler().kbdAlt(modifiers))
 
268
    return true;
 
269
 
 
270
  bool handled = true;
 
271
  int oldSelectedItem = _selectedItem;
 
272
 
 
273
  if (_editMode)
 
274
  {
 
275
    // Class EditableWidget handles all text editing related key presses for us
 
276
    handled = EditableWidget::handleKeyDown(ascii, keycode, modifiers);
 
277
  }
 
278
  else
 
279
  {
 
280
    // not editmode
 
281
    switch (keycode)
 
282
    {
 
283
      case ' ':  // space
 
284
        // Snap list back to currently highlighted line
 
285
        if(_highlightedItem >= 0)
 
286
        {
 
287
          _currentPos = _highlightedItem;
 
288
          scrollToHighlighted();
 
289
        }
 
290
        break;
 
291
 
 
292
      default:
 
293
        handled = false;
 
294
    }
 
295
  }
 
296
 
 
297
  if (_selectedItem != oldSelectedItem)
 
298
  {
 
299
    myScrollBar->draw();
 
300
    scrollToSelected();
 
301
  }
 
302
 
 
303
  _currentKeyDown = keycode;
 
304
  return handled;
 
305
}
 
306
 
 
307
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
308
bool RomListWidget::handleKeyUp(int ascii, int keycode, int modifiers)
 
309
{
 
310
  if (keycode == _currentKeyDown)
 
311
    _currentKeyDown = 0;
 
312
  return true;
79
313
}
80
314
 
81
315
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
82
316
bool RomListWidget::handleEvent(Event::Type e)
83
317
{
84
 
  return ListWidget::handleEvent(e); // override CheckListWidget::handleEvent()
 
318
  if(!isEnabled() || _editMode)
 
319
    return false;
 
320
 
 
321
  bool handled = true;
 
322
  int oldSelectedItem = _selectedItem;
 
323
 
 
324
  switch(e)
 
325
  {
 
326
    case Event::UISelect:
 
327
      if (_selectedItem >= 0)
 
328
      {
 
329
        if (_editable)
 
330
          startEditMode();
 
331
      }
 
332
      break;
 
333
 
 
334
    case Event::UIUp:
 
335
      if (_selectedItem > 0)
 
336
        _selectedItem--;
 
337
      break;
 
338
 
 
339
    case Event::UIDown:
 
340
      if (_selectedItem < (int)myList->size() - 1)
 
341
        _selectedItem++;
 
342
      break;
 
343
 
 
344
    case Event::UIPgUp:
 
345
      _selectedItem -= _rows - 1;
 
346
      if (_selectedItem < 0)
 
347
        _selectedItem = 0;
 
348
      break;
 
349
 
 
350
    case Event::UIPgDown:
 
351
      _selectedItem += _rows - 1;
 
352
      if (_selectedItem >= (int)myList->size() )
 
353
        _selectedItem = myList->size() - 1;
 
354
      break;
 
355
 
 
356
    case Event::UIHome:
 
357
      _selectedItem = 0;
 
358
      break;
 
359
 
 
360
    case Event::UIEnd:
 
361
      _selectedItem = myList->size() - 1;
 
362
      break;
 
363
 
 
364
    default:
 
365
      handled = false;
 
366
  }
 
367
 
 
368
  if (_selectedItem != oldSelectedItem)
 
369
  {
 
370
    myScrollBar->draw();
 
371
    scrollToSelected();
 
372
  }
 
373
 
 
374
  return handled;
 
375
}
 
376
 
 
377
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
378
void RomListWidget::handleCommand(CommandSender* sender, int cmd, int data, int id)
 
379
{
 
380
  switch (cmd)
 
381
  {
 
382
    case kCheckActionCmd:
 
383
      // We let the parent class handle this
 
384
      // Pass it as a kRLBreakpointChangedCmd command, since that's the intent
 
385
      sendCommand(kRLBreakpointChangedCmd, myCheckList[id]->getState(), _currentPos+id);
 
386
      break;
 
387
 
 
388
    case kSetPositionCmd:
 
389
      if (_currentPos != (int)data)
 
390
      {
 
391
        _currentPos = data;
 
392
        setDirty(); draw();
 
393
      }
 
394
      break;
 
395
  }
 
396
}
 
397
 
 
398
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
399
void RomListWidget::lostFocusWidget()
 
400
{
 
401
  _editMode = false;
 
402
 
 
403
  // Reset to normal data entry
 
404
  abortEditMode();
85
405
}
86
406
 
87
407
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
88
408
void RomListWidget::drawWidget(bool hilite)
89
409
{
90
410
//cerr << "RomListWidget::drawWidget\n";
91
 
  FrameBuffer& fb = _boss->instance()->frameBuffer();
92
 
  int i, pos, len = _list.size();
93
 
  string buffer;
 
411
  FBSurface& s = _boss->dialog().surface();
 
412
  const CartDebug::DisassemblyList& dlist = *myList;
 
413
  int i, pos, xpos, ypos, len = dlist.size();
94
414
  int deltax;
95
415
 
96
416
  // Draw a thin frame around the list and to separate columns
97
 
  fb.hLine(_x, _y, _x + _w - 1, kColor);
98
 
  fb.hLine(_x, _y + _h - 1, _x + _w - 1, kShadowColor);
99
 
  fb.vLine(_x, _y, _y + _h - 1, kColor);
 
417
  s.hLine(_x, _y, _x + _w - 1, kColor);
 
418
  s.hLine(_x, _y + _h - 1, _x + _w - 1, kShadowColor);
 
419
  s.vLine(_x, _y, _y + _h - 1, kColor);
100
420
 
101
 
  fb.vLine(_x + CheckboxWidget::boxSize() + 5, _y, _y + _h - 1, kColor);
 
421
  s.vLine(_x + CheckboxWidget::boxSize() + 5, _y, _y + _h - 1, kColor);
102
422
 
103
423
  // Draw the list items
104
 
  for (i = 0, pos = _currentPos; i < _rows && pos < len; i++, pos++)
 
424
  const GUI::Rect& r = getEditRect();
 
425
  const GUI::Rect& l = getLineRect();
 
426
  int large_disasmw = _w - l.x() - _labelWidth,
 
427
      small_disasmw = large_disasmw - r.width();
 
428
  xpos = _x + CheckboxWidget::boxSize() + 10;  ypos = _y + 2;
 
429
  for (i = 0, pos = _currentPos; i < _rows && pos < len; i++, pos++, ypos += _fontHeight)
105
430
  {
106
431
    // Draw checkboxes for correct lines (takes scrolling into account)
107
 
    _checkList[i]->setState(_stateList[pos]);
108
 
    _checkList[i]->setDirty();
109
 
    _checkList[i]->draw();
110
 
 
111
 
    const int y = _y + 2 + _fontHeight * i;
112
 
 
113
 
    GUI::Rect l = getLineRect();
114
 
    GUI::Rect r = getEditRect();
 
432
    myCheckList[i]->setState(myBPState->isSet(dlist[pos].address));
 
433
    myCheckList[i]->setDirty();
 
434
    myCheckList[i]->draw();
115
435
 
116
436
    // Draw highlighted item in a frame
117
437
    if (_highlightedItem == pos)
118
438
    {
119
 
      fb.frameRect(_x + l.left - 3, _y + 1 + _fontHeight * i,
120
 
                   _w - l.left, _fontHeight, kDbgColorHi);
 
439
      s.frameRect(_x + l.x() - 3, _y + 1 + _fontHeight * i,
 
440
                  _w - l.x(), _fontHeight, kDbgColorHi);
121
441
    }
122
442
 
123
443
    // Draw the selected item inverted, on a highlighted background.
124
444
    if (_selectedItem == pos && _hasFocus)
125
445
    {
126
446
      if (!_editMode)
127
 
        fb.fillRect(_x + r.left - 3, _y + 1 + _fontHeight * i,
128
 
                    r.width(), _fontHeight,
129
 
                    kTextColorHi);
 
447
        s.fillRect(_x + r.x() - 3, _y + 1 + _fontHeight * i,
 
448
                   r.width(), _fontHeight, kTextColorHi);
130
449
      else
131
 
        fb.frameRect(_x + r.left - 3, _y + 1 + _fontHeight * i,
132
 
                     r.width(), _fontHeight,
133
 
                     kTextColorHi);
 
450
        s.frameRect(_x + r.x() - 3, _y + 1 + _fontHeight * i,
 
451
                    r.width(), _fontHeight, kTextColorHi);
134
452
    }
135
453
 
136
 
    // Draw labels and actual disassembly
137
 
    fb.drawString(_font, myLabel[pos], _x + r.left - myLabelWidth, y,
138
 
                  myLabelWidth, kTextColor);
139
 
 
140
 
    fb.drawString(_font, myDisasm[pos], _x + r.right, y,
141
 
                  _w - r.right, kTextColor);
142
 
 
143
 
    // Draw editable bytes
144
 
    if (_selectedItem == pos && _editMode)
 
454
    // Draw labels
 
455
    s.drawString(_font, dlist[pos].label, xpos, ypos, _labelWidth, kTextColor);
 
456
 
 
457
    // Sometimes there aren't any bytes to display, in which case the disassembly
 
458
    // should get all remaining space
 
459
    if(dlist[pos].bytes != "")
145
460
    {
146
 
      buffer = _editString;
147
 
      adjustOffset();
148
 
      deltax = -_editScrollOffset;
149
 
 
150
 
      fb.drawString(_font, buffer, _x + r.left, y, r.width(), kTextColor,
151
 
                    kTextAlignLeft, deltax, false);
 
461
      // Draw disassembly
 
462
      s.drawString(_font, dlist[pos].disasm, xpos + _labelWidth, ypos,
 
463
                   small_disasmw, kTextColor);
 
464
 
 
465
      // Draw bytes
 
466
      {
 
467
        if (_selectedItem == pos && _editMode)
 
468
        {
 
469
          adjustOffset();
 
470
          deltax = -_editScrollOffset;
 
471
 
 
472
          s.drawString(_font, _editString, _x + r.x(), ypos, r.width(), kTextColor,
 
473
                       kTextAlignLeft, deltax, false);
 
474
 
 
475
          drawCaret();
 
476
        }
 
477
        else
 
478
        {
 
479
          deltax = 0;
 
480
          s.drawString(_font, dlist[pos].bytes, _x + r.x(), ypos, r.width(), kTextColor);
 
481
        }
 
482
      }
152
483
    }
153
484
    else
154
485
    {
155
 
      buffer = _list[pos];
156
 
      deltax = 0;
157
 
      fb.drawString(_font, buffer, _x + r.left, y, r.width(), kTextColor);
 
486
      // Draw disassembly, giving it all remaining horizontal space
 
487
      s.drawString(_font, dlist[pos].disasm, xpos + _labelWidth, ypos,
 
488
                   large_disasmw, kTextColor);
158
489
    }
159
490
  }
160
 
 
161
 
  // Only draw the caret while editing, and if it's in the current viewport
162
 
  if(_editMode && (_selectedItem >= _scrollBar->_currentPos) &&
163
 
    (_selectedItem < _scrollBar->_currentPos + _rows))
164
 
    drawCaret();
165
491
}
166
492
 
167
493
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
172
498
            xoffset = CheckboxWidget::boxSize() + 10;
173
499
  r.top    += yoffset;
174
500
  r.bottom += yoffset;
175
 
  r.left  += xoffset;
176
 
  r.right -= xoffset - 15;
 
501
  r.left   += xoffset;
 
502
  r.right  -= xoffset - 15;
177
503
        
178
504
  return r;
179
505
}
182
508
GUI::Rect RomListWidget::getEditRect() const
183
509
{
184
510
  GUI::Rect r(2, 1, _w, _fontHeight);
185
 
  const int yoffset = (_selectedItem - _currentPos) * _fontHeight,
186
 
            xoffset = CheckboxWidget::boxSize() + 10;
 
511
  const int yoffset = (_selectedItem - _currentPos) * _fontHeight;
187
512
  r.top    += yoffset;
188
513
  r.bottom += yoffset;
189
 
  r.left   += xoffset + myLabelWidth;
190
 
  r.right   = r.left + myBytesWidth;
 
514
  r.left   += _w - _bytesWidth;
 
515
  r.right   = _w;
191
516
        
192
517
  return r;
193
518
}
 
519
 
 
520
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
521
bool RomListWidget::tryInsertChar(char c, int pos)
 
522
{
 
523
  // Not sure how efficient this is, or should we even care?
 
524
  c = tolower(c);
 
525
  if((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') ||
 
526
     c == '%' || c == '#' || c == '$' || c == ' ')
 
527
  {
 
528
    _editString.insert(pos, 1, c);
 
529
    return true;
 
530
  }
 
531
  else
 
532
    return false;
 
533
}
 
534
 
 
535
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
536
void RomListWidget::startEditMode()
 
537
{
 
538
  if (_editable && !_editMode && _selectedItem >= 0)
 
539
  {
 
540
    // Does this line represent an editable area?
 
541
    if((*myList)[_selectedItem].bytes == "")
 
542
      return;
 
543
 
 
544
    _editMode = true;
 
545
 
 
546
    // Widget gets raw data while editing
 
547
    EditableWidget::startEditMode();
 
548
    setEditString((*myList)[_selectedItem].bytes);
 
549
  }
 
550
}
 
551
 
 
552
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
553
void RomListWidget::endEditMode()
 
554
{
 
555
  if (!_editMode)
 
556
    return;
 
557
 
 
558
  // Send a message that editing finished with a return/enter key press
 
559
  // The parent then calls getEditString() to get the newly entered data
 
560
  _editMode = false;
 
561
  sendCommand(kRLRomChangedCmd, _selectedItem, _id);
 
562
 
 
563
  // Reset to normal data entry
 
564
  EditableWidget::endEditMode();
 
565
}
 
566
 
 
567
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
568
void RomListWidget::abortEditMode()
 
569
{
 
570
  // Undo any changes made
 
571
  _editMode = false;
 
572
 
 
573
  // Reset to normal data entry
 
574
  EditableWidget::abortEditMode();
 
575
}