1019{
1020 wxString buf = text_data.GetText();
1021 int clip_size = buf.size();
1022
1023 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", clip_size %1%, pasted_data %2%") %clip_size %buf;
1024 if (clip_size <= 0)
1025 return;
1030 int src_row_cnt = src_bottom_row - src_top_row + 1;
1031 int src_col_cnt = src_right_col -src_left_col + 1;
1032
1033 const wxGridBlocks blocks = GetSelectedBlocks();
1034 wxGridBlocks::iterator iter = blocks.begin();
1035 wxGridBlockCoords selection;
1036 if (iter == blocks.end())
1037 {
1038
1039 if (m_currentCellCoords == wxGridNoCellCoords)
1040 {
1041 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", no selection and no current , can not paste");
1042 return;
1043 }
1044
1045 selection = wxGridBlockCoords(GetGridCursorRow(),
1046 GetGridCursorCol(),
1047 GetGridCursorRow(),
1048 GetGridCursorCol());
1049 }
1050 else
1051 {
1052 selection = *blocks.begin();
1053 }
1054
1055 int dst_top_row = selection.GetTopRow();
1056 int dst_bottom_row = selection.GetBottomRow();
1057 int dst_left_col = selection.GetLeftCol();
1058 int dst_right_col = selection.GetRightCol();
1059 int dst_row_cnt = dst_bottom_row - dst_top_row + 1;
1060 int dst_col_cnt = dst_right_col - dst_left_col + 1;
1061 wxArrayString string_array;
1062
1063 auto split = [](wxString& source, wxArrayString& array) {
1064 wxString temp = source;
1065 wxChar split_char1 = '\t';
1066 wxChar split_char2 = '\n';
1067 bool finished = false;
1068 while (!finished && (temp.Length() > 0)) {
1069 int pos = temp.find(split_char2);
1070 if (pos == 0)
1071 {
1072 temp = temp.substr(1);
1073 continue;
1074 }
1075
1076 wxString temp_line;
1077 if (pos == wxString::npos)
1078 {
1079 temp_line = temp;
1080 finished = true;
1081 }
1082 else
1083 {
1084 temp_line = temp.substr(0, pos);
1085 temp = temp.substr(pos+1);
1086 }
1087
1088 while(true) {
1089 pos = temp_line.find(split_char1);
1090 if (pos == 0)
1091 {
1092 temp_line = temp_line.substr(1);
1093 continue;
1094 }
1095 else if (pos == wxString::npos)
1096 {
1097 if (temp_line.Length() > 0)
1098 {
1099 array.push_back(temp_line.Trim());
1100 break;
1101 }
1102 }
1103 else
1104 {
1105 array.push_back(temp_line.substr(0, pos));
1106 temp_line = temp_line.substr(pos+1);
1107 }
1108 }
1109 }
1110 };
1111
1113 if ((src_row_cnt == 1) && (src_col_cnt == 1))
1114 {
1115 if ((dst_col_cnt != 1) || (dst_left_col != src_left_col)) {
1116 wxLogWarning(
_L(
"One cell can only be copied to one or more cells in the same column."));
1117 }
1118 else {
1119 split(buf, string_array);
1120 wxString source_string = string_array[0];
1121 if (string_array.GetCount() <= 0) {
1122 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(", can not split pasted data %1%") % buf;
1123 return;
1124 }
1125 for (int i = 0; i < dst_row_cnt; i++)
1126 {
1127 if (!this->IsReadOnly(dst_top_row + i, dst_left_col)) {
1128 grid_table->SetValue(dst_top_row + i, dst_left_col, source_string);
1129 grid_table->OnCellValueChanged(dst_top_row + i, dst_left_col);
1130 }
1131 }
1132 }
1133
1134 }
1135 else {
1136 wxLogWarning(
_L(
"Copying multiple cells is not supported."));
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155 }
1156 this->ForceRefresh();
1157}
#define _L(s)
Definition OBJ.cpp:34
Vec3d pos(const Pt &p)
Definition ReprojectPointsOnMesh.hpp:16