Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development

Is HEAD missing way to get event SCIwindow ??

(1/1)

Pecan:
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))


--- End code ---

thanks
Pecan

mandrav:
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
    ...
}

--- End code ---

rickg22:
BTW, what's the difference between static_cast<type*>(pointer) and (type*)(pointer) ? I never understood it.

takeshimiya:
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.

Navigation

[0] Message Index

Go to full version