<commit_before>// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/page_info_model.h"

#include <string>

#include "app/l10n_util.h"
#include "base/callback.h"
#include "base/i18n/time_formatting.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/cert_store.h"
#include "chrome/browser/pref_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/ssl/ssl_manager.h"
#include "chrome/common/pref_names.h"
#include "grit/generated_resources.h"
#include "net/base/cert_status_flags.h"
#include "net/base/x509_certificate.h"

namespace {
  // Returns a name that can be used to represent the issuer.  It tries in this
  // order CN, O and OU and returns the first non-empty one found.
  std::string GetIssuerName(const net::X509Certificate::Principal& issuer) {
    if (!issuer.common_name.empty())
      return issuer.common_name;
    if (!issuer.organization_names.empty())
      return issuer.organization_names[0];
    if (!issuer.organization_unit_names.empty())
      return issuer.organization_unit_names[0];

    return std::string();
  }
}

PageInfoModel::PageInfoModel(Profile* profile,
                             const GURL& url,
                             const NavigationEntry::SSLStatus& ssl,
                             bool show_history,
                             PageInfoModelObserver* observer)
    : observer_(observer) {
  bool state = true;
  string16 head_line;
  string16 description;
  scoped_refptr<net::X509Certificate> cert;

  // Identity section.
  string16 subject_name(UTF8ToUTF16(url.host()));
  bool empty_subject_name = false;
  if (subject_name.empty()) {
    subject_name.assign(
        l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
    empty_subject_name = true;
  }
  if (ssl.cert_id() &&
      CertStore::GetSharedInstance()->RetrieveCert(ssl.cert_id(), &cert) &&
      !net::IsCertStatusError(ssl.cert_status())) {
    // OK HTTPS page.
    if ((ssl.cert_status() & net::CERT_STATUS_IS_EV) != 0) {
      DCHECK(!cert->subject().organization_names.empty());
      head_line =
          l10n_util::GetStringFUTF16(IDS_PAGE_INFO_EV_IDENTITY_TITLE,
              UTF8ToUTF16(cert->subject().organization_names[0]),
              UTF8ToUTF16(url.host()));
      // An EV Cert is required to have a city (localityName) and country but
      // state is "if any".
      DCHECK(!cert->subject().locality_name.empty());
      DCHECK(!cert->subject().country_name.empty());
      string16 locality;
      if (!cert->subject().state_or_province_name.empty()) {
        locality = l10n_util::GetStringFUTF16(
            IDS_PAGEINFO_ADDRESS,
            UTF8ToUTF16(cert->subject().locality_name),
            UTF8ToUTF16(cert->subject().state_or_province_name),
            UTF8ToUTF16(cert->subject().country_name));
      } else {
        locality = l10n_util::GetStringFUTF16(
            IDS_PAGEINFO_PARTIAL_ADDRESS,
            UTF8ToUTF16(cert->subject().locality_name),
            UTF8ToUTF16(cert->subject().country_name));
      }
      DCHECK(!cert->subject().organization_names.empty());
      description.assign(l10n_util::GetStringFUTF16(
          IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV,
          UTF8ToUTF16(cert->subject().organization_names[0]),
          locality,
          UTF8ToUTF16(GetIssuerName(cert->issuer()))));
    } else {
      // Non EV OK HTTPS.
      if (empty_subject_name)
        head_line.clear();  // Don't display any title.
      else
        head_line.assign(subject_name);
      string16 issuer_name(UTF8ToUTF16(GetIssuerName(cert->issuer())));
      if (issuer_name.empty()) {
        issuer_name.assign(l10n_util::GetStringUTF16(
            IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
      } else {
        description.assign(l10n_util::GetStringFUTF16(
            IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
      }
    }
  } else {
    // Bad HTTPS.
    description.assign(l10n_util::GetStringUTF16(
        IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
    state = false;
  }
  sections_.push_back(SectionInfo(
      state,
      l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE),
      head_line,
      description));

  // Connection section.
  // We consider anything less than 80 bits encryption to be weak encryption.
  // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
  // weakly encrypted connections.
  state = true;
  head_line.clear();
  description.clear();
  if (ssl.security_bits() <= 0) {
    state = false;
    description.assign(l10n_util::GetStringFUTF16(
        IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
        subject_name));
  } else if (ssl.security_bits() < 80) {
    state = false;
    description.assign(l10n_util::GetStringFUTF16(
        IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
        subject_name));
  } else {
    description.assign(l10n_util::GetStringFUTF16(
        IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT,
        subject_name,
        IntToString16(ssl.security_bits())));
    if (ssl.displayed_insecure_content() || ssl.ran_insecure_content()) {
      state = false;
      description.assign(l10n_util::GetStringFUTF16(
          IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK,
          description,
          l10n_util::GetStringUTF16(ssl.ran_insecure_content() ?
              IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR :
              IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
    }
  }
  sections_.push_back(SectionInfo(
      state,
      l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE),
      head_line,
      description));

  // Request the number of visits.
  HistoryService* history = profile->GetHistoryService(
      Profile::EXPLICIT_ACCESS);
  if (show_history && history) {
    history->GetVisitCountToHost(
        url,
        &request_consumer_,
        NewCallback(this, &PageInfoModel::OnGotVisitCountToHost));
  }
}

int PageInfoModel::GetSectionCount() {
  return sections_.size();
}

PageInfoModel::SectionInfo PageInfoModel::GetSectionInfo(int index) {
  DCHECK(index < static_cast<int>(sections_.size()));
  return sections_[index];
}

void PageInfoModel::OnGotVisitCountToHost(HistoryService::Handle handle,
                                          bool found_visits,
                                          int count,
                                          base::Time first_visit) {
  if (!found_visits) {
    // This indicates an error, such as the page wasn't http/https; do nothing.
    return;
  }

  bool visited_before_today = false;
  if (count) {
    base::Time today = base::Time::Now().LocalMidnight();
    base::Time first_visit_midnight = first_visit.LocalMidnight();
    visited_before_today = (first_visit_midnight < today);
  }

  if (!visited_before_today) {
    sections_.push_back(SectionInfo(
        false,
        l10n_util::GetStringUTF16(
            IDS_PAGE_INFO_SECURITY_TAB_PERSONAL_HISTORY_TITLE),
        string16(),
        l10n_util::GetStringUTF16(
            IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY)));
  } else {
    sections_.push_back(SectionInfo(
        true,
        l10n_util::GetStringUTF16(
            IDS_PAGE_INFO_SECURITY_TAB_PERSONAL_HISTORY_TITLE),
        string16(),
        l10n_util::GetStringFUTF16(
            IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY,
            WideToUTF16(base::TimeFormatShortDate(first_visit)))));
  }
  observer_->ModelChanged();
}

// static
void PageInfoModel::RegisterPrefs(PrefService* prefs) {
  prefs->RegisterDictionaryPref(prefs::kPageInfoWindowPlacement);
}
<commit_msg>Trivial change: update a comment.<commit_after>// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/page_info_model.h"

#include <string>

#include "app/l10n_util.h"
#include "base/callback.h"
#include "base/i18n/time_formatting.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/cert_store.h"
#include "chrome/browser/pref_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/ssl/ssl_manager.h"
#include "chrome/common/pref_names.h"
#include "grit/generated_resources.h"
#include "net/base/cert_status_flags.h"
#include "net/base/x509_certificate.h"

namespace {
  // Returns a name that can be used to represent the issuer.  It tries in this
  // order CN, O and OU and returns the first non-empty one found.
  std::string GetIssuerName(const net::X509Certificate::Principal& issuer) {
    if (!issuer.common_name.empty())
      return issuer.common_name;
    if (!issuer.organization_names.empty())
      return issuer.organization_names[0];
    if (!issuer.organization_unit_names.empty())
      return issuer.organization_unit_names[0];

    return std::string();
  }
}

PageInfoModel::PageInfoModel(Profile* profile,
                             const GURL& url,
                             const NavigationEntry::SSLStatus& ssl,
                             bool show_history,
                             PageInfoModelObserver* observer)
    : observer_(observer) {
  bool state = true;
  string16 head_line;
  string16 description;
  scoped_refptr<net::X509Certificate> cert;

  // Identity section.
  string16 subject_name(UTF8ToUTF16(url.host()));
  bool empty_subject_name = false;
  if (subject_name.empty()) {
    subject_name.assign(
        l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
    empty_subject_name = true;
  }
  if (ssl.cert_id() &&
      CertStore::GetSharedInstance()->RetrieveCert(ssl.cert_id(), &cert) &&
      !net::IsCertStatusError(ssl.cert_status())) {
    // OK HTTPS page.
    if ((ssl.cert_status() & net::CERT_STATUS_IS_EV) != 0) {
      DCHECK(!cert->subject().organization_names.empty());
      head_line =
          l10n_util::GetStringFUTF16(IDS_PAGE_INFO_EV_IDENTITY_TITLE,
              UTF8ToUTF16(cert->subject().organization_names[0]),
              UTF8ToUTF16(url.host()));
      // An EV Cert is required to have a city (localityName) and country but
      // state is "if any".
      DCHECK(!cert->subject().locality_name.empty());
      DCHECK(!cert->subject().country_name.empty());
      string16 locality;
      if (!cert->subject().state_or_province_name.empty()) {
        locality = l10n_util::GetStringFUTF16(
            IDS_PAGEINFO_ADDRESS,
            UTF8ToUTF16(cert->subject().locality_name),
            UTF8ToUTF16(cert->subject().state_or_province_name),
            UTF8ToUTF16(cert->subject().country_name));
      } else {
        locality = l10n_util::GetStringFUTF16(
            IDS_PAGEINFO_PARTIAL_ADDRESS,
            UTF8ToUTF16(cert->subject().locality_name),
            UTF8ToUTF16(cert->subject().country_name));
      }
      DCHECK(!cert->subject().organization_names.empty());
      description.assign(l10n_util::GetStringFUTF16(
          IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV,
          UTF8ToUTF16(cert->subject().organization_names[0]),
          locality,
          UTF8ToUTF16(GetIssuerName(cert->issuer()))));
    } else {
      // Non EV OK HTTPS.
      if (empty_subject_name)
        head_line.clear();  // Don't display any title.
      else
        head_line.assign(subject_name);
      string16 issuer_name(UTF8ToUTF16(GetIssuerName(cert->issuer())));
      if (issuer_name.empty()) {
        issuer_name.assign(l10n_util::GetStringUTF16(
            IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
      } else {
        description.assign(l10n_util::GetStringFUTF16(
            IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
      }
    }
  } else {
    // HTTP or bad HTTPS.
    description.assign(l10n_util::GetStringUTF16(
        IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
    state = false;
  }
  sections_.push_back(SectionInfo(
      state,
      l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE),
      head_line,
      description));

  // Connection section.
  // We consider anything less than 80 bits encryption to be weak encryption.
  // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
  // weakly encrypted connections.
  state = true;
  head_line.clear();
  description.clear();
  if (ssl.security_bits() <= 0) {
    state = false;
    description.assign(l10n_util::GetStringFUTF16(
        IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
        subject_name));
  } else if (ssl.security_bits() < 80) {
    state = false;
    description.assign(l10n_util::GetStringFUTF16(
        IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
        subject_name));
  } else {
    description.assign(l10n_util::GetStringFUTF16(
        IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT,
        subject_name,
        IntToString16(ssl.security_bits())));
    if (ssl.displayed_insecure_content() || ssl.ran_insecure_content()) {
      state = false;
      description.assign(l10n_util::GetStringFUTF16(
          IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK,
          description,
          l10n_util::GetStringUTF16(ssl.ran_insecure_content() ?
              IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR :
              IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
    }
  }
  sections_.push_back(SectionInfo(
      state,
      l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_CONNECTION_TITLE),
      head_line,
      description));

  // Request the number of visits.
  HistoryService* history = profile->GetHistoryService(
      Profile::EXPLICIT_ACCESS);
  if (show_history && history) {
    history->GetVisitCountToHost(
        url,
        &request_consumer_,
        NewCallback(this, &PageInfoModel::OnGotVisitCountToHost));
  }
}

int PageInfoModel::GetSectionCount() {
  return sections_.size();
}

PageInfoModel::SectionInfo PageInfoModel::GetSectionInfo(int index) {
  DCHECK(index < static_cast<int>(sections_.size()));
  return sections_[index];
}

void PageInfoModel::OnGotVisitCountToHost(HistoryService::Handle handle,
                                          bool found_visits,
                                          int count,
                                          base::Time first_visit) {
  if (!found_visits) {
    // This indicates an error, such as the page wasn't http/https; do nothing.
    return;
  }

  bool visited_before_today = false;
  if (count) {
    base::Time today = base::Time::Now().LocalMidnight();
    base::Time first_visit_midnight = first_visit.LocalMidnight();
    visited_before_today = (first_visit_midnight < today);
  }

  if (!visited_before_today) {
    sections_.push_back(SectionInfo(
        false,
        l10n_util::GetStringUTF16(
            IDS_PAGE_INFO_SECURITY_TAB_PERSONAL_HISTORY_TITLE),
        string16(),
        l10n_util::GetStringUTF16(
            IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY)));
  } else {
    sections_.push_back(SectionInfo(
        true,
        l10n_util::GetStringUTF16(
            IDS_PAGE_INFO_SECURITY_TAB_PERSONAL_HISTORY_TITLE),
        string16(),
        l10n_util::GetStringFUTF16(
            IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY,
            WideToUTF16(base::TimeFormatShortDate(first_visit)))));
  }
  observer_->ModelChanged();
}

// static
void PageInfoModel::RegisterPrefs(PrefService* prefs) {
  prefs->RegisterDictionaryPref(prefs::kPageInfoWindowPlacement);
}
<|endoftext|>


<commit_before>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/common/auto_start_linux.h"

#include "base/environment.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/nix/xdg_util.h"

namespace {

const FilePath::CharType kAutostart[] = "autostart";
const FilePath::CharType kConfig[] = ".config";
const char kXdgConfigHome[] = "XDG_CONFIG_HOME";

FilePath GetAutostartDirectory(base::Environment* environment) {
  FilePath result =
      base::nix::GetXDGDirectory(environment, kXdgConfigHome, kConfig);
  result = result.Append(kAutostart);
  return result;
}

}  // namespace

bool AutoStart::AddApplication(const std::string& autostart_filename,
                               const std::string& application_name,
                               const std::string& command_line,
                               bool is_terminal_app) {
  scoped_ptr<base::Environment> environment(base::Environment::Create());
  FilePath autostart_directory = GetAutostartDirectory(environment.get());
  if (!file_util::DirectoryExists(autostart_directory) &&
      !file_util::CreateDirectory(autostart_directory)) {
    return false;
  }

  FilePath autostart_file = autostart_directory.Append(autostart_filename);
  std::string autostart_file_contents =
      "[Desktop Entry]\n"
      "Type=Application\n"
      "Terminal=" + is_terminal_app ? "true\n" : "false\n"
      "Exec=" + command_line + "\n"
      "Name=" + application_name + "\n";
  std::string::size_type content_length = autostart_file_contents.length();
  if (file_util::WriteFile(autostart_file, autostart_file_contents.c_str(),
                           content_length) !=
      static_cast<int>(content_length)) {
    file_util::Delete(autostart_file, false);
    return false;
  }
  return true;
}

bool AutoStart::Remove(const std::string& autostart_filename) {
  scoped_ptr<base::Environment> environment(base::Environment::Create());
  FilePath autostart_directory = GetAutostartDirectory(environment.get());
  FilePath autostart_file = autostart_directory.Append(autostart_filename);
  return file_util::Delete(autostart_file, false);
}
<commit_msg>Fixed regression in the Linux AutoStart code caused by my previous CL.<commit_after>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/common/auto_start_linux.h"

#include "base/environment.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/nix/xdg_util.h"

namespace {

const FilePath::CharType kAutostart[] = "autostart";
const FilePath::CharType kConfig[] = ".config";
const char kXdgConfigHome[] = "XDG_CONFIG_HOME";

FilePath GetAutostartDirectory(base::Environment* environment) {
  FilePath result =
      base::nix::GetXDGDirectory(environment, kXdgConfigHome, kConfig);
  result = result.Append(kAutostart);
  return result;
}

}  // namespace

bool AutoStart::AddApplication(const std::string& autostart_filename,
                               const std::string& application_name,
                               const std::string& command_line,
                               bool is_terminal_app) {
  scoped_ptr<base::Environment> environment(base::Environment::Create());
  FilePath autostart_directory = GetAutostartDirectory(environment.get());
  if (!file_util::DirectoryExists(autostart_directory) &&
      !file_util::CreateDirectory(autostart_directory)) {
    return false;
  }

  FilePath autostart_file = autostart_directory.Append(autostart_filename);
  std::string terminal = is_terminal_app ? "true" : "false";
  std::string autostart_file_contents =
      "[Desktop Entry]\n"
      "Type=Application\n"
      "Terminal=" + terminal + "\n"
      "Exec=" + command_line + "\n"
      "Name=" + application_name + "\n";
  std::string::size_type content_length = autostart_file_contents.length();
  if (file_util::WriteFile(autostart_file, autostart_file_contents.c_str(),
                           content_length) !=
      static_cast<int>(content_length)) {
    file_util::Delete(autostart_file, false);
    return false;
  }
  return true;
}

bool AutoStart::Remove(const std::string& autostart_filename) {
  scoped_ptr<base::Environment> environment(base::Environment::Create());
  FilePath autostart_directory = GetAutostartDirectory(environment.get());
  FilePath autostart_file = autostart_directory.Append(autostart_filename);
  return file_util::Delete(autostart_file, false);
}
<|endoftext|>


<commit_before>/* sdlxyz.h, SDL image loader for XYZ files.
   Copyright (C) 2018 EasyRPG Project <https://github.com/EasyRPG/>.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#include "sdlxyz.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <zlib.h>

static SDL_Surface* XYZLoaderMakeSurface(int w, int h, unsigned char * data) {
	SDL_Surface* sf = SDL_CreateRGBSurface(0, w, h, 8, 0, 0, 0, 0);
	if (sf) {
		SDL_Palette * palette = sf->format->palette;
		// According to SDL_Surface's remarks,
		//  no lock is needed unless RLE-optimized,
		//  so we can just avoid that potential error case.
		for (int i = 0; i < 256; i++) {
			palette->colors[i].r = data[(i * 3) + 0];
			palette->colors[i].g = data[(i * 3) + 1];
			palette->colors[i].b = data[(i * 3) + 2];
			palette->colors[i].a = 255;
		}
		memcpy(sf->pixels, data + 768, w * h);
	}
	return sf;
}

static SDL_Surface* XYZLoaderCore(FILE* f) {
	fseek(f, 0, SEEK_END);
	long compressedDataSize = ftell(f) - 8;
	fseek(f, 0, SEEK_SET);
	// Read header
	if (fgetc(f) != 'X')
		return NULL;
	if (fgetc(f) != 'Y')
		return NULL;
	if (fgetc(f) != 'Z')
		return NULL;
	if (fgetc(f) != '1')
		return NULL;
	int tmp, w, h;
	tmp = fgetc(f);
	if (tmp < 0)
		return NULL;
	w = tmp;
	tmp = fgetc(f);
	if (tmp < 0)
		return NULL;
	w |= tmp << 8;
	tmp = fgetc(f);
	if (tmp < 0)
		return NULL;
	h = tmp;
	tmp = fgetc(f);
	if (tmp < 0)
		return NULL;
	h |= tmp << 8;
	size_t total = 768 + (w * h);
	size_t totalBackup = total;
	// Now the room for error has mostly ceded, allocate & fill buffers
	unsigned char * compressedData = (unsigned char *) malloc(compressedDataSize);
	if (!compressedData)
		return NULL;
	if (fread(compressedData, compressedDataSize, 1, f) != 1) {
		free(compressedData);
		return NULL;
	}
	unsigned char * decompressedData = (unsigned char *) malloc(total);
	if (!decompressedData) {
		free(compressedData);
		return NULL;
	}
	int status = uncompress(decompressedData, &total, compressedData, compressedDataSize);
	SDL_Surface * sf = NULL;
	if (totalBackup != total)
		status = Z_STREAM_END;
	if (status == Z_OK)
		sf = XYZLoaderMakeSurface(w, h, decompressedData);
	free(compressedData);
	free(decompressedData);
	return sf;
}

SDL_Surface* LoadImageXYZ(const char* image_path) {
	FILE* f = fopen(image_path, "rb");
	if (!f)
		return NULL;
	// XYZ
	SDL_Surface* sf = XYZLoaderCore(f);
	fclose(f);
	return sf;
}

<commit_msg>Use ZLib types<commit_after>/* sdlxyz.h, SDL image loader for XYZ files.
   Copyright (C) 2018 EasyRPG Project <https://github.com/EasyRPG/>.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#include "sdlxyz.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <zlib.h>

static SDL_Surface* XYZLoaderMakeSurface(int w, int h, unsigned char * data) {
	SDL_Surface* sf = SDL_CreateRGBSurface(0, w, h, 8, 0, 0, 0, 0);
	if (sf) {
		SDL_Palette * palette = sf->format->palette;
		// According to SDL_Surface's remarks,
		//  no lock is needed unless RLE-optimized,
		//  so we can just avoid that potential error case.
		for (int i = 0; i < 256; i++) {
			palette->colors[i].r = data[(i * 3) + 0];
			palette->colors[i].g = data[(i * 3) + 1];
			palette->colors[i].b = data[(i * 3) + 2];
			palette->colors[i].a = 255;
		}
		memcpy(sf->pixels, data + 768, w * h);
	}
	return sf;
}

static SDL_Surface* XYZLoaderCore(FILE* f) {
	fseek(f, 0, SEEK_END);
	long compressedDataSize = ftell(f) - 8;
	fseek(f, 0, SEEK_SET);
	// Read header
	if (fgetc(f) != 'X')
		return NULL;
	if (fgetc(f) != 'Y')
		return NULL;
	if (fgetc(f) != 'Z')
		return NULL;
	if (fgetc(f) != '1')
		return NULL;
	int tmp, w, h;
	tmp = fgetc(f);
	if (tmp < 0)
		return NULL;
	w = tmp;
	tmp = fgetc(f);
	if (tmp < 0)
		return NULL;
	w |= tmp << 8;
	tmp = fgetc(f);
	if (tmp < 0)
		return NULL;
	h = tmp;
	tmp = fgetc(f);
	if (tmp < 0)
		return NULL;
	h |= tmp << 8;
	uLongf total = 768 + (w * h);
	uLongf totalBackup = total;
	// Now the room for error has mostly ceded, allocate & fill buffers
	Bytef * compressedData = (Bytef *) malloc(compressedDataSize);
	if (!compressedData)
		return NULL;
	if (fread(compressedData, compressedDataSize, 1, f) != 1) {
		free(compressedData);
		return NULL;
	}
	Bytef * decompressedData = (Bytef *) malloc(total);
	if (!decompressedData) {
		free(compressedData);
		return NULL;
	}
	int status = uncompress(decompressedData, &total, compressedData, compressedDataSize);
	SDL_Surface * sf = NULL;
	if (totalBackup != total)
		status = Z_STREAM_END;
	if (status == Z_OK)
		sf = XYZLoaderMakeSurface(w, h, decompressedData);
	free(compressedData);
	free(decompressedData);
	return sf;
}

SDL_Surface* LoadImageXYZ(const char* image_path) {
	FILE* f = fopen(image_path, "rb");
	if (!f)
		return NULL;
	// XYZ
	SDL_Surface* sf = XYZLoaderCore(f);
	fclose(f);
	return sf;
}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: xlconst.hxx,v $
 *
 *  $Revision: 1.25 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 19:35:35 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef SC_XLCONST_HXX
#define SC_XLCONST_HXX

#ifndef SC_ADDRESS_HXX
#include "address.hxx"
#endif

// Common =====================================================================

// BIFF versions --------------------------------------------------------------

/** An enumeration for all Excel file format types (BIFF types). */
enum XclBiff
{
    EXC_BIFF2 = 0,              /// MS Excel 2.1
    EXC_BIFF3,                  /// MS Excel 3.0
    EXC_BIFF4,                  /// MS Excel 4.0
    EXC_BIFF5,                  /// MS Excel 5.0, MS Excel 7.0 (95)
    EXC_BIFF8,                  /// MS Excel 8.0 (97), 9.0 (2000), 10.0 (XP), 11.0 (2003)
    EXC_BIFF_UNKNOWN            /// Unknown BIFF version.
};

// Excel sheet dimensions -----------------------------------------------------

const SCCOL EXC_MAXCOL2                     = 255;
const SCROW EXC_MAXROW2                     = 16383;
const SCTAB EXC_MAXTAB2                     = 0;

const SCCOL EXC_MAXCOL3                     = EXC_MAXCOL2;
const SCROW EXC_MAXROW3                     = EXC_MAXROW2;
const SCTAB EXC_MAXTAB3                     = EXC_MAXTAB2;

const SCCOL EXC_MAXCOL4                     = EXC_MAXCOL3;
const SCROW EXC_MAXROW4                     = EXC_MAXROW3;
const SCTAB EXC_MAXTAB4                     = 32767;

const SCCOL EXC_MAXCOL5                     = EXC_MAXCOL4;
const SCROW EXC_MAXROW5                     = EXC_MAXROW4;
const SCTAB EXC_MAXTAB5                     = EXC_MAXTAB4;

const SCCOL EXC_MAXCOL8                     = EXC_MAXCOL5;
const SCROW EXC_MAXROW8                     = 65535;
const SCTAB EXC_MAXTAB8                     = EXC_MAXTAB5;

const sal_uInt16 EXC_NOTAB                  = SAL_MAX_UINT16;   /// An invalid Excel sheet index, for common use.
const SCTAB SCTAB_INVALID                   = SCTAB_MAX;        /// An invalid Calc sheet index, for common use.
const SCTAB SCTAB_GLOBAL                    = SCTAB_MAX;        /// A Calc sheet index for the workbook globals.

// Storage/stream names -------------------------------------------------------

#define EXC_STORAGE_VBA_PROJECT             CREATE_STRING( "_VBA_PROJECT_CUR" )
#define EXC_STORAGE_VBA                     CREATE_STRING( "VBA" )

#define EXC_STREAM_BOOK                     CREATE_STRING( "Book" )
#define EXC_STREAM_WORKBOOK                 CREATE_STRING( "Workbook" )
#define EXC_STREAM_CTLS                     CREATE_STRING( "Ctls" )

// Encoded URLs ---------------------------------------------------------------

const sal_Unicode EXC_URLSTART_ENCODED      = '\x01';   /// Encoded URL.
const sal_Unicode EXC_URLSTART_SELF         = '\x02';   /// Reference to own workbook.
const sal_Unicode EXC_URLSTART_SELFENCODED  = '\x03';   /// Encoded self reference.
const sal_Unicode EXC_URLSTART_OWNDOC       = '\x04';   /// Reference to own workbook (BIFF5/BIFF7).

const sal_Unicode EXC_URL_DOSDRIVE          = '\x01';   /// DOS drive letter or UNC server name.
const sal_Unicode EXC_URL_DRIVEROOT         = '\x02';   /// Root directory of current drive.
const sal_Unicode EXC_URL_SUBDIR            = '\x03';   /// Directory name delimiter.
const sal_Unicode EXC_URL_PARENTDIR         = '\x04';   /// Parent directory.
const sal_Unicode EXC_URL_RAW               = '\x05';   /// Unencoded URL.
const sal_Unicode EXC_URL_SHEETNAME         = '\x09';   /// Sheet name starts here (BIFF4).

const sal_Unicode EXC_DDE_DELIM             = '\x03';   /// DDE application-topic delimiter

// Error codes ----------------------------------------------------------------

const sal_uInt8 EXC_ERR_NULL                = 0x00;
const sal_uInt8 EXC_ERR_DIV0                = 0x07;
const sal_uInt8 EXC_ERR_VALUE               = 0x0F;
const sal_uInt8 EXC_ERR_REF                 = 0x17;
const sal_uInt8 EXC_ERR_NAME                = 0x1D;
const sal_uInt8 EXC_ERR_NUM                 = 0x24;
const sal_uInt8 EXC_ERR_NA                  = 0x2A;

// Cached values list (EXTERNNAME, ptgArray, ...) -----------------------------

const sal_uInt8 EXC_CACHEDVAL_EMPTY         = 0x00;
const sal_uInt8 EXC_CACHEDVAL_DOUBLE        = 0x01;
const sal_uInt8 EXC_CACHEDVAL_STRING        = 0x02;
const sal_uInt8 EXC_CACHEDVAL_BOOL          = 0x04;
const sal_uInt8 EXC_CACHEDVAL_ERROR         = 0x10;

// RK values ------------------------------------------------------------------

const sal_Int32 EXC_RK_100FLAG              = 0x00000001;
const sal_Int32 EXC_RK_INTFLAG              = 0x00000002;
const sal_Int32 EXC_RK_VALUEMASK            = 0xFFFFFFFC;

const sal_Int32 EXC_RK_DBL                  = 0x00000000;
const sal_Int32 EXC_RK_DBL100               = EXC_RK_100FLAG;
const sal_Int32 EXC_RK_INT                  = EXC_RK_INTFLAG;
const sal_Int32 EXC_RK_INT100               = EXC_RK_100FLAG | EXC_RK_INTFLAG;

// Measures -------------------------------------------------------------------

const sal_Int32 EXC_POINTS_PER_INCH         = 72;
const sal_Int32 EXC_TWIPS_PER_INCH          = EXC_POINTS_PER_INCH * 20;

const sal_uInt8 EXC_ROT_BOTTOM_TOP          = 90;       /// Vertical rotation bottom->top.
const sal_uInt8 EXC_ROT_TOP_BOTTOM          = 180;      /// Vertical rotation top->bottom.
const sal_uInt8 EXC_ROT_STACKED             = 0xFF;     /// Characters vertically stacked.

// Records (ordered by lowest record ID) ======================================

// (0x0009, 0x0209, 0x0409, 0x0809) BOF ---------------------------------------

const sal_uInt16 EXC_ID2_BOF                = 0x0009;
const sal_uInt16 EXC_ID3_BOF                = 0x0209;
const sal_uInt16 EXC_ID4_BOF                = 0x0409;
const sal_uInt16 EXC_ID5_BOF                = 0x0809;

const sal_uInt16 EXC_BOF_BIFF2              = 0x0200;
const sal_uInt16 EXC_BOF_BIFF3              = 0x0300;
const sal_uInt16 EXC_BOF_BIFF4              = 0x0400;
const sal_uInt16 EXC_BOF_BIFF5              = 0x0500;
const sal_uInt16 EXC_BOF_BIFF8              = 0x0600;

const sal_uInt16 EXC_BOF_GLOBALS            = 0x0005;   /// BIFF5-BIFF8 workbook globals.
const sal_uInt16 EXC_BOF_VBMODULE           = 0x0006;   /// BIFF5-BIFF8 Visual BASIC module.
const sal_uInt16 EXC_BOF_SHEET              = 0x0010;   /// Simple worksheet.
const sal_uInt16 EXC_BOF_CHART              = 0x0020;   /// Chart-only sheet.
const sal_uInt16 EXC_BOF_MACROSHEET         = 0x0040;   /// BIFF2-BIFF4 macro sheet.
const sal_uInt16 EXC_BOF_WORKSPACE          = 0x0100;   /// BIFF3-BIFF8 workspace file.

// (0x000A) EOF ---------------------------------------------------------------

const sal_uInt16 EXC_ID_EOF                 = 0x000A;

// (0x0012) PROTECT -----------------------------------------------------------

const sal_uInt16 EXC_ID_PROTECT             = 0x0012;

// (0x0013) PASSWORD ----------------------------------------------------------

const sal_uInt16 EXC_ID_PASSWORD            = 0x0013;

// (0x0019) WINDOWPROTECT -----------------------------------------------------

const sal_uInt16 EXC_ID_WINDOWPROTECT       = 0x0019;

// (0x0081) WSBOOL ------------------------------------------------------------

const sal_uInt16 EXC_ID_WSBOOL              = 0x0081;

const sal_uInt16 EXC_WSBOOL_ROWBELOW        = 0x0040;
const sal_uInt16 EXC_WSBOOL_COLBELOW        = 0x0080;
const sal_uInt16 EXC_WSBOOL_FITTOPAGE       = 0x0100;

const sal_uInt16 EXC_WSBOOL_DEFAULTFLAGS    = 0x04C1;

// (0x008C) COUNTRY -----------------------------------------------------------

const sal_uInt16 EXC_ID_COUNTRY             = 0x008C;

// (0x009B) FILTERMODE --------------------------------------------------------

const sal_uInt16 EXC_ID_FILTERMODE          = 0x009B;

// (0x009D) AUTOFILTERINFO ----------------------------------------------------

const sal_uInt16 EXC_ID_AUTOFILTERINFO      = 0x009D;

// (0x009E) AUTOFILTER --------------------------------------------------------

const sal_uInt16 EXC_ID_AUTOFILTER          = 0x009E;

// (0x0160) USESELFS ----------------------------------------------------------

const sal_uInt16 EXC_ID_USESELFS            = 0x0160;

// (0x01AA,0x01AB) USERSVIEWBEGIN, USERSVIEWEND -------------------------------

const sal_uInt16 EXC_ID_USERSVIEWBEGIN      = 0x01AA;
const sal_uInt16 EXC_ID_USERSVIEWEND        = 0x01AB;

// ============================================================================

#endif

<commit_msg>INTEGRATION: CWS dr37 (1.24.36); FILE MERGED 2005/08/09 16:29:55 dr 1.24.36.2: #i47246# drawing layer import reworked 2005/07/20 15:41:42 dr 1.24.36.1: dump workspace files<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: xlconst.hxx,v $
 *
 *  $Revision: 1.26 $
 *
 *  last change: $Author: hr $ $Date: 2005-09-28 12:02:07 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef SC_XLCONST_HXX
#define SC_XLCONST_HXX

#ifndef SC_ADDRESS_HXX
#include "address.hxx"
#endif

// Common =====================================================================

// BIFF versions --------------------------------------------------------------

/** An enumeration for all Excel file format types (BIFF types). */
enum XclBiff
{
    EXC_BIFF2 = 0,              /// MS Excel 2.1
    EXC_BIFF3,                  /// MS Excel 3.0
    EXC_BIFF4,                  /// MS Excel 4.0
    EXC_BIFF5,                  /// MS Excel 5.0, MS Excel 7.0 (95)
    EXC_BIFF8,                  /// MS Excel 8.0 (97), 9.0 (2000), 10.0 (XP), 11.0 (2003)
    EXC_BIFF_UNKNOWN            /// Unknown BIFF version.
};

// Excel sheet dimensions -----------------------------------------------------

const SCCOL EXC_MAXCOL2                     = 255;
const SCROW EXC_MAXROW2                     = 16383;
const SCTAB EXC_MAXTAB2                     = 0;

const SCCOL EXC_MAXCOL3                     = EXC_MAXCOL2;
const SCROW EXC_MAXROW3                     = EXC_MAXROW2;
const SCTAB EXC_MAXTAB3                     = EXC_MAXTAB2;

const SCCOL EXC_MAXCOL4                     = EXC_MAXCOL3;
const SCROW EXC_MAXROW4                     = EXC_MAXROW3;
const SCTAB EXC_MAXTAB4                     = 32767;

const SCCOL EXC_MAXCOL5                     = EXC_MAXCOL4;
const SCROW EXC_MAXROW5                     = EXC_MAXROW4;
const SCTAB EXC_MAXTAB5                     = EXC_MAXTAB4;

const SCCOL EXC_MAXCOL8                     = EXC_MAXCOL5;
const SCROW EXC_MAXROW8                     = 65535;
const SCTAB EXC_MAXTAB8                     = EXC_MAXTAB5;

const sal_uInt16 EXC_NOTAB                  = SAL_MAX_UINT16;   /// An invalid Excel sheet index, for common use.
const SCTAB SCTAB_INVALID                   = SCTAB_MAX;        /// An invalid Calc sheet index, for common use.
const SCTAB SCTAB_GLOBAL                    = SCTAB_MAX;        /// A Calc sheet index for the workbook globals.

// Storage/stream names -------------------------------------------------------

#define EXC_STORAGE_OLE_LINKED              CREATE_STRING( "LNK" )
#define EXC_STORAGE_OLE_EMBEDDED            CREATE_STRING( "MBD" )
#define EXC_STORAGE_VBA_PROJECT             CREATE_STRING( "_VBA_PROJECT_CUR" )
#define EXC_STORAGE_VBA                     CREATE_STRING( "VBA" )

#define EXC_STREAM_BOOK                     CREATE_STRING( "Book" )
#define EXC_STREAM_WORKBOOK                 CREATE_STRING( "Workbook" )
#define EXC_STREAM_CTLS                     CREATE_STRING( "Ctls" )

// Encoded URLs ---------------------------------------------------------------

const sal_Unicode EXC_URLSTART_ENCODED      = '\x01';   /// Encoded URL.
const sal_Unicode EXC_URLSTART_SELF         = '\x02';   /// Reference to own workbook.
const sal_Unicode EXC_URLSTART_SELFENCODED  = '\x03';   /// Encoded self reference.
const sal_Unicode EXC_URLSTART_OWNDOC       = '\x04';   /// Reference to own workbook (BIFF5/BIFF7).

const sal_Unicode EXC_URL_DOSDRIVE          = '\x01';   /// DOS drive letter or UNC server name.
const sal_Unicode EXC_URL_DRIVEROOT         = '\x02';   /// Root directory of current drive.
const sal_Unicode EXC_URL_SUBDIR            = '\x03';   /// Directory name delimiter.
const sal_Unicode EXC_URL_PARENTDIR         = '\x04';   /// Parent directory.
const sal_Unicode EXC_URL_RAW               = '\x05';   /// Unencoded URL.
const sal_Unicode EXC_URL_SHEETNAME         = '\x09';   /// Sheet name starts here (BIFF4).

const sal_Unicode EXC_DDE_DELIM             = '\x03';   /// DDE application-topic delimiter

// Error codes ----------------------------------------------------------------

const sal_uInt8 EXC_ERR_NULL                = 0x00;
const sal_uInt8 EXC_ERR_DIV0                = 0x07;
const sal_uInt8 EXC_ERR_VALUE               = 0x0F;
const sal_uInt8 EXC_ERR_REF                 = 0x17;
const sal_uInt8 EXC_ERR_NAME                = 0x1D;
const sal_uInt8 EXC_ERR_NUM                 = 0x24;
const sal_uInt8 EXC_ERR_NA                  = 0x2A;

// Cached values list (EXTERNNAME, ptgArray, ...) -----------------------------

const sal_uInt8 EXC_CACHEDVAL_EMPTY         = 0x00;
const sal_uInt8 EXC_CACHEDVAL_DOUBLE        = 0x01;
const sal_uInt8 EXC_CACHEDVAL_STRING        = 0x02;
const sal_uInt8 EXC_CACHEDVAL_BOOL          = 0x04;
const sal_uInt8 EXC_CACHEDVAL_ERROR         = 0x10;

// RK values ------------------------------------------------------------------

const sal_Int32 EXC_RK_100FLAG              = 0x00000001;
const sal_Int32 EXC_RK_INTFLAG              = 0x00000002;
const sal_Int32 EXC_RK_VALUEMASK            = 0xFFFFFFFC;

const sal_Int32 EXC_RK_DBL                  = 0x00000000;
const sal_Int32 EXC_RK_DBL100               = EXC_RK_100FLAG;
const sal_Int32 EXC_RK_INT                  = EXC_RK_INTFLAG;
const sal_Int32 EXC_RK_INT100               = EXC_RK_100FLAG | EXC_RK_INTFLAG;

// Measures -------------------------------------------------------------------

const sal_Int32 EXC_POINTS_PER_INCH         = 72;
const sal_Int32 EXC_TWIPS_PER_INCH          = EXC_POINTS_PER_INCH * 20;

const sal_uInt8 EXC_ROT_BOTTOM_TOP          = 90;       /// Vertical rotation bottom->top.
const sal_uInt8 EXC_ROT_TOP_BOTTOM          = 180;      /// Vertical rotation top->bottom.
const sal_uInt8 EXC_ROT_STACKED             = 0xFF;     /// Characters vertically stacked.

// Records (ordered by lowest record ID) ======================================

// (0x0009, 0x0209, 0x0409, 0x0809) BOF ---------------------------------------

const sal_uInt16 EXC_ID2_BOF                = 0x0009;
const sal_uInt16 EXC_ID3_BOF                = 0x0209;
const sal_uInt16 EXC_ID4_BOF                = 0x0409;
const sal_uInt16 EXC_ID5_BOF                = 0x0809;

const sal_uInt16 EXC_BOF_BIFF2              = 0x0200;
const sal_uInt16 EXC_BOF_BIFF3              = 0x0300;
const sal_uInt16 EXC_BOF_BIFF4              = 0x0400;
const sal_uInt16 EXC_BOF_BIFF5              = 0x0500;
const sal_uInt16 EXC_BOF_BIFF8              = 0x0600;

const sal_uInt16 EXC_BOF_GLOBALS            = 0x0005;   /// BIFF5-BIFF8 workbook globals.
const sal_uInt16 EXC_BOF_VBMODULE           = 0x0006;   /// BIFF5-BIFF8 Visual BASIC module.
const sal_uInt16 EXC_BOF_SHEET              = 0x0010;   /// Regular worksheet.
const sal_uInt16 EXC_BOF_CHART              = 0x0020;   /// Chart sheet.
const sal_uInt16 EXC_BOF_MACROSHEET         = 0x0040;   /// Macro sheet.
const sal_uInt16 EXC_BOF_WORKSPACE          = 0x0100;   /// Workspace.
const sal_uInt16 EXC_BOF_UNKNOWN            = 0xFFFF;   /// Internal use only.

// (0x000A) EOF ---------------------------------------------------------------

const sal_uInt16 EXC_ID_EOF                 = 0x000A;

// (0x0012) PROTECT -----------------------------------------------------------

const sal_uInt16 EXC_ID_PROTECT             = 0x0012;

// (0x0013) PASSWORD ----------------------------------------------------------

const sal_uInt16 EXC_ID_PASSWORD            = 0x0013;

// (0x0019) WINDOWPROTECT -----------------------------------------------------

const sal_uInt16 EXC_ID_WINDOWPROTECT       = 0x0019;

// (0x0081) WSBOOL ------------------------------------------------------------

const sal_uInt16 EXC_ID_WSBOOL              = 0x0081;

const sal_uInt16 EXC_WSBOOL_ROWBELOW        = 0x0040;
const sal_uInt16 EXC_WSBOOL_COLBELOW        = 0x0080;
const sal_uInt16 EXC_WSBOOL_FITTOPAGE       = 0x0100;

const sal_uInt16 EXC_WSBOOL_DEFAULTFLAGS    = 0x04C1;

// (0x008C) COUNTRY -----------------------------------------------------------

const sal_uInt16 EXC_ID_COUNTRY             = 0x008C;

// (0x009B) FILTERMODE --------------------------------------------------------

const sal_uInt16 EXC_ID_FILTERMODE          = 0x009B;

// (0x009D) AUTOFILTERINFO ----------------------------------------------------

const sal_uInt16 EXC_ID_AUTOFILTERINFO      = 0x009D;

// (0x009E) AUTOFILTER --------------------------------------------------------

const sal_uInt16 EXC_ID_AUTOFILTER          = 0x009E;

// (0x0160) USESELFS ----------------------------------------------------------

const sal_uInt16 EXC_ID_USESELFS            = 0x0160;

// (0x01AA,0x01AB) USERSVIEWBEGIN, USERSVIEWEND -------------------------------

const sal_uInt16 EXC_ID_USERSVIEWBEGIN      = 0x01AA;
const sal_uInt16 EXC_ID_USERSVIEWEND        = 0x01AB;

// ============================================================================

#endif

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: xlconst.hxx,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: hr $ $Date: 2003-11-05 13:42:39 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (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.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

// ============================================================================

#ifndef SC_XLCONST_HXX
#define SC_XLCONST_HXX

#ifndef _SAL_TYPES_H_
#include <sal/types.h>
#endif

// Common =====================================================================

// Excel sheet dimensions -----------------------------------------------------

const sal_uInt16 EXC_MAXCOL_BIFF2           = 255;
const sal_uInt16 EXC_MAXROW_BIFF2           = 16383;
const sal_uInt16 EXC_MAXTAB_BIFF2           = 0;

const sal_uInt16 EXC_MAXCOL_BIFF4           = EXC_MAXCOL_BIFF2;
const sal_uInt16 EXC_MAXROW_BIFF4           = EXC_MAXROW_BIFF2;
const sal_uInt16 EXC_MAXTAB_BIFF4           = 32767;

const sal_uInt16 EXC_MAXCOL_BIFF8           = EXC_MAXCOL_BIFF4;
const sal_uInt16 EXC_MAXROW_BIFF8           = 65535;
const sal_uInt16 EXC_MAXTAB_BIFF8           = EXC_MAXTAB_BIFF4;

const sal_uInt16 EXC_NOTAB                  = 0xFFFF;   /// An invalid sheet index, for common use.

// In/out stream --------------------------------------------------------------

const sal_uInt32 RECORD_SEEK_TO_BEGIN       = 0UL;
const sal_uInt32 RECORD_SEEK_TO_END         = ~0UL;

const sal_uInt16 EXC_MAXRECSIZE_BIFF5       = 2080;
const sal_uInt16 EXC_MAXRECSIZE_BIFF8       = 8224;

const sal_uInt16 EXC_ID_UNKNOWN             = 0xFFFF;
const sal_uInt16 EXC_ID_CONT                = 0x003C;

// String import/export -------------------------------------------------------

/** Flags used to specify import/export mode of strings. */
typedef sal_uInt16                          XclStrFlags;
const XclStrFlags EXC_STR_DEFAULT           = 0x0000;   /// Default string settings.
const XclStrFlags EXC_STR_FORCEUNICODE      = 0x0001;   /// Always use UCS-2 characters (default: try to compress). BIFF8 only.
const XclStrFlags EXC_STR_8BITLENGTH        = 0x0002;   /// 8-bit string length field (default: 16-bit).
const XclStrFlags EXC_STR_SMARTFLAGS        = 0x0004;   /// Omit flags on empty string (default: read/write always). BIFF8 only.

const sal_uInt8 EXC_STRF_16BIT              = 0x01;
const sal_uInt8 EXC_STRF_FAREAST            = 0x04;
const sal_uInt8 EXC_STRF_RICH               = 0x08;
const sal_uInt8 EXC_STRF_UNKNOWN            = 0xF2;

// Fixed-size characters
const sal_uInt8 EXC_LF_C                    = '\x0A';       /// LF character (used for line break).
const sal_uInt16 EXC_LF                     = EXC_LF_C;     /// LF character (unicode).
const sal_uInt8 EXC_NUL_C                   = '\x00';       /// NUL chararcter.
const sal_uInt16 EXC_NUL                    = EXC_NUL_C;    /// NUL chararcter (unicode).

// Encoded URLs ---------------------------------------------------------------

const sal_Unicode EXC_URLSTART_ENCODED      = '\x01';   /// Encoded URL.
const sal_Unicode EXC_URLSTART_SELF         = '\x02';   /// Reference to own workbook.
const sal_Unicode EXC_URLSTART_SELFENCODED  = '\x03';   /// Encoded self reference.

const sal_Unicode EXC_URL_DOSDRIVE          = '\x01';   /// DOS drive letter or UNC server name.
const sal_Unicode EXC_URL_DRIVEROOT         = '\x02';   /// Root directory of current drive.
const sal_Unicode EXC_URL_SUBDIR            = '\x03';   /// Directory name delimiter.
const sal_Unicode EXC_URL_PARENTDIR         = '\x04';   /// Parent directory.
const sal_Unicode EXC_URL_MACVOLUME         = '\x05';   /// MAC volume name.
const sal_Unicode EXC_URL_SHEETNAME         = '\x09';   /// Sheet name starts here (BIFF4).

const sal_Unicode EXC_DDE_DELIM             = '\x03';   /// DDE application-topic delimiter

// Cached values list (EXTERNNAME, ptgArray, ...) -----------------------------

const sal_uInt8 EXC_CACHEDVAL_EMPTY         = 0x00;
const sal_uInt8 EXC_CACHEDVAL_DOUBLE        = 0x01;
const sal_uInt8 EXC_CACHEDVAL_STRING        = 0x02;
const sal_uInt8 EXC_CACHEDVAL_BOOL          = 0x04;
const sal_uInt8 EXC_CACHEDVAL_ERROR         = 0x10;

// Measures -------------------------------------------------------------------

const sal_Int32 EXC_POINTS_PER_INCH         = 72;
const sal_Int32 EXC_TWIPS_PER_INCH          = EXC_POINTS_PER_INCH * 20;

// Line styles ----------------------------------------------------------------

const sal_uInt8 EXC_LINE_NONE               = 0x00;
const sal_uInt8 EXC_LINE_THIN               = 0x01;
const sal_uInt8 EXC_LINE_MEDIUM             = 0x02;
const sal_uInt8 EXC_LINE_THICK              = 0x05;
const sal_uInt8 EXC_LINE_DOUBLE             = 0x06;
const sal_uInt8 EXC_LINE_HAIR               = 0x07;

// Background patterns --------------------------------------------------------

const sal_uInt8 EXC_PATT_NONE               = 0x00;
const sal_uInt8 EXC_PATT_SOLID              = 0x01;
const sal_uInt8 EXC_PATT_50_PERC            = 0x02;
const sal_uInt8 EXC_PATT_75_PERC            = 0x03;
const sal_uInt8 EXC_PATT_25_PERC            = 0x04;
const sal_uInt8 EXC_PATT_12_5_PERC          = 0x11;
const sal_uInt8 EXC_PATT_6_25_PERC          = 0x12;

// Records (ordered by lowest record ID) ======================================

// (0x0007, 0x0207) STRING ----------------------------------------------------

const sal_uInt16 EXC_ID_STRING              = 0x0207;

// (0x001C) NOTE --------------------------------------------------------------

const sal_uInt16 EXC_ID_NOTE                = 0x001C;
const sal_uInt16 EXC_NOTE_VISIBLE           = 0x0002;

// (0x0012, 0x0019) PROTECT and WINDOWPROTECT --------------------

const sal_uInt16 EXC_ID_PROTECT             = 0x0012;
const sal_uInt16 EXC_ID_WINDOWPROTECT       = 0x0019;

// (0x0055) DEFCOLWIDTH -------------------------------------------------------

const sal_uInt16 EXC_ID_DEFCOLWIDTH         = 0x0055;

// (0x007D) COLINFO -----------------------------------------------------------

const sal_uInt16 EXC_ID_COLINFO             = 0x007D;

const sal_uInt16 EXC_COLINFO_HIDDEN         = 0x0001;
const sal_uInt16 EXC_COLINFO_COLLAPSED      = 0x1000;

// (0x007E) RK ----------------------------------------------------------------

const sal_Int32 EXC_RK_100FLAG              = 0x00000001;
const sal_Int32 EXC_RK_INTFLAG              = 0x00000002;
const sal_Int32 EXC_RK_VALUEMASK            = 0xFFFFFFFC;

const sal_Int32 EXC_RK_DBL                  = 0x00000000;
const sal_Int32 EXC_RK_DBL100               = EXC_RK_100FLAG;
const sal_Int32 EXC_RK_INT                  = EXC_RK_INTFLAG;
const sal_Int32 EXC_RK_INT100               = EXC_RK_100FLAG | EXC_RK_INTFLAG;

// (0x0081) WSBOOL ------------------------------------------------------------

const sal_uInt16 EXC_ID_WSBOOL              = 0x0081;

const sal_uInt16 EXC_WSBOOL_ROWBELOW        = 0x0040;
const sal_uInt16 EXC_WSBOOL_COLBELOW        = 0x0080;
const sal_uInt16 EXC_WSBOOL_FITTOPAGE       = 0x0100;

const sal_uInt16 EXC_WSBOOL_DEFAULTFLAGS    = 0x04C1;

// (0x008C) COUNTRY -----------------------------------------------------------

const sal_uInt16 EXC_ID_COUNTRY             = 0x008C;

// ============================================================================

#endif

<commit_msg>INTEGRATION: CWS calcrtl (1.9.20); FILE MERGED 2003/11/27 11:23:15 nn 1.9.20.2: RESYNC: (1.9-1.10); FILE MERGED 2003/10/10 15:33:57 dr 1.9.20.1: #i1967# first preparations for >32000 rows<commit_after>/*************************************************************************
 *
 *  $RCSfile: xlconst.hxx,v $
 *
 *  $Revision: 1.11 $
 *
 *  last change: $Author: hr $ $Date: 2004-02-03 12:27:31 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (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.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

// ============================================================================

#ifndef SC_XLCONST_HXX
#define SC_XLCONST_HXX

#ifndef _SAL_TYPES_H_
#include <sal/types.h>
#endif

// global.hxx can be removed if SC*** typedefs are there
#ifndef SC_SCGLOB_HXX
#include "global.hxx"
#endif

// Common =====================================================================

typedef USHORT SCCOL;
const SCCOL SCMAXCOL = MAXCOL;
const SCCOL SCCOLCOUNT = SCMAXCOL + 1;

typedef USHORT SCROW;
const SCROW SCMAXROW = MAXROW;
const SCROW SCROWCOUNT = SCMAXROW + 1;

typedef USHORT SCTAB;
const SCTAB SCMAXTAB = MAXTAB;
const SCTAB SCTABCOUNT = SCMAXTAB + 1;

// remember to remove the #include "global.hxx" above

// Excel sheet dimensions -----------------------------------------------------

const sal_uInt16 EXC_MAXCOL2                = 255;
const sal_uInt16 EXC_MAXROW2                = 16383;
const sal_uInt16 EXC_MAXTAB2                = 0;

const sal_uInt16 EXC_MAXCOL3                = EXC_MAXCOL2;
const sal_uInt16 EXC_MAXROW3                = EXC_MAXROW2;
const sal_uInt16 EXC_MAXTAB3                = EXC_MAXTAB2;

const sal_uInt16 EXC_MAXCOL4                = EXC_MAXCOL3;
const sal_uInt16 EXC_MAXROW4                = EXC_MAXROW3;
const sal_uInt16 EXC_MAXTAB4                = 32767;

const sal_uInt16 EXC_MAXCOL5                = EXC_MAXCOL4;
const sal_uInt16 EXC_MAXROW5                = EXC_MAXROW4;
const sal_uInt16 EXC_MAXTAB5                = EXC_MAXTAB4;

const sal_uInt16 EXC_MAXCOL8                = EXC_MAXCOL5;
const sal_uInt16 EXC_MAXROW8                = 65535;
const sal_uInt16 EXC_MAXTAB8                = EXC_MAXTAB5;

const sal_uInt16 EXC_NOTAB                  = 0xFFFF;   /// An invalid sheet index, for common use.

// In/out stream --------------------------------------------------------------

const sal_uInt32 RECORD_SEEK_TO_BEGIN       = 0;
const sal_uInt32 RECORD_SEEK_TO_END         = ~RECORD_SEEK_TO_BEGIN;

const sal_uInt16 EXC_MAXRECSIZE_BIFF5       = 2080;
const sal_uInt16 EXC_MAXRECSIZE_BIFF8       = 8224;

const sal_uInt16 EXC_ID_UNKNOWN             = 0xFFFF;
const sal_uInt16 EXC_ID_CONT                = 0x003C;

// String import/export -------------------------------------------------------

/** Flags used to specify import/export mode of strings. */
typedef sal_uInt16                          XclStrFlags;
const XclStrFlags EXC_STR_DEFAULT           = 0x0000;   /// Default string settings.
const XclStrFlags EXC_STR_FORCEUNICODE      = 0x0001;   /// Always use UCS-2 characters (default: try to compress). BIFF8 only.
const XclStrFlags EXC_STR_8BITLENGTH        = 0x0002;   /// 8-bit string length field (default: 16-bit).
const XclStrFlags EXC_STR_SMARTFLAGS        = 0x0004;   /// Omit flags on empty string (default: read/write always). BIFF8 only.

const sal_uInt8 EXC_STRF_16BIT              = 0x01;
const sal_uInt8 EXC_STRF_FAREAST            = 0x04;
const sal_uInt8 EXC_STRF_RICH               = 0x08;
const sal_uInt8 EXC_STRF_UNKNOWN            = 0xF2;

// Fixed-size characters
const sal_uInt8 EXC_LF_C                    = '\x0A';       /// LF character (used for line break).
const sal_uInt16 EXC_LF                     = EXC_LF_C;     /// LF character (unicode).
const sal_uInt8 EXC_NUL_C                   = '\x00';       /// NUL chararcter.
const sal_uInt16 EXC_NUL                    = EXC_NUL_C;    /// NUL chararcter (unicode).

// Encoded URLs ---------------------------------------------------------------

const sal_Unicode EXC_URLSTART_ENCODED      = '\x01';   /// Encoded URL.
const sal_Unicode EXC_URLSTART_SELF         = '\x02';   /// Reference to own workbook.
const sal_Unicode EXC_URLSTART_SELFENCODED  = '\x03';   /// Encoded self reference.

const sal_Unicode EXC_URL_DOSDRIVE          = '\x01';   /// DOS drive letter or UNC server name.
const sal_Unicode EXC_URL_DRIVEROOT         = '\x02';   /// Root directory of current drive.
const sal_Unicode EXC_URL_SUBDIR            = '\x03';   /// Directory name delimiter.
const sal_Unicode EXC_URL_PARENTDIR         = '\x04';   /// Parent directory.
const sal_Unicode EXC_URL_MACVOLUME         = '\x05';   /// MAC volume name.
const sal_Unicode EXC_URL_SHEETNAME         = '\x09';   /// Sheet name starts here (BIFF4).

const sal_Unicode EXC_DDE_DELIM             = '\x03';   /// DDE application-topic delimiter

// Cached values list (EXTERNNAME, ptgArray, ...) -----------------------------

const sal_uInt8 EXC_CACHEDVAL_EMPTY         = 0x00;
const sal_uInt8 EXC_CACHEDVAL_DOUBLE        = 0x01;
const sal_uInt8 EXC_CACHEDVAL_STRING        = 0x02;
const sal_uInt8 EXC_CACHEDVAL_BOOL          = 0x04;
const sal_uInt8 EXC_CACHEDVAL_ERROR         = 0x10;

// Measures -------------------------------------------------------------------

const sal_Int32 EXC_POINTS_PER_INCH         = 72;
const sal_Int32 EXC_TWIPS_PER_INCH          = EXC_POINTS_PER_INCH * 20;

// Records (ordered by lowest record ID) ======================================

// (0x0007, 0x0207) STRING ----------------------------------------------------

const sal_uInt16 EXC_ID_STRING              = 0x0207;

// (0x001C) NOTE --------------------------------------------------------------

const sal_uInt16 EXC_ID_NOTE                = 0x001C;
const sal_uInt16 EXC_NOTE_VISIBLE           = 0x0002;

// (0x0012, 0x0019) PROTECT and WINDOWPROTECT --------------------

const sal_uInt16 EXC_ID_PROTECT             = 0x0012;
const sal_uInt16 EXC_ID_WINDOWPROTECT       = 0x0019;

// (0x0055) DEFCOLWIDTH -------------------------------------------------------

const sal_uInt16 EXC_ID_DEFCOLWIDTH         = 0x0055;

// (0x007D) COLINFO -----------------------------------------------------------

const sal_uInt16 EXC_ID_COLINFO             = 0x007D;

const sal_uInt16 EXC_COLINFO_HIDDEN         = 0x0001;
const sal_uInt16 EXC_COLINFO_COLLAPSED      = 0x1000;

// (0x007E) RK ----------------------------------------------------------------

const sal_Int32 EXC_RK_100FLAG              = 0x00000001;
const sal_Int32 EXC_RK_INTFLAG              = 0x00000002;
const sal_Int32 EXC_RK_VALUEMASK            = 0xFFFFFFFC;

const sal_Int32 EXC_RK_DBL                  = 0x00000000;
const sal_Int32 EXC_RK_DBL100               = EXC_RK_100FLAG;
const sal_Int32 EXC_RK_INT                  = EXC_RK_INTFLAG;
const sal_Int32 EXC_RK_INT100               = EXC_RK_100FLAG | EXC_RK_INTFLAG;

// (0x0081) WSBOOL ------------------------------------------------------------

const sal_uInt16 EXC_ID_WSBOOL              = 0x0081;

const sal_uInt16 EXC_WSBOOL_ROWBELOW        = 0x0040;
const sal_uInt16 EXC_WSBOOL_COLBELOW        = 0x0080;
const sal_uInt16 EXC_WSBOOL_FITTOPAGE       = 0x0100;

const sal_uInt16 EXC_WSBOOL_DEFAULTFLAGS    = 0x04C1;

// (0x008C) COUNTRY -----------------------------------------------------------

const sal_uInt16 EXC_ID_COUNTRY             = 0x008C;

// ============================================================================

#endif

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: tpstat.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 20:51:02 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#undef SC_DLLIMPLEMENTATION

#ifdef PCH
#include "ui_pch.hxx"
#endif

#pragma hdrstop

#include "document.hxx"
#include "docsh.hxx"
#include "scresid.hxx"
#include "tpstat.hrc"

#include "tpstat.hxx"

//========================================================================
// Dokumentinfo-Tabpage:
//========================================================================

SfxTabPage* __EXPORT ScDocStatPage::Create( Window *pParent, const SfxItemSet& rSet )
{
    return new ScDocStatPage( pParent, rSet );
}

//------------------------------------------------------------------------

ScDocStatPage::ScDocStatPage( Window *pParent, const SfxItemSet& rSet )
    :   SfxTabPage( pParent, ScResId(RID_SCPAGE_STAT), rSet ),
        aFtTablesLbl    ( this, ScResId( FT_TABLES_LBL ) ),
        aFtTables       ( this, ScResId( FT_TABLES ) ),
        aFtCellsLbl     ( this, ScResId( FT_CELLS_LBL ) ),
        aFtCells        ( this, ScResId( FT_CELLS ) ),
        aFtPagesLbl     ( this, ScResId( FT_PAGES_LBL ) ),
        aFtPages        ( this, ScResId( FT_PAGES ) ),
        aFlInfo         ( this, ScResId( FL_INFO ) )
{
    ScDocShell* pDocSh = PTR_CAST( ScDocShell, SfxObjectShell::Current() );
    ScDocStat   aDocStat;

    if ( pDocSh )
        pDocSh->GetDocStat( aDocStat );

    String aInfo = aFlInfo.GetText();
    aInfo += aDocStat.aDocName;
    aFlInfo     .SetText( aInfo );
    aFtTables   .SetText( String::CreateFromInt32( aDocStat.nTableCount ) );
    aFtCells    .SetText( String::CreateFromInt32( aDocStat.nCellCount ) );
    aFtPages    .SetText( String::CreateFromInt32( aDocStat.nPageCount ) );

    FreeResource();
}

//------------------------------------------------------------------------

__EXPORT ScDocStatPage::~ScDocStatPage()
{
}

//------------------------------------------------------------------------

BOOL __EXPORT ScDocStatPage::FillItemSet( SfxItemSet& rSet )
{
    return FALSE;
}

//------------------------------------------------------------------------

void __EXPORT ScDocStatPage::Reset( const SfxItemSet& rSet )
{
}

<commit_msg>INTEGRATION: CWS pchfix01 (1.4.214); FILE MERGED 2006/07/12 10:02:35 kaib 1.4.214.1: #i67080# Converted cxx files in sc, added initial project level pch and stripped old PCH definitions.<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: tpstat.cxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: kz $ $Date: 2006-07-21 13:46:19 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sc.hxx"

#undef SC_DLLIMPLEMENTATION

#include "document.hxx"
#include "docsh.hxx"
#include "scresid.hxx"
#include "tpstat.hrc"

#include "tpstat.hxx"

//========================================================================
// Dokumentinfo-Tabpage:
//========================================================================

SfxTabPage* __EXPORT ScDocStatPage::Create( Window *pParent, const SfxItemSet& rSet )
{
    return new ScDocStatPage( pParent, rSet );
}

//------------------------------------------------------------------------

ScDocStatPage::ScDocStatPage( Window *pParent, const SfxItemSet& rSet )
    :   SfxTabPage( pParent, ScResId(RID_SCPAGE_STAT), rSet ),
        aFtTablesLbl    ( this, ScResId( FT_TABLES_LBL ) ),
        aFtTables       ( this, ScResId( FT_TABLES ) ),
        aFtCellsLbl     ( this, ScResId( FT_CELLS_LBL ) ),
        aFtCells        ( this, ScResId( FT_CELLS ) ),
        aFtPagesLbl     ( this, ScResId( FT_PAGES_LBL ) ),
        aFtPages        ( this, ScResId( FT_PAGES ) ),
        aFlInfo         ( this, ScResId( FL_INFO ) )
{
    ScDocShell* pDocSh = PTR_CAST( ScDocShell, SfxObjectShell::Current() );
    ScDocStat   aDocStat;

    if ( pDocSh )
        pDocSh->GetDocStat( aDocStat );

    String aInfo = aFlInfo.GetText();
    aInfo += aDocStat.aDocName;
    aFlInfo     .SetText( aInfo );
    aFtTables   .SetText( String::CreateFromInt32( aDocStat.nTableCount ) );
    aFtCells    .SetText( String::CreateFromInt32( aDocStat.nCellCount ) );
    aFtPages    .SetText( String::CreateFromInt32( aDocStat.nPageCount ) );

    FreeResource();
}

//------------------------------------------------------------------------

__EXPORT ScDocStatPage::~ScDocStatPage()
{
}

//------------------------------------------------------------------------

BOOL __EXPORT ScDocStatPage::FillItemSet( SfxItemSet& rSet )
{
    return FALSE;
}

//------------------------------------------------------------------------

void __EXPORT ScDocStatPage::Reset( const SfxItemSet& rSet )
{
}

<|endoftext|>


<commit_before>// Copyright (c) 2017 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.

#include "atom/browser/net/url_request_stream_job.h"

#include <algorithm>
#include <memory>
#include <ostream>
#include <string>
#include <utility>

#include "atom/common/api/event_emitter_caller.h"
#include "atom/common/atom_constants.h"
#include "atom/common/native_mate_converters/net_converter.h"
#include "atom/common/node_includes.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "native_mate/dictionary.h"
#include "net/base/net_errors.h"
#include "net/filter/gzip_source_stream.h"

namespace atom {

namespace {

void BeforeStartInUI(base::WeakPtr<URLRequestStreamJob> job,
                     mate::Arguments* args) {
  v8::Local<v8::Value> value;
  int error = net::OK;
  bool ended = false;
  if (!args->GetNext(&value) || !value->IsObject()) {
    // Invalid opts.
    content::BrowserThread::PostTask(
        content::BrowserThread::IO, FROM_HERE,
        base::BindOnce(&URLRequestStreamJob::OnError, job, net::ERR_FAILED));
    return;
  }

  mate::Dictionary opts(args->isolate(), v8::Local<v8::Object>::Cast(value));
  int status_code;
  if (!opts.Get("statusCode", &status_code)) {
    // assume HTTP OK if statusCode is not passed.
    status_code = 200;
  }
  std::string status("HTTP/1.1 ");
  status.append(base::IntToString(status_code));
  status.append(" ");
  status.append(
      net::GetHttpReasonPhrase(static_cast<net::HttpStatusCode>(status_code)));
  status.append("\0\0", 2);
  scoped_refptr<net::HttpResponseHeaders> response_headers(
      new net::HttpResponseHeaders(status));

  if (opts.Get("headers", &value)) {
    mate::Converter<net::HttpResponseHeaders*>::FromV8(args->isolate(), value,
                                                       response_headers.get());
  }

  if (!opts.Get("data", &value)) {
    // Assume the opts is already a stream
    value = opts.GetHandle();
  } else if (value->IsNullOrUndefined()) {
    // "data" was explicitly passed as null or undefined, assume the user wants
    // to send an empty body.
    ended = true;
    content::BrowserThread::PostTask(
        content::BrowserThread::IO, FROM_HERE,
        base::BindOnce(&URLRequestStreamJob::StartAsync, job, nullptr,
                       base::RetainedRef(response_headers), ended, error));
    return;
  }

  mate::Dictionary data(args->isolate(), v8::Local<v8::Object>::Cast(value));
  if (!data.Get("on", &value) || !value->IsFunction() ||
      !data.Get("removeListener", &value) || !value->IsFunction()) {
    // If data is passed but it is not a stream, signal an error.
    content::BrowserThread::PostTask(
        content::BrowserThread::IO, FROM_HERE,
        base::BindOnce(&URLRequestStreamJob::OnError, job, net::ERR_FAILED));
    return;
  }

  auto subscriber = std::make_unique<mate::StreamSubscriber>(
      args->isolate(), data.GetHandle(), job);

  content::BrowserThread::PostTask(
      content::BrowserThread::IO, FROM_HERE,
      base::BindOnce(&URLRequestStreamJob::StartAsync, job,
                     std::move(subscriber), base::RetainedRef(response_headers),
                     ended, error));
}

}  // namespace

URLRequestStreamJob::URLRequestStreamJob(net::URLRequest* request,
                                         net::NetworkDelegate* network_delegate)
    : net::URLRequestJob(request, network_delegate),
      pending_buf_(nullptr),
      pending_buf_size_(0),
      ended_(false),
      response_headers_(nullptr),
      weak_factory_(this) {}

URLRequestStreamJob::~URLRequestStreamJob() {
  if (subscriber_) {
    content::BrowserThread::DeleteSoon(content::BrowserThread::UI, FROM_HERE,
                                       std::move(subscriber_));
  }
}

void URLRequestStreamJob::Start() {
  auto request_details = std::make_unique<base::DictionaryValue>();
  FillRequestDetails(request_details.get(), request());
  content::BrowserThread::PostTask(
      content::BrowserThread::UI, FROM_HERE,
      base::BindOnce(&JsAsker::AskForOptions, base::Unretained(isolate()),
                     handler(), std::move(request_details),
                     base::Bind(&BeforeStartInUI, weak_factory_.GetWeakPtr())));
}

void URLRequestStreamJob::StartAsync(
    std::unique_ptr<mate::StreamSubscriber> subscriber,
    scoped_refptr<net::HttpResponseHeaders> response_headers,
    bool ended,
    int error) {
  if (error != net::OK) {
    NotifyStartError(
        net::URLRequestStatus(net::URLRequestStatus::FAILED, error));
    return;
  }

  ended_ = ended;
  response_headers_ = response_headers;
  subscriber_ = std::move(subscriber);
  request_start_time_ = base::TimeTicks::Now();
  NotifyHeadersComplete();
}

void URLRequestStreamJob::OnData(std::vector<char>&& buffer) {  // NOLINT
  if (write_buffer_.empty()) {
    // Quick branch without copying.
    write_buffer_ = std::move(buffer);
  } else {
    // write_buffer_ += buffer
    size_t len = write_buffer_.size();
    write_buffer_.resize(len + buffer.size());
    std::copy(buffer.begin(), buffer.end(), write_buffer_.begin() + len);
  }

  // Copy to output.
  if (pending_buf_) {
    int len = BufferCopy(&write_buffer_, pending_buf_.get(), pending_buf_size_);
    write_buffer_.erase(write_buffer_.begin(), write_buffer_.begin() + len);
    ReadRawDataComplete(len);
  }
}

void URLRequestStreamJob::OnEnd() {
  ended_ = true;
  ReadRawDataComplete(0);
}

void URLRequestStreamJob::OnError(int error) {
  NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, error));
}

int URLRequestStreamJob::ReadRawData(net::IOBuffer* dest, int dest_size) {
  response_start_time_ = base::TimeTicks::Now();

  if (ended_)
    return 0;

  // When write_buffer_ is empty, there is no data valable yet, we have to save
  // the dest buffer util DataAvailable.
  if (write_buffer_.empty()) {
    pending_buf_ = dest;
    pending_buf_size_ = dest_size;
    return net::ERR_IO_PENDING;
  }

  // Read from the write buffer and clear them after reading.
  int len = BufferCopy(&write_buffer_, dest, dest_size);
  write_buffer_.erase(write_buffer_.begin(), write_buffer_.begin() + len);
  return len;
}

void URLRequestStreamJob::DoneReading() {
  content::BrowserThread::DeleteSoon(content::BrowserThread::UI, FROM_HERE,
                                     std::move(subscriber_));
  write_buffer_.clear();
}

void URLRequestStreamJob::DoneReadingRedirectResponse() {
  DoneReading();
}

std::unique_ptr<net::SourceStream> URLRequestStreamJob::SetUpSourceStream() {
  std::unique_ptr<net::SourceStream> source =
      net::URLRequestJob::SetUpSourceStream();
  size_t i = 0;
  std::string type;
  while (response_headers_->EnumerateHeader(&i, "Content-Encoding", &type)) {
    if (base::LowerCaseEqualsASCII(type, "gzip") ||
        base::LowerCaseEqualsASCII(type, "x-gzip")) {
      return net::GzipSourceStream::Create(std::move(source),
                                           net::SourceStream::TYPE_GZIP);
    } else if (base::LowerCaseEqualsASCII(type, "deflate")) {
      return net::GzipSourceStream::Create(std::move(source),
                                           net::SourceStream::TYPE_DEFLATE);
    }
  }
  return source;
}

bool URLRequestStreamJob::GetMimeType(std::string* mime_type) const {
  return response_headers_->GetMimeType(mime_type);
}

int URLRequestStreamJob::GetResponseCode() const {
  return response_headers_->response_code();
}

void URLRequestStreamJob::GetResponseInfo(net::HttpResponseInfo* info) {
  info->headers = response_headers_;
}

void URLRequestStreamJob::GetLoadTimingInfo(
    net::LoadTimingInfo* load_timing_info) const {
  load_timing_info->send_start = request_start_time_;
  load_timing_info->send_end = request_start_time_;
  load_timing_info->request_start = request_start_time_;
  load_timing_info->receive_headers_end = response_start_time_;
}

void URLRequestStreamJob::Kill() {
  weak_factory_.InvalidateWeakPtrs();
  net::URLRequestJob::Kill();
}

int URLRequestStreamJob::BufferCopy(std::vector<char>* source,
                                    net::IOBuffer* target,
                                    int target_size) {
  int bytes_written = std::min(static_cast<int>(source->size()), target_size);
  memcpy(target->data(), source->data(), bytes_written);
  return bytes_written;
}

}  // namespace atom
<commit_msg>fix: don't call ReadRawDataComplete if it's not necessary (#15185)<commit_after>// Copyright (c) 2017 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.

#include "atom/browser/net/url_request_stream_job.h"

#include <algorithm>
#include <memory>
#include <ostream>
#include <string>
#include <utility>

#include "atom/common/api/event_emitter_caller.h"
#include "atom/common/atom_constants.h"
#include "atom/common/native_mate_converters/net_converter.h"
#include "atom/common/node_includes.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "native_mate/dictionary.h"
#include "net/base/net_errors.h"
#include "net/filter/gzip_source_stream.h"

namespace atom {

namespace {

void BeforeStartInUI(base::WeakPtr<URLRequestStreamJob> job,
                     mate::Arguments* args) {
  v8::Local<v8::Value> value;
  int error = net::OK;
  bool ended = false;
  if (!args->GetNext(&value) || !value->IsObject()) {
    // Invalid opts.
    content::BrowserThread::PostTask(
        content::BrowserThread::IO, FROM_HERE,
        base::BindOnce(&URLRequestStreamJob::OnError, job, net::ERR_FAILED));
    return;
  }

  mate::Dictionary opts(args->isolate(), v8::Local<v8::Object>::Cast(value));
  int status_code;
  if (!opts.Get("statusCode", &status_code)) {
    // assume HTTP OK if statusCode is not passed.
    status_code = 200;
  }
  std::string status("HTTP/1.1 ");
  status.append(base::IntToString(status_code));
  status.append(" ");
  status.append(
      net::GetHttpReasonPhrase(static_cast<net::HttpStatusCode>(status_code)));
  status.append("\0\0", 2);
  scoped_refptr<net::HttpResponseHeaders> response_headers(
      new net::HttpResponseHeaders(status));

  if (opts.Get("headers", &value)) {
    mate::Converter<net::HttpResponseHeaders*>::FromV8(args->isolate(), value,
                                                       response_headers.get());
  }

  if (!opts.Get("data", &value)) {
    // Assume the opts is already a stream
    value = opts.GetHandle();
  } else if (value->IsNullOrUndefined()) {
    // "data" was explicitly passed as null or undefined, assume the user wants
    // to send an empty body.
    ended = true;
    content::BrowserThread::PostTask(
        content::BrowserThread::IO, FROM_HERE,
        base::BindOnce(&URLRequestStreamJob::StartAsync, job, nullptr,
                       base::RetainedRef(response_headers), ended, error));
    return;
  }

  mate::Dictionary data(args->isolate(), v8::Local<v8::Object>::Cast(value));
  if (!data.Get("on", &value) || !value->IsFunction() ||
      !data.Get("removeListener", &value) || !value->IsFunction()) {
    // If data is passed but it is not a stream, signal an error.
    content::BrowserThread::PostTask(
        content::BrowserThread::IO, FROM_HERE,
        base::BindOnce(&URLRequestStreamJob::OnError, job, net::ERR_FAILED));
    return;
  }

  auto subscriber = std::make_unique<mate::StreamSubscriber>(
      args->isolate(), data.GetHandle(), job);

  content::BrowserThread::PostTask(
      content::BrowserThread::IO, FROM_HERE,
      base::BindOnce(&URLRequestStreamJob::StartAsync, job,
                     std::move(subscriber), base::RetainedRef(response_headers),
                     ended, error));
}

}  // namespace

URLRequestStreamJob::URLRequestStreamJob(net::URLRequest* request,
                                         net::NetworkDelegate* network_delegate)
    : net::URLRequestJob(request, network_delegate),
      pending_buf_(nullptr),
      pending_buf_size_(0),
      ended_(false),
      response_headers_(nullptr),
      weak_factory_(this) {}

URLRequestStreamJob::~URLRequestStreamJob() {
  if (subscriber_) {
    content::BrowserThread::DeleteSoon(content::BrowserThread::UI, FROM_HERE,
                                       std::move(subscriber_));
  }
}

void URLRequestStreamJob::Start() {
  auto request_details = std::make_unique<base::DictionaryValue>();
  FillRequestDetails(request_details.get(), request());
  content::BrowserThread::PostTask(
      content::BrowserThread::UI, FROM_HERE,
      base::BindOnce(&JsAsker::AskForOptions, base::Unretained(isolate()),
                     handler(), std::move(request_details),
                     base::Bind(&BeforeStartInUI, weak_factory_.GetWeakPtr())));
}

void URLRequestStreamJob::StartAsync(
    std::unique_ptr<mate::StreamSubscriber> subscriber,
    scoped_refptr<net::HttpResponseHeaders> response_headers,
    bool ended,
    int error) {
  if (error != net::OK) {
    NotifyStartError(
        net::URLRequestStatus(net::URLRequestStatus::FAILED, error));
    return;
  }

  ended_ = ended;
  response_headers_ = response_headers;
  subscriber_ = std::move(subscriber);
  request_start_time_ = base::TimeTicks::Now();
  NotifyHeadersComplete();
}

void URLRequestStreamJob::OnData(std::vector<char>&& buffer) {  // NOLINT
  if (write_buffer_.empty()) {
    // Quick branch without copying.
    write_buffer_ = std::move(buffer);
  } else {
    // write_buffer_ += buffer
    size_t len = write_buffer_.size();
    write_buffer_.resize(len + buffer.size());
    std::copy(buffer.begin(), buffer.end(), write_buffer_.begin() + len);
  }

  // Copy to output.
  if (pending_buf_) {
    int len = BufferCopy(&write_buffer_, pending_buf_.get(), pending_buf_size_);
    write_buffer_.erase(write_buffer_.begin(), write_buffer_.begin() + len);
    pending_buf_ = nullptr;
    pending_buf_size_ = 0;
    ReadRawDataComplete(len);
  }
}

void URLRequestStreamJob::OnEnd() {
  ended_ = true;
  if (pending_buf_) {
    ReadRawDataComplete(0);
  }
}

void URLRequestStreamJob::OnError(int error) {
  NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, error));
}

int URLRequestStreamJob::ReadRawData(net::IOBuffer* dest, int dest_size) {
  response_start_time_ = base::TimeTicks::Now();

  if (ended_)
    return 0;

  // When write_buffer_ is empty, there is no data valable yet, we have to save
  // the dest buffer util DataAvailable.
  if (write_buffer_.empty()) {
    pending_buf_ = dest;
    pending_buf_size_ = dest_size;
    return net::ERR_IO_PENDING;
  }

  // Read from the write buffer and clear them after reading.
  int len = BufferCopy(&write_buffer_, dest, dest_size);
  write_buffer_.erase(write_buffer_.begin(), write_buffer_.begin() + len);
  return len;
}

void URLRequestStreamJob::DoneReading() {
  content::BrowserThread::DeleteSoon(content::BrowserThread::UI, FROM_HERE,
                                     std::move(subscriber_));
  write_buffer_.clear();
}

void URLRequestStreamJob::DoneReadingRedirectResponse() {
  DoneReading();
}

std::unique_ptr<net::SourceStream> URLRequestStreamJob::SetUpSourceStream() {
  std::unique_ptr<net::SourceStream> source =
      net::URLRequestJob::SetUpSourceStream();
  size_t i = 0;
  std::string type;
  while (response_headers_->EnumerateHeader(&i, "Content-Encoding", &type)) {
    if (base::LowerCaseEqualsASCII(type, "gzip") ||
        base::LowerCaseEqualsASCII(type, "x-gzip")) {
      return net::GzipSourceStream::Create(std::move(source),
                                           net::SourceStream::TYPE_GZIP);
    } else if (base::LowerCaseEqualsASCII(type, "deflate")) {
      return net::GzipSourceStream::Create(std::move(source),
                                           net::SourceStream::TYPE_DEFLATE);
    }
  }
  return source;
}

bool URLRequestStreamJob::GetMimeType(std::string* mime_type) const {
  return response_headers_->GetMimeType(mime_type);
}

int URLRequestStreamJob::GetResponseCode() const {
  return response_headers_->response_code();
}

void URLRequestStreamJob::GetResponseInfo(net::HttpResponseInfo* info) {
  info->headers = response_headers_;
}

void URLRequestStreamJob::GetLoadTimingInfo(
    net::LoadTimingInfo* load_timing_info) const {
  load_timing_info->send_start = request_start_time_;
  load_timing_info->send_end = request_start_time_;
  load_timing_info->request_start = request_start_time_;
  load_timing_info->receive_headers_end = response_start_time_;
}

void URLRequestStreamJob::Kill() {
  weak_factory_.InvalidateWeakPtrs();
  net::URLRequestJob::Kill();
}

int URLRequestStreamJob::BufferCopy(std::vector<char>* source,
                                    net::IOBuffer* target,
                                    int target_size) {
  int bytes_written = std::min(static_cast<int>(source->size()), target_size);
  memcpy(target->data(), source->data(), bytes_written);
  return bytes_written;
}

}  // namespace atom
<|endoftext|>