~ubuntu-branches/ubuntu/saucy/manaplus/saucy-proposed

« back to all changes in this revision

Viewing changes to src/gui/widgets/guitable.cpp

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi, Andrei Karas, Patrick Matthäi
  • Date: 2013-06-10 10:53:26 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130610105326-c3xqk5ebcgy3jxmb
Tags: 1.3.6.9-1
[ Andrei Karas ]
* Add new files to copyright file.

[ Patrick Matthäi ]
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
 
49
49
    virtual ~GuiTableActionListener();
50
50
 
51
 
    virtual void action(const gcn::ActionEvent& actionEvent);
 
51
    virtual void action(const gcn::ActionEvent& actionEvent) override;
52
52
 
53
53
protected:
54
54
    GuiTable *mTable;
170
170
    setHeight(getRowHeight() * rows_nr);
171
171
}
172
172
 
173
 
void GuiTable::setSelected(int row, int column)
 
173
void GuiTable::setSelected(const int row, const int column)
174
174
{
175
175
    mSelectedColumn = column;
176
176
    mSelectedRow = row;
194
194
int GuiTable::getRowHeight() const
195
195
{
196
196
    if (mModel)
197
 
        return mModel->getRowHeight() + 1;  // border
 
197
        return mModel->getRowHeight() + 4;  // border
198
198
    else
199
199
        return 0;
200
200
}
202
202
int GuiTable::getColumnWidth(int i) const
203
203
{
204
204
    if (mModel)
205
 
        return mModel->getColumnWidth(i) + 1;  // border
 
205
        return mModel->getColumnWidth(i) + 4;  // border
206
206
    else
207
207
        return 0;
208
208
}
209
209
 
210
 
void GuiTable::setSelectedRow(int selected)
 
210
void GuiTable::setSelectedRow(const int selected)
211
211
{
212
212
    if (!mModel)
213
213
    {
215
215
    }
216
216
    else
217
217
    {
 
218
        const int rows = mModel->getRows();
218
219
        if (selected < 0 && !mWrappingEnabled)
219
220
        {
220
221
            mSelectedRow = -1;
221
222
        }
222
 
        else if (selected >= mModel->getRows() && mWrappingEnabled)
 
223
        else if (selected >= rows && mWrappingEnabled)
223
224
        {
224
225
            mSelectedRow = 0;
225
226
        }
226
 
        else if ((selected >= mModel->getRows() && !mWrappingEnabled) ||
 
227
        else if ((selected >= rows && !mWrappingEnabled) ||
227
228
                 (selected < 0 && mWrappingEnabled))
228
229
        {
229
 
            mSelectedRow = mModel->getRows() - 1;
 
230
            mSelectedRow = rows - 1;
230
231
        }
231
232
        else
232
233
        {
235
236
    }
236
237
}
237
238
 
238
 
void GuiTable::setSelectedColumn(int selected)
 
239
void GuiTable::setSelectedColumn(const int selected)
239
240
{
240
241
    if (!mModel)
241
242
    {
301
302
    if (Client::getGuiAlpha() != mAlpha)
302
303
        mAlpha = Client::getGuiAlpha();
303
304
 
 
305
    const gcn::Rectangle &rect = mDimension;
 
306
    const int width = rect.width;
 
307
    const int height = rect.height;
 
308
    const int y = rect.y;
304
309
    if (mOpaque)
305
310
    {
306
311
        mBackgroundColor.a = static_cast<int>(mAlpha * 255.0f);
307
312
        graphics->setColor(mBackgroundColor);
308
 
        graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
 
313
        graphics->fillRectangle(gcn::Rectangle(0, 0, width, height));
309
314
    }
310
315
 
311
316
    // First, determine how many rows we need to draw,
312
317
    // and where we should start.
313
 
    int first_row = -(getY() / getRowHeight());
 
318
    const int rHeight = getRowHeight();
 
319
    int first_row = -(y / rHeight);
314
320
 
315
321
    if (first_row < 0)
316
322
        first_row = 0;
317
323
 
318
 
    unsigned rows_nr = 1 + (getHeight() / getRowHeight());  // May overestimate
319
 
                                                            // by one.
320
 
 
 
324
    unsigned rows_nr = 1 + (height / rHeight);  // May overestimate by one.
321
325
    unsigned max_rows_nr;
322
326
    if (mModel->getRows() < first_row)
323
327
        max_rows_nr = 0;
331
335
    const unsigned first_column = 0;
332
336
    const unsigned last_column1 = mModel->getColumns();
333
337
 
334
 
    // Set up everything for drawing
335
 
    const int height = getRowHeight();
336
 
    int y_offset = first_row * height;
 
338
    int y_offset = first_row * rHeight;
337
339
 
338
340
    for (unsigned r = first_row; r < first_row + rows_nr; ++r)
339
341
    {
342
344
        for (unsigned c = first_column; c + 1 <= last_column1; ++c)
343
345
        {
344
346
            gcn::Widget *const widget = mModel->getElementAt(r, c);
345
 
            const int width = getColumnWidth(c);
 
347
            const int cWidth = getColumnWidth(c);
346
348
            if (widget)
347
349
            {
348
 
                gcn::Rectangle bounds(x_offset, y_offset, width, height);
 
350
                gcn::Rectangle bounds(x_offset, y_offset, cWidth, rHeight);
349
351
 
350
352
                if (widget == mTopWidget)
351
353
                {
364
366
                        mSelectedRow) && c == 0)
365
367
                    {
366
368
                        graphics->fillRectangle(gcn::Rectangle(0, y_offset,
367
 
                            getWidth(), height));
 
369
                            width, rHeight));
368
370
                    }
369
371
                    else if (!mLinewiseMode && mSelectedColumn > 0
370
372
                             && c == static_cast<unsigned>(mSelectedColumn)
371
373
                             && r == static_cast<unsigned>(mSelectedRow))
372
374
                    {
373
375
                        graphics->fillRectangle(gcn::Rectangle(
374
 
                            x_offset, y_offset, width, height));
 
376
                            x_offset, y_offset, cWidth, rHeight));
375
377
                    }
376
378
                }
377
379
                graphics->pushClipArea(bounds);
379
381
                graphics->popClipArea();
380
382
            }
381
383
 
382
 
            x_offset += width;
 
384
            x_offset += cWidth;
383
385
        }
