12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef UI_VIEWS_CONTROLS_TABLE_TABLE_UTILS_H_ 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define UI_VIEWS_CONTROLS_TABLE_TABLE_UTILS_H_ 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <vector> 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/models/table_model.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/views_export.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace gfx { 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class FontList; 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace views { 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TableView; 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)VIEWS_EXPORT extern const int kUnspecifiedColumnWidth; 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Returns the width needed to display the contents of the specified column. 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This is used internally by CalculateTableColumnSizes() and generally not 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// useful by itself. |header_padding| is padding added to the header. 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)VIEWS_EXPORT int WidthForContent(const gfx::FontList& header_font_list, 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::FontList& content_font_list, 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int padding, 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int header_padding, 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const ui::TableColumn& column, 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::TableModel* model); 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Determines the width for each of the specified columns. |width| is the width 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// to fit the columns into. |header_font_list| the font list used to draw the 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// header and |content_font_list| the header used to draw the content. |padding| 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// is extra horizontal spaced added to each cell, and |header_padding| added to 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// the width needed for the header. 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)VIEWS_EXPORT std::vector<int> CalculateTableColumnSizes( 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int width, 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int first_column_padding, 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::FontList& header_font_list, 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::FontList& content_font_list, 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int padding, 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int header_padding, 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::vector<ui::TableColumn>& columns, 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::TableModel* model); 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Converts a TableColumn::Alignment to the alignment for drawing the string. 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)int TableColumnAlignmentToCanvasAlignment(ui::TableColumn::Alignment alignment); 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Returns the index of the closest visible column index to |x|. Return value is 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// in terms of table->visible_columns(). 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)int GetClosestVisibleColumnIndex(const TableView* table, int x); 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace views 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // UI_VIEWS_CONTROLS_TABLE_TABLE_UTILS_H_ 58