X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fgui%2FguiTable.cpp;h=2f761cc773eb9b85e36562f892b56c86ac4ca035;hb=ad148587dcf5244c2d2011dba339786c765c54c4;hp=a2738afa9dac4d1f2d222a05a83a8bb85f8ea6ee;hpb=20a85d76d94c9c5c7fbe198c3d0e1fbee97a485f;p=dragonfireclient.git diff --git a/src/gui/guiTable.cpp b/src/gui/guiTable.cpp index a2738afa9..2f761cc77 100644 --- a/src/gui/guiTable.cpp +++ b/src/gui/guiTable.cpp @@ -17,7 +17,6 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - #include "guiTable.h" #include #include @@ -25,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include -#include #include "client/renderingengine.h" #include "debug.h" #include "log.h" @@ -34,25 +32,22 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/string.h" #include "util/numeric.h" #include "util/string.h" // for parseColorString() -#include "settings.h" // for settings -#include "porting.h" // for dpi -#include "guiscalingfilter.h" +#include "settings.h" // for settings +#include "porting.h" // for dpi +#include "client/guiscalingfilter.h" /* GUITable */ -GUITable::GUITable(gui::IGUIEnvironment *env, - gui::IGUIElement* parent, s32 id, - core::rect rectangle, - ISimpleTextureSource *tsrc -): - gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle), - m_tsrc(tsrc) +GUITable::GUITable(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, + core::rect rectangle, ISimpleTextureSource *tsrc) : + gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle), + m_tsrc(tsrc) { assert(tsrc != NULL); - gui::IGUISkin* skin = Environment->getSkin(); + gui::IGUISkin *skin = Environment->getSkin(); m_font = skin->getFont(); if (m_font) { @@ -62,12 +57,11 @@ GUITable::GUITable(gui::IGUIEnvironment *env, } const s32 s = skin->getSize(gui::EGDS_SCROLLBAR_SIZE); - m_scrollbar = Environment->addScrollBar(false, - core::rect(RelativeRect.getWidth() - s, - 0, + m_scrollbar = new GUIScrollBar(Environment, this, -1, + core::rect(RelativeRect.getWidth() - s, 0, RelativeRect.getWidth(), RelativeRect.getHeight()), - this, -1); + false, true); m_scrollbar->setSubElement(true); m_scrollbar->setTabStop(false); m_scrollbar->setAlignment(gui::EGUIA_LOWERRIGHT, gui::EGUIA_LOWERRIGHT, @@ -78,15 +72,17 @@ GUITable::GUITable(gui::IGUIEnvironment *env, setTabStop(true); setTabOrder(-1); updateAbsolutePosition(); - + float density = RenderingEngine::getDisplayDensity(); +#ifdef __ANDROID__ + density = 1; // dp scaling is applied by the skin +#endif core::rect relative_rect = m_scrollbar->getRelativePosition(); - s32 width = (relative_rect.getWidth()/(2.0/3.0)) * - RenderingEngine::getDisplayDensity() * - g_settings->getFloat("gui_scaling"); + s32 width = (relative_rect.getWidth() / (2.0 / 3.0)) * density * + g_settings->getFloat("gui_scaling"); m_scrollbar->setRelativePosition(core::rect( - relative_rect.LowerRightCorner.X-width,relative_rect.UpperLeftCorner.Y, - relative_rect.LowerRightCorner.X,relative_rect.LowerRightCorner.Y - )); + relative_rect.LowerRightCorner.X - width, + relative_rect.UpperLeftCorner.Y, relative_rect.LowerRightCorner.X, + relative_rect.LowerRightCorner.Y)); } GUITable::~GUITable() @@ -97,7 +93,8 @@ GUITable::~GUITable() if (m_font) m_font->drop(); - m_scrollbar->remove(); + if (m_scrollbar) + m_scrollbar->drop(); } GUITable::Option GUITable::splitOption(const std::string &str) @@ -106,12 +103,10 @@ GUITable::Option GUITable::splitOption(const std::string &str) if (equal_pos == std::string::npos) return GUITable::Option(str, ""); - return GUITable::Option(str.substr(0, equal_pos), - str.substr(equal_pos + 1)); + return GUITable::Option(str.substr(0, equal_pos), str.substr(equal_pos + 1)); } -void GUITable::setTextList(const std::vector &content, - bool transparent) +void GUITable::setTextList(const std::vector &content, bool transparent) { clear(); @@ -125,7 +120,7 @@ void GUITable::setTextList(const std::vector &content, s32 empty_string_index = allocString(""); m_rows.resize(content.size()); - for (s32 i = 0; i < (s32) content.size(); ++i) { + for (s32 i = 0; i < (s32)content.size(); ++i) { Row *row = &m_rows[i]; row->cells = new Cell[1]; row->cellcount = 1; @@ -135,7 +130,7 @@ void GUITable::setTextList(const std::vector &content, Cell *cell = row->cells; cell->xmin = 0; - cell->xmax = 0x7fff; // something large enough + cell->xmax = 0x7fff; // something large enough cell->xpos = 6; cell->content_type = COLUMN_TYPE_TEXT; cell->content_index = empty_string_index; @@ -149,19 +144,15 @@ void GUITable::setTextList(const std::vector &content, if (s[0] == '#' && s[1] == '#') { // double # to escape cell->content_index = allocString(s.substr(2)); - } - else if (s[0] == '#' && s.size() >= 7 && - parseColorString( - s.substr(0,7), cell->color, false)) { + } else if (s[0] == '#' && s.size() >= 7 && + parseColorString(s.substr(0, 7), cell->color, false)) { // single # for color cell->color_defined = true; cell->content_index = allocString(s.substr(7)); - } - else { + } else { // no #, just text cell->content_index = allocString(s); } - } allocationComplete(); @@ -170,8 +161,7 @@ void GUITable::setTextList(const std::vector &content, updateScrollBar(); } -void GUITable::setTable(const TableOptions &options, - const TableColumns &columns, +void GUITable::setTable(const TableOptions &options, const TableColumns &columns, std::vector &content) { clear(); @@ -210,8 +200,8 @@ void GUITable::setTable(const TableOptions &options, else if (name == "opendepth") opendepth = stoi(value); else - errorstream<<"Invalid table option: \""<= 0); // Append empty strings to content if there is an incomplete row s32 cellcount = rowcount * colcount; - while (content.size() < (u32) cellcount) + while (content.size() < (u32)cellcount) content.emplace_back(""); // Create temporary rows (for processing columns) - struct TempRow { + struct TempRow + { // Current horizontal position (may different between rows due // to indent/tree columns, or text/image columns with width<0) s32 x; @@ -240,9 +231,9 @@ void GUITable::setTable(const TableOptions &options, // Vector of completed cells in this row std::vector cells; // Stores colors and how long they last (maximum column index) - std::vector > colors; + std::vector> colors; - TempRow(): x(0), indent(0), content_index(0), content_width(0) {} + TempRow() : x(0), indent(0), content_index(0), content_width(0) {} }; TempRow *rows = new TempRow[rowcount]; @@ -271,8 +262,8 @@ void GUITable::setTable(const TableOptions &options, else if (columns[j].type == "tree") columntype = COLUMN_TYPE_TREE; else - errorstream<<"Invalid table column type: \"" - <colors.empty() && row->colors.back().second < j) + while (!row->colors.empty() && + row->colors.back().second < j) row->colors.pop_back(); } } // Make template for new cells Cell newcell; - memset(&newcell, 0, sizeof newcell); newcell.content_type = columntype; newcell.tooltip_index = tooltip_index; - newcell.reported_column = j+1; + newcell.reported_column = j + 1; if (columntype == COLUMN_TYPE_TEXT) { // Find right edge of column s32 xmax = 0; for (s32 i = 0; i < rowcount; ++i) { TempRow *row = &rows[i]; - row->content_index = allocString(content[i * colcount + j]); + row->content_index = + allocString(content[i * colcount + j]); const core::stringw &text = m_strings[row->content_index]; - row->content_width = m_font ? - m_font->getDimension(text.c_str()).Width : 0; + row->content_width = + m_font ? m_font->getDimension(text.c_str()) + .Width + : 0; row->content_width = MYMAX(row->content_width, width); s32 row_xmax = row->x + padding + row->content_width; xmax = MYMAX(xmax, row_xmax); @@ -355,7 +347,8 @@ void GUITable::setTable(const TableOptions &options, // Add a new cell (of text type) to each row for (s32 i = 0; i < rowcount; ++i) { newcell.xmin = rows[i].x + padding; - alignContent(&newcell, xmax, rows[i].content_width, align); + alignContent(&newcell, xmax, rows[i].content_width, + align); newcell.content_index = rows[i].content_index; newcell.color_defined = !rows[i].colors.empty(); if (newcell.color_defined) @@ -363,8 +356,7 @@ void GUITable::setTable(const TableOptions &options, rows[i].cells.push_back(newcell); rows[i].x = newcell.xmax; } - } - else if (columntype == COLUMN_TYPE_IMAGE) { + } else if (columntype == COLUMN_TYPE_IMAGE) { // Find right edge of column s32 xmax = 0; for (s32 i = 0; i < rowcount; ++i) { @@ -375,7 +367,7 @@ void GUITable::setTable(const TableOptions &options, // column options so check active_image_indices. s32 image_index = stoi(content[i * colcount + j]); std::map::iterator image_iter = - active_image_indices.find(image_index); + active_image_indices.find(image_index); if (image_iter != active_image_indices.end()) row->content_index = image_iter->second; @@ -385,7 +377,9 @@ void GUITable::setTable(const TableOptions &options, image = m_images[row->content_index]; // Get content width and update xmax - row->content_width = image ? image->getOriginalSize().Width : 0; + row->content_width = + image ? image->getOriginalSize().Width + : 0; row->content_width = MYMAX(row->content_width, width); s32 row_xmax = row->x + padding + row->content_width; xmax = MYMAX(xmax, row_xmax); @@ -393,27 +387,28 @@ void GUITable::setTable(const TableOptions &options, // Add a new cell (of image type) to each row for (s32 i = 0; i < rowcount; ++i) { newcell.xmin = rows[i].x + padding; - alignContent(&newcell, xmax, rows[i].content_width, align); + alignContent(&newcell, xmax, rows[i].content_width, + align); newcell.content_index = rows[i].content_index; rows[i].cells.push_back(newcell); rows[i].x = newcell.xmax; } active_image_indices.clear(); - } - else if (columntype == COLUMN_TYPE_COLOR) { + } else if (columntype == COLUMN_TYPE_COLOR) { for (s32 i = 0; i < rowcount; ++i) { video::SColor cellcolor(255, 255, 255, 255); - if (parseColorString(content[i * colcount + j], cellcolor, true)) - rows[i].colors.emplace_back(cellcolor, j+span); + if (parseColorString(content[i * colcount + j], cellcolor, + true)) + rows[i].colors.emplace_back(cellcolor, j + span); } - } - else if (columntype == COLUMN_TYPE_INDENT || + } else if (columntype == COLUMN_TYPE_INDENT || columntype == COLUMN_TYPE_TREE) { // For column type "tree", reserve additional space for +/- // Also enable special processing for treeview-type tables s32 content_width = 0; if (columntype == COLUMN_TYPE_TREE) { - content_width = m_font ? m_font->getDimension(L"+").Width : 0; + content_width = m_font ? m_font->getDimension(L"+").Width + : 0; m_has_tree_column = true; } // Add a new cell (of indent or tree type) to each row @@ -445,7 +440,7 @@ void GUITable::setTable(const TableOptions &options, Row *row = &m_rows[i]; row->cellcount = rows[i].cells.size(); row->cells = new Cell[row->cellcount]; - memcpy((void*) row->cells, (void*) &rows[i].cells[0], + memcpy((void *)row->cells, (void *)&rows[i].cells[0], row->cellcount * sizeof(Cell)); row->indent = rows[i].indent; row->visible_index = i; @@ -456,10 +451,12 @@ void GUITable::setTable(const TableOptions &options, if (m_has_tree_column) { // Treeview: convert tree to indent cells on leaf rows for (s32 i = 0; i < rowcount; ++i) { - if (i == rowcount-1 || m_rows[i].indent >= m_rows[i+1].indent) + if (i == rowcount - 1 || m_rows[i].indent >= m_rows[i + 1].indent) for (s32 j = 0; j < m_rows[i].cellcount; ++j) - if (m_rows[i].cells[j].content_type == COLUMN_TYPE_TREE) - m_rows[i].cells[j].content_type = COLUMN_TYPE_INDENT; + if (m_rows[i].cells[j].content_type == + COLUMN_TYPE_TREE) + m_rows[i].cells[j].content_type = + COLUMN_TYPE_INDENT; } // Treeview: close rows according to opendepth option @@ -488,9 +485,9 @@ void GUITable::clear() // Get colors from skin gui::IGUISkin *skin = Environment->getSkin(); - m_color = skin->getColor(gui::EGDC_BUTTON_TEXT); - m_background = skin->getColor(gui::EGDC_3D_HIGH_LIGHT); - m_highlight = skin->getColor(gui::EGDC_HIGH_LIGHT); + m_color = skin->getColor(gui::EGDC_BUTTON_TEXT); + m_background = skin->getColor(gui::EGDC_3D_HIGH_LIGHT); + m_highlight = skin->getColor(gui::EGDC_HIGH_LIGHT); m_highlight_text = skin->getColor(gui::EGDC_HIGH_LIGHT_TEXT); // Reset members @@ -519,15 +516,14 @@ std::string GUITable::checkEvent() std::ostringstream os(std::ios::binary); if (m_sel_doubleclick) { - os<<"DCL:"; + os << "DCL:"; m_sel_doubleclick = false; + } else { + os << "CHG:"; } - else { - os<<"CHG:"; - } - os<= 0 && m_selected < (s32) m_visible_rows.size()); + assert(m_selected >= 0 && m_selected < (s32)m_visible_rows.size()); return m_visible_rows[m_selected] + 1; } @@ -577,7 +573,7 @@ void GUITable::setSelected(s32 index) if (index >= 0) { m_selected = m_rows[index].visible_index; - assert(m_selected >= 0 && m_selected < (s32) m_visible_rows.size()); + assert(m_selected >= 0 && m_selected < (s32)m_visible_rows.size()); } if (m_selected != old_selected || selection_invisible) { @@ -612,7 +608,7 @@ void GUITable::setDynamicData(const DynamicData &dyndata) m_scrollbar->setPos(dyndata.scrollpos); } -const c8* GUITable::getTypeName() const +const c8 *GUITable::getTypeName() const { return "GUITable"; } @@ -634,12 +630,11 @@ void GUITable::draw() bool draw_background = m_background.getAlpha() > 0; if (m_border) - skin->draw3DSunkenPane(this, m_background, - true, draw_background, + skin->draw3DSunkenPane(this, m_background, true, draw_background, AbsoluteRect, &AbsoluteClippingRect); else if (draw_background) - skin->draw2DRectangle(this, m_background, - AbsoluteRect, &AbsoluteClippingRect); + skin->draw2DRectangle( + this, m_background, AbsoluteRect, &AbsoluteClippingRect); // get clipping rect @@ -658,14 +653,12 @@ void GUITable::draw() s32 scrollpos = m_scrollbar->getPos(); s32 row_min = scrollpos / m_rowheight; - s32 row_max = (scrollpos + AbsoluteRect.getHeight() - 1) - / m_rowheight + 1; - row_max = MYMIN(row_max, (s32) m_visible_rows.size()); + s32 row_max = (scrollpos + AbsoluteRect.getHeight() - 1) / m_rowheight + 1; + row_max = MYMIN(row_max, (s32)m_visible_rows.size()); core::rect row_rect(AbsoluteRect); if (m_scrollbar->isVisible()) - row_rect.LowerRightCorner.X -= - skin->getSize(gui::EGDS_SCROLLBAR_SIZE); + row_rect.LowerRightCorner.X -= skin->getSize(gui::EGDS_SCROLLBAR_SIZE); row_rect.UpperLeftCorner.Y += row_min * m_rowheight - scrollpos; row_rect.LowerRightCorner.Y = row_rect.UpperLeftCorner.Y + m_rowheight; @@ -691,33 +684,27 @@ void GUITable::draw() } void GUITable::drawCell(const Cell *cell, video::SColor color, - const core::rect &row_rect, - const core::rect &client_clip) + const core::rect &row_rect, const core::rect &client_clip) { - if ((cell->content_type == COLUMN_TYPE_TEXT) - || (cell->content_type == COLUMN_TYPE_TREE)) { + if ((cell->content_type == COLUMN_TYPE_TEXT) || + (cell->content_type == COLUMN_TYPE_TREE)) { core::rect text_rect = row_rect; - text_rect.UpperLeftCorner.X = row_rect.UpperLeftCorner.X - + cell->xpos; - text_rect.LowerRightCorner.X = row_rect.UpperLeftCorner.X - + cell->xmax; + text_rect.UpperLeftCorner.X = row_rect.UpperLeftCorner.X + cell->xpos; + text_rect.LowerRightCorner.X = row_rect.UpperLeftCorner.X + cell->xmax; if (cell->color_defined) color = cell->color; if (m_font) { if (cell->content_type == COLUMN_TYPE_TEXT) - m_font->draw(m_strings[cell->content_index], - text_rect, color, - false, true, &client_clip); + m_font->draw(m_strings[cell->content_index], text_rect, + color, false, true, &client_clip); else // tree - m_font->draw(cell->content_index ? L"+" : L"-", - text_rect, color, - false, true, &client_clip); + m_font->draw(cell->content_index ? L"+" : L"-", text_rect, + color, false, true, &client_clip); } - } - else if (cell->content_type == COLUMN_TYPE_IMAGE) { + } else if (cell->content_type == COLUMN_TYPE_IMAGE) { if (cell->content_index < 0) return; @@ -726,11 +713,9 @@ void GUITable::drawCell(const Cell *cell, video::SColor color, video::ITexture *image = m_images[cell->content_index]; if (image) { - core::position2d dest_pos = - row_rect.UpperLeftCorner; + core::position2d dest_pos = row_rect.UpperLeftCorner; dest_pos.X += cell->xpos; - core::rect source_rect( - core::position2d(0, 0), + core::rect source_rect(core::position2d(0, 0), image->getOriginalSize()); s32 imgh = source_rect.LowerRightCorner.Y; s32 rowh = row_rect.getHeight(); @@ -741,8 +726,8 @@ void GUITable::drawCell(const Cell *cell, video::SColor color, video::SColor color(255, 255, 255, 255); - driver->draw2DImage(image, dest_pos, source_rect, - &client_clip, color, true); + driver->draw2DImage(image, dest_pos, source_rect, &client_clip, + color, true); } } } @@ -753,40 +738,41 @@ bool GUITable::OnEvent(const SEvent &event) return IGUIElement::OnEvent(event); if (event.EventType == EET_KEY_INPUT_EVENT) { - if (event.KeyInput.PressedDown && ( - event.KeyInput.Key == KEY_DOWN || - event.KeyInput.Key == KEY_UP || - event.KeyInput.Key == KEY_HOME || - event.KeyInput.Key == KEY_END || - event.KeyInput.Key == KEY_NEXT || - event.KeyInput.Key == KEY_PRIOR)) { + if (event.KeyInput.PressedDown && + (event.KeyInput.Key == KEY_DOWN || + event.KeyInput.Key == KEY_UP || + event.KeyInput.Key == KEY_HOME || + event.KeyInput.Key == KEY_END || + event.KeyInput.Key == KEY_NEXT || + event.KeyInput.Key == KEY_PRIOR)) { s32 offset = 0; switch (event.KeyInput.Key) { - case KEY_DOWN: - offset = 1; - break; - case KEY_UP: - offset = -1; - break; - case KEY_HOME: - offset = - (s32) m_visible_rows.size(); - break; - case KEY_END: - offset = m_visible_rows.size(); - break; - case KEY_NEXT: - offset = AbsoluteRect.getHeight() / m_rowheight; - break; - case KEY_PRIOR: - offset = - (s32) (AbsoluteRect.getHeight() / m_rowheight); - break; - default: - break; + case KEY_DOWN: + offset = 1; + break; + case KEY_UP: + offset = -1; + break; + case KEY_HOME: + offset = -(s32)m_visible_rows.size(); + break; + case KEY_END: + offset = m_visible_rows.size(); + break; + case KEY_NEXT: + offset = AbsoluteRect.getHeight() / m_rowheight; + break; + case KEY_PRIOR: + offset = -(s32)(AbsoluteRect.getHeight() / m_rowheight); + break; + default: + break; } s32 old_selected = m_selected; s32 rowcount = m_visible_rows.size(); if (rowcount != 0) { - m_selected = rangelim(m_selected + offset, 0, rowcount-1); + m_selected = rangelim( + m_selected + offset, 0, rowcount - 1); autoScroll(); } @@ -796,27 +782,24 @@ bool GUITable::OnEvent(const SEvent &event) return true; } - if (event.KeyInput.PressedDown && ( - event.KeyInput.Key == KEY_LEFT || - event.KeyInput.Key == KEY_RIGHT)) { + if (event.KeyInput.PressedDown && + (event.KeyInput.Key == KEY_LEFT || + event.KeyInput.Key == KEY_RIGHT)) { // Open/close subtree via keyboard if (m_selected >= 0) { int dir = event.KeyInput.Key == KEY_LEFT ? -1 : 1; toggleVisibleTree(m_selected, dir, true); } return true; - } - else if (!event.KeyInput.PressedDown && ( - event.KeyInput.Key == KEY_RETURN || - event.KeyInput.Key == KEY_SPACE)) { + } else if (!event.KeyInput.PressedDown && + (event.KeyInput.Key == KEY_RETURN || + event.KeyInput.Key == KEY_SPACE)) { sendTableEvent(0, true); return true; - } - else if (event.KeyInput.Key == KEY_ESCAPE || + } else if (event.KeyInput.Key == KEY_ESCAPE || event.KeyInput.Key == KEY_SPACE) { // pass to parent - } - else if (event.KeyInput.PressedDown && event.KeyInput.Char) { + } else if (event.KeyInput.PressedDown && event.KeyInput.Char) { // change selection based on text as it is typed u64 now = porting::getTimeMs(); if (now - m_keynav_time >= 500) @@ -825,12 +808,13 @@ bool GUITable::OnEvent(const SEvent &event) // add to key buffer if not a key repeat if (!(m_keynav_buffer.size() == 1 && - m_keynav_buffer[0] == event.KeyInput.Char)) { + m_keynav_buffer[0] == event.KeyInput.Char)) { m_keynav_buffer.append(event.KeyInput.Char); } // find the selected item, starting at the current selection - // don't change selection if the key buffer matches the current item + // don't change selection if the key buffer matches the current + // item s32 old_selected = m_selected; s32 start = MYMAX(m_selected, 0); s32 rowcount = m_visible_rows.size(); @@ -855,8 +839,8 @@ bool GUITable::OnEvent(const SEvent &event) if (event.MouseInput.Event == EMIE_MOUSE_WHEEL) { m_scrollbar->setPos(m_scrollbar->getPos() + - (event.MouseInput.Wheel < 0 ? -3 : 3) * - - (s32) m_rowheight / 2); + (event.MouseInput.Wheel < 0 ? -3 : 3) * + -(s32)m_rowheight / 2); return true; } @@ -877,24 +861,24 @@ bool GUITable::OnEvent(const SEvent &event) // IGUIScrollBar passes double click events to its parent, // which we don't want. Detect this case and discard the event if (event.MouseInput.Event != EMIE_MOUSE_MOVED && - m_scrollbar->isVisible() && - m_scrollbar->isPointInside(p)) + m_scrollbar->isVisible() && m_scrollbar->isPointInside(p)) return true; if (event.MouseInput.isLeftPressed() && - (isPointInside(p) || - event.MouseInput.Event == EMIE_MOUSE_MOVED)) { + (isPointInside(p) || event.MouseInput.Event == + EMIE_MOUSE_MOVED)) { s32 sel_column = 0; - bool sel_doubleclick = (event.MouseInput.Event - == EMIE_LMOUSE_DOUBLE_CLICK); + bool sel_doubleclick = (event.MouseInput.Event == + EMIE_LMOUSE_DOUBLE_CLICK); bool plusminus_clicked = false; // For certain events (left click), report column // Also open/close subtrees when the +/- is clicked - if (cell && ( - event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN || - event.MouseInput.Event == EMIE_LMOUSE_DOUBLE_CLICK || - event.MouseInput.Event == EMIE_LMOUSE_TRIPLE_CLICK)) { + if (cell && (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN || + event.MouseInput.Event == + EMIE_LMOUSE_DOUBLE_CLICK || + event.MouseInput.Event == + EMIE_LMOUSE_TRIPLE_CLICK)) { sel_column = cell->reported_column; if (cell->content_type == COLUMN_TYPE_TREE) plusminus_clicked = true; @@ -904,15 +888,13 @@ bool GUITable::OnEvent(const SEvent &event) if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) { toggleVisibleTree(row_i, 0, false); } - } - else { + } else { // Normal selection s32 old_selected = m_selected; m_selected = row_i; autoScroll(); - if (m_selected != old_selected || - sel_column >= 1 || + if (m_selected != old_selected || sel_column >= 1 || sel_doubleclick) { sendTableEvent(sel_column, sel_doubleclick); } @@ -974,9 +956,9 @@ void GUITable::allocationComplete() m_alloc_images.clear(); } -const GUITable::Row* GUITable::getRow(s32 i) const +const GUITable::Row *GUITable::getRow(s32 i) const { - if (i >= 0 && i < (s32) m_visible_rows.size()) + if (i >= 0 && i < (s32)m_visible_rows.size()) return &m_rows[m_visible_rows[i]]; return NULL; @@ -992,7 +974,8 @@ bool GUITable::doesRowStartWith(const Row *row, const core::stringw &str) const if (cell->content_type == COLUMN_TYPE_TEXT) { const core::stringw &cellstr = m_strings[cell->content_index]; if (cellstr.size() >= str.size() && - str.equals_ignore_case(cellstr.subString(0, str.size()))) + str.equals_ignore_case( + cellstr.subString(0, str.size()))) return true; } } @@ -1045,8 +1028,7 @@ s32 GUITable::getCellAt(s32 x, s32 row_i) const jmin = pivot + 1; } - if (jmin >= 0 && jmin < row->cellcount && - rel_x >= row->cells[jmin].xmin && + if (jmin >= 0 && jmin < row->cellcount && rel_x >= row->cells[jmin].xmin && rel_x <= row->cells[jmin].xmax) return jmin; @@ -1074,6 +1056,7 @@ void GUITable::updateScrollBar() m_scrollbar->setMax(scrollmax); m_scrollbar->setSmallStep(m_rowheight); m_scrollbar->setLargeStep(2 * m_rowheight); + m_scrollbar->setPageSize(totalheight); } void GUITable::sendTableEvent(s32 column, bool doubleclick) @@ -1096,8 +1079,8 @@ void GUITable::getOpenedTrees(std::set &opened_trees) const opened_trees.clear(); s32 rowcount = m_rows.size(); for (s32 i = 0; i < rowcount - 1; ++i) { - if (m_rows[i].indent < m_rows[i+1].indent && - m_rows[i+1].visible_index != -2) + if (m_rows[i].indent < m_rows[i + 1].indent && + m_rows[i + 1].visible_index != -2) opened_trees.insert(i); } } @@ -1129,18 +1112,16 @@ void GUITable::setOpenedTrees(const std::set &opened_trees) // Visible row row->visible_index = m_visible_rows.size(); m_visible_rows.push_back(i); - } - else if (parents.back() == closed_parents.back()) { + } else if (parents.back() == closed_parents.back()) { // Invisible row, direct parent is closed row->visible_index = -2; - } - else { + } else { // Invisible row, direct parent is open, some ancestor is closed row->visible_index = -1; } // If not a leaf, add to parents list - if (i < m_rows.size()-1 && row->indent < m_rows[i+1].indent) { + if (i < m_rows.size() - 1 && row->indent < m_rows[i + 1].indent) { parents.push_back(i); s32 content_index = 0; // "-", open @@ -1218,14 +1199,13 @@ void GUITable::toggleVisibleTree(s32 row_i, int dir, bool move_selection) const Row *maybe_child = getRow(sel + 1); if (maybe_child && maybe_child->indent > row->indent) sel++; - } - else if (!was_open && !do_open) { + } else if (!was_open && !do_open) { // Move selection to parent assert(getRow(sel) != NULL); while (sel > 0 && getRow(sel - 1)->indent >= row->indent) sel--; sel--; - if (sel < 0) // was root already selected? + if (sel < 0) // was root already selected? sel = row_i; } if (sel != m_selected) { @@ -1243,16 +1223,13 @@ void GUITable::alignContent(Cell *cell, s32 xmax, s32 content_width, s32 align) if (align == 0) { cell->xpos = cell->xmin; cell->xmax = xmax; - } - else if (align == 1) { + } else if (align == 1) { cell->xpos = (cell->xmin + xmax - content_width) / 2; cell->xmax = xmax; - } - else if (align == 2) { + } else if (align == 2) { cell->xpos = xmax - content_width; cell->xmax = xmax; - } - else { + } else { // inline alignment: the cells of the column don't have an aligned // right border, the right border of each cell depends on the content cell->xpos = cell->xmin;