Ejemplo n.º 1
0
bool CGridLocus::XferName(int nCol, COARallele *pAllele)
{
    bool bRtn = true;
    if(!GetBoolValue(ROW_DISABLE,nCol))
    {
        bool bAmel = m_pLocusEdited->IsAmel();
        s = GetCellValue(ROW_ALLELE,nCol);
        nwxString::Trim(&s);
        if(bAmel)
        {
            s.MakeUpper();
            const char *ps = s.c_str();
            if( (!*ps) || (strchr("XY12",*ps) == NULL) )
            {
                // not x/y
                bRtn = false;
                mainApp::ShowError(_T("Invalid allele name"),this);
                SetCellValue(ROW_ALLELE,nCol,pAllele->FormatName(true,false));
                SetGridCursor(ROW_ALLELE,nCol);
                SelectBlock(ROW_ALLELE,nCol,ROW_ALLELE,nCol);
            }
        }
        if(bRtn)
        {
            pAllele->SetName(s,bAmel);
        }
    }
    return bRtn;
}
Ejemplo n.º 2
0
void PropGrid::OnRangeSelected( wxGridRangeSelectEvent& ev )
{

	if(ev.Selecting())
	{
		bool reselect=false;
		//Fusion avec la précédente séléction
		if((currentSelection.TopRow==ev.GetTopRow() && currentSelection.BottomRow==ev.GetBottomRow()))
		{
			currentSelection.LeftCol=wxMin(currentSelection.LeftCol,ev.GetLeftCol());
			currentSelection.RightCol=wxMax(ev.GetRightCol(),currentSelection.RightCol);
		}
		else if(currentSelection.LeftCol==ev.GetLeftCol() && currentSelection.RightCol==ev.GetRightCol())
		{
			currentSelection.TopRow=wxMin(ev.GetTopRow(),currentSelection.TopRow);
			currentSelection.BottomRow=wxMax(ev.GetBottomRow(),currentSelection.BottomRow);
		}else{
			currentSelection.TopRow=ev.GetTopRow();
			currentSelection.LeftCol=ev.GetLeftCol();
			currentSelection.BottomRow=ev.GetBottomRow();
			currentSelection.RightCol=ev.GetRightCol();
		}
		//if(oldSelection.TopRow!=currentSelection.TopRow || oldSelection.LeftCol!=currentSelection.LeftCol || oldSelection.BottomRow!=currentSelection.BottomRow || oldSelection.RightCol!=currentSelection.RightCol)
		if(reselect)
			SelectBlock(currentSelection.TopRow, currentSelection.LeftCol, currentSelection.BottomRow, currentSelection.RightCol);
	}else{
		currentSelection=t_selection();
	}
	#ifdef __WXDEBUG__
	//wxLogDebug("orig:[%i;%i] dest:[%i;%i] sel[%i]",currentSelection.TopRow,currentSelection.LeftCol,currentSelection.BottomRow,currentSelection.RightCol,ev.Selecting());
	#endif

    ev.Skip();
}
//---------------------------------------------------------
void CVIEW_Table_Control::On_LClick(wxGridEvent &event)
{
	int					iField		= m_Field_Offset + event.GetCol();
	CSG_Table_Record	*pRecord	= m_pRecords[event.GetRow()];

	//-----------------------------------------------------
	if( event.AltDown() )
	{
		if( m_pTable->Get_Field_Type(iField) == SG_DATATYPE_String )
		{
			if( event.ControlDown() )
			{
				g_pData->Open   (pRecord->asString(iField));
			}
			else
			{
				Open_Application(pRecord->asString(iField));
			}
		}
	}

	//-----------------------------------------------------
	else if( event.ControlDown() )
	{
		m_pTable->Select(pRecord, true);

		Update_Selection();
	}

	else if( event.ShiftDown() )
	{
		SelectBlock(event.GetRow(), 0, GetGridCursorRow(), GetNumberCols(), false);
	}

	else
	{
		SelectRow(event.GetRow(), false);

		if( pRecord && iField >= m_Field_Offset && iField < m_pTable->Get_Field_Count() && m_pTable->Get_Field_Type(iField) == SG_DATATYPE_Color )
		{
			long	lValue;

			if( DLG_Color(lValue = pRecord->asInt(iField)) )
			{
				pRecord->Set_Value(iField, lValue);

				SetCellBackgroundColour(event.GetRow(), event.GetCol(), Get_Color_asWX(pRecord->asInt(iField)));

				ForceRefresh();
			}
		}
	}

	//-----------------------------------------------------
	SetGridCursor(event.GetRow(), event.GetCol());
}
Ejemplo n.º 4
0
void wxGridSelection::SelectCell( int row, int col,
                                  const wxKeyboardState& kbd,
                                  bool sendEvent )
{
    if ( m_selectionMode == wxGrid::wxGridSelectRows )
    {
        SelectBlock(row, 0, row, m_grid->GetNumberCols() - 1, kbd, sendEvent);

        return;
    }
    else if ( m_selectionMode == wxGrid::wxGridSelectColumns )
    {
        SelectBlock(0, col, m_grid->GetNumberRows() - 1, col, kbd, sendEvent);

        return;
    }
    else if ( IsInSelection ( row, col ) )
        return;

    m_cellSelection.Add( wxGridCellCoords( row, col ) );

    // Update View:
    if ( !m_grid->GetBatchCount() )
    {
        wxRect r = m_grid->BlockToDeviceRect(
            wxGridCellCoords( row, col ),
            wxGridCellCoords( row, col ) );
        ((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
    }

    // Send event
    if (sendEvent)
    {
        wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
            wxEVT_GRID_RANGE_SELECT,
            m_grid,
            wxGridCellCoords( row, col ),
            wxGridCellCoords( row, col ),
            true,
            kbd);
        m_grid->GetEventHandler()->ProcessEvent( gridEvt );
    }
}
Ejemplo n.º 5
0
/**
	Mouse click scenarios.
*/
void AlbumView::MouseDown(BPoint where)
{
    // This is an event hook so there must be a Looper.
	BMessage *message = Window()->CurrentMessage();

    int32 mods = 0, clicks = 0, buttons=0;
    message->FindInt32("modifiers", &mods);
    message->FindInt32("clicks", &clicks);
    message->FindInt32("buttons", &buttons);
		
    // Scale back.
	where.x /= fZoom;
	where.y /= fZoom;
	
	int32 i = IndexOf(&where);
	int32 changes = 0;
	if (i >= 0) {
		AlbumItem *item = ItemAt(i);
		
		// double-clicks are handled later in MouseUp()
		fDoubleClick = (fLastSelected == i && clicks == 2 && (buttons & B_PRIMARY_MOUSE_BUTTON));
        fMayDrag = !fDoubleClick && (buttons & B_PRIMARY_MOUSE_BUTTON);			
        if (mods & B_SHIFT_KEY) 
        	// Block selection
			changes += SelectBlock(fLastSelected, i, !item->IsSelected());
        else if (mods & B_COMMAND_KEY)
        	// Modify selection
        	changes += Select(i, 1, !item->IsSelected());
		else {
			// Normal selection
			if (!item->IsSelected())
				changes += DeselectAll();
        	changes += Select(i);
		}
        fLastWhere = where;
        fLastSelected = i;
    }
    else
	   	changes += DeselectAll();

	if (changes > 0) {
		//PRINT(("selection changed\n"));
    	SelectionChanged();
    	if (!fDoubleClick && Message()) {
			BMessage msg = *Message();
			msg.AddInt32("buttons", buttons);
    		msg.AddPoint("where", where);        
        	msg.AddInt32("index", fLastSelected);
			Invoke(&msg);
    	}
	}
    
    
}
Ejemplo n.º 6
0
bool CDownloadTransfer::SelectFragment(const Fragments::List& oPossible, QWORD& nOffset, QWORD& nLength, bool bEndGame) const
{
	ASSUME_LOCK( Transfers.m_pSection );

	blockPair oSelection( SelectBlock( oPossible, m_pAvailable, bEndGame ) );

	nOffset = oSelection.first;
	nLength = oSelection.second;

	return nLength > 0ull;
}
bool WorkingParameters::SetCurrentModel(int id) {
  ParameterBlock device = SelectBlock(_T("Device"));
  if (device.IsNull()) {
    return false;
  }
  for (ParameterBlock block = device.GetFirstChildBlock(); !block.IsNull(); block = block.GetNextBlock()) {
    if (block.GetIntParameter(_T("id"), -1) == id) {
      currentModelId_ = id;
      currentModelParameters_ = block;
      return true;
    }
  }
  return false;
}
int WorkingParameters::Login(LPCTSTR userName, LPCTSTR password) {
  ParameterBlock usersBlock = SelectBlock(_T("Users"));
  ParameterBlock user = usersBlock.GetFirstChildBlock();
  for (; !user.IsNull(); user = user.GetNextBlock()) {
    if (user.GetName() == _T("User")) {
      if (user.GetStringParameter(_T("name"), NULL) == userName) {
        if (user.GetStringParameter(_T("password"), NULL) == MD5::CalcString(password)) {
			userName_.Format(L"%s", userName);
			currentPermission_ = user.GetIntParameter(_T("permission"), 3);
			return currentPermission_;
        }
      }
    }
  }
  return -1;
}
bool WorkingParameters::LoadXML() {
  LastErrorHolder errorHolder;

  xmlDoc_.Release();

  HRESULT hr = xmlDoc_.CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER);
  if (FAILED(hr)) {
    errorHolder.SetError(ERROR_XML_COMPONENT_DAMAGE);
    return false;
  }

  TCHAR configFilePath[MAX_PATH];
  GetAppDataPath(configFilePath);
  PathAddBackslash(configFilePath);
  _tcscat(configFilePath, _T("config\\manifest.xml"));
  CComVariant varPath(configFilePath);
  VARIANT_BOOL successful;
  hr = xmlDoc_->load(varPath, &successful);
  if (FAILED(hr)) {
    errorHolder.SetError(ERROR_CONFIG_UNAVAILABLE);
    return false;
  }

  IXMLDOMElement *root = NULL;
  xmlDoc_->get_documentElement(&root);
  if (root == NULL) {
    errorHolder.SetError(ERROR_SERVER_CONFIG);
    return false;
  }
  
  Reset(root);

  ParameterBlock deviceBlock = SelectBlock(_T("Device"));
  if (deviceBlock.IsNull()) {
    errorHolder.SetError(ERROR_SERVER_CONFIG);
    return false;
  }

  currentModelParameters_ = deviceBlock.GetFirstChildBlock();
  if (currentModelParameters_.IsNull()) {
    errorHolder.SetError(ERROR_SERVER_CONFIG);
    return false;
  }
  currentModelId_ = currentModelParameters_.GetIntParameter(_T("id"), -1);

  return true;
}
Ejemplo n.º 10
0
static  an      GenSelTable( an node, sel_handle s_node, type_def *tipe )
/***********************************************************************/
{
    an          lt;

    if( s_node->lower != 0 ) {
        node = BGBinary( O_MINUS, node,
                          BGInteger( s_node->lower, tipe ), tipe , true );
    }
    /* generate if's to check if index in table*/
    if( s_node->other_wise != NULL ) {
        lt = BGCompare( O_LE, BGDuplicate(node),
                        BGInteger( s_node->upper - s_node->lower, tipe ), NULL,
                        UnSignedIntTipe( tipe ) );
        BGControl( O_IF_FALSE, lt, s_node->other_wise );
    }
    /* generate table*/
    /* index into table*/
    node = BGConvert( node, UnSignedIntTipe( tipe ) ); /* value an unsigned index */
    SelectBlock( MakeJmpTab( s_node->list, s_node->lower, s_node->upper,
                             s_node->other_wise ),
                 node, s_node->other_wise );
    return( node );
}
Ejemplo n.º 11
0
/**
	Keyboard navigation.
*/
void AlbumView::KeyDown(const char *bytes, int32 numBytes)
{
	AlbumItem *item = ItemAt(fLastSelected);
	if (item == NULL)
		return;
    BRect b = Bounds();
	BRect frame = item->Frame();
	// you never know...
	if (!frame.IsValid())
		return;
	BRect r;
    int32 i = fLastSelected;
    switch (bytes[0]) {
    	case B_LEFT_ARROW:
        	while (i > 0 && !IsItemVisible(item = ItemAt(--i))) {}
        	break;
    	case B_RIGHT_ARROW:
        	while (i >= 0 && i < CountItems()-1 && !IsItemVisible(item = ItemAt(++i))) {}
        	break;
    	case B_UP_ARROW:
			while (i > 0) {
				item = ItemAt(--i);
          		r = item->Frame();
          		if (IsItemVisible(item) && r.top < frame.top && (r.right==frame.right || r.left < frame.right))
          			break;
			}
    		break;
    	case B_DOWN_ARROW:
			while (i >= 0 && i < CountItems()-1) {
				item = ItemAt(++i);
          		r = item->Frame();
           		if (IsItemVisible(item) && r.top > frame.bottom && ( r.left==frame.left || r.right > frame.left) )
           			break;
			}
    		break;
    	case B_PAGE_DOWN:
			while (i >= 0 && i < CountItems()-1) {
				item = ItemAt(++i);
          		r = item->Frame();
           		if (IsItemVisible(item) && r.top > frame.bottom+b.Height() && ( r.left==frame.left || r.right > frame.left) )
           			break;
			}
    		break;
    	case B_PAGE_UP:
			while (i > 0) {
				item = ItemAt(--i);
          		r = item->Frame();
          		if (IsItemVisible(item) && r.top < frame.top-b.Height() && (r.right==frame.right || r.left < frame.right))
          			break;
			}
    		break;
    	default:
        	BView::KeyDown(bytes, numBytes);
        	break;
    }
	     
	// change selection
	if (i != fLastSelected && IsItemVisible(item)) {
	   	int32 mods = 0;
	   	Window()->CurrentMessage()->FindInt32("modifiers", &mods);

	    if (mods & B_SHIFT_KEY) {
			// block selection
	    	SelectBlock(fLastSelected, i, !ItemAt(i)->IsSelected());
	    	Select(i);
	    }
	    else  {
	    	// normal selection
	    	DeselectAll();
	    	Select(i);
	    }    
	    fLastSelected = i;
	    
	    // notify 
		SelectionChanged();		
		if (Message()) {
			BMessage msg = *Message();
        	msg.AddInt32("index", fLastSelected);
			Invoke(&msg);
		}
		
		// bring into view  
		r = Adjust(ItemAt(fLastSelected)->Frame());
		float dx=0,dy=0;      
		if (r.right > b.right)
			dx = r.right - b.right;
		else if (r.left < b.left)
			dx = r.left - b.left;
		if (r.bottom > b.bottom)
			dy = r.bottom - b.bottom;
		else if (r.top < b.top)
			dy = r.top - b.top;
		ScrollBy(dx,dy);				
	}
}
bool WorkingParameters::LoadFromServer() {
  LastErrorHolder errorHolder;

  TCHAR configFilePath[MAX_PATH];
  GetModuleFileName(NULL, configFilePath, _countof(configFilePath));
  PathRemoveFileSpec(configFilePath);
  PathAddBackslash(configFilePath);
  _tcscat(configFilePath, _T("FTPCONFIG.ini"));

  TCHAR serverIP[128];
  GetPrivateProfileString(TEXT("Config"), TEXT("ServerIP"), NULL, serverIP, _countof(serverIP), configFilePath);
  int serverPort = GetPrivateProfileInt(TEXT("Config"), TEXT("ServerPort"), 21, configFilePath);
  TCHAR userName[128];
  GetPrivateProfileString(TEXT("Config"), TEXT("User"), NULL, userName, _countof(userName), configFilePath);
  TCHAR password[128];
  GetPrivateProfileString(TEXT("Config"), TEXT("Password"), NULL, password, _countof(password), configFilePath);
  TCHAR remotePath[MAX_PATH];
  GetPrivateProfileString(TEXT("Config"), TEXT("RemotePath"), NULL, remotePath, _countof(remotePath), configFilePath);

  FtpClient client;
  if (!client.Connect(serverIP, serverPort, DecodePassword(userName), DecodePassword(password))) {
	errorHolder.SaveLastError();
    return false;
  }

  TCHAR appConfigPath[MAX_PATH];
  GetAppDataPath(appConfigPath);
  PathAddBackslash(appConfigPath);
  _tcscat(appConfigPath, _T("config"));
  if (!CreateDirectoryRecusively(appConfigPath)) {
    errorHolder.SaveLastError();
    return false;
  }
  PathAddBackslash(appConfigPath);

  TCHAR remoteManifestFilePath[MAX_PATH];
  _tcscpy(remoteManifestFilePath, remotePath);
  _tcscat(remoteManifestFilePath, _T("manifest.xml"));
  TCHAR localManifestFilePath[MAX_PATH];
  _tcscpy(localManifestFilePath, appConfigPath);
  _tcscat(localManifestFilePath, _T("manifest.xml"));
  if (!client.GetFile(remoteManifestFilePath, localManifestFilePath)) {
    errorHolder.SaveLastError();
    return false;
  }

  if (!LoadXML()) {
    errorHolder.SaveLastError();
    return false;
  }

  if (!theApp.IsSkipUpdate()) {
    ParameterBlock verBlock = SelectBlock(_T("Application\\LastVersion"));
    if (!verBlock.IsNull()) {
      CString lastVersion = verBlock.GetStringParameter(_T("version"), NULL);
	  // 当且仅当服务器版本号高于当前版本号时才升级
	  int lastV1, lastV2, lastV3, lastV4;
	  lastV1 = lastV2 = lastV3 = lastV4 = 999;
	  swscanf(lastVersion, _T("%d.%d.%d.%d"), &lastV1, &lastV2, &lastV3, &lastV4);
	  CString curVersion = AfxGetApp()->GetProfileString(_T(""), _T("Version"));
	  int curV1, curV2, curV3, curV4;
	  curV1 = curV2 = curV3 = curV4 = 0;
	  swscanf(curVersion, _T("%d.%d.%d.%d"), &curV1, &curV2, &curV3, &curV4);
	  bool skip = false;
	  if ((lastV1 * 1000 + lastV2 * 100 + lastV3 * 10 + lastV4) > (curV1 * 1000 + curV2 * 100 + curV3 * 10 + curV4))
	  {
      //if (lastVersion != AfxGetApp()->GetProfileString(_T(""), _T("Version"))) {
        CString remotePath = verBlock.GetStringParameter(_T("path"), NULL);
        TCHAR updateFilePath[MAX_PATH];
        _tcscpy(updateFilePath, appConfigPath);
        _tcscat(updateFilePath, _T("app_update.dat"));
        if (!client.GetFile(remotePath, updateFilePath)) {
          errorHolder.SaveLastError();
          return false;
        }
        appUpdated_ = true;
        appUpdateFilePath_ = updateFilePath;
        lastAppVersion_ = lastVersion;
      }
    }
  }

  // update fireware files from server.
  ParameterBlock deviceBlock = SelectBlock(_T("Device"));
  if (deviceBlock.IsNull()) {
    errorHolder.SetError(ERROR_SERVER_CONFIG);
    return false;
  }

  ParameterBlock modelBlock = deviceBlock.GetFirstChildBlock();
  if (modelBlock.IsNull()) {
    errorHolder.SetError(ERROR_SERVER_CONFIG);
    return false;
  }
  for (; !modelBlock.IsNull(); modelBlock = modelBlock.GetNextBlock()) {
    if (modelBlock.GetName() == _T("Model")) {
      int id = modelBlock.GetIntParameter(_T("id"), -1);
      if (id == -1) {
        errorHolder.SetError(ERROR_SERVER_CONFIG);
        return false;
      }
      CString localFirewarePath(appConfigPath);      
      localFirewarePath.AppendFormat(_T("firmware_%d.dat"), id);
      ParameterBlock firmwareBlock = modelBlock.SelectBlock(_T("Firmware"));
      if (firmwareBlock.IsNull()) {
        errorHolder.SetError(ERROR_SERVER_CONFIG);
        return false;
      }
      bool getFile = true;
      CString remoteCheckSum = firmwareBlock.GetStringParameter(_T("checkSum"), NULL);
      CString localCheckSum;
      if (!remoteCheckSum.IsEmpty() && MD5::CalcFile(localFirewarePath, &localCheckSum)) {
        getFile = (remoteCheckSum != localCheckSum);
      }
      if (getFile) {
        CString path = firmwareBlock.GetStringParameter(_T("path"), NULL);
        if (!client.GetFile(path, localFirewarePath)) {
          errorHolder.SaveLastError();
          return false;
        }
      }
    }
  }

  return true;
}
Ejemplo n.º 13
0
void wxGridSelection::ToggleCellSelection( int row, int col,
                                           bool ControlDown, bool ShiftDown,
                                           bool AltDown, bool MetaDown )
{
    // if the cell is not selected, select it
    if ( !IsInSelection ( row, col ) )
    {
        SelectCell( row, col, ControlDown, ShiftDown,
                    AltDown, MetaDown );
        return;
    }

    // otherwise deselect it. This can be simple or more or
    // less difficult, depending on how the cell is selected.
    size_t count, n;

    // The simplest case: The cell is contained in m_cellSelection
    // Then it can't be contained in rows/cols/block (since those
    // would remove the cell from m_cellSelection on creation), so
    // we just have to remove it from m_cellSelection.

    if ( m_selectionMode == wxGrid::wxGridSelectCells )
    {
        count = m_cellSelection.GetCount();
        for ( n = 0; n < count; n++ )
        {
            wxGridCellCoords& coords = m_cellSelection[n];
            if ( row == coords.GetRow() && col == coords.GetCol() )
            {
                wxGridCellCoords coords = m_cellSelection[n];
                m_cellSelection.RemoveAt(n);
                if ( !m_grid->GetBatchCount() )
                {
                    wxRect r = m_grid->BlockToDeviceRect( coords, coords );
                    ((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
                }

                // Send event
                wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
                                                wxEVT_GRID_RANGE_SELECT,
                                                m_grid,
                                                wxGridCellCoords( row, col ),
                                                wxGridCellCoords( row, col ),
                                                false,
                                                ControlDown, ShiftDown,
                                                AltDown, MetaDown );
                m_grid->GetEventHandler()->ProcessEvent(gridEvt);
                return;
            }
        }
    }

    // The most difficult case: The cell is member of one or even several
    // blocks. Split each such block in up to 4 new parts, that don't
    // contain the cell to be selected, like this:
    // |---------------------------|
    // |                           |
    // |           part 1          |
    // |                           |
    // |---------------------------|
    // |   part 3   |x|   part 4   |
    // |---------------------------|
    // |                           |
    // |           part 2          |
    // |                           |
    // |---------------------------|
    //   (The x marks the newly deselected cell).
    // Note: in row selection mode, we only need part1 and part2;
    //       in column selection mode, we only need part 3 and part4,
    //          which are expanded to whole columns automatically!

    count = m_blockSelectionTopLeft.GetCount();
    for ( n = 0; n < count; n++ )
      {
        wxGridCellCoords& coords1 = m_blockSelectionTopLeft[n];
        wxGridCellCoords& coords2 = m_blockSelectionBottomRight[n];
        int topRow = coords1.GetRow();
        int leftCol = coords1.GetCol();
        int bottomRow = coords2.GetRow();
        int rightCol = coords2.GetCol();
        if ( BlockContainsCell( topRow, leftCol, bottomRow, rightCol,
                                row, col ) )
        {
            // remove the block
            m_blockSelectionTopLeft.RemoveAt(n);
            m_blockSelectionBottomRight.RemoveAt(n);
            n--; count--;
            // add up to 4 smaller blocks and set update region
            if ( m_selectionMode != wxGrid::wxGridSelectColumns )
            {
                if ( topRow < row )
                    SelectBlock( topRow, leftCol, row - 1, rightCol,
                                 false, false, false, false, false );
                if ( bottomRow > row )
                    SelectBlock( row + 1, leftCol, bottomRow, rightCol,
                                 false, false, false, false, false );
            }
            if ( m_selectionMode != wxGrid::wxGridSelectRows )
            {
                if ( leftCol < col )
                    SelectBlock( row, leftCol, row, col - 1,
                                 false, false, false, false, false );
                if ( rightCol > col )
                    SelectBlock( row, col + 1, row, rightCol,
                                 false, false, false, false, false );
            }
        }
    }

    // remove a cell from a row, adding up to two new blocks
    if ( m_selectionMode != wxGrid::wxGridSelectColumns )
    {
        count = m_rowSelection.GetCount();
        for ( n = 0; n < count; n++ )
        {
            if ( m_rowSelection[n] == row )
            {
                m_rowSelection.RemoveAt(n);
                n--; count--;
                if (m_selectionMode == wxGrid::wxGridSelectCells)
                {
                    if ( col > 0 )
                        SelectBlock( row, 0, row, col - 1,
                                     false, false, false, false, false );
                    if ( col < m_grid->GetNumberCols() - 1 )
                        SelectBlock( row, col + 1,
                                     row, m_grid->GetNumberCols() - 1,
                                     false, false, false, false, false );
                }
            }
        }
    }

    // remove a cell from a column, adding up to two new blocks
    if ( m_selectionMode != wxGrid::wxGridSelectRows )
    {
        count = m_colSelection.GetCount();
        for ( n = 0; n < count; n++ )
        {
            if ( m_colSelection[n] == col )
            {
                m_colSelection.RemoveAt(n);
                n--; count--;
                if (m_selectionMode == wxGrid::wxGridSelectCells)
                {
                    if ( row > 0 )
                        SelectBlock( 0, col, row - 1, col,
                                     false, false, false, false, false );
                    if ( row < m_grid->GetNumberRows() - 1 )
                        SelectBlock( row + 1, col,
                                     m_grid->GetNumberRows() - 1, col,
                                     false, false, false, false, false );
                }
            }
        }
    }

    // Refresh the screen and send the event; according to m_selectionMode,
    // we need to either update only the cell, or the whole row/column.
    wxRect r;
    switch (m_selectionMode)
    {
      case wxGrid::wxGridSelectCells:
      {
          if ( !m_grid->GetBatchCount() )
          {
              r = m_grid->BlockToDeviceRect( wxGridCellCoords( row, col ),
                                             wxGridCellCoords( row, col ) );
              ((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
          }

          wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
                                          wxEVT_GRID_RANGE_SELECT,
                                          m_grid,
                                          wxGridCellCoords( row, col ),
                                          wxGridCellCoords( row, col ),
                                          false,
                                          ControlDown, ShiftDown,
                                          AltDown, MetaDown );
          m_grid->GetEventHandler()->ProcessEvent(gridEvt);
          break;
      }
      case wxGrid::wxGridSelectRows:
      {
          if ( !m_grid->GetBatchCount() )
          {
              r = m_grid->BlockToDeviceRect( wxGridCellCoords( row, 0 ),
                                             wxGridCellCoords( row, m_grid->GetNumberCols() - 1 ) );
              ((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
          }

          wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
                                          wxEVT_GRID_RANGE_SELECT,
                                          m_grid,
                                          wxGridCellCoords( row, 0 ),
                                          wxGridCellCoords( row, m_grid->GetNumberCols() - 1 ),
                                          false,
                                          ControlDown, ShiftDown,
                                          AltDown, MetaDown );
          m_grid->GetEventHandler()->ProcessEvent(gridEvt);
          break;
      }
      case wxGrid::wxGridSelectColumns:
      {
          if ( !m_grid->GetBatchCount() )
          {
              r = m_grid->BlockToDeviceRect( wxGridCellCoords( 0, col ),
                                             wxGridCellCoords( m_grid->GetNumberRows() - 1, col ) );
              ((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
          }

          wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
                                          wxEVT_GRID_RANGE_SELECT,
                                          m_grid,
                                          wxGridCellCoords( 0, col ),
                                          wxGridCellCoords( m_grid->GetNumberRows() - 1, col ),
                                          false,
                                          ControlDown, ShiftDown,
                                          AltDown, MetaDown );
          m_grid->GetEventHandler()->ProcessEvent(gridEvt);
          break;
      }
    }
}
Ejemplo n.º 14
0
// Change the selection mode
void wxGridSelection::SetSelectionMode(wxGrid::wxGridSelectionModes selmode)
{
    // if selection mode is unchanged return immediately
    if (selmode == m_selectionMode)
        return;

    if ( m_selectionMode != wxGrid::wxGridSelectCells )
    {
        // if changing form row to column selection
        // or vice versa, clear the selection.
        if ( selmode != wxGrid::wxGridSelectCells )
            ClearSelection();

        m_selectionMode = selmode;
    }
    else
    {
        // if changing from cell selection to something else,
        // promote selected cells/blocks to whole rows/columns.
        size_t n;
        while ( ( n = m_cellSelection.GetCount() ) > 0 )
        {
            n--;
            wxGridCellCoords& coords = m_cellSelection[n];
            int row = coords.GetRow();
            int col = coords.GetCol();
            m_cellSelection.RemoveAt(n);
            if (selmode == wxGrid::wxGridSelectRows)
                SelectRow( row );
            else // selmode == wxGridSelectColumns)
                SelectCol( col );
        }

        for (n = 0; n < m_blockSelectionTopLeft.GetCount(); n++)
        // Note that m_blockSelectionTopLeft's size may be changing!
        {
            wxGridCellCoords& coords = m_blockSelectionTopLeft[n];
            int topRow = coords.GetRow();
            int leftCol = coords.GetCol();
            coords = m_blockSelectionBottomRight[n];
            int bottomRow = coords.GetRow();
            int rightCol = coords.GetCol();
            if (selmode == wxGrid::wxGridSelectRows)
            {
                if (leftCol != 0 || rightCol != m_grid->GetNumberCols() - 1 )
                {
                    m_blockSelectionTopLeft.RemoveAt(n);
                    m_blockSelectionBottomRight.RemoveAt(n);
                    SelectBlock( topRow, 0,
                                 bottomRow, m_grid->GetNumberCols() - 1,
                                 false, false, false, false, false );
                }
            }
            else // selmode == wxGridSelectColumns)
            {
                if (topRow != 0 || bottomRow != m_grid->GetNumberRows() - 1 )
                {
                    m_blockSelectionTopLeft.RemoveAt(n);
                    m_blockSelectionBottomRight.RemoveAt(n);
                    SelectBlock( 0, leftCol,
                                 m_grid->GetNumberRows() - 1, rightCol,
                                 false, false, false, false, false );
                }
            }
        }
        m_selectionMode = selmode;
    }
}