diff --git a/ctl/ctlSQLGrid.cpp b/ctl/ctlSQLGrid.cpp index aa7fbed..e012390 100644 --- a/ctl/ctlSQLGrid.cpp +++ b/ctl/ctlSQLGrid.cpp @@ -61,6 +61,7 @@ ctlSQLGrid::ctlSQLGrid(wxWindow *parent, wxWindowID id, const wxPoint &pos, cons SetCellHighlightColour(wxColor(0, 0, 0)); grp=NULL; isSort=false; + searchStr = ""; Connect(wxID_ANY, wxEVT_GRID_LABEL_LEFT_DCLICK, wxGridEventHandler(ctlSQLGrid::OnLabelDoubleClick)); } #include "wx/renderer.h" diff --git a/ctl/ctlSQLResult.cpp b/ctl/ctlSQLResult.cpp index 15dca1a..04a9b6e 100644 --- a/ctl/ctlSQLResult.cpp +++ b/ctl/ctlSQLResult.cpp @@ -38,6 +38,9 @@ ctlSQLResult::ctlSQLResult(wxWindow *parent, pgConn *_conn, wxWindowID id, const cg=GetGridLineColour(); Connect(wxID_ANY, wxEVT_GRID_RANGE_SELECT, wxGridRangeSelectEventHandler(ctlSQLResult::OnGridSelect)); Connect(wxID_ANY, wxEVT_GRID_COL_SORT, wxGridEventHandler(ctlSQLResult::OnGridColSort)); + Connect(wxID_ANY, wxEVT_KEY_UP, wxCharEventHandler(ctlSQLResult::OnKeyUp)); + Connect(wxID_ANY, wxEVT_CHAR, wxCharEventHandler(ctlSQLResult::OnKeyChar)); + m_win_s = NULL; } @@ -754,6 +757,98 @@ wxString ctlSQLResult::SummaryColumn() result.Printf(wxT("%f"), sum); return result; } +void ctlSQLResult::OnKeyUp(wxKeyEvent& event) { + if (event.GetKeyCode() == WXK_ESCAPE && this->searchStr.Len() > 0) { + OnKeyChar(event); + event.Skip(false); + return; + } + if (event.GetKeyCode() == WXK_SPACE && this->searchStr.Len()>0) { + OnKeyChar(event); + event.Skip(false); + return; + } + if (event.GetKeyCode() == WXK_RETURN && this->searchStr.Len() > 0) { + OnKeyChar(event); + event.Skip(false); + return; + } + + event.Skip(); +} +void ctlSQLResult::OnKeyChar(wxKeyEvent& event) { + if (event.GetKeyCode() == WXK_RETURN) { + sqlResultTable* t = (sqlResultTable*)GetTable(); + if (!(thread && thread->DataValid())) { return ; } + //wxString fltval=GetCellValue(row,col); + wxString text; + int colS = GetGridCursorCol(); + int rowS= GetGridCursorRow(); + wxString fltval = this->searchStr; + bool eq; + size_t numRows = GetNumberRows(); + size_t numCols = GetNumberCols(); + int all = 0, show = 0, hide = 0; + for (size_t i = rowS; i < numRows; i++) + { + //str.Append(GetExportLine(i, cols)); + //SetRowSize(i,sizerow); + if (GetRowSize(i) == 0) continue; + for (int col = 0; col < numCols; col++) + { + if ((t->GetValueFast(i, col).Find(fltval) != wxNOT_FOUND)) { + MakeCellVisible(i, col); + SetGridCursor(i, col); + return; + } + + } + } + } + if (event.GetKeyCode() == WXK_BACK) { + this->searchStr=this->searchStr.RemoveLast(); + m_win_s->SetValue(this->searchStr); + Refresh(); + } + if (event.GetKeyCode() == WXK_ESCAPE) { + this->searchStr = ""; + if (m_win_s != NULL) { + m_win_s->Destroy(); + m_win_s = NULL; + } + Refresh(); + + } + else + { + wxChar uc = event.GetUnicodeKey(); + if (uc != WXK_NONE) { + if (uc >= 32) { + this->searchStr.Append(uc); + if (this->searchStr.Len() == 1) { + if (m_win_s == NULL) { + int colS = GetGridCursorCol(); + wxWindow* t = this->GetGridColLabelWindow(); + + wxRect r = CellToRect(0, colS); + r.y = 0; + m_win_s = new wxTextCtrl(t, wxID_ANY, "", + r.GetPosition(), + r.GetSize(), + wxTE_PROCESS_ENTER); + //|wxTE_READONLY + m_win_s->SetInsertionPointEnd(); + + } + } + m_win_s->SetValue(this->searchStr); + Refresh(); + } + + } + } + event.Skip(); +} void ctlSQLResult::OnGridColSort(wxGridEvent& event) { const int col = event.GetCol(); diff --git a/include/ctl/ctlSQLGrid.h b/include/ctl/ctlSQLGrid.h index f0351db..1ea4e03 100644 --- a/include/ctl/ctlSQLGrid.h +++ b/include/ctl/ctlSQLGrid.h @@ -58,6 +58,9 @@ public: GroupRows *grp; int generatesql; // 0 -���, 1 - insert , 2 - in_list wxString sqlquerytext; + // Fast searh + wxString searchStr; + WX_DECLARE_STRING_HASH_MAP( int, ColKeySizeHashMap ); DECLARE_DYNAMIC_CLASS(ctlSQLGrid) @@ -195,6 +198,7 @@ class CursorCellRenderer : public wxGridCellStringRenderer const wxRect& rect, int row, int col, bool isSelected) { int hAlign, vAlign; + int sPos=-1; attr.GetAlignment(&hAlign, &vAlign); ////////////////////////////////////////////////////////////////////////////// //CursorCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected); // @@ -218,7 +222,7 @@ class CursorCellRenderer : public wxGridCellStringRenderer { wxColor color; color.Set(239, 228, 176); - if (text.Find(wxT('\n'))!=wxNOT_FOUND ) + if (sPos=text.Find(wxT('\n'))!=wxNOT_FOUND ) dc.SetBrush( wxBrush(color, wxSOLID) ); else dc.SetBrush( wxBrush(attr.GetBackgroundColour(), wxSOLID) ); @@ -231,9 +235,54 @@ class CursorCellRenderer : public wxGridCellStringRenderer dc.SetPen( *wxTRANSPARENT_PEN ); dc.DrawRectangle(rect); - ////////////////////////////////////////////////////////////////////////////// SetTextColoursAndFont(grid, attr, dc, isSelected); + ctlSQLGrid* ctrl = static_cast(&grid); + if (!ctrl->searchStr.IsEmpty()) { + if (sPos == -1) sPos = text.Len(); + int pp; + + pp = text.Find(ctrl->searchStr); + if (pp >= 0) { + wxArrayString lines; + grid.StringToLines(text, lines); + wxRect r; + r.y = rect.y; + dc.SetBrush(*wxYELLOW_BRUSH); + size_t nLines = lines.GetCount(); + for (size_t l = 0; l < nLines; l++) + { + const wxString& line = lines[l]; + pp = line.Find(ctrl->searchStr); + if (line.empty() || (pp==-1)) + { + r.y += dc.GetCharHeight(); + continue; + } + + int lineWidth, lineWidthP, lineHeight,start=0; + wxString pref; + if (hAlign == wxALIGN_RIGHT) { + start = pp + ctrl->searchStr.Len(); + pref = line.substr(start); + } else + pref = line.substr(start, pp); + + dc.GetTextExtent(pref, &lineWidthP, &lineHeight); + r.x=rect.x+lineWidthP; + pref= line.substr(pp, ctrl->searchStr.Len()); + dc.GetTextExtent(pref, &lineWidth, &lineHeight); + r.width = lineWidth; + r.height = lineHeight; + if (hAlign == wxALIGN_RIGHT) r.x = rect.x + (rect.width - lineWidth- lineWidthP); + if (!(r.y < (rect.y + rect.height))) { r.y = rect.y + rect.height - 5; r.height = 5; } + if (!((r.x < (rect.x + rect.width)))) { r.x = rect.x + rect.width - 5; r.width = 5; } + dc.DrawRoundedRectangle(r, 3); + break; + } + } + } + grid.DrawTextRectangle(dc, text, rect, hAlign, vAlign); } diff --git a/include/ctl/ctlSQLResult.h b/include/ctl/ctlSQLResult.h index 4676cef..ffa323d 100644 --- a/include/ctl/ctlSQLResult.h +++ b/include/ctl/ctlSQLResult.h @@ -74,6 +74,8 @@ public: void ResultsFinished(); void OnGridSelect(wxGridRangeSelectEvent &event); void OnGridColSort(wxGridEvent& event); + void OnKeyChar(wxKeyEvent& event); + void OnKeyUp(wxKeyEvent& event); wxString SetFilter(int row,int col,bool reverse); wxArrayString colNames; @@ -83,6 +85,7 @@ private: pgQueryThread *thread; pgConn *conn; bool rowcountSuppressed; + wxTextCtrl* m_win_s; }; class sqlResultTable : public wxGridStringTable//wxGridTableBase