1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     lyt_Group.cpp
4 
5   Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain proprietary
8   information of Nintendo and/or its licensed developers and are protected by
9   national and international copyright laws. They may not be disclosed to third
10   parties or copied or duplicated in any form, in whole or in part, without the
11   prior written consent of Nintendo.
12 
13   The content herein is highly confidential and should be handled accordingly.
14 
15   $Revision: 31311 $
16  *---------------------------------------------------------------------------*/
17 
18 #include "precompiled.h"
19 
20 #include <nw/lyt/lyt_Common.h>
21 #include <nw/lyt/lyt_Group.h>
22 #include <nw/lyt/lyt_Layout.h>
23 
24 namespace nw
25 {
26 namespace lyt
27 {
28 
Group()29 Group::Group()
30 {
31     Init();
32 
33     std::memset(m_Name, 0, sizeof(m_Name));
34 }
35 
Group(const res::Group * pResGroup,Pane * pRootPane)36 Group::Group(
37     const res::Group* pResGroup,
38     Pane* pRootPane
39 )
40 {
41     Init();
42 
43     ut::strcpy(m_Name, sizeof(m_Name), pResGroup->name);
44 
45     const char *const paneNameBase = internal::ConvertOffsToPtr<char>(pResGroup, sizeof(res::Group));
46 
47     for (int i = 0; i < pResGroup->paneNum; ++i)
48     {
49         if (Pane* pFindPane = pRootPane->FindPaneByName(paneNameBase + i * ResourceNameStrMax, true))
50         {
51             AppendPane(pFindPane);
52         }
53     }
54 }
55 
56 void
Init()57 Group::Init()
58 {
59     m_UserAllocated = false;
60 }
61 
~Group()62 Group::~Group()
63 {
64     // OSReport("Group::~Group()\n");
65 
66     for (PaneLinkList::Iterator it = m_PaneLinkList.GetBeginIter(); it != m_PaneLinkList.GetEndIter();)
67     {
68         PaneLinkList::Iterator currIt = it++;
69         m_PaneLinkList.Erase(currIt);
70         Layout::DeleteObj(&(*currIt));
71     }
72 }
73 
74 void
AppendPane(Pane * pPane)75 Group::AppendPane(Pane* pPane)
76 {
77     if (PaneLink* pPaneLink = Layout::NewObj<PaneLink>())
78     {
79         pPaneLink->target = pPane;
80         m_PaneLinkList.PushBack(pPaneLink);
81     }
82 }
83 
~GroupContainer()84 GroupContainer::~GroupContainer()
85 {
86     // OSReport("GroupContainer::~GroupContainer()\n");
87 
88     // Groupの後処理
89     for (GroupList::Iterator it = m_GroupList.GetBeginIter(); it != m_GroupList.GetEndIter();)
90     {
91         GroupList::Iterator currIt = it++;
92         m_GroupList.Erase(currIt);
93         if (! currIt->IsUserAllocated())
94         {
95             Layout::DeleteObj(&(*currIt));
96         }
97     }
98 }
99 
100 void
AppendGroup(Group * pGroup)101 GroupContainer::AppendGroup(Group* pGroup)
102 {
103     m_GroupList.PushBack(pGroup);
104 }
105 
106 Group*
FindGroupByName(const char * findName)107 GroupContainer::FindGroupByName(const char* findName)
108 {
109     // 子供に一致するものが無いか検索
110     for (GroupList::Iterator it = m_GroupList.GetBeginIter(); it != m_GroupList.GetEndIter(); ++it)
111     {
112         if (internal::EqualsResName(it->GetName(), findName))
113         {
114             return &(*it);
115         }
116     }
117 
118     return 0;
119 }
120 
121 } // namespace nw::lyt
122 } // namespace nw
123