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

« back to all changes in this revision

Viewing changes to src/gui/BrowserDialog.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Mario Iseli
  • Date: 2006-04-08 18:38:25 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060408183825-vu1jk57rk929derx
* New Maintainer (Closes: #361345)
* New upstream release (Closes: #349725)
* Build-Depend now on libslang2-dev (Closes: #325577)
* Complete rebuild of debian/, upgraded to policy-standards
  3.6.2 and compat-level 5.
* Removed stellarc since stella only reads ~/.stellarc and even
  works without a first config.
* New debian/watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//============================================================================
 
2
//
 
3
//   SSSS    tt          lll  lll       
 
4
//  SS  SS   tt           ll   ll        
 
5
//  SS     tttttt  eeee   ll   ll   aaaa 
 
6
//   SSSS    tt   ee  ee  ll   ll      aa
 
7
//      SS   tt   eeeeee  ll   ll   aaaaa  --  "An Atari 2600 VCS Emulator"
 
8
//  SS  SS   tt   ee      ll   ll  aa  aa
 
9
//   SSSS     ttt  eeeee llll llll  aaaaa
 
10
//
 
11
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
 
12
//
 
13
// See the file "license" for information on usage and redistribution of
 
14
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
 
15
//
 
16
// $Id: BrowserDialog.cxx,v 1.18 2006/03/20 13:23:13 stephena Exp $
 
17
//
 
18
//   Based on code from ScummVM - Scumm Interpreter
 
19
//   Copyright (C) 2002-2004 The ScummVM project
 
20
//============================================================================
 
21
 
 
22
#include "OSystem.hxx"
 
23
#include "Widget.hxx"
 
24
#include "StringListWidget.hxx"
 
25
#include "Dialog.hxx"
 
26
#include "FSNode.hxx"
 
27
#include "GuiObject.hxx"
 
28
#include "GuiUtils.hxx"
 
29
#include "BrowserDialog.hxx"
 
30
 
 
31
#include "bspf.hxx"
 
32
 
 
33
/* We want to use this as a general directory selector at some point... possible uses
 
34
 * - to select the data dir for a game
 
35
 * - to select the place where save games are stored
 
36
 * - others???
 
37
 * TODO - make this dialog font sensitive
 
38
 */
 
39
 
 
40
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
41
BrowserDialog::BrowserDialog(GuiObject* boss, const GUI::Font& font,
 
42
                             int x, int y, int w, int h)
 
43
  : Dialog(boss->instance(), boss->parent(), x, y, w, h),
 
44
    CommandSender(boss),
 
45
    _fileList(NULL),
 
46
    _currentPath(NULL)
 
47
{
 
48
  const int lineHeight = font.getLineHeight(),
 
49
            bwidth     = font.getStringWidth("Cancel") + 20,
 
50
            bheight    = font.getLineHeight() + 4;
 
51
  int xpos, ypos;
 
52
 
 
53
  xpos = 10;  ypos = 4;
 
54
  _title = new StaticTextWidget(this, font, xpos, ypos,
 
55
                                _w - 2 * xpos, lineHeight,
 
56
                                "", kTextAlignCenter);
 
57
 
 
58
  // Current path - TODO: handle long paths ?
 
59
  ypos += lineHeight + 4;
 
60
  _currentPath = new StaticTextWidget(this, font, xpos, ypos,
 
61
                                       _w - 2 * xpos, lineHeight,
 
62
                                      "DUMMY", kTextAlignLeft);
 
63
 
 
64
  // Add file list
 
65
  ypos += lineHeight;
 
66
  _fileList = new StringListWidget(this, font, xpos, ypos,
 
67
                                   _w - 2 * xpos, _h - bheight - ypos - 15);
 
68
  _fileList->setNumberingMode(kListNumberingOff);
 
69
  _fileList->setEditable(false);
 
70
  _fileList->setFlags(WIDGET_NODRAW_FOCUS);
 
71
  addFocusWidget(_fileList);
 
72
 
 
73
  // Buttons
 
74
  xpos = 10;  ypos = _h - bheight - 8;
 
75
  _goUpButton = new ButtonWidget(this, font, xpos, ypos, bwidth, bheight,
 
76
                                 "Go up", kGoUpCmd, 0);
 
77
#ifndef MAC_OSX
 
78
  xpos = _w - 2 *(bwidth + 10);  
 
79
  new ButtonWidget(this, font, xpos, ypos, bwidth, bheight, "Choose",
 
80
                   kChooseCmd, 0);
 
81
  xpos += bwidth + 10;
 
82
  new ButtonWidget(this, font, xpos, ypos, bwidth, bheight, "Cancel",
 
83
                   kCloseCmd, 0);
 
84
#else
 
85
  xpos = _w - 2 *(bwidth + 10);  ypos = _h - bheight - 8;
 
86
  new ButtonWidget(this, font, xpos, ypos, bwidth, bheight, "Cancel",
 
87
                   kCloseCmd, 0);
 
88
  xpos += bwidth + 10;
 
89
  new ButtonWidget(this, font, xpos, ypos, bwidth, bheight, "Choose",
 
90
                   kChooseCmd, 0);
 
91
#endif
 
92
}
 
93
 
 
94
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
95
void BrowserDialog::setStartPath(const string& startpath)
 
96
{
 
97
  // If no node has been set, or the last used one is now invalid,
 
98
  // go back to the root/default dir.
 
99
  _choice = FilesystemNode(startpath);
 
100
 
 
101
  if (_choice.isValid())
 
102
    _node = _choice;
 
103
  else if (!_node.isValid())
 
104
    _node = FilesystemNode();
 
105
 
 
106
  // Alway refresh file list
 
107
  updateListing();
 
108
}
 
109
 
 
110
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
111
void BrowserDialog::handleCommand(CommandSender* sender, int cmd,
 
112
                                  int data, int id)
 
113
{
 
114
  switch (cmd)
 
115
  {
 
116
    case kChooseCmd:
 
117
    {
 
118
      // If nothing is selected in the list widget, choose the current dir.
 
119
      // Else, choose the dir that is selected.
 
120
      int selection = _fileList->getSelected();
 
121
      if (selection >= 0 && selection < (int)_nodeContent.size())
 
122
        _choice = _nodeContent[selection];
 
123
      else
 
124
        _choice = _node;
 
125
 
 
126
      // Send a signal to the calling class that a selection has been made
 
127
      // Since we aren't derived from a widget, we don't have a 'data' or 'id'
 
128
      if(_cmd)
 
129
        sendCommand(_cmd, 0, 0);
 
130
 
 
131
      close();
 
132
      break;
 
133
    }
 
134
 
 
135
    case kGoUpCmd:
 
136
      _node = _node.getParent();
 
137
      updateListing();
 
138
      break;
 
139
 
 
140
    case kListItemActivatedCmd:
 
141
    case kListItemDoubleClickedCmd:
 
142
      _node = _nodeContent[data];
 
143
      updateListing();
 
144
      break;
 
145
 
 
146
    default:
 
147
      Dialog::handleCommand(sender, cmd, data, 0);
 
148
      break;
 
149
  }
 
150
}
 
151
 
 
152
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
153
void BrowserDialog::updateListing()
 
154
{
 
155
  // Update the path display
 
156
  _currentPath->setLabel(_node.path());
 
157
 
 
158
  // Read in the data from the file system
 
159
  _nodeContent = _node.listDir();
 
160
  _nodeContent.sort();
 
161
 
 
162
  // Populate the ListWidget
 
163
  StringList list;
 
164
  int size = _nodeContent.size();
 
165
  for (int i = 0; i < size; i++)
 
166
  {
 
167
    if(_nodeContent[i].isDirectory())
 
168
      list.push_back(" [" + _nodeContent[i].displayName() + "]");
 
169
    else
 
170
      list.push_back(_nodeContent[i].displayName());
 
171
  }
 
172
 
 
173
  _fileList->setList(list);
 
174
  if(size > 0)
 
175
    _fileList->setSelected(0);
 
176
 
 
177
  // Only hilite the 'up' button if there's a parent directory
 
178
  _goUpButton->setEnabled(_node.hasParent());
 
179
 
 
180
  // Finally, redraw
 
181
  setDirty(); draw();
 
182
}