Ejemplo n.º 1
0
void wxsBitmapComboBox::OnBuildCreatingCode() {
int         i,n;
wxString    ss, tt, vv;
bool        ilist;

// we only handle C++ constructs here

    if (GetLanguage() != wxsCPP) wxsCodeMarks::Unknown(_T("wxsBitmapComboBox"),GetLanguage());

// header files

    AddHeader(_T("<wx/bmpcbox.h>"),GetInfo().ClassName,hfInPCH);

// the basic constructor

    vv = GetVarName();
    Codef(_T("%C(%W, %I, wxEmptyString, %P, %S, 0, NULL, %T, %V, %N);\n"));

// was a valid image-list specified?

    ilist = (wxsImageListEditorDlg::FindTool(this, mImageList) != NULL);

// add all text items, and the bitmaps at the bottom of the code
// bitmaps have to added after the wxsImages' and wxsImageList's were added
// note: first 2 items in mItems are used only in the dialog

    for(i=2; i<(int)mItems.GetCount(); ++i) {
        ss = mItems.Item(i);
        ParseComboItem(ss, tt, n);

// add the text item

        Codef(_T("%s->Append(_T(\"%s\"));\n"), vv.wx_str(), tt.wx_str());

// add the bitmap at the bottom of the code

        if ((ilist) && (n >= 0)) {
            tt.Printf(_T("%s->SetItemBitmap(%d, %s->GetBitmap(%d));\n"), vv.wx_str(), i-2, mImageList.wx_str(), n);
            AddEventCode(tt);
        };
    };

    AddEventCode(_T("\n"));

// finish setup

    BuildSetupWindowCode();

}
Ejemplo n.º 2
0
/*! \brief Create the initial control.
 *
 * \return void
 *
 */
void wxsTreeCtrl::OnBuildCreatingCode()
{
    int             i, n;
    int             iRed, iGreen, iBlue;
    wxsImageList   *ilist;
    int             iLevel, iImg1, iImg2, iImg3, iImg4;
    wxColor         colour;
    bool            bBold;
    wxString        sText;
    wxString        arrItems[32];
    wxString        sSource;
    wxString        sTop;
    wxString        sVarName;
    wxString        sItem;
    wxString        sPrevItem;


    switch(GetLanguage())
    {
        case wxsCPP:
            {
                AddHeader(_T("<wx/treectrl.h>"), GetInfo().ClassName, 0);
                AddHeader(_T("<wx/treectrl.h>"), _T("wxTreeEvent"), 0);
                Codef(_T("%C(%W, %I, %P, %S, %T, %V, %N);\n"));

                // assign the image-list -- AFTER the image list has been built
                sVarName = GetVarName();
                ilist = (wxsImageList *) wxsImageListEditorDlg::FindTool(this, m_sImageList);
                if(ilist != NULL)
                {
                    // Locator comment.
                    AddEventCode(wxString::Format(_("// Set the images for %s.\n"), sVarName.wx_str()));
                    sSource.Printf(_T("%s->SetImageList(%s);\n"), sVarName.wx_str(), m_sImageList.wx_str());
                    AddEventCode(sSource);
                }

                // and now each item in the tree data list
                sTop = wxEmptyString;
                arrItems[0] = wxEmptyString;
                n = 0;
                for(i = 2;i < (int)m_arrItems.GetCount();i++)
                {
                    // the string, broken into pieces
                    sSource = m_arrItems.Item(i);
                    wxsImageTreeEditorDlg::ParseTreeItem(sSource, iLevel, colour, bBold, iImg1, iImg2, iImg3, iImg4, sText);

                    // make a name for the new item
                    n += 1;
                    sItem.Printf(_("_Item%d"), n);
                    sItem = sVarName + sItem;

                    arrItems[iLevel] = sItem;

                    // there is a problem with wxTR_HIDE_ROOT and ScrollTo(root), so make sure that
                    // we only scroll to first shown item
                    if(i == 3)
                    {
                        sTop = sItem;
                    }

                    // ID of parent item
                    if(iLevel <= 0)
                    {
                        sPrevItem = wxEmptyString;
                    }
                    else
                    {
                        sPrevItem = arrItems[iLevel - 1];
                    }

                    // make the new item -- level 0 is the root item
                    if(iLevel <= 0)
                        Codef(_T("wxTreeItemId %s = %s->AddRoot(%n);\n"), sItem.wx_str(), sVarName.wx_str(), sText.wx_str());
                    else
                        Codef(_T("wxTreeItemId %s = %s->AppendItem(%s, %n);\n"), sItem.wx_str(), sVarName.wx_str(), sPrevItem.wx_str(), sText.wx_str());

                    // set text color of current item if not the default color of black
                    iRed = colour.Red();
                    iGreen = colour.Green();
                    iBlue = colour.Blue();
                    if((colour.IsOk()) && ((iRed + iGreen + iBlue) != 0))
                    {
                        sSource.Printf(_("%d,%d,%d"), iRed, iGreen, iBlue);
                        Codef(_T("%ASetItemTextColour(%s, wxColour(%s));\n"), sItem.wx_str(), sSource.wx_str());
                    }

                    if(bBold)
                    {
                        Codef(_T("%ASetItemBold(%s, true);\n"), sItem.wx_str());
                    }

                    // and the image-list indices
                    if(ilist != NULL)
                    {
                        if(iImg1 >= 0)
                        {
                            sSource.Printf(_T("%s->SetItemImage(%s, %d, wxTreeItemIcon_Normal);\n"), sVarName.wx_str(), sItem.wx_str(), iImg1);
                            AddEventCode(sSource);
                        }
                        if(iImg2 >= 0)
                        {
                            sSource.Printf(_T("%s->SetItemImage(%s, %d, wxTreeItemIcon_Selected);\n"), sVarName.wx_str(), sItem.wx_str(), iImg2);
                            AddEventCode(sSource);
                        }
                        if(iImg3 >= 0)
                        {
                            sSource.Printf(_T("%s->SetItemImage(%s, %d, wxTreeItemIcon_Expanded);\n"), sVarName.wx_str(), sItem.wx_str(), iImg3);
                            AddEventCode(sSource);
                        }
                        if(iImg4 >= 0)
                        {
                            sSource.Printf(_T("%s->SetItemImage(%s, %d, wxTreeItemIcon_SelectedExpanded);\n"), sVarName.wx_str(), sItem.wx_str(), iImg4);
                            AddEventCode(sSource);
                        }
                    }
                }

                // show everything
                if(m_bExpand)
                {
                    Codef(_T("%AExpandAll();\n"));
                }
                if(sTop.Length() > 0)
                {
                    Codef(_T("%AScrollTo(%s);\n"), sTop.wx_str());
                }

                BuildSetupWindowCode();
                return;
            }

        case wxsUnknownLanguage: // fall-through
        default:
            {
                wxsCodeMarks::Unknown(_T("wxsTreeCtrl::OnBuildCreatingCode"), GetLanguage());
            }
    }
}
Ejemplo n.º 3
0
void wxsImagePanel::OnBuildCreatingCode() {
wxString    vname;
wxString    iname;
wxsImage    *image;
wxString    tt;

// we only handle C++ constructs here

    if (GetLanguage() != wxsCPP) wxsCodeMarks::Unknown(_T("wxsImagePanel"),GetLanguage());

// who we are

    vname = GetVarName();

// get the image record, and the name of the bitmap associated with it

    image = (wxsImage *) wxsImageListEditorDlg::FindTool(this, mImage);

    if (image == NULL) {
        iname = wxEmptyString;
    }
    else {
        iname  = image->GetVarName();
        iname += _("_BMP");
    };

// include files

    AddHeader(_("\"wx/wxImagePanel.h\""), GetInfo().ClassName, 0);

// create the panel

    Codef(_T("%C(%W, %I, %P, %S, %T, %N);\n"));

// the stretching flag

    Codef(_T("%ASetStretch(%b);\n"), mStretch);

// the image has to be assigned to the panel AFTER the image is created
// since wxsImage is a wxsTool type, that all happens after the panel is created

    if (iname.Length() > 0) {
		// Locator comment.
		tt.Printf(_("// Set the bitmap for %s.\n"), vname.wx_str());
        AddEventCode(tt);

#if wxCHECK_VERSION(3, 0, 0)
        tt.Printf(_T("%s->SetBitmap(*%s);\n"), vname.wx_str(), iname.wx_str());
#else
        tt.Printf(_T("%s->SetBitmap(*%s);\n"), vname.c_str(), iname.c_str());
#endif
        AddEventCode(tt);
    }
    else
    {
        // if we can't find the image in wxsImage, we fallback to interpret it as a file path
        // some code snippet likes below:
        // wxBitmap bmp = wxBitmap(wxImage(_T("input.png")));
        // ImagePanel1->SetBitmap(bmp);
        wxString bmpFilename = vname + _T("_bmp");
        Codef(_T("wxBitmap %s = wxBitmap(wxImage((\"%s\")));\n"), bmpFilename.wx_str(), mImage.wx_str());
        Codef(_T("%ASetBitmap(%s);\n"), bmpFilename.wx_str());
    }

// do the rest of it

    BuildSetupWindowCode();

// add children

    AddChildrenCode();
}