<commit_before>#include <vector>
#include <iostream>
#include <algorithm>
#include <limits>

using namespace std;

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

#include "treehash/boosted-treehash.hh"
extern "C" {
#include "timers.h"
}

void fill_random(uint64_t * data, size_t n) {
  const int rfd = open("/dev/urandom", O_RDONLY);
  if (-1 == rfd) {
    const int err = errno;
    fprintf(stderr, "%s\n", strerror(err));
    exit(err);
  }
  char * const cdata = (char *)data;
  for (size_t i = 0; i < n; i += read(rfd, &cdata[i], sizeof(uint64_t)*n-i));
  (void)close(rfd);
}

uint64_t * alloc_random(size_t n) {
  uint64_t * ans = (uint64_t *)malloc(sizeof(uint64_t) * n);
  if (!ans) {
    fprintf(stderr, "Failed allocation of %zd words\n", n);
    exit(1);
  }
  fill_random(ans, n);
  return ans;
}

uint64_t sum = 0;

template<size_t N>
ticks bench(const void * r, const uint64_t * data, const size_t i) {
  const ticks start = startRDTSC();
  sum += boosted_treehash<N>(r, data, i);
  const ticks finish = startRDTSC();
  return finish-start;
}

int main() {
  size_t max_len = 2048;
  const uint64_t * const data = alloc_random(max_len);
  const void * const r64 = alloc_random(128);
  size_t iters = 10000;
  const size_t max_depth = 9;
  vector<vector<ticks> > cycles(max_depth, vector<ticks>(iters));
  size_t samples = 100;
  cout << "# length percentile optimal-treeboost " << endl;
  for (size_t i = 1; i < max_len; i = 1 + 1.001*i) {
    for (size_t j = 0; j < iters; ++j) {
      cycles[0][j] = bench<1>(r64, data, i);
      cycles[1][j] = bench<2>(r64, data, i);
      cycles[2][j] = bench<3>(r64, data, i);
      cycles[3][j] = bench<4>(r64, data, i);
      cycles[4][j] = bench<5>(r64, data, i);
      cycles[5][j] = bench<6>(r64, data, i);
      cycles[6][j] = bench<7>(r64, data, i);
      cycles[7][j] = bench<8>(r64, data, i);
      cycles[8][j] = bench<9>(r64, data, i);
    }
    for (size_t j = 0; j < max_depth; ++j) {
      sort(cycles[j].begin(), cycles[j].end(), std::greater<ticks>());
    }
    for (size_t j = 0; j <= samples; ++j) {
      size_t loc = (iters * j)/samples;
      if (loc >= iters) loc = iters-1;
      ticks min_val = numeric_limits<ticks>::max();
      int min_idx = -1;
      for (size_t k = 0; k < max_depth; ++k) {
        if (cycles[k][loc] < min_val) {
          min_val = cycles[k][loc];
          min_idx = k;
        }
      }
      cout << i << " " << j << " " << 1+min_idx << endl;
    }
    cout << endl;
  }
  cerr << "# ignore " << sum << endl;
};
<commit_msg>Force computation without producing output<commit_after>#include <vector>
#include <iostream>
#include <algorithm>
#include <limits>

using namespace std;

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

#include "treehash/boosted-treehash.hh"
extern "C" {
#include "timers.h"
}

void fill_random(uint64_t * data, size_t n) {
  const int rfd = open("/dev/urandom", O_RDONLY);
  if (-1 == rfd) {
    const int err = errno;
    fprintf(stderr, "%s\n", strerror(err));
    exit(err);
  }
  char * const cdata = (char *)data;
  for (size_t i = 0; i < n; i += read(rfd, &cdata[i], sizeof(uint64_t)*n-i));
  (void)close(rfd);
}

uint64_t * alloc_random(size_t n) {
  uint64_t * ans = (uint64_t *)malloc(sizeof(uint64_t) * n);
  if (!ans) {
    fprintf(stderr, "Failed allocation of %zd words\n", n);
    exit(1);
  }
  fill_random(ans, n);
  return ans;
}

uint64_t sum = 0;

template<size_t N>
ticks bench(const void * r, const uint64_t * data, const size_t i) {
  const ticks start = startRDTSC();
  sum += boosted_treehash<N>(r, data, i);
  const ticks finish = startRDTSC();
  return finish-start;
}

int main() {
  size_t max_len = 2048;
  const uint64_t * const data = alloc_random(max_len);
  const void * const r64 = alloc_random(128);
  size_t iters = 10000;
  const size_t max_depth = 9;
  vector<vector<ticks> > cycles(max_depth, vector<ticks>(iters));
  size_t samples = 100;
  cout << "# length percentile optimal-treeboost " << endl;
  for (size_t i = 1; i < max_len; i = 1 + 1.001*i) {
    for (size_t j = 0; j < iters; ++j) {
      cycles[0][j] = bench<1>(r64, data, i);
      cycles[1][j] = bench<2>(r64, data, i);
      cycles[2][j] = bench<3>(r64, data, i);
      cycles[3][j] = bench<4>(r64, data, i);
      cycles[4][j] = bench<5>(r64, data, i);
      cycles[5][j] = bench<6>(r64, data, i);
      cycles[6][j] = bench<7>(r64, data, i);
      cycles[7][j] = bench<8>(r64, data, i);
      cycles[8][j] = bench<9>(r64, data, i);
    }
    for (size_t j = 0; j < max_depth; ++j) {
      sort(cycles[j].begin(), cycles[j].end(), std::greater<ticks>());
    }
    for (size_t j = 0; j <= samples; ++j) {
      size_t loc = (iters * j)/samples;
      if (loc >= iters) loc = iters-1;
      ticks min_val = numeric_limits<ticks>::max();
      int min_idx = -1;
      for (size_t k = 0; k < max_depth; ++k) {
        if (cycles[k][loc] < min_val) {
          min_val = cycles[k][loc];
          min_idx = k;
        }
      }
      cout << i << " " << j << " " << 1+min_idx << endl;
    }
    cout << endl;
  }
  if (0 == sum) {
    cerr << "# Magic happens: sum of all hashes is 0!" << endl;
    return 1;
  }
};
<|endoftext|>


<commit_before>/* bzflag
 * Copyright (c) 1993 - 2008 Tim Riker
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named LICENSE that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#ifdef _MSC_VER
#pragma warning( 4: 4786 )
#endif
#include "common.h"

/* system implementation headers */
#include <iostream>
#include <math.h>
#include <sstream>
#include <string.h>

/* common implementation headers */
#include "Pack.h"
#include "WorldFileObject.h"
#include "WorldFileLocation.h"
#include "MeshTransform.h"

WorldFileLocation::WorldFileLocation()
{
  pos[0] = pos[1] = pos[2] = 0.0f;
  rotation = 0.0f;
  size[0] = size[1] = size[2] = 1.0f;
}

bool WorldFileLocation::read(const char *cmd, std::istream& input)
{
  //
  // Position, Size, and Rotation
  //
  if ((strcasecmp(cmd, "pos") == 0) ||
      (strcasecmp(cmd, "position") == 0)) {
    if (!(input >> pos[0] >> pos[1] >> pos[2])) {
      return false;
    }
  } else if (strcasecmp(cmd, "size") == 0){
    if (!(input >> size[0] >> size[1] >> size[2])) {
      return false;
    }
  } else if ((strcasecmp(cmd, "rot") == 0) ||
	   (strcasecmp(cmd, "rotation") == 0)) {
    if (!(input >> rotation)) {
      return false;
    }
    // convert to radians
    rotation = (float)(rotation * (M_PI / 180.0));
  } else if (strcasecmp ("shift", cmd) == 0) {
    float data[3];
    if (!(input >> data[0] >> data[1] >> data[2])) {
      std::cout << "parameters errors " << std::endl;
      return false;
    }
    transform.addShift(data);
  } else if (strcasecmp ("scale", cmd) == 0) {
    float data[3];
    if (!(input >> data[0] >> data[1] >> data[2])) {
      std::cout << "parameters errors " << std::endl;
      return false;
    }
    transform.addScale(data);
  } else if (strcasecmp ("shear", cmd) == 0) {
    float data[3];
    if (!(input >> data[0] >> data[1] >> data[2])) {
      std::cout << "parameters errors " << std::endl;
      return false;
    }
    transform.addShear(data);
  } else if (strcasecmp ("spin", cmd) == 0) {
    float angle, normal[3];
    if (!(input >> angle >> normal[0] >> normal[1] >> normal[2])) {
      std::cout << "parameters errors " << std::endl;
      return false;
    }
    transform.addSpin(angle, normal);
  } else if (strcasecmp ("xform", cmd) == 0) {
    std::string _name;
    if (!(input >> _name)) {
      std::cout << "parameters errors " << std::endl;
      return false;
    }
    int xform = TRANSFORMMGR.findTransform(_name);
    if (xform == -1) {
      std::cout << "couldn't find Transform: " << _name << std::endl;
    } else {
      transform.addReference(xform);
    }
  } else {
    return WorldFileObject::read(cmd, input);
  }

  return true;
}

void * WorldFileLocation::pack(void *buf) const
{
  buf = nboPackFloatVector (buf, pos);
  buf = nboPackFloatVector (buf, size);
  buf = nboPackFloat (buf, rotation);
  return buf;
}

// Local variables: ***
// mode: C++ ***
// tab-width: 8 ***
// c-basic-offset: 2 ***
// indent-tabs-mode: t ***
// End: ***
// ex: shiftwidth=2 tabstop=8
<commit_msg>Whitespace<commit_after>/* bzflag
 * Copyright (c) 1993 - 2008 Tim Riker
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named LICENSE that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#ifdef _MSC_VER
#pragma warning( 4: 4786 )
#endif
#include "common.h"

/* system implementation headers */
#include <iostream>
#include <math.h>
#include <sstream>
#include <string.h>

/* common implementation headers */
#include "Pack.h"
#include "WorldFileObject.h"
#include "WorldFileLocation.h"
#include "MeshTransform.h"

WorldFileLocation::WorldFileLocation()
{
  pos[0] = pos[1] = pos[2] = 0.0f;
  rotation = 0.0f;
  size[0] = size[1] = size[2] = 1.0f;
}

bool WorldFileLocation::read(const char *cmd, std::istream& input)
{
  //
  // Position, Size, and Rotation
  //
  if ((strcasecmp(cmd, "pos") == 0) ||
      (strcasecmp(cmd, "position") == 0)) {
    if (!(input >> pos[0] >> pos[1] >> pos[2])) {
      return false;
    }
  } else if (strcasecmp(cmd, "size") == 0) {
    if (!(input >> size[0] >> size[1] >> size[2])) {
      return false;
    }
  } else if ((strcasecmp(cmd, "rot") == 0) ||
	     (strcasecmp(cmd, "rotation") == 0)) {
    if (!(input >> rotation)) {
      return false;
    }
    // convert to radians
    rotation = (float)(rotation * (M_PI / 180.0));
  } else if (strcasecmp ("shift", cmd) == 0) {
    float data[3];
    if (!(input >> data[0] >> data[1] >> data[2])) {
      std::cout << "parameters errors " << std::endl;
      return false;
    }
    transform.addShift(data);
  } else if (strcasecmp ("scale", cmd) == 0) {
    float data[3];
    if (!(input >> data[0] >> data[1] >> data[2])) {
      std::cout << "parameters errors " << std::endl;
      return false;
    }
    transform.addScale(data);
  } else if (strcasecmp ("shear", cmd) == 0) {
    float data[3];
    if (!(input >> data[0] >> data[1] >> data[2])) {
      std::cout << "parameters errors " << std::endl;
      return false;
    }
    transform.addShear(data);
  } else if (strcasecmp ("spin", cmd) == 0) {
    float angle, normal[3];
    if (!(input >> angle >> normal[0] >> normal[1] >> normal[2])) {
      std::cout << "parameters errors " << std::endl;
      return false;
    }
    transform.addSpin(angle, normal);
  } else if (strcasecmp ("xform", cmd) == 0) {
    std::string _name;
    if (!(input >> _name)) {
      std::cout << "parameters errors " << std::endl;
      return false;
    }
    int xform = TRANSFORMMGR.findTransform(_name);
    if (xform == -1) {
      std::cout << "couldn't find Transform: " << _name << std::endl;
    } else {
      transform.addReference(xform);
    }
  } else {
    return WorldFileObject::read(cmd, input);
  }

  return true;
}

void * WorldFileLocation::pack(void *buf) const
{
  buf = nboPackFloatVector (buf, pos);
  buf = nboPackFloatVector (buf, size);
  buf = nboPackFloat (buf, rotation);
  return buf;
}

// Local variables: ***
// mode: C++ ***
// tab-width: 8 ***
// c-basic-offset: 2 ***
// indent-tabs-mode: t ***
// End: ***
// ex: shiftwidth=2 tabstop=8
<|endoftext|>


<commit_before>/* bzflag
 * Copyright (c) 1993 - 2004 Tim Riker
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named LICENSE that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#ifdef _MSC_VER
#pragma warning( 4: 4786 )
#endif

#include "WorldFileObstacle.h"

WorldFileObstacle::WorldFileObstacle()
{
  pos[0] = pos[1] = pos[2] = 0.0f;
  rotation = 0.0f;
  size[0] = size[1] = size[2] = 1.0f;
  driveThrough = false;
  shootThrough = false;
  flipZ = false;
}

bool WorldFileObstacle::read(const char *cmd, std::istream& input)
{
  if (strcasecmp(cmd, "position") == 0)
    input >> pos[0] >> pos[1] >> pos[2];
  else if (strcasecmp(cmd, "rotation") == 0) {
    input >> rotation;
    rotation = rotation * M_PI / 180.0f;
  } else if (strcasecmp(cmd, "size") == 0){
    input >> size[0] >> size[1] >> size[2];
    if (size[2] < 0)
      flipZ = true;
    size[0] = fabs(size[0]);	// make sure they are postive, no more tricks
    size[1] = fabs(size[1]);
    size[2] = fabs(size[2]);
  }
  else if (strcasecmp(cmd, "drivethrough") == 0)
    driveThrough = true;
  else if (strcasecmp(cmd, "shootthrough") == 0)
    shootThrough = true;
  else if (strcasecmp(cmd, "pasable") == 0)
    driveThrough = shootThrough = true;
  else if (strcasecmp(cmd, "flipz") == 0)
    flipZ = true;
  else
    return WorldFileObject::read(cmd, input);
  return true;
}

// Local variables: ***
// mode:C++ ***
// tab-width: 8 ***
// c-basic-offset: 2 ***
// indent-tabs-mode: t ***
// End: ***
// ex: shiftwidth=2 tabstop=8
<commit_msg>pasable -> passable<commit_after>/* bzflag
 * Copyright (c) 1993 - 2004 Tim Riker
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named LICENSE that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#ifdef _MSC_VER
#pragma warning( 4: 4786 )
#endif

#include "WorldFileObstacle.h"

WorldFileObstacle::WorldFileObstacle()
{
  pos[0] = pos[1] = pos[2] = 0.0f;
  rotation = 0.0f;
  size[0] = size[1] = size[2] = 1.0f;
  driveThrough = false;
  shootThrough = false;
  flipZ = false;
}

bool WorldFileObstacle::read(const char *cmd, std::istream& input)
{
  if (strcasecmp(cmd, "position") == 0)
    input >> pos[0] >> pos[1] >> pos[2];
  else if (strcasecmp(cmd, "rotation") == 0) {
    input >> rotation;
    rotation = rotation * M_PI / 180.0f;
  } else if (strcasecmp(cmd, "size") == 0){
    input >> size[0] >> size[1] >> size[2];
    if (size[2] < 0)
      flipZ = true;
    size[0] = fabs(size[0]);	// make sure they are postive, no more tricks
    size[1] = fabs(size[1]);
    size[2] = fabs(size[2]);
  }
  else if (strcasecmp(cmd, "drivethrough") == 0)
    driveThrough = true;
  else if (strcasecmp(cmd, "shootthrough") == 0)
    shootThrough = true;
  else if (strcasecmp(cmd, "passable") == 0)
    driveThrough = shootThrough = true;
  else if (strcasecmp(cmd, "flipz") == 0)
    flipZ = true;
  else
    return WorldFileObject::read(cmd, input);
  return true;
}

// Local variables: ***
// mode:C++ ***
// tab-width: 8 ***
// c-basic-offset: 2 ***
// indent-tabs-mode: t ***
// End: ***
// ex: shiftwidth=2 tabstop=8
<|endoftext|>


<commit_before>#include "Value.h"

#include <sstream>
#include <cassert>

namespace libol {
    Value Value::create(Object &val) {
        Value value;
        value.type = OBJECT;
        value.value = new Object(val);
        return value;
    }

    Value Value::create(Array &val) {
        Value value;
        value.type = ARRAY;
        value.value = new Array(val);
        return value;
    }

    Value Value::create(float &val) {
        Value value;
        value.type = FLOAT;
        value.value = new float(val);
        return value;
    }

    Value Value::create(bool &val) {
        Value value;
        value.type = BOOL;
        value.value = new bool(val);
        return value;
    }

    Value Value::create(uint64_t &val) {
        assert(!(val & ((uint64_t) 1 << 61))); // assert that the msb is not set
        return create((int64_t &) val);
    }

    Value Value::create(uint32_t &val) {
        if (val >= 2147483648) {
            int64_t large = (int64_t) val;
            return create(large);
        }
        return create((int32_t &) val);
    }

    Value Value::create(uint16_t &val) {
        int32_t intval = (int32_t) val;
        return create(intval);
    }

    Value Value::create(uint8_t &val) {
        int32_t intval = (int32_t) val;
        return create(intval);
    }

    Value Value::create(int64_t &val) {
        Value value;
        value.type = LARGE_INTEGER;
        value.value = new int64_t(val);
        return value;
    }

    Value Value::create(int32_t &val) {
        Value value;
        value.type = INTEGER;
        value.value = new int32_t(val);
        return value;
    }

    Value Value::create(int16_t &val) {
        int32_t intval = (int32_t) val;
        return create(intval);
    }

    Value Value::create(int8_t &val) {
        int32_t intval = (int32_t) val;
        return create(intval);
    }

    Value Value::create(std::string &val) {
        Value value;
        value.type = STRING;
        value.value = new std::string(val);
        return value;
    }

    Value Value::create(const char *&val) {
        std::string str = std::string(val);
        return create(str);
    }

    std::string Value::toString(size_t indent) {
        std::stringstream result, tabs;
        for (size_t i = 0; i < indent; i++)
            tabs << "\t";
        std::string indentation = tabs.str();

        switch (type) {
            case OBJECT: {
                Object &obj = this->as<Object>();
                result << "{" << std::endl;
                for (auto it = obj.begin(); it != obj.end();) {
                    result << indentation << "\t\"" << it->first << "\": ";
                    result << it->second.toString(indent + 1);
                    if (++it != obj.end())
                        result << ",";
                    result << std::endl;
                }
                if (obj.size())
                    result << indentation;
                result << "}";
                break;
            }
            case ARRAY: {
                Array &arr = this->as<Array>();
                result << "[";
                for (size_t i = 0; i < arr.size(); i++) {
                    result << arr.at(i).toString(indent);
                    if (i + 1 < arr.size())
                        result << ",";
                }
                result << "]";
                break;
            }
            case STRING:
                result << "\"" << this->as<std::string>() << "\"";
                break;
            case INTEGER:
                result << this->as<int32_t>();
                break;
            case LARGE_INTEGER:
                result << this->as<int64_t>();
                break;
            case FLOAT:
                result << this->as<float>();
                break;
            case BOOL:
                result << (this->as<bool>() ? "true" : "false");
                break;
            default:
                result << "undefined";
                break;
            case UNDEFINED:
                break;
        }
        return result.str();
    }

    void Value::destroy() {
        switch (type) {
            case OBJECT: {
                Object &obj = this->as<Object>();
                for (auto it = obj.begin(); it != obj.end(); it++) {
                    it->second.destroy();
                }
                delete &obj;
                break;
            }
            case ARRAY: {
                Array &arr = this->as<Array>();
                for (size_t i = 0; i < arr.size(); i++) {
                    arr.at(i).destroy();
                }
                delete &arr;
                break;
            }
            case STRING:
                delete &this->as<std::string>();
                break;
            case INTEGER:
                delete &this->as<int32_t>();
                break;
            case LARGE_INTEGER:
                delete &this->as<int64_t>();
                break;
            case FLOAT:
                delete &this->as<float>();
                break;
            case BOOL:
                delete &this->as<bool>();
                break;
            case UNDEFINED:
                break;
        }
        type = UNDEFINED;
        value = nullptr;
    }

    void Object::set(std::string name, Value value) {
        map.insert(std::pair<std::string, Value> {name, value});
    }

    Value Object::get(std::string name) {
        return map.at(name);
    }

    size_t Object::size() {
        return map.size();
    }

    void Array::push(Value value) {
        vector.push_back(value);
    }

    size_t Array::size() {
        return vector.size();
    }

    Value Array::at(size_t index) {
        return vector.at(index);
    }
}
<commit_msg>Fix JSON formatting<commit_after>#include "Value.h"

#include <sstream>
#include <cassert>

namespace libol {
    Value Value::create(Object &val) {
        Value value;
        value.type = OBJECT;
        value.value = new Object(val);
        return value;
    }

    Value Value::create(Array &val) {
        Value value;
        value.type = ARRAY;
        value.value = new Array(val);
        return value;
    }

    Value Value::create(float &val) {
        Value value;
        value.type = FLOAT;
        value.value = new float(val);
        return value;
    }

    Value Value::create(bool &val) {
        Value value;
        value.type = BOOL;
        value.value = new bool(val);
        return value;
    }

    Value Value::create(uint64_t &val) {
        assert(!(val & ((uint64_t) 1 << 61))); // assert that the msb is not set
        return create((int64_t &) val);
    }

    Value Value::create(uint32_t &val) {
        if (val >= 2147483648) {
            int64_t large = (int64_t) val;
            return create(large);
        }
        return create((int32_t &) val);
    }

    Value Value::create(uint16_t &val) {
        int32_t intval = (int32_t) val;
        return create(intval);
    }

    Value Value::create(uint8_t &val) {
        int32_t intval = (int32_t) val;
        return create(intval);
    }

    Value Value::create(int64_t &val) {
        Value value;
        value.type = LARGE_INTEGER;
        value.value = new int64_t(val);
        return value;
    }

    Value Value::create(int32_t &val) {
        Value value;
        value.type = INTEGER;
        value.value = new int32_t(val);
        return value;
    }

    Value Value::create(int16_t &val) {
        int32_t intval = (int32_t) val;
        return create(intval);
    }

    Value Value::create(int8_t &val) {
        int32_t intval = (int32_t) val;
        return create(intval);
    }

    Value Value::create(std::string &val) {
        Value value;
        value.type = STRING;
        value.value = new std::string(val);
        return value;
    }

    Value Value::create(const char *&val) {
        std::string str = std::string(val);
        return create(str);
    }

    std::string Value::toString(size_t indent) {
        std::stringstream result, tabs;
        for (size_t i = 0; i < indent; i++)
            tabs << "\t";
        std::string indentation = tabs.str();

        switch (type) {
            case OBJECT: {
                Object &obj = this->as<Object>();
                result << "{";
                if(obj.size())
                    result << std::endl;
                for (auto it = obj.begin(); it != obj.end();) {
                    result << indentation << "\t\"" << it->first << "\": ";
                    result << it->second.toString(indent + 1);
                    if (++it != obj.end())
                        result << ",";
                    result << std::endl;
                }
                if (obj.size())
                    result << indentation;
                result << "}";
                break;
            }
            case ARRAY: {
                Array &arr = this->as<Array>();
                result << "[";
                for (size_t i = 0; i < arr.size(); i++) {
                    result << arr.at(i).toString(indent);
                    if (i + 1 < arr.size())
                        result << ",";
                }
                result << "]";
                break;
            }
            case STRING:
                result << "\"" << this->as<std::string>() << "\"";
                break;
            case INTEGER:
                result << this->as<int32_t>();
                break;
            case LARGE_INTEGER:
                result << this->as<int64_t>();
                break;
            case FLOAT:
                result << this->as<float>();
                break;
            case BOOL:
                result << (this->as<bool>() ? "true" : "false");
                break;
            default:
                result << "undefined";
                break;
            case UNDEFINED:
                break;
        }
        return result.str();
    }

    void Value::destroy() {
        switch (type) {
            case OBJECT: {
                Object &obj = this->as<Object>();
                for (auto it = obj.begin(); it != obj.end(); it++) {
                    it->second.destroy();
                }
                delete &obj;
                break;
            }
            case ARRAY: {
                Array &arr = this->as<Array>();
                for (size_t i = 0; i < arr.size(); i++) {
                    arr.at(i).destroy();
                }
                delete &arr;
                break;
            }
            case STRING:
                delete &this->as<std::string>();
                break;
            case INTEGER:
                delete &this->as<int32_t>();
                break;
            case LARGE_INTEGER:
                delete &this->as<int64_t>();
                break;
            case FLOAT:
                delete &this->as<float>();
                break;
            case BOOL:
                delete &this->as<bool>();
                break;
            case UNDEFINED:
                break;
        }
        type = UNDEFINED;
        value = nullptr;
    }

    void Object::set(std::string name, Value value) {
        map.insert(std::pair<std::string, Value> {name, value});
    }

    Value Object::get(std::string name) {
        return map.at(name);
    }

    size_t Object::size() {
        return map.size();
    }

    void Array::push(Value value) {
        vector.push_back(value);
    }

    size_t Array::size() {
        return vector.size();
    }

    Value Array::at(size_t index) {
        return vector.at(index);
    }
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: sddlgfact.hxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 04:18: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_DLGFACT_HXX
#define _SD_DLGFACT_HXX

// include ---------------------------------------------------------------
#include "sdabstdlg.hxx"

#define DECL_ABSTDLG_BASE(Class,DialogClass)        \
    DialogClass*        pDlg;                       \
public:                                             \
                    Class( DialogClass* p)          \
                     : pDlg(p)                      \
                     {}                             \
    virtual         ~Class();                       \
    virtual USHORT  Execute() ;

#define IMPL_ABSTDLG_BASE(Class)                    \
Class::~Class()                                     \
{                                                   \
    delete pDlg;                                    \
}                                                   \
USHORT Class::Execute()                             \
{                                                   \
    return pDlg->Execute();                         \
}

namespace sd {
    class MorphDlg;
    class CopyDlg;
    class BreakDlg;
    class OutlineBulletDlg;
        class HeaderFooterDialog;
}
// add for BreakDlg
class Dialog;
class VclAbstractDialog_Impl : public VclAbstractDialog
{
    DECL_ABSTDLG_BASE(VclAbstractDialog_Impl,Dialog);
};

// add for CopyDlg

class AbstractCopyDlg_Impl : public AbstractCopyDlg
{
    DECL_ABSTDLG_BASE(AbstractCopyDlg_Impl,::sd::CopyDlg);
    virtual void    GetAttr( SfxItemSet& rOutAttrs );
};

// add for SdCustomShowDlg
class SdCustomShowDlg;
class AbstractSdCustomShowDlg_Impl : public AbstractSdCustomShowDlg
{
    DECL_ABSTDLG_BASE(AbstractSdCustomShowDlg_Impl,SdCustomShowDlg);
    virtual BOOL        IsModified() const ;
    virtual BOOL        IsCustomShow() const ;
};

//add for SdCharDlg begin
class SfxTabDialog;
class AbstractTabDialog_Impl : public SfxAbstractTabDialog
{
    DECL_ABSTDLG_BASE( AbstractTabDialog_Impl,SfxTabDialog );
    virtual void                SetCurPageId( USHORT nId );
    virtual const SfxItemSet*   GetOutputItemSet() const;
    virtual const USHORT*       GetInputRanges( const SfxItemPool& pItem ); //add by CHINA001
    virtual void                SetInputSet( const SfxItemSet* pInSet );   //add by CHINA001
        //From class Window.
    virtual void        SetText( const XubString& rStr ); //add by CHINA001
    virtual String      GetText() const; //add by CHINA001
};
//add for SdCharDlg end

//add for OutlineBulletDlg begin
class SfxTabDialog;
class AbstractBulletDialog_Impl : public SfxAbstractTabDialog
{
    DECL_ABSTDLG_BASE( AbstractBulletDialog_Impl,SfxTabDialog );
    virtual void                SetCurPageId( USHORT nId );
    virtual const SfxItemSet*   GetOutputItemSet() const;
    virtual const USHORT*       GetInputRanges( const SfxItemPool& pItem );
    virtual void                SetInputSet( const SfxItemSet* pInSet );
        //From class Window.
    virtual void        SetText( const XubString& rStr );
    virtual String      GetText() const;
};
//add for OutlineBulletDlg end

class SdPresLayoutTemplateDlg;
class SdPresLayoutTemplateDlg_Impl : public SfxAbstractTabDialog
{
    DECL_ABSTDLG_BASE( SdPresLayoutTemplateDlg_Impl,SdPresLayoutTemplateDlg );
    virtual void                SetCurPageId( USHORT nId );
    virtual const SfxItemSet*   GetOutputItemSet() const;
    virtual const USHORT*       GetInputRanges( const SfxItemPool& pItem ); //add by CHINA001
    virtual void                SetInputSet( const SfxItemSet* pInSet );   //add by CHINA001
        //From class Window.
    virtual void        SetText( const XubString& rStr ); //add by CHINA001
    virtual String      GetText() const; //add by CHINA001
};

// add for AssistentDlg
class AssistentDlg;
class AbstractAssistentDlg_Impl : public AbstractAssistentDlg
{
    DECL_ABSTDLG_BASE(AbstractAssistentDlg_Impl,AssistentDlg);
    virtual SfxObjectShellLock GetDocument();
    virtual OutputType GetOutputMedium() const;
    virtual BOOL IsSummary() const;
    virtual StartType GetStartType() const;
    virtual String GetDocPath() const;
    virtual BOOL GetStartWithFlag() const;
    virtual BOOL IsDocEmpty() const;
    virtual String GetPassword();
};

// add for SdModifyFieldDlg
class SdModifyFieldDlg;
class AbstractSdModifyFieldDlg_Impl : public AbstractSdModifyFieldDlg
{
    DECL_ABSTDLG_BASE(AbstractSdModifyFieldDlg_Impl,SdModifyFieldDlg);
    virtual SvxFieldData*       GetField();
    virtual SfxItemSet          GetItemSet();
};

// add for SdSnapLineDlg
class SdSnapLineDlg;
class AbstractSdSnapLineDlg_Impl : public AbstractSdSnapLineDlg
{
    DECL_ABSTDLG_BASE(AbstractSdSnapLineDlg_Impl,SdSnapLineDlg);
    virtual void GetAttr(SfxItemSet& rOutAttrs);
    virtual void HideRadioGroup();
    virtual void HideDeleteBtn();
    virtual void SetInputFields(BOOL bEnableX, BOOL bEnableY);
    //from class Window
    virtual void    SetText( const XubString& rStr );
};

// add for SdInsertLayerDlg
class SdInsertLayerDlg;
class AbstractSdInsertLayerDlg_Impl : public AbstractSdInsertLayerDlg
{
    DECL_ABSTDLG_BASE(AbstractSdInsertLayerDlg_Impl,SdInsertLayerDlg);
    virtual void    GetAttr( SfxItemSet& rOutAttrs ) ;
    //from class Window
    virtual void    SetHelpId( ULONG nHelpId ) ;
};

// add for SdInsertPasteDlg
class SdInsertPasteDlg;
class AbstractSdInsertPasteDlg_Impl : public AbstractSdInsertPasteDlg
{
    DECL_ABSTDLG_BASE(AbstractSdInsertPasteDlg_Impl,SdInsertPasteDlg);
    virtual BOOL            IsInsertBefore() const;
};

// add for SdInsertPagesObjsDlg
class SdInsertPagesObjsDlg;
class AbstractSdInsertPagesObjsDlg_Impl : public AbstractSdInsertPagesObjsDlg
{
    DECL_ABSTDLG_BASE(AbstractSdInsertPagesObjsDlg_Impl,SdInsertPagesObjsDlg);
    virtual ::Window *  GetWindow(); //this method is added for return a Window type pointer
    virtual List*       GetList( USHORT nType );
    virtual BOOL        IsLink();
    virtual BOOL        IsRemoveUnnessesaryMasterPages() const;
};

// add for MorphDlg
class AbstractMorphDlg_Impl : public AbstractMorphDlg
{
    DECL_ABSTDLG_BASE(AbstractMorphDlg_Impl,::sd::MorphDlg);
    virtual void            SaveSettings() const;
    virtual USHORT          GetFadeSteps() const;
    virtual BOOL            IsAttributeFade() const ;
    virtual BOOL            IsOrientationFade() const ;
};

// add for SdNewFoilDlg
class SdNewFoilDlg;
class AbstractSdNewFoilDlg_Impl : public AbstractSdNewFoilDlg
{
    DECL_ABSTDLG_BASE(AbstractSdNewFoilDlg_Impl,SdNewFoilDlg);
    virtual void    GetAttr( SfxItemSet& rOutAttrs );
};

// add for SdStartPresentationDlg
class SdStartPresentationDlg;
class AbstractSdStartPresDlg_Impl : public AbstractSdStartPresDlg
{
    DECL_ABSTDLG_BASE(AbstractSdStartPresDlg_Impl,SdStartPresentationDlg);
    virtual void    GetAttr( SfxItemSet& rOutAttrs );
};

// add for SdPrintDlg
class SdPrintDlg;
class AbstractSdPrintDlg_Impl : public AbstractSdPrintDlg
{
    DECL_ABSTDLG_BASE(AbstractSdPrintDlg_Impl,SdPrintDlg);
    virtual USHORT  GetAttr();
};

// add for SdPresLayoutDlg
class SdPresLayoutDlg;
class AbstractSdPresLayoutDlg_Impl : public AbstractSdPresLayoutDlg
{
    DECL_ABSTDLG_BASE(AbstractSdPresLayoutDlg_Impl,SdPresLayoutDlg);
    virtual void    GetAttr(SfxItemSet& rOutAttrs);
};

// add for SdActionDlg
class SfxSingleTabDialog;
class AbstractSfxSingleTabDialog_Impl :public AbstractSfxSingleTabDialog
{
    DECL_ABSTDLG_BASE(AbstractSfxSingleTabDialog_Impl,SfxSingleTabDialog);
    virtual const SfxItemSet*   GetOutputItemSet() const;
};

// add for SdVectorizeDlg
class SdVectorizeDlg;
class AbstractSdVectorizeDlg_Impl :public AbstractSdVectorizeDlg
{
    DECL_ABSTDLG_BASE(AbstractSdVectorizeDlg_Impl,SdVectorizeDlg);
    virtual const GDIMetaFile&  GetGDIMetaFile() const ;
};

// add for SdPublishingDlg
class SdPublishingDlg;
class AbstractSdPublishingDlg_Impl :public AbstractSdPublishingDlg
{
    DECL_ABSTDLG_BASE(AbstractSdPublishingDlg_Impl,SdPublishingDlg);
    virtual void GetParameterSequence( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rParams );
};

// add for HeaderFooterDialog
class AbstractHeaderFooterDialog_Impl :public AbstractHeaderFooterDialog
{
  DECL_ABSTDLG_BASE(AbstractHeaderFooterDialog_Impl,::sd::HeaderFooterDialog);
  virtual void ApplyToAll( TabPage* pPage );
  virtual void Apply( TabPage* pPage );
  virtual void Cancel( TabPage* pPage );
};

//------------------------------------------------------------------------
//AbstractDialogFactory_Impl implementations
class SdAbstractDialogFactory_Impl : public SdAbstractDialogFactory
{

public:
    virtual VclAbstractDialog*          CreateBreakDlg( const ResId& rResId,
                                            ::Window* pWindow,
                                            ::sd::DrawView* pDrView,
                                            ::sd::DrawDocShell* pShell,
                                            ULONG nSumActionCount,
                                            ULONG nObjCount ); //add for BreakDlg
    virtual AbstractCopyDlg*            CreateCopyDlg( const ResId& rResId,
                                            ::Window* pWindow, const SfxItemSet& rInAttrs,
                                            XColorTable* pColTab, ::sd::View* pView ); //add for CopyDlg
    virtual AbstractSdCustomShowDlg*    CreateSdCustomShowDlg( const ResId& rResId,
                                            ::Window* pWindow, SdDrawDocument& rDrawDoc ); //add for SdCustomShowDlg
    virtual SfxAbstractTabDialog*       CreateSdTabDialog( const ResId& rResId,
                                            ::Window* pParent, const SfxItemSet* pAttr,
                                            SfxObjectShell* pDocShell, BOOL bAreaPage = TRUE ); //add for SdCharDlg, SdPageDlg
    virtual AbstractAssistentDlg*       CreateAssistentDlg( const ResId& rResId,
                                            ::Window* pParent, BOOL bAutoPilot); //add for AssistentDlg
    virtual AbstractSdModifyFieldDlg*   CreateSdModifyFieldDlg( const ResId& rResId,
                                            ::Window* pWindow, const SvxFieldData* pInField, const SfxItemSet& rSet ); //add for SdModifyFieldDlg
    virtual AbstractSdSnapLineDlg*      CreateSdSnapLineDlg( const ResId& rResId,
                                            ::Window* pWindow, const SfxItemSet& rInAttrs, ::sd::View* pView); //add for SdSnapLineDlg
    virtual AbstractSdInsertLayerDlg*   CreateSdInsertLayerDlg( const ResId& rResId,
                                            ::Window* pWindow,
                                            const SfxItemSet& rInAttrs,
                                            BOOL bDeletable,
                                            String aStr ); //add for SdInsertLayerDlg
    virtual AbstractSdInsertPasteDlg*   CreateSdInsertPasteDlg( const ResId& rResId, ::Window* pWindow ); //add for SdInsertPasteDlg
    virtual AbstractSdInsertPagesObjsDlg*   CreateSdInsertPagesObjsDlg( const ResId& rResId,
                                                ::Window* pParent,
                                                const SdDrawDocument* pDoc,
                                                SfxMedium* pSfxMedium,
                                                const String& rFileName ); //add for SdInsertPagesObjsDlg
    virtual AbstractMorphDlg*           CreateMorphDlg( const ResId& rResId,
                                                ::Window* pParent,
                                                const SdrObject* pObj1,
                                                const SdrObject* pObj2); //add for MorphDlg
    virtual AbstractSdNewFoilDlg*       CreateSdNewFoilDlg( const ResId& rResId,
                                                ::Window* pWindow,
                                                const SfxItemSet& rInAttrs,
                                                PageKind ePgKind,
                                                ::sd::DrawDocShell* pDocShell,
                                                BOOL bChangeFoil ); //add for SdNewFoilDlg
    virtual SfxAbstractTabDialog*       CreateSdItemSetTabDlg ( const ResId& rResId,
                                                ::Window* pParent,
                                                const SfxItemSet* pAttr,
                                                ::sd::View* pView = NULL ); //add for OutlineBulletDlg,SdParagraphDlg
    virtual AbstractSdStartPresDlg*     CreateSdStartPresentationDlg( const ResId& rResId,
                                                ::Window* pWindow,
                                                const SfxItemSet& rInAttrs,
                                                List& rPageNames,
                                                List* pCSList ); //add for SdStartPresentationDlg
    virtual AbstractSdPrintDlg*         CreateSdPrintDlg( const ResId& rResId, ::Window* pWindow ); //add for SdPrintDlg
    virtual SfxAbstractTabDialog*       CreateSdPresLayoutTemplateDlg( const ResId& rResId,
                                                SfxObjectShell* pDocSh, ::Window* pParent,
                                                SdResId DlgId, SfxStyleSheetBase& rStyleBase,
                                                PresentationObjects ePO, SfxStyleSheetBasePool* pSSPool ); //add for SdPresLayoutTemplateDlg
    virtual AbstractSdPresLayoutDlg*    CreateSdPresLayoutDlg( const ResId& rResId,
                                                ::sd::DrawDocShell* pDocShell,
                                                ::sd::ViewShell* pViewShell,
                                                ::Window* pWindow,
                                                const SfxItemSet& rInAttrs); //add for SdPresLayoutDlg
    virtual SfxAbstractTabDialog*       CreateSdTabTemplateDlg( const ResId& rResId,
                                                ::Window* pParent,
                                                const SfxObjectShell* pDocShell,
                                                SfxStyleSheetBase& rStyleBase,
                                                SdrModel* pModel,
                                                SdrView* pView ); //add for SdTabTemplateDlg
    virtual AbstractSfxSingleTabDialog* CreateSfxSingleTabDialog( const ResId& rResId,
                                                ::Window* pParent,
                                                const SfxItemSet* pAttr,
                                                ::sd::View* pView ); //add for SdActionDlg
    virtual AbstractSdVectorizeDlg*     CreateSdVectorizeDlg( const ResId& rResId,
                                                ::Window* pParent, const Bitmap& rBmp,
                                                ::sd::DrawDocShell* pDocShell ); //add for SdVectorizeDlg
    virtual AbstractSdPublishingDlg*    CreateSdPublishingDlg( const ResId& rResId,
                                                ::Window* pWindow, DocumentType eDocType); //add for SdPublishingDlg

      virtual VclAbstractDialog*          CreateMasterLayoutDialog( ::Window* pParent,
                                                                  SdDrawDocument* pDoc,
                                                                  SdPage* ); // add for MasterLayoutDialog

    virtual AbstractHeaderFooterDialog* CreateHeaderFooterDialog( ViewShell* pViewShell,
                                                                  ::Window* pParent,
                                                                  SdDrawDocument* pDoc,
                                                                  SdPage* pCurrentPage ); // add for HeaderFooterDialog

    // For TabPage
    virtual CreateTabPage               GetTabPageCreatorFunc( USHORT nId );

    virtual GetTabPageRanges            GetTabPageRangesFunc( USHORT nId );

};

#endif

<commit_msg>INTEGRATION: CWS sdwarningsbegone (1.6.316); FILE MERGED 2006/11/27 13:47:59 cl 1.6.316.2: #i69285# warning free code changes for sd project 2006/11/22 12:41:48 cl 1.6.316.1: #i69285# warning free code changes for unxlngi6.pro<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: sddlgfact.hxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: kz $ $Date: 2006-12-12 17:09:17 $
 *
 *  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_DLGFACT_HXX
#define _SD_DLGFACT_HXX

// include ---------------------------------------------------------------
#include "sdabstdlg.hxx"

#define DECL_ABSTDLG_BASE(Class,DialogClass)        \
    DialogClass*        pDlg;                       \
public:                                             \
                    Class( DialogClass* p)          \
                     : pDlg(p)                      \
                     {}                             \
    virtual         ~Class();                       \
    virtual USHORT  Execute() ;

#define IMPL_ABSTDLG_BASE(Class)                    \
Class::~Class()                                     \
{                                                   \
    delete pDlg;                                    \
}                                                   \
USHORT Class::Execute()                             \
{                                                   \
    return pDlg->Execute();                         \
}

namespace sd {
    class MorphDlg;
    class CopyDlg;
    class BreakDlg;
    class OutlineBulletDlg;
        class HeaderFooterDialog;
}
// add for BreakDlg
class Dialog;
class VclAbstractDialog_Impl : public VclAbstractDialog
{
    DECL_ABSTDLG_BASE(VclAbstractDialog_Impl,Dialog)
};

// add for CopyDlg

class AbstractCopyDlg_Impl : public AbstractCopyDlg
{
    DECL_ABSTDLG_BASE(AbstractCopyDlg_Impl,::sd::CopyDlg)
    virtual void    GetAttr( SfxItemSet& rOutAttrs );
};

// add for SdCustomShowDlg
class SdCustomShowDlg;
class AbstractSdCustomShowDlg_Impl : public AbstractSdCustomShowDlg
{
    DECL_ABSTDLG_BASE(AbstractSdCustomShowDlg_Impl,SdCustomShowDlg)
    virtual BOOL        IsModified() const ;
    virtual BOOL        IsCustomShow() const ;
};

//add for SdCharDlg begin
class SfxTabDialog;
class AbstractTabDialog_Impl : public SfxAbstractTabDialog
{
    DECL_ABSTDLG_BASE( AbstractTabDialog_Impl,SfxTabDialog )
    virtual void                SetCurPageId( USHORT nId );
    virtual const SfxItemSet*   GetOutputItemSet() const;
    virtual const USHORT*       GetInputRanges( const SfxItemPool& pItem );
    virtual void                SetInputSet( const SfxItemSet* pInSet );
        //From class Window.
    virtual void        SetText( const XubString& rStr );
    virtual String      GetText() const;
};
//add for SdCharDlg end

//add for OutlineBulletDlg begin
class SfxTabDialog;
class AbstractBulletDialog_Impl : public SfxAbstractTabDialog
{
    DECL_ABSTDLG_BASE( AbstractBulletDialog_Impl,SfxTabDialog )
    virtual void                SetCurPageId( USHORT nId );
    virtual const SfxItemSet*   GetOutputItemSet() const;
    virtual const USHORT*       GetInputRanges( const SfxItemPool& pItem );
    virtual void                SetInputSet( const SfxItemSet* pInSet );
        //From class Window.
    virtual void        SetText( const XubString& rStr );
    virtual String      GetText() const;
};
//add for OutlineBulletDlg end

class SdPresLayoutTemplateDlg;
class SdPresLayoutTemplateDlg_Impl : public SfxAbstractTabDialog
{
    DECL_ABSTDLG_BASE( SdPresLayoutTemplateDlg_Impl,SdPresLayoutTemplateDlg )
    virtual void                SetCurPageId( USHORT nId );
    virtual const SfxItemSet*   GetOutputItemSet() const;
    virtual const USHORT*       GetInputRanges( const SfxItemPool& pItem );
    virtual void                SetInputSet( const SfxItemSet* pInSet );
        //From class Window.
    virtual void        SetText( const XubString& rStr );
    virtual String      GetText() const;
};

// add for AssistentDlg
class AssistentDlg;
class AbstractAssistentDlg_Impl : public AbstractAssistentDlg
{
    DECL_ABSTDLG_BASE(AbstractAssistentDlg_Impl,AssistentDlg)
    virtual SfxObjectShellLock GetDocument();
    virtual OutputType GetOutputMedium() const;
    virtual BOOL IsSummary() const;
    virtual StartType GetStartType() const;
    virtual String GetDocPath() const;
    virtual BOOL GetStartWithFlag() const;
    virtual BOOL IsDocEmpty() const;
    virtual String GetPassword();
};

// add for SdModifyFieldDlg
class SdModifyFieldDlg;
class AbstractSdModifyFieldDlg_Impl : public AbstractSdModifyFieldDlg
{
    DECL_ABSTDLG_BASE(AbstractSdModifyFieldDlg_Impl,SdModifyFieldDlg)
    virtual SvxFieldData*       GetField();
    virtual SfxItemSet          GetItemSet();
};

// add for SdSnapLineDlg
class SdSnapLineDlg;
class AbstractSdSnapLineDlg_Impl : public AbstractSdSnapLineDlg
{
    DECL_ABSTDLG_BASE(AbstractSdSnapLineDlg_Impl,SdSnapLineDlg)
    virtual void GetAttr(SfxItemSet& rOutAttrs);
    virtual void HideRadioGroup();
    virtual void HideDeleteBtn();
    virtual void SetInputFields(BOOL bEnableX, BOOL bEnableY);
    //from class Window
    virtual void    SetText( const XubString& rStr );
};

// add for SdInsertLayerDlg
class SdInsertLayerDlg;
class AbstractSdInsertLayerDlg_Impl : public AbstractSdInsertLayerDlg
{
    DECL_ABSTDLG_BASE(AbstractSdInsertLayerDlg_Impl,SdInsertLayerDlg)
    virtual void    GetAttr( SfxItemSet& rOutAttrs ) ;
    //from class Window
    virtual void    SetHelpId( ULONG nHelpId ) ;
};

// add for SdInsertPasteDlg
class SdInsertPasteDlg;
class AbstractSdInsertPasteDlg_Impl : public AbstractSdInsertPasteDlg
{
    DECL_ABSTDLG_BASE(AbstractSdInsertPasteDlg_Impl,SdInsertPasteDlg)
    virtual BOOL            IsInsertBefore() const;
};

// add for SdInsertPagesObjsDlg
class SdInsertPagesObjsDlg;
class AbstractSdInsertPagesObjsDlg_Impl : public AbstractSdInsertPagesObjsDlg
{
    DECL_ABSTDLG_BASE(AbstractSdInsertPagesObjsDlg_Impl,SdInsertPagesObjsDlg)
    virtual ::Window *  GetWindow(); //this method is added for return a Window type pointer
    virtual List*       GetList( USHORT nType );
    virtual BOOL        IsLink();
    virtual BOOL        IsRemoveUnnessesaryMasterPages() const;
};

// add for MorphDlg
class AbstractMorphDlg_Impl : public AbstractMorphDlg
{
    DECL_ABSTDLG_BASE(AbstractMorphDlg_Impl,::sd::MorphDlg)
    virtual void            SaveSettings() const;
    virtual USHORT          GetFadeSteps() const;
    virtual BOOL            IsAttributeFade() const ;
    virtual BOOL            IsOrientationFade() const ;
};

// add for SdStartPresentationDlg
class SdStartPresentationDlg;
class AbstractSdStartPresDlg_Impl : public AbstractSdStartPresDlg
{
    DECL_ABSTDLG_BASE(AbstractSdStartPresDlg_Impl,SdStartPresentationDlg)
    virtual void    GetAttr( SfxItemSet& rOutAttrs );
};

// add for SdPrintDlg
class SdPrintDlg;
class AbstractSdPrintDlg_Impl : public AbstractSdPrintDlg
{
    DECL_ABSTDLG_BASE(AbstractSdPrintDlg_Impl,SdPrintDlg)
    virtual USHORT  GetAttr();
};

// add for SdPresLayoutDlg
class SdPresLayoutDlg;
class AbstractSdPresLayoutDlg_Impl : public AbstractSdPresLayoutDlg
{
    DECL_ABSTDLG_BASE(AbstractSdPresLayoutDlg_Impl,SdPresLayoutDlg)
    virtual void    GetAttr(SfxItemSet& rOutAttrs);
};

// add for SdActionDlg
class SfxSingleTabDialog;
class AbstractSfxSingleTabDialog_Impl :public AbstractSfxSingleTabDialog
{
    DECL_ABSTDLG_BASE(AbstractSfxSingleTabDialog_Impl,SfxSingleTabDialog)
    virtual const SfxItemSet*   GetOutputItemSet() const;
};

// add for SdVectorizeDlg
class SdVectorizeDlg;
class AbstractSdVectorizeDlg_Impl :public AbstractSdVectorizeDlg
{
    DECL_ABSTDLG_BASE(AbstractSdVectorizeDlg_Impl,SdVectorizeDlg)
    virtual const GDIMetaFile&  GetGDIMetaFile() const ;
};

// add for SdPublishingDlg
class SdPublishingDlg;
class AbstractSdPublishingDlg_Impl :public AbstractSdPublishingDlg
{
    DECL_ABSTDLG_BASE(AbstractSdPublishingDlg_Impl,SdPublishingDlg)
    virtual void GetParameterSequence( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rParams );
};

// add for HeaderFooterDialog
class AbstractHeaderFooterDialog_Impl :public AbstractHeaderFooterDialog
{
  DECL_ABSTDLG_BASE(AbstractHeaderFooterDialog_Impl,::sd::HeaderFooterDialog)
  virtual void ApplyToAll( TabPage* pPage );
  virtual void Apply( TabPage* pPage );
  virtual void Cancel( TabPage* pPage );
};

//------------------------------------------------------------------------
//AbstractDialogFactory_Impl implementations
class SdAbstractDialogFactory_Impl : public SdAbstractDialogFactory
{

public:
    virtual VclAbstractDialog*          CreateBreakDlg(::Window* pWindow, ::sd::DrawView* pDrView, ::sd::DrawDocShell* pShell, ULONG nSumActionCount, ULONG nObjCount );
    virtual AbstractCopyDlg*            CreateCopyDlg( ::Window* pWindow, const SfxItemSet& rInAttrs, XColorTable* pColTab, ::sd::View* pView );
    virtual AbstractSdCustomShowDlg*    CreateSdCustomShowDlg( ::Window* pWindow, SdDrawDocument& rDrawDoc );
    virtual SfxAbstractTabDialog*       CreateSdTabCharDialog( ::Window* pParent, const SfxItemSet* pAttr, SfxObjectShell* pDocShell );
    virtual SfxAbstractTabDialog*       CreateSdTabPageDialog( ::Window* pParent, const SfxItemSet* pAttr, SfxObjectShell* pDocShell, BOOL bAreaPage = TRUE );
    virtual AbstractAssistentDlg*       CreateAssistentDlg( ::Window* pParent, BOOL bAutoPilot);
    virtual AbstractSdModifyFieldDlg*   CreateSdModifyFieldDlg( ::Window* pWindow, const SvxFieldData* pInField, const SfxItemSet& rSet );
    virtual AbstractSdSnapLineDlg*      CreateSdSnapLineDlg( ::Window* pWindow, const SfxItemSet& rInAttrs, ::sd::View* pView);
    virtual AbstractSdInsertLayerDlg*   CreateSdInsertLayerDlg( ::Window* pWindow, const SfxItemSet& rInAttrs, BOOL bDeletable, String aStr );
    virtual AbstractSdInsertPasteDlg*   CreateSdInsertPasteDlg( ::Window* pWindow );
    virtual AbstractSdInsertPagesObjsDlg* CreateSdInsertPagesObjsDlg( ::Window* pParent, const SdDrawDocument* pDoc, SfxMedium* pSfxMedium, const String& rFileName );
    virtual AbstractMorphDlg*           CreateMorphDlg( ::Window* pParent, const SdrObject* pObj1, const SdrObject* pObj2);
    virtual SfxAbstractTabDialog*       CreateSdOutlineBulletTabDlg ( ::Window* pParent, const SfxItemSet* pAttr, ::sd::View* pView = NULL );
    virtual SfxAbstractTabDialog*       CreateSdParagraphTabDlg ( ::Window* pParent, const SfxItemSet* pAttr );
    virtual AbstractSdStartPresDlg*     CreateSdStartPresentationDlg( ::Window* pWindow, const SfxItemSet& rInAttrs, List& rPageNames, List* pCSList );
    virtual AbstractSdPrintDlg*         CreateSdPrintDlg( ::Window* pWindow ); //add for SdPrintDlg
    virtual SfxAbstractTabDialog*       CreateSdPresLayoutTemplateDlg( SfxObjectShell* pDocSh, ::Window* pParent, SdResId DlgId, SfxStyleSheetBase& rStyleBase, PresentationObjects ePO, SfxStyleSheetBasePool* pSSPool );
    virtual AbstractSdPresLayoutDlg*    CreateSdPresLayoutDlg( ::sd::DrawDocShell* pDocShell, ::sd::ViewShell* pViewShell, ::Window* pWindow, const SfxItemSet& rInAttrs);
    virtual SfxAbstractTabDialog*       CreateSdTabTemplateDlg( ::Window* pParent, const SfxObjectShell* pDocShell, SfxStyleSheetBase& rStyleBase, SdrModel* pModel, SdrView* pView );
    virtual AbstractSfxSingleTabDialog* CreatSdActionDialog( ::Window* pParent, const SfxItemSet* pAttr, ::sd::View* pView );
    virtual AbstractSdVectorizeDlg*     CreateSdVectorizeDlg( ::Window* pParent, const Bitmap& rBmp, ::sd::DrawDocShell* pDocShell );
    virtual AbstractSdPublishingDlg*    CreateSdPublishingDlg( ::Window* pWindow, DocumentType eDocType);

      virtual VclAbstractDialog*          CreateMasterLayoutDialog( ::Window* pParent,
                                                                  SdDrawDocument* pDoc,
                                                                  SdPage* ); // add for MasterLayoutDialog

    virtual AbstractHeaderFooterDialog* CreateHeaderFooterDialog( ViewShell* pViewShell,
                                                                  ::Window* pParent,
                                                                  SdDrawDocument* pDoc,
                                                                  SdPage* pCurrentPage ); // add for HeaderFooterDialog

    // For TabPage
    virtual CreateTabPage               GetSdOptionsContentsTabPageCreatorFunc();
    virtual CreateTabPage               GetSdPrintOptionsTabPageCreatorFunc();
    virtual CreateTabPage               GetSdOptionsMiscTabPageCreatorFunc();
    virtual CreateTabPage               GetSdOptionsSnapTabPageCreatorFunc();
};

#endif

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: fuoltext.cxx,v $
 *
 *  $Revision: 1.12 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-16 18:52:52 $
 *
 *  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_sd.hxx"

#include "fuoltext.hxx"

#include <sfx2/viewfrm.hxx>

#ifndef _OUTLINER_HXX
#include <svx/outliner.hxx>
#endif
#ifndef _EEITEM_HXX //autogen
#include <svx/eeitem.hxx>
#endif
#define ITEMID_FIELD    EE_FEATURE_FIELD
#ifndef _SVX_FLDITEM_HXX //autogen
#include <svx/flditem.hxx>
#endif
#ifndef _SFX_BINDINGS_HXX //autogen
#include <sfx2/bindings.hxx>
#endif
#ifndef _SFXDOCFILE_HXX
#include <sfx2/docfile.hxx>
#endif
#ifndef _SFXDISPATCH_HXX
#include <sfx2/dispatch.hxx>
#endif

#include <svx/svxids.hrc>
#include "app.hrc"
#ifndef SD_OUTLINE_VIEW_HXX
#include "OutlineView.hxx"
#endif
#ifndef SD_WINDOW_SHELL_HXX
#include "Window.hxx"
#endif
#include "DrawDocShell.hxx"
#ifndef SD_VIEW_SHELL_HXX
#include "ViewShell.hxx"
#endif
#ifndef SD_OUTLINE_VIEW_SHELL_HXX
#include "OutlineViewShell.hxx"
#endif

#include <stdio.h>          // Fuer SlotFilter-Listing

namespace sd {

static USHORT SidArray[] = {
                SID_STYLE_FAMILY2,
                SID_STYLE_FAMILY5,
                SID_STYLE_UPDATE_BY_EXAMPLE,
                SID_CUT,
                SID_COPY,
                SID_PASTE,
                SID_SELECTALL,
                SID_ATTR_CHAR_FONT,
                SID_ATTR_CHAR_POSTURE,
                SID_ATTR_CHAR_WEIGHT,
                SID_ATTR_CHAR_UNDERLINE,
                SID_ATTR_CHAR_FONTHEIGHT,
                SID_ATTR_CHAR_COLOR,
                SID_OUTLINE_UP,
                SID_OUTLINE_DOWN,
                SID_OUTLINE_LEFT,
                SID_OUTLINE_RIGHT,
                //SID_OUTLINE_FORMAT,
                SID_OUTLINE_COLLAPSE_ALL,
                //SID_OUTLINE_BULLET,
                SID_OUTLINE_COLLAPSE,
                SID_OUTLINE_EXPAND_ALL,
                SID_OUTLINE_EXPAND,
                SID_SET_SUPER_SCRIPT,
                SID_SET_SUB_SCRIPT,
                SID_HYPERLINK_GETLINK,
                SID_PRESENTATION_TEMPLATES,
                SID_STATUS_PAGE,
                SID_STATUS_LAYOUT,
                SID_EXPAND_PAGE,
                SID_SUMMARY_PAGE,
                SID_PARASPACE_INCREASE,
                SID_PARASPACE_DECREASE,
                0 };

TYPEINIT1( FuOutlineText, FuOutline );

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

FuOutlineText::FuOutlineText(ViewShell* pViewShell, ::sd::Window* pWindow,
                             ::sd::View* pView, SdDrawDocument* pDoc,
                             SfxRequest& rReq)
       : FuOutline(pViewShell, pWindow, pView, pDoc, rReq)
{
}

FunctionReference FuOutlineText::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
{
    FunctionReference xFunc( new FuOutlineText( pViewSh, pWin, pView, pDoc, rReq ) );
    xFunc->DoExecute( rReq );
    return xFunc;
}

/*************************************************************************
|*
|* MouseButtonDown-event
|*
\************************************************************************/

BOOL FuOutlineText::MouseButtonDown(const MouseEvent& rMEvt)
{
    BOOL bReturn = FALSE;

    pWindow->GrabFocus();

    bReturn = pOutlineView->GetViewByWindow(pWindow)->MouseButtonDown(rMEvt);

    if (bReturn)
    {
        // Attributierung der akt. Textstelle kann jetzt anders sein
        pViewShell->GetViewFrame()->GetBindings().Invalidate( SidArray );
    }
    else
    {
        bReturn = FuOutline::MouseButtonDown(rMEvt);
    }

    return (bReturn);
}

/*************************************************************************
|*
|* MouseMove-event
|*
\************************************************************************/

BOOL FuOutlineText::MouseMove(const MouseEvent& rMEvt)
{
    BOOL bReturn = FALSE;

    bReturn = pOutlineView->GetViewByWindow(pWindow)->MouseMove(rMEvt);

    if (!bReturn)
    {
        bReturn = FuOutline::MouseMove(rMEvt);
    }

    // MT 07/2002: Done in OutlinerView::MouseMove
    /*
    const SvxFieldItem* pFieldItem = pOutlineView->GetViewByWindow( pWindow )->
                                        GetFieldUnderMousePointer();
    const SvxFieldData* pField = NULL;
    if( pFieldItem )
        pField = pFieldItem->GetField();

    if( pField && pField->ISA( SvxURLField ) )
    {
       pWindow->SetPointer( Pointer( POINTER_REFHAND ) );
    }
    else
       pWindow->SetPointer( Pointer( POINTER_TEXT ) );
    */

    return (bReturn);
}

/*************************************************************************
|*
|* MouseButtonUp-event
|*
\************************************************************************/

BOOL FuOutlineText::MouseButtonUp(const MouseEvent& rMEvt)
{
    BOOL bReturn = FALSE;

    bReturn = pOutlineView->GetViewByWindow(pWindow)->MouseButtonUp(rMEvt);

    if (bReturn)
    {
        // Attributierung der akt. Textstelle kann jetzt anders sein
        pViewShell->GetViewFrame()->GetBindings().Invalidate( SidArray );
    }
    else
    {
        const SvxFieldItem* pFieldItem = pOutlineView->GetViewByWindow( pWindow )->GetFieldUnderMousePointer();
        if( pFieldItem )
        {
            const SvxFieldData* pField = pFieldItem->GetField();

            if( pField && pField->ISA( SvxURLField ) )
            {
                bReturn = TRUE;
                pWindow->ReleaseMouse();
                SfxStringItem aStrItem( SID_FILE_NAME, ( (SvxURLField*) pField)->GetURL() );
                SfxStringItem aReferer( SID_REFERER, pDocSh->GetMedium()->GetName() );
                SfxBoolItem aBrowseItem( SID_BROWSE, TRUE );
                SfxViewFrame* pFrame = pViewShell->GetViewFrame();

                if ( rMEvt.IsMod1() )
                {
                    // Im neuen Frame oeffnen
                    pFrame->GetDispatcher()->Execute(SID_OPENDOC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
                                &aStrItem, &aBrowseItem, &aReferer, 0L);
                }
                else
                {
                    // Im aktuellen Frame oeffnen
                    SfxFrameItem aFrameItem( SID_DOCFRAME, pFrame );
                    pFrame->GetDispatcher()->Execute(SID_OPENDOC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
                                &aStrItem, &aFrameItem, &aBrowseItem, &aReferer, 0L);
                }
            }
        }
    }

    if( !bReturn )
        bReturn = FuOutline::MouseButtonUp(rMEvt);

    return (bReturn);
}

/*************************************************************************
|*
|* Tastaturereignisse bearbeiten
|*
|* Wird ein KeyEvent bearbeitet, so ist der Return-Wert TRUE, andernfalls
|* FALSE.
|*
\************************************************************************/

BOOL FuOutlineText::KeyInput(const KeyEvent& rKEvt)
{
    BOOL bReturn = FALSE;

    USHORT nKeyGroup = rKEvt.GetKeyCode().GetGroup();
    if( !pDocSh->IsReadOnly() || nKeyGroup == KEYGROUP_CURSOR )
    {
        pWindow->GrabFocus();

        std::auto_ptr< OutlineViewModelChangeGuard > aGuard;

        if( (nKeyGroup != KEYGROUP_CURSOR) && (nKeyGroup != KEYGROUP_FKEYS) )
            aGuard.reset( new OutlineViewModelChangeGuard( *pOutlineView ) );

        bReturn = pOutlineView->GetViewByWindow(pWindow)->PostKeyEvent(rKEvt);

        if (bReturn)
        {
            UpdateForKeyPress (rKEvt);
        }
        else
        {
            bReturn = FuOutline::KeyInput(rKEvt);
        }
    }

    return (bReturn);
}

void FuOutlineText::UpdateForKeyPress (const KeyEvent& rEvent)
{
    // Attributes at the current text position may have changed.
    pViewShell->GetViewFrame()->GetBindings().Invalidate(SidArray);

    bool bUpdatePreview = true;
    switch (rEvent.GetKeyCode().GetCode())
    {
        // When just the cursor has been moved the preview only changes when
        // it moved to entries of another page.  To prevent unnecessary
        // updates we check this here.  This is an early rejection test, so
        // missing a key is not a problem.
        case KEY_UP:
        case KEY_DOWN:
        case KEY_LEFT:
        case KEY_RIGHT:
        case KEY_HOME:
        case KEY_END:
        case KEY_PAGEUP:
        case KEY_PAGEDOWN:
        {
            SdPage* pCurrentPage = pOutlineViewShell->GetActualPage();
            bUpdatePreview = (pCurrentPage != pOutlineViewShell->GetActualPage());
        }
        break;
    }
    if (bUpdatePreview)
        pOutlineViewShell->UpdatePreview (pOutlineViewShell->GetActualPage());
}

/*************************************************************************
|*
|* Function aktivieren
|*
\************************************************************************/

void FuOutlineText::Activate()
{
    FuOutline::Activate();
}

/*************************************************************************
|*
|* Function deaktivieren
|*
\************************************************************************/

void FuOutlineText::Deactivate()
{
    FuOutline::Deactivate();
}

/*************************************************************************
|*
|* Cut object to clipboard
|*
\************************************************************************/

void FuOutlineText::DoCut()
{
    pOutlineView->GetViewByWindow(pWindow)->Cut();
}

/*************************************************************************
|*
|* Copy object to clipboard
|*
\************************************************************************/

void FuOutlineText::DoCopy()
{
    pOutlineView->GetViewByWindow(pWindow)->Copy();
}

/*************************************************************************
|*
|* Paste object from clipboard
|*
\************************************************************************/

void FuOutlineText::DoPaste()
{
    pOutlineView->GetViewByWindow(pWindow)->PasteSpecial();
}

} // end of namespace sd
<commit_msg>INTEGRATION: CWS sdwarningsbegone (1.12.38); FILE MERGED 2006/11/22 12:41:54 cl 1.12.38.1: #i69285# warning free code changes for unxlngi6.pro<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: fuoltext.cxx,v $
 *
 *  $Revision: 1.13 $
 *
 *  last change: $Author: kz $ $Date: 2006-12-12 17:20:50 $
 *
 *  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_sd.hxx"

#include "fuoltext.hxx"

#include <sfx2/viewfrm.hxx>

#ifndef _OUTLINER_HXX
#include <svx/outliner.hxx>
#endif
#ifndef _EEITEM_HXX //autogen
#include <svx/eeitem.hxx>
#endif
#define ITEMID_FIELD    EE_FEATURE_FIELD
#ifndef _SVX_FLDITEM_HXX //autogen
#include <svx/flditem.hxx>
#endif
#ifndef _SFX_BINDINGS_HXX //autogen
#include <sfx2/bindings.hxx>
#endif
#ifndef _SFXDOCFILE_HXX
#include <sfx2/docfile.hxx>
#endif
#ifndef _SFXDISPATCH_HXX
#include <sfx2/dispatch.hxx>
#endif

#include <svx/svxids.hrc>
#include "app.hrc"
#ifndef SD_OUTLINE_VIEW_HXX
#include "OutlineView.hxx"
#endif
#ifndef SD_WINDOW_SHELL_HXX
#include "Window.hxx"
#endif
#include "DrawDocShell.hxx"
#ifndef SD_VIEW_SHELL_HXX
#include "ViewShell.hxx"
#endif
#ifndef SD_OUTLINE_VIEW_SHELL_HXX
#include "OutlineViewShell.hxx"
#endif

#include <stdio.h>          // Fuer SlotFilter-Listing

namespace sd {

static USHORT SidArray[] = {
                SID_STYLE_FAMILY2,
                SID_STYLE_FAMILY5,
                SID_STYLE_UPDATE_BY_EXAMPLE,
                SID_CUT,
                SID_COPY,
                SID_PASTE,
                SID_SELECTALL,
                SID_ATTR_CHAR_FONT,
                SID_ATTR_CHAR_POSTURE,
                SID_ATTR_CHAR_WEIGHT,
                SID_ATTR_CHAR_UNDERLINE,
                SID_ATTR_CHAR_FONTHEIGHT,
                SID_ATTR_CHAR_COLOR,
                SID_OUTLINE_UP,
                SID_OUTLINE_DOWN,
                SID_OUTLINE_LEFT,
                SID_OUTLINE_RIGHT,
                //SID_OUTLINE_FORMAT,
                SID_OUTLINE_COLLAPSE_ALL,
                //SID_OUTLINE_BULLET,
                SID_OUTLINE_COLLAPSE,
                SID_OUTLINE_EXPAND_ALL,
                SID_OUTLINE_EXPAND,
                SID_SET_SUPER_SCRIPT,
                SID_SET_SUB_SCRIPT,
                SID_HYPERLINK_GETLINK,
                SID_PRESENTATION_TEMPLATES,
                SID_STATUS_PAGE,
                SID_STATUS_LAYOUT,
                SID_EXPAND_PAGE,
                SID_SUMMARY_PAGE,
                SID_PARASPACE_INCREASE,
                SID_PARASPACE_DECREASE,
                0 };

TYPEINIT1( FuOutlineText, FuOutline );

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

FuOutlineText::FuOutlineText(ViewShell* pViewShell, ::sd::Window* pWindow,
                             ::sd::View* pView, SdDrawDocument* pDoc,
                             SfxRequest& rReq)
       : FuOutline(pViewShell, pWindow, pView, pDoc, rReq)
{
}

FunctionReference FuOutlineText::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
{
    FunctionReference xFunc( new FuOutlineText( pViewSh, pWin, pView, pDoc, rReq ) );
    xFunc->DoExecute( rReq );
    return xFunc;
}

/*************************************************************************
|*
|* MouseButtonDown-event
|*
\************************************************************************/

BOOL FuOutlineText::MouseButtonDown(const MouseEvent& rMEvt)
{
    BOOL bReturn = FALSE;

    mpWindow->GrabFocus();

    bReturn = pOutlineView->GetViewByWindow(mpWindow)->MouseButtonDown(rMEvt);

    if (bReturn)
    {
        // Attributierung der akt. Textstelle kann jetzt anders sein
        mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArray );
    }
    else
    {
        bReturn = FuOutline::MouseButtonDown(rMEvt);
    }

    return (bReturn);
}

/*************************************************************************
|*
|* MouseMove-event
|*
\************************************************************************/

BOOL FuOutlineText::MouseMove(const MouseEvent& rMEvt)
{
    BOOL bReturn = FALSE;

    bReturn = pOutlineView->GetViewByWindow(mpWindow)->MouseMove(rMEvt);

    if (!bReturn)
    {
        bReturn = FuOutline::MouseMove(rMEvt);
    }

    // MT 07/2002: Done in OutlinerView::MouseMove
    /*
    const SvxFieldItem* pFieldItem = pOutlineView->GetViewByWindow( mpWindow )->
                                        GetFieldUnderMousePointer();
    const SvxFieldData* pField = NULL;
    if( pFieldItem )
        pField = pFieldItem->GetField();

    if( pField && pField->ISA( SvxURLField ) )
    {
       mpWindow->SetPointer( Pointer( POINTER_REFHAND ) );
    }
    else
       mpWindow->SetPointer( Pointer( POINTER_TEXT ) );
    */

    return (bReturn);
}

/*************************************************************************
|*
|* MouseButtonUp-event
|*
\************************************************************************/

BOOL FuOutlineText::MouseButtonUp(const MouseEvent& rMEvt)
{
    BOOL bReturn = FALSE;

    bReturn = pOutlineView->GetViewByWindow(mpWindow)->MouseButtonUp(rMEvt);

    if (bReturn)
    {
        // Attributierung der akt. Textstelle kann jetzt anders sein
        mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArray );
    }
    else
    {
        const SvxFieldItem* pFieldItem = pOutlineView->GetViewByWindow( mpWindow )->GetFieldUnderMousePointer();
        if( pFieldItem )
        {
            const SvxFieldData* pField = pFieldItem->GetField();

            if( pField && pField->ISA( SvxURLField ) )
            {
                bReturn = TRUE;
                mpWindow->ReleaseMouse();
                SfxStringItem aStrItem( SID_FILE_NAME, ( (SvxURLField*) pField)->GetURL() );
                SfxStringItem aReferer( SID_REFERER, mpDocSh->GetMedium()->GetName() );
                SfxBoolItem aBrowseItem( SID_BROWSE, TRUE );
                SfxViewFrame* pFrame = mpViewShell->GetViewFrame();

                if ( rMEvt.IsMod1() )
                {
                    // Im neuen Frame oeffnen
                    pFrame->GetDispatcher()->Execute(SID_OPENDOC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
                                &aStrItem, &aBrowseItem, &aReferer, 0L);
                }
                else
                {
                    // Im aktuellen Frame oeffnen
                    SfxFrameItem aFrameItem( SID_DOCFRAME, pFrame );
                    pFrame->GetDispatcher()->Execute(SID_OPENDOC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
                                &aStrItem, &aFrameItem, &aBrowseItem, &aReferer, 0L);
                }
            }
        }
    }

    if( !bReturn )
        bReturn = FuOutline::MouseButtonUp(rMEvt);

    return (bReturn);
}

/*************************************************************************
|*
|* Tastaturereignisse bearbeiten
|*
|* Wird ein KeyEvent bearbeitet, so ist der Return-Wert TRUE, andernfalls
|* FALSE.
|*
\************************************************************************/

BOOL FuOutlineText::KeyInput(const KeyEvent& rKEvt)
{
    BOOL bReturn = FALSE;

    USHORT nKeyGroup = rKEvt.GetKeyCode().GetGroup();
    if( !mpDocSh->IsReadOnly() || nKeyGroup == KEYGROUP_CURSOR )
    {
        mpWindow->GrabFocus();

        std::auto_ptr< OutlineViewModelChangeGuard > aGuard;

        if( (nKeyGroup != KEYGROUP_CURSOR) && (nKeyGroup != KEYGROUP_FKEYS) )
            aGuard.reset( new OutlineViewModelChangeGuard( *pOutlineView ) );

        bReturn = pOutlineView->GetViewByWindow(mpWindow)->PostKeyEvent(rKEvt);

        if (bReturn)
        {
            UpdateForKeyPress (rKEvt);
        }
        else
        {
            bReturn = FuOutline::KeyInput(rKEvt);
        }
    }

    return (bReturn);
}

void FuOutlineText::UpdateForKeyPress (const KeyEvent& rEvent)
{
    // Attributes at the current text position may have changed.
    mpViewShell->GetViewFrame()->GetBindings().Invalidate(SidArray);

    bool bUpdatePreview = true;
    switch (rEvent.GetKeyCode().GetCode())
    {
        // When just the cursor has been moved the preview only changes when
        // it moved to entries of another page.  To prevent unnecessary
        // updates we check this here.  This is an early rejection test, so
        // missing a key is not a problem.
        case KEY_UP:
        case KEY_DOWN:
        case KEY_LEFT:
        case KEY_RIGHT:
        case KEY_HOME:
        case KEY_END:
        case KEY_PAGEUP:
        case KEY_PAGEDOWN:
        {
            SdPage* pCurrentPage = pOutlineViewShell->GetActualPage();
            bUpdatePreview = (pCurrentPage != pOutlineViewShell->GetActualPage());
        }
        break;
    }
    if (bUpdatePreview)
        pOutlineViewShell->UpdatePreview (pOutlineViewShell->GetActualPage());
}

/*************************************************************************
|*
|* Function aktivieren
|*
\************************************************************************/

void FuOutlineText::Activate()
{
    FuOutline::Activate();
}

/*************************************************************************
|*
|* Function deaktivieren
|*
\************************************************************************/

void FuOutlineText::Deactivate()
{
    FuOutline::Deactivate();
}

/*************************************************************************
|*
|* Cut object to clipboard
|*
\************************************************************************/

void FuOutlineText::DoCut()
{
    pOutlineView->GetViewByWindow(mpWindow)->Cut();
}

/*************************************************************************
|*
|* Copy object to clipboard
|*
\************************************************************************/

void FuOutlineText::DoCopy()
{
    pOutlineView->GetViewByWindow(mpWindow)->Copy();
}

/*************************************************************************
|*
|* Paste object from clipboard
|*
\************************************************************************/

void FuOutlineText::DoPaste()
{
    pOutlineView->GetViewByWindow(mpWindow)->PasteSpecial();
}

} // end of namespace sd
<|endoftext|>


<commit_before><commit_msg>coverity#705876 Dereference before null check<commit_after><|endoftext|>


<commit_before><commit_msg>-Werror,-Wunused-const-variable<commit_after><|endoftext|>