Author Topic: Is HEAD missing way to get event SCIwindow ??  (Read 7604 times)

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2750
Is HEAD missing way to get event SCIwindow ??
« on: December 09, 2005, 02:42:45 am »
I have a question about the proper way to obtain a ptr to the cbStyledTextCtrl window.

In HEAD, when a plugin gets an EVT_EDITOR_CLOSE event, it cannot use GetBuiltinActiveEditor()
because the active editor is NOT the one being closed. Attempting to do so will crash C::B.

How should one get a ptr to SCIwindow from event.GetEditor() ??
class EditorBase has no GetControl() function.
RC2 had a event.GetEditor()->GetControl() call.

In the following hack, ...FindWindowByName("SCIwindow", event.GetEditor()) works, but is it
proper to do so??

Code
// ----------------------------------------------------------------------------
void cbDragScroll::OnEditorClose(CodeBlocksEvent& event)
// ----------------------------------------------------------------------------
{
    if (m_IsAttached)
     {
        // Get rid of our event handler
        //v1.RC2 wxFrame* thisEditor = (wxFrame*)event.GetEditor()->GetControl();

        wxWindow* thisWindow = event.GetEditor();

        //v1.RC3 alpha
        // Cannot use GetBuiltinActiveEditor() because the active Editor is NOT the
        // one being closed!!
        // wxWindow* thisEditor
        //  = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor()->GetControl();

        //find the cbStyledTextCtrl wxScintilla window
        wxWindow*
          thisEditor = thisWindow->FindWindowByName("SCIwindow", thisWindow);

        if ( (thisEditor) && (m_EditorPtrs.Index(thisEditor) != wxNOT_FOUND))


thanks
Pecan

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Is HEAD missing way to get event SCIwindow ??
« Reply #1 on: December 09, 2005, 09:48:38 am »
event.GetEditor() returns EditorBase* (up to RC2, it used to return cbEditor*).
So, try the following:
Code
cbEditor* ed = 0;
EditorBase* eb = event.GetEditor();
if (eb && eb->IsBuiltinEditor())
    ed = static_cast<cbEditor*>(eb);

if (ed)
{
    // ed->GetControl() should work now
    ...
}
Be patient!
This bug will be fixed soon...

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Is HEAD missing way to get event SCIwindow ??
« Reply #2 on: December 09, 2005, 04:23:25 pm »
BTW, what's the difference between static_cast<type*>(pointer) and (type*)(pointer) ? I never understood it.

takeshimiya

  • Guest
Re: Is HEAD missing way to get event SCIwindow ??
« Reply #3 on: December 09, 2005, 04:28:38 pm »
It is the same:

(type*)(pointer)  C way
static_cast<type*>(pointer)  C++ way

The C way works on the C++ way of course, but not the opposite.