<commit_before>// __BEGIN_LICENSE__
// Copyright (C) 2006-2010 United States Government as represented by
// the Administrator of the National Aeronautics and Space Administration.
// All Rights Reserved.
// __END_LICENSE__

/// \file dem_profile2.cc
///

// Standard
#include <iostream>

// Vision Workbench
#include <vw/Image.h>
#include <vw/FileIO.h>
#include <vw/Cartography.h>
using namespace vw;

// Boost
#include <boost/program_options.hpp>
namespace po = boost::program_options;

// Main
int main ( int argc, char *argv[] ) {

  std::string input_file;
  std::string start_ll, end_ll;
  std::string start_px, end_px;
  double idx_column, idx_row;
  double nodata_value;

  po::variables_map vm;

  po::options_description general_options("Options");
  general_options.add_options()
    ("col", po::value<double>(&idx_column), "Process only a single column at this index")
    ("row", po::value<double>(&idx_row), "Process only a single row at this index")
    ("nodata-value", po::value<double>(&nodata_value), "Set the nodata value that is used in the DEM")
    //("ll-start", po::value<std::string>(&start_ll), "Start a profile at this Lon Lat location")
    //("ll-end", po::value<std::string>(&end_ll), "End a profile at this Lon Lat location")
    ("px-start", po::value<std::string>(&start_px)->composing(), "Start a profile at this pixel location")
    ("px-end", po::value<std::string>(&end_px), "End a profile at this pixel location")
    ("help,h", "Display this help message");

  po::options_description hidden_options("");
  hidden_options.add_options()
    ("input-dem", po::value<std::string>(&input_file));

  po::options_description options("Allowed Options");
  options.add(general_options).add(hidden_options);

  po::positional_options_description pos;
  pos.add("input-dem", 1);

  po::store( po::command_line_parser( argc, argv ).options(options).positional(pos).run(), vm );
  po::notify( vm );

  std::ostringstream usage;
  usage << "Usage: " << argv[0] << " <dem-file> [options] \n\n";
  usage << general_options << "\n";

  if ( vm.count("help") || !vm.count("input-dem") ) {
    vw_out() << usage.str() << "\n";
    return 1;
  } else if ( vm.count("ll-start") ^ vm.count("ll-end") ) {
    vw_out() << "Must specify both ends if creating a Lat Lon Profile!\n";
    vw_out() << usage.str() << "\n";
    return 1;
  } else if ( vm.count("px-start") ^ vm.count("px-end") ) {
    vw_out() << "Must specify both ends if creating a Pixel Profile!\n";
    vw_out() << usage.str() << "\n";
    return 1;
  } else if ( vm.count("ll-start") && ( start_ll.size() != 2 ||
                                        end_ll.size() != 2 ) ) {
    vw_out() << "Start and End Lon Lat locations require 2 values, longitude and latitude.\n";
  }

  // Finally starting to perform some work
  cartography::GeoReference georef;
  cartography::read_georeference(georef, input_file);
  DiskImageView<float> disk_dem_file( input_file );
  ImageViewRef<PixelMask<float> > dem;
  if ( vm.count("nodata-value") ) {
    vw_out() << "\t--> Masking nodata value: " << nodata_value << "\n";
    dem = interpolate(create_mask( disk_dem_file, nodata_value ),
                      BicubicInterpolation(),
                      ZeroEdgeExtension());
  } else {
    DiskImageResource *disk_dem_rsrc = DiskImageResource::open(input_file);
    if ( disk_dem_rsrc->has_nodata_value() ) {
      nodata_value = disk_dem_rsrc->nodata_value();
      vw_out() << "\t--> Extracted nodata value from file: " << nodata_value << "\n";
      dem = interpolate(create_mask( disk_dem_file, nodata_value ),
                        BicubicInterpolation(),
                        ZeroEdgeExtension());
    } else {
      dem = interpolate(pixel_cast<PixelMask<float> >(disk_dem_file),
                        BicubicInterpolation(),
                        ZeroEdgeExtension());
    }
  }

  Vector2 start, end; // Pixel Locations (everything boils down to it
                      // at the moment :/. Maybe in the future where
                      // flying cars are possible, when a user
                      // provides LL coordinates .. SLERP is used.
  if ( vm.count("col") ) {
    start = Vector2(idx_column, 0);
    end = Vector2(idx_column, dem.rows()-1);
  } else if ( vm.count("row") ) {
    start = Vector2(0,idx_row);
    end = Vector2(dem.cols()-1,idx_row);
  } else if ( vm.count("ll-start") && vm.count("ll-end") ) {
    // Parsing string into a ll coordinate.
    if ( start_ll.find(',') == std::string::npos ||
         end_ll.find(',') == std::string::npos ) {
      vw_out() << "Longitude and Latitude values must be delimited by a comma.\n";
      vw_out() << "\tEx: --ll-start -109.54,33.483\n\n";
      vw_out() << usage.str() << "\n";
      return 1;
    }

    size_t s_break = start_px.find(',');
    size_t e_break = end_px.find(',');

    Vector2 ll_start, ll_end;

  } else if ( vm.count("px-start") && vm.count("px-end") ) {
    // Parsing string into pixel coordinates.
    if ( start_px.find(',') == std::string::npos ||
         end_px.find(',') == std::string::npos ) {
      vw_out() << "Column and Row pixel values must be delimited by a comma.\n";
      vw_out() << "\tEx: --px-start 65,109\n\n";
      vw_out() << usage.str() << "\n";
      return 1;
    }

    size_t s_break = start_px.find(',');
    size_t e_break = end_px.find(',');

    start.x() = atof(start_px.substr(0,s_break).c_str());
    start.y() = atof(start_px.substr(s_break+1, start_px.size()-s_break-1).c_str());
    end.x() = atof(end_px.substr(0,e_break).c_str());
    end.y() = atof(end_px.substr(e_break+1, end_px.size()-e_break-1).c_str());
  } else {
    // Dial down the middle if the user provides only a DEM.
    start = Vector2( dem.cols()/2, 0);
    end = Vector2( dem.cols()/2, dem.rows()-1);
  }

  // Debug
  vw_out() << "Start: " << start << "\n";
  vw_out() << "End:   " << end << "\n";

  // Working out the output file
  BBox2i bound = bounding_box( dem );
  if ( !bound.contains( start ) ||
       !bound.contains( end ) ) {
    vw_out() << "Given coordinates are not with in the image!\nExiting early .....\n";
    return 1;
  }

  std::ofstream output_file( "profile.csv" );
  output_file << std::setprecision(12) << "lon,lat,pix_x,pix_y,altitude,radius\n";

  Vector2i delta = end - start;
  for ( float r = 0; r < 1.0; r +=1/norm_2(delta) ) {
    Vector2 c_idx = Vector2(0.5,0.5) + start + r*delta;

    if ( !dem(int(c_idx.x()),int(c_idx.y())).valid() )
      continue;

    Vector2 lonlat_loc = georef.pixel_to_lonlat( c_idx );
    double altitude = dem( c_idx.x(), c_idx.y() );
    Vector3 xyz_pos = georef.datum().geodetic_to_cartesian( Vector3( lonlat_loc.x(),
                                                                     lonlat_loc.y(),
                                                                     altitude ));
    double radius = norm_2( xyz_pos );

    output_file << lonlat_loc.x() << "," << lonlat_loc.y() << "," << c_idx.x()
                << "," << c_idx.y() << "," << altitude << "," << radius << "\n";
  }
  output_file.close();

  return 0;
}
<commit_msg>Missed one correction for nodata<commit_after>// __BEGIN_LICENSE__
// Copyright (C) 2006-2010 United States Government as represented by
// the Administrator of the National Aeronautics and Space Administration.
// All Rights Reserved.
// __END_LICENSE__

/// \file dem_profile2.cc
///

// Standard
#include <iostream>

// Vision Workbench
#include <vw/Image.h>
#include <vw/FileIO.h>
#include <vw/Cartography.h>
using namespace vw;

// Boost
#include <boost/program_options.hpp>
namespace po = boost::program_options;

// Main
int main ( int argc, char *argv[] ) {

  std::string input_file;
  std::string start_ll, end_ll;
  std::string start_px, end_px;
  double idx_column, idx_row;
  double nodata_value;

  po::variables_map vm;

  po::options_description general_options("Options");
  general_options.add_options()
    ("col", po::value<double>(&idx_column), "Process only a single column at this index")
    ("row", po::value<double>(&idx_row), "Process only a single row at this index")
    ("nodata-value", po::value<double>(&nodata_value), "Set the nodata value that is used in the DEM")
    //("ll-start", po::value<std::string>(&start_ll), "Start a profile at this Lon Lat location")
    //("ll-end", po::value<std::string>(&end_ll), "End a profile at this Lon Lat location")
    ("px-start", po::value<std::string>(&start_px)->composing(), "Start a profile at this pixel location")
    ("px-end", po::value<std::string>(&end_px), "End a profile at this pixel location")
    ("help,h", "Display this help message");

  po::options_description hidden_options("");
  hidden_options.add_options()
    ("input-dem", po::value<std::string>(&input_file));

  po::options_description options("Allowed Options");
  options.add(general_options).add(hidden_options);

  po::positional_options_description pos;
  pos.add("input-dem", 1);

  po::store( po::command_line_parser( argc, argv ).options(options).positional(pos).run(), vm );
  po::notify( vm );

  std::ostringstream usage;
  usage << "Usage: " << argv[0] << " <dem-file> [options] \n\n";
  usage << general_options << "\n";

  if ( vm.count("help") || !vm.count("input-dem") ) {
    vw_out() << usage.str() << "\n";
    return 1;
  } else if ( vm.count("ll-start") ^ vm.count("ll-end") ) {
    vw_out() << "Must specify both ends if creating a Lat Lon Profile!\n";
    vw_out() << usage.str() << "\n";
    return 1;
  } else if ( vm.count("px-start") ^ vm.count("px-end") ) {
    vw_out() << "Must specify both ends if creating a Pixel Profile!\n";
    vw_out() << usage.str() << "\n";
    return 1;
  } else if ( vm.count("ll-start") && ( start_ll.size() != 2 ||
                                        end_ll.size() != 2 ) ) {
    vw_out() << "Start and End Lon Lat locations require 2 values, longitude and latitude.\n";
  }

  // Finally starting to perform some work
  cartography::GeoReference georef;
  cartography::read_georeference(georef, input_file);
  DiskImageView<float> disk_dem_file( input_file );
  ImageViewRef<PixelMask<float> > dem;
  if ( vm.count("nodata-value") ) {
    vw_out() << "\t--> Masking nodata value: " << nodata_value << "\n";
    dem = interpolate(create_mask( disk_dem_file, nodata_value ),
                      BicubicInterpolation(),
                      ZeroEdgeExtension());
  } else {
    DiskImageResource *disk_dem_rsrc = DiskImageResource::open(input_file);
    if ( disk_dem_rsrc->has_nodata_read() ) {
      nodata_value = disk_dem_rsrc->nodata_read();
      vw_out() << "\t--> Extracted nodata value from file: " << nodata_value << "\n";
      dem = interpolate(create_mask( disk_dem_file, nodata_value ),
                        BicubicInterpolation(),
                        ZeroEdgeExtension());
    } else {
      dem = interpolate(pixel_cast<PixelMask<float> >(disk_dem_file),
                        BicubicInterpolation(),
                        ZeroEdgeExtension());
    }
  }

  Vector2 start, end; // Pixel Locations (everything boils down to it
                      // at the moment :/. Maybe in the future where
                      // flying cars are possible, when a user
                      // provides LL coordinates .. SLERP is used.
  if ( vm.count("col") ) {
    start = Vector2(idx_column, 0);
    end = Vector2(idx_column, dem.rows()-1);
  } else if ( vm.count("row") ) {
    start = Vector2(0,idx_row);
    end = Vector2(dem.cols()-1,idx_row);
  } else if ( vm.count("ll-start") && vm.count("ll-end") ) {
    // Parsing string into a ll coordinate.
    if ( start_ll.find(',') == std::string::npos ||
         end_ll.find(',') == std::string::npos ) {
      vw_out() << "Longitude and Latitude values must be delimited by a comma.\n";
      vw_out() << "\tEx: --ll-start -109.54,33.483\n\n";
      vw_out() << usage.str() << "\n";
      return 1;
    }

    size_t s_break = start_px.find(',');
    size_t e_break = end_px.find(',');

    Vector2 ll_start, ll_end;

  } else if ( vm.count("px-start") && vm.count("px-end") ) {
    // Parsing string into pixel coordinates.
    if ( start_px.find(',') == std::string::npos ||
         end_px.find(',') == std::string::npos ) {
      vw_out() << "Column and Row pixel values must be delimited by a comma.\n";
      vw_out() << "\tEx: --px-start 65,109\n\n";
      vw_out() << usage.str() << "\n";
      return 1;
    }

    size_t s_break = start_px.find(',');
    size_t e_break = end_px.find(',');

    start.x() = atof(start_px.substr(0,s_break).c_str());
    start.y() = atof(start_px.substr(s_break+1, start_px.size()-s_break-1).c_str());
    end.x() = atof(end_px.substr(0,e_break).c_str());
    end.y() = atof(end_px.substr(e_break+1, end_px.size()-e_break-1).c_str());
  } else {
    // Dial down the middle if the user provides only a DEM.
    start = Vector2( dem.cols()/2, 0);
    end = Vector2( dem.cols()/2, dem.rows()-1);
  }

  // Debug
  vw_out() << "Start: " << start << "\n";
  vw_out() << "End:   " << end << "\n";

  // Working out the output file
  BBox2i bound = bounding_box( dem );
  if ( !bound.contains( start ) ||
       !bound.contains( end ) ) {
    vw_out() << "Given coordinates are not with in the image!\nExiting early .....\n";
    return 1;
  }

  std::ofstream output_file( "profile.csv" );
  output_file << std::setprecision(12) << "lon,lat,pix_x,pix_y,altitude,radius\n";

  Vector2i delta = end - start;
  for ( float r = 0; r < 1.0; r +=1/norm_2(delta) ) {
    Vector2 c_idx = Vector2(0.5,0.5) + start + r*delta;

    if ( !dem(int(c_idx.x()),int(c_idx.y())).valid() )
      continue;

    Vector2 lonlat_loc = georef.pixel_to_lonlat( c_idx );
    double altitude = dem( c_idx.x(), c_idx.y() );
    Vector3 xyz_pos = georef.datum().geodetic_to_cartesian( Vector3( lonlat_loc.x(),
                                                                     lonlat_loc.y(),
                                                                     altitude ));
    double radius = norm_2( xyz_pos );

    output_file << lonlat_loc.x() << "," << lonlat_loc.y() << "," << c_idx.x()
                << "," << c_idx.y() << "," << altitude << "," << radius << "\n";
  }
  output_file.close();

  return 0;
}
<|endoftext|>


<commit_before>#include "stdafx.h"
#include <ctime>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "console.h"
#include "note.h"
#include "text.h"

namespace note {

	void Note::pretty_print() const
	{
		std::string dc = format_time(&m_date_created);
		std::string dm = format_time(&m_date_modified);
		std::string sub_str;
		if (m_text.size() > MAINCOLSIZE)
			sub_str = m_text.substr(0, MAINCOLSIZE - 5) + "...";
		else
			sub_str = m_text;

		std::cout << std::left
			<< std::setw(5) << m_tmpId
			<< std::setw(MAINCOLSIZE) << sub_str
			<< std::setw(DATECOLSIZE) << "[" + dm + "]"
			<< std::setw(DATECOLSIZE) << "[" + dc + "]"
			<< std::endl
			<< std::endl;
	}

	// prints a header for collection / collection list
	void print_header()
	{
		// consider changiing (and resetting) console color? maybe wrap each part in function...
		CONSOLE_SCREEN_BUFFER_INFO csbi;
		change_console_color(11, &csbi);
		std::cout << std::left
			<< std::setw(5) << "#"
			<< std::setw(MAINCOLSIZE) << "Note"
			<< std::setw(DATECOLSIZE) << "Last Modified"
			<< std::setw(DATECOLSIZE) << "Date Created"
			<< std::endl
			<< std::setw(5) << "---"
			<< std::setw(MAINCOLSIZE) << "---"
			<< std::setw(DATECOLSIZE) << "---"
			<< std::setw(DATECOLSIZE) << "---"
			<< std::endl;
		reset_console_color(csbi);
	}

	/**
	 * Serialize the note.
	 */
	std::ostream& operator<< (std::ostream &out, const Note &n) {
		out << n.m_date_created
			<< ','
			<< n.m_date_modified
			<< ','
			<< n.m_text.size()
			<< ','
			<< n.m_text
			<< std::endl;
		return out;
	}

	/**
	 * Deserialize the note.
	 */
	std::istream& operator>> (std::istream &in, Note &n) {
		// TODO: we are losing a character when we read it in!!!
		int len = 0;
		char comma;
		in >> n.m_date_created
			>> comma
			>> n.m_date_modified
			>> comma
			>> len
			>> comma;
		if (in && len) {
			std::vector<char> tmp_txt(len);
			// get seems to work better than read for non-binary...
			in.get(&tmp_txt[0], len);
			n.m_text = std::string(&tmp_txt[0]);
		}
		return in;
	}

	/**
	* Got a little funky here. Wanted to make use of the overloaded i/o operators,
	* but also wanted to inherit base recordable's save methods.
	* So base uses serialize/deserialize member methods (pure virtuals), and
	* derived forms can call them and simply use the friend ops within.
	*/
	std::ostream& Note::serialize(std::ostream &out) const {
		out << *this;
		return out;
	}
	std::istream& Note::deserialize(std::istream &in) {
		in >> *this;
		return in;
	}

	/**
	 * Adds a note to a collection's note file.
	 * Returns false if unable to save.
	 * Command should handle validation of the collection, as
	 * well as any updates to date modified field for the collection.
	 */
	bool add_note(std::string text, std::string path) {
		bool inserted = false;
		Note n(text);
		if (n.save(path))
			inserted = true;
		return inserted;
	}

	/**
	 * Gets all notes in a collection.
	 */
	std::vector<Note> get_all_notes(std::string path) {
		std::vector<Note> notes;
		std::ifstream inf(path);
		if (!inf)
			std::cerr << "Oh no!!! Notesy can't find or open this collection!!! :(" << std::endl << std::endl;
		else {
			Note n;
			int ct = 0;
			while (inf >> n) {
				n.set_tmpId(++ct);
				notes.push_back(n);
				inf.ignore(1, '\n');
			}
			inf.close();
		}
		return notes;
	}

	/**
	* Lists all notes.
	*/
	void list_all_notes(std::vector<Note> &notes)
	{
		print_header();
		// use the const ref so we don't copy
		for (const auto &iter : notes) {
			iter.pretty_print();
		}
	}

	/**
	* Lists all notes.
	*/
	void list_all_notes(std::string path)
	{
		auto notes = get_all_notes(path);
		list_all_notes(notes);
	}
}
<commit_msg>adjust note read for missing last char<commit_after>#include "stdafx.h"
#include <ctime>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "console.h"
#include "note.h"
#include "text.h"

namespace note {

	void Note::pretty_print() const
	{
		std::string dc = format_time(&m_date_created);
		std::string dm = format_time(&m_date_modified);
		std::string sub_str;
		if (m_text.size() > MAINCOLSIZE)
			sub_str = m_text.substr(0, MAINCOLSIZE - 5) + "...";
		else
			sub_str = m_text;

		std::cout << std::left
			<< std::setw(5) << m_tmpId
			<< std::setw(MAINCOLSIZE) << sub_str
			<< std::setw(DATECOLSIZE) << "[" + dm + "]"
			<< std::setw(DATECOLSIZE) << "[" + dc + "]"
			<< std::endl
			<< std::endl;
	}

	// prints a header for collection / collection list
	void print_header()
	{
		// consider changiing (and resetting) console color? maybe wrap each part in function...
		CONSOLE_SCREEN_BUFFER_INFO csbi;
		change_console_color(11, &csbi);
		std::cout << std::left
			<< std::setw(5) << "#"
			<< std::setw(MAINCOLSIZE) << "Note"
			<< std::setw(DATECOLSIZE) << "Last Modified"
			<< std::setw(DATECOLSIZE) << "Date Created"
			<< std::endl
			<< std::setw(5) << "---"
			<< std::setw(MAINCOLSIZE) << "---"
			<< std::setw(DATECOLSIZE) << "---"
			<< std::setw(DATECOLSIZE) << "---"
			<< std::endl;
		reset_console_color(csbi);
	}

	/**
	 * Serialize the note.
	 */
	std::ostream& operator<< (std::ostream &out, const Note &n) {
		out << n.m_date_created
			<< ','
			<< n.m_date_modified
			<< ','
			<< n.m_text.size()
			<< ','
			<< n.m_text
			<< std::endl;
		return out;
	}

	/**
	 * Deserialize the note.
	 */
	std::istream& operator>> (std::istream &in, Note &n) {
		int len = 0;
		char comma;
		in >> n.m_date_created
			>> comma
			>> n.m_date_modified
			>> comma
			>> len
			>> comma;
		if (in && len) {
			std::vector<char> tmp_txt(len);
			// leave room for the null terminator, or buffer will be too small
			char *buf = new char[len + 1];
			in.get(buf, len + 1);
			n.m_text = std::string(buf);
			delete buf;
		}
		return in;
	}

	/**
	* Got a little funky here. Wanted to make use of the overloaded i/o operators,
	* but also wanted to inherit base recordable's save methods.
	* So base uses serialize/deserialize member methods (pure virtuals), and
	* derived forms can call them and simply use the friend ops within.
	*/
	std::ostream& Note::serialize(std::ostream &out) const {
		out << *this;
		return out;
	}
	std::istream& Note::deserialize(std::istream &in) {
		in >> *this;
		return in;
	}

	/**
	 * Adds a note to a collection's note file.
	 * Returns false if unable to save.
	 * Command should handle validation of the collection, as
	 * well as any updates to date modified field for the collection.
	 */
	bool add_note(std::string text, std::string path) {
		bool inserted = false;
		Note n(text);
		if (n.save(path))
			inserted = true;
		return inserted;
	}

	/**
	 * Gets all notes in a collection.
	 */
	std::vector<Note> get_all_notes(std::string path) {
		std::vector<Note> notes;
		std::ifstream inf(path);
		if (!inf)
			std::cerr << "Oh no!!! Notesy can't find or open this collection!!! :(" << std::endl << std::endl;
		else {
			Note n;
			int ct = 0;
			while (inf >> n) {
				n.set_tmpId(++ct);
				notes.push_back(n);
				inf.ignore(1, '\n');
			}
			inf.close();
		}
		return notes;
	}

	/**
	* Lists all notes.
	*/
	void list_all_notes(std::vector<Note> &notes)
	{
		print_header();
		// use the const ref so we don't copy
		for (const auto &iter : notes) {
			iter.pretty_print();
		}
	}

	/**
	* Lists all notes.
	*/
	void list_all_notes(std::string path)
	{
		auto notes = get_all_notes(path);
		list_all_notes(notes);
	}
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: propread.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: sj $ $Date: 2002-11-18 12:58:25 $
 *
 *  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 _PROPREAD_HXX_
#define _PROPREAD_HXX_

#ifndef _SOLAR_H
#include <tools/solar.h>
#endif
#ifndef _SVSTOR_HXX
#include <so3/svstor.hxx>
#endif
#ifndef _SV_GEN_HXX
#include <tools/gen.hxx>
#endif
#ifndef _LIST_HXX
#include <tools/list.hxx>
#endif
#ifndef _STREAM_HXX
#include <tools/stream.hxx>
#endif
#ifndef _DATETIME_HXX
#include <tools/datetime.hxx>
#endif

#include <tools/string.hxx>

// SummaryInformation
#define PID_TITLE               0x02
#define PID_SUBJECT             0x03
#define PID_AUTHOR              0x04
#define PID_KEYWORDS            0x05
#define PID_COMMENTS            0x06
#define PID_TEMPLATE            0x07
#define PID_LASTAUTHOR          0x08
#define PID_REVNUMBER           0x09
#define PID_EDITTIME            0x0a
#define PID_LASTPRINTED_DTM     0x0b
#define PID_CREATE_DTM          0x0c
#define PID_LASTSAVED_DTM       0x0d

// DocumentSummaryInformation
#define PID_CATEGORY            0x02
#define PID_PRESFORMAT          0x03
#define PID_BYTECOUNT           0x04
#define PID_LINECOUNT           0x05
#define PID_PARACOUNT           0x06
#define PID_SLIDECOUNT          0x07
#define PID_NOTECOUNT           0x08
#define PID_HIDDENCOUNT         0x09
#define PID_MMCLIPCOUNT         0x0a
#define PID_SCALE               0x0b
#define PID_HEADINGPAIR         0x0c
#define PID_DOCPARTS            0x0d
#define PID_MANAGER             0x0e
#define PID_COMPANY             0x0f
#define PID_LINKSDIRTY          0x10

#define VT_EMPTY            0
#define VT_NULL             1
#define VT_I2               2
#define VT_I4               3
#define VT_R4               4
#define VT_R8               5
#define VT_CY               6
#define VT_DATE             7
#define VT_BSTR             8
#define VT_UI4              9
#define VT_ERROR            10
#define VT_BOOL             11
#define VT_VARIANT          12
#define VT_DECIMAL          14
#define VT_I1               16
#define VT_UI1              17
#define VT_UI2              18
#define VT_I8               20
#define VT_UI8              21
#define VT_INT              22
#define VT_UINT             23
#define VT_LPSTR            30
#define VT_LPWSTR           31
#define VT_FILETIME         64
#define VT_BLOB             65
#define VT_STREAM           66
#define VT_STORAGE          67
#define VT_STREAMED_OBJECT  68
#define VT_STORED_OBJECT    69
#define VT_BLOB_OBJECT      70
#define VT_CF               71
#define VT_CLSID            72
#define VT_VECTOR           0x1000
#define VT_ARRAY            0x2000
#define VT_BYREF            0x4000
#define VT_TYPEMASK         0xFFF

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

class PropItem : public SvMemoryStream
{
        sal_uInt16      mnTextEnc;

    public :
                        PropItem(){};
        void            Clear();

        void            SetTextEncoding( sal_uInt16 nTextEnc ){ mnTextEnc = nTextEnc; };
        sal_Bool        Read( String& rString, sal_uInt32 nType = VT_EMPTY, sal_Bool bDwordAlign = sal_True );
        PropItem&       operator=( PropItem& rPropItem );
};

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

class Dictionary : protected List
{
    friend class Section;

        void        AddProperty( UINT32 nId, const String& rString );

    public :
                    Dictionary(){};
                    ~Dictionary();
        Dictionary& operator=( Dictionary& rDictionary );
        UINT32      GetProperty( const String& rPropName );
};

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

class Section : private List
{
        sal_uInt16              mnTextEnc;

    protected:

        BYTE                    aFMTID[ 16 ];

        void                    AddProperty( sal_uInt32 nId, const sal_uInt8* pBuf, sal_uInt32 nBufSize );

    public:
                                Section( const sal_uInt8* pFMTID );
                                Section( Section& rSection );
                                ~Section();

        Section&                operator=( Section& rSection );
        sal_Bool                GetProperty( sal_uInt32 nId, PropItem& rPropItem );
        sal_Bool                GetDictionary( Dictionary& rDict );
        const sal_uInt8*        GetFMTID() const { return aFMTID; };
        void                    Read( SvStorageStream* pStrm );
};

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

class PropRead : private List
{
        sal_Bool                mbStatus;
        SvStorageStream*        mpSvStream;

        sal_uInt16              mnByteOrder;
        sal_uInt16              mnFormat;
        sal_uInt16              mnVersionLo;
        sal_uInt16              mnVersionHi;
        sal_uInt8               mApplicationCLSID[ 16 ];

        void                    AddSection( Section& rSection );

    public:
                                PropRead( SvStorage& rSvStorage, const String& rName );
                                ~PropRead();

        PropRead&               operator=( PropRead& rPropRead );
        const Section*          GetSection( const BYTE* pFMTID );
        sal_Bool                IsValid() const { return mbStatus; };
        void                    Read();
};

#endif

<commit_msg>INTEGRATION: CWS mav09 (1.3.386); FILE MERGED 2004/04/14 14:11:55 mba 1.3.386.1: #i27773#: remove so3; new storage API<commit_after>/*************************************************************************
 *
 *  $RCSfile: propread.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: kz $ $Date: 2004-10-04 18:17:45 $
 *
 *  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 _PROPREAD_HXX_
#define _PROPREAD_HXX_

#ifndef _SOLAR_H
#include <tools/solar.h>
#endif
#include <sot/storage.hxx>
#ifndef _SV_GEN_HXX
#include <tools/gen.hxx>
#endif
#ifndef _LIST_HXX
#include <tools/list.hxx>
#endif
#ifndef _STREAM_HXX
#include <tools/stream.hxx>
#endif
#ifndef _DATETIME_HXX
#include <tools/datetime.hxx>
#endif

#include <tools/string.hxx>

// SummaryInformation
#define PID_TITLE               0x02
#define PID_SUBJECT             0x03
#define PID_AUTHOR              0x04
#define PID_KEYWORDS            0x05
#define PID_COMMENTS            0x06
#define PID_TEMPLATE            0x07
#define PID_LASTAUTHOR          0x08
#define PID_REVNUMBER           0x09
#define PID_EDITTIME            0x0a
#define PID_LASTPRINTED_DTM     0x0b
#define PID_CREATE_DTM          0x0c
#define PID_LASTSAVED_DTM       0x0d

// DocumentSummaryInformation
#define PID_CATEGORY            0x02
#define PID_PRESFORMAT          0x03
#define PID_BYTECOUNT           0x04
#define PID_LINECOUNT           0x05
#define PID_PARACOUNT           0x06
#define PID_SLIDECOUNT          0x07
#define PID_NOTECOUNT           0x08
#define PID_HIDDENCOUNT         0x09
#define PID_MMCLIPCOUNT         0x0a
#define PID_SCALE               0x0b
#define PID_HEADINGPAIR         0x0c
#define PID_DOCPARTS            0x0d
#define PID_MANAGER             0x0e
#define PID_COMPANY             0x0f
#define PID_LINKSDIRTY          0x10

#define VT_EMPTY            0
#define VT_NULL             1
#define VT_I2               2
#define VT_I4               3
#define VT_R4               4
#define VT_R8               5
#define VT_CY               6
#define VT_DATE             7
#define VT_BSTR             8
#define VT_UI4              9
#define VT_ERROR            10
#define VT_BOOL             11
#define VT_VARIANT          12
#define VT_DECIMAL          14
#define VT_I1               16
#define VT_UI1              17
#define VT_UI2              18
#define VT_I8               20
#define VT_UI8              21
#define VT_INT              22
#define VT_UINT             23
#define VT_LPSTR            30
#define VT_LPWSTR           31
#define VT_FILETIME         64
#define VT_BLOB             65
#define VT_STREAM           66
#define VT_STORAGE          67
#define VT_STREAMED_OBJECT  68
#define VT_STORED_OBJECT    69
#define VT_BLOB_OBJECT      70
#define VT_CF               71
#define VT_CLSID            72
#define VT_VECTOR           0x1000
#define VT_ARRAY            0x2000
#define VT_BYREF            0x4000
#define VT_TYPEMASK         0xFFF

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

class PropItem : public SvMemoryStream
{
        sal_uInt16      mnTextEnc;

    public :
                        PropItem(){};
        void            Clear();

        void            SetTextEncoding( sal_uInt16 nTextEnc ){ mnTextEnc = nTextEnc; };
        sal_Bool        Read( String& rString, sal_uInt32 nType = VT_EMPTY, sal_Bool bDwordAlign = sal_True );
        PropItem&       operator=( PropItem& rPropItem );
};

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

class Dictionary : protected List
{
    friend class Section;

        void        AddProperty( UINT32 nId, const String& rString );

    public :
                    Dictionary(){};
                    ~Dictionary();
        Dictionary& operator=( Dictionary& rDictionary );
        UINT32      GetProperty( const String& rPropName );
};

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

class Section : private List
{
        sal_uInt16              mnTextEnc;

    protected:

        BYTE                    aFMTID[ 16 ];

        void                    AddProperty( sal_uInt32 nId, const sal_uInt8* pBuf, sal_uInt32 nBufSize );

    public:
                                Section( const sal_uInt8* pFMTID );
                                Section( Section& rSection );
                                ~Section();

        Section&                operator=( Section& rSection );
        sal_Bool                GetProperty( sal_uInt32 nId, PropItem& rPropItem );
        sal_Bool                GetDictionary( Dictionary& rDict );
        const sal_uInt8*        GetFMTID() const { return aFMTID; };
        void                    Read( SvStorageStream* pStrm );
};

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

class PropRead : private List
{
        sal_Bool                mbStatus;
        SvStorageStream*        mpSvStream;

        sal_uInt16              mnByteOrder;
        sal_uInt16              mnFormat;
        sal_uInt16              mnVersionLo;
        sal_uInt16              mnVersionHi;
        sal_uInt8               mApplicationCLSID[ 16 ];

        void                    AddSection( Section& rSection );

    public:
                                PropRead( SvStorage& rSvStorage, const String& rName );
                                ~PropRead();

        PropRead&               operator=( PropRead& rPropRead );
        const Section*          GetSection( const BYTE* pFMTID );
        sal_Bool                IsValid() const { return mbStatus; };
        void                    Read();
};

#endif

<|endoftext|>


<commit_before><commit_msg>coverity#1265810 Dereference null return value<commit_after><|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: fusldlg.cxx,v $
 *
 *  $Revision: 1.1.1.1 $
 *
 *  last change: $Author: hr $ $Date: 2000-09-18 16:48:36 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

#pragma hdrstop

#ifndef _SFXITEMSET_HXX //autogen
#include <svtools/itemset.hxx>
#endif
#ifndef _MSGBOX_HXX //autogen
#include <vcl/msgbox.hxx>
#endif

#include "drawdoc.hxx"
#include "sdpage.hxx"
#include "present.hxx"
#include "sdresid.hxx"
#include "strings.hrc"
#include "sdattr.hxx"
#include "fusldlg.hxx"
#include "glob.hrc"

#include "sdmod.hxx"
#include "viewshel.hxx"
#include "optsitem.hxx"

#define ITEMVALUE(ItemSet,Id,Cast) ((const Cast&)(ItemSet).Get(Id)).GetValue()

TYPEINIT1( FuSlideShowDlg, FuPoor );

/*************************************************************************
|*
|* Konstruktor
|*
\************************************************************************/

FuSlideShowDlg::FuSlideShowDlg( SdViewShell* pViewSh, SdWindow*  pWin,
                                SdView* pView, SdDrawDocument* pDoc, SfxRequest& rReq) :
            FuPoor( pViewSh, pWin, pView, pDoc, rReq )
{
    SfxItemSet      aDlgSet( pDoc->GetPool(), ATTR_PRESENT_START, ATTR_PRESENT_END );
    List            aPageNameList;
    const String&   rPresPage = pDoc->GetPresPage();
    String          aFirstPage;
    String          aStandardName( SdResId( STR_PAGE ) );
    SdPage*         pPage = NULL;
    long            nPage;

    for( nPage = pDoc->GetSdPageCount( PK_STANDARD ) - 1L; nPage >= 0L; nPage-- )
    {
        pPage = pDoc->GetSdPage( (USHORT) nPage, PK_STANDARD );
        String* pStr = new String( pPage->GetName() );

        if ( !pStr->Len() )
        {
            *pStr = String( SdResId( STR_PAGE ) );
            (*pStr).Append( UniString::CreateFromInt32( nPage + 1 ) );
        }

        aPageNameList.Insert( pStr, (ULONG) 0 );

        // ist dies unsere (vorhandene) erste Seite?
        if ( rPresPage == *pStr )
            aFirstPage = rPresPage;
        else if ( pPage->IsSelected() && !aFirstPage.Len() )
            aFirstPage = *pStr;
    }
    List* pCustomShowList = pDoc->GetCustomShowList(); // No Create

    /// NEU
    BOOL bStartWithActualPage = SD_MOD()->GetSdOptions( pDoc->GetDocumentType() )->IsStartWithActualPage();
    if( bStartWithActualPage )
    {
        aFirstPage = pViewSh->GetActualPage()->GetName();
        pCustomShowList = NULL;
    }

    if( !aFirstPage.Len() && pPage )
        aFirstPage = pPage->GetName();

    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_ALL, pDoc->GetPresAll() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_CUSTOMSHOW, pDoc->IsCustomShow() ) );
    aDlgSet.Put( SfxStringItem( ATTR_PRESENT_DIANAME, aFirstPage ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_ENDLESS, pDoc->GetPresEndless() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_MANUEL, pDoc->GetPresManual() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_MOUSE, pDoc->GetPresMouseVisible() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_PEN, pDoc->GetPresMouseAsPen() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_NAVIGATOR, pDoc->GetStartPresWithNavigator() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_ANIMATION_ALLOWED, pDoc->IsAnimationAllowed() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_CHANGE_PAGE, !pDoc->GetPresLockedPages() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_ALWAYS_ON_TOP, pDoc->GetPresAlwaysOnTop() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_FULLSCREEN, pDoc->GetPresFullScreen() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_START_ACTUAL_PAGE, bStartWithActualPage ) );
    aDlgSet.Put( SfxUInt32Item( ATTR_PRESENT_PAUSE_TIMEOUT, pDoc->GetPresPause() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_SHOW_PAUSELOGO, pDoc->IsPresShowLogo() ) );

    SdStartPresentationDlg aDlg( (Window*) pWindow, aDlgSet, aPageNameList, pCustomShowList );

    if( aDlg.Execute() == RET_OK )
    {
        String  aPage;
        ULONG   nValue32;
        BOOL    bValue;
        BOOL    bValuesChanged = FALSE;

        aDlg.GetAttr( aDlgSet );

        aPage = ITEMVALUE( aDlgSet, ATTR_PRESENT_DIANAME, SfxStringItem );
        if( aPage != pDoc->GetPresPage() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresPage( aPage );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_ALL, SfxBoolItem );
        if ( bValue != pDoc->GetPresAll() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresAll( bValue );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_CUSTOMSHOW, SfxBoolItem );
        if ( bValue != pDoc->IsCustomShow() )
        {
            bValuesChanged = TRUE;
            pDoc->SetCustomShow( bValue );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_ENDLESS, SfxBoolItem );
        if ( bValue != pDoc->GetPresEndless() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresEndless( bValue );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_MANUEL, SfxBoolItem );
        if ( bValue != pDoc->GetPresManual() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresManual( bValue );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_MOUSE, SfxBoolItem );
        if ( bValue != pDoc->GetPresMouseVisible() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresMouseVisible( bValue );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_PEN, SfxBoolItem );
        if ( bValue != pDoc->GetPresMouseAsPen() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresMouseAsPen( bValue );
        }

        bValue = !ITEMVALUE( aDlgSet, ATTR_PRESENT_CHANGE_PAGE, SfxBoolItem );
        if ( bValue != pDoc->GetPresLockedPages() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresLockedPages( bValue );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_NAVIGATOR, SfxBoolItem );
        if ( bValue != pDoc->GetStartPresWithNavigator() )
        {
            bValuesChanged = TRUE;
            pDoc->SetStartPresWithNavigator( bValue );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_ANIMATION_ALLOWED, SfxBoolItem );
        if ( bValue != pDoc->IsAnimationAllowed() )
        {
            bValuesChanged = TRUE;
            pDoc->SetAnimationAllowed( bValue );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_ALWAYS_ON_TOP, SfxBoolItem );
        if ( bValue != pDoc->GetPresAlwaysOnTop() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresAlwaysOnTop( bValue );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_FULLSCREEN, SfxBoolItem );
        if ( bValue != pDoc->GetPresFullScreen() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresFullScreen( bValue );
        }

        nValue32 = ITEMVALUE( aDlgSet, ATTR_PRESENT_PAUSE_TIMEOUT, SfxUInt32Item );
        if( nValue32 != pDoc->GetPresPause() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresPause( nValue32 );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_SHOW_PAUSELOGO, SfxBoolItem );
        if ( bValue != pDoc->IsPresShowLogo() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresShowLogo( bValue );
        }

        // wenn sich etwas geaendert hat, setzen wir das Modified-Flag,
        if ( bValuesChanged )
            pDoc->SetChanged( TRUE );
    }

    // Strings aus Liste loeschen
    for( void* pStr = aPageNameList.First(); pStr; pStr = aPageNameList.Next() )
        delete (String*) pStr;
}

<commit_msg>INTEGRATION: CWS draw14 (1.1.1.1.182); FILE MERGED 2003/05/28 09:19:26 cl 1.1.1.1.182.1: #109180# changed start from current page feature<commit_after>/*************************************************************************
 *
 *  $RCSfile: fusldlg.cxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: vg $ $Date: 2003-06-04 12:27:46 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

#pragma hdrstop

#ifndef _SFXITEMSET_HXX //autogen
#include <svtools/itemset.hxx>
#endif
#ifndef _MSGBOX_HXX //autogen
#include <vcl/msgbox.hxx>
#endif

#include "drawdoc.hxx"
#include "sdpage.hxx"
#include "present.hxx"
#include "sdresid.hxx"
#include "strings.hrc"
#include "sdattr.hxx"
#include "fusldlg.hxx"
#include "glob.hrc"

#include "sdmod.hxx"
#include "viewshel.hxx"
#include "optsitem.hxx"

#define ITEMVALUE(ItemSet,Id,Cast) ((const Cast&)(ItemSet).Get(Id)).GetValue()

TYPEINIT1( FuSlideShowDlg, FuPoor );

/*************************************************************************
|*
|* Konstruktor
|*
\************************************************************************/

FuSlideShowDlg::FuSlideShowDlg( SdViewShell* pViewSh, SdWindow*  pWin,
                                SdView* pView, SdDrawDocument* pDoc, SfxRequest& rReq) :
            FuPoor( pViewSh, pWin, pView, pDoc, rReq )
{
    SfxItemSet      aDlgSet( pDoc->GetPool(), ATTR_PRESENT_START, ATTR_PRESENT_END );
    List            aPageNameList;
    const String&   rPresPage = pDoc->GetPresPage();
    String          aFirstPage;
    String          aStandardName( SdResId( STR_PAGE ) );
    SdPage*         pPage = NULL;
    long            nPage;

    for( nPage = pDoc->GetSdPageCount( PK_STANDARD ) - 1L; nPage >= 0L; nPage-- )
    {
        pPage = pDoc->GetSdPage( (USHORT) nPage, PK_STANDARD );
        String* pStr = new String( pPage->GetName() );

        if ( !pStr->Len() )
        {
            *pStr = String( SdResId( STR_PAGE ) );
            (*pStr).Append( UniString::CreateFromInt32( nPage + 1 ) );
        }

        aPageNameList.Insert( pStr, (ULONG) 0 );

        // ist dies unsere (vorhandene) erste Seite?
        if ( rPresPage == *pStr )
            aFirstPage = rPresPage;
        else if ( pPage->IsSelected() && !aFirstPage.Len() )
            aFirstPage = *pStr;
    }
    List* pCustomShowList = pDoc->GetCustomShowList(); // No Create

    BOOL bStartWithActualPage = SD_MOD()->GetSdOptions( pDoc->GetDocumentType() )->IsStartWithActualPage();
/* #109180# change in behaviour, even when always start with current page is enabled, range settings are
            still used
    if( bStartWithActualPage )
    {
        aFirstPage = pViewSh->GetActualPage()->GetName();
        pCustomShowList = NULL;
    }
*/
    if( !aFirstPage.Len() && pPage )
        aFirstPage = pPage->GetName();

    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_ALL, pDoc->GetPresAll() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_CUSTOMSHOW, pDoc->IsCustomShow() ) );
    aDlgSet.Put( SfxStringItem( ATTR_PRESENT_DIANAME, aFirstPage ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_ENDLESS, pDoc->GetPresEndless() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_MANUEL, pDoc->GetPresManual() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_MOUSE, pDoc->GetPresMouseVisible() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_PEN, pDoc->GetPresMouseAsPen() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_NAVIGATOR, pDoc->GetStartPresWithNavigator() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_ANIMATION_ALLOWED, pDoc->IsAnimationAllowed() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_CHANGE_PAGE, !pDoc->GetPresLockedPages() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_ALWAYS_ON_TOP, pDoc->GetPresAlwaysOnTop() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_FULLSCREEN, pDoc->GetPresFullScreen() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_START_ACTUAL_PAGE, bStartWithActualPage ) );
    aDlgSet.Put( SfxUInt32Item( ATTR_PRESENT_PAUSE_TIMEOUT, pDoc->GetPresPause() ) );
    aDlgSet.Put( SfxBoolItem( ATTR_PRESENT_SHOW_PAUSELOGO, pDoc->IsPresShowLogo() ) );

    SdStartPresentationDlg aDlg( (Window*) pWindow, aDlgSet, aPageNameList, pCustomShowList );

    if( aDlg.Execute() == RET_OK )
    {
        String  aPage;
        ULONG   nValue32;
        BOOL    bValue;
        BOOL    bValuesChanged = FALSE;

        aDlg.GetAttr( aDlgSet );

        aPage = ITEMVALUE( aDlgSet, ATTR_PRESENT_DIANAME, SfxStringItem );
        if( aPage != pDoc->GetPresPage() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresPage( aPage );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_ALL, SfxBoolItem );
        if ( bValue != pDoc->GetPresAll() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresAll( bValue );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_CUSTOMSHOW, SfxBoolItem );
        if ( bValue != pDoc->IsCustomShow() )
        {
            bValuesChanged = TRUE;
            pDoc->SetCustomShow( bValue );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_ENDLESS, SfxBoolItem );
        if ( bValue != pDoc->GetPresEndless() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresEndless( bValue );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_MANUEL, SfxBoolItem );
        if ( bValue != pDoc->GetPresManual() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresManual( bValue );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_MOUSE, SfxBoolItem );
        if ( bValue != pDoc->GetPresMouseVisible() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresMouseVisible( bValue );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_PEN, SfxBoolItem );
        if ( bValue != pDoc->GetPresMouseAsPen() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresMouseAsPen( bValue );
        }

        bValue = !ITEMVALUE( aDlgSet, ATTR_PRESENT_CHANGE_PAGE, SfxBoolItem );
        if ( bValue != pDoc->GetPresLockedPages() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresLockedPages( bValue );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_NAVIGATOR, SfxBoolItem );
        if ( bValue != pDoc->GetStartPresWithNavigator() )
        {
            bValuesChanged = TRUE;
            pDoc->SetStartPresWithNavigator( bValue );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_ANIMATION_ALLOWED, SfxBoolItem );
        if ( bValue != pDoc->IsAnimationAllowed() )
        {
            bValuesChanged = TRUE;
            pDoc->SetAnimationAllowed( bValue );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_ALWAYS_ON_TOP, SfxBoolItem );
        if ( bValue != pDoc->GetPresAlwaysOnTop() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresAlwaysOnTop( bValue );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_FULLSCREEN, SfxBoolItem );
        if ( bValue != pDoc->GetPresFullScreen() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresFullScreen( bValue );
        }

        nValue32 = ITEMVALUE( aDlgSet, ATTR_PRESENT_PAUSE_TIMEOUT, SfxUInt32Item );
        if( nValue32 != pDoc->GetPresPause() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresPause( nValue32 );
        }

        bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_SHOW_PAUSELOGO, SfxBoolItem );
        if ( bValue != pDoc->IsPresShowLogo() )
        {
            bValuesChanged = TRUE;
            pDoc->SetPresShowLogo( bValue );
        }

        // wenn sich etwas geaendert hat, setzen wir das Modified-Flag,
        if ( bValuesChanged )
            pDoc->SetChanged( TRUE );
    }

    // Strings aus Liste loeschen
    for( void* pStr = aPageNameList.First(); pStr; pStr = aPageNameList.Next() )
        delete (String*) pStr;
}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: fuinsfil.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: kz $ $Date: 2005-01-18 15:17:26 $
 *
 *  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 SD_FU_INSERT_FILE_HXX
#define SD_FU_INSERT_FILE_HXX

#ifndef SD_FU_POOR_HXX
#include "fupoor.hxx"
#endif
#include <vector>

class SfxMedium;
struct StyleRequestData;

namespace sd {

class FuInsertFile
    : public FuPoor
{
public:
    TYPEINFO();

    FuInsertFile (
        ViewShell* pViewSh,
        ::sd::Window* pWin,
        ::sd::View* pView,
        SdDrawDocument* pDoc,
        SfxRequest& rReq);
    virtual ~FuInsertFile (void);

    virtual void    Activate();     // Function aktivieren
    virtual void    Deactivate();   // Function deaktivieren

    static void     GetSupportedFilterVector( ::std::vector< String >& rFilterVector );

private:

    String          aLayoutName;    // Layoutname der aktuell eingefuegten Seite
    String          aFilterName;    // gewaehlter Dateifilter
    String          aFile;          // gewaehlter Dateiname

    void            InsTextOrRTFinOlMode(SfxMedium* pMedium);
    BOOL            InsSDDinOlMode(SfxMedium* pMedium);
    void            InsTextOrRTFinDrMode(SfxMedium* pMedium);
    BOOL            InsSDDinDrMode(SfxMedium* pMedium);
};

} // end of namespace sd

#endif
<commit_msg>INTEGRATION: CWS ooo19126 (1.4.236); FILE MERGED 2005/09/05 13:23:07 rt 1.4.236.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: fuinsfil.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 05:34:42 $
 *
 *  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 SD_FU_INSERT_FILE_HXX
#define SD_FU_INSERT_FILE_HXX

#ifndef SD_FU_POOR_HXX
#include "fupoor.hxx"
#endif
#include <vector>

class SfxMedium;
struct StyleRequestData;

namespace sd {

class FuInsertFile
    : public FuPoor
{
public:
    TYPEINFO();

    FuInsertFile (
        ViewShell* pViewSh,
        ::sd::Window* pWin,
        ::sd::View* pView,
        SdDrawDocument* pDoc,
        SfxRequest& rReq);
    virtual ~FuInsertFile (void);

    virtual void    Activate();     // Function aktivieren
    virtual void    Deactivate();   // Function deaktivieren

    static void     GetSupportedFilterVector( ::std::vector< String >& rFilterVector );

private:

    String          aLayoutName;    // Layoutname der aktuell eingefuegten Seite
    String          aFilterName;    // gewaehlter Dateifilter
    String          aFile;          // gewaehlter Dateiname

    void            InsTextOrRTFinOlMode(SfxMedium* pMedium);
    BOOL            InsSDDinOlMode(SfxMedium* pMedium);
    void            InsTextOrRTFinDrMode(SfxMedium* pMedium);
    BOOL            InsSDDinDrMode(SfxMedium* pMedium);
};

} // end of namespace sd

#endif
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: StorageNativeInputStream.cxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: hr $ $Date: 2004-11-09 12:09:23 $
 *
 *  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): Ocke Janssen
 *
 *
 ************************************************************************/

#if HAVE_CONFIG_H
#include <config.h>
#endif

#ifndef _COM_SUN_STAR_IO_XSTREAM_HPP_
#include <com/sun/star/io/XStream.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_DOCUMENT_XDOCUMENTSUBSTORAGESUPPLIER_HPP_
#include <com/sun/star/document/XDocumentSubStorageSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_EMBED_XSTORAGE_HPP_
#include <com/sun/star/embed/XStorage.hpp>
#endif
#ifndef _COM_SUN_STAR_EMBED_ELEMENTMODES_HPP_
#include <com/sun/star/embed/ElementModes.hpp>
#endif
#ifndef _COMPHELPER_STLTYPES_HXX_
#include <comphelper/stl_types.hxx>
#endif
#ifndef _COMPHELPER_TYPES_HXX_
#include <comphelper/types.hxx>
#endif
#include "hsqldb/HStorageAccess.h"
#include "hsqldb/HStorageMap.hxx"
#include "hsqldb/StorageNativeInputStream.h"

#include "jvmaccess/virtualmachine.hxx"
#include "com/sun/star/lang/XSingleComponentFactory.hpp"

#include <rtl/logfile.hxx>
#include <limits>

using namespace ::com::sun::star::container;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::document;
using namespace ::com::sun::star::embed;
using namespace ::com::sun::star::io;
using namespace ::com::sun::star::lang;
using namespace ::connectivity::hsqldb;

#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
/*****************************************************************************/
/* exception macros */

#define ThrowException(env, type, msg) { \
    env->ThrowNew(env->FindClass(type), msg); }
/*
 * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream
 * Method:    openStream
 * Signature: (Ljava/lang/String;Ljava/lang/String;I)V
 */
JNIEXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_openStream
  (JNIEnv * env, jobject obj_this,jstring key, jstring name, jint mode)
{
    Java_com_sun_star_sdbcx_comp_hsqldb_NativeStorageAccess_openStream(env,obj_this,name,key,mode);
}
// -----------------------------------------------------------------------------

/*
 * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream
 * Method:    read
 * Signature: (Ljava/lang/String;Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_read__Ljava_lang_String_2Ljava_lang_String_2
  (JNIEnv * env, jobject obj_this,jstring key, jstring name)
{
    return Java_com_sun_star_sdbcx_comp_hsqldb_NativeStorageAccess_read__Ljava_lang_String_2Ljava_lang_String_2(env,obj_this,name,key);
}
// -----------------------------------------------------------------------------

/*
 * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream
 * Method:    read
 * Signature: (Ljava/lang/String;Ljava/lang/String;[BII)I
 */
JNIEXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_read__Ljava_lang_String_2Ljava_lang_String_2_3BII
  (JNIEnv * env, jobject obj_this,jstring key, jstring name, jbyteArray buffer, jint off, jint len)
{
    ::boost::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key);
    Reference< XInputStream> xIn = pHelper.get() ? pHelper->getInputStream() : Reference< XInputStream>();
    OSL_ENSURE(xIn.is(),"Input stream is NULL!");
    if ( xIn.is() )
    {
        sal_Int32 nBytesRead = 0;

        jsize nLen = env->GetArrayLength(buffer);
        Sequence< ::sal_Int8 > aData(nLen);

        sal_Int32 av = xIn->available();
        if ( av != 0 && nLen > av)
            nBytesRead = xIn->readBytes(aData, av);
        else
            nBytesRead = xIn->readBytes(aData,nLen);

        // Casting bytesRead to an int is okay, since the user can
        // only pass in an integer length to read, so the bytesRead
        // must <= len.
        //
        if (nBytesRead <= 0) {
            return -1;
        } else if (nBytesRead < len) {
            env->SetByteArrayRegion(buffer,off,nBytesRead,&aData[0]);
        } else {
            env->SetByteArrayRegion(buffer,off,len,&aData[0]);
        }
        return nBytesRead;
    }
    ThrowException( env,
                    "java/io/IOException",
                    "Stream is not valid");
    return -1;
}
// -----------------------------------------------------------------------------

/*
 * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream
 * Method:    close
 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_close
  (JNIEnv * env, jobject obj_this,jstring key, jstring name)
{
    StorageContainer::revokeStream(env,name,key);
}
// -----------------------------------------------------------------------------

/*
 * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream
 * Method:    skip
 * Signature: (Ljava/lang/String;Ljava/lang/String;J)J
 */
JNIEXPORT jlong JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_skip
  (JNIEnv * env, jobject obj_this,jstring key, jstring name, jlong n)
{
    ::boost::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key);
    OSL_ENSURE(pHelper.get(),"No stream helper!");
    if ( pHelper.get() )
    {
        Reference<XInputStream> xIn = pHelper->getInputStream();
        if ( xIn.is() )
        {
            try
            {
                sal_Int32 avail = xIn->available();
                sal_Int64 tmpLongVal = n;
                sal_Int32 tmpIntVal;
                do {
                    if (tmpLongVal >= ::std::numeric_limits<sal_Int64>::max() )
                        tmpIntVal = ::std::numeric_limits<sal_Int32>::max();
                    else // Casting is safe here.
                        tmpIntVal = static_cast<sal_Int32>(tmpLongVal);

                    tmpLongVal -= tmpIntVal;

                    xIn->skipBytes(tmpIntVal);
                } while (tmpLongVal > 0);

                if ( avail != 0 && avail < n) {
                    return(avail);
                } else {
                    return(n);
                }
            }
            catch(Exception& e)
            {
                OSL_ENSURE(0,"Exception catched! : writeBytes(aData);");
                if (JNI_FALSE != env->ExceptionCheck())
                    env->ExceptionClear();
                ::rtl::OString cstr( ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_JAVA_UTF8 ) );
                OSL_TRACE( __FILE__": forwarding Exception: %s", cstr.getStr() );
                ThrowException( env,
                                "java/io/IOException",
                                cstr.getStr());
            }
        }
    }
    else
    {
        ThrowException( env,
                        "java/io/IOException",
                        "Stream is not valid");
    }
    return 0;
}
// -----------------------------------------------------------------------------

/*
 * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream
 * Method:    available
 * Signature: (Ljava/lang/String;Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_available
  (JNIEnv * env, jobject obj_this,jstring key, jstring name)
{
    ::boost::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key);
    OSL_ENSURE(pHelper.get(),"No stream helper!");
    Reference<XInputStream> xIn = pHelper.get() ? pHelper->getInputStream() : Reference<XInputStream>();
    if ( xIn.is() )
    {
        try
        {
            return xIn->available();
        }
        catch(Exception& e)
        {
            OSL_ENSURE(0,"Exception catched! : writeBytes(aData);");
            if (JNI_FALSE != env->ExceptionCheck())
                env->ExceptionClear();
            ::rtl::OString cstr( ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_JAVA_UTF8 ) );
            OSL_TRACE( __FILE__": forwarding Exception: %s", cstr.getStr() );
            ThrowException( env,
                            "java/io/IOException",
                            cstr.getStr());
        }
    }
    else
    {
        ThrowException( env,
                        "java/io/IOException",
                        "Stream is not valid");
    }
    return 0;
}
// -----------------------------------------------------------------------------

/*
 * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream
 * Method:    read
 * Signature: (Ljava/lang/String;Ljava/lang/String;[B)I
 */
JNIEXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_read__Ljava_lang_String_2Ljava_lang_String_2_3B
  (JNIEnv * env, jobject obj_this,jstring key, jstring name, jbyteArray buffer)
{
    ::boost::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key);
    Reference< XInputStream> xIn = pHelper.get() ? pHelper->getInputStream() : Reference< XInputStream>();
    OSL_ENSURE(xIn.is(),"Input stream is NULL!");
    sal_Int32 nBytesRead = 0;
    if ( xIn.is() )
    {
        jsize nLen = env->GetArrayLength(buffer);
        Sequence< ::sal_Int8 > aData(nLen);

        sal_Int32 av = xIn->available();
        if ( av != 0 && nLen > av)
            nBytesRead = xIn->readBytes(aData, av);
        else
            nBytesRead = xIn->readBytes(aData,nLen);

        // Casting bytesRead to an int is okay, since the user can
        // only pass in an integer length to read, so the bytesRead
        // must <= len.
        //
        if (nBytesRead <= 0) {
            return -1;
        }
        env->SetByteArrayRegion(buffer,0,nLen,&aData[0]);
    }
    return nBytesRead;
}
// -----------------------------------------------------------------------------
<commit_msg>INTEGRATION: CWS hsqldb2 (1.2.20); FILE MERGED 2005/01/28 12:21:54 oj 1.2.20.2: #i39922# new interfaces in hsqldb and some debug info 2005/01/25 08:42:51 oj 1.2.20.1: #i39922# correct stream handling<commit_after>/*************************************************************************
 *
 *  $RCSfile: StorageNativeInputStream.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: vg $ $Date: 2005-02-16 15:52:28 $
 *
 *  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): Ocke Janssen
 *
 *
 ************************************************************************/

#if HAVE_CONFIG_H
#include <config.h>
#endif

#ifndef _COM_SUN_STAR_IO_XSTREAM_HPP_
#include <com/sun/star/io/XStream.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_DOCUMENT_XDOCUMENTSUBSTORAGESUPPLIER_HPP_
#include <com/sun/star/document/XDocumentSubStorageSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_EMBED_XSTORAGE_HPP_
#include <com/sun/star/embed/XStorage.hpp>
#endif
#ifndef _COM_SUN_STAR_EMBED_ELEMENTMODES_HPP_
#include <com/sun/star/embed/ElementModes.hpp>
#endif
#ifndef _COMPHELPER_STLTYPES_HXX_
#include <comphelper/stl_types.hxx>
#endif
#ifndef _COMPHELPER_TYPES_HXX_
#include <comphelper/types.hxx>
#endif
#include "hsqldb/HStorageAccess.h"
#include "hsqldb/HStorageMap.hxx"
#include "hsqldb/StorageNativeInputStream.h"

#include "jvmaccess/virtualmachine.hxx"
#include "com/sun/star/lang/XSingleComponentFactory.hpp"

#include <rtl/logfile.hxx>
#include <limits>

using namespace ::com::sun::star::container;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::document;
using namespace ::com::sun::star::embed;
using namespace ::com::sun::star::io;
using namespace ::com::sun::star::lang;
using namespace ::connectivity::hsqldb;

#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
/*****************************************************************************/
/* exception macros */

#define ThrowException(env, type, msg) { \
    env->ThrowNew(env->FindClass(type), msg); }
/*
 * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream
 * Method:    openStream
 * Signature: (Ljava/lang/String;Ljava/lang/String;I)V
 */
JNIEXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_openStream
  (JNIEnv * env, jobject obj_this,jstring key, jstring name, jint mode)
{
#if OSL_DEBUG_LEVEL > 1
    {
        ::rtl::OUString sOrgName = StorageContainer::jstring2ustring(env,name);
        sOrgName += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".input"));
        ::rtl::OString sName = ::rtl::OUStringToOString(sOrgName,RTL_TEXTENCODING_ASCII_US);
        getStreams()[sOrgName] = fopen( sName.getStr(), "a+" );
    }
#endif
    StorageContainer::registerStream(env,name,key,mode);
}
// -----------------------------------------------------------------------------

/*
 * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream
 * Method:    read
 * Signature: (Ljava/lang/String;Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_read__Ljava_lang_String_2Ljava_lang_String_2
  (JNIEnv * env, jobject obj_this,jstring key, jstring name)
{
    return Java_com_sun_star_sdbcx_comp_hsqldb_NativeStorageAccess_read__Ljava_lang_String_2Ljava_lang_String_2(env,obj_this,name,key);
}
// -----------------------------------------------------------------------------

/*
 * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream
 * Method:    read
 * Signature: (Ljava/lang/String;Ljava/lang/String;[BII)I
 */
JNIEXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_read__Ljava_lang_String_2Ljava_lang_String_2_3BII
  (JNIEnv * env, jobject obj_this,jstring key, jstring name, jbyteArray buffer, jint off, jint len)
{
    return Java_com_sun_star_sdbcx_comp_hsqldb_NativeStorageAccess_read__Ljava_lang_String_2Ljava_lang_String_2_3BII(env,obj_this,name,key,buffer,off,len);
}
// -----------------------------------------------------------------------------

/*
 * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream
 * Method:    close
 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_close
  (JNIEnv * env, jobject obj_this,jstring key, jstring name)
{
#if OSL_DEBUG_LEVEL > 1
    {
        ::rtl::OUString sOrgName = StorageContainer::jstring2ustring(env,name);
        sOrgName += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".input"));
        fclose( getStreams()[sOrgName] );
        getStreams().erase(sOrgName);
    }
#endif
    StorageContainer::revokeStream(env,name,key);
}
// -----------------------------------------------------------------------------

/*
 * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream
 * Method:    skip
 * Signature: (Ljava/lang/String;Ljava/lang/String;J)J
 */
JNIEXPORT jlong JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_skip
  (JNIEnv * env, jobject obj_this,jstring key, jstring name, jlong n)
{
    ::boost::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key);
    OSL_ENSURE(pHelper.get(),"No stream helper!");
    if ( pHelper.get() )
    {
        Reference<XInputStream> xIn = pHelper->getInputStream();
        if ( xIn.is() )
        {
            try
            {
                sal_Int32 avail = xIn->available();
                sal_Int64 tmpLongVal = n;
                sal_Int32 tmpIntVal;
                do {
                    if (tmpLongVal >= ::std::numeric_limits<sal_Int64>::max() )
                        tmpIntVal = ::std::numeric_limits<sal_Int32>::max();
                    else // Casting is safe here.
                        tmpIntVal = static_cast<sal_Int32>(tmpLongVal);

                    tmpLongVal -= tmpIntVal;

                    xIn->skipBytes(tmpIntVal);
                } while (tmpLongVal > 0);

                if ( avail != 0 && avail < n) {
                    return(avail);
                } else {
                    return(n);
                }
            }
            catch(Exception& e)
            {
                OSL_ENSURE(0,"Exception catched! : skip();");
                if (JNI_FALSE != env->ExceptionCheck())
                    env->ExceptionClear();
                ::rtl::OString cstr( ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_JAVA_UTF8 ) );
                OSL_TRACE( __FILE__": forwarding Exception: %s", cstr.getStr() );
                ThrowException( env,
                                "java/io/IOException",
                                cstr.getStr());
            }
        }
    }
    else
    {
        ThrowException( env,
                        "java/io/IOException",
                        "Stream is not valid");
    }
    return 0;
}
// -----------------------------------------------------------------------------

/*
 * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream
 * Method:    available
 * Signature: (Ljava/lang/String;Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_available
  (JNIEnv * env, jobject obj_this,jstring key, jstring name)
{
    ::boost::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key);
    OSL_ENSURE(pHelper.get(),"No stream helper!");
    Reference<XInputStream> xIn = pHelper.get() ? pHelper->getInputStream() : Reference<XInputStream>();
    if ( xIn.is() )
    {
        try
        {
            return xIn->available();
        }
        catch(Exception& e)
        {
            OSL_ENSURE(0,"Exception catched! : available();");
            if (JNI_FALSE != env->ExceptionCheck())
                env->ExceptionClear();
            ::rtl::OString cstr( ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_JAVA_UTF8 ) );
            OSL_TRACE( __FILE__": forwarding Exception: %s", cstr.getStr() );
            ThrowException( env,
                            "java/io/IOException",
                            cstr.getStr());
        }
    }
    else
    {
        ThrowException( env,
                        "java/io/IOException",
                        "Stream is not valid");
    }
    return 0;
}
// -----------------------------------------------------------------------------

/*
 * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream
 * Method:    read
 * Signature: (Ljava/lang/String;Ljava/lang/String;[B)I
 */
JNIEXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_read__Ljava_lang_String_2Ljava_lang_String_2_3B
  (JNIEnv * env, jobject obj_this,jstring key, jstring name, jbyteArray buffer)
{
    ::boost::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key);
    Reference< XInputStream> xIn = pHelper.get() ? pHelper->getInputStream() : Reference< XInputStream>();
    OSL_ENSURE(xIn.is(),"Input stream is NULL!");
    sal_Int32 nBytesRead = 0;
    if ( xIn.is() )
    {
        jsize nLen = env->GetArrayLength(buffer);
        Sequence< ::sal_Int8 > aData(nLen);

        sal_Int32 av = xIn->available();
        if ( av > 0 )
        {
            if (nLen > av)
                nBytesRead = xIn->readBytes(aData, av);
            else
                nBytesRead = xIn->readBytes(aData,nLen);
        }

        // Casting bytesRead to an int is okay, since the user can
        // only pass in an integer length to read, so the bytesRead
        // must <= len.
        //
        if (nBytesRead <= 0) {
            return -1;
        }
        OSL_ENSURE(nLen >= nBytesRead,"Buffer is too small!");
        OSL_ENSURE(aData.getLength() >= nBytesRead,"Buffer is too small!");
        env->SetByteArrayRegion(buffer,0,nBytesRead,&aData[0]);
#if OSL_DEBUG_LEVEL > 1
        ::rtl::OUString sOrgName = StorageContainer::jstring2ustring(env,name);
        sOrgName += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".input"));
        fwrite(&aData[0],sizeof(sal_Int8),nBytesRead,getStreams()[sOrgName]);
#endif
    }
    return nBytesRead;
}
// -----------------------------------------------------------------------------
<|endoftext|>


<commit_before><commit_msg>coverity#1187866 unused bStartWithActualPage<commit_after><|endoftext|>