384
386
 
385
 
        y_offset += height;
 
387
        y_offset += rHeight;
386
388
    }
387
389
 
388
390
    if (mTopWidget)
410
412
 
411
413
gcn::Rectangle GuiTable::getChildrenArea()
412
414
{
413
 
    return gcn::Rectangle(0, 0, getWidth(), getHeight());
 
415
    return gcn::Rectangle(0, 0, mDimension.width, mDimension.height);
414
416
}
415
417
 
416
418
// -- KeyListener notifications
483
485
{
484
486
    if (isFocused())
485
487
    {
486
 
        if (getSelectedRow() > 0 || (getSelectedRow() == 0
487
 
            && mWrappingEnabled))
488
 
        {
489
 
            setSelectedRow(getSelectedRow() - 1);
490
 
        }
 
488
        const int selRow = getSelectedRow();
 
489
        if (selRow > 0 || (selRow == 0 && mWrappingEnabled))
 
490
            setSelectedRow(selRow - 1);
491
491
        mouseEvent.consume();
492
492
    }
493
493
}
552
552
{
553
553
    int row = -1;
554
554
 
555
 
    if (getRowHeight() > 0)
556
 
       row = y / getRowHeight();
 
555
    const int rowHeight = getRowHeight();
 
556
    if (rowHeight > 0)
 
557
       row = y / rowHeight;
557
558
 
558
559
    if (!mModel || row < 0 || row >= mModel->getRows())
559
560
        return -1;
592
593
 
593
594
    gcn::Widget::_setFocusHandler(focusHandler);
594
595
 
595
 
    for (int r = 0; r < mModel->getRows(); ++r)
 
596
    const int rows = mModel->getRows();
 
597
    const int cols = mModel->getColumns();
 
598
    for (int r = 0; r < rows; ++r)
596
599
    {
597
 
        for (int c = 0; c < mModel->getColumns(); ++c)
 
600
        for (int c = 0; c < cols ; ++c)
598
601
        {
599
602
            gcn::Widget *const w = mModel->getElementAt(r, c);
600
603
            if (w)