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
m_pNotebook->Connect(wxEVT_MIDDLE_UP, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) &EditorManager::OnMouseMiddleNotebook);
in the editormanager.cpp and add the OnMouseMiddleNotebook in EditorManager.
Everything was ok, but then i tried to implement the function, with this code
void EditorManager::OnMouseMiddleNotebook(wxMouseEvent& event){
int index;
index = GetNotebook()->HitTest(event.GetPosition());
if(index != wxNOT_FOUND){
QueryClose(GetEditor(index));
}
}
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]
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.
I've changed my code to
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;
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?
Try this:
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();
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,
event.Skip() wasn't the only change. I hope you noticed it...
Ahh, i didn't notice them, but i just copy-and-paste your code so i also copied all your changes.
BTW, i played a little bit with the wxWidgets-Samples which also use wxNotebook, but every time i try to rum "HitTest", the sample crashes also.
After that I've build wxWidgets as debug-build and link the samples against it, but still the same problem and the stack-dump go deeply into the wxWidgets source-code.
So I think this is a wxWidget Bug, (or feature :D) Maybe I find something about it in the wxWidgets forums.
Thx for your effort.
I can't help you with your problem, but the future, you wan't to add, is included in my little plugin:
http://forums.next.codeblocks.org/index.php?topic=1005
Perphaps you find the solution for your problem in my code, or simply use my plugin :D
Just found your plugin some minutes ago and try to compile and use it - sounds good. :D