update dev300-m58
[ooovba.git] / sd / source / ui / toolpanel / TestPanel.cxx
blobd3b8eb4c85657eabf3a18c03e591e4f89f608f26
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TestPanel.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "TestPanel.hxx"
35 #include "taskpane/ScrollPanel.hxx"
36 #include "taskpane/TaskPaneControlFactory.hxx"
38 #include <vcl/lstbox.hxx>
39 #include <vcl/button.hxx>
41 namespace sd { namespace toolpanel {
43 /** This factory class is used to create instances of TestPanel. It can be
44 extended so that its constructor stores arguments that later are passed
45 to new TestPanel objects.
47 class TestPanelFactory
48 : public ControlFactory
50 protected:
51 virtual TreeNode* InternalCreateControl (TreeNode* pTreeNode)
53 return new TestPanel (pTreeNode);
58 class Wrapper
59 : public TreeNode
61 public:
62 Wrapper (
63 TreeNode* pParent,
64 Size aPreferredSize,
65 ::Window* pWrappedControl,
66 bool bIsResizable)
67 : TreeNode (pParent),
68 maPreferredSize(aPreferredSize),
69 mpWrappedControl(pWrappedControl),
70 mbIsResizable(bIsResizable)
72 mpWrappedControl->Show();
74 virtual ~Wrapper (void)
76 delete mpWrappedControl;
79 virtual Size GetPreferredSize (void)
81 return maPreferredSize;
83 virtual sal_Int32 GetPreferredWidth (sal_Int32 )
85 return maPreferredSize.Width();
87 virtual sal_Int32 GetPreferredHeight (sal_Int32 )
89 return maPreferredSize.Height();
91 virtual ::Window* GetWindow (void)
93 return mpWrappedControl;
95 virtual bool IsResizable (void)
97 return mbIsResizable;
99 virtual bool IsExpandable (void) const
101 return false;
103 virtual bool IsExpanded (void) const
105 return true;
108 private:
109 Size maPreferredSize;
110 ::Window* mpWrappedControl;
111 bool mbIsResizable;
115 TestPanel::TestPanel (TreeNode* pParent)
116 : SubToolPanel (pParent)
118 // Create a scrollable panel with two list boxes.
119 ScrollPanel* pScrollPanel = new ScrollPanel (this);
121 ListBox* pBox = new ListBox (pScrollPanel->GetWindow());
122 int i;
123 for (i=1; i<=20; i++)
125 XubString aString (XubString::CreateFromAscii("Text "));
126 aString.Append (XubString::CreateFromInt32(i));
127 aString.Append (XubString::CreateFromAscii("/20"));
128 pBox->InsertEntry (aString);
130 pScrollPanel->AddControl (
131 ::std::auto_ptr<TreeNode>(new Wrapper (
132 pScrollPanel, Size (200,300), pBox, true)),
133 String::CreateFromAscii ("First ListBox"),
136 pBox = new ListBox (pScrollPanel->GetWindow());
137 for (i=1; i<=20; i++)
139 XubString aString (XubString::CreateFromAscii("More Text "));
140 aString.Append (XubString::CreateFromInt32(i));
141 aString.Append (XubString::CreateFromAscii("/20"));
142 pBox->InsertEntry (aString);
144 pScrollPanel->AddControl (
145 ::std::auto_ptr<TreeNode>(new Wrapper (
146 pScrollPanel, Size (200,300), pBox, true)),
147 String::CreateFromAscii ("Second ListBox"),
150 AddControl (::std::auto_ptr<TreeNode>(pScrollPanel));
152 // Add a fixed size button.
153 Button* pButton = new OKButton (this);
154 AddControl (
155 ::std::auto_ptr<TreeNode>(new Wrapper (
156 this, Size (100,30), pButton, false)),
157 String::CreateFromAscii ("Button Area"),
165 TestPanel::~TestPanel (void)
172 std::auto_ptr<ControlFactory> TestPanel::CreateControlFactory (void)
174 return std::auto_ptr<ControlFactory>(new TestPanelFactory());
178 } } // end of namespace ::sd::toolpanel