diff options
Diffstat (limited to 'shell/source/win32/shlxthandler/propsheets')
5 files changed, 822 insertions, 0 deletions
diff --git a/shell/source/win32/shlxthandler/propsheets/document_statistic.cxx b/shell/source/win32/shlxthandler/propsheets/document_statistic.cxx new file mode 100644 index 0000000000..6a27e1ab1b --- /dev/null +++ b/shell/source/win32/shlxthandler/propsheets/document_statistic.cxx @@ -0,0 +1,145 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include "document_statistic.hxx" +#include <utilities.hxx> +#include <metainforeader.hxx> +#include <resource.h> +#include <fileextensions.hxx> +#include <config.hxx> +#include <iso8601_converter.hxx> + +const bool READONLY = false; + +document_statistic_reader_ptr create_document_statistic_reader(const std::wstring& document_name, CMetaInfoReader* meta_info_accessor) +{ + File_Type_t file_type = get_file_type(document_name); + + if (WRITER == file_type) + return document_statistic_reader_ptr(new writer_document_statistic_reader(document_name, meta_info_accessor)); + else if (CALC == file_type) + return document_statistic_reader_ptr(new calc_document_statistic_reader(document_name, meta_info_accessor)); + else + return document_statistic_reader_ptr(new draw_impress_math_document_statistic_reader(document_name, meta_info_accessor)); +} + + +document_statistic_reader::document_statistic_reader(const std::wstring& document_name, CMetaInfoReader* meta_info_accessor) : + document_name_(document_name), + meta_info_accessor_(meta_info_accessor) +{} + +document_statistic_reader::~document_statistic_reader() +{} + +void document_statistic_reader::read(statistic_group_list_t* group_list) +{ + group_list->clear(); + fill_description_section(meta_info_accessor_, group_list); + fill_origin_section(meta_info_accessor_, group_list); +} + +std::wstring document_statistic_reader::get_document_name() const +{ + return document_name_; +} + +void document_statistic_reader::fill_origin_section(CMetaInfoReader *meta_info_accessor, statistic_group_list_t* group_list) +{ + statistic_item_list_t il; + + il.push_back(statistic_item(GetResString(IDS_AUTHOR), meta_info_accessor->getTagData( META_INFO_AUTHOR ), READONLY)); + + il.push_back(statistic_item(GetResString(IDS_MODIFIED), + iso8601_date_to_local_date(meta_info_accessor->getTagData(META_INFO_MODIFIED )), READONLY)); + + il.push_back(statistic_item(GetResString(IDS_DOCUMENT_NUMBER), meta_info_accessor->getTagData( META_INFO_DOCUMENT_NUMBER ), READONLY)); + + il.push_back(statistic_item(GetResString(IDS_EDITING_TIME), + iso8601_duration_to_local_duration(meta_info_accessor->getTagData( META_INFO_EDITING_TIME )), READONLY)); + + group_list->push_back(statistic_group_t(GetResString(IDS_ORIGIN), il)); +} + +writer_document_statistic_reader::writer_document_statistic_reader(const std::wstring& document_name, CMetaInfoReader* meta_info_accessor) : + document_statistic_reader(document_name, meta_info_accessor) +{} + +void writer_document_statistic_reader::fill_description_section(CMetaInfoReader *meta_info_accessor, statistic_group_list_t* group_list) +{ + statistic_item_list_t il; + + il.push_back(statistic_item(GetResString(IDS_TITLE), meta_info_accessor->getTagData( META_INFO_TITLE ), READONLY)); + il.push_back(statistic_item(GetResString(IDS_COMMENTS), meta_info_accessor->getTagData( META_INFO_DESCRIPTION ), READONLY)); + il.push_back(statistic_item(GetResString(IDS_SUBJECT), meta_info_accessor->getTagData( META_INFO_SUBJECT ), READONLY)); + il.push_back(statistic_item(GetResString(IDS_KEYWORDS), meta_info_accessor->getTagData(META_INFO_KEYWORDS ), READONLY)); + il.push_back(statistic_item(GetResString(IDS_PAGES), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_PAGES) , READONLY)); + il.push_back(statistic_item(GetResString(IDS_TABLES), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_TABLES) , READONLY)); + il.push_back(statistic_item(GetResString(IDS_GRAPHICS), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_DRAWS) , READONLY)); + il.push_back(statistic_item(GetResString(IDS_OLE_OBJECTS), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_OBJECTS) , READONLY)); + il.push_back(statistic_item(GetResString(IDS_PARAGRAPHS), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_PARAGRAPHS) , READONLY)); + il.push_back(statistic_item(GetResString(IDS_WORDS), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_WORDS) , READONLY)); + il.push_back(statistic_item(GetResString(IDS_CHARACTERS), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_CHARACTERS) , READONLY)); + + group_list->push_back(statistic_group_t(GetResString(IDS_DESCRIPTION), il)); +} + +calc_document_statistic_reader::calc_document_statistic_reader( + const std::wstring& document_name, CMetaInfoReader* meta_info_accessor) : + document_statistic_reader(document_name, meta_info_accessor) +{} + +void calc_document_statistic_reader::fill_description_section( + CMetaInfoReader *meta_info_accessor,statistic_group_list_t* group_list) +{ + statistic_item_list_t il; + + il.push_back(statistic_item(GetResString(IDS_TITLE), meta_info_accessor->getTagData( META_INFO_TITLE ), READONLY)); + il.push_back(statistic_item(GetResString(IDS_COMMENTS), meta_info_accessor->getTagData( META_INFO_DESCRIPTION ), READONLY)); + il.push_back(statistic_item(GetResString(IDS_SUBJECT), meta_info_accessor->getTagData( META_INFO_SUBJECT ), READONLY)); + il.push_back(statistic_item(GetResString(IDS_KEYWORDS), meta_info_accessor->getTagData(META_INFO_KEYWORDS ), READONLY)); + il.push_back(statistic_item(GetResString(IDS_TABLES), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_TABLES) , READONLY)); + il.push_back(statistic_item(GetResString(IDS_CELLS), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_CELLS) , READONLY)); + il.push_back(statistic_item(GetResString(IDS_OLE_OBJECTS), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_OBJECTS) , READONLY)); + + group_list->push_back(statistic_group_t(GetResString(IDS_DESCRIPTION), il)); +} + +draw_impress_math_document_statistic_reader::draw_impress_math_document_statistic_reader( + const std::wstring& document_name, CMetaInfoReader* meta_info_accessor) : + document_statistic_reader(document_name, meta_info_accessor) +{} + +void draw_impress_math_document_statistic_reader::fill_description_section( + CMetaInfoReader *meta_info_accessor, statistic_group_list_t* group_list) +{ + statistic_item_list_t il; + + il.push_back(statistic_item(GetResString(IDS_TITLE), meta_info_accessor->getTagData( META_INFO_TITLE ), READONLY)); + il.push_back(statistic_item(GetResString(IDS_COMMENTS), meta_info_accessor->getTagData( META_INFO_DESCRIPTION ), READONLY)); + il.push_back(statistic_item(GetResString(IDS_SUBJECT), meta_info_accessor->getTagData( META_INFO_SUBJECT ), READONLY)); + il.push_back(statistic_item(GetResString(IDS_KEYWORDS), meta_info_accessor->getTagData(META_INFO_KEYWORDS ), READONLY)); + il.push_back(statistic_item(GetResString(IDS_PAGES), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_PAGES) , READONLY)); + il.push_back(statistic_item(GetResString(IDS_OLE_OBJECTS), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_OBJECTS) , READONLY)); + + group_list->push_back(statistic_group_t(GetResString(IDS_DESCRIPTION), il)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/source/win32/shlxthandler/propsheets/document_statistic.hxx b/shell/source/win32/shlxthandler/propsheets/document_statistic.hxx new file mode 100644 index 0000000000..e6f0dc5dc2 --- /dev/null +++ b/shell/source/win32/shlxthandler/propsheets/document_statistic.hxx @@ -0,0 +1,122 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SHELL_SOURCE_WIN32_SHLXTHANDLER_PROPSHEETS_DOCUMENT_STATISTIC_HXX +#define INCLUDED_SHELL_SOURCE_WIN32_SHLXTHANDLER_PROPSHEETS_DOCUMENT_STATISTIC_HXX + +#include <utility> +#include <string> +#include <memory> +#include <vector> +#include <metainforeader.hxx> + + +struct statistic_item +{ + statistic_item(); + + statistic_item( + const std::wstring& title, + const std::wstring& value, + bool editable) : + title_(title), + value_(value), + editable_(editable) + {} + + std::wstring title_; + std::wstring value_; + bool editable_; +}; + + +typedef std::vector<statistic_item> statistic_item_list_t; +typedef std::pair<std::wstring, statistic_item_list_t> statistic_group_t; +typedef std::vector<statistic_group_t> statistic_group_list_t; + + +class document_statistic_reader; +typedef std::unique_ptr<document_statistic_reader> document_statistic_reader_ptr; + +document_statistic_reader_ptr create_document_statistic_reader(const std::wstring& document_name, CMetaInfoReader* meta_info_accessor); + + +class document_statistic_reader +{ +public: + virtual ~document_statistic_reader(); + + void read(statistic_group_list_t* group_list); + + std::wstring get_document_name() const; + +protected: + document_statistic_reader(const std::wstring& document_name, CMetaInfoReader* meta_info_accessor); + + virtual void fill_description_section(CMetaInfoReader *meta_info_accessor,statistic_group_list_t* group_list) = 0; + + virtual void fill_origin_section( CMetaInfoReader *meta_info_accessor,statistic_group_list_t* group_list); + +private: + std::wstring document_name_; + CMetaInfoReader* meta_info_accessor_; + + friend document_statistic_reader_ptr create_document_statistic_reader( + const std::wstring& document_name, CMetaInfoReader* meta_info_accessor); +}; + + +class writer_document_statistic_reader : public document_statistic_reader +{ +protected: + writer_document_statistic_reader(const std::wstring& document_name, CMetaInfoReader* meta_info_accessor); + + virtual void fill_description_section(CMetaInfoReader *meta_info_accessor, statistic_group_list_t* group_list) override; + + friend document_statistic_reader_ptr create_document_statistic_reader( + const std::wstring& document_name, CMetaInfoReader* meta_info_accessor); +}; + + +class calc_document_statistic_reader : public document_statistic_reader +{ +protected: + calc_document_statistic_reader(const std::wstring& document_name, CMetaInfoReader* meta_info_accessor); + + virtual void fill_description_section( CMetaInfoReader *meta_info_accessor,statistic_group_list_t* group_list) override; + + friend document_statistic_reader_ptr create_document_statistic_reader( + const std::wstring& document_name, CMetaInfoReader* meta_info_accessor); +}; + + +class draw_impress_math_document_statistic_reader : public document_statistic_reader +{ +protected: + draw_impress_math_document_statistic_reader(const std::wstring& document_name, CMetaInfoReader* meta_info_accessor); + + virtual void fill_description_section(CMetaInfoReader *meta_info_accessor, statistic_group_list_t* group_list) override; + + friend document_statistic_reader_ptr create_document_statistic_reader( + const std::wstring& document_name, CMetaInfoReader* meta_info_accessor); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/source/win32/shlxthandler/propsheets/listviewbuilder.cxx b/shell/source/win32/shlxthandler/propsheets/listviewbuilder.cxx new file mode 100644 index 0000000000..5f0705c74d --- /dev/null +++ b/shell/source/win32/shlxthandler/propsheets/listviewbuilder.cxx @@ -0,0 +1,175 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include "listviewbuilder.hxx" +#include "document_statistic.hxx" +#include <utilities.hxx> +#include <config.hxx> +#include <global.hxx> + +#include <commctrl.h> +#include <resource.h> + +// Unicode-only defines to break dependence on UNICODE define +#if !defined ListView_InsertColumnW +#define ListView_InsertColumnW(hwnd, iCol, pcol) \ + static_cast<int>(SNDMSG((hwnd), LVM_INSERTCOLUMNW, WPARAM(int(iCol)), reinterpret_cast<LPARAM>(pcol))) +#endif + +#if !defined ListView_InsertItemW +#define ListView_InsertItemW(hwnd, pitem) \ + static_cast<int>(SNDMSG((hwnd), LVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(pitem))) +#endif + +#if !defined ListView_SetItemW +#define ListView_SetItemW(hwnd, pitem) \ + static_cast<bool>(SNDMSG((hwnd), LVM_SETITEMW, 0, reinterpret_cast<LPARAM>(pitem))) +#endif + + +list_view_builder_ptr create_list_view_builder( + HWND hwnd_lv, const std::wstring& col1, const std::wstring& col2) +{ + return list_view_builder_ptr(new list_view_builder(hwnd_lv, col1, col2)); +} + + +list_view_builder::list_view_builder( + HWND hwnd_list_view, + const std::wstring& column1_title, + const std::wstring& column2_title) : + row_index_(-1), + hwnd_list_view_(hwnd_list_view), + column1_title_(column1_title), + column2_title_(column2_title), + group_count_(-1), + row_count_(0) +{ +} + + +list_view_builder::~list_view_builder() +{ +} + + +void list_view_builder::build(statistic_group_list_t& gl) +{ + setup_list_view(); + + for (const auto& group : gl) + { + if (!group.second.empty()) + insert_group(group.first); + + for (const auto& item : group.second) + insert_item(item.title_, item.value_, item.editable_); + } +} + + +void list_view_builder::setup_list_view() +{ + HIMAGELIST h_ils = ImageList_Create(16,15,ILC_MASK, 7, 0); + HBITMAP h_bmp = LoadBitmapW(GetCurrentModuleHandle(), MAKEINTRESOURCEW(IDB_PROPERTY_IMAGES)); + ImageList_AddMasked(h_ils, h_bmp, RGB(255, 0, 255)); + + (void) ListView_SetImageList(hwnd_list_view_, h_ils, LVSIL_SMALL); + + std::wstring header = GetResString(IDS_PROPERTY); + + LVCOLUMNW lvc; + lvc.mask = LVCF_FMT | + LVCF_WIDTH | + LVCF_TEXT | + LVCF_SUBITEM; + + lvc.iSubItem = 0; + lvc.pszText = const_cast<wchar_t*>(header.c_str()); + lvc.cx = 120; + lvc.fmt = LVCFMT_LEFT; + + ListView_InsertColumnW(hwnd_list_view_, 0, &lvc); + lvc.iSubItem = 1; + header = GetResString(IDS_PROPERTY_VALUE); + lvc.pszText = const_cast<wchar_t*>(header.c_str()); + ListView_InsertColumnW(hwnd_list_view_, 1, &lvc); + ListView_EnableGroupView(hwnd_list_view_, TRUE); +} + + +void list_view_builder::insert_group(const std::wstring& name) +{ + LVGROUP lvg; + + ZeroMemory(&lvg, sizeof(lvg)); + + lvg.cbSize = sizeof(lvg); + lvg.mask = LVGF_HEADER | LVGF_STATE | LVGF_GROUPID; + lvg.pszHeader = const_cast<wchar_t*>(name.c_str()); + lvg.cchHeader = static_cast<int>(name.size() + 1); + lvg.iGroupId = ++group_count_; + lvg.state = LVGS_NORMAL; + lvg.uAlign = LVGA_HEADER_CENTER; + + ListView_InsertGroup(get_list_view(), row_count_++, &lvg); +} + + +void list_view_builder::insert_item(const std::wstring& title, const std::wstring& value, bool is_editable) +{ + LVITEMW lvi; + + lvi.iItem = ++row_index_; + lvi.iSubItem = 0; + lvi.mask = LVIF_TEXT | LVIF_GROUPID; + lvi.state = 0; + lvi.stateMask = 0; + lvi.pszText = const_cast<wchar_t*>(title.c_str()); + lvi.iGroupId = group_count_; + + if (title.length() > 0) + { + lvi.mask |= LVIF_IMAGE; + + if (is_editable) + lvi.iImage = 4; + else + lvi.iImage = 3; + } + + ListView_InsertItemW(get_list_view(), &lvi); + + lvi.mask = LVIF_TEXT; + lvi.iSubItem = 1; + lvi.pszText = const_cast<wchar_t*>(value.c_str()); + + ListView_SetItemW(get_list_view(), &lvi); + + row_count_++; +} + + +HWND list_view_builder::get_list_view() const +{ + return hwnd_list_view_; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/source/win32/shlxthandler/propsheets/listviewbuilder.hxx b/shell/source/win32/shlxthandler/propsheets/listviewbuilder.hxx new file mode 100644 index 0000000000..689da439dd --- /dev/null +++ b/shell/source/win32/shlxthandler/propsheets/listviewbuilder.hxx @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SHELL_SOURCE_WIN32_SHLXTHANDLER_PROPSHEETS_LISTVIEWBUILDER_HXX +#define INCLUDED_SHELL_SOURCE_WIN32_SHLXTHANDLER_PROPSHEETS_LISTVIEWBUILDER_HXX + +#if !defined WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif +#include <windows.h> + +#include <string> +#include <memory> +#include "document_statistic.hxx" + + +class list_view_builder; +typedef std::unique_ptr<list_view_builder> list_view_builder_ptr; + +// factory method for list_view_builder +list_view_builder_ptr create_list_view_builder( + HWND hwnd_lv, const std::wstring& col1, const std::wstring& col2); + + +class list_view_builder +{ +public: + virtual ~list_view_builder(); + + void build(statistic_group_list_t& gl); + +protected: + list_view_builder( + HWND hwnd_list_view, + const std::wstring& column1_title, + const std::wstring& column2_title); + + virtual void setup_list_view(); + virtual void insert_group(const std::wstring& title); + virtual void insert_item(const std::wstring& title, const std::wstring& value, bool is_editable); + + HWND get_list_view() const; +private: + int row_index_; + HWND hwnd_list_view_; + std::wstring column1_title_; + std::wstring column2_title_; + int group_count_; + int row_count_; + + friend list_view_builder_ptr create_list_view_builder(HWND hwnd_lv, const std::wstring& col1, const std::wstring& col2); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/shell/source/win32/shlxthandler/propsheets/propsheets.cxx b/shell/source/win32/shlxthandler/propsheets/propsheets.cxx new file mode 100644 index 0000000000..48a125d581 --- /dev/null +++ b/shell/source/win32/shlxthandler/propsheets/propsheets.cxx @@ -0,0 +1,308 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <config.hxx> +#include <global.hxx> + +#include <propsheets.hxx> +#include <utilities.hxx> +#include <resource.h> +#include "listviewbuilder.hxx" + +#include <shellapi.h> + +#include <sal/macros.h> + +#include <memory> +#include <string> +#include <vector> +#include <utility> +#include <strsafe.h> + + +/*--------------------------------------------- + INFO - INFO - INFO - INFO - INFO - INFO + + See MSDN "Using Windows XP Visual Styles" + for hints how to enable the new common + control library for our property sheet. + + INFO - INFO - INFO - INFO - INFO - INFO +----------------------------------------------*/ + + +CPropertySheet::CPropertySheet(LONG RefCnt) : + m_RefCnt(RefCnt) +{ + OutputDebugStringFormatW(L"CPropertySheet::CTor [%d], [%ld]", m_RefCnt, g_DllRefCnt ); + InterlockedIncrement(&g_DllRefCnt); +} + + +CPropertySheet::~CPropertySheet() +{ + OutputDebugStringFormatW(L"CPropertySheet::DTor [%d], [%ld]", m_RefCnt, g_DllRefCnt ); + InterlockedDecrement(&g_DllRefCnt); +} + + +// IUnknown methods + + +HRESULT STDMETHODCALLTYPE CPropertySheet::QueryInterface( + REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject) +{ + *ppvObject = nullptr; + + IUnknown* pUnk = nullptr; + if (IID_IUnknown == riid || IID_IShellExtInit == riid) + { + pUnk = static_cast<IShellExtInit*>(this); + pUnk->AddRef(); + *ppvObject = pUnk; + return S_OK; + } + else if (IID_IShellPropSheetExt == riid) + { + pUnk = static_cast<IShellPropSheetExt*>(this); + pUnk->AddRef(); + *ppvObject = pUnk; + return S_OK; + } + + return E_NOINTERFACE; +} + + +ULONG STDMETHODCALLTYPE CPropertySheet::AddRef() +{ + OutputDebugStringFormatW(L"CPropertySheet::AddRef [%d]", m_RefCnt ); + return InterlockedIncrement(&m_RefCnt); +} + + +ULONG STDMETHODCALLTYPE CPropertySheet::Release() +{ + OutputDebugStringFormatW(L"CPropertySheet::Release [%d]", m_RefCnt ); + LONG refcnt = InterlockedDecrement(&m_RefCnt); + + if (0 == refcnt) + delete this; + + return refcnt; +} + + +// IShellExtInit + + +HRESULT STDMETHODCALLTYPE CPropertySheet::Initialize( + LPCITEMIDLIST /*pidlFolder*/, IDataObject * lpdobj, HKEY /*hkeyProgID*/) +{ + InitCommonControls(); + + STGMEDIUM medium; + FORMATETC fe = {CF_HDROP, nullptr, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; + + HRESULT hr = lpdobj->GetData(&fe, &medium); + + // save the file name + if (SUCCEEDED(hr) && + (1 == DragQueryFileW( + static_cast<HDROP>(medium.hGlobal), + 0xFFFFFFFF, + nullptr, + 0))) + { + UINT size = DragQueryFileW( static_cast<HDROP>(medium.hGlobal), 0, nullptr, 0 ); + if ( size != 0 ) + { + auto buffer = std::make_unique<WCHAR[]>( size + 1 ); + UINT result_size = DragQueryFileW( static_cast<HDROP>(medium.hGlobal), + 0, buffer.get(), size + 1 ); + if ( result_size != 0 ) + { + std::wstring fname = getShortPathName( buffer.get() ); + ZeroMemory( m_szFileName, sizeof( m_szFileName ) ); + wcsncpy( m_szFileName, fname.c_str(), ( SAL_N_ELEMENTS( m_szFileName ) - 1 ) ); + hr = S_OK; + } + else + hr = E_INVALIDARG; + } + else + hr = E_INVALIDARG; + } + else + hr = E_INVALIDARG; + + ReleaseStgMedium(&medium); + + return hr; +} + + +// IShellPropSheetExt + + +HRESULT STDMETHODCALLTYPE CPropertySheet::AddPages(LPFNSVADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam) +{ + std::wstring proppage_header; + + PROPSHEETPAGEW psp; + ZeroMemory(&psp, sizeof(psp)); + + // add the summary property page + psp.dwSize = sizeof(psp); + psp.dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USECALLBACK; + psp.hInstance = GetCurrentModuleHandle(); + psp.lParam = reinterpret_cast<LPARAM>(this); + psp.pfnCallback = reinterpret_cast<LPFNPSPCALLBACKW>(CPropertySheet::PropPageSummaryCallback); + + HPROPSHEETPAGE hPage = nullptr; + + // add the statistics property page + proppage_header = GetResString(IDS_PROPPAGE_STATISTICS_TITLE); + + psp.pszTemplate = MAKEINTRESOURCEW(IDD_PROPPAGE_STATISTICS); + psp.pszTitle = proppage_header.c_str(); + psp.pfnDlgProc = reinterpret_cast<DLGPROC>(CPropertySheet::PropPageStatisticsProc); + + hPage = CreatePropertySheetPageW(&psp); + + if (hPage) + { + if (lpfnAddPage(hPage, lParam)) + AddRef(); + else + DestroyPropertySheetPage(hPage); + } + + // always return success else no property sheet will be displayed at all + return NOERROR; +} + + +HRESULT STDMETHODCALLTYPE CPropertySheet::ReplacePage( + EXPPS /*uPageID*/, LPFNSVADDPROPSHEETPAGE /*lpfnReplaceWith*/, LPARAM /*lParam*/) +{ + return E_NOTIMPL; +} + + +UINT CALLBACK CPropertySheet::PropPageSummaryCallback( + HWND /*hwnd*/, UINT uMsg, LPPROPSHEETPAGE ppsp) +{ + CPropertySheet* pImpl = + reinterpret_cast<CPropertySheet*>(ppsp->lParam); + + // release this instance, acquired in the AddPages method + if (PSPCB_RELEASE == uMsg) + { + pImpl->Release(); + } + + return TRUE; +} + + +bool CALLBACK CPropertySheet::PropPageSummaryProc(HWND hwnd, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam) +{ + switch (uiMsg) + { + case WM_INITDIALOG: + { + LPPROPSHEETPAGE psp = reinterpret_cast<LPPROPSHEETPAGE>(lParam); + CPropertySheet* pImpl = reinterpret_cast<CPropertySheet*>(psp->lParam); + pImpl->InitPropPageSummary(hwnd, psp); + return true; + } + } + + return false; +} + + +BOOL CALLBACK CPropertySheet::PropPageStatisticsProc(HWND hwnd, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam) +{ + switch (uiMsg) + { + case WM_INITDIALOG: + { + LPPROPSHEETPAGE psp = reinterpret_cast<LPPROPSHEETPAGE>(lParam); + CPropertySheet* pImpl = reinterpret_cast<CPropertySheet*>(psp->lParam); + pImpl->InitPropPageStatistics(hwnd, psp); + return TRUE; + } + } + + return FALSE; +} + +void CPropertySheet::InitPropPageSummary(HWND hwnd, LPPROPSHEETPAGE /*lppsp*/) +{ + try + { + CMetaInfoReader metaInfo(m_szFileName); + + SetWindowTextW(GetDlgItem(hwnd,IDC_TITLE), metaInfo.getTagData( META_INFO_TITLE ).c_str() ); + SetWindowTextW(GetDlgItem(hwnd,IDC_AUTHOR), metaInfo.getTagData( META_INFO_AUTHOR ).c_str() ); + SetWindowTextW(GetDlgItem(hwnd,IDC_SUBJECT), metaInfo.getTagData( META_INFO_SUBJECT ).c_str() ); + SetWindowTextW(GetDlgItem(hwnd,IDC_KEYWORDS), metaInfo.getTagData( META_INFO_KEYWORDS ).c_str() ); + + // comments read from meta.xml use "\n" for return, but this will not displayable in Edit control, add + // "\r" before "\n" to form "\r\n" in order to display return in Edit control. + std::wstring tempStr = metaInfo.getTagData( META_INFO_DESCRIPTION ); + std::wstring::size_type itor = tempStr.find ( L"\n" , 0 ); + while (itor != std::wstring::npos) + { + tempStr.insert(itor, L"\r"); + itor = tempStr.find(L"\n", itor + 2); + } + SetWindowTextW(GetDlgItem(hwnd,IDC_COMMENTS), tempStr.c_str()); + } + catch (const std::exception&) + { + } +} + + +void CPropertySheet::InitPropPageStatistics(HWND hwnd, LPPROPSHEETPAGE /*lppsp*/) +{ + try + { + CMetaInfoReader metaInfo(m_szFileName); + + document_statistic_reader_ptr doc_stat_reader = create_document_statistic_reader(m_szFileName, &metaInfo); + + statistic_group_list_t sgl; + doc_stat_reader->read(&sgl); + + list_view_builder_ptr lv_builder = create_list_view_builder( + GetDlgItem(hwnd, IDC_STATISTICSLIST), + GetResString(IDS_PROPERTY), + GetResString(IDS_PROPERTY_VALUE)); + + lv_builder->build(sgl); + } + catch (const std::exception&) + { + } +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |