vcldemo: dump and render all icons from images.zip when zoomed in.

Change-Id: I89f37b8a1ed70334a3485bc3ca06d04cfe6d0827
This commit is contained in:
Michael Meeks
2014-11-14 11:58:28 +00:00
committed by Markus Mohrhard
parent f5b3ea832e
commit 3bc5e986b3
3 changed files with 51 additions and 40 deletions

View File

@@ -55,6 +55,8 @@ public:
* be too late for the destructors of the bitmaps in m_iconCache)*/ * be too late for the destructors of the bitmaps in m_iconCache)*/
void shutDown(); void shutDown();
css::uno::Reference< css::container::XNameAccess > getNameAccess();
private: private:
bool doLoadImage( bool doLoadImage(
OUString const & name, OUString const & style, OUString const & name, OUString const & style,
@@ -62,8 +64,7 @@ private:
typedef std::pair< typedef std::pair<
OUString, OUString,
com::sun::star::uno::Reference< css::uno::Reference< css::container::XNameAccess > > Path;
com::sun::star::container::XNameAccess > > Path;
typedef boost::unordered_map< typedef boost::unordered_map<
OUString, bool, OUStringHash > CheckStyleCache; OUString, bool, OUStringHash > CheckStyleCache;
@@ -78,6 +79,8 @@ private:
bool m_cacheIcons; bool m_cacheIcons;
IconLinkHash m_linkHash; IconLinkHash m_linkHash;
bool checkPathAccess();
void setStyle(OUString const & style ); void setStyle(OUString const & style );
void resetPaths(); void resetPaths();
@@ -89,7 +92,6 @@ private:
void loadImageLinks(); void loadImageLinks();
void parseLinkFile(boost::shared_ptr< SvStream > stream); void parseLinkFile(boost::shared_ptr< SvStream > stream);
OUString const & getRealImageName(OUString const & name); OUString const & getRealImageName(OUString const & name);
std::vector<OUString> getAllPaths();
}; };
typedef salhelper::SingletonRef< ImplImageTree > ImplImageTreeSingletonRef; typedef salhelper::SingletonRef< ImplImageTree > ImplImageTreeSingletonRef;

View File

@@ -248,17 +248,9 @@ bool ImplImageTree::find(
} }
} }
if (!m_path.second.is()) { if (!checkPathAccess())
try {
m_path.second = css::packages::zip::ZipFileAccess::createWithURL(comphelper::getProcessComponentContext(), m_path.first + ".zip");
} catch (const css::uno::RuntimeException &) {
throw;
} catch (const css::uno::Exception & e) {
SAL_INFO("vcl", "ImplImageTree::find exception "
<< e.Message << " for " << m_path.first);
return false; return false;
}
}
for (std::vector< OUString >::const_reverse_iterator j(paths.rbegin()); for (std::vector< OUString >::const_reverse_iterator j(paths.rbegin());
j != paths.rend(); ++j) j != paths.rend(); ++j)
{ {
@@ -288,21 +280,9 @@ void ImplImageTree::loadImageLinks()
} }
} }
if ( !m_path.second.is() ) if (!checkPathAccess())
{
try
{
m_path.second = css::packages::zip::ZipFileAccess::createWithURL(comphelper::getProcessComponentContext(), m_path.first + ".zip");
} catch (const css::uno::RuntimeException &) {
throw;
}
catch (const css::uno::Exception & e)
{
SAL_INFO("vcl", "ImplImageTree::find exception "
<< e.Message << " for " << m_path.first);
return; return;
}
}
if ( m_path.second->hasByName(aLinkFilename) ) if ( m_path.second->hasByName(aLinkFilename) )
{ {
css::uno::Reference< css::io::XInputStream > s; css::uno::Reference< css::io::XInputStream > s;
@@ -349,21 +329,41 @@ OUString const & ImplImageTree::getRealImageName(OUString const & name)
return it->second; return it->second;
} }
std::vector<OUString> ImplImageTree::getAllPaths() bool ImplImageTree::checkPathAccess()
{ {
std::vector<OUString> aNames; if (m_path.second.is())
return true;
return aNames; try {
m_path.second = css::packages::zip::ZipFileAccess::createWithURL(comphelper::getProcessComponentContext(), m_path.first + ".zip");
} catch (const css::uno::RuntimeException &) {
throw;
} catch (const css::uno::Exception & e) {
SAL_INFO("vcl", "ImplImageTree::zip file location exception "
<< e.Message << " for " << m_path.first);
return false;
}
return m_path.second.is();
}
css::uno::Reference< css::container::XNameAccess > ImplImageTree::getNameAccess()
{
checkPathAccess();
return m_path.second;
} }
// For vcldemo / debugging // For vcldemo / debugging
SAL_DLLPUBLIC std::vector<OUString> ImageTree_getAllImageNames(); SAL_DLLPUBLIC css::uno::Sequence< OUString > ImageTree_getAllImageNames();
/// Recursively dump all names ... /// Recursively dump all names ...
std::vector<OUString> ImageTree_getAllImageNames() css::uno::Sequence< OUString > ImageTree_getAllImageNames()
{ {
static ImplImageTreeSingletonRef aImageTree; static ImplImageTreeSingletonRef aImageTree;
return aImageTree.getAllPaths();
css::uno::Reference< css::container::XNameAccess > xRef(
aImageTree->getNameAccess() );
return xRef->getElementNames();
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -31,7 +31,7 @@
#endif #endif
// debugging hook just for us // debugging hook just for us
SAL_DLLPUBLIC std::vector<OUString> ImageTree_getAllImageNames(); SAL_DLLPUBLIC css::uno::Sequence< OUString > ImageTree_getAllImageNames();
using namespace css; using namespace css;
@@ -566,6 +566,7 @@ public:
struct DrawIcons : public RegionRenderer struct DrawIcons : public RegionRenderer
{ {
std::vector<OUString> maIconNames;
std::vector<BitmapEx> maIcons; std::vector<BitmapEx> maIcons;
bool bHasLoadedAll; bool bHasLoadedAll;
DrawIcons() : bHasLoadedAll(false) DrawIcons() : bHasLoadedAll(false)
@@ -596,19 +597,25 @@ public:
"cmd/lc_hyperlinkdialog.png", "cmd/lc_hyperlinkdialog.png",
}; };
for (size_t i = 0; i < SAL_N_ELEMENTS(pNames); i++) for (size_t i = 0; i < SAL_N_ELEMENTS(pNames); i++)
maIcons.push_back(BitmapEx(OUString::createFromAscii(pNames[i]))); {
maIconNames.push_back(OUString::createFromAscii(pNames[i]));
maIcons.push_back(BitmapEx(maIconNames[i]));
}
} }
void LoadAllIcons() void LoadAllImages()
{ {
if (bHasLoadedAll) if (bHasLoadedAll)
return; return;
bHasLoadedAll = true; bHasLoadedAll = true;
std::vector<OUString> aAllIcons = ImageTree_getAllImageNames(); css::uno::Sequence< OUString > aAllIcons = ImageTree_getAllImageNames();
for (size_t i = 0; i < aAllIcons.size(); i++) for (sal_Int32 i = 0; i < aAllIcons.getLength() && i < 1024; i++)
{
maIconNames.push_back(aAllIcons[i]);
maIcons.push_back(BitmapEx(aAllIcons[i])); maIcons.push_back(BitmapEx(aAllIcons[i]));
} }
}
void doDrawIcons(OutputDevice &rDev, Rectangle r) void doDrawIcons(OutputDevice &rDev, Rectangle r)
{ {
@@ -617,6 +624,7 @@ public:
for (size_t i = 0; i < maIcons.size(); i++) for (size_t i = 0; i < maIcons.size(); i++)
{ {
Size aSize(maIcons[i].GetSizePixel()); Size aSize(maIcons[i].GetSizePixel());
// sAL_DEBUG("Draw icon '" << maIconNames[i] << "'");
rDev.DrawBitmapEx(p, maIcons[i]); rDev.DrawBitmapEx(p, maIcons[i]);
p.Move(aSize.Width(), 0); p.Move(aSize.Width(), 0);
if (aSize.Height() > nMaxH) if (aSize.Height() > nMaxH)
@@ -635,6 +643,7 @@ public:
{ {
if (rCtx.meStyle == RENDER_EXPANDED) if (rCtx.meStyle == RENDER_EXPANDED)
{ {
LoadAllImages();
doDrawIcons(rDev, r); doDrawIcons(rDev, r);
} }
else else