⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multicell.cpp

📁 wxGTK 是 wxWidgets 的 linux GTK+ (>2.2.3)版本。wxWidgets 是一个跨平台的 GUI 框架
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/////////////////////////////////////////////////////////////////////////////// Name:        multicell.cpp// Purpose:     provide two new classes for layout, wxMultiCellSizer and wxMultiCellCanvas// Author:      Jonathan Bayer// Modified by:// Created:// RCS-ID:      $Id: multicell.cpp,v 1.17 2006/10/16 09:29:31 ABX Exp $// Copyright:   (c) Jonathan Bayer// Licence:     wxWindows licence/////////////////////////////////////////////////////////////////////////////// This was inspired by the gbsizer class written by Alex Andruschak// For compilers that support precompilation, includes "wx.h".#include "wx/wxprec.h"#ifdef __BORLANDC__    #pragma hdrstop#endif// ----------------------------------------------------------------------------// headers// ----------------------------------------------------------------------------#ifndef WX_PRECOMP    #include "wx/wx.h"#endif#include "wx/gizmos/multicell.h"//---------------------------------------------------------------------------IMPLEMENT_ABSTRACT_CLASS(wxMultiCellSizer, wxSizer);IMPLEMENT_ABSTRACT_CLASS(wxMultiCellItemHandle, wxObject);//---------------------------------------------------------------------------// wxMultiCellItemHandle//---------------------------------------------------------------------------/* *Function Name: wxMultiCellItemHandle :: wxMultiCellItemHandle * *Parameters:    int         row *               int         column *               int         height *               int         width *               wxSize      size *               wxResizable Style *               wxSize      weight *               int         align * *Description:   This is the constructor for the class. * */void wxMultiCellItemHandle :: Initialize( int row, int column, int height, int width, wxSize size, wxResizable Style, wxSize weight, int align){    m_column = column;    m_row = row;    m_width = width;    m_height = height;    m_style = Style;    m_fixedSize = size;    m_alignment = align;    m_weight = weight;}//---------------------------------------------------------------------------wxMultiCellItemHandle :: wxMultiCellItemHandle( int row, int column, int height, int width, wxSize size, wxResizable Style, wxSize weight, int align){    Initialize(row, column,height, width, size, Style, weight, align);}//---------------------------------------------------------------------------wxMultiCellItemHandle :: wxMultiCellItemHandle( int row, int column, wxSize size, wxResizable style, wxSize weight, int align){    Initialize(row, column,1, 1, size, style, weight, align);}//---------------------------------------------------------------------------wxMultiCellItemHandle :: wxMultiCellItemHandle( int row, int column, wxResizable style, wxSize weight, int align){    Initialize(row, column, 1, 1, wxSize(1, 1), style, weight, align);}//---------------------------------------------------------------------------int wxMultiCellItemHandle::GetColumn(){    return m_column;}//---------------------------------------------------------------------------int wxMultiCellItemHandle::GetRow(){    return m_row;}//---------------------------------------------------------------------------int wxMultiCellItemHandle::GetWidth(){    return m_width;}//---------------------------------------------------------------------------int wxMultiCellItemHandle::GetHeight(){    return m_height;}//---------------------------------------------------------------------------wxResizable    wxMultiCellItemHandle :: GetStyle(){    return m_style;};//---------------------------------------------------------------------------wxSize wxMultiCellItemHandle :: GetLocalSize(){    return m_fixedSize;};//---------------------------------------------------------------------------int wxMultiCellItemHandle :: GetAlignment(){    return m_alignment;};//---------------------------------------------------------------------------wxSize wxMultiCellItemHandle :: GetWeight(){    return m_weight;};//---------------------------------------------------------------------------//---------------------------------------------------------------------------// wxMultiCellSizer//---------------------------------------------------------------------------/* *Function Name: wxMultiCellSizer::Initialize * *Parameters:    wxsize Initial size of sizer * *Description:   This is a common function to initialize all the members of *               this class.  It is only called from the constructors * */void wxMultiCellSizer::Initialize( wxSize size ){    m_cell_count = size;    m_maxHeight = (int *)malloc((1 + m_cell_count.GetHeight()) * sizeof(int));    m_maxWidth = (int *)malloc( (1 + m_cell_count.GetWidth()) * sizeof(int));    m_rowStretch = (int *)malloc( (1 + m_cell_count.GetHeight()) * sizeof(int));    m_colStretch = (int *)malloc((1 + m_cell_count.GetWidth()) * sizeof(int));    m_weights = (wxSize **)malloc((1 + wxMax(m_cell_count.GetHeight(), m_cell_count.GetWidth())) * sizeof(wxSize *));    m_minSizes = (wxSize **)malloc((1 + wxMax(m_cell_count.GetHeight(), m_cell_count.GetWidth())) * sizeof(wxSize *));    for (int x = 0; x < 1 + wxMax(m_cell_count.GetHeight(), m_cell_count.GetWidth()); x++)    {        m_weights[x] = new wxSize(0,0);        m_minSizes[x] = new wxSize(0,0);    }    m_maxWeights = 1 + wxMax(m_cell_count.GetHeight(), m_cell_count.GetWidth());    m_defaultCellSize = wxSize(5, 5);    m_win = NULL;    m_pen = wxRED_PEN;}//---------------------------------------------------------------------------wxMultiCellSizer::wxMultiCellSizer( wxSize & size ){    Initialize(size);}//---------------------------------------------------------------------------wxMultiCellSizer::wxMultiCellSizer( int rows, int cols){    wxSize size(cols, rows);    Initialize(size);}//---------------------------------------------------------------------------wxMultiCellSizer::~wxMultiCellSizer(){    WX_CLEAR_LIST(wxSizerItemList, m_children);    free(m_maxHeight);    free(m_maxWidth);    free(m_rowStretch);    free(m_colStretch);    for (int x = 0; x < 1 + wxMax(m_cell_count.GetHeight(), m_cell_count.GetWidth()); x++)    {        delete m_weights[x];        delete m_minSizes[x];    }    free(m_weights);    free(m_minSizes);}//---------------------------------------------------------------------------bool wxMultiCellSizer::EnableGridLines(wxWindow *win){    m_win = win;    return true;}//---------------------------------------------------------------------------bool wxMultiCellSizer::SetGridPen(const wxPen *pen){    m_pen = pen;    return true;}//---------------------------------------------------------------------------bool wxMultiCellSizer::SetDefaultCellSize(wxSize size){    m_defaultCellSize = size;    return true;}//---------------------------------------------------------------------------bool wxMultiCellSizer::SetColumnWidth(int column, int colSize, bool expandable){    if (expandable)    {        m_minSizes[column]->SetWidth(-colSize);    }    else    {        m_minSizes[column]->SetWidth(colSize);    }    return true;}//---------------------------------------------------------------------------bool wxMultiCellSizer::SetRowHeight(int row, int rowSize, bool expandable){    if (expandable)    {        m_minSizes[row]->SetHeight(-rowSize);    }    else    {        m_minSizes[row]->SetHeight(rowSize);    }    return true;}//---------------------------------------------------------------------------void wxMultiCellSizer::RecalcSizes(){    if (m_children.GetCount() == 0)        return;    wxSize size = GetSize();    wxPoint pos = GetPosition();    GetMinimums();    // We need to take the unused space and equally give it out to all the rows/columns    // which are stretchable    int unUsedWidth = size.GetWidth() - Sum(m_maxWidth, m_cell_count.GetWidth());    int unUsedHeight = size.GetHeight() - Sum(m_maxHeight, m_cell_count.GetHeight());    int totalWidthWeight = 0;    int totalHeightWeight = 0;    int x;    for (x = 0; x < wxMax(m_cell_count.GetHeight(), m_cell_count.GetWidth()); x++)    {        if (m_rowStretch[x])        {            totalHeightWeight += m_weights[x]->GetHeight();        }        if (x < m_cell_count.GetWidth() && m_colStretch[x])        {            totalWidthWeight += m_weights[x]->GetWidth();        }    }    for (x = 0; x < wxMax(m_cell_count.GetHeight(), m_cell_count.GetWidth()); x++)    {        if (x < m_cell_count.GetHeight() && m_rowStretch[x])        {            m_maxHeight[x] += unUsedHeight * m_weights[x]->GetHeight() / totalHeightWeight;        }        if (x < m_cell_count.GetWidth() && m_colStretch[x])        {            m_maxWidth[x] += unUsedWidth * m_weights[x]->GetWidth() / totalWidthWeight;        }    }    // We now have everything we need to figure each cell position and size    // The arrays m_maxHeight and m_maxWidth now contain the final widths and height of    // each row and column.    double cell_width = (double)size.GetWidth() / (double)m_cell_count.GetWidth();    double cell_height = (double)size.GetHeight() / (double)m_cell_count.GetHeight();    wxPoint c_point;    wxSize  c_size;    wxSizerItemList::compatibility_iterator current = m_children.GetFirst();    while (current)    {        wxSizerItem *item = current->GetData();        wxMultiCellItemHandle *rect;        if (item != NULL &&            (rect = (wxMultiCellItemHandle *)item->GetUserData()) != NULL)        {            c_point.x = pos.x + (int)(rect->GetColumn() * cell_width);            c_point.y = pos.y + (int)(rect->GetRow() * cell_height);            c_point.x = pos.x + Sum(m_maxWidth, rect->GetColumn());            c_point.y = pos.y + Sum(m_maxHeight, rect->GetRow());            c_size = rect->GetLocalSize();            wxSize minSize( item->CalcMin() );            if (c_size.GetHeight() != wxDefaultCoord ||                c_size.GetWidth() != wxDefaultCoord)            {                minSize.SetHeight(wxMax(minSize.GetHeight(), c_size.GetHeight()));                minSize.SetWidth(wxMax(minSize.GetWidth(), c_size.GetWidth()));            }            if (rect->GetStyle() & wxHORIZONTAL_RESIZABLE ||                rect->GetWidth() > 1                || m_minSizes[rect->GetColumn()]->GetWidth() < 0)            {                int w = 0;                for (int x = 0; x < rect->GetWidth(); x++)                {                    w += m_maxWidth[rect->GetColumn() + x];                }                c_size.SetWidth(w);            }            else            {                c_size.SetWidth(minSize.GetWidth() );            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -