Support hotkey for context help window.

Улучшена поддержка клавиши для навигации в контекстной справке.
Краткий список:
PAGEDOWN,PAGEUP,UP,DOWN,HOME,END - скроллинг окна.
+ - увеличить размер окна.
S - screenshot контекстной справки.
C - копирование в html формате.
This commit is contained in:
lsv 2026-04-13 15:03:25 +05:00
parent a0ff59ae98
commit d47a0fb61c
3 changed files with 130 additions and 130 deletions

View file

@ -90,7 +90,7 @@ ctlSQLBox::ctlSQLBox(wxWindow *parent, wxWindowID id, const wxPoint &pos, const
m_dlgFindReplace = 0;
m_dlgTransformText = 0;
m_database = NULL;
m_autocompDisabled = false;
process = 0;
processID = 0;
@ -378,7 +378,7 @@ void ctlSQLBox::OnTextMark(wxCommandEvent& ev) {
int spos=0;
if (ind>0) {
spos=IndicatorStart(9,curr);
if (spos>=0) {
if (spos>=0) {
epos=IndicatorEnd(9,curr);
len=epos-spos;
//len=PositionRelative(spos,epos);
@ -386,7 +386,7 @@ void ctlSQLBox::OnTextMark(wxCommandEvent& ev) {
IndicatorClearRange(spos,len);
}
} else {
// goto
// goto
epos=IndicatorEnd(9,curr);
if (epos==0) return;
if (epos==GetTextLength()) {
@ -396,13 +396,13 @@ void ctlSQLBox::OnTextMark(wxCommandEvent& ev) {
GotoPos(epos);
return;
}
}
if (epos!=GetTextLength()) {
epos=IndicatorEnd(9,epos);
GotoPos(epos);
}
}
}
@ -637,7 +637,7 @@ void ctlSQLBox::OnCopy(wxCommandEvent& ev) {
Copy();
}
void ctlSQLBox::OnFuncHelp(wxCommandEvent& ev) {
FunctionPGHelper *fh=winMain->GetFunctionPGHelper();
int pos = GetCurrentPos();
if (!fh->isValid()) return;
@ -685,12 +685,12 @@ void ctlSQLBox::OnFuncHelp(wxCommandEvent& ev) {
if (bigtext) {
rr.x=(int) sizeScreen.x*0.8;rr.y=sizeScreen.y*0.7;
}
m_PopupHelp = new popuphelp(this->GetParent(), key, fh,p,rr);
m_PopupHelp = new popuphelp(this, key, fh,p,rr);
if (m_PopupHelp && m_PopupHelp->IsValid() && rr != m_PopupHelp->GetSizePopup() && !bigtext) {
// recreate with new size
rr = m_PopupHelp->GetSizePopup();
delete m_PopupHelp;
m_PopupHelp = new popuphelp(this->GetParent(), key, fh, p, rr);
m_PopupHelp = new popuphelp(this, key, fh, p, rr);
}
if (m_PopupHelp && m_PopupHelp->IsValid()) {
@ -756,7 +756,7 @@ void ctlSQLBox::Colourise(int start, int end)
}
}
hword = -1;
nextchar:
#ifdef WIN32
int i = IsDBCSLeadByte(ch) ? 2 : 1;
@ -882,7 +882,7 @@ void ctlSQLBox::OnKeyDown(wxKeyEvent &event)
}
if (!AutoCompActive()) {
// work only hide autocomplite
if (m_hint_mode) {
if (event.GetKeyCode() == WXK_RIGHT && event.GetModifiers() == wxMOD_ALT && !hint.IsEmpty()) {
wxString ins = hint.substr(s.length());
@ -954,7 +954,7 @@ void ctlSQLBox::OnKeyDown(wxKeyEvent &event)
return;
}
if ((event.GetKeyCode() == '9')&&(event.GetModifiers() == (wxMOD_SHIFT)))
{
int pos = GetCurrentPos() ;
@ -1027,7 +1027,7 @@ void ctlSQLBox::OnKeyDown(wxKeyEvent &event)
if (pos==wxNOT_FOUND||(pos==calltip.length())) pos=ct_hl;
}
CallTipSetHighlight(prev,pos);
ct_hl=pos;
}
}
@ -1079,7 +1079,7 @@ void ctlSQLBox::OnKeyDown(wxKeyEvent &event)
{
f=true;
}
if (t.EndsWith(rpl)&&f)
{
@ -1354,7 +1354,7 @@ wxString ctlSQLBox::ExternalFormat(int typecmd)
break;
}
wxArrayString choiceCmpOpts;
choiceCmpOpts.Add(_("All line (use all EOL)"));
choiceCmpOpts.Add(_("First line pattern (ignore all but the first EOL)"));
choiceCmpOpts.Add(_("Try looking for patterns above"));
@ -1527,7 +1527,7 @@ std::pair<int,int> ctlSQLBox::SelectQuery(int startposition)
#endif
pos=pos+i;
}
}
pos--;
while ((pos) >= 0)
@ -1558,7 +1558,7 @@ std::pair<int,int> ctlSQLBox::SelectQuery(int startposition)
if (startposition<0) SetSelection(pstart,pend);
//return result {pstart,pend};
return std::make_pair(pstart, pend);
}
void ctlSQLBox::HighlightBrace(int start, int len, int inicator) {
{
@ -1688,7 +1688,7 @@ void ctlSQLBox::OnPositionStc(wxStyledTextEvent &event)
}
ident.Clear();
}
}
if (st != 1 &&st != 2 && st != 6 && st != 7 &&(ch==';')&&startsql==0) startsql=pos+1;
if (( ch == '}' ||
@ -1708,11 +1708,11 @@ void ctlSQLBox::OnPositionStc(wxStyledTextEvent &event)
}
}
int endtext= GetLength();
bool isfrom=false;
pos=startsql;
ident.Clear();
while (pos<endtext) {
ch = GetCharAt(pos);
@ -1829,7 +1829,7 @@ wxString ctlSQLBox::TextToHtml(int start, int end,bool isAddNewLine, const std::
if (isAddNewLine) newline = L"\u2936<br>";
//if (isAddNewLine) newline = L"&ldca;<br>";
//if (isAddNewLine) newline = L"<br>\x0b78";
int IndexObj=0;
int pos=999999999;
wxString obj;
@ -1851,13 +1851,13 @@ wxString ctlSQLBox::TextToHtml(int start, int end,bool isAddNewLine, const std::
int s = 0;
//wxUniChar c = selText[k].GetValue();
if (c == '\r') { k++; continue; };
if (c == '\n') { lstr += newline; k++; continue; };
if (c == 9) s = 5;
if (c == 32) s = 1;
if (c == '<') { lstr+="&lt;"; k++; continue; };
if (c == '>') { lstr+="&gt;"; k++; continue; };
if (c == '&') { lstr+="&amp;"; k++; continue; };
if (c == '&') { lstr+="&amp;"; k++; continue; };
if (s > 0) for (int tt = 0; tt < s; tt++) lstr += "&nbsp;";
else lstr += c;
k++;
@ -1895,7 +1895,7 @@ void ctlSQLBox::Copy() {
wxTheClipboard->SetData(dataobj);
wxTheClipboard->Close();
}
} else wxStyledTextCtrl::Copy();
@ -1920,7 +1920,7 @@ void ctlSQLBox::OnAutoComplete(wxCommandEvent &rev)
int poshome=PositionFromLine(GetCurrentLine());
int posspc=PositionRelative(poshome,spaceidx);
if (spaceidx != -1) {
while (poshome< posspc) {
int ch = GetCharAt(posspc);
int st = GetStyleAt(posspc) & 0x1F;
@ -1932,7 +1932,7 @@ void ctlSQLBox::OnAutoComplete(wxCommandEvent &rev)
} else if (ch==' ') {
break;
}
}
wxString lastexp=GetTextRange(PositionFromLine(GetCurrentLine()),posspc);
spacecharidx=lastexp.Length();
@ -2019,7 +2019,7 @@ void ctlSQLBox::OnAutoComplete(wxCommandEvent &rev)
if (!field.IsEmpty()) {
wxString lf;
wxString tabn;
wxString r=f.GetColsList(field, lf, tabn);
if (r == "\t") r.clear();
int l2 = 0;
@ -2111,7 +2111,7 @@ void ctlSQLBox::OnAutoComplete(wxCommandEvent &rev)
}
wxString f_name;
if (!fl && !alias.IsEmpty()) {
wxString lst=list_table;
wxString table;
//alias.Replace(wxT("."), wxT(""));
@ -2151,7 +2151,7 @@ void ctlSQLBox::OnAutoComplete(wxCommandEvent &rev)
AutoCompShow(l2, prev);
return;
}
//list_table.Find(alias
//list_table.Find(alias
}
l=0;
for (int kk=what.Len()-1;kk>=0;kk--) {

View file

@ -991,7 +991,7 @@ void ctlSQLGrid::OnShowPopup(wxThreadEvent& event) {
// recreate with new size
rr = m_Popup->GetSizePopup();
delete m_Popup;
m_Popup = new popuphelp((wxWindow*)winMain, key, &fh, p, rr);
m_Popup = new popuphelp(this, key, &fh, p, rr);
}
if (m_Popup && m_Popup->IsValid()) {

View file

@ -37,7 +37,99 @@ public:
sizew = sz;
}
wxSize GetSizePopup() { return sizew; }
popuphelp(wxWindow* parent,wxString keyword, FunctionPGHelper *hhelper,wxPoint &posit,wxSize &newSz) : wxPopupTransientWindow(parent) {
void keyProcessing(wxKeyEvent& event) {
if (event.GetKeyCode() == WXK_ESCAPE) {
Hide();
event.Skip();
return;
}
if (event.GetKeyCode() == WXK_NUMPAD_ADD) {
wxSize sz = this->GetSize();
wxSize szh = htmlWindow->GetSize();
int xx, yy;
htmlWindow->GetVirtualSize(&xx, &yy);
wxPoint p = GetScreenPosition();
wxSize sizeScreen = getScreenSizeForPoint(p);
if (yy > szh.y) {
if (p.y + sz.y + 50 < sizeScreen.y)
sz.y += 50;
else
if (p.y > 50) { p.y = p.y - 50; sz.y += 50; }
}
if (p.x + sz.x + 50 < sizeScreen.x)
sz.x += 50;
else
if (p.x > 50) { p.x = p.x - 50; sz.x += 50; }
SetSize(p.x, p.y, sz.x, sz.y, wxSIZE_USE_EXISTING);
Layout();
wxSize newsz = GetSize();
//std::cout << sz.GetWidth() << "," << sz.GetHeight() << " new: " << newsz.GetWidth() << "," << newsz.GetHeight() << std::endl;
}
if (event.GetKeyCode() == WXK_PAGEDOWN) htmlWindow->ScrollPages(1);
if (event.GetKeyCode() == WXK_PAGEUP) htmlWindow->ScrollPages(-1);
if (event.GetKeyCode() == WXK_DOWN) htmlWindow->ScrollLines(1);
if (event.GetKeyCode() == WXK_UP) htmlWindow->ScrollLines(-1);
if (event.GetKeyCode() == WXK_HOME) htmlWindow->ScrollPages(-1000);
if (event.GetKeyCode() == WXK_END) htmlWindow->ScrollPages(1000);
//std::cout << "key code " << event.GetKeyCode() << " " << std::endl;
if (event.GetKeyCode() == 'C' && hist.size() > 0) {
if (wxTheClipboard->Open())
{
wxString h = hist[hist.size() - 1];
// Добавляем данные (можно добавить несколько форматов, если нужно)
wxDataObjectComposite* dataobj = new wxDataObjectComposite();
dataobj->Add(new wxHTMLDataObject(h));
wxTheClipboard->SetData(dataobj);
// fix for linux app crush
wxSafeYield();
wxTheClipboard->Close(); // crush app without wxSafeYield();
}
else
{
wxLogError("No open clipboard.");
}
}
if (event.GetKeyCode() == 'S') {
wxSize clientSize = this->GetClientSize();
// Создаём битмап того же размера
wxBitmap bitmap(clientSize.x, clientSize.y, -1); // -1 — лучший формат для экрана
// Создаём DC для рисования в битмап
wxMemoryDC memDC;
memDC.SelectObject(bitmap);
// Очищаем фон (опционально, если окно не полностью перерисовано)
memDC.SetBackground(*wxWHITE_BRUSH);
memDC.Clear();
// Используем wxClientDC для чтения содержимого окна
wxClientDC clientDC(this);
// Переносим данные с clientDC в memDC (копируем прямоугольник)
// Важно: координаты — относительно окна!
memDC.Blit(0, 0, clientSize.x, clientSize.y, &clientDC, 0, 0);
// Освобождаем DC
memDC.SelectObject(wxNullBitmap);
// Открываем буфер обмена
if (wxTheClipboard->Open())
{
// Добавляем данные (можно добавить несколько форматов, если нужно)
wxTheClipboard->SetData(new wxBitmapDataObject(bitmap));
wxTheClipboard->Close();
}
else
{
wxLogError("No open clipboard.");
}
}
};
popuphelp(wxWindow* parent,wxString keyword, FunctionPGHelper *hhelper,wxPoint &posit,wxSize &newSz) : wxPopupTransientWindow(parent, wxPU_CONTAINS_CONTROLS| wxBORDER_NONE) {
wxSize top_sz(newSz);
sizew = top_sz;
//SetSize(top_sz);
@ -48,7 +140,7 @@ public:
int size = fnt.GetPointSize();
SetFont(fnt);
htmlWindow = new wxHtmlWindow(this, -1, wxDefaultPosition, sizew);
wxFont font(size, wxFontFamily::wxFONTFAMILY_MODERN, wxFontStyle::wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
wxString fixf = font.GetFaceName();
wxString scalf = fnt.GetFaceName();
@ -64,7 +156,7 @@ public:
htmlWindow->SetRelatedStatusBar(0);
//htmlWindow->SetPage("<html><body><h1>TEST</h1><span fgcolor=\"#332233\">Set Page Works</span></body></hmtl>");
wxString txt;
txt=hhelper->getDBinfoKeyword(keyword,true);
if (txt.IsEmpty()) {
@ -82,7 +174,7 @@ public:
//wxSize sz= htmlWindow->GetSize();
//sz = htmlWindow->GetBestSize();
//htmlWindow->SetHTMLBackgroundImage(wxBitmapBundle::FromSVGFile("data/bg.svg", wxSize(65, 45)));
wxBoxSizer* topsizer;
wxBoxSizer* topsizer;
topsizer = new wxBoxSizer(wxVERTICAL);
//htmlWindow->SetInitialSize(wxSize(htmlWindow->GetInternalRepresentation()->GetWidth(), htmlWindow->GetInternalRepresentation()->GetHeight()));
@ -129,7 +221,7 @@ public:
//this->Bind(wxEVT_HTML_CELL_CLICKED, [&](wxHtmlCellEvent& event) {
// wxHtmlCell* c = event.GetCell();
//
//
// wxString ctext=c->ConvertToText(NULL);
// ctext=htmlWindow->SelectionToText();
// wxString s = wxString::Format("cell = %s",ctext.c_str());
@ -146,7 +238,7 @@ public:
SetPage(body);
}
return;
}
}
body=this->hhelper->getDBinfoKeyword(name,false);
if (body.IsEmpty()) {
body=this->hhelper->getHelpString(name);
@ -158,99 +250,7 @@ public:
//ctext=htmlWindow->SelectionToText();
//wxString s = wxString::Format("cell = %s",ctext.c_str());
});
htmlWindow->Bind(wxEVT_KEY_DOWN, [&](wxKeyEvent& event) {
if (event.GetKeyCode() == WXK_ESCAPE) {
Hide();
event.Skip();
return;
}
if (event.GetKeyCode() == WXK_NUMPAD_ADD) {
wxSize sz=this->GetSize();
wxSize szh=htmlWindow->GetSize();
int xx, yy;
htmlWindow->GetVirtualSize(&xx, &yy);
wxPoint p=GetScreenPosition();
wxSize sizeScreen=getScreenSizeForPoint(p);
if (yy>szh.y) {
if (p.y+sz.y +50 <sizeScreen.y)
sz.y+=50;
else
if (p.y>50) {p.y=p.y-50; sz.y+=50;}
}
if (p.x+sz.x +50 <sizeScreen.x)
sz.x+=50;
else
if (p.x>50) {p.x=p.x-50; sz.x+=50;}
SetSize(p.x,p.y,sz.x,sz.y,wxSIZE_USE_EXISTING);
Layout();
wxSize newsz=GetSize();
//std::cout << sz.GetWidth() << "," << sz.GetHeight() << " new: " << newsz.GetWidth() << "," << newsz.GetHeight() << std::endl;
}
if (event.GetKeyCode() == WXK_PAGEDOWN) htmlWindow->ScrollPages(1);
if (event.GetKeyCode() == WXK_PAGEUP) htmlWindow->ScrollPages(-1);
if (event.GetKeyCode() == WXK_DOWN) htmlWindow->ScrollLines(1);
if (event.GetKeyCode() == WXK_UP) htmlWindow->ScrollLines(-1);
if (event.GetKeyCode() == WXK_HOME) htmlWindow->ScrollPages(-1000);
if (event.GetKeyCode() == WXK_END) htmlWindow->ScrollPages(1000);
//std::cout << "key code " << event.GetKeyCode() << " " << std::endl;
if (event.GetKeyCode() == 'C' && hist.size()>0) {
if (wxTheClipboard->Open())
{
wxString h=hist[hist.size()-1];
// Добавляем данные (можно добавить несколько форматов, если нужно)
wxDataObjectComposite* dataobj = new wxDataObjectComposite();
dataobj->Add(new wxHTMLDataObject(h));
wxTheClipboard->SetData(dataobj);
// fix for linux app crush
wxSafeYield();
wxTheClipboard->Close(); // crush app without wxSafeYield();
}
else
{
wxLogError("No open clipboard.");
}
}
if (event.GetKeyCode() == 'S') {
wxSize clientSize = this->GetClientSize();
// Создаём битмап того же размера
wxBitmap bitmap(clientSize.x, clientSize.y, -1); // -1 — лучший формат для экрана
// Создаём DC для рисования в битмап
wxMemoryDC memDC;
memDC.SelectObject(bitmap);
// Очищаем фон (опционально, если окно не полностью перерисовано)
memDC.SetBackground(*wxWHITE_BRUSH);
memDC.Clear();
// Используем wxClientDC для чтения содержимого окна
wxClientDC clientDC(this);
// Переносим данные с clientDC в memDC (копируем прямоугольник)
// Важно: координаты — относительно окна!
memDC.Blit(0, 0, clientSize.x, clientSize.y, &clientDC, 0, 0);
// Освобождаем DC
memDC.SelectObject(wxNullBitmap);
// Открываем буфер обмена
if (wxTheClipboard->Open())
{
// Добавляем данные (можно добавить несколько форматов, если нужно)
wxDataObjectComposite* dataobj = new wxDataObjectComposite();
dataobj->Add(new wxBitmapDataObject(bitmap));
wxTheClipboard->SetData(dataobj);
wxTheClipboard->Close();
}
else
{
wxLogError("No open clipboard.");
}
}
});
Bind(wxEVT_CHAR_HOOK, &popuphelp::keyProcessing,this);
htmlWindow->Bind(wxEVT_RIGHT_UP, [&](wxMouseEvent& event) {
wxString name;
wxLongLong e = wxGetLocalTimeMillis();
@ -322,7 +322,7 @@ private:
innerbody.Replace("<body>", "<html><body TEXT=\"#000000\" BGCOLOR=\"#FFFFE0\" LINK=\"#0000FF\" VLINK=\"#FF0000\" ALINK=\"#000088\">", false);
h = "" + innerbody + "";
}
else
else
h = "<html><body TEXT=\"#000000\" BGCOLOR=\"#FFFFE0\" LINK=\"#0000FF\" VLINK=\"#FF0000\" ALINK=\"#000088\">" + innerbody + "</body></hmtl>";
if (gethistory) {
@ -346,7 +346,7 @@ private:
hist_viewp.pop_back();
htmlWindow->Scroll(ps);
} else {
//
//
wxPoint ps(0,0);
htmlWindow->Scroll(ps);
}