Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
Close file tab on middle-click
DaKaLKa:
I started to look on the C::B-Code and want to add a feature.
I just want to add that middle-click on files-tabs close the file, so i made a
--- Code: ---m_pNotebook->Connect(wxEVT_MIDDLE_UP, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) &EditorManager::OnMouseMiddleNotebook);
--- End code ---
in the editormanager.cpp and add the OnMouseMiddleNotebook in EditorManager.
Everything was ok, but then i tried to implement the function, with this code
--- Code: ---void EditorManager::OnMouseMiddleNotebook(wxMouseEvent& event){
int index;
index = GetNotebook()->HitTest(event.GetPosition());
if(index != wxNOT_FOUND){
QueryClose(GetEditor(index));
}
}
--- End code ---
But when i run c::b and click on the file-tab, c::b crash.
I tried some modified code, but it seems, that "HitTest" crash.
I'm using wxWidget 2.6.2, MinGW (ported with c::b) and WinXP.
I'm just started using wxWidgets, is something wrong in my code?
Hope this is the right board to post such a message
See codeblocks.txt for stack dump.
Thx, DaKaLKa
[attachment deleted by admin]
thomas:
The function looks ok, even though it boldly assumes that all pointers returned are valid.
However, if you can see a file tab, then you can assume that there is a notebook, fair enough.
Have you tried writing index to the debug console?
Maybe HitTest returns garbage (off by one, possibly? Try opening 3 documents, and click on the middle one - if the wrong document closes, you know). If index is garbage, then GetEditor() returns a null pointer.
DaKaLKa:
I've changed my code to
--- Code: ---void EditorManager::OnMouseMiddleNotebook(wxMouseEvent& event){
int index;
wxPoint pt = event.GetPosition();
Manager::Get()->GetMessageManager()->DebugLog("X : %d Y : %d \n", pt.x,pt.y);
Manager::Get()->GetMessageManager()->DebugLog("Start HitTest!",index);
int pageNr = m_pNotebook->HitTest (pt);
Manager::Get()->GetMessageManager()->DebugLog("HitTest completed!",index);
return;
--- End code ---
But it seems, that there is a problem with HitTest, C::B crash just after "Start HitTest!" is printed in debug-log.
Very strange.
Has anybody an idea?
mandrav:
Try this:
--- Code: ---void EditorManager::OnMouseMiddleNotebook(wxMouseEvent& event){
int index;
wxPoint pt = event.GetPosition();
Manager::Get()->GetMessageManager()->DebugLog("X : %d Y : %d \n", pt.x,pt.y);
Manager::Get()->GetMessageManager()->DebugLog("Start HitTest!");
int pageNr = m_pNotebook->HitTest (pt);
Manager::Get()->GetMessageManager()->DebugLog("HitTest completed: %d",pageNr);
event.Skip();
--- End code ---
DaKaLKa:
Thanks, I've tried "event.Skip()", but it still crash :cry:
I even tried m_pNotebook->HitTest(wxPoint(0,0)), but it still crashed when calling HitTest.
Has somebody the same behaviour?
Thx,
Navigation
[0] Message Index
[#] Next page
Go to full version