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