📄 view_table_control.cpp
字号:
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CVIEW_Table_Control::On_Field_Add(wxCommandEvent &event)
{
int i;
CSG_String sFields;
CSG_Parameters P;
//-----------------------------------------------------
for(i=0; i<m_pTable->Get_Field_Count(); i++)
{
sFields.Append(m_pTable->Get_Field_Name(i)); sFields.Append(wxT('|'));
}
//-----------------------------------------------------
P.Set_Name(LNG("Add Field"));
P.Add_String(
NULL , "NAME" , LNG("Name"),
LNG(""),
LNG("Field")
);
P.Add_Choice(
NULL , "TYPE" , LNG("Field Type"),
LNG(""),
CSG_String::Format(wxT("%s|%s|%s|%s|%s|%s|%s|%s|"),
LNG("character string"),
LNG("1 byte integer"),
LNG("2 byte integer"),
LNG("4 byte integer"),
LNG("4 byte floating point"),
LNG("8 byte floating point"),
LNG("date (dd.mm.yyyy)"),
LNG("color (rgb)")
)
);
P.Add_Choice(
NULL , "FIELD" , LNG("Insert Position"),
LNG(""),
sFields, m_pTable->Get_Field_Count() - 1
);
P.Add_Choice(
NULL , "INSERT" , LNG("Insert Method"),
LNG(""),
CSG_String::Format(wxT("%s|%s|"),
LNG("before"),
LNG("after")
), 1
);
//-----------------------------------------------------
if( DLG_Parameters(&P) )
{
int Position;
TSG_Table_Field_Type Type;
switch( P("TYPE")->asInt() )
{
default:
case 0: Type = TABLE_FIELDTYPE_String; break;
case 1: Type = TABLE_FIELDTYPE_Char; break;
case 2: Type = TABLE_FIELDTYPE_Short; break;
case 3: Type = TABLE_FIELDTYPE_Int; break;
case 4: Type = TABLE_FIELDTYPE_Float; break;
case 5: Type = TABLE_FIELDTYPE_Double; break;
case 6: Type = TABLE_FIELDTYPE_Date; break;
case 7: Type = TABLE_FIELDTYPE_Color; break;
}
Position = P("FIELD")->asInt() + P("INSERT")->asInt();
m_pTable->Add_Field(P("NAME")->asString(), Type, Position);
Update_Table();
}
}
void CVIEW_Table_Control::On_Field_Add_UI(wxUpdateUIEvent &event)
{
event.Enable(FIXED_COLS == false);
}
//---------------------------------------------------------
void CVIEW_Table_Control::On_Field_Del(wxCommandEvent &event)
{
int i;
CSG_Parameters P;
//-----------------------------------------------------
P.Set_Name(LNG("Delete Fields"));
for(i=0; i<m_pTable->Get_Field_Count(); i++)
{
P.Add_Value(
NULL , CSG_String::Format(wxT("_%d_"), i), m_pTable->Get_Field_Name(i),
LNG(""),
PARAMETER_TYPE_Bool, false
);
}
//-----------------------------------------------------
if( DLG_Parameters(&P) )
{
for(i=m_pTable->Get_Field_Count()-1; i>=0; i--)
{
if( P(CSG_String::Format(wxT("_%d_"), i))->asBool() )
{
m_pTable->Del_Field(i);
}
}
Update_Table();
}
}
void CVIEW_Table_Control::On_Field_Del_UI(wxUpdateUIEvent &event)
{
event.Enable(FIXED_COLS == false);
}
//---------------------------------------------------------
void CVIEW_Table_Control::On_Field_Sort(wxCommandEvent &event)
{
CSG_String sFields;
CSG_Parameters P;
//-----------------------------------------------------
for(int i=0; i<m_pTable->Get_Field_Count(); i++)
{
sFields.Append(m_pTable->Get_Field_Name(i)); sFields.Append('|');
}
//-----------------------------------------------------
P.Set_Name(LNG("Sort Table"));
P.Add_Choice(
NULL , "FIELD" , LNG("Sort by"),
LNG(""),
sFields
);
P.Add_Choice(
NULL , "METHOD" , LNG("Direction"),
LNG(""),
CSG_String::Format(wxT("%s|%s|%s|"),
LNG("unsorted"),
LNG("ascending"),
LNG("descending")
), 1
);
//-----------------------------------------------------
if( DLG_Parameters(&P) )
{
Sort_Table(P("FIELD")->asInt(), P("METHOD")->asInt());
}
}
void CVIEW_Table_Control::On_Field_Sort_UI(wxUpdateUIEvent &event)
{
event.Enable(m_pTable->Get_Field_Count() > 0 && m_pTable->Get_Record_Count() > 1);
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CVIEW_Table_Control::On_Record_Add(wxCommandEvent &event)
{
Add_Record();
}
void CVIEW_Table_Control::On_Record_Add_UI(wxUpdateUIEvent &event)
{
event.Enable(!FIXED_ROWS);
}
//---------------------------------------------------------
void CVIEW_Table_Control::On_Record_Ins(wxCommandEvent &event)
{
Ins_Record();
}
void CVIEW_Table_Control::On_Record_Ins_UI(wxUpdateUIEvent &event)
{
event.Enable(!FIXED_ROWS);
}
//---------------------------------------------------------
void CVIEW_Table_Control::On_Record_Del(wxCommandEvent &event)
{
Del_Record();
}
void CVIEW_Table_Control::On_Record_Del_UI(wxUpdateUIEvent &event)
{
event.Enable(!FIXED_ROWS);
}
//---------------------------------------------------------
void CVIEW_Table_Control::On_Record_Clr(wxCommandEvent &event)
{
Del_Records();
}
void CVIEW_Table_Control::On_Record_Clr_UI(wxUpdateUIEvent &event)
{
event.Enable(!FIXED_ROWS);
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CVIEW_Table_Control::On_Autosize_Cols(wxCommandEvent &event)
{
AutoSizeColumns(false);
}
//---------------------------------------------------------
void CVIEW_Table_Control::On_Autosize_Rows(wxCommandEvent &event)
{
AutoSizeRows(false);
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CVIEW_Table_Control::On_LClick(wxGridEvent &event)
{
int iRecord, iField;
long lValue;
CSG_Table_Record *pRecord;
iRecord = event.GetRow();
if( (pRecord = m_pTable->Get_Record_byIndex(iRecord)) != NULL )
{
iField = event.GetCol();
if( iField >= 0 && iField < m_pTable->Get_Field_Count() )
{
switch( m_pTable->Get_Field_Type(iField) )
{
default:
break;
case TABLE_FIELDTYPE_Color:
if( DLG_Color(lValue = pRecord->asInt(iField)) )
{
pRecord->Set_Value(iField, lValue);
SET_CELL_COLOR(iRecord, iField, lValue);
ForceRefresh();
}
return;
}
}
}
event.Skip();
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CVIEW_Table_Control::On_LClick_Label(wxGridEvent &event)
{
if( event.GetCol() >= 0 )
{
SelectRow (GetGridCursorRow(), false);
SetGridCursor (GetGridCursorRow(), event.GetCol());
}
else if( event.GetRow() >= 0 )
{
SelectRow (event.GetRow(), false);
SetGridCursor (event.GetRow(), GetGridCursorCol());
}
else
{
SelectAll();
}
}
//---------------------------------------------------------
void CVIEW_Table_Control::On_RClick_Label(wxGridEvent &event)
{
wxMenu *pMenu;
//-----------------------------------------------------
if( event.GetCol() != -1 )
{
SetGridCursor (GetGridCursorRow(), event.GetCol());
pMenu = new wxMenu(GetColLabelValue(event.GetCol()), 0);
CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_FIELD_ADD);
CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_FIELD_DEL);
pMenu->AppendSeparator();
CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_AUTOSIZE_COLS);
CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_FIELD_SORT);
PopupMenu(pMenu, event.GetPosition().x, event.GetPosition().y - GetColLabelSize());
delete(pMenu);
}
//-----------------------------------------------------
else if( event.GetRow() != -1 )
{
SelectRow (event.GetRow(), false);
SetGridCursor (event.GetRow(), GetGridCursorCol());
pMenu = new wxMenu(wxString::Format(wxT("%s %d"), LNG("Row"), 1 + event.GetRow()), 0);
CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_RECORD_ADD);
CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_RECORD_INS);
CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_RECORD_DEL);
CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_RECORD_DEL_ALL);
pMenu->AppendSeparator();
CMD_Menu_Add_Item(pMenu, false, ID_CMD_TABLE_AUTOSIZE_ROWS);
PopupMenu(pMenu, event.GetPosition().x - GetRowLabelSize(), event.GetPosition().y);
delete(pMenu);
}
//-----------------------------------------------------
else
{
ClearSelection();
}
}
//---------------------------------------------------------
void CVIEW_Table_Control::On_LDClick_Label(wxGridEvent &event)
{
Sort_Table(event.GetCol(), -1);
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CVIEW_Table_Control::On_Select(wxGridRangeSelectEvent &event)
{
for(int iRow=event.GetTopRow(); iRow<=event.GetBottomRow(); iRow++)
{
_Select(iRow, event.Selecting());
}
event.Skip();
}
//---------------------------------------------------------
inline void CVIEW_Table_Control::_Select(int iRow, bool bSelect)
{
CSG_Table_Record *pRecord;
if( (pRecord = m_pTable->Get_Record_byIndex(iRow)) != NULL && bSelect != pRecord->is_Selected() )
{
m_pTable->Select(pRecord, true);
if( m_pTable->is_Private() )
{
g_pData->Update_Views(m_pTable->Get_Owner());
}
}
}
//---------------------------------------------------------
void CVIEW_Table_Control::Update_Selection(void)
{
int i, j, n;
CSG_Table_Record *pRecord, **Selection;
if( (n = m_pTable->Get_Selection_Count()) > 0 )
{
Selection = (CSG_Table_Record **)SG_Malloc(n * sizeof(CSG_Table_Record *));
for(i=0; i<n; i++)
{
Selection[i] = m_pTable->Get_Selection(i);
}
ClearSelection();
for(j=0; j<m_pTable->Get_Record_Count(); j++)
{
pRecord = m_pTable->Get_Record_byIndex(j);
for(i=0; i<n; i++)
{
if( pRecord == Selection[i] )
{
SelectRow(j, true);
break;
}
}
}
SG_Free(Selection);
}
else
{
ClearSelection();
}
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -