<commit_before>// 8.30.2017
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cassert>
using namespace std;

int removedup(vector<int> &nums)
{
    if (nums.empty()) return 0;

    int index = 0;
    for (int i = 1; i < nums.size(); i++)
        if (nums[i] != nums[index])
            nums[++index] = nums[i];

    return index + 1;
}

int removedup2(vector<int> &nums) {
    return distance(nums.begin(), unique(nums.begin(), nums.end()));
}

int removedup3(vector<int> &nums) {
    //return distance(nums.begin(), removedup3(nums.begin(), nums.end(), nums.begin()));
    vector<int>::iterator first = nums.begin(), last = nums.end();

    removedup3(first, last, first);
    return 1;
}

template<typename InIt, typename OutIt>
OutIt removedup3(InIt first, InIt last, OutIt out) {
    while (first != last) {
        *out++ = *first;
        first = upper_bound(first, last, first);
    }

    return out;
}

int main()
{
    {
        int A[] = {1, 1, 2};
        vector<int> nums(A, A + 3);

        int len = removedup(nums);
        assert(len == 2);
    }

    {
        int A[] = {1, 1, 2};
        vector<int> nums(A, A + 3);

        int len = removedup2(nums);
        assert(len == 2);
    }
    {
        int A[] = {1, 1, 2};
        vector<int> nums(A, A + 3);

        int len = removedup3(nums);
        assert(len == 2);
    }

    return 0;
}

<commit_msg>remove dup<commit_after>// 8.30.2017
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cassert>
using namespace std;

int removedup(vector<int> &nums)
{
    if (nums.empty()) return 0;

    int index = 0;
    for (int i = 1; i < nums.size(); i++)
        if (nums[i] != nums[index])
            nums[++index] = nums[i];

    return index + 1;
}

int removedup2(vector<int> &nums) {
    return distance(nums.begin(), unique(nums.begin(), nums.end()));
}

template<typename InIt, typename OutIt>
OutIt removedupx(InIt first, InIt last, OutIt out) {
    while (first != last) {
        *out++ = *first;
        first = upper_bound(first, last, *first);
    }

    return out;
}
int removedup3(vector<int> &nums) {
    //return distance(nums.begin(), removedup3(nums.begin(), nums.end(), nums.begin()));
    vector<int>::iterator first = nums.begin(), last = nums.end();

    return distance(nums.begin(), removedupx(first, last, first));
}

int main()
{
    {
        int A[] = {1, 1, 2};
        vector<int> nums(A, A + 3);

        int len = removedup(nums);
        assert(len == 2);
    }

    {
        int A[] = {1, 1, 2};
        vector<int> nums(A, A + 3);

        int len = removedup2(nums);
        assert(len == 2);
    }
    {
        int A[] = {1, 1, 2};
        vector<int> nums(A, A + 3);

        int len = removedup3(nums);
        assert(len == 2);
    }

    return 0;
}

<|endoftext|>


<commit_before>#include <stdio.h>

// This is so that we can access private fields for
// checking their values in tests.
#define protected public
#define private public

#include <Scratch.h>
using namespace Scratch;

static int g_iTestNumber = 1;
static int g_iTestOK = 0;
static int g_iTestFailed = 0;

#if _DEBUG
#define TEST_BREAK() __asm { int 3 };
#else
#define TEST_BREAK()
#endif

#define TESTS(id) \
  aTests.Push() = id; \
  if(strArg == id || strArg == "All")

#define TEST(expr) { \
  printf("TEST %d: (%s) - ", g_iTestNumber, #expr); \
  if(!(expr)) { \
    printf("FAILED!!!\n"); \
    g_iTestFailed++; \
    TEST_BREAK(); \
  } else { \
    printf("OK\n"); \
    g_iTestOK++; \
  } \
  g_iTestNumber++; \
}

#if WINDOWS
#define TEST_WINDOWS(expr) TEST(expr)
#define TEST_UNIX(expr)
#else
#define TEST_WINDOWS(expr)
#define TEST_UNIX(expr) TEST(expr)
#endif

int main(int argc, char* argv[])
{
  CStackArray<CString> aTests;
  CString strArg;

  if(argc > 1) {
    strArg = argv[1];
  }

  TESTS("CString")
  {
    CString strFoo;
    TEST(strFoo.str_szBuffer == CString::str_szEmpty);

    strFoo = "a";
    TEST(strFoo == "a");

    strFoo = "";
    TEST(strFoo.str_szBuffer == CString::str_szEmpty);

    int x = 5;
    int y = 10;
    strFoo.SetF("%d %d", x, y);
    TEST(strFoo == "5 10");

    strFoo.AppendF(" %d", x);
    TEST(strFoo == "5 10 5");

    CStackArray<CString> aParse;
    strFoo.Split(" ", aParse);
    TEST(aParse.Count() == 3);
    TEST(aParse[0] == "5" && aParse[1] == "10" && aParse[2] == "5");

    strFoo = "     Foo  ";
    TEST(strFoo.Trim() == "Foo");

    strFoo = "a a b b a";
    TEST(strFoo.Replace("b", "a") == "a a a a a");

    TEST(strFoo.SubString(4, 3) == "b b");

    TEST(strFoo.ToUpper() == "A A B B A");

    strFoo = "A A B B A";
    TEST(strFoo.ToLower() == "a a b b a");

    strFoo.Fill('x', 5);
    TEST(strFoo == "xxxxx");

    strFoo = "BaaaaaXaaaB";
    TEST(strFoo.Contains('X'));
    TEST(strFoo.Contains("Xaaa"));

    TEST(strFoo.StartsWith("Baaa"));
    TEST(strFoo.EndsWith("aaaB"));

    TEST((const char*)strFoo == strFoo.str_szBuffer);

    strFoo = "x";
    strFoo += "x";

    TEST(strFoo == "xx");

    strFoo *= 3;
    TEST(strFoo == "xxxxxx");
    TEST(strFoo != "aaaaaa");

    strFoo = "x";
    TEST(strFoo + "y" == "xy");

    TEST(strFoo * 3 == "xxx");

    TEST(strPrintF("Hello %d %d", x, y) == "Hello 5 10");
  }

  TESTS("CFilename")
  {
    CFilename fnmFoo;
    TEST(fnmFoo.str_szBuffer == CString::str_szEmpty);

    fnmFoo = "/var/www/test.html";
    TEST(fnmFoo.Extension() == "html");
    TEST(fnmFoo.Path() == "/var/www");
    TEST(fnmFoo.Filename() == "test.html");

    fnmFoo.FromHome(".zshrc");
    TEST_WINDOWS(fnmFoo.StartsWith("C:\\Users\\"));
    TEST_UNIX(fnmFoo == "~/.zshrc");
  }

  TESTS("CStackArray")
  {
    CStackArray<int> sa;
    TEST(sa.Count() == 0);

    sa.Push() = 5;
    TEST(sa.Count() == 1);
    TEST(sa[0] == 5);

    sa.PushBegin() = 10;
    TEST(sa.Count() == 2);
    TEST(sa[0] == 10);

    int* pNewInt = new int;
    *pNewInt = 15;
    sa.Push(pNewInt);
    TEST(sa.Count() == 3);
    TEST(sa[2] == 15);

    int* pLastInt = sa.Pop();
    TEST(sa.Count() == 2);
    TEST(pLastInt == pNewInt);
    delete pLastInt;

    delete sa.PopAt(0);
    TEST(sa.Count() == 1);
    TEST(sa[0] == 5);

    int* pRemainingInt = &sa[0];
    sa.PopAll();
    TEST(sa.Count() == 0);
    TEST(*pRemainingInt == 5);
    delete pRemainingInt;

    sa.Push() = 20;
    sa.Clear();
    TEST(sa.Count() == 0);

    pNewInt = new int;
    *pNewInt = 15;
    sa.Push() = 5;
    sa.Push() = 10;
    sa.Push(pNewInt);
    sa.Push() = 20;
    TEST(sa.Find(10) == 1);
    TEST(sa.Find(25) == -1);
    TEST(sa.FindPointer(pNewInt) == 2);
    TEST(sa.FindAny([](int &i) { return i == 20; }) == 3);

    TEST(sa.Contains(15));
    TEST(!sa.Contains(25));
    TEST(sa.ContainsPointer(pNewInt));
    TEST(sa.ContainsAny([](int &i) { return i == 20; }));
  }

  TESTS("CDictionary")
  {
    CDictionary<CString, int> dic;
    TEST(dic.Count() == 0);

    dic.Add("foo", 5);
    TEST(dic.Count() == 1);
    TEST(dic["foo"] == 5);

    dic["bar"] = 10;
    TEST(dic["bar"] == 10);

    CDictionaryPair<CString, int> pair = dic.Push("foobar");
    *pair.value = 15;
    TEST(dic["foobar"] == 15);

    TEST(dic.IndexByKey("bar") == 1);
    TEST(dic.IndexByValue(10) == 1);

    TEST(dic.HasKey("foobar"));
    TEST(dic.HasValue(15));

    dic.RemoveByIndex(0);
    TEST(dic.Count() == 2);
    TEST(!dic.HasKey("foo"));

    dic.RemoveByKey("bar");
    TEST(dic.Count() == 1);
    TEST(!dic.HasKey("bar"));

    dic.RemoveByValue(15);
    TEST(dic.Count() == 0);

    dic["foo"] = 5;
    dic["bar"] = 10;
    dic["foobar"] = 15;
    dic["barfoo"] = 20;
    TEST(dic.Count() == 4);
    dic.PopByIndex(0).Delete();
    TEST(dic.Count() == 3);
    TEST(!dic.HasKey("foo"));
    dic.PopByKey("bar").Delete();
    TEST(dic.Count() == 2);
    TEST(!dic.HasKey("bar"));
    dic.PopByValue(15).Delete();
    TEST(dic.Count() == 1);
    TEST(!dic.HasKey("foobar"));

    dic.Clear();
    TEST(dic.Count() == 0);

    dic["foo"] = 5;
    dic["bar"] = 10;
    TEST(dic.GetKeyByIndex(0) == "foo");
    TEST(dic.GetValueByIndex(1) == 10);
  }

  TESTS("CFileStream")
  {
    CFileStream fsWriter;
    fsWriter.Open("test.txt", "w");
    fsWriter.WriteLine("foo");
    fsWriter.WriteLine("bar");
    fsWriter << INDEX(5);
    fsWriter << FLOAT(2.5f);
    fsWriter << CString("test");
    fsWriter.Close();

    CFileStream fsReader;
    fsReader.Open("test.txt", "r");

    TEST(fsReader.ReadLine() == "foo");
    TEST(fsReader.ReadLine() == "bar");

    INDEX i;
    FLOAT f;
    CString s;

    fsReader >> i;
    TEST(i == 5);

    fsReader >> f;
    TEST(f > 2.0f && f < 3.0f);

    fsReader >> s;
    TEST(s == "test");

    fsReader.ReadChar();
    TEST(fsReader.AtEOF());

    fsReader.Close();
  }

  if(argc == 1) {
    printf("No test name given! Existing tests:\n\n");
    for(int i=0; i<aTests.Count(); i++) {
      printf(" * %s\n", (const char*)aTests[i]);
    }
    printf("\nOr pass \"All\" to run all tests.");
    return 1;
  }

  printf("\n");
  printf("      OK: %d\n", g_iTestOK);
  printf("  Failed: %d\n", g_iTestFailed);
  printf("\n");

#if _DEBUG
  getchar();
#endif

  return g_iTestFailed;
}
<commit_msg>Fix TEST_BREAK not working on linux<commit_after>#include <stdio.h>

// This is so that we can access private fields for
// checking their values in tests.
#define protected public
#define private public

#include <Scratch.h>
using namespace Scratch;

static int g_iTestNumber = 1;
static int g_iTestOK = 0;
static int g_iTestFailed = 0;

#if DEBUG
  #if WINDOWS
    #define TEST_BREAK() __asm { int 3 };
  #else
    #define TEST_BREAK() __asm__("int $0x03");
  #endif
#else
  #define TEST_BREAK()
#endif

#define TESTS(id) \
  aTests.Push() = id; \
  if(strArg == id || strArg == "All")

#define TEST(expr) { \
  printf("TEST %d: (%s) - ", g_iTestNumber, #expr); \
  if(!(expr)) { \
    printf("FAILED!!!\n"); \
    g_iTestFailed++; \
    TEST_BREAK(); \
  } else { \
    printf("OK\n"); \
    g_iTestOK++; \
  } \
  g_iTestNumber++; \
}

#if WINDOWS
#define TEST_WINDOWS(expr) TEST(expr)
#define TEST_UNIX(expr)
#else
#define TEST_WINDOWS(expr)
#define TEST_UNIX(expr) TEST(expr)
#endif

int main(int argc, char* argv[])
{
  CStackArray<CString> aTests;
  CString strArg;

  if(argc > 1) {
    strArg = argv[1];
  }

  TESTS("CString")
  {
    CString strFoo;
    TEST(strFoo.str_szBuffer == CString::str_szEmpty);

    strFoo = "a";
    TEST(strFoo == "a");

    strFoo = "";
    TEST(strFoo.str_szBuffer == CString::str_szEmpty);

    int x = 5;
    int y = 10;
    strFoo.SetF("%d %d", x, y);
    TEST(strFoo == "5 10");

    strFoo.AppendF(" %d", x);
    TEST(strFoo == "5 10 5");

    CStackArray<CString> aParse;
    strFoo.Split(" ", aParse);
    TEST(aParse.Count() == 3);
    TEST(aParse[0] == "5" && aParse[1] == "10" && aParse[2] == "5");

    strFoo = "     Foo  ";
    TEST(strFoo.Trim() == "Foo");

    strFoo = "a a b b a";
    TEST(strFoo.Replace("b", "a") == "a a a a a");

    TEST(strFoo.SubString(4, 3) == "b b");

    TEST(strFoo.ToUpper() == "A A B B A");

    strFoo = "A A B B A";
    TEST(strFoo.ToLower() == "a a b b a");

    strFoo.Fill('x', 5);
    TEST(strFoo == "xxxxx");

    strFoo = "BaaaaaXaaaB";
    TEST(strFoo.Contains('X'));
    TEST(strFoo.Contains("Xaaa"));

    TEST(strFoo.StartsWith("Baaa"));
    TEST(strFoo.EndsWith("aaaB"));

    TEST((const char*)strFoo == strFoo.str_szBuffer);

    strFoo = "x";
    strFoo += "x";

    TEST(strFoo == "xx");

    strFoo *= 3;
    TEST(strFoo == "xxxxxx");
    TEST(strFoo != "aaaaaa");

    strFoo = "x";
    TEST(strFoo + "y" == "xy");

    TEST(strFoo * 3 == "xxx");

    TEST(strPrintF("Hello %d %d", x, y) == "Hello 5 10");
  }

  TESTS("CFilename")
  {
    CFilename fnmFoo;
    TEST(fnmFoo.str_szBuffer == CString::str_szEmpty);

    fnmFoo = "/var/www/test.html";
    TEST(fnmFoo.Extension() == "html");
    TEST(fnmFoo.Path() == "/var/www");
    TEST(fnmFoo.Filename() == "test.html");

    fnmFoo.FromHome(".zshrc");
    TEST_WINDOWS(fnmFoo.StartsWith("C:\\Users\\"));
    TEST_UNIX(fnmFoo == "~/.zshrc");
  }

  TESTS("CStackArray")
  {
    CStackArray<int> sa;
    TEST(sa.Count() == 0);

    sa.Push() = 5;
    TEST(sa.Count() == 1);
    TEST(sa[0] == 5);

    sa.PushBegin() = 10;
    TEST(sa.Count() == 2);
    TEST(sa[0] == 10);

    int* pNewInt = new int;
    *pNewInt = 15;
    sa.Push(pNewInt);
    TEST(sa.Count() == 3);
    TEST(sa[2] == 15);

    int* pLastInt = sa.Pop();
    TEST(sa.Count() == 2);
    TEST(pLastInt == pNewInt);
    delete pLastInt;

    delete sa.PopAt(0);
    TEST(sa.Count() == 1);
    TEST(sa[0] == 5);

    int* pRemainingInt = &sa[0];
    sa.PopAll();
    TEST(sa.Count() == 0);
    TEST(*pRemainingInt == 5);
    delete pRemainingInt;

    sa.Push() = 20;
    sa.Clear();
    TEST(sa.Count() == 0);

    pNewInt = new int;
    *pNewInt = 15;
    sa.Push() = 5;
    sa.Push() = 10;
    sa.Push(pNewInt);
    sa.Push() = 20;
    TEST(sa.Find(10) == 1);
    TEST(sa.Find(25) == -1);
    TEST(sa.FindPointer(pNewInt) == 2);
    TEST(sa.FindAny([](int &i) { return i == 20; }) == 3);

    TEST(sa.Contains(15));
    TEST(!sa.Contains(25));
    TEST(sa.ContainsPointer(pNewInt));
    TEST(sa.ContainsAny([](int &i) { return i == 20; }));
  }

  TESTS("CDictionary")
  {
    CDictionary<CString, int> dic;
    TEST(dic.Count() == 0);

    dic.Add("foo", 5);
    TEST(dic.Count() == 1);
    TEST(dic["foo"] == 5);

    dic["bar"] = 10;
    TEST(dic["bar"] == 10);

    CDictionaryPair<CString, int> pair = dic.Push("foobar");
    *pair.value = 15;
    TEST(dic["foobar"] == 15);

    TEST(dic.IndexByKey("bar") == 1);
    TEST(dic.IndexByValue(10) == 1);

    TEST(dic.HasKey("foobar"));
    TEST(dic.HasValue(15));

    dic.RemoveByIndex(0);
    TEST(dic.Count() == 2);
    TEST(!dic.HasKey("foo"));

    dic.RemoveByKey("bar");
    TEST(dic.Count() == 1);
    TEST(!dic.HasKey("bar"));

    dic.RemoveByValue(15);
    TEST(dic.Count() == 0);

    dic["foo"] = 5;
    dic["bar"] = 10;
    dic["foobar"] = 15;
    dic["barfoo"] = 20;
    TEST(dic.Count() == 4);
    dic.PopByIndex(0).Delete();
    TEST(dic.Count() == 3);
    TEST(!dic.HasKey("foo"));
    dic.PopByKey("bar").Delete();
    TEST(dic.Count() == 2);
    TEST(!dic.HasKey("bar"));
    dic.PopByValue(15).Delete();
    TEST(dic.Count() == 1);
    TEST(!dic.HasKey("foobar"));

    dic.Clear();
    TEST(dic.Count() == 0);

    dic["foo"] = 5;
    dic["bar"] = 10;
    TEST(dic.GetKeyByIndex(0) == "foo");
    TEST(dic.GetValueByIndex(1) == 10);
  }

  TESTS("CFileStream")
  {
    CFileStream fsWriter;
    fsWriter.Open("test.txt", "w");
    fsWriter.WriteLine("foo");
    fsWriter.WriteLine("bar");
    fsWriter << INDEX(5);
    fsWriter << FLOAT(2.5f);
    fsWriter << CString("test");
    fsWriter.Close();

    CFileStream fsReader;
    fsReader.Open("test.txt", "r");

    TEST(fsReader.ReadLine() == "foo");
    TEST(fsReader.ReadLine() == "bar");

    INDEX i;
    FLOAT f;
    CString s;

    fsReader >> i;
    TEST(i == 5);

    fsReader >> f;
    TEST(f > 2.0f && f < 3.0f);

    fsReader >> s;
    TEST(s == "test");

    fsReader.ReadChar();
    TEST(fsReader.AtEOF());

    fsReader.Close();
  }

  if(argc == 1) {
    printf("No test name given! Existing tests:\n\n");
    for(int i=0; i<aTests.Count(); i++) {
      printf(" * %s\n", (const char*)aTests[i]);
    }
    printf("\nOr pass \"All\" to run all tests.");
    return 1;
  }

  printf("\n");
  printf("      OK: %d\n", g_iTestOK);
  printf("  Failed: %d\n", g_iTestFailed);
  printf("\n");

#if _DEBUG
  getchar();
#endif

  return g_iTestFailed;
}
<|endoftext|>


<commit_before>/* Tab to open/close menu
 * Menu appears on the side, vertical layout listing the tools.
 * Click on a tool to select it.
 * 	The tool expands to show its options.
 * 	Previous tool closes.
 * 	Layout adjusts.
 * If the menu is too large, use middle button drag.
 * */
#include <allegro5/allegro5.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include "menu.h"
#include "platform.h"
#include "create_platform.h"
#include "edit_platform.h"
#include "file.h"
#include "create_sprite.h"
#include "edit_sprite.h"
#include <iostream>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_image.h>

int main(int argc, const char* argv[])
{
	al_init();

	al_init_font_addon();
	al_init_ttf_addon();
	al_init_image_addon();

	ALLEGRO_DISPLAY *display;
	al_set_new_display_flags(ALLEGRO_WINDOWED);
	display = al_create_display(800, 600);

	al_install_keyboard();
	al_install_mouse();

	ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
	al_register_event_source(event_queue, (ALLEGRO_EVENT_SOURCE *)display);
	al_register_event_source(event_queue, al_get_keyboard_event_source());
	al_register_event_source(event_queue, al_get_mouse_event_source());

	ALLEGRO_FONT* font = al_load_ttf_font("data/times.ttf", 12, 0);

	Vector2 camera(-400, -300);

	Platforms platforms;
	Bitmaps bitmaps;
	Sprites sprites;

	File* file = new File(font);
	file->platforms = &platforms;
	file->bitmaps = &bitmaps;
	file->sprites = &sprites;

	Menu menu;
	menu.Add_entry(new Create_platform(platforms, camera, font));
	menu.Add_entry(new Edit_platform(platforms, camera, font));
	menu.Add_entry(file);
	menu.Add_entry(new Create_sprite(bitmaps, sprites, camera, font));
	menu.Add_entry(new Edit_sprite(sprites, camera, font));

	if(argc==2)
		file->Load(argv[1]);

	while(1)
	{
		ALLEGRO_EVENT event;
		if (al_get_next_event(event_queue, &event))
		{
			if (ALLEGRO_EVENT_DISPLAY_CLOSE == event.type ||
					ALLEGRO_EVENT_KEY_DOWN == event.type &&
					ALLEGRO_KEY_ESCAPE == event.keyboard.keycode)
			{
				break;
			}
			if(ALLEGRO_EVENT_MOUSE_AXES)
			{
				ALLEGRO_MOUSE_STATE mstate;
				al_get_mouse_state(&mstate);
				if(al_mouse_button_down(&mstate, 3))
				{
					camera.x -= event.mouse.dx;
					camera.y -= event.mouse.dy;
				}
			}
			menu.Event(event);
		}

		for(Sprites::iterator i = sprites.begin(); i != sprites.end(); ++i)
		{
			(*i)->Draw(camera);
		}
		for(Platforms::iterator i = platforms.begin(); i != platforms.end(); ++i)
		{
			(*i)->Draw(camera, al_map_rgb_f(0, 1, 0));
		}

		al_draw_line(0, -camera.y, 800, -camera.y, al_map_rgba_f(0, 1, 0, 0.5), 0);
		al_draw_line(-camera.x, 0, -camera.x, 600, al_map_rgba_f(0, 0, 1, 0.5), 0);

		menu.Draw();

		al_flip_display();
		al_clear_to_color(al_map_rgb(0, 0, 0));

		al_rest(0.001);
	}

	al_destroy_event_queue(event_queue);
	al_destroy_display(display);
}
<commit_msg>Initialize primitives addon<commit_after>/* Tab to open/close menu
 * Menu appears on the side, vertical layout listing the tools.
 * Click on a tool to select it.
 * 	The tool expands to show its options.
 * 	Previous tool closes.
 * 	Layout adjusts.
 * If the menu is too large, use middle button drag.
 * */
#include <allegro5/allegro5.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include "menu.h"
#include "platform.h"
#include "create_platform.h"
#include "edit_platform.h"
#include "file.h"
#include "create_sprite.h"
#include "edit_sprite.h"
#include <iostream>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_image.h>

int main(int argc, const char* argv[])
{
	al_init();

	al_init_font_addon();
	al_init_ttf_addon();
	al_init_image_addon();
	al_init_primitives_addon();

	ALLEGRO_DISPLAY *display;
	al_set_new_display_flags(ALLEGRO_WINDOWED);
	display = al_create_display(800, 600);

	al_install_keyboard();
	al_install_mouse();

	ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
	al_register_event_source(event_queue, (ALLEGRO_EVENT_SOURCE *)display);
	al_register_event_source(event_queue, al_get_keyboard_event_source());
	al_register_event_source(event_queue, al_get_mouse_event_source());

	ALLEGRO_FONT* font = al_load_ttf_font("data/times.ttf", 12, 0);

	Vector2 camera(-400, -300);

	Platforms platforms;
	Bitmaps bitmaps;
	Sprites sprites;

	File* file = new File(font);
	file->platforms = &platforms;
	file->bitmaps = &bitmaps;
	file->sprites = &sprites;

	Menu menu;
	menu.Add_entry(new Create_platform(platforms, camera, font));
	menu.Add_entry(new Edit_platform(platforms, camera, font));
	menu.Add_entry(file);
	menu.Add_entry(new Create_sprite(bitmaps, sprites, camera, font));
	menu.Add_entry(new Edit_sprite(sprites, camera, font));

	if(argc==2)
		file->Load(argv[1]);

	while(1)
	{
		ALLEGRO_EVENT event;
		if (al_get_next_event(event_queue, &event))
		{
			if (ALLEGRO_EVENT_DISPLAY_CLOSE == event.type ||
					ALLEGRO_EVENT_KEY_DOWN == event.type &&
					ALLEGRO_KEY_ESCAPE == event.keyboard.keycode)
			{
				break;
			}
			if(ALLEGRO_EVENT_MOUSE_AXES)
			{
				ALLEGRO_MOUSE_STATE mstate;
				al_get_mouse_state(&mstate);
				if(al_mouse_button_down(&mstate, 3))
				{
					camera.x -= event.mouse.dx;
					camera.y -= event.mouse.dy;
				}
			}
			menu.Event(event);
		}

		for(Sprites::iterator i = sprites.begin(); i != sprites.end(); ++i)
		{
			(*i)->Draw(camera);
		}
		for(Platforms::iterator i = platforms.begin(); i != platforms.end(); ++i)
		{
			(*i)->Draw(camera, al_map_rgb_f(0, 1, 0));
		}

		al_draw_line(0, -camera.y, 800, -camera.y, al_map_rgba_f(0, 1, 0, 0.5), 0);
		al_draw_line(-camera.x, 0, -camera.x, 600, al_map_rgba_f(0, 0, 1, 0.5), 0);

		menu.Draw();

		al_flip_display();
		al_clear_to_color(al_map_rgb(0, 0, 0));

		al_rest(0.001);
	}

	al_destroy_event_queue(event_queue);
	al_destroy_display(display);
}
<|endoftext|>


<commit_before>/*
 *   pyxpcconnection: OS X XPC Bindings for Python
 *
 *   Copyright (c) 2015 Matthew Else
 *
 *   Based on node-xpc-connection: Copyright Sandeep Mistry 2015
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *    http://www.apache.org/licenses/LICENSE-2.0
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
#include <iostream>
#include <vector>

#include "XpcConnectionBase.h"

// define these so that prettyprint can do it's magic :)
std::ostream& operator<<(std::ostream& os, const boost::python::object& o)
{
    return os << boost::python::extract<std::string>(boost::python::str(o))();
}

std::ostream& operator<<(std::ostream& os, const boost::python::dict& o)
{
    return os << boost::python::extract<std::string>(boost::python::str(o))();
}

#include "prettyprint.hpp"

XpcConnectionBase::XpcConnectionBase(std::string target) :
    serviceName(target) {
    dispatchQueue = dispatch_queue_create(serviceName.c_str(), 0);
    xpcConnection = xpc_connection_create_mach_service(serviceName.c_str(), dispatchQueue, XPC_CONNECTION_MACH_SERVICE_PRIVILEGED);

    xpc_connection_set_event_handler(xpcConnection, ^(xpc_object_t event) {
        // this seems to fix a segfault (it's never released, so this should probably be a problem...)
        auto gstate = PyGILState_Ensure();

        xpc_retain(event);

        // handle the event
        handleEvent(event);
        PyGILState_Release(gstate);
    });

    xpc_connection_resume(xpcConnection);

}

xpc_object_t XpcConnectionBase::ValueToXpcObject(boost::python::object obj) {
    auto gstate = PyGILState_Ensure();

    xpc_object_t xpcObject = NULL;

    std::string type = boost::python::extract<std::string>(obj.attr("__class__").attr("__name__"));

    //std::cout << "unpacking: " << type << std::endl;

    if (type == "UUID") {
        boost::python::object s = obj.attr("bytes");

        std::string str = boost::python::extract<std::string>(s);

        std::vector<uint8_t> data;

        for (int i = 0; i < str.size(); i++) {
            data.push_back(str.data()[i] & 0xff);
        }

        uuid_t *uuid = (uuid_t *)str.data();

        xpcObject = xpc_uuid_create(*uuid);
    } else if (type == "str") {
        std::string s = boost::python::extract<std::string>(obj);

        xpcObject = xpc_string_create(s.c_str());
    } else if (type == "int") {
        long int_val = boost::python::extract<int>(obj);

        xpcObject = xpc_int64_create(int_val);
    } else if (type == "dict") {
        boost::python::dict dict = boost::python::extract<boost::python::dict>(obj);
        xpcObject = XpcConnectionBase::DictToXpcObject(dict);
    } else if (type == "list") {
        boost::python::list list = boost::python::extract<boost::python::list>(obj);

        xpcObject = XpcConnectionBase::ListToXpcObject(list);
    } else if (type == (PY_MAJOR_VERSION == 3 ? "memoryview" : "buffer")) {
        std::string s = boost::python::extract<std::string>(obj);

        xpcObject = xpc_data_create(s.c_str(), s.size());
    } else if (obj.is_none()) {
        /* empty */
    } else {
        //std::cout << "[xpc] unexpected data type: " << type << std::endl;
    }

    PyGILState_Release(gstate);

    return xpcObject;
}

xpc_object_t XpcConnectionBase::ListToXpcObject(boost::python::list list) {
    xpc_object_t xpcArray = xpc_array_create(NULL, 0);

    for(uint32_t i = 0; i < boost::python::len(list); i++) {
        boost::python::object value = list[i];

        xpc_object_t xpcValue = XpcConnectionBase::ValueToXpcObject(value);

        xpc_array_append_value(xpcArray, xpcValue);
        if (xpcValue) {
            xpc_release(xpcValue);
        }
    }

    return xpcArray;
}

xpc_object_t XpcConnectionBase::DictToXpcObject(boost::python::dict object) {
    xpc_object_t xpcObject = xpc_dictionary_create(NULL, NULL, 0);

    boost::python::object iterator = object.keys();

    boost::python::ssize_t n = boost::python::len(iterator);

    for (boost::python::ssize_t i = 0; i < n; i++) {
        boost::python::object key = iterator[i];

        std::string key_s = boost::python::extract<std::string>(key);

        boost::python::object value = object[key];

        xpc_object_t xpcValue = XpcConnectionBase::ValueToXpcObject(value);
        xpc_dictionary_set_value(xpcObject, key_s.c_str(), xpcValue);

        if (xpcValue) {
            xpc_release(xpcValue);
        }
    }

    return xpcObject;
}

boost::python::object XpcConnectionBase::XpcObjectToValue(xpc_object_t xpcObject) {
    auto gstate = PyGILState_Ensure();
    xpc_type_t valueType = xpc_get_type(xpcObject);

    boost::python::object obj;

    if (valueType == XPC_TYPE_INT64) {
        long value = xpc_int64_get_value(xpcObject);
        obj = boost::python::object(value);
    }
    else if (valueType == XPC_TYPE_STRING) {
        std::string value(xpc_string_get_string_ptr(xpcObject));
        obj = boost::python::object(value);
    }
    else if (valueType == XPC_TYPE_DATA) {
        std::string value((char *)xpc_data_get_bytes_ptr(xpcObject), xpc_data_get_length(xpcObject));
        obj = boost::python::object(value);
    }
    else if (valueType == XPC_TYPE_DICTIONARY) {
        obj = XpcConnectionBase::XpcDictToDict(xpcObject);
    }
    else if (valueType == XPC_TYPE_ARRAY) {
        obj = XpcConnectionBase::XpcArrayToList(xpcObject);
    }
    else if (valueType == XPC_TYPE_UUID) {
        std::string buffer((char *)xpc_uuid_get_bytes(xpcObject), sizeof(uuid_t));
        std::string new_buffer;
        new_buffer.assign(buffer);
        obj = boost::python::object(new_buffer);
    }

    PyGILState_Release(gstate);
    return obj;
}

boost::python::dict XpcConnectionBase::XpcDictToDict(xpc_object_t xpcDictionary) {
    __block boost::python::dict d;

    xpc_dictionary_apply(xpcDictionary, ^bool(const char *key, xpc_object_t value) {
        std::string s(key);
        boost::python::object val = XpcConnectionBase::XpcObjectToValue(value);

        d[s] = val;

        return true;
    });

    return d;
}

boost::python::dict XpcConnectionBase::XpcArrayToList(xpc_object_t xpcArray) {
    __block boost::python::dict array;

    xpc_array_apply(xpcArray, ^bool(size_t index, xpc_object_t value) {
        array[index] = XpcConnectionBase::XpcObjectToValue(value);

        return true;
    });

    return array;
}

void XpcConnectionBase::handleEvent(xpc_object_t event) {
    try {
        auto gstate = PyGILState_Ensure();
        // return a tuple containing type, and details
        xpc_type_t eventType = xpc_get_type(event);

        if (eventType == XPC_TYPE_ERROR) {
            std::string message = "unknown";

            if (event == XPC_ERROR_CONNECTION_INTERRUPTED) {
                message = "connection interrupted";
            } else if (event == XPC_ERROR_CONNECTION_INVALID) {
                message = "connection invalid";
            }

            //std::cout << "[xpc] error: " << message << std::endl;

            boost::python::tuple args = boost::python::make_tuple(std::string("error"), message);
            //handler(args);
        } else if (eventType == XPC_TYPE_DICTIONARY) {
            boost::python::object obj = XpcConnectionBase::XpcObjectToValue(event);
            boost::python::tuple args = boost::python::make_tuple(std::string("event"), obj);

            //std::cout << "[xpc] received XPC event: " << obj.attr("__getitem__")("kCBMsgId") << std::endl;

            handler(args);
        } else {
            //std::cout << "[xpc] received something strange..." << std::endl;
        }

        PyGILState_Release(gstate);
        xpc_release(event);
    } catch(boost::python::error_already_set const&) {
        PyErr_Print();
    }
}

void XpcConnectionBase::sendMessage(boost::python::dict obj) {
    auto gstate = PyGILState_Ensure();

    xpc_object_t message = XpcConnectionBase::DictToXpcObject(obj);

    xpc_connection_send_message(xpcConnection, message);

    xpc_release(message);

    PyGILState_Release(gstate);
}
<commit_msg>Fix handling of raw byte data<commit_after>/*
 *   pyxpcconnection: OS X XPC Bindings for Python
 *
 *   Copyright (c) 2015 Matthew Else
 *
 *   Based on node-xpc-connection: Copyright Sandeep Mistry 2015
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *    http://www.apache.org/licenses/LICENSE-2.0
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
#include <iostream>
#include <vector>

#include "XpcConnectionBase.h"

// define these so that prettyprint can do it's magic :)
std::ostream& operator<<(std::ostream& os, const boost::python::object& o)
{
    return os << boost::python::extract<std::string>(boost::python::str(o))();
}

std::ostream& operator<<(std::ostream& os, const boost::python::dict& o)
{
    return os << boost::python::extract<std::string>(boost::python::str(o))();
}

#include "prettyprint.hpp"

XpcConnectionBase::XpcConnectionBase(std::string target) :
    serviceName(target) {
    dispatchQueue = dispatch_queue_create(serviceName.c_str(), 0);
    xpcConnection = xpc_connection_create_mach_service(serviceName.c_str(), dispatchQueue, XPC_CONNECTION_MACH_SERVICE_PRIVILEGED);

    xpc_connection_set_event_handler(xpcConnection, ^(xpc_object_t event) {
        // this seems to fix a segfault (it's never released, so this should probably be a problem...)
        auto gstate = PyGILState_Ensure();

        xpc_retain(event);

        // handle the event
        handleEvent(event);
        PyGILState_Release(gstate);
    });

    xpc_connection_resume(xpcConnection);

}

xpc_object_t XpcConnectionBase::ValueToXpcObject(boost::python::object obj) {
    auto gstate = PyGILState_Ensure();

    xpc_object_t xpcObject = NULL;

    std::string type = boost::python::extract<std::string>(obj.attr("__class__").attr("__name__"));

    //std::cout << "unpacking: " << type << std::endl;

    if (type == "UUID") {
        boost::python::object s = obj.attr("bytes");

        std::string str = boost::python::extract<std::string>(s);

        std::vector<uint8_t> data;

        for (int i = 0; i < str.size(); i++) {
            data.push_back(str.data()[i] & 0xff);
        }

        uuid_t *uuid = (uuid_t *)str.data();

        xpcObject = xpc_uuid_create(*uuid);
    } else if (type == "str") {
        std::string s = boost::python::extract<std::string>(obj);

        xpcObject = xpc_string_create(s.c_str());
    } else if (type == "int") {
        long int_val = boost::python::extract<int>(obj);

        xpcObject = xpc_int64_create(int_val);
    } else if (type == "dict") {
        boost::python::dict dict = boost::python::extract<boost::python::dict>(obj);
        xpcObject = XpcConnectionBase::DictToXpcObject(dict);
    } else if (type == "list") {
        boost::python::list list = boost::python::extract<boost::python::list>(obj);

        xpcObject = XpcConnectionBase::ListToXpcObject(list);
    } else if (type == "tuple") {
        // data in the first element
        boost::python::tuple t = boost::python::extract<boost::python::tuple>(obj);
        boost::python::object data = t[0];
        std::string str_data = boost::python::extract<std::string>(data);

        xpcObject = xpc_data_create(str_data.c_str(), str_data.size());

    } else if (obj.is_none()) {
        /* empty */
    } else {
        //std::cout << "[xpc] unexpected data type: " << type << std::endl;
    }

    PyGILState_Release(gstate);

    return xpcObject;
}

xpc_object_t XpcConnectionBase::ListToXpcObject(boost::python::list list) {
    xpc_object_t xpcArray = xpc_array_create(NULL, 0);

    for(uint32_t i = 0; i < boost::python::len(list); i++) {
        boost::python::object value = list[i];

        xpc_object_t xpcValue = XpcConnectionBase::ValueToXpcObject(value);

        xpc_array_append_value(xpcArray, xpcValue);
        if (xpcValue) {
            xpc_release(xpcValue);
        }
    }

    return xpcArray;
}

xpc_object_t XpcConnectionBase::DictToXpcObject(boost::python::dict object) {
    xpc_object_t xpcObject = xpc_dictionary_create(NULL, NULL, 0);

    boost::python::object iterator = object.keys();

    boost::python::ssize_t n = boost::python::len(iterator);

    for (boost::python::ssize_t i = 0; i < n; i++) {
        boost::python::object key = iterator[i];

        std::string key_s = boost::python::extract<std::string>(key);

        boost::python::object value = object[key];

        xpc_object_t xpcValue = XpcConnectionBase::ValueToXpcObject(value);
        xpc_dictionary_set_value(xpcObject, key_s.c_str(), xpcValue);

        if (xpcValue) {
            xpc_release(xpcValue);
        }
    }

    return xpcObject;
}

boost::python::object XpcConnectionBase::XpcObjectToValue(xpc_object_t xpcObject) {
    auto gstate = PyGILState_Ensure();
    xpc_type_t valueType = xpc_get_type(xpcObject);

    boost::python::object obj;

    if (valueType == XPC_TYPE_INT64) {
        long value = xpc_int64_get_value(xpcObject);
        obj = boost::python::object(value);
    }
    else if (valueType == XPC_TYPE_STRING) {
        std::string value(xpc_string_get_string_ptr(xpcObject));
        obj = boost::python::object(value);
    }
    else if (valueType == XPC_TYPE_DATA) {
        std::string value((char *)xpc_data_get_bytes_ptr(xpcObject), xpc_data_get_length(xpcObject));
        obj = boost::python::object(value);
    }
    else if (valueType == XPC_TYPE_DICTIONARY) {
        obj = XpcConnectionBase::XpcDictToDict(xpcObject);
    }
    else if (valueType == XPC_TYPE_ARRAY) {
        obj = XpcConnectionBase::XpcArrayToList(xpcObject);
    }
    else if (valueType == XPC_TYPE_UUID) {
        std::string buffer((char *)xpc_uuid_get_bytes(xpcObject), sizeof(uuid_t));
        std::string new_buffer;
        new_buffer.assign(buffer);
        obj = boost::python::object(new_buffer);
    }

    PyGILState_Release(gstate);
    return obj;
}

boost::python::dict XpcConnectionBase::XpcDictToDict(xpc_object_t xpcDictionary) {
    __block boost::python::dict d;

    xpc_dictionary_apply(xpcDictionary, ^bool(const char *key, xpc_object_t value) {
        std::string s(key);
        boost::python::object val = XpcConnectionBase::XpcObjectToValue(value);

        d[s] = val;

        return true;
    });

    return d;
}

boost::python::dict XpcConnectionBase::XpcArrayToList(xpc_object_t xpcArray) {
    __block boost::python::dict array;

    xpc_array_apply(xpcArray, ^bool(size_t index, xpc_object_t value) {
        array[index] = XpcConnectionBase::XpcObjectToValue(value);

        return true;
    });

    return array;
}

void XpcConnectionBase::handleEvent(xpc_object_t event) {
    try {
        auto gstate = PyGILState_Ensure();
        // return a tuple containing type, and details
        xpc_type_t eventType = xpc_get_type(event);

        if (eventType == XPC_TYPE_ERROR) {
            std::string message = "unknown";

            if (event == XPC_ERROR_CONNECTION_INTERRUPTED) {
                message = "connection interrupted";
            } else if (event == XPC_ERROR_CONNECTION_INVALID) {
                message = "connection invalid";
            }

            //std::cout << "[xpc] error: " << message << std::endl;

            boost::python::tuple args = boost::python::make_tuple(std::string("error"), message);
            //handler(args);
        } else if (eventType == XPC_TYPE_DICTIONARY) {
            boost::python::object obj = XpcConnectionBase::XpcObjectToValue(event);
            boost::python::tuple args = boost::python::make_tuple(std::string("event"), obj);

            //std::cout << "[xpc] received XPC event: " << obj.attr("__getitem__")("kCBMsgId") << std::endl;

            handler(args);
        } else {
            //std::cout << "[xpc] received something strange..." << std::endl;
        }

        PyGILState_Release(gstate);
        xpc_release(event);
    } catch(boost::python::error_already_set const&) {
        PyErr_Print();
    }
}

void XpcConnectionBase::sendMessage(boost::python::dict obj) {
    auto gstate = PyGILState_Ensure();

    xpc_object_t message = XpcConnectionBase::DictToXpcObject(obj);

    xpc_connection_send_message(xpcConnection, message);

    xpc_release(message);

    PyGILState_Release(gstate);
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: swtypes.cxx,v $
 *
 *  $Revision: 1.15 $
 *
 *  last change: $Author: vg $ $Date: 2008-03-18 15:54:41 $
 *
 *  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_sw.hxx"

#include "swtypes.hxx"

#ifndef _STRING_HXX
#include "tools/string.hxx"
#endif
#ifndef _SV_SVAPP_HXX
#include <vcl/svapp.hxx>
#endif
#ifndef _SV_WINDOW_HXX //autogen
#include <vcl/window.hxx>
#endif
#ifndef _SV_GRAPH_HXX //autogen
#include <vcl/graph.hxx>
#endif
#ifndef _UNO_LINGU_HXX
#include <svx/unolingu.hxx>
#endif

#ifndef _PAGEFRM_HXX
#include <pagefrm.hxx>
#endif
#ifndef _SWATRSET_HXX
#include <swatrset.hxx>
#endif
#ifndef _FRMFMT_HXX
#include <frmfmt.hxx>
#endif
#ifndef _FRMTOOL_HXX
#include <frmtool.hxx>
#endif
#ifndef _NDTXT_HXX
#include <ndtxt.hxx>
#endif
#ifndef _UNDOBJ_HXX
#include <undobj.hxx>
#endif
#ifndef _SWTABLE_HXX
#include <swtable.hxx>
#endif
#ifndef _VISCRS_HXX
#include <viscrs.hxx>
#endif
#ifndef _FNTCACHE_HXX
#include <fntcache.hxx>
#endif
#ifndef _SWFNTCCH_HXX
#include <swfntcch.hxx>
#endif
#ifndef _HFFRM_HXX
#include <hffrm.hxx>
#endif
#ifndef _COLFRM_HXX
#include <colfrm.hxx>
#endif
#ifndef _BODYFRM_HXX
#include <bodyfrm.hxx>
#endif
#ifndef _TABFRM_HXX
#include <tabfrm.hxx>
#endif
#ifndef _TXTFRM_HXX
#include <txtfrm.hxx>
#endif
#ifndef _SWTBLFMT_HXX
#include <swtblfmt.hxx>
#endif
#ifndef _ROWFRM_HXX
#include <rowfrm.hxx>
#endif
#ifndef _CELLFRM_HXX
#include <cellfrm.hxx>
#endif
#ifndef _SECTFRM_HXX
#include <sectfrm.hxx>
#endif

using namespace com::sun::star;

ByteString aEmptyByteStr;       // Konstante Strings
String aEmptyStr;               // Konstante Strings
String aDotStr('.');            // Konstante Strings

IMPL_FIXEDMEMPOOL_NEWDEL( SwAttrSet, 25, 25 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwStartNode, 20, 20 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwEndNode,   20, 20 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwTableBox, 50, 50 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwUndoDelete, 10, 10 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwUndoInsert, 10, 10 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwPaM, 10, 10 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwCursor, 10, 10 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwShellCrsr, 10, 10 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwTxtNode, 50, 50 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwpHints, 25, 25 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwFntObj, 50, 50 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwFontObj, 50, 50 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwBorderAttrs, 100, 100 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwCellFrm,    50, 50 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwRowFrm,     10, 10 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwColumnFrm,  40, 40 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwSectionFrm, 20, 20 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwTabFrm, 10, 10 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwPageFrm,    20, 20 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwBodyFrm,    20, 20 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwHeaderFrm,  20, 20 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwFooterFrm,  20, 20 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwTxtFrm,     50,  50 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwTableFmt, 10, 10 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwTableLineFmt, 10, 10 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwTableBoxFmt, 50, 50 )
IMPL_FIXEDMEMPOOL_NEWDEL( _SwCursor_SavePos, 20, 20 )

Size GetGraphicSizeTwip( const Graphic& rGraphic, OutputDevice* pOutDev )
{
    const MapMode aMapTwip( MAP_TWIP );
     Size aSize( rGraphic.GetPrefSize() );
    if( MAP_PIXEL == rGraphic.GetPrefMapMode().GetMapUnit() )
    {
        if( !pOutDev )
            pOutDev = Application::GetDefaultDevice();
        aSize = pOutDev->PixelToLogic( aSize, aMapTwip );
    }
    else
        aSize = OutputDevice::LogicToLogic( aSize,
                                        rGraphic.GetPrefMapMode(), aMapTwip );
    return aSize;
}

uno::Reference< linguistic2::XSpellChecker1 >  GetSpellChecker()
{
    return LinguMgr::GetSpellChecker();
}

uno::Reference< linguistic2::XHyphenator >  GetHyphenator()
{
    return LinguMgr::GetHyphenator();
}

uno::Reference< linguistic2::XThesaurus >  GetThesaurus()
{
    return LinguMgr::GetThesaurus();
}

uno::Reference< beans::XPropertySet >  GetLinguPropertySet()
{
    return LinguMgr::GetLinguPropertySet();
}

<commit_msg>INTEGRATION: CWS changefileheader (1.15.14); FILE MERGED 2008/04/01 15:56:48 thb 1.15.14.3: #i85898# Stripping all external header guards 2008/04/01 12:53:51 thb 1.15.14.2: #i85898# Stripping all external header guards 2008/03/31 16:53:43 rt 1.15.14.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: swtypes.cxx,v $
 * $Revision: 1.16 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

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

#include "swtypes.hxx"
#include "tools/string.hxx"
#include <vcl/svapp.hxx>
#include <vcl/window.hxx>
#include <vcl/graph.hxx>
#include <svx/unolingu.hxx>
#include <pagefrm.hxx>
#include <swatrset.hxx>
#include <frmfmt.hxx>
#include <frmtool.hxx>
#include <ndtxt.hxx>
#include <undobj.hxx>
#include <swtable.hxx>
#include <viscrs.hxx>
#include <fntcache.hxx>
#include <swfntcch.hxx>
#include <hffrm.hxx>
#include <colfrm.hxx>
#include <bodyfrm.hxx>
#include <tabfrm.hxx>
#include <txtfrm.hxx>
#include <swtblfmt.hxx>
#include <rowfrm.hxx>
#include <cellfrm.hxx>
#include <sectfrm.hxx>

using namespace com::sun::star;

ByteString aEmptyByteStr;       // Konstante Strings
String aEmptyStr;               // Konstante Strings
String aDotStr('.');            // Konstante Strings

IMPL_FIXEDMEMPOOL_NEWDEL( SwAttrSet, 25, 25 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwStartNode, 20, 20 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwEndNode,   20, 20 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwTableBox, 50, 50 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwUndoDelete, 10, 10 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwUndoInsert, 10, 10 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwPaM, 10, 10 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwCursor, 10, 10 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwShellCrsr, 10, 10 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwTxtNode, 50, 50 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwpHints, 25, 25 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwFntObj, 50, 50 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwFontObj, 50, 50 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwBorderAttrs, 100, 100 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwCellFrm,    50, 50 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwRowFrm,     10, 10 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwColumnFrm,  40, 40 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwSectionFrm, 20, 20 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwTabFrm, 10, 10 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwPageFrm,    20, 20 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwBodyFrm,    20, 20 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwHeaderFrm,  20, 20 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwFooterFrm,  20, 20 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwTxtFrm,     50,  50 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwTableFmt, 10, 10 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwTableLineFmt, 10, 10 )
IMPL_FIXEDMEMPOOL_NEWDEL( SwTableBoxFmt, 50, 50 )
IMPL_FIXEDMEMPOOL_NEWDEL( _SwCursor_SavePos, 20, 20 )

Size GetGraphicSizeTwip( const Graphic& rGraphic, OutputDevice* pOutDev )
{
    const MapMode aMapTwip( MAP_TWIP );
     Size aSize( rGraphic.GetPrefSize() );
    if( MAP_PIXEL == rGraphic.GetPrefMapMode().GetMapUnit() )
    {
        if( !pOutDev )
            pOutDev = Application::GetDefaultDevice();
        aSize = pOutDev->PixelToLogic( aSize, aMapTwip );
    }
    else
        aSize = OutputDevice::LogicToLogic( aSize,
                                        rGraphic.GetPrefMapMode(), aMapTwip );
    return aSize;
}

uno::Reference< linguistic2::XSpellChecker1 >  GetSpellChecker()
{
    return LinguMgr::GetSpellChecker();
}

uno::Reference< linguistic2::XHyphenator >  GetHyphenator()
{
    return LinguMgr::GetHyphenator();
}

uno::Reference< linguistic2::XThesaurus >  GetThesaurus()
{
    return LinguMgr::GetThesaurus();
}

uno::Reference< beans::XPropertySet >  GetLinguPropertySet()
{
    return LinguMgr::GetLinguPropertySet();
}

<|endoftext|>


<commit_before><commit_msg>fdo#60250: InsertNewPage: copy margins for mirrored pages<commit_after><|endoftext|>


<commit_before><commit_msg>formatting<commit_after><|endoftext|>


<commit_before><commit_msg>rtl::OUStrings are supposed to be immutable<commit_after><|endoftext|>


<commit_before><commit_msg>WaE: 'WW8_BRC' defined as a struct here but previously declared as a class<commit_after><|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: xmlitemm.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: dvo $ $Date: 2002-06-19 13:07:54 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

#ifdef PRECOMPILED
#include "filt_pch.hxx"
#endif

#pragma hdrstop

#include <hintids.hxx>

#ifndef _SVX_UNOMID_HXX
#include <svx/unomid.hxx>
#endif

#ifndef _XMLOFF_XMLNMSPE_HXX
#include <xmloff/xmlnmspe.hxx>
#endif
#ifndef _XMLITMAP_HXX
#include "xmlitmap.hxx"
#endif
#ifndef _XMLOFF_XMLTOKEN_HXX
#include <xmloff/xmltoken.hxx>
#endif

#ifndef _UNOMID_H
#include <unomid.h>
#endif

using namespace ::xmloff::token;

#define M_E( p, l, w, m ) \
    { XML_NAMESPACE_##p, XML_##l, w, m }
#define M_E_SI( p, l, w, m ) \
    { XML_NAMESPACE_##p, XML_##l, w, MID_FLAG_SPECIAL_ITEM_IMPORT|m }
#define M_E_SE( p, l, w, m ) \
    { XML_NAMESPACE_##p, XML_##l, w, MID_FLAG_SPECIAL_ITEM_EXPORT|m }

#define M_END { 0, XML_TOKEN_INVALID, 0, 0 }

SvXMLItemMapEntry aXMLTableItemMap[] =
{
    // RES_FILL_ORDER
    // not required
    // RES_FRM_SIZE
    M_E_SE( STYLE,  WIDTH,          RES_FRM_SIZE,   MID_FRMSIZE_WIDTH ),
    M_E_SE( STYLE,  REL_WIDTH,      RES_FRM_SIZE,   MID_FRMSIZE_REL_WIDTH ),
    // RES_PAPER_BIN
    // not required
    // TODO: RES_LR_SPACE
    M_E_SE( FO, MARGIN_LEFT,        RES_LR_SPACE,   MID_L_MARGIN ),
    M_E_SE( FO, MARGIN_RIGHT,       RES_LR_SPACE,   MID_R_MARGIN ),
    // RES_UL_SPACE
    M_E( FO,    MARGIN_TOP,         RES_UL_SPACE,   MID_UP_MARGIN ),
    M_E( FO,    MARGIN_BOTTOM,      RES_UL_SPACE,   MID_LO_MARGIN ),
    // RES_PAGEDESC
    M_E( STYLE, PAGE_NUMBER,        RES_PAGEDESC,   MID_PAGEDESC_PAGENUMOFFSET),
    // RES_BREAK
    M_E( FO,    BREAK_BEFORE,       RES_BREAK,  MID_BREAK_BEFORE ),
    M_E( FO,    BREAK_AFTER,        RES_BREAK,  MID_BREAK_AFTER ),
    // RES_CNTNT
    // not required
    // RES_HEADER
    // not required
    // RES_FOOTER
    // not required
    // RES_PRINT
    // not required
    // RES_OPAQUE
    // not required
    // RES_PROTECT
    // not required
    // RES_SURROUND
    // not required
    // RES_VERT_ORIENT
    // not required
    // RES_HORI_ORIENT
    M_E( TABLE, ALIGN,                  RES_HORI_ORIENT, 0 ),
    // RES_ANCHOR
    // not required
    // RES_BACKGROUND
    M_E( FO,    BACKGROUND_COLOR,       RES_BACKGROUND, MID_BACK_COLOR ),
    M_E( STYLE, BACKGROUND_IMAGE,       RES_BACKGROUND, MID_FLAG_ELEMENT_ITEM ),
    // RES_BOX
    // not required
    // RES_SHADOW
    M_E( STYLE, SHADOW,             RES_SHADOW, 0 ),
    // RES_FRMMACRO
    // not required
    // RES_COL
    // not required
    // RES_KEEP
    M_E( FO, KEEP_WITH_NEXT,        RES_KEEP, 0 ),
    // RES_URL
    // not required
    // RES_EDIT_IN_READONLY
    // not required
    // RES_LAYOUT_SPLIT
    M_E( STYLE, MAY_BREAK_BETWEEN_ROWS, RES_LAYOUT_SPLIT, 0 ),
    // RES_CHAIN
    // not required
    // RES_LINENUMBER
    // not required
    // RES_FTN_AT_TXTEND
    // not required
    // RES_END_AT_TXTEND
    // not required
    // RES_UNKNOWNATR_CONTAINER
    M_E_SE( TEXT, XMLNS, RES_UNKNOWNATR_CONTAINER, 0 ),

    // RES_FRAMEDIR
    M_E( STYLE, WRITING_MODE, RES_FRAMEDIR, 0 ),
    M_END
};

SvXMLItemMapEntry aXMLTableColItemMap[] =
{
    M_E_SI( STYLE,  COLUMN_WIDTH,     RES_FRM_SIZE, MID_FRMSIZE_COL_WIDTH ),
    M_E( STYLE,     REL_COLUMN_WIDTH, RES_FRM_SIZE, MID_FRMSIZE_REL_COL_WIDTH ),
    M_END
};

SvXMLItemMapEntry aXMLTableRowItemMap[] =
{
    // RES_FILL_ORDER
    // not required
    // RES_FRM_SIZE
    M_E( STYLE, ROW_HEIGHT,         RES_FRM_SIZE,   MID_FRMSIZE_FIX_HEIGHT ),
    M_E( STYLE, MIN_ROW_HEIGHT,     RES_FRM_SIZE,   MID_FRMSIZE_MIN_HEIGHT ),
    // RES_PAPER_BIN
    // not required
    // RES_LR_SPACE
    // not required
    // RES_UL_SPACE
    // not required
    // RES_PAGEDESC
    // not required
    // RES_BREAK
    // not required
    // RES_CNTNT
    // not required
    // RES_HEADER
    // not required
    // RES_FOOTER
    // not required
    // RES_PRINT
    // not required
    // RES_OPAQUE
    // not required
    // RES_PROTECT
    // not required
    // RES_SURROUND
    // not required
    // RES_VERT_ORIENT
    // not required
    // RES_HORI_ORIENT
    // not required
    // RES_ANCHOR
    // not required
    // RES_BACKGROUND
    M_E( FO,    BACKGROUND_COLOR,       RES_BACKGROUND, MID_BACK_COLOR ),
    M_E( STYLE, BACKGROUND_IMAGE,       RES_BACKGROUND, MID_FLAG_ELEMENT_ITEM ),
    // RES_BOX
    // not required
    // RES_ANCHOR
    // not required
    // RES_SHADOW
    // not required
    // RES_FRMMACRO
    // not required
    // RES_COL
    // not required
    // RES_KEEP
    // not required
    // RES_URL
    // not required
    // RES_EDIT_IN_READONLY
    // not required
    // RES_LAYOUT_SPLIT
    // not required
    // RES_CHAIN
    // not required
    // RES_LINENUMBER
    // not required
    // RES_FTN_AT_TXTEND
    // not required
    // RES_END_AT_TXTEND
    // not required
    // RES_UNKNOWNATR_CONTAINER
    M_E_SE( TEXT, XMLNS, RES_UNKNOWNATR_CONTAINER, 0 ),
    M_END
};

SvXMLItemMapEntry aXMLTableCellItemMap[] =
{
    // RES_FILL_ORDER
    // not required
    // RES_FRM_SIZE
    // not required
    // RES_PAPER_BIN
    // not required
    // RES_LR_SPACE
    // not required
    // RES_UL_SPACE
    // not required
    // RES_PAGEDESC
    // not required
    // RES_BREAK
    // not required
    // RES_CNTNT
    // not required
    // RES_HEADER
    // not required
    // RES_FOOTER
    // not required
    // RES_PRINT
    // not required
    // RES_OPAQUE
    // not required
    // RES_PROTECT
    // not required
    // RES_SURROUND
    // not required
    // RES_VERT_ORIENT
    M_E( FO,    VERTICAL_ALIGN,                 RES_VERT_ORIENT, 0 ),
    // RES_HORI_ORIENT
    // not required
    // RES_ANCHOR
    // not required
    // RES_BACKGROUND
    M_E( FO,    BACKGROUND_COLOR,       RES_BACKGROUND, MID_BACK_COLOR ),
    M_E( STYLE, BACKGROUND_IMAGE,       RES_BACKGROUND, MID_FLAG_ELEMENT_ITEM ),
    // RES_BOX
    M_E( STYLE, BORDER_LINE_WIDTH,        RES_BOX, ALL_BORDER_LINE_WIDTH ),
    M_E( STYLE, BORDER_LINE_WIDTH_LEFT,   RES_BOX, LEFT_BORDER_LINE_WIDTH ),
    M_E( STYLE, BORDER_LINE_WIDTH_RIGHT,  RES_BOX, RIGHT_BORDER_LINE_WIDTH ),
    M_E( STYLE, BORDER_LINE_WIDTH_TOP,    RES_BOX, TOP_BORDER_LINE_WIDTH ),
    M_E( STYLE, BORDER_LINE_WIDTH_BOTTOM, RES_BOX, BOTTOM_BORDER_LINE_WIDTH ),
    M_E( FO,    PADDING,                  RES_BOX, ALL_BORDER_PADDING ),
    M_E( FO,    PADDING_LEFT,             RES_BOX, LEFT_BORDER_PADDING ),
    M_E( FO,    PADDING_RIGHT,            RES_BOX, RIGHT_BORDER_PADDING ),
    M_E( FO,    PADDING_TOP,              RES_BOX, TOP_BORDER_PADDING ),
    M_E( FO,    PADDING_BOTTOM,           RES_BOX, BOTTOM_BORDER_PADDING ),
    M_E( FO,    BORDER,                   RES_BOX, ALL_BORDER ),
    M_E( FO,    BORDER_LEFT,              RES_BOX, LEFT_BORDER ),
    M_E( FO,    BORDER_RIGHT,             RES_BOX, RIGHT_BORDER ),
    M_E( FO,    BORDER_TOP,               RES_BOX, TOP_BORDER ),
    M_E( FO,    BORDER_BOTTOM,            RES_BOX, BOTTOM_BORDER ),
    // RES_SHADOW
    // not required
    // RES_FRMMACRO
    // not required
    // RES_COL
    // not required
    // RES_KEEP
    // not required
    // RES_URL
    // not required
    // RES_EDIT_IN_READONLY
    // not required
    // RES_LAYOUT_SPLIT
    // not required
    // RES_CHAIN
    // not required
    // RES_LINENUMBER
    // not required
    // RES_FTN_AT_TXTEND
    // not required
    // RES_END_AT_TXTEND
    // not required
    // RES_UNKNOWNATR_CONTAINER
    M_E_SE( TEXT, XMLNS, RES_UNKNOWNATR_CONTAINER, 0 ),
    M_END
};
<commit_msg>INTEGRATION: CWS os8 (1.7.146); FILE MERGED 2003/04/03 07:13:21 os 1.7.146.1: #108583# precompiled headers removed<commit_after>/*************************************************************************
 *
 *  $RCSfile: xmlitemm.cxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: vg $ $Date: 2003-04-17 15:08:27 $
 *
 *  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

#include <hintids.hxx>

#ifndef _SVX_UNOMID_HXX
#include <svx/unomid.hxx>
#endif

#ifndef _XMLOFF_XMLNMSPE_HXX
#include <xmloff/xmlnmspe.hxx>
#endif
#ifndef _XMLITMAP_HXX
#include "xmlitmap.hxx"
#endif
#ifndef _XMLOFF_XMLTOKEN_HXX
#include <xmloff/xmltoken.hxx>
#endif

#ifndef _UNOMID_H
#include <unomid.h>
#endif

using namespace ::xmloff::token;

#define M_E( p, l, w, m ) \
    { XML_NAMESPACE_##p, XML_##l, w, m }
#define M_E_SI( p, l, w, m ) \
    { XML_NAMESPACE_##p, XML_##l, w, MID_FLAG_SPECIAL_ITEM_IMPORT|m }
#define M_E_SE( p, l, w, m ) \
    { XML_NAMESPACE_##p, XML_##l, w, MID_FLAG_SPECIAL_ITEM_EXPORT|m }

#define M_END { 0, XML_TOKEN_INVALID, 0, 0 }

SvXMLItemMapEntry aXMLTableItemMap[] =
{
    // RES_FILL_ORDER
    // not required
    // RES_FRM_SIZE
    M_E_SE( STYLE,  WIDTH,          RES_FRM_SIZE,   MID_FRMSIZE_WIDTH ),
    M_E_SE( STYLE,  REL_WIDTH,      RES_FRM_SIZE,   MID_FRMSIZE_REL_WIDTH ),
    // RES_PAPER_BIN
    // not required
    // TODO: RES_LR_SPACE
    M_E_SE( FO, MARGIN_LEFT,        RES_LR_SPACE,   MID_L_MARGIN ),
    M_E_SE( FO, MARGIN_RIGHT,       RES_LR_SPACE,   MID_R_MARGIN ),
    // RES_UL_SPACE
    M_E( FO,    MARGIN_TOP,         RES_UL_SPACE,   MID_UP_MARGIN ),
    M_E( FO,    MARGIN_BOTTOM,      RES_UL_SPACE,   MID_LO_MARGIN ),
    // RES_PAGEDESC
    M_E( STYLE, PAGE_NUMBER,        RES_PAGEDESC,   MID_PAGEDESC_PAGENUMOFFSET),
    // RES_BREAK
    M_E( FO,    BREAK_BEFORE,       RES_BREAK,  MID_BREAK_BEFORE ),
    M_E( FO,    BREAK_AFTER,        RES_BREAK,  MID_BREAK_AFTER ),
    // RES_CNTNT
    // not required
    // RES_HEADER
    // not required
    // RES_FOOTER
    // not required
    // RES_PRINT
    // not required
    // RES_OPAQUE
    // not required
    // RES_PROTECT
    // not required
    // RES_SURROUND
    // not required
    // RES_VERT_ORIENT
    // not required
    // RES_HORI_ORIENT
    M_E( TABLE, ALIGN,                  RES_HORI_ORIENT, 0 ),
    // RES_ANCHOR
    // not required
    // RES_BACKGROUND
    M_E( FO,    BACKGROUND_COLOR,       RES_BACKGROUND, MID_BACK_COLOR ),
    M_E( STYLE, BACKGROUND_IMAGE,       RES_BACKGROUND, MID_FLAG_ELEMENT_ITEM ),
    // RES_BOX
    // not required
    // RES_SHADOW
    M_E( STYLE, SHADOW,             RES_SHADOW, 0 ),
    // RES_FRMMACRO
    // not required
    // RES_COL
    // not required
    // RES_KEEP
    M_E( FO, KEEP_WITH_NEXT,        RES_KEEP, 0 ),
    // RES_URL
    // not required
    // RES_EDIT_IN_READONLY
    // not required
    // RES_LAYOUT_SPLIT
    M_E( STYLE, MAY_BREAK_BETWEEN_ROWS, RES_LAYOUT_SPLIT, 0 ),
    // RES_CHAIN
    // not required
    // RES_LINENUMBER
    // not required
    // RES_FTN_AT_TXTEND
    // not required
    // RES_END_AT_TXTEND
    // not required
    // RES_UNKNOWNATR_CONTAINER
    M_E_SE( TEXT, XMLNS, RES_UNKNOWNATR_CONTAINER, 0 ),

    // RES_FRAMEDIR
    M_E( STYLE, WRITING_MODE, RES_FRAMEDIR, 0 ),
    M_END
};

SvXMLItemMapEntry aXMLTableColItemMap[] =
{
    M_E_SI( STYLE,  COLUMN_WIDTH,     RES_FRM_SIZE, MID_FRMSIZE_COL_WIDTH ),
    M_E( STYLE,     REL_COLUMN_WIDTH, RES_FRM_SIZE, MID_FRMSIZE_REL_COL_WIDTH ),
    M_END
};

SvXMLItemMapEntry aXMLTableRowItemMap[] =
{
    // RES_FILL_ORDER
    // not required
    // RES_FRM_SIZE
    M_E( STYLE, ROW_HEIGHT,         RES_FRM_SIZE,   MID_FRMSIZE_FIX_HEIGHT ),
    M_E( STYLE, MIN_ROW_HEIGHT,     RES_FRM_SIZE,   MID_FRMSIZE_MIN_HEIGHT ),
    // RES_PAPER_BIN
    // not required
    // RES_LR_SPACE
    // not required
    // RES_UL_SPACE
    // not required
    // RES_PAGEDESC
    // not required
    // RES_BREAK
    // not required
    // RES_CNTNT
    // not required
    // RES_HEADER
    // not required
    // RES_FOOTER
    // not required
    // RES_PRINT
    // not required
    // RES_OPAQUE
    // not required
    // RES_PROTECT
    // not required
    // RES_SURROUND
    // not required
    // RES_VERT_ORIENT
    // not required
    // RES_HORI_ORIENT
    // not required
    // RES_ANCHOR
    // not required
    // RES_BACKGROUND
    M_E( FO,    BACKGROUND_COLOR,       RES_BACKGROUND, MID_BACK_COLOR ),
    M_E( STYLE, BACKGROUND_IMAGE,       RES_BACKGROUND, MID_FLAG_ELEMENT_ITEM ),
    // RES_BOX
    // not required
    // RES_ANCHOR
    // not required
    // RES_SHADOW
    // not required
    // RES_FRMMACRO
    // not required
    // RES_COL
    // not required
    // RES_KEEP
    // not required
    // RES_URL
    // not required
    // RES_EDIT_IN_READONLY
    // not required
    // RES_LAYOUT_SPLIT
    // not required
    // RES_CHAIN
    // not required
    // RES_LINENUMBER
    // not required
    // RES_FTN_AT_TXTEND
    // not required
    // RES_END_AT_TXTEND
    // not required
    // RES_UNKNOWNATR_CONTAINER
    M_E_SE( TEXT, XMLNS, RES_UNKNOWNATR_CONTAINER, 0 ),
    M_END
};

SvXMLItemMapEntry aXMLTableCellItemMap[] =
{
    // RES_FILL_ORDER
    // not required
    // RES_FRM_SIZE
    // not required
    // RES_PAPER_BIN
    // not required
    // RES_LR_SPACE
    // not required
    // RES_UL_SPACE
    // not required
    // RES_PAGEDESC
    // not required
    // RES_BREAK
    // not required
    // RES_CNTNT
    // not required
    // RES_HEADER
    // not required
    // RES_FOOTER
    // not required
    // RES_PRINT
    // not required
    // RES_OPAQUE
    // not required
    // RES_PROTECT
    // not required
    // RES_SURROUND
    // not required
    // RES_VERT_ORIENT
    M_E( FO,    VERTICAL_ALIGN,                 RES_VERT_ORIENT, 0 ),
    // RES_HORI_ORIENT
    // not required
    // RES_ANCHOR
    // not required
    // RES_BACKGROUND
    M_E( FO,    BACKGROUND_COLOR,       RES_BACKGROUND, MID_BACK_COLOR ),
    M_E( STYLE, BACKGROUND_IMAGE,       RES_BACKGROUND, MID_FLAG_ELEMENT_ITEM ),
    // RES_BOX
    M_E( STYLE, BORDER_LINE_WIDTH,        RES_BOX, ALL_BORDER_LINE_WIDTH ),
    M_E( STYLE, BORDER_LINE_WIDTH_LEFT,   RES_BOX, LEFT_BORDER_LINE_WIDTH ),
    M_E( STYLE, BORDER_LINE_WIDTH_RIGHT,  RES_BOX, RIGHT_BORDER_LINE_WIDTH ),
    M_E( STYLE, BORDER_LINE_WIDTH_TOP,    RES_BOX, TOP_BORDER_LINE_WIDTH ),
    M_E( STYLE, BORDER_LINE_WIDTH_BOTTOM, RES_BOX, BOTTOM_BORDER_LINE_WIDTH ),
    M_E( FO,    PADDING,                  RES_BOX, ALL_BORDER_PADDING ),
    M_E( FO,    PADDING_LEFT,             RES_BOX, LEFT_BORDER_PADDING ),
    M_E( FO,    PADDING_RIGHT,            RES_BOX, RIGHT_BORDER_PADDING ),
    M_E( FO,    PADDING_TOP,              RES_BOX, TOP_BORDER_PADDING ),
    M_E( FO,    PADDING_BOTTOM,           RES_BOX, BOTTOM_BORDER_PADDING ),
    M_E( FO,    BORDER,                   RES_BOX, ALL_BORDER ),
    M_E( FO,    BORDER_LEFT,              RES_BOX, LEFT_BORDER ),
    M_E( FO,    BORDER_RIGHT,             RES_BOX, RIGHT_BORDER ),
    M_E( FO,    BORDER_TOP,               RES_BOX, TOP_BORDER ),
    M_E( FO,    BORDER_BOTTOM,            RES_BOX, BOTTOM_BORDER ),
    // RES_SHADOW
    // not required
    // RES_FRMMACRO
    // not required
    // RES_COL
    // not required
    // RES_KEEP
    // not required
    // RES_URL
    // not required
    // RES_EDIT_IN_READONLY
    // not required
    // RES_LAYOUT_SPLIT
    // not required
    // RES_CHAIN
    // not required
    // RES_LINENUMBER
    // not required
    // RES_FTN_AT_TXTEND
    // not required
    // RES_END_AT_TXTEND
    // not required
    // RES_UNKNOWNATR_CONTAINER
    M_E_SE( TEXT, XMLNS, RES_UNKNOWNATR_CONTAINER, 0 ),
    M_END
};
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: swtablerep.cxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: hr $ $Date: 2004-05-10 16:38:20 $
 *
 *  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 _HINTIDS_HXX
#include <hintids.hxx>
#endif

#ifndef _LIST_HXX //autogen
#include <tools/list.hxx>
#endif
#ifndef _SV_MSGBOX_HXX //autogen
#include <vcl/msgbox.hxx>
#endif
#ifndef _SFXSTRITEM_HXX //autogen
#include <svtools/stritem.hxx>
#endif
#ifndef _SFXINTITEM_HXX //autogen
#include <svtools/intitem.hxx>
#endif
//CHINA001 #ifndef _SVX_BORDER_HXX //autogen
//CHINA001 #include <svx/border.hxx>
//CHINA001 #endif
//CHINA001 #ifndef _SVX_BACKGRND_HXX //autogen
//CHINA001 #include <svx/backgrnd.hxx>
//CHINA001 #endif
#ifndef _SVX_HTMLMODE_HXX
#include <svx/htmlmode.hxx>
#endif
#ifndef _SVX_KEEPITEM_HXX //autogen
#include <svx/keepitem.hxx>
#endif
#ifndef _SVX_BRKITEM_HXX //autogen
#include <svx/brkitem.hxx>
#endif
#ifndef _SVX_ULSPITEM_HXX //autogen
#include <svx/ulspitem.hxx>
#endif
#ifndef _SVX_FRMDIRITEM_HXX
#include <svx/frmdiritem.hxx>
#endif

#ifndef _SVTOOLS_CTLOPTIONS_HXX
#include <svtools/ctloptions.hxx>
#endif
#ifndef _SWMODULE_HXX
#include <swmodule.hxx>
#endif

#ifndef _FMTORNT_HXX //autogen
#include <fmtornt.hxx>
#endif
#ifndef _FMTPDSC_HXX //autogen
#include <fmtpdsc.hxx>
#endif
#ifndef _FMTTSPLT_HXX //autogen
#include <fmtlsplt.hxx>
#endif

#include <svx/htmlcfg.hxx>

#ifndef _FMTROWSPLT_HXX //autogen
#include <fmtrowsplt.hxx>
#endif
#ifndef _SVX_HTMLMODE_HXX
#include <svx/htmlmode.hxx>
#endif

#ifndef _DOCSH_HXX
#include <docsh.hxx>
#endif
#ifndef _WRTSH_HXX
#include <wrtsh.hxx>
#endif
#ifndef _VIEW_HXX
#include <view.hxx>
#endif
#ifndef _VIEWOPT_HXX
#include <viewopt.hxx>
#endif
#ifndef _UITOOL_HXX
#include <uitool.hxx>
#endif
#ifndef _FRMATR_HXX
#include <frmatr.hxx>
#endif

#ifndef _TABLEPG_HXX
#include <tablepg.hxx>
#endif
#ifndef _TABLEMGR_HXX
#include <tablemgr.hxx>
#endif
#ifndef _PAGEDESC_HXX
#include <pagedesc.hxx>
#endif
#ifndef _UIITEMS_HXX
#include <uiitems.hxx>
#endif
#ifndef _POOLFMT_HXX
#include <poolfmt.hxx>
#endif
#ifndef _SWSTYLENAMEMAPPER_HXX
#include <SwStyleNameMapper.hxx>
#endif

#ifndef _CMDID_H
#include <cmdid.h>
#endif
#ifndef _TABLEDLG_HRC
#include <tabledlg.hrc>
#endif
#ifndef _TABLE_HRC
#include <table.hrc>
#endif
#ifndef _SWTABLEREP_HXX
#include "swtablerep.hxx"
#endif

#ifdef DEBUG_TBLDLG

void DbgTColumn(TColumn* pTColumn, USHORT nCount)
{
    for(USHORT i = 0; i < nCount; i++)
    {
        String sMsg(i);
        sMsg += pTColumn[i].bVisible ? " v " : " h ";
        sMsg += pTColumn[i].nWidth;
        DBG_ERROR(sMsg)
    }
}
#endif

#ifdef DEBUG_TBLDLG
#define DEBUG_TBLDLG_TCOLUMN(pTColumn, nCount) DbgTColumn(pTColumn, nCount)
#else
#define DEBUG_TBLDLG_TCOLUMN
#endif
/*-----------------20.08.96 09.43-------------------
--------------------------------------------------*/
SwTableRep::SwTableRep( const SwTabCols& rTabCol, BOOL bCplx )
    : nTblWidth(0),
    nSpace(0),
    nLeftSpace(0),
    nRightSpace(0),
    nAlign(0),
    nWidthPercent(0),
    bLineSelected(FALSE),
    bComplex(bCplx),
    bWidthChanged(FALSE),
    bColsChanged(FALSE)
{
    nAllCols = nColCount = rTabCol.Count();
    pTColumns = new TColumn[ nColCount + 1 ];
    SwTwips nStart = 0,
            nEnd;
    for( USHORT i = 0; i < nAllCols; ++i )
    {
        nEnd  = rTabCol[ i ] - rTabCol.GetLeft();
        pTColumns[ i ].nWidth = nEnd - nStart;
        pTColumns[ i ].bVisible = !rTabCol.IsHidden(i);
        if(!pTColumns[ i ].bVisible)
            nColCount --;
        nStart = nEnd;
    }
    pTColumns[ nAllCols ].nWidth = rTabCol.GetRight() - rTabCol.GetLeft() - nStart;
    pTColumns[ nAllCols ].bVisible = TRUE;
    nColCount++;
    nAllCols++;
}

/*-----------------20.08.96 09.43-------------------
--------------------------------------------------*/
SwTableRep::~SwTableRep()
{
    delete[] pTColumns;
}

/*-----------------20.08.96 13.33-------------------
--------------------------------------------------*/
BOOL SwTableRep::FillTabCols( SwTabCols& rTabCols ) const
{
    long nOldLeft = rTabCols.GetLeft(),
         nOldRight = rTabCols.GetRight();

    BOOL bSingleLine = FALSE;
    USHORT i;

    for ( i = 0; i < rTabCols.Count(); ++i )
        if(!pTColumns[i].bVisible)
        {
            bSingleLine = TRUE;
            break;
        }

DEBUG_TBLDLG_TCOLUMN(pTColumns, nAllCols);

    SwTwips nPos = 0;
    SwTwips nLeft = GetLeftSpace();
    rTabCols.SetLeft(nLeft);
    if(bSingleLine)
    {
        // die unsichtbaren Trenner werden aus den alten TabCols genommen
        // die sichtbaren kommen aus pTColumns
        TColumn*    pOldTColumns = new TColumn[nAllCols + 1];
        SwTwips nStart = 0,
                nEnd;
        for(USHORT i = 0; i < nAllCols - 1; i++)
        {
            nEnd  = rTabCols[i] - rTabCols.GetLeft();
            pOldTColumns[i].nWidth = nEnd - nStart;
            pOldTColumns[i].bVisible = !rTabCols.IsHidden(i);
            nStart = nEnd;
        }
        pOldTColumns[nAllCols - 1].nWidth = rTabCols.GetRight() - rTabCols.GetLeft() - nStart;
        pOldTColumns[nAllCols - 1].bVisible = TRUE;

DEBUG_TBLDLG_TCOLUMN(pOldTColumns, nAllCols);

        USHORT nOldPos = 0;
        USHORT nNewPos = 0;
        SwTwips nOld = 0;
        SwTwips nNew = 0;
        BOOL bOld = FALSE;
        BOOL bFirst = TRUE;
        i = 0;

        while ( i < nAllCols -1 )
        {
            while((bFirst || bOld ) && nOldPos < nAllCols )
            {
                nOld += pOldTColumns[nOldPos].nWidth;
                nOldPos++;
                if(!pOldTColumns[nOldPos - 1].bVisible)
                    break;
            }
            while((bFirst || !bOld ) && nNewPos < nAllCols )
            {
                nNew += pTColumns[nNewPos].nWidth;
                nNewPos++;
                if(pOldTColumns[nNewPos - 1].bVisible)
                    break;
            }
            bFirst = FALSE;
            // sie muessen sortiert eingefuegt werden
            bOld = nOld < nNew;
            nPos = USHORT(bOld ? nOld : nNew);
            rTabCols[i] = nPos + nLeft;
            rTabCols.SetHidden( i, bOld );
            i++;
        }
        rTabCols.SetRight(nLeft + nTblWidth);

        delete[] pOldTColumns;
    }
    else
    {
        for ( i = 0; i < nAllCols - 1; ++i )
        {
            nPos += pTColumns[i].nWidth;
            rTabCols[i] = nPos + rTabCols.GetLeft();
            rTabCols.SetHidden( i, !pTColumns[i].bVisible );
            rTabCols.SetRight(nLeft + pTColumns[nAllCols - 1].nWidth + nPos);
        }
    }

// Rundungsfehler abfangen
    if(Abs((long)nOldLeft - (long)rTabCols.GetLeft()) < 3)
        rTabCols.SetLeft(nOldLeft);

    if(Abs((long)nOldRight - (long)rTabCols.GetRight()) < 3)
        rTabCols.SetRight(nOldRight);

    if(GetRightSpace() >= 0 &&
            rTabCols.GetRight() > rTabCols.GetRightMax())
        rTabCols.SetRight(rTabCols.GetRightMax());
    return bSingleLine;
}<commit_msg>INTEGRATION: CWS ooo19126 (1.2.726); FILE MERGED 2005/09/05 13:47:32 rt 1.2.726.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: swtablerep.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 11:04:57 $
 *
 *  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
 *
 ************************************************************************/

#pragma hdrstop

#ifndef _HINTIDS_HXX
#include <hintids.hxx>
#endif

#ifndef _LIST_HXX //autogen
#include <tools/list.hxx>
#endif
#ifndef _SV_MSGBOX_HXX //autogen
#include <vcl/msgbox.hxx>
#endif
#ifndef _SFXSTRITEM_HXX //autogen
#include <svtools/stritem.hxx>
#endif
#ifndef _SFXINTITEM_HXX //autogen
#include <svtools/intitem.hxx>
#endif
//CHINA001 #ifndef _SVX_BORDER_HXX //autogen
//CHINA001 #include <svx/border.hxx>
//CHINA001 #endif
//CHINA001 #ifndef _SVX_BACKGRND_HXX //autogen
//CHINA001 #include <svx/backgrnd.hxx>
//CHINA001 #endif
#ifndef _SVX_HTMLMODE_HXX
#include <svx/htmlmode.hxx>
#endif
#ifndef _SVX_KEEPITEM_HXX //autogen
#include <svx/keepitem.hxx>
#endif
#ifndef _SVX_BRKITEM_HXX //autogen
#include <svx/brkitem.hxx>
#endif
#ifndef _SVX_ULSPITEM_HXX //autogen
#include <svx/ulspitem.hxx>
#endif
#ifndef _SVX_FRMDIRITEM_HXX
#include <svx/frmdiritem.hxx>
#endif

#ifndef _SVTOOLS_CTLOPTIONS_HXX
#include <svtools/ctloptions.hxx>
#endif
#ifndef _SWMODULE_HXX
#include <swmodule.hxx>
#endif

#ifndef _FMTORNT_HXX //autogen
#include <fmtornt.hxx>
#endif
#ifndef _FMTPDSC_HXX //autogen
#include <fmtpdsc.hxx>
#endif
#ifndef _FMTTSPLT_HXX //autogen
#include <fmtlsplt.hxx>
#endif

#include <svx/htmlcfg.hxx>

#ifndef _FMTROWSPLT_HXX //autogen
#include <fmtrowsplt.hxx>
#endif
#ifndef _SVX_HTMLMODE_HXX
#include <svx/htmlmode.hxx>
#endif

#ifndef _DOCSH_HXX
#include <docsh.hxx>
#endif
#ifndef _WRTSH_HXX
#include <wrtsh.hxx>
#endif
#ifndef _VIEW_HXX
#include <view.hxx>
#endif
#ifndef _VIEWOPT_HXX
#include <viewopt.hxx>
#endif
#ifndef _UITOOL_HXX
#include <uitool.hxx>
#endif
#ifndef _FRMATR_HXX
#include <frmatr.hxx>
#endif

#ifndef _TABLEPG_HXX
#include <tablepg.hxx>
#endif
#ifndef _TABLEMGR_HXX
#include <tablemgr.hxx>
#endif
#ifndef _PAGEDESC_HXX
#include <pagedesc.hxx>
#endif
#ifndef _UIITEMS_HXX
#include <uiitems.hxx>
#endif
#ifndef _POOLFMT_HXX
#include <poolfmt.hxx>
#endif
#ifndef _SWSTYLENAMEMAPPER_HXX
#include <SwStyleNameMapper.hxx>
#endif

#ifndef _CMDID_H
#include <cmdid.h>
#endif
#ifndef _TABLEDLG_HRC
#include <tabledlg.hrc>
#endif
#ifndef _TABLE_HRC
#include <table.hrc>
#endif
#ifndef _SWTABLEREP_HXX
#include "swtablerep.hxx"
#endif

#ifdef DEBUG_TBLDLG

void DbgTColumn(TColumn* pTColumn, USHORT nCount)
{
    for(USHORT i = 0; i < nCount; i++)
    {
        String sMsg(i);
        sMsg += pTColumn[i].bVisible ? " v " : " h ";
        sMsg += pTColumn[i].nWidth;
        DBG_ERROR(sMsg)
    }
}
#endif

#ifdef DEBUG_TBLDLG
#define DEBUG_TBLDLG_TCOLUMN(pTColumn, nCount) DbgTColumn(pTColumn, nCount)
#else
#define DEBUG_TBLDLG_TCOLUMN
#endif
/*-----------------20.08.96 09.43-------------------
--------------------------------------------------*/
SwTableRep::SwTableRep( const SwTabCols& rTabCol, BOOL bCplx )
    : nTblWidth(0),
    nSpace(0),
    nLeftSpace(0),
    nRightSpace(0),
    nAlign(0),
    nWidthPercent(0),
    bLineSelected(FALSE),
    bComplex(bCplx),
    bWidthChanged(FALSE),
    bColsChanged(FALSE)
{
    nAllCols = nColCount = rTabCol.Count();
    pTColumns = new TColumn[ nColCount + 1 ];
    SwTwips nStart = 0,
            nEnd;
    for( USHORT i = 0; i < nAllCols; ++i )
    {
        nEnd  = rTabCol[ i ] - rTabCol.GetLeft();
        pTColumns[ i ].nWidth = nEnd - nStart;
        pTColumns[ i ].bVisible = !rTabCol.IsHidden(i);
        if(!pTColumns[ i ].bVisible)
            nColCount --;
        nStart = nEnd;
    }
    pTColumns[ nAllCols ].nWidth = rTabCol.GetRight() - rTabCol.GetLeft() - nStart;
    pTColumns[ nAllCols ].bVisible = TRUE;
    nColCount++;
    nAllCols++;
}

/*-----------------20.08.96 09.43-------------------
--------------------------------------------------*/
SwTableRep::~SwTableRep()
{
    delete[] pTColumns;
}

/*-----------------20.08.96 13.33-------------------
--------------------------------------------------*/
BOOL SwTableRep::FillTabCols( SwTabCols& rTabCols ) const
{
    long nOldLeft = rTabCols.GetLeft(),
         nOldRight = rTabCols.GetRight();

    BOOL bSingleLine = FALSE;
    USHORT i;

    for ( i = 0; i < rTabCols.Count(); ++i )
        if(!pTColumns[i].bVisible)
        {
            bSingleLine = TRUE;
            break;
        }

DEBUG_TBLDLG_TCOLUMN(pTColumns, nAllCols);

    SwTwips nPos = 0;
    SwTwips nLeft = GetLeftSpace();
    rTabCols.SetLeft(nLeft);
    if(bSingleLine)
    {
        // die unsichtbaren Trenner werden aus den alten TabCols genommen
        // die sichtbaren kommen aus pTColumns
        TColumn*    pOldTColumns = new TColumn[nAllCols + 1];
        SwTwips nStart = 0,
                nEnd;
        for(USHORT i = 0; i < nAllCols - 1; i++)
        {
            nEnd  = rTabCols[i] - rTabCols.GetLeft();
            pOldTColumns[i].nWidth = nEnd - nStart;
            pOldTColumns[i].bVisible = !rTabCols.IsHidden(i);
            nStart = nEnd;
        }
        pOldTColumns[nAllCols - 1].nWidth = rTabCols.GetRight() - rTabCols.GetLeft() - nStart;
        pOldTColumns[nAllCols - 1].bVisible = TRUE;

DEBUG_TBLDLG_TCOLUMN(pOldTColumns, nAllCols);

        USHORT nOldPos = 0;
        USHORT nNewPos = 0;
        SwTwips nOld = 0;
        SwTwips nNew = 0;
        BOOL bOld = FALSE;
        BOOL bFirst = TRUE;
        i = 0;

        while ( i < nAllCols -1 )
        {
            while((bFirst || bOld ) && nOldPos < nAllCols )
            {
                nOld += pOldTColumns[nOldPos].nWidth;
                nOldPos++;
                if(!pOldTColumns[nOldPos - 1].bVisible)
                    break;
            }
            while((bFirst || !bOld ) && nNewPos < nAllCols )
            {
                nNew += pTColumns[nNewPos].nWidth;
                nNewPos++;
                if(pOldTColumns[nNewPos - 1].bVisible)
                    break;
            }
            bFirst = FALSE;
            // sie muessen sortiert eingefuegt werden
            bOld = nOld < nNew;
            nPos = USHORT(bOld ? nOld : nNew);
            rTabCols[i] = nPos + nLeft;
            rTabCols.SetHidden( i, bOld );
            i++;
        }
        rTabCols.SetRight(nLeft + nTblWidth);

        delete[] pOldTColumns;
    }
    else
    {
        for ( i = 0; i < nAllCols - 1; ++i )
        {
            nPos += pTColumns[i].nWidth;
            rTabCols[i] = nPos + rTabCols.GetLeft();
            rTabCols.SetHidden( i, !pTColumns[i].bVisible );
            rTabCols.SetRight(nLeft + pTColumns[nAllCols - 1].nWidth + nPos);
        }
    }

// Rundungsfehler abfangen
    if(Abs((long)nOldLeft - (long)rTabCols.GetLeft()) < 3)
        rTabCols.SetLeft(nOldLeft);

    if(Abs((long)nOldRight - (long)rTabCols.GetRight()) < 3)
        rTabCols.SetRight(nOldRight);

    if(GetRightSpace() >= 0 &&
            rTabCols.GetRight() > rTabCols.GetRightMax())
        rTabCols.SetRight(rTabCols.GetRightMax());
    return bSingleLine;
}<|endoftext|>


<commit_before><commit_msg>Resolves: fdo#85666 when matching existing list indent use matching level<commit_after><|endoftext|>