wxDataViewItem GetPrevItem( wxDataViewCtrl const& aView, wxDataViewItem const& aItem )
{
    auto prevItem = GetPrevSibling( aView, aItem );

    if( !prevItem.IsOk() )
    {
        prevItem = aView.GetModel()->GetParent( aItem );
    }
    else if( aView.IsExpanded( prevItem ) )
    {
        wxDataViewItemArray children;
        aView.GetModel()->GetChildren( prevItem, children );
        prevItem = children[children.size() - 1];
    }

    return prevItem;
}
wxDataViewItem GetNextItem( wxDataViewCtrl const& aView, wxDataViewItem const& aItem )
{
    wxDataViewItem nextItem;

    if( !aItem.IsOk() )
    {
        // No selection. Select the first.
        wxDataViewItemArray children;
        aView.GetModel()->GetChildren( aItem, children );
        return children[0];
    }

    if( aView.IsExpanded( aItem ) )
    {
        wxDataViewItemArray children;
        aView.GetModel()->GetChildren( aItem, children );
        nextItem = children[0];
    }
    else
    {
        // Walk up levels until we find one that has a next sibling.
        for( wxDataViewItem walk = aItem; walk.IsOk(); walk = aView.GetModel()->GetParent( walk ) )
        {
            nextItem = GetNextSibling( aView, walk );

            if( nextItem.IsOk() )
                break;
        }
    }

    return nextItem;
}
Exemplo n.º 3
0
void wxOSXDataViewModelNotifier::AdjustRowHeights(wxDataViewItemArray const& items)
{
  if ((m_DataViewCtrlPtr->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) != 0)
  {
      size_t const noOfItems = items.GetCount();

      wxDataViewModel *model = GetOwner();

      for (size_t itemIndex=0; itemIndex<noOfItems; ++itemIndex)
      {
        int height = 20; // TODO find out standard height
        unsigned int num = m_DataViewCtrlPtr->GetColumnCount();
        unsigned int col;

        for (col = 0; col < num; col++)
        {
            wxDataViewColumn* column(m_DataViewCtrlPtr->GetColumnPtr(col));

            if (!(column->IsHidden()))
            {
              wxDataViewCustomRenderer *renderer = dynamic_cast<wxDataViewCustomRenderer*>(column->GetRenderer());
              if (renderer)
              {
                  wxVariant value;
                  model->GetValue( value, items[itemIndex], column->GetModelColumn() );
                  renderer->SetValue( value );
                  height = wxMax( height, renderer->GetSize().y );
              }
            }
        }
        if (height > 20)
          m_DataViewCtrlPtr->GetDataViewPeer()->SetRowHeight(items[itemIndex],height);
      }
  }
}
Exemplo n.º 4
0
void wxOSXDataViewModelNotifier::AdjustAutosizedColumns()
{
  unsigned count = m_DataViewCtrlPtr->GetColumnCount();
  for ( unsigned col = 0; col < count; col++ )
  {
      wxDataViewColumn *column = m_DataViewCtrlPtr->GetColumnPtr(col);

      if ( column->GetWidthVariable() == wxCOL_WIDTH_AUTOSIZE )
        m_DataViewCtrlPtr->GetDataViewPeer()->FitColumnWidthToContent(col);
  }
}
Exemplo n.º 5
0
bool wxOSXDataViewModelNotifier::ItemAdded(wxDataViewItem const& parent, wxDataViewItem const& item)
{
  bool noFailureFlag;


  wxCHECK_MSG(item.IsOk(),false,"Added item is invalid.");
  noFailureFlag = m_DataViewCtrlPtr->GetDataViewPeer()->Add(parent,item);
  AdjustRowHeight(item);
  return noFailureFlag;
}
Exemplo n.º 6
0
bool wxOSXDataViewModelNotifier::ItemsDeleted(wxDataViewItem const& parent, wxDataViewItemArray const& items)
{
  bool noFailureFlag;


 // when this method is called and currently an item is being edited this item may have already been deleted in the model (the passed item and the being edited item have
 // not to be identical because the being edited item might be below the passed item in the hierarchy);
 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
 // has been started and that variables can currently not be updated even when requested by the system:
  m_DataViewCtrlPtr->SetDeleting(true);
 // delete all specified items:
  noFailureFlag = m_DataViewCtrlPtr->GetDataViewPeer()->Remove(parent,items);
 // enable automatic updating again:
  m_DataViewCtrlPtr->SetDeleting(false);

  AdjustAutosizedColumns();
 // done:
  return noFailureFlag;
}
wxDataViewItem GetNextSibling( wxDataViewCtrl const& aView, wxDataViewItem const& aItem )
{
    wxDataViewItemArray siblings;
    wxDataViewItem      invalid;
    wxDataViewItem      parent = aView.GetModel()->GetParent( aItem );

    aView.GetModel()->GetChildren( parent, siblings );

    for( size_t i = 0; i < siblings.size(); ++i )
    {
        if( siblings[i] == aItem )
        {
            if( i == siblings.size() - 1 )
                return invalid;
            else
                return siblings[i + 1];
        }
    }

    return invalid;
}
Exemplo n.º 8
0
bool wxOSXDataViewModelNotifier::ValueChanged(wxDataViewItem const& item, unsigned int col)
{
  wxCHECK_MSG(item.IsOk(),             false,"Passed item is invalid.");
  wxCHECK_MSG(GetOwner() != NULL,false,"Owner not initialized.");
  if (m_DataViewCtrlPtr->GetDataViewPeer()->Update(GetOwner()->GetParent(item),item))
  {
    wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId());

    dataViewEvent.SetEventObject(m_DataViewCtrlPtr);
    dataViewEvent.SetColumn(col);
    dataViewEvent.SetItem(item);
   // send the equivalent wxWidget event:
    m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent);

    AdjustAutosizedColumns();
   // done
    return true;
  }
  else
    return false;
}
Exemplo n.º 9
0
bool wxOSXDataViewModelNotifier::ItemsAdded(wxDataViewItem const& parent, wxDataViewItemArray const& items)
{
  bool noFailureFlag;


 // insert all valid items into control:
  noFailureFlag = m_DataViewCtrlPtr->GetDataViewPeer()->Add(parent,items);
 // adjust row heights:
  AdjustRowHeights(items);
 // done:
  return noFailureFlag;
}
Exemplo n.º 10
0
bool wxOSXDataViewModelNotifier::ItemChanged(wxDataViewItem const& item)
{
  wxCHECK_MSG(item.IsOk(),             false,"Changed item is invalid.");
  wxCHECK_MSG(GetOwner() != NULL,false,"Owner not initialized.");
  if (m_DataViewCtrlPtr->GetDataViewPeer()->Update(GetOwner()->GetParent(item),item))
  {
   // sent the equivalent wxWidget event:
    wxDataViewEvent dataViewEvent(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId());

    dataViewEvent.SetEventObject(m_DataViewCtrlPtr);
    dataViewEvent.SetItem(item);
   // sent the equivalent wxWidget event:
    m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
   // row height may have to be adjusted:
    AdjustRowHeight(item);
    AdjustAutosizedColumns();
   // done
    return true;
  }
  else
    return false;
}
Exemplo n.º 11
0
bool wxOSXDataViewModelNotifier::ItemsChanged(wxDataViewItemArray const& items)
{
  size_t const noOfItems = items.GetCount();

  wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId());


  dataViewEvent.SetEventObject(m_DataViewCtrlPtr);
  for (size_t indexItem=0; indexItem<noOfItems; ++indexItem)
    if (m_DataViewCtrlPtr->GetDataViewPeer()->Update(GetOwner()->GetParent(items[indexItem]),items[indexItem]))
    {
     // send for all changed items a wxWidget event:
      dataViewEvent.SetItem(items[indexItem]);
      m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
    }
    else
      return false;
 // if this location is reached all items have been updated:
  AdjustRowHeights(items);
  AdjustAutosizedColumns();
 // done:
  return true;
}
Exemplo n.º 12
0
void wxOSXDataViewModelNotifier::Resort()
{
  m_DataViewCtrlPtr->GetDataViewPeer()->Resort();
}
Exemplo n.º 13
0
bool wxOSXDataViewModelNotifier::Cleared()
{
  return m_DataViewCtrlPtr->GetDataViewPeer()->Reload();
}