Example #1
0
wxObject *wxListbookXmlHandler::DoCreateResource()
{
    if (m_class == wxT("listbookpage"))
    {
        wxXmlNode *n = GetParamNode(wxT("object"));

        if ( !n )
            n = GetParamNode(wxT("object_ref"));

        if (n)
        {
            bool old_ins = m_isInside;
            m_isInside = false;
            wxObject *item = CreateResFromNode(n, m_listbook, NULL);
            m_isInside = old_ins;
            wxWindow *wnd = wxDynamicCast(item, wxWindow);

            if (wnd)
            {
                m_listbook->AddPage(wnd, GetText(wxT("label")),
                                         GetBool(wxT("selected")));
                if ( HasParam(wxT("bitmap")) )
                {
                    wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
                    wxImageList *imgList = m_listbook->GetImageList();
                    if ( imgList == NULL )
                    {
                        imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
                        m_listbook->AssignImageList( imgList );
                    }
                    int imgIndex = imgList->Add(bmp);
                    m_listbook->SetPageImage(m_listbook->GetPageCount()-1, imgIndex );
                }
                else if ( HasParam(wxT("image")) )
                {
                    if ( m_listbook->GetImageList() )
                    {
                        m_listbook->SetPageImage(m_listbook->GetPageCount()-1,
                                                 GetLong(wxT("image")) );
                    }
                    else // image without image list?
                    {
                        ReportError(n, "image can only be used in conjunction "
                                       "with imagelist");
                    }
                }
            }
            else
            {
                ReportError(n, "listbookpage child must be a window");
            }
            return wnd;
        }
        else
        {
            ReportError("listbookpage must have a window child");
            return NULL;
        }
    }

    else
    {
        XRC_MAKE_INSTANCE(nb, wxListbook)

        nb->Create(m_parentAsWindow,
                   GetID(),
                   GetPosition(), GetSize(),
                   GetStyle(wxT("style")),
                   GetName());

        wxImageList *imagelist = GetImageList();
        if ( imagelist )
            nb->AssignImageList(imagelist);

        wxListbook *old_par = m_listbook;
        m_listbook = nb;
        bool old_ins = m_isInside;
        m_isInside = true;
        CreateChildren(m_listbook, true/*only this handler*/);
        m_isInside = old_ins;
        m_listbook = old_par;

        return nb;
    }
}
Example #2
0
bool SelectCommand::Apply(CommandExecutionContext context)
{
    wxString mode = GetString(wxT("Mode"));
    if (mode.IsSameAs(wxT("None")))
    {
        // select none
        context.proj->OnSelectNone();
    }
    else if (mode.IsSameAs(wxT("All")))
    {
        // select all
        context.proj->OnSelectAll();
    }
    else if (mode.IsSameAs(wxT("Range")))
    {
        // select range
        double t0 = GetDouble(wxT("StartTime"));
        double t1 = GetDouble(wxT("EndTime"));

        TrackList *tracks = context.proj->GetTracks();

        if (t0 < context.proj->GetTracks()->GetMinOffset())
        {
            Error(wxT("Start time is before start of track!"));
            return false;
        }
        if (t1 > context.proj->GetTracks()->GetEndTime())
        {
            Error(wxT("End time is after end of track!"));
            return false;
        }
        context.proj->mViewInfo.sel0 = t0;
        context.proj->mViewInfo.sel1 = t1;

        // select specified tracks
        long firstTrack = GetLong(wxT("FirstTrack"));
        long lastTrack = GetLong(wxT("LastTrack"));

        if (firstTrack < 0)
        {
            Error(wxT("Trying to select a negatively numbered track!"));
            return false;
        }
        if (lastTrack >= tracks->GetCount())
        {
            Error(wxT("Trying to select higher number track than exists!"));
            return false;
        }

        int index = 0;
        TrackListIterator iter(tracks);
        Track *t = iter.First();
        while (t) {
            bool sel = firstTrack <= index && index <= lastTrack;
            t->SetSelected(sel);

            if (sel)
                Status(wxT("Selected track '") + t->GetName() + wxT("'"));

            t = iter.Next();
            ++index;
        }
        wxASSERT(index >= lastTrack);
    }
    else if (mode.IsSameAs(wxT("Name")))
    {
        wxString name = GetString(wxT("TrackName"));
        TrackList *tracks = context.proj->GetTracks();
        TrackListIterator iter(tracks);
        Track *t = iter.First();
        while (t) {
            bool sel = t->GetName().IsSameAs(name);
            t->SetSelected(sel);

            if (sel)
                Status(wxT("Selected track '") + t->GetName() + wxT("'"));

            t = iter.Next();
        }
    }
    else
    {
        Error(wxT("Invalid selection mode!"));
        return false;
    }
    return true;
}
Example #3
0
std::string
JSONNode::ToString(const std::string &indent) const
{
    //char buf[1024];
    std::ostringstream ostr;
    if(type == JSONNULLVALUE)
        return "null";

    if(type == JSONBOOL)
        return GetBool() ? "true" : "false";

    if(type == JSONSTRING)
    {
        std::string str = "\"" + EscapeString(json.str) + "\"";
        return str;
    }

//    if(type == JSONINTEGER)
//    {
//        ostr << GetInt();
//        return ostr.str();
//    }
    if(type == JSONLONG)
    {
        ostr << GetLong();
        return ostr.str();
    }
//    if(type == JSONFLOAT)
//    {
//        ostr << GetFloat();
//        return ostr.str();
//    }
    if(type == JSONDOUBLE)
    {
        ostr << GetDouble();
        return ostr.str();
    }

    if(type == JSONARRAY)
    {
        std::string output = "[";
        for(size_t i = 0; i < json.array.size(); ++i)
        {
            output += json.array[i].ToString();

            if(i != json.array.size() - 1)
                output += ",";
        }
        output += "]";

        return output;
    }

    if(type == JSONOBJECT)
    {
        std::string output = "{";

        size_t index = 0;
        for(JSONObject::const_iterator itr = json.object.begin();
              itr != json.object.end(); ++itr)
        {
            std::string pair = "\"" + itr->first + "\"";
            pair += ":";
            pair += itr->second.ToString();

            output += pair;

            if(index != json.object.size() - 1)
                output += ",";

            ++index;
        }

        output += "}";
        return output;
    }

    /// default returns nothing..
    return "";
}
wxObject *wxBitmapComboBoxXmlHandler::DoCreateResource()
{
    if (m_class == wxT("ownerdrawnitem"))
    {
        if ( !m_combobox )
        {
            ReportError("ownerdrawnitem only allowed within a wxBitmapComboBox");
            return NULL;
        }

        m_combobox->Append(GetText(wxT("text")),
                           GetBitmap(wxT("bitmap")));

        return m_combobox;
    }
    else /*if( m_class == wxT("wxBitmapComboBox"))*/
    {
        // find the selection
        long selection = GetLong( wxT("selection"), -1 );

        XRC_MAKE_INSTANCE(control, wxBitmapComboBox)

        control->Create(m_parentAsWindow,
                        GetID(),
                        GetText(wxT("value")),
                        GetPosition(), GetSize(),
                        0,
                        NULL,
                        GetStyle(),
                        wxDefaultValidator,
                        GetName());

        m_isInside = true;
        m_combobox = control;

        wxXmlNode *children_node = GetParamNode(wxT("object"));

        wxXmlNode *n = children_node;

#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
        while (n)
        {
            if ((n->GetType() == wxXML_ELEMENT_NODE) &&
                (n->GetName() == wxT("object")))
            {
                CreateResFromNode(n, control, NULL);
            }
            n = n->GetNext();
        }

        m_isInside = false;
        m_combobox = NULL;

        if (selection != -1)
            control->SetSelection(selection);

        SetupWindow(control);

        return control;
    }
}
wxObject *wxTreebookXmlHandler::DoCreateResource()
{
    if (m_class == wxT("wxTreebook"))
    {
        XRC_MAKE_INSTANCE(tbk, wxTreebook)

        tbk->Create(m_parentAsWindow,
                    GetID(),
                    GetPosition(), GetSize(),
                    GetStyle(wxT("style")),
                    GetName());

        wxImageList *imagelist = GetImageList();
        if ( imagelist )
            tbk->AssignImageList(imagelist);

        wxTreebook * old_par = m_tbk;
        m_tbk = tbk;

        bool old_ins = m_isInside;
        m_isInside = true;

        wxArrayTbkPageIndexes old_treeContext = m_treeContext;
        m_treeContext.Clear();

        CreateChildren(m_tbk, true/*only this handler*/);

        m_treeContext = old_treeContext;
        m_isInside = old_ins;
        m_tbk = old_par;

        return tbk;
    }

//    else ( m_class == wxT("treebookpage") )
    wxXmlNode *n = GetParamNode(wxT("object"));
    wxWindow *wnd = NULL;

    if ( !n )
        n = GetParamNode(wxT("object_ref"));

    if (n)
    {
        bool old_ins = m_isInside;
        m_isInside = false;
        wxObject *item = CreateResFromNode(n, m_tbk, NULL);
        m_isInside = old_ins;
        wnd = wxDynamicCast(item, wxWindow);

        if (wnd == NULL && item != NULL)
        {
            ReportError(n, "treebookpage child must be a window");
        }
    }

    size_t depth = GetLong( wxT("depth") );

    if( depth <= m_treeContext.GetCount() )
    {
        // first prepare the icon
        int imgIndex = wxNOT_FOUND;
        if ( HasParam(wxT("bitmap")) )
        {
            wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
            wxImageList *imgList = m_tbk->GetImageList();
            if ( imgList == NULL )
            {
                imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
                m_tbk->AssignImageList( imgList );
            }
            imgIndex = imgList->Add(bmp);
        }
        else if ( HasParam(wxT("image")) )
        {
            if ( m_tbk->GetImageList() )
            {
                imgIndex = GetLong(wxT("image"));
            }
            else // image without image list?
            {
                ReportError(n, "image can only be used in conjunction "
                               "with imagelist");
            }
        }

        // then add the page to the corresponding parent
        if( depth < m_treeContext.GetCount() )
            m_treeContext.RemoveAt(depth, m_treeContext.GetCount() - depth );
        if( depth == 0)
        {
            m_tbk->AddPage(wnd,
                GetText(wxT("label")), GetBool(wxT("selected")), imgIndex);
        }
        else
        {
            m_tbk->InsertSubPage(m_treeContext.Item(depth - 1), wnd,
                GetText(wxT("label")), GetBool(wxT("selected")), imgIndex);
        }

        m_treeContext.Add( m_tbk->GetPageCount() - 1);

    }
    else
    {
        ReportParamError("depth", "invalid depth");
    }

    return wnd;
}
Example #6
0
float CEgIStream::GetFloat() {
	long v = GetLong();
	return *( (float*) &v );
}
bool SelectCommand::Apply(CommandExecutionContext context)
{
   wxString mode = GetString(wxT("Mode"));
   if (mode.IsSameAs(wxT("None")))
   {
      // select none
      context.GetProject()->OnSelectNone();
   }
   else if (mode.IsSameAs(wxT("All")))
   {
      // select all
      context.GetProject()->OnSelectAll();
   }
   else if (mode.IsSameAs(wxT("Range")))
   {
      // select range
      double t0 = GetDouble(wxT("StartTime"));
      double t1 = GetDouble(wxT("EndTime"));

      TrackList *tracks = context.GetProject()->GetTracks();

      if (t0 < context.GetProject()->GetTracks()->GetMinOffset())
      {
         Error(wxT("Start time is before start of track!"));
         return false;
      }
      if (t1 > context.GetProject()->GetTracks()->GetEndTime())
      {
         Error(wxT("End time is after end of track!"));
         return false;
      }

      // PRL: to do: only setting time boundaries of current selection.
      // Should other fields be left alone, or rather
      // defaulted, as in the second branch?
      // Or should this command take more parameters?
#if 1
      context.GetProject()->mViewInfo.selectedRegion.setTimes(t0, t1);
#else
      context.GetProject()->mViewInfo.selectedRegion = SelectedRegion(t0, t1);
#endif

      // select specified tracks
      long firstTrack = GetLong(wxT("FirstTrack"));
      long lastTrack = GetLong(wxT("LastTrack"));

      if (firstTrack < 0)
      {
         Error(wxT("Trying to select a negatively numbered track!"));
         return false;
      }
      if (lastTrack >= tracks->GetCount())
      {
         Error(wxT("Trying to select higher number track than exists!"));
         return false;
      }

      int index = 0;
      TrackListIterator iter(tracks);
      Track *t = iter.First();
      while (t) {
         bool sel = firstTrack <= index && index <= lastTrack;
         t->SetSelected(sel);

         if (sel)
            Status(wxT("Selected track '") + t->GetName() + wxT("'"));

         t = iter.Next();
         ++index;
      }
      wxASSERT(index >= lastTrack);
   }
   else if (mode.IsSameAs(wxT("Name")))
   {
      wxString name = GetString(wxT("TrackName"));
      TrackList *tracks = context.GetProject()->GetTracks();
      TrackListIterator iter(tracks);
      Track *t = iter.First();
      while (t) {
         bool sel = t->GetName().IsSameAs(name);
         t->SetSelected(sel);

         if (sel)
            Status(wxT("Selected track '") + t->GetName() + wxT("'"));

         t = iter.Next();
      }
   }
   else
   {
      Error(wxT("Invalid selection mode!"));
      return false;
   }
   return true;
}
Example #8
0
wxSizer*  wxSizerXmlHandler::Handle_wxGridSizer()
{
    return new wxGridSizer(GetLong(wxT("rows")), GetLong(wxT("cols")),
                           GetDimension(wxT("vgap")), GetDimension(wxT("hgap")));
}
Example #9
0
wxObject *CGRadioBox::DoCreateResource()
{
    if ( m_class == wxT("wxRadioBox"))
    {
        // find the selection
        long selection = GetLong( wxT("selection"), -1 );

        // need to build the list of strings from children
        m_insideBox = true;
        CreateChildrenPrivately( NULL, GetParamNode(wxT("content")));

        wxString *strings;
        if ( !labels.empty() )
        {
            strings = new wxString[labels.size()];
            const unsigned count = labels.size();
            for( unsigned i = 0; i < count; i++ )
                strings[i] = labels[i];
        }
        else
        {
            strings = NULL;
        }

        XRC_MAKE_INSTANCE(control, wxRadioBox)

        control->Create(m_parentAsWindow,
                        GetID(),
                        GetText(wxT("label")),
                        GetPosition(), GetSize(),
                        labels.size(),
                        strings,
                        GetLong(wxT("dimension"), 1),
                        GetStyle(),
                        wxDefaultValidator,
                        GetName());

        delete[] strings;

        if (selection != -1)
            control->SetSelection(selection);

        SetupWindow(control);

        const unsigned count = labels.size();
        for( unsigned i = 0; i < count; i++ )
        {

            if ( !tooltips[i].empty() )
                control->SetItemToolTip(i, tooltips[i]);


            if ( helptextSpecified[i] )
                control->SetItemHelpText(i, helptexts[i]);

        }

        labels.clear();    // dump the strings

        tooltips.clear();    // dump the tooltips

        helptexts.clear();   // dump the helptexts
        helptextSpecified.clear();

        return control;
    }
    else // inside the radiobox element
    {
        // we handle handle <item tooltip="..." helptext="...">Label</item> constructs here

        wxString str = GetNodeContent(m_node);

        wxString tooltip;
        m_node->GetAttribute(wxT("tooltip"), &tooltip);

        wxString helptext;
        bool hasHelptext = m_node->GetAttribute(wxT("helptext"), &helptext);

        if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
        {
            str = wxGetTranslation(str, m_resource->GetDomain());
            if ( !tooltip.empty() )
                tooltip = wxGetTranslation(tooltip, m_resource->GetDomain());
            if ( hasHelptext )
                helptext = wxGetTranslation(helptext, m_resource->GetDomain());
        }

        labels.push_back(str);
        tooltips.push_back(tooltip);
        helptexts.push_back(helptext);
        helptextSpecified.push_back(hasHelptext);

        return NULL;
    }

}
Example #10
0
wxObject *wxToolBarAddOnXmlHandler::DoCreateResource()
{
    wxToolBar* toolbar=NULL;
    if (m_class == _T("tool"))
    {
        wxCHECK_MSG(m_toolbar, NULL, _("Incorrect syntax of XRC resource: tool not within a toolbar!"));

        wxSize bitmapSize = m_toolbar->GetToolBitmapSize();

        if (GetPosition() != wxDefaultPosition)
        {
            m_toolbar->AddTool(GetID(),
            #if wxCHECK_VERSION(2, 9, 0)
                               wxEmptyString,
            #endif
                               GetCenteredBitmap(_T("bitmap"), wxART_TOOLBAR, bitmapSize),
                               GetCenteredBitmap(_T("bitmap2"), wxART_TOOLBAR, bitmapSize),
            #if !wxCHECK_VERSION(2, 9, 0)
                               GetBool(_T("toggle")),
                               GetPosition().x,
                               GetPosition().y,
                               NULL,
            #else
                               wxITEM_NORMAL,
            #endif
                               GetText(_T("tooltip")),
                               GetText(_T("longhelp")));
           if (GetBool(_T("disabled")))
           {
               m_toolbar->Realize();
               m_toolbar->EnableTool(GetID(),false);
           }
        }
        else
        {
            wxItemKind kind = wxITEM_NORMAL;
            if (GetBool(_T("radio")))
                kind = wxITEM_RADIO;
            if (GetBool(_T("toggle")))
            {
                wxASSERT_MSG( kind == wxITEM_NORMAL,
                              _("can't have both toggleable and radion button at once") );
                kind = wxITEM_CHECK;
            }
            m_toolbar->AddTool(GetID(),
                               GetText(_T("label")),
                               GetCenteredBitmap(_T("bitmap"), wxART_TOOLBAR, bitmapSize),
                               GetCenteredBitmap(_T("bitmap2"), wxART_TOOLBAR, bitmapSize),
                               kind,
                               GetText(_T("tooltip")),
                               GetText(_T("longhelp")));
           if (GetBool(_T("disabled")))
           {
               m_toolbar->Realize();
               m_toolbar->EnableTool(GetID(),false);
           }
        }
        return m_toolbar; // must return non-NULL
    }

    else if (m_class == _T("separator"))
    {
        wxCHECK_MSG(m_toolbar, NULL, _("Incorrect syntax of XRC resource: separator not within a toolbar!"));
        m_toolbar->AddSeparator();
        return m_toolbar; // must return non-NULL
    }

    else /*<object class="wxToolBar">*/
    {
        m_isAddon=(m_class == _T("wxToolBarAddOn"));
        if(m_isAddon)
        { // special case: Only add items to toolbar
          toolbar=(wxToolBar*)m_instance;
          // XRC_MAKE_INSTANCE(toolbar, wxToolBar);
        }
        else
        {
            int style = GetStyle(_T("style"), wxNO_BORDER | wxTB_HORIZONTAL);
            #ifdef __WXMSW__
            if (!(style & wxNO_BORDER)) style |= wxNO_BORDER;
            #endif

            XRC_MAKE_INSTANCE(toolbar, wxToolBar)

            toolbar->Create(m_parentAsWindow,
                             GetID(),
                             GetPosition(),
                             GetSize(),
                             style,
                             GetName());
            wxSize bmpsize = GetSize(_T("bitmapsize"));
            if (!(bmpsize == wxDefaultSize))
                toolbar->SetToolBitmapSize(bmpsize);
            wxSize margins = GetSize(_T("margins"));
            if (!(margins == wxDefaultSize))
                toolbar->SetMargins(margins.x, margins.y);
            long packing = GetLong(_T("packing"), -1);
            if (packing != -1)
                toolbar->SetToolPacking(packing);
            long separation = GetLong(_T("separation"), -1);
            if (separation != -1)
                toolbar->SetToolSeparation(separation);
        }

        wxXmlNode *children_node = GetParamNode(_T("object"));
        if (!children_node)
           children_node = GetParamNode(_T("object_ref"));

        if (children_node == NULL) return toolbar;

        m_isInside = TRUE;
        m_toolbar = toolbar;

        wxXmlNode *n = children_node;

        while (n)
        {
            if ((n->GetType() == wxXML_ELEMENT_NODE) &&
                (n->GetName() == _T("object") || n->GetName() == _T("object_ref")))
            {
                wxObject *created = CreateResFromNode(n, toolbar, NULL);
                wxControl *control = wxDynamicCast(created, wxControl);
                if (!IsOfClass(n, _T("tool")) &&
                    !IsOfClass(n, _T("separator")) &&
                    control != NULL &&
                    control != toolbar)
                {
                    wxLogDebug(_T("control=%p, parent=%p, toolbar=%p"), control, control->GetParent(), toolbar);
                    toolbar->AddControl(control);
                }
            }
            n = n->GetNext();
        }

        toolbar->Realize();

        m_isInside = FALSE;
        m_toolbar = NULL;

        if(!m_isAddon)
        {
            if (m_parentAsWindow && !GetBool(_T("dontattachtoframe")))
            {
                wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
                if (parentFrame)
                    parentFrame->SetToolBar(toolbar);
            }
        }
        m_isAddon=false;
        return toolbar;
    }
}
Example #11
0
BOOL TRegistry::GetInt(LPCSTR subKey, int *val)
{
	return	GetLong(subKey, (long *)val);
}
Example #12
0
wxObject *wxAuiToolBarXmlHandler::DoCreateResource()
{
    wxAuiToolBar* toolbar=NULL;

    if (m_class == _T("tool"))
    {
        wxCHECK_MSG(m_toolbar, NULL, _("Incorrect syntax of XRC resource: tool not within a toolbar!"));

        wxSize bitmapSize = m_toolbar->GetToolBitmapSize();

        if (GetPosition() != wxDefaultPosition)
        {
            m_toolbar->AddTool(GetID(),
                               GetCenteredBitmap(_T("bitmap"), wxART_OTHER, wxSize(16,16)),
                               NULL, //GetCenteredBitmap(_T("bitmap2"), wxART_TOOLBAR, bitmapSize),
                               GetBool(_T("toggle")),
                               NULL,
                               GetText(_T("tooltip")),
                               GetText(_T("longhelp")));

           if (GetBool(_T("disabled")))
           {
               m_toolbar->Realize();
               m_toolbar->EnableTool(GetID(),false);
           }
        }
        else
        {
            wxItemKind kind = wxITEM_NORMAL;
            if (GetBool(_T("radio")))
                kind = wxITEM_RADIO;
            if (GetBool(_T("toggle")))
            {
                wxASSERT_MSG( kind == wxITEM_NORMAL,
                              _("can't have both toggleable and radion button at once") );
                kind = wxITEM_CHECK;
            }

            m_toolbar->AddTool(GetID(),
                               GetText(_T("label")),
                               GetCenteredBitmap(_T("bitmap"), wxART_OTHER, bitmapSize),
                               GetCenteredBitmap(_T("bitmap2"), wxART_OTHER, bitmapSize),
                               kind,
                               GetText(_T("tooltip")),
                               GetText(_T("longhelp")));

           if (GetBool(_T("disabled")))
           {
               m_toolbar->Realize();
               m_toolbar->EnableTool(GetID(),false);
           }
        }
        return m_toolbar; // must return non-NULL
    }

    else if (m_class == _T("overflow_tool"))
    {
        wxCHECK_MSG(m_toolbar, NULL, _("Incorrect syntax of XRC resource: tool not within a toolbar!"));

        wxSize bitmapSize = m_toolbar->GetToolBitmapSize();

        wxItemKind kind = wxITEM_NORMAL;
        if (GetBool(_T("radio")))
                kind = wxITEM_RADIO;
        if (GetBool(_T("toggle")))
        {
                wxASSERT_MSG( kind == wxITEM_NORMAL,
                              _("can't have both toggleable and radion button at once") );
                kind = wxITEM_CHECK;
        }
        if (GetBool(_T("separator")))
            kind = wxITEM_SEPARATOR;

        m_toolbar->AddOverflowTool(GetID(),
                               GetText(_T("label")),
                               GetCenteredBitmap(_T("bitmap"), wxART_OTHER, bitmapSize),
                               GetText(_T("longhelp")),
                               kind,
                               GetBool(_T("prepend"),0)   );

        if (GetBool(_T("disabled")))
        {
               m_toolbar->Realize();
               m_toolbar->EnableTool(GetID(),false);
        }

        return m_toolbar; // must return non-NULL
    }

    else if (m_class == _T("separator"))
    {
        wxCHECK_MSG(m_toolbar, NULL, _("Incorrect syntax of XRC resource: separator not within a toolbar!"));
        m_toolbar->AddSeparator();
        return m_toolbar; // must return non-NULL
    }

    else /*<object class="wxAuiToolBar">*/
    {
        toolbar=(wxAuiToolBar*)m_instance;
        if(!toolbar && (m_class == _T("wxToolBarAddOn")))
        {
           toolbar = new wxAuiToolBar(m_parentAsWindow, -1, wxDefaultPosition, wxDefaultSize);
           m_instance = (wxObject *)toolbar;
        }

            long style = GetStyle(_T("style"), -1);
            if (style!=-1)
                toolbar->SetWindowStyle(style);

            style = GetStyle(_T("add_style"), -1);
            if (style!=-1)
                toolbar->SetWindowStyle(toolbar->GetWindowStyle() | style);

            style = GetStyle(_T("remove_style"), -1);
            if (style!=-1)
                toolbar->SetWindowStyle(toolbar->GetWindowStyle() & ~style);

            wxSize bmpsize = GetSize(_T("bitmapsize"));
            // First find the generic bitmap size
            if (!(bmpsize == wxDefaultSize))
                toolbar->SetToolBitmapSize(bmpsize);
            else
            {
                // if no generic size then find the platform dependent size
                #ifdef __WXMSW__
                    bmpsize = GetSize(_T("bitmapsize_win"));
                #endif
                #ifdef __WXMAC__
                    bmpsize = GetSize(_T("bitmapsize_mac"));
                #endif
                #ifdef __WXGTK__
                    bmpsize = GetSize(_T("bitmapsize_unix"));
                #endif

                if (!(bmpsize == wxDefaultSize))
                    toolbar->SetToolBitmapSize(bmpsize);
            }

            wxSize margins = GetSize(_T("margins"));
            if (!(margins == wxDefaultSize))
                toolbar->SetMargins(margins.x, margins.y);
            long packing = GetLong(_T("packing"), -1);
            if (packing != -1)
                toolbar->SetToolPacking(packing);
            long separation = GetLong(_T("separation"), -1);
            if (separation != -1)
                toolbar->SetToolSeparation(separation);

        wxXmlNode *children_node = GetParamNode(_T("object"));
        if (!children_node)
           children_node = GetParamNode(_T("object_ref"));

        if (children_node == NULL) return toolbar;

        m_isInside = TRUE;
        m_toolbar = toolbar;

        wxXmlNode *n = children_node;

        while (n)
        {
            if ((n->GetType() == wxXML_ELEMENT_NODE) &&
                (n->GetName() == _T("object") || n->GetName() == _T("object_ref")))
            {
                wxObject *created = CreateResFromNode(n, toolbar, NULL);
                wxControl *control = wxDynamicCast(created, wxControl);
                if (!IsOfClass(n, _T("tool")) &&
                    !IsOfClass(n, _T("separator")) &&
                    control != NULL &&
                    control != toolbar)
                {
                    //Manager::Get()->GetLogManager()->DebugLog(F(_T("control=%p, parent=%p, toolbar=%p"), control, control->GetParent(), toolbar));
                    toolbar->AddControl(control);
                }
            }
            n = n->GetNext();
        }
        toolbar->Realize();
        m_isInside = FALSE;
        m_toolbar = NULL;
        m_isAddon=false;
        return toolbar;
    }
}
Example #13
0
bool WayOrderList::ParseNode(const TiXmlNode * node, Player * player, Game *game)
{
	const TiXmlNode * child1;
	const TiXmlNode * child2;

	WayOrder * wo;
	Location * loc;
	bool fmo;
	Player * player2;
	long speed;

	nPlayer = player->GetID();
	// don't verify the fleet, it might not yet exist
	if (nFleet <= 0 || nFleet > Rules::MaxFleets) {
		Message * mess = player->AddMessage("Error: invalid fleet number");
		mess->AddLong("Waypoint order", nFleet);
		nFleet = 0;
		return true;
	}

	for (child1 = node->FirstChild("Waypoint"); child1; child1 = child1->NextSibling("Waypoint")) {
		wo = NULL;
		loc = NULL;
		fmo = false;
		speed = 0;
		unsigned long pnum = GetLong(child1->FirstChild("Player"));
		if (pnum < 0 || pnum > game->NumberPlayers()) {
			Message * mess = player->AddMessage("Error: invalid player number");
			mess->AddLong("", pnum);
			mess->AddItem("Where", "Fleet destination");
			continue;
		}
		player2 = game->NCGetPlayer(pnum);

		for (child2 = child1->FirstChild(); child2; child2 = child2->NextSibling()) {
			if (child2->Type() == TiXmlNode::COMMENT)
				continue;

			if (stricmp(child2->Value(), "Location") == 0) {
				if (loc != NULL)
					continue;

				Location * nl = new Location();
				if (!nl->ParseNode(child2, game)) {
					delete nl;
					continue;
				}
				loc = nl;
				fmo = true;
			} else if (stricmp(child2->Value(), "Planet") == 0) {
				if (loc != NULL)
					continue;

				Planet * planet = game->GetGalaxy()->GetPlanet(GetString(child2));
				if (!planet) {
					Message * mess = player->AddMessage("Error: invalid planet");
					mess->AddItem("", GetString(child2));
					mess->AddItem("Where", "Waypoint order");
					continue;
				}
				loc = planet;
			} else if (stricmp(child2->Value(), "Minefield") == 0) {
				if (loc != NULL)
					continue;

				///@todo add after mines are added
			} else if (stricmp(child2->Value(), "Scrap") == 0) {
				if (loc != NULL)
					continue;

				long l = GetLong(child2);
				Salvage * salvage = game->GetGalaxy()->GetSalvage(l);
				if (!salvage || !salvage->SeenBy(player)) {
					Message * mess = player->AddMessage("Error: invalid salvage pile");
					mess->AddLong("Waypoint order", l);
					continue;
				}
				loc = salvage;
			} else if (stricmp(child2->Value(), "Packet") == 0) {
				if (loc != NULL)
					continue;

				///@todo add after packets are added
			} else if (stricmp(child2->Value(), "Trader") == 0) {
				if (loc != NULL)
					continue;

				///@todo add after Mystery Traders are added
			} else if (stricmp(child2->Value(), "Fleet") == 0) {
				if (loc != NULL)
					continue;

				if (player2 == player) {
					loc = new TempFleet(game, GetLong(child2), player);
					fmo = true;
				} else {
					Fleet * f2 = player2->NCGetFleet(GetLong(child2));
					if (!f2 || !f2->SeenBy(player)) {
						Message * mess = player->AddMessage("Error: invalid fleet number");
						mess->AddLong("Waypoint order", GetLong(child2));
						continue;
					}

					loc = f2;
//					f2->AddChaser(nPlayer, nFleet);
//					chasing.push_back(f2);
				}
			} else if (stricmp(child2->Value(), "Speed") == 0) {
				speed = GetLong(child2);
				if (speed < -1 || speed > Rules::GetConstant("MaxSpeed")) {
					Message * mess = player->AddMessage("Error: invalid speed");
					mess->AddLong("Waypoint order", speed);
					continue;
				}
			} else if (stricmp(child2->Value(), "Order") == 0) {
				if (loc == NULL)
					continue;

				const TiXmlNode * child3;
				child3 = child2->FirstChild();
				while (child3->Type() == TiXmlNode::COMMENT)
					child3 = child3->NextSibling();

				if (strnicmp(child3->Value(), "No Task", 7) == 0) {
					wo = new WayOrder(loc, fmo);
					wo->mOrder = OT_NONE;
				} else if (strnicmp(child3->Value(), "Colonize", 8) == 0) {
					wo = new WayOrder(loc, fmo);
					wo->mOrder = OT_COLONIZE;
				} else if (strnicmp(child3->Value(), "Remote Mine", 11) == 0) {
					wo = new WayOrder(loc, fmo);
					wo->mOrder = OT_REMOTEMINE;
				} else if (strnicmp(child3->Value(), "Scrap", 5) == 0) {
					wo = new WayOrder(loc, fmo);
					wo->mOrder = OT_SCRAP;
				} else if (strnicmp(child3->Value(), "Route", 5) == 0) {
					wo = new WayOrder(loc, fmo);
					wo->mOrder = OT_ROUTE;
				} else if (strnicmp(child3->Value(), "Merge", 5) == 0) {
					unsigned long num = (unsigned long)GetLong(child3);
					if (num > Rules::MaxFleets) {
						Message * mess = player->AddMessage("Error: invalid fleet number");
						mess->AddLong("Waypoint order", num);
						continue;
					}

					wo = new WayOrderNumber(num, loc, fmo);
					wo->mOrder = OT_MERGE;
				} else if (strnicmp(child3->Value(), "LayMine", 7) == 0) {
					long num = GetLong(child3);
					if (num < -1 || num == 0) {
						Message * mess = player->AddMessage("Error: invalid number of years");
						mess->AddLong("Waypoint order", num);
						continue;
					}

					wo = new WayOrderNumber(num, loc, fmo);
					wo->mOrder = OT_LAYMINE;
				} else if (strnicmp(child3->Value(), "Transfer", 8) == 0) {
					unsigned long num = GetLong(child3);
					if (num < 0 || num > game->NumberPlayers()) {
						Message * mess = player->AddMessage("Error: invalid player number");
						mess->AddLong("", num);
						mess->AddItem("Where", "Waypoint order");
						continue;
					}

					wo = new WayOrderNumber(num, loc, fmo);
					wo->mOrder = OT_TRANSFER;
				} else if (strnicmp(child3->Value(), "Patrol", 6) == 0) {
					long s = GetLong(child3->FirstChild("Speed"));
					if (s < 0 || s > Rules::GetConstant("MaxSpeed")) {
						Message * mess = player->AddMessage("Error: invalid speed");
						mess->AddLong("Waypoint order", s);
						continue;
					}

					long r = GetLong(child3->FirstChild("Range"));
					if (r <= 0) {
						Message * mess = player->AddMessage("Error: invalid range");
						mess->AddLong("Waypoint order", r);
						continue;
					}

					wo = new WayOrderPatrol(s, r, loc, fmo);
					wo->mOrder = OT_PATROL;
				} else if (strnicmp(child3->Value(), "Transport", 9) == 0) {
					WayOrderTransport * wot;
					wot = new WayOrderTransport(loc, fmo);
					if (!wot->ParseNode(child3, player))
						continue;

					wo = wot;
					wo->mOrder = OT_TRANSPORT;
				}
			} else {
				Message * mess = player->AddMessage("Warning: Unknown type");
				mess->AddItem("Waypoint order", child2->Value());
				continue;
			}
		}

		if (wo != NULL) {
			wo->mSpeed = speed;
			orders.push_back(wo);
		} else if (fmo && loc) {
			delete loc;
		}
	}

	return true;
}
Example #14
0
long OdbcStatement::GetLong(unsigned int column)
{
  long val = 0;
  GetLong(column, &val);
  return val;
}
Example #15
0
wxObject * MaxSplitterWindowXmlHandler::DoCreateResource()
{
    XRC_MAKE_INSTANCE(splitter, MaxSplitterWindow);

    splitter->Create(m_parentAsWindow,
                     GetID(),
                     GetPosition(), GetSize(),
                     GetStyle(wxT("style"), wxSP_3D),
                     GetName());

	splitter->MaxBind(CB_PREF(wx_wxsplitterwindow_wxSplitterWindow__xrcNew)(splitter));

    SetupWindow(splitter);

    long sashpos = GetLong(wxT("sashpos"), 0);
    long minpanesize = GetLong(wxT("minsize"), -1);
    float gravity = GetFloat(wxT("gravity"), 0.0);
    if (minpanesize != -1)
        splitter->SetMinimumPaneSize(minpanesize);
    if (gravity != 0.0)
        splitter->SetSashGravity(gravity);

    wxWindow *win1 = NULL, *win2 = NULL;
    wxXmlNode *n = m_node->GetChildren();
    while (n)
    {
        if ((n->GetType() == wxXML_ELEMENT_NODE) &&
            (n->GetName() == wxT("object") ||
             n->GetName() == wxT("object_ref")))
        {
            wxObject *created = CreateResFromNode(n, splitter, NULL);
            wxWindow *win = wxDynamicCast(created, wxWindow);
            if (win1 == NULL)
            {
                win1 = win;
            }
            else
            {
                win2 = win;
                break;
            }
        }
        n = n->GetNext();
    }

    if (win1 == NULL)
        wxLogError(wxT("wxSplitterWindow node must contain at least one window."));

    bool horizontal = (GetParamValue(wxT("orientation")) != wxT("vertical"));
    if (win1 && win2)
    {
        if (horizontal)
            splitter->SplitHorizontally(win1, win2, sashpos);
        else
            splitter->SplitVertically(win1, win2, sashpos);
    }
    else
    {
        splitter->Initialize(win1);
    }

    return splitter;

}
Example #16
0
wxObject *wxRadioBoxXmlHandler::DoCreateResource()
{
    if ( m_class == wxT("wxRadioBox"))
    {
        // find the selection
        long selection = GetLong( wxT("selection"), -1 );

        // need to build the list of strings from children
        m_insideBox = true;
        CreateChildrenPrivately( NULL, GetParamNode(wxT("content")));

        XRC_MAKE_INSTANCE(control, wxRadioBox)

        control->Create(m_parentAsWindow,
                        GetID(),
                        GetText(wxT("label")),
                        GetPosition(), GetSize(),
                        m_labels,
                        GetLong(wxT("dimension"), 1),
                        GetStyle(),
                        wxDefaultValidator,
                        GetName());

        if (selection != -1)
            control->SetSelection(selection);

        SetupWindow(control);

        const unsigned count = m_labels.size();
        for( unsigned i = 0; i < count; i++ )
        {
#if wxUSE_TOOLTIPS
            if ( !m_tooltips[i].empty() )
                control->SetItemToolTip(i, m_tooltips[i]);
#endif // wxUSE_TOOLTIPS
#if wxUSE_HELP
            if ( m_helptextSpecified[i] )
                control->SetItemHelpText(i, m_helptexts[i]);
#endif // wxUSE_HELP

            if ( !m_isShown[i] )
                control->Show(i, false);
            if ( !m_isEnabled[i] )
                control->Enable(i, false);
        }


        // forget information about the items of this radiobox, we should start
        // afresh for the next one
        m_labels.clear();

#if wxUSE_TOOLTIPS
        m_tooltips.clear();
#endif // wxUSE_TOOLTIPS

#if wxUSE_HELP
        m_helptexts.clear();
        m_helptextSpecified.clear();
#endif // wxUSE_HELP

        m_isShown.clear();
        m_isEnabled.clear();

        return control;
    }
    else // inside the radiobox element
    {
        // we handle handle <item>Label</item> constructs here, and the item
        // tag can have tooltip, helptext, enabled and hidden attributes

        wxString label = GetNodeContent(m_node);

        wxString tooltip;
        m_node->GetAttribute(wxT("tooltip"), &tooltip);

        wxString helptext;
        bool hasHelptext = m_node->GetAttribute(wxT("helptext"), &helptext);

        if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
        {
            label = wxGetTranslation(label, m_resource->GetDomain());
            if ( !tooltip.empty() )
                tooltip = wxGetTranslation(tooltip, m_resource->GetDomain());
            if ( hasHelptext )
                helptext = wxGetTranslation(helptext, m_resource->GetDomain());
        }

        m_labels.push_back(label);
#if wxUSE_TOOLTIPS
        m_tooltips.push_back(tooltip);
#endif // wxUSE_TOOLTIPS
#if wxUSE_HELP
        m_helptexts.push_back(helptext);
        m_helptextSpecified.push_back(hasHelptext);
#endif // wxUSE_HELP
        m_isEnabled.push_back(GetBoolAttr("enabled", 1));
        m_isShown.push_back(!GetBoolAttr("hidden", 0));

        return NULL;
    }

}
Example #17
0
wxObject *wxStatusBarXmlHandler::DoCreateResource()
{
    XRC_MAKE_INSTANCE(statbar, wxStatusBar)

    statbar->Create(m_parentAsWindow,
                    GetID(),
                    GetStyle(),
                    GetName());

    int fields = GetLong(wxT("fields"), 1);
    wxString widths = GetParamValue(wxT("widths"));
    wxString styles = GetParamValue(wxT("styles"));

    if (fields > 1 && !widths.IsEmpty())
    {
        int *width = new int[fields];

        for (int i = 0; i < fields; ++i)
        {
            width[i] = wxAtoi(widths.BeforeFirst(wxT(',')));
            if(widths.Find(wxT(',')))
                widths.Remove(0, widths.Find(wxT(',')) + 1);
        }
        statbar->SetFieldsCount(fields, width);
        delete[] width;
    }
    else
        statbar->SetFieldsCount(fields);

    if (!styles.empty())
    {
        int *style = new int[fields];
        for (int i = 0; i < fields; ++i)
        {
            style[i] = wxSB_NORMAL;

            wxString first = styles.BeforeFirst(wxT(','));
            if (first == wxT("wxSB_NORMAL"))
                style[i] = wxSB_NORMAL;
            else if (first == wxT("wxSB_FLAT"))
                style[i] = wxSB_FLAT;
            else if (first == wxT("wxSB_RAISED"))
                style[i] = wxSB_RAISED;
            else if (!first.empty())
            {
                ReportParamError
                (
                    "styles",
                    wxString::Format
                    (
                        "unknown status bar field style \"%s\"",
                        first
                    )
                );
            }

            if(styles.Find(wxT(',')))
                styles.Remove(0, styles.Find(wxT(',')) + 1);
        }
        statbar->SetStatusStyles(fields, style);
        delete [] style;
    }

    CreateChildren(statbar);

    if (m_parentAsWindow)
    {
        wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
        if (parentFrame)
            parentFrame->SetStatusBar(statbar);
    }

    return statbar;
}
Example #18
0
wxObject *wxToolBarXmlHandlerEx::DoCreateResource()
{
	if (m_class == wxT("tool"))
	{
		wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: tool not within a toolbar!"));

		if (GetPosition() != wxDefaultPosition)
		{
			m_toolbar->AddTool(GetID(),
							   GetBitmap(wxT("bitmap"), wxART_TOOLBAR),
							   GetBitmap(wxT("bitmap2"), wxART_TOOLBAR),
							   GetBool(wxT("toggle")),
							   GetPosition().x,
							   GetPosition().y,
							   NULL,
							   GetText(wxT("tooltip")),
							   GetText(wxT("longhelp")));
		}
		else
		{
			wxItemKind kind = wxITEM_NORMAL;
			if (GetBool(wxT("radio")))
				kind = wxITEM_RADIO;
			if (GetBool(wxT("toggle")))
			{
				wxASSERT_MSG( kind == wxITEM_NORMAL,
							  _T("can't have both toggleable and radion button at once") );
				kind = wxITEM_CHECK;
			}
			m_toolbar->AddTool(GetID(),
							   GetText(wxT("label")),
							   GetBitmap(wxT("bitmap"), wxART_TOOLBAR, m_iconSize),
							   GetBitmap(wxT("bitmap2"), wxART_TOOLBAR, m_iconSize),
							   kind,
							   GetText(wxT("tooltip")),
							   GetText(wxT("longhelp")));

			if ( GetBool(wxT("disabled")) )
				m_toolbar->EnableTool(GetID(), false);
		}
		return m_toolbar; // must return non-NULL
	}

	else if (m_class == wxT("separator"))
	{
		wxCHECK_MSG(m_toolbar, NULL, wxT("Incorrect syntax of XRC resource: separator not within a toolbar!"));
		m_toolbar->AddSeparator();
		return m_toolbar; // must return non-NULL
	}

	else /*<object class="wxToolBar">*/
	{
		int style = GetStyle(wxT("style"), wxNO_BORDER | wxTB_HORIZONTAL);
#ifdef __WXMSW__
		if (!(style & wxNO_BORDER)) style |= wxNO_BORDER;
#endif

		XRC_MAKE_INSTANCE(toolbar, wxToolBar)

		toolbar->Create(m_parentAsWindow,
						 GetID(),
						 GetPosition(),
						 GetSize(),
						 style,
						 GetName());

		wxSize bmpsize;
		if (m_iconSize.IsFullySpecified())
			bmpsize = m_iconSize;
		else
			bmpsize = GetSize(wxT("bitmapsize"));
		if (!(bmpsize == wxDefaultSize))
			toolbar->SetToolBitmapSize(bmpsize);
		wxSize margins = GetSize(wxT("margins"));
		if (!(margins == wxDefaultSize))
			toolbar->SetMargins(margins.x, margins.y);
		long packing = GetLong(wxT("packing"), -1);
		if (packing != -1)
			toolbar->SetToolPacking(packing);
		long separation = GetLong(wxT("separation"), -1);
		if (separation != -1)
			toolbar->SetToolSeparation(separation);
		if (HasParam(wxT("bg")))
			toolbar->SetBackgroundColour(GetColour(wxT("bg")));

		wxXmlNode *children_node = GetParamNode(wxT("object"));
		if (!children_node)
		   children_node = GetParamNode(wxT("object_ref"));

		if (children_node == NULL) return toolbar;

		m_isInside = true;
		m_toolbar = toolbar;

		wxXmlNode *n = children_node;

		while (n)
		{
			if ((n->GetType() == wxXML_ELEMENT_NODE) &&
				(n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
			{
				wxObject *created = CreateResFromNode(n, toolbar, NULL);
				wxControl *control = wxDynamicCast(created, wxControl);
				if (!IsOfClass(n, wxT("tool")) &&
					!IsOfClass(n, wxT("separator")) &&
					control != NULL)
					toolbar->AddControl(control);
			}
			n = n->GetNext();
		}

		m_isInside = false;
		m_toolbar = NULL;

		toolbar->Realize();

		if (m_parentAsWindow && !GetBool(wxT("dontattachtoframe")))
		{
			wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
			if (parentFrame)
				parentFrame->SetToolBar(toolbar);
		}

		return toolbar;
	}
}