<commit_before>/*****************************************************************************
 * x266.cpp: WC Encoder Functions
 *****************************************************************************
 * Copyright (C) 2015-2020 x266 project
 *
 * Authors: Min Chen <chenm003@163.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
 *
 * This program is also available under a commercial proprietary license.
 * For more information, contact us at chenm003@163.com.
 *****************************************************************************/

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <assert.h>

 /*****************************************************************************
 *****************************************************************************/
#define MAX_WIDTH           (4096)
#define MAX_HEIGHT          (2048)
#define REF_BLOCK_SZ        (16)
#define REF_FRAME_STRD      (MAX_WIDTH / REF_BLOCK_SZ)

// Thanks to https://gist.github.com/PhilCK/1534763
#ifdef __GNUC__
#define PACKED( class_to_pack ) class_to_pack __attribute__((__packed__))
#else
#define PACKED( class_to_pack ) __pragma( pack(push, 1) ) class_to_pack __pragma( pack(pop) )
#endif

/*****************************************************************************
 *****************************************************************************/

PACKED(struct _ref_block_t
{
    // REF_BLOCK_SZ=16
    uint8_t     m_Y[16*16];         // 256 bytes - Y
    uint8_t     m_C[2*8*8];         // 128 bytes - UV
    uint8_t     m_I[128];           // 128 bytes - Info
});
typedef struct _ref_block_t ref_block_t;

typedef struct _codec_t
{
    ref_block_t    *m_frames[3];            // [0]=Cur, [1..N]=References
    intptr_t        m_frames_strd;
} codec_t;

/*****************************************************************************
 *****************************************************************************/
void xConvInputFmt(ref_block_t     *pBlock,
                   const uint8_t   *inpY,
                   const intptr_t   strdY,
                   const uint8_t   *inpU,
                   const uint8_t   *inpV,
                   const intptr_t   strdC,
                   const int        width,
                   const int        height)
{
    assert(!(width % REF_BLOCK_SZ) && "width is not multiple of 16");
    assert(!(height % REF_BLOCK_SZ) && "height is not multiple of 16");

    int i, j, x, y;
    for(y = 0; y < height; y += REF_BLOCK_SZ)
    {
        for(x = 0; x < width; x += REF_BLOCK_SZ)
        {
            // Y
            for(i = 0; i < REF_BLOCK_SZ; i++)
            {
                memcpy(&pBlock->m_Y[i * REF_BLOCK_SZ],
                       &inpY[(y+i)*strdY + x],
                       REF_BLOCK_SZ*sizeof(uint8_t));
            }

            // UV - 420SP
            for(i = 0; i < REF_BLOCK_SZ/2; i++)
            {
                for(j = 0; j < REF_BLOCK_SZ/2; j++)
                {
                    pBlock->m_C[i*REF_BLOCK_SZ + j*2 + 0] = inpU[((y>>1)+i)*strdC + ((x>>1)+j)];
                    pBlock->m_C[i*REF_BLOCK_SZ + j*2 + 1] = inpV[((y>>1)+i)*strdC + ((x>>1)+j)];
                }
            }
            pBlock++;
        }
    }
}

 /*****************************************************************************
 *****************************************************************************/
int main(int argc, char *argv[])
{
    if(argc < 5)
    {
        fprintf(stderr, "Usage: %s -i in_file -o out_file -w width -h height -f frames\n", argv[0]);
        return 0;
    }

    // Encoder parameters
    FILE *fpi = NULL;
    FILE *fpo = NULL;
    int nWidth = 0;
    int nHeight = 0;
    int nFrames = 0;

    int i;
    for(i = 1; i < argc; i++)
    {
        if(!_stricmp(argv[i], "-i"))
        {
            fpi = fopen(argv[++i], "rb");
        }
        else if(!_stricmp(argv[i], "-o"))
        {
            fpo = fopen(argv[++i], "wb");
        }
        else if(!_stricmp(argv[i], "-w"))
        {
            nWidth = atoi(argv[++i]);
        }
        else if(!_stricmp(argv[i], "-h"))
        {
            nHeight = atoi(argv[++i]);
        }
        else if(!_stricmp(argv[i], "-f"))
        {
            nFrames = atoi(argv[++i]);
        }
    }

    int ret = 0;

    // Validate parameters
    if(nWidth == 0 || nWidth > MAX_WIDTH ||
       nHeight == 0 || nHeight > MAX_HEIGHT ||
       fpi == NULL || fpo == NULL)
    {
        fprintf(stderr, "Parameters check failed\n");
        ret = -1;
        goto _cleanup;
    }

    // Unit Tests
#if TEST_xConvInputFmt
    {
        int i, j;
        uint8_t tmp[32*16+2*32*16/4];
        memset(tmp, 0xCC, sizeof(tmp));

        for(i = 0; i < 32*16+2*32*16/4; i++)
        {
            tmp[i] = i;
        }

        ref_block_t blocks[2];
        memset(blocks, 0xCD, sizeof(blocks));

        xConvInputFmt(blocks, &tmp[0], 32, &tmp[256], &tmp[320], 16, 32, 16);
        printf("xConvFmt Done\n");
    }
#endif

    // Encode

    // Prepare input frame

    // Cleanup
_cleanup:
    if(fpi)
        fclose(fpi);
    if(fpo)
        fclose(fpo);

    return ret;
}

<commit_msg>[x266] xConvOutput420 for convert internal YUV420SP into YUV420<commit_after>/*****************************************************************************
 * x266.cpp: WC Encoder Functions
 *****************************************************************************
 * Copyright (C) 2015-2020 x266 project
 *
 * Authors: Min Chen <chenm003@163.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
 *
 * This program is also available under a commercial proprietary license.
 * For more information, contact us at chenm003@163.com.
 *****************************************************************************/

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <assert.h>

 /*****************************************************************************
 *****************************************************************************/
#define MAX_WIDTH           (4096)
#define MAX_HEIGHT          (2048)
#define REF_BLOCK_SZ        (16)
#define REF_FRAME_STRD      (MAX_WIDTH / REF_BLOCK_SZ)

// Thanks to https://gist.github.com/PhilCK/1534763
#ifdef __GNUC__
#define PACKED( class_to_pack ) class_to_pack __attribute__((__packed__))
#else
#define PACKED( class_to_pack ) __pragma( pack(push, 1) ) class_to_pack __pragma( pack(pop) )
#endif

#define ASIZE(x)            (sizeof(x) / sizeof((x)[0]))

/*****************************************************************************
 *****************************************************************************/

PACKED(struct _ref_block_t
{
    // REF_BLOCK_SZ=16
    uint8_t     m_Y[16*16];         // 256 bytes - Y
    uint8_t     m_C[2*8*8];         // 128 bytes - UV
    uint8_t     m_I[128];           // 128 bytes - Info
});
typedef struct _ref_block_t ref_block_t;

typedef struct _codec_t
{
    ref_block_t    *m_frames[3];            // [0]=Cur, [1..N]=References
    intptr_t        m_frames_strd;
} codec_t;

/*****************************************************************************
 *****************************************************************************/
void xConvInputFmt(ref_block_t     *pBlock,
                   const uint8_t   *inpY,
                   const intptr_t   strdY,
                   const uint8_t   *inpU,
                   const uint8_t   *inpV,
                   const intptr_t   strdC,
                   const int        width,
                   const int        height)
{
    assert(!(width % REF_BLOCK_SZ) && "width is not multiple of 16");
    assert(!(height % REF_BLOCK_SZ) && "height is not multiple of 16");

    int i, j, x, y;
    for(y = 0; y < height; y += REF_BLOCK_SZ)
    {
        for(x = 0; x < width; x += REF_BLOCK_SZ)
        {
            // Y
            for(i = 0; i < REF_BLOCK_SZ; i++)
            {
                memcpy(&pBlock->m_Y[i * REF_BLOCK_SZ],
                       &inpY[(y+i)*strdY + x],
                       REF_BLOCK_SZ*sizeof(uint8_t));
            }

            // UV - 420SP
            for(i = 0; i < REF_BLOCK_SZ/2; i++)
            {
                for(j = 0; j < REF_BLOCK_SZ/2; j++)
                {
                    pBlock->m_C[i*REF_BLOCK_SZ + j*2 + 0] = inpU[((y>>1)+i)*strdC + ((x>>1)+j)];
                    pBlock->m_C[i*REF_BLOCK_SZ + j*2 + 1] = inpV[((y>>1)+i)*strdC + ((x>>1)+j)];
                }
            }
            pBlock++;
        }
    }
}

void xConvOutput420(const ref_block_t  *pBlock,
                    uint8_t            *outY,
                    const intptr_t      strdY,
                    uint8_t            *outU,
                    uint8_t            *outV,
                    intptr_t            strdC,
                    const int           width,
                    const int           height)
{
    assert(!(width % REF_BLOCK_SZ) && "width is not multiple of 16");
    assert(!(height % REF_BLOCK_SZ) && "height is not multiple of 16");

    int i, j, x, y;
    for(y = 0; y < height; y += REF_BLOCK_SZ)
    {
        for(x = 0; x < width; x += REF_BLOCK_SZ)
        {
            // Y
            for(i = 0; i < REF_BLOCK_SZ; i++)
            {
                memcpy(&outY[(y+i)*strdY + x],
                       &pBlock->m_Y[i * REF_BLOCK_SZ],
                       REF_BLOCK_SZ*sizeof(uint8_t));
            }

            // UV - 420SP
            for(i = 0; i < REF_BLOCK_SZ/2; i++)
            {
                for(j = 0; j < REF_BLOCK_SZ/2; j++)
                {
                    outU[((y>>1)+i)*strdC + ((x>>1)+j)] = pBlock->m_C[i*REF_BLOCK_SZ + j*2 + 0];
                    outV[((y>>1)+i)*strdC + ((x>>1)+j)] = pBlock->m_C[i*REF_BLOCK_SZ + j*2 + 1];
                }
            }
            pBlock++;
        }
    }
}

 /*****************************************************************************
 *****************************************************************************/
int main(int argc, char *argv[])
{
    if(argc < 5)
    {
        fprintf(stderr, "Usage: %s -i in_file -o out_file -w width -h height -f frames\n", argv[0]);
        return 0;
    }

    // Encoder parameters
    FILE *fpi = NULL;
    FILE *fpo = NULL;
    uint32_t nWidth = 0;
    uint32_t nHeight = 0;
    int nFrames = 0;
    uint8_t *frameBuf = NULL;

    int i;
    for(i = 1; i < argc; i++)
    {
        if(!_stricmp(argv[i], "-i"))
        {
            fpi = fopen(argv[++i], "rb");
        }
        else if(!_stricmp(argv[i], "-o"))
        {
            fpo = fopen(argv[++i], "wb");
        }
        else if(!_stricmp(argv[i], "-w"))
        {
            nWidth = atoi(argv[++i]);
        }
        else if(!_stricmp(argv[i], "-h"))
        {
            nHeight = atoi(argv[++i]);
        }
        else if(!_stricmp(argv[i], "-f"))
        {
            nFrames = atoi(argv[++i]);
        }
    }

    int ret = 0;

    // Validate parameters
    if(nWidth == 0 || nWidth > MAX_WIDTH ||
       nHeight == 0 || nHeight > MAX_HEIGHT ||
       fpi == NULL || fpo == NULL)
    {
        fprintf(stderr, "Parameters check failed\n");
        ret = -1;
        goto _cleanup;
    }

    // Unit Tests
#if TEST_xConvInputFmt
    {
        int i, j;
        uint8_t tmp[32*16+2*32*16/4];
        memset(tmp, 0xCC, sizeof(tmp));

        for(i = 0; i < 32*16+2*32*16/4; i++)
        {
            tmp[i] = i;
        }

        ref_block_t blocks[2];
        memset(blocks, 0xCD, sizeof(blocks));

        xConvInputFmt(blocks, &tmp[0], 32, &tmp[256], &tmp[320], 16, 32, 16);
        printf("xConvFmt Done\n");
    }
#endif

    // Initialize codec
    const uint32_t frameSize = nWidth * nHeight * 3 / 2;
    frameBuf = (uint8_t*)_aligned_malloc(frameSize * sizeof(uint8_t), 4096);
    assert(frameBuf && "Memory allocate failed\n");

    codec_t codec;
    memset(&codec, 0, sizeof(codec));

    codec.m_frames_strd = nWidth / REF_BLOCK_SZ;
    for(i = 0; i < ASIZE(codec.m_frames); i++)
    {
        codec.m_frames[i] = (ref_block_t *)_aligned_malloc(nWidth * nHeight / (REF_BLOCK_SZ * REF_BLOCK_SZ) * sizeof(ref_block_t), 4096);
    }

    // Encode loop
    for(i = 0; i < nFrames; i++)
    {
        // Prepare input frame
        if(frameSize != fread(frameBuf, 1, frameSize, fpi))
        {
            fprintf(stderr, "Read file failed\n");
            goto _cleanup;
        }

        xConvInputFmt(codec.m_frames[0],
                      frameBuf,
                      nWidth,
                      frameBuf + nWidth * nHeight,
                      frameBuf + nWidth * nHeight * 5 / 4,
                      nWidth / 2,
                      nWidth,
                      nHeight);

        // for test only
        memset(frameBuf, 0xCD, nWidth * nHeight * 3 / 2 * sizeof(uint8_t));
        xConvOutput420(codec.m_frames[0],
                       frameBuf,
                       nWidth,
                       frameBuf + nWidth * nHeight,
                       frameBuf + nWidth * nHeight * 5 / 4,
                       nWidth / 2,
                       nWidth,
                       nHeight);

        fwrite(frameBuf, 1, frameSize, fpo);
    }
    printf("Encode %d frames done\n", i);

    // Cleanup
_cleanup:
    if(fpi)
        fclose(fpi);
    if(fpo)
        fclose(fpo);
    if(frameBuf)
        _aligned_free(frameBuf);

    for(i = 0; i < ASIZE(codec.m_frames); i++)
    {
        if(codec.m_frames[i])
            _aligned_free((codec.m_frames[i]));
    }

    return ret;
}

<|endoftext|>


<commit_before>#include "pstream.hh"

#include <string.h>

static void
streamnum (print_stream *s, unsigned long long num,
           bool neg = false, unsigned base = 10, int width = 0, char pad = 0,
           bool alt = false)
{
  char buf[68], *x = buf + sizeof(buf);

  if (num == 0)
    *--x = '0';
  else {
    for (; num; num /= base)
      *--x = "0123456789abcdef"[num % base];
    if (alt) {
      if (base == 16 && pad != '0') {
        *--x = 'x';
        *--x = '0';
      } else if (base == 8) {
        *--x = '0';
      }
    }
    if (neg)
      *--x = '-';
  }

  size_t len = buf + sizeof(buf) - x;

  if (alt && base == 16 && pad == '0') {
    // Special case.  Otherwise, this would print like 0000x1
    to_stream(s, "0x");
    if (width >= 2)
      width -= 2;
  }

  for (; width > len; width--)
    to_stream(s, pad);
  to_stream(s, sbuf(x, len));
  for (; width < 0; width++)
    to_stream(s, pad);
}

#define INT_TO_STREAM(typ)                              \
  void to_stream(print_stream *s, unsigned typ v)       \
  {                                                     \
    streamnum(s, v);                                    \
  }                                                     \
                                                        \
  void to_stream(print_stream *s, typ v)                \
  {                                                     \
    if (v < 0)                                          \
      streamnum(s, -v, true);                           \
    else                                                \
      streamnum(s, v, false);                           \
  }                                                     \
  static_assert(true, "need a semicolon")

INT_TO_STREAM(int);
INT_TO_STREAM(long);
INT_TO_STREAM(long long);

void to_stream(print_stream *s, const char *str)
{
  to_stream(s, sbuf(str, strlen(str)));
}

void to_stream(print_stream *s, void *ptr)
{
  to_stream(s, sbuf("0x", 2));
  streamnum(s, (unsigned long long)ptr, false, 16);
}

void to_stream(print_stream *s, const integer_formatter &n)
{
  streamnum(s, n.val_, n.neg_, n.base_, n.width_, n.pad_, n.alt_);
}

void to_stream(print_stream *s, const sflags &f)
{
  unsigned long long rem = f.val_;
  bool first = true;
  for (auto &flag : f.flags_) {
    if ((f.val_ & flag.mask_) == flag.test_) {
      if (!first)
        to_stream(s, '|');
      to_stream(s, flag.name_);
      rem &= ~flag.mask_;
      first = false;
    }
  }
  if (rem) {
    if (!first)
      to_stream(s, '|');
    to_stream(s, shex(rem));
  }
}

void to_stream(print_stream *s, const senum &f)
{
  unsigned long long cur = ~0;
  for (auto &value : f.values_) {
    if (value.next_)
      cur++;
    else
      cur = value.value_;
    if (f.val_ == cur) {
      to_stream(s, value.name_);
      return;
    }
  }
  to_stream(s, f.val_);
}

void to_stream(print_stream *s, const shexdump &f)
{
  // Compute common prefix of all addresses
  uintptr_t addr = f.start_;
  uintptr_t end_addr = f.start_ + f.len_;
  int common = 0;
  while (addr != end_addr) {
    common += 8;
    addr >>= 8;
    end_addr >>= 8;
  }

  // Print the prefix just once (otherwise 64-bit addresses cause
  // lines to exceed 80 columns)
  if (addr)
    s->print(shex(addr << common), "+\n");

  // Compute width of distinct suffix
  uintptr_t mask = (1ull << common) - 1;
  int width = common / 4;

  // Round down starting address
  addr = f.start_ & ~15;
  const uint8_t *p = (const uint8_t*)f.base_ - (f.start_ - addr);

  // Round up ending address
  end_addr = ((f.start_ + f.len_) | 15) + 1;

  // Hex dump
  char ascii[16];
  for (; addr < end_addr; addr++, p++) {
    if (addr % 16 == 0)
      s->print(sfmt(addr & mask).base(16).width(width).pad(), ": ");

    if (addr < f.start_ || addr >= f.start_ + f.len_) {
      to_stream(s, "  ");
      ascii[addr % 16] = ' ';
    } else {
      to_stream(s, sfmt(*p).base(16).width(2).pad());
      if (*p < ' ' || *p > '~')
        ascii[addr % 16] = '.';
      else
        ascii[addr % 16] = *p;
    }

    if (addr % 16 == 15)
      s->print("  ", sbuf(ascii, sizeof ascii), '\n');
    else if (addr % 16 == 7)
      to_stream(s, "  ");
    else
      to_stream(s, ' ');
  }
}
<commit_msg>pstream: Compute hexdump prefix in nibbles rather than bytes<commit_after>#include "pstream.hh"

#include <string.h>

static void
streamnum (print_stream *s, unsigned long long num,
           bool neg = false, unsigned base = 10, int width = 0, char pad = 0,
           bool alt = false)
{
  char buf[68], *x = buf + sizeof(buf);

  if (num == 0)
    *--x = '0';
  else {
    for (; num; num /= base)
      *--x = "0123456789abcdef"[num % base];
    if (alt) {
      if (base == 16 && pad != '0') {
        *--x = 'x';
        *--x = '0';
      } else if (base == 8) {
        *--x = '0';
      }
    }
    if (neg)
      *--x = '-';
  }

  size_t len = buf + sizeof(buf) - x;

  if (alt && base == 16 && pad == '0') {
    // Special case.  Otherwise, this would print like 0000x1
    to_stream(s, "0x");
    if (width >= 2)
      width -= 2;
  }

  for (; width > len; width--)
    to_stream(s, pad);
  to_stream(s, sbuf(x, len));
  for (; width < 0; width++)
    to_stream(s, pad);
}

#define INT_TO_STREAM(typ)                              \
  void to_stream(print_stream *s, unsigned typ v)       \
  {                                                     \
    streamnum(s, v);                                    \
  }                                                     \
                                                        \
  void to_stream(print_stream *s, typ v)                \
  {                                                     \
    if (v < 0)                                          \
      streamnum(s, -v, true);                           \
    else                                                \
      streamnum(s, v, false);                           \
  }                                                     \
  static_assert(true, "need a semicolon")

INT_TO_STREAM(int);
INT_TO_STREAM(long);
INT_TO_STREAM(long long);

void to_stream(print_stream *s, const char *str)
{
  to_stream(s, sbuf(str, strlen(str)));
}

void to_stream(print_stream *s, void *ptr)
{
  to_stream(s, sbuf("0x", 2));
  streamnum(s, (unsigned long long)ptr, false, 16);
}

void to_stream(print_stream *s, const integer_formatter &n)
{
  streamnum(s, n.val_, n.neg_, n.base_, n.width_, n.pad_, n.alt_);
}

void to_stream(print_stream *s, const sflags &f)
{
  unsigned long long rem = f.val_;
  bool first = true;
  for (auto &flag : f.flags_) {
    if ((f.val_ & flag.mask_) == flag.test_) {
      if (!first)
        to_stream(s, '|');
      to_stream(s, flag.name_);
      rem &= ~flag.mask_;
      first = false;
    }
  }
  if (rem) {
    if (!first)
      to_stream(s, '|');
    to_stream(s, shex(rem));
  }
}

void to_stream(print_stream *s, const senum &f)
{
  unsigned long long cur = ~0;
  for (auto &value : f.values_) {
    if (value.next_)
      cur++;
    else
      cur = value.value_;
    if (f.val_ == cur) {
      to_stream(s, value.name_);
      return;
    }
  }
  to_stream(s, f.val_);
}

void to_stream(print_stream *s, const shexdump &f)
{
  // Compute common prefix of all addresses
  uintptr_t addr = f.start_;
  uintptr_t end_addr = f.start_ + f.len_;
  int common = 0;
  while (addr != end_addr) {
    common += 4;
    addr >>= 4;
    end_addr >>= 4;
  }

  // Print the prefix just once (otherwise 64-bit addresses cause
  // lines to exceed 80 columns)
  if (addr)
    s->print(shex(addr << common), "+\n");

  // Compute width of distinct suffix
  uintptr_t mask = (1ull << common) - 1;
  int width = common / 4;

  // Round down starting address
  addr = f.start_ & ~15;
  const uint8_t *p = (const uint8_t*)f.base_ - (f.start_ - addr);

  // Round up ending address
  end_addr = ((f.start_ + f.len_) | 15) + 1;

  // Hex dump
  char ascii[16];
  for (; addr < end_addr; addr++, p++) {
    if (addr % 16 == 0)
      s->print(sfmt(addr & mask).base(16).width(width).pad(), ": ");

    if (addr < f.start_ || addr >= f.start_ + f.len_) {
      to_stream(s, "  ");
      ascii[addr % 16] = ' ';
    } else {
      to_stream(s, sfmt(*p).base(16).width(2).pad());
      if (*p < ' ' || *p > '~')
        ascii[addr % 16] = '.';
      else
        ascii[addr % 16] = *p;
    }

    if (addr % 16 == 15)
      s->print("  ", sbuf(ascii, sizeof ascii), '\n');
    else if (addr % 16 == 7)
      to_stream(s, "  ");
    else
      to_stream(s, ' ');
  }
}
<|endoftext|>


<commit_before>#include "swrd.hpp"
#include "../parser/swrdParser.hpp"
#include <fstream>
#include "flex.hpp"

namespace wrd {

    WRD_DEF_ME(sinterpreter)

    tstr<sobj> me::interp(const wchar* script) {
        YY_BUFFER_STATE buffer = yy_scan_string(script);
        tstr<sobj> ret = _runParser();
        yy_delete_buffer(buffer);
        return ret;
    }
    tstr<sobj> me::interp(const std::string& script) {
        return interp(script.c_str());
    }
    tstr<sobj> me::interpFile(const wchar* path) {
        yyin = fopen(path, "r");
        if(!yyin)
            return WRD_E("invalid file path %s.", path), tstr<sobj>();

        std::string fileName = _extractFileName(path);
        WRD_I("interpreting file '%s'...", fileName.c_str());

        tstr<sobj> ret = _runParser();

        ret->setName(fileName);
        fclose(yyin);
        WRD_I("%s swrd file interpreted.", fileName.c_str());
        return ret;
    }
    tstr<sobj> me::interpFile(const std::string& path) {
        return interpFile(path.c_str());
    }

    tstr<sobj> me::_runParser() {
        int res = yyparse();
        if(res)
            return WRD_E("interpretion has been failed. res=%d", res), tstr<sobj>();
        if(!root)
            WRD_E("nothing interpreted.");

        return tstr<sobj>(root);
    }

    std::string me::_extractFileName(const std::string& path) {
        size_t atSlash = path.find_last_of("\\/");
        if(atSlash < 0) return "";

        return path.substr(atSlash + 1);
    }
}
<commit_msg>swrd: fix: couldn't interpreter file after reading a buffer<commit_after>#include "swrd.hpp"
#include "../parser/swrdParser.hpp"
#include <fstream>
#include "flex.hpp"

void yyrestart(FILE*);

namespace wrd {

    WRD_DEF_ME(sinterpreter)

    tstr<sobj> me::interp(const wchar* script) {
        YY_BUFFER_STATE buffer = yy_scan_string(script);
        tstr<sobj> ret = _runParser();
        yy_delete_buffer(buffer);
        return ret;
    }
    tstr<sobj> me::interp(const std::string& script) {
        return interp(script.c_str());
    }
    tstr<sobj> me::interpFile(const wchar* path) {
        yyin = fopen(path, "r");
        yyrestart(yyin);
        if(!yyin)
            return WRD_E("invalid file path %s.", path), tstr<sobj>();

        std::string fileName = _extractFileName(path);
        WRD_I("interpreting file '%s'...", fileName.c_str());

        tstr<sobj> ret = _runParser();

        ret->setName(fileName);
        fclose(yyin);
        WRD_I("%s swrd file interpreted.", fileName.c_str());
        return ret;
    }
    tstr<sobj> me::interpFile(const std::string& path) {
        return interpFile(path.c_str());
    }

    tstr<sobj> me::_runParser() {
        int res = yyparse();
        if(res)
            return WRD_E("interpretion has been failed. res=%d", res), tstr<sobj>();
        if(!root)
            WRD_E("nothing interpreted.");

        return tstr<sobj>(root);
    }

    std::string me::_extractFileName(const std::string& path) {
        size_t atSlash = path.find_last_of("\\/");
        if(atSlash < 0) return "";

        return path.substr(atSlash + 1);
    }
}
<|endoftext|>


<commit_before>/*
 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "config.h"
#include "FocusController.h"

#include "AXObjectCache.h"
#include "Chrome.h"
#include "Document.h"
#include "Editor.h"
#include "EditorClient.h"
#include "Element.h"
#include "Event.h"
#include "EventHandler.h"
#include "EventNames.h"
#include "Frame.h"
#include "FrameView.h"
#include "FrameTree.h"
#include "HTMLFrameOwnerElement.h"
#include "HTMLNames.h"
#include "KeyboardEvent.h"
#include "Page.h"
#include "Range.h"
#include "RenderObject.h"
#include "RenderWidget.h"
#include "SelectionController.h"
#include "Widget.h"
#include <wtf/Platform.h>

namespace WebCore {

using namespace EventNames;
using namespace HTMLNames;

FocusController::FocusController(Page* page)
    : m_page(page)
    , m_isActive(false)
{
}

void FocusController::setFocusedFrame(PassRefPtr<Frame> frame)
{
    if (m_focusedFrame == frame)
        return;

    if (m_focusedFrame && m_focusedFrame->view())
        m_focusedFrame->selection()->setFocused(false);

    m_focusedFrame = frame;

    if (m_focusedFrame m_focusedFrame->view())
        m_focusedFrame->selection()->setFocused(true);
}

Frame* FocusController::focusedOrMainFrame()
{
    if (Frame* frame = focusedFrame())
        return frame;
    return m_page->mainFrame();
}

static Node* deepFocusableNode(FocusDirection direction, Node* node, KeyboardEvent* event)
{
    // The node we found might be a HTMLFrameOwnerElement, so descend down the frame tree until we find either:
    // 1) a focusable node, or
    // 2) the deepest-nested HTMLFrameOwnerElement
    while (node && node->isFrameOwnerElement()) {
        HTMLFrameOwnerElement* owner = static_cast<HTMLFrameOwnerElement*>(node);
        if (!owner->contentFrame())
            break;

        Document* document = owner->contentFrame()->document();
        if (!document)
            break;

        node = (direction == FocusDirectionForward)
            ? document->nextFocusableNode(0, event)
            : document->previousFocusableNode(0, event);
        if (!node) {
            node = owner;
            break;
        }
    }

    return node;
}

bool FocusController::setInitialFocus(FocusDirection direction, KeyboardEvent* event)
{
    return advanceFocus(direction, event, true);
}

bool FocusController::advanceFocus(FocusDirection direction, KeyboardEvent* event, bool initialFocus)
{
    Frame* frame = focusedOrMainFrame();
    ASSERT(frame);
    Document* document = frame->document();
    if (!document)
        return false;

    Node* node = (direction == FocusDirectionForward)
        ? document->nextFocusableNode(document->focusedNode(), event)
        : document->previousFocusableNode(document->focusedNode(), event);

    // If there's no focusable node to advance to, move up the frame tree until we find one.
    while (!node && frame) {
        Frame* parentFrame = frame->tree()->parent();
        if (!parentFrame)
            break;

        Document* parentDocument = parentFrame->document();
        if (!parentDocument)
            break;

        HTMLFrameOwnerElement* owner = frame->ownerElement();
        if (!owner)
            break;

        node = (direction == FocusDirectionForward)
            ? parentDocument->nextFocusableNode(owner, event)
            : parentDocument->previousFocusableNode(owner, event);

        frame = parentFrame;
    }

    node = deepFocusableNode(direction, node, event);

    if (!node) {
        // We didn't find a node to focus, so we should try to pass focus to Chrome.
        if (!initialFocus && m_page->chrome()->canTakeFocus(direction)) {
            document->setFocusedNode(0);
            setFocusedFrame(0);
            m_page->chrome()->takeFocus(direction);
            return true;
        }

        // Chrome doesn't want focus, so we should wrap focus.
        if (Document* d = m_page->mainFrame()->document())
            node = (direction == FocusDirectionForward)
                ? d->nextFocusableNode(0, event)
                : d->previousFocusableNode(0, event);

        node = deepFocusableNode(direction, node, event);

        if (!node)
            return false;
    }

    ASSERT(node);

    if (node == document->focusedNode())
        // Focus wrapped around to the same node.
        return true;

    if (!node->isElementNode())
        // FIXME: May need a way to focus a document here.
        return false;

    if (node->isFrameOwnerElement()) {
        // We focus frames rather than frame owners.
        // FIXME: We should not focus frames that have no scrollbars, as focusing them isn't useful to the user.
        HTMLFrameOwnerElement* owner = static_cast<HTMLFrameOwnerElement*>(node);
        if (!owner->contentFrame())
            return false;

        document->setFocusedNode(0);
        setFocusedFrame(owner->contentFrame());
        return true;
    }

    // FIXME: It would be nice to just be able to call setFocusedNode(node) here, but we can't do
    // that because some elements (e.g. HTMLInputElement and HTMLTextAreaElement) do extra work in
    // their focus() methods.

    Document* newDocument = node->document();

    if (newDocument != document)
        // Focus is going away from this document, so clear the focused node.
        document->setFocusedNode(0);

    if (newDocument)
        setFocusedFrame(newDocument->frame());

    static_cast<Element*>(node)->focus(false);
    return true;
}

static bool relinquishesEditingFocus(Node *node)
{
    ASSERT(node);
    ASSERT(node->isContentEditable());

    Node* root = node->rootEditableElement();
    Frame* frame = node->document()->frame();
    if (!frame || !root)
        return false;

    return frame->editor()->shouldEndEditing(rangeOfContents(root).get());
}

static void clearSelectionIfNeeded(Frame* oldFocusedFrame, Frame* newFocusedFrame, Node* newFocusedNode)
{
    if (!oldFocusedFrame || !newFocusedFrame)
        return;

    if (oldFocusedFrame->document() != newFocusedFrame->document())
        return;

    SelectionController* s = oldFocusedFrame->selection();
    if (s->isNone())
        return;

    Node* selectionStartNode = s->selection().start().node();
    if (selectionStartNode == newFocusedNode || selectionStartNode->isDescendantOf(newFocusedNode) || selectionStartNode->shadowAncestorNode() == newFocusedNode)
        return;

    if (Node* mousePressNode = newFocusedFrame->eventHandler()->mousePressNode())
        if (mousePressNode->renderer() && !mousePressNode->canStartSelection())
            if (Node* root = s->rootEditableElement())
                if (Node* shadowAncestorNode = root->shadowAncestorNode())
                    // Don't do this for textareas and text fields, when they lose focus their selections should be cleared
                    // and then restored when they regain focus, to match other browsers.
                    if (!shadowAncestorNode->hasTagName(inputTag) && !shadowAncestorNode->hasTagName(textareaTag))
                        return;

    s->clear();
}

bool FocusController::setFocusedNode(Node* node, PassRefPtr<Frame> newFocusedFrame)
{
    RefPtr<Frame> oldFocusedFrame = focusedFrame();
    RefPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame->document() : 0;

    Node* oldFocusedNode = oldDocument ? oldDocument->focusedNode() : 0;
    if (oldFocusedNode == node)
        return true;

    if (oldFocusedNode && oldFocusedNode->rootEditableElement() == oldFocusedNode && !relinquishesEditingFocus(oldFocusedNode))
        return false;

    clearSelectionIfNeeded(oldFocusedFrame.get(), newFocusedFrame.get(), node);

    if (!node) {
        if (oldDocument)
            oldDocument->setFocusedNode(0);
        m_page->editorClient()->setInputMethodState(false);
        return true;
    }

    RefPtr<Document> newDocument = node ? node->document() : 0;

    if (newDocument && newDocument->focusedNode() == node) {
        m_page->editorClient()->setInputMethodState(node->shouldUseInputMethod());
        return true;
    }

    if (oldDocument && oldDocument != newDocument)
        oldDocument->setFocusedNode(0);

    setFocusedFrame(newFocusedFrame);

    if (newDocument)
        newDocument->setFocusedNode(node);

    m_page->editorClient()->setInputMethodState(node->shouldUseInputMethod());

    return true;
}

void FocusController::setActive(bool active)
{
    if (m_isActive == active)
        return;

    m_isActive = active;

    // FIXME: It would be nice to make Mac use this implementation someday.
    // Right now Mac calls updateControlTints from within WebKit, and moving
    // the call to here is not simple.
#if !PLATFORM(MAC) && !PLATFORM(WX)
    if (FrameView* view = m_page->mainFrame()->view()) {
        view->layoutIfNeededRecursive();
        view->updateControlTints();
    }
#endif

    focusedOrMainFrame()->selection()->pageActivationChanged();
}

} // namespace WebCore
<commit_msg><commit_after>/*
 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "config.h"
#include "FocusController.h"

#include "AXObjectCache.h"
#include "Chrome.h"
#include "Document.h"
#include "Editor.h"
#include "EditorClient.h"
#include "Element.h"
#include "Event.h"
#include "EventHandler.h"
#include "EventNames.h"
#include "Frame.h"
#include "FrameView.h"
#include "FrameTree.h"
#include "HTMLFrameOwnerElement.h"
#include "HTMLNames.h"
#include "KeyboardEvent.h"
#include "Page.h"
#include "Range.h"
#include "RenderObject.h"
#include "RenderWidget.h"
#include "SelectionController.h"
#include "Widget.h"
#include <wtf/Platform.h>

namespace WebCore {

using namespace EventNames;
using namespace HTMLNames;

FocusController::FocusController(Page* page)
    : m_page(page)
    , m_isActive(false)
{
}

void FocusController::setFocusedFrame(PassRefPtr<Frame> frame)
{
    if (m_focusedFrame == frame)
        return;

    if (m_focusedFrame && m_focusedFrame->view())
        m_focusedFrame->selection()->setFocused(false);

    m_focusedFrame = frame;

    if (m_focusedFrame && m_focusedFrame->view())
        m_focusedFrame->selection()->setFocused(true);
}

Frame* FocusController::focusedOrMainFrame()
{
    if (Frame* frame = focusedFrame())
        return frame;
    return m_page->mainFrame();
}

static Node* deepFocusableNode(FocusDirection direction, Node* node, KeyboardEvent* event)
{
    // The node we found might be a HTMLFrameOwnerElement, so descend down the frame tree until we find either:
    // 1) a focusable node, or
    // 2) the deepest-nested HTMLFrameOwnerElement
    while (node && node->isFrameOwnerElement()) {
        HTMLFrameOwnerElement* owner = static_cast<HTMLFrameOwnerElement*>(node);
        if (!owner->contentFrame())
            break;

        Document* document = owner->contentFrame()->document();
        if (!document)
            break;

        node = (direction == FocusDirectionForward)
            ? document->nextFocusableNode(0, event)
            : document->previousFocusableNode(0, event);
        if (!node) {
            node = owner;
            break;
        }
    }

    return node;
}

bool FocusController::setInitialFocus(FocusDirection direction, KeyboardEvent* event)
{
    return advanceFocus(direction, event, true);
}

bool FocusController::advanceFocus(FocusDirection direction, KeyboardEvent* event, bool initialFocus)
{
    Frame* frame = focusedOrMainFrame();
    ASSERT(frame);
    Document* document = frame->document();
    if (!document)
        return false;

    Node* node = (direction == FocusDirectionForward)
        ? document->nextFocusableNode(document->focusedNode(), event)
        : document->previousFocusableNode(document->focusedNode(), event);

    // If there's no focusable node to advance to, move up the frame tree until we find one.
    while (!node && frame) {
        Frame* parentFrame = frame->tree()->parent();
        if (!parentFrame)
            break;

        Document* parentDocument = parentFrame->document();
        if (!parentDocument)
            break;

        HTMLFrameOwnerElement* owner = frame->ownerElement();
        if (!owner)
            break;

        node = (direction == FocusDirectionForward)
            ? parentDocument->nextFocusableNode(owner, event)
            : parentDocument->previousFocusableNode(owner, event);

        frame = parentFrame;
    }

    node = deepFocusableNode(direction, node, event);

    if (!node) {
        // We didn't find a node to focus, so we should try to pass focus to Chrome.
        if (!initialFocus && m_page->chrome()->canTakeFocus(direction)) {
            document->setFocusedNode(0);
            setFocusedFrame(0);
            m_page->chrome()->takeFocus(direction);
            return true;
        }

        // Chrome doesn't want focus, so we should wrap focus.
        if (Document* d = m_page->mainFrame()->document())
            node = (direction == FocusDirectionForward)
                ? d->nextFocusableNode(0, event)
                : d->previousFocusableNode(0, event);

        node = deepFocusableNode(direction, node, event);

        if (!node)
            return false;
    }

    ASSERT(node);

    if (node == document->focusedNode())
        // Focus wrapped around to the same node.
        return true;

    if (!node->isElementNode())
        // FIXME: May need a way to focus a document here.
        return false;

    if (node->isFrameOwnerElement()) {
        // We focus frames rather than frame owners.
        // FIXME: We should not focus frames that have no scrollbars, as focusing them isn't useful to the user.
        HTMLFrameOwnerElement* owner = static_cast<HTMLFrameOwnerElement*>(node);
        if (!owner->contentFrame())
            return false;

        document->setFocusedNode(0);
        setFocusedFrame(owner->contentFrame());
        return true;
    }

    // FIXME: It would be nice to just be able to call setFocusedNode(node) here, but we can't do
    // that because some elements (e.g. HTMLInputElement and HTMLTextAreaElement) do extra work in
    // their focus() methods.

    Document* newDocument = node->document();

    if (newDocument != document)
        // Focus is going away from this document, so clear the focused node.
        document->setFocusedNode(0);

    if (newDocument)
        setFocusedFrame(newDocument->frame());

    static_cast<Element*>(node)->focus(false);
    return true;
}

static bool relinquishesEditingFocus(Node *node)
{
    ASSERT(node);
    ASSERT(node->isContentEditable());

    Node* root = node->rootEditableElement();
    Frame* frame = node->document()->frame();
    if (!frame || !root)
        return false;

    return frame->editor()->shouldEndEditing(rangeOfContents(root).get());
}

static void clearSelectionIfNeeded(Frame* oldFocusedFrame, Frame* newFocusedFrame, Node* newFocusedNode)
{
    if (!oldFocusedFrame || !newFocusedFrame)
        return;

    if (oldFocusedFrame->document() != newFocusedFrame->document())
        return;

    SelectionController* s = oldFocusedFrame->selection();
    if (s->isNone())
        return;

    Node* selectionStartNode = s->selection().start().node();
    if (selectionStartNode == newFocusedNode || selectionStartNode->isDescendantOf(newFocusedNode) || selectionStartNode->shadowAncestorNode() == newFocusedNode)
        return;

    if (Node* mousePressNode = newFocusedFrame->eventHandler()->mousePressNode())
        if (mousePressNode->renderer() && !mousePressNode->canStartSelection())
            if (Node* root = s->rootEditableElement())
                if (Node* shadowAncestorNode = root->shadowAncestorNode())
                    // Don't do this for textareas and text fields, when they lose focus their selections should be cleared
                    // and then restored when they regain focus, to match other browsers.
                    if (!shadowAncestorNode->hasTagName(inputTag) && !shadowAncestorNode->hasTagName(textareaTag))
                        return;

    s->clear();
}

bool FocusController::setFocusedNode(Node* node, PassRefPtr<Frame> newFocusedFrame)
{
    RefPtr<Frame> oldFocusedFrame = focusedFrame();
    RefPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame->document() : 0;

    Node* oldFocusedNode = oldDocument ? oldDocument->focusedNode() : 0;
    if (oldFocusedNode == node)
        return true;

    if (oldFocusedNode && oldFocusedNode->rootEditableElement() == oldFocusedNode && !relinquishesEditingFocus(oldFocusedNode))
        return false;

    clearSelectionIfNeeded(oldFocusedFrame.get(), newFocusedFrame.get(), node);

    if (!node) {
        if (oldDocument)
            oldDocument->setFocusedNode(0);
        m_page->editorClient()->setInputMethodState(false);
        return true;
    }

    RefPtr<Document> newDocument = node ? node->document() : 0;

    if (newDocument && newDocument->focusedNode() == node) {
        m_page->editorClient()->setInputMethodState(node->shouldUseInputMethod());
        return true;
    }

    if (oldDocument && oldDocument != newDocument)
        oldDocument->setFocusedNode(0);

    setFocusedFrame(newFocusedFrame);

    if (newDocument)
        newDocument->setFocusedNode(node);

    m_page->editorClient()->setInputMethodState(node->shouldUseInputMethod());

    return true;
}

void FocusController::setActive(bool active)
{
    if (m_isActive == active)
        return;

    m_isActive = active;

    // FIXME: It would be nice to make Mac use this implementation someday.
    // Right now Mac calls updateControlTints from within WebKit, and moving
    // the call to here is not simple.
#if !PLATFORM(MAC) && !PLATFORM(WX)
    if (FrameView* view = m_page->mainFrame()->view()) {
        view->layoutIfNeededRecursive();
        view->updateControlTints();
    }
#endif

    focusedOrMainFrame()->selection()->pageActivationChanged();
}

} // namespace WebCore
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: ToolBarManager.hxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: rt $ $Date: 2008-03-12 11:42:56 $
 *
 *  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_TOOL_BAR_MANAGER_HXX
#define SD_TOOL_BAR_MANAGER_HXX

#include "ViewShell.hxx"
#include "ShellFactory.hxx"
#include <rtl/ustring.hxx>

#ifndef _COM_SUN_STAR_FRAME_XFRAME_HPP_
#include <com/sun/star/frame/XFrame.hpp>
#endif

#include <sal/types.h>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>

class SdrView;

namespace sd { namespace tools {
class EventMultiplexer;
} }

namespace sd {

class ViewShellBase;
class ViewShellManager;

/** Manage the set of visible tool bars (and object bars).  Usually they
    belong to the current view in the center pane.

    Tool bars are managed in groups.  Each group can be set, reset, or
    modified independently of the others.  This allows for instance to
    replace the toolbars associated with the current function independently
    from those assoicated with the main view.

    The ToolBarManager has two high level methods which contain the
    knowledge about which tool bars to show in a specific context.
    When the view in the center pane changes then MainViewShellChanged()
    sets up the tool bars for the new view.  On changes of the selection the
    SelectionHasChanged() method shows the tool bars for the new context.

    The update of the actually visible tool bars to the set currently
    required by the main view shell and its functions is divided into two
    parts, PreUpdate() and PostUpdate().  This are to be called before
    respectively after the update of the view shell stack.  The reason for
    this is to save time by not updating tool bars that will not be visible
    in a short time on a view shell switch.
*/
class ToolBarManager
    : public ::boost::enable_shared_from_this<ToolBarManager>
{
public:
    /** Use this method instead of the constructor to create new objects of
        this class.
    */
    static ::boost::shared_ptr<ToolBarManager> Create (
        ViewShellBase& rBase,
        tools::EventMultiplexer& rMultiplexer,
        ViewShellManager& rViewShellManager);

    ~ToolBarManager (void);

    /** Call this method prior to the destructor to prevent the
        ToolBarManager from accessing the ViewShellManager or the
        XLayoutManager when those are possibly not well and alive anymore
        (like during the destruction of the ViewShellBase.)
    */
    void Shutdown (void);

    /** When the view in the center pane changes then this method sets up
        the initial set of tool bars for the new view.
        The ToolBarManager listenes for view switching itself and then calls
        MainViewShellChanged().  Calling this method from the outside should
        not be necessary.
        @param nShellType
            The type of the new main view shell.
    */
    void MainViewShellChanged (ViewShell::ShellType nShellType);
    void MainViewShellChanged (const ViewShell& rMainViewShell);

    /** Call this method when the selection has changed to update the more
        temporary tool bars (those in the TBG_FUNCTION group.)
    */
    void SelectionHasChanged (
        const ViewShell& rViewShell,
        const SdrView& rView);

    /** The set of tool bars that are handled by this manager class.
    */
    const static ::rtl::OUString msToolBar;                  // RID_DRAW_TOOLBOX, 23011
                                                             // RID_GRAPHIC_TOOLBOX, 23025
    const static ::rtl::OUString msOptionsToolBar;           // RID_DRAW_OPTIONS_TOOLBOX, 23020
                                                             // RID_GRAPHIC_OPTIONS_TOOLBOX, 23026
    const static ::rtl::OUString msCommonTaskToolBar;        // RID_DRAW_COMMONTASK_TOOLBOX, 23021
    const static ::rtl::OUString msViewerToolBar;            // RID_DRAW_VIEWER_TOOLBOX, 23023
                                                             // RID_GRAPHIC_VIEWER_TOOLBOX, 23024
    const static ::rtl::OUString msSlideSorterToolBar;       // RID_SLIDE_TOOLBOX, 23012
    const static ::rtl::OUString msSlideSorterObjectBar;     // RID_SLIDE_OBJ_TOOLBOX, 23014
    const static ::rtl::OUString msOutlineToolBar;           // RID_OUTLINE_TOOLBOX, 23017
    const static ::rtl::OUString msMasterViewToolBar;        // SID_MASTERPAGE, 27053
    const static ::rtl::OUString msDrawingObjectToolBar;     // RID_DRAW_OBJ_TOOLBOX, 23013
    const static ::rtl::OUString msGluePointsToolBar;        // RID_GLUEPOINTS_TOOLBOX, 23019
    const static ::rtl::OUString msTextObjectBar;            // RID_DRAW_TEXT_TOOLBOX, 23016
                                                             // RID_GRAPHIC_TEXT_TOOLBOX, 23028
    const static ::rtl::OUString msBezierObjectBar;          // RID_BEZIER_TOOLBOX, 23015
    const static ::rtl::OUString msGraphicObjectBar;         // RID_DRAW_GRAF_TOOLBOX, 23030
    const static ::rtl::OUString msMediaObjectBar;           // RID_DRAW_MEDIA_TOOLBOX, 23031
    const static ::rtl::OUString msTableObjectBar;           // RID_DRAW_TABLE_TOOLBOX

    /** The set of tool bar groups.
    */
    enum ToolBarGroup {
        TBG__FIRST,

        TBG_PERMANENT = TBG__FIRST,
        TBG_FUNCTION,
        TBG_MASTER_MODE,

        TBG__LAST = TBG_MASTER_MODE
    };

    /** Only after calls with bValid=<TRUE/> may the tool bar manager use
        the frame::XLayoutManager to change the visible tool bars.  Call
        this method when the controller is attached to or detachted from the
        frame.  When called with <FALSE/> then ResetAllToolBars() is
        executed.
    */
    void SetValid (bool bValid);

    /** Reset the set of visible object bars in the specified group.  Tool
        bars in other groups are not affected.
        @param rParentShell
            When this shell is not the main view then the method returns
            immediately.
        @param eGroup
            Only the tool bars in this group are rest.
    */
    void ResetToolBars (ToolBarGroup eGroup);

    /** Reset all tool bars, regardless of the group they belong to.
        @param rParentShell
            When this shell is not the main view then the method returns
            immediately.
    */
    void ResetAllToolBars (void);

    /** Add the tool bar with the given name to the specified group of tool
        bars.
        @param rParentShell
            When this shell is not the main view then the method returns
            immediately.
        @param eGroup
            The new tool bar is added to this group.
        @param rsToolBarName
            The base name of the tool bar.  A proper prefix (like
            private:resource/toolbar/) is added.  The name may be one of the
            ones defined above.  Other names are allowed as well.
    */
    void AddToolBar (
        ToolBarGroup eGroup,
        const ::rtl::OUString& rsToolBarName);

    /** Add the tool bar shell to the shell stack.  This method basically
        forwards the call to the ViewShellManager.
        For some tool bar shells additional tool bars are made visible.
        @param rParentShell
            When this shell is not the main view then the method returns
            immediately.
        @param eGroup
            The group is used for the actual tool bars.
        @param nToolBarId
            Id of the tool bar shell.
    */
    void AddToolBarShell (
        ToolBarGroup eGroup,
        ShellId nToolBarId);

    /** Remove the tool bar with the given name from the specified group.
        If the tool bar is not visible then nothing happens.
        If the tool bar is a member of another group then nothing happens
        either.
    */
    void RemoveToolBar (
        ToolBarGroup eGroup,
        const ::rtl::OUString& rsToolBarName);

    void RemoveToolBarShell (
        ToolBarGroup eGroup,
        ShellId nToolBarId);

    /** This is basically a shortcut for ResetToolBars(),AddToolBar().  The
        main difference is, that all sub shells of the specified parent
        shell are deactivated as well.
        @param rParentShell
            When this shell is not the main view then the method returns
            immediately.
        @param eGroup
            The new tool bar is added to this group.
        @param rsToolBarName
            The base name of the tool bar.  A proper prefix (like
            private:resource/toolbar/) is added.  The name may be one of the
            ones defined above.  Other names are allowed as well.
    */
    void SetToolBar (
        ToolBarGroup eGroup,
        const ::rtl::OUString& rsToolBarName);

    /** This is basically a shortcut for ResetToolBars(),AddToolBar().  The
        main difference is, that all sub shells of the specified parent
        shell are deactivated as well.
        @param rParentShell
            When this shell is not the main view then the method returns
            immediately.
        @param rParentShell
            When this shell is not the main view then the method returns
            immediately.
        @param eGroup
            The group is currently not used.
        @param nToolBarId
            Id of the tool bar shell.
    */
    void SetToolBarShell (
        ToolBarGroup eGroup,
        ShellId nToolBarId);

    void PreUpdate (void);

    /** Request an update of the active tool bars.  The update is made
        asynchronously.
    */
    void RequestUpdate (void);

    /** This is a hint for the ToolBarManager to improve the performance
        when it updates its tool bars when its own lock is released.  Taking
        control of the release of the update lock of the ViewShellManager
        avoids some shell stack modifications and tool bar updates.
    */
    void LockViewShellManager (void);

    /** Use this class to prevent the visible tool bars from being updated
        (and thus causing repaints and GUI rearrangements) when several tool
        bar operations are made in a row.
    */
    class UpdateLock { public:
        UpdateLock(const ::boost::shared_ptr<ToolBarManager>& rpManager)
            : mpManager(rpManager) { mpManager->LockUpdate(); }
        ~UpdateLock(void) { mpManager->UnlockUpdate(); }
    private:
        ::boost::shared_ptr<ToolBarManager> mpManager;
    };
    friend class UpdateLock;

    /** Return whether updates of tool bars are locked.
    */
    bool IsUpdateLocked (void) const;

    void ToolBarsDestroyed(void);

private:
    class Implementation;
    ::boost::scoped_ptr<Implementation> mpImpl;

    /** The ViewShellBase is used to get the XLayoutManager and to determine
        the plug in mode.
    */
    ToolBarManager (void);

    void LockUpdate (void);
    void UnlockUpdate (void);
};

} // end of namespace sd

#endif
<commit_msg>INTEGRATION: CWS presenterview (1.4.20); FILE MERGED 2008/03/26 10:45:36 cl 1.4.20.3: RESYNC: (1.5-1.6); FILE MERGED 2007/07/11 09:05:56 af 1.4.20.2: RESYNC: (1.4-1.5); FILE MERGED 2007/07/10 14:27:27 af 1.4.20.1: #i18486# Converted several members of ViewShellBase to shared_ptrs.<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: ToolBarManager.hxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: kz $ $Date: 2008-04-03 13:58:08 $
 *
 *  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_TOOL_BAR_MANAGER_HXX
#define SD_TOOL_BAR_MANAGER_HXX

#include "ViewShell.hxx"
#include "ShellFactory.hxx"
#include <rtl/ustring.hxx>

#ifndef _COM_SUN_STAR_FRAME_XFRAME_HPP_
#include <com/sun/star/frame/XFrame.hpp>
#endif

#include <sal/types.h>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>

class SdrView;

namespace sd { namespace tools {
class EventMultiplexer;
} }

namespace sd {

class ViewShellBase;
class ViewShellManager;

/** Manage the set of visible tool bars (and object bars).  Usually they
    belong to the current view in the center pane.

    Tool bars are managed in groups.  Each group can be set, reset, or
    modified independently of the others.  This allows for instance to
    replace the toolbars associated with the current function independently
    from those assoicated with the main view.

    The ToolBarManager has two high level methods which contain the
    knowledge about which tool bars to show in a specific context.
    When the view in the center pane changes then MainViewShellChanged()
    sets up the tool bars for the new view.  On changes of the selection the
    SelectionHasChanged() method shows the tool bars for the new context.

    The update of the actually visible tool bars to the set currently
    required by the main view shell and its functions is divided into two
    parts, PreUpdate() and PostUpdate().  This are to be called before
    respectively after the update of the view shell stack.  The reason for
    this is to save time by not updating tool bars that will not be visible
    in a short time on a view shell switch.
*/
class ToolBarManager
    : public ::boost::enable_shared_from_this<ToolBarManager>
{
public:
    /** Use this method instead of the constructor to create new objects of
        this class.
    */
    static ::boost::shared_ptr<ToolBarManager> Create (
        ViewShellBase& rBase,
        const ::boost::shared_ptr<tools::EventMultiplexer>& rpMultiplexer,
        const ::boost::shared_ptr<ViewShellManager>& rpViewShellManager);

    ~ToolBarManager (void);

    /** Call this method prior to the destructor to prevent the
        ToolBarManager from accessing the ViewShellManager or the
        XLayoutManager when those are possibly not well and alive anymore
        (like during the destruction of the ViewShellBase.)
    */
    void Shutdown (void);

    /** When the view in the center pane changes then this method sets up
        the initial set of tool bars for the new view.
        The ToolBarManager listenes for view switching itself and then calls
        MainViewShellChanged().  Calling this method from the outside should
        not be necessary.
        @param nShellType
            The type of the new main view shell.
    */
    void MainViewShellChanged (ViewShell::ShellType nShellType);
    void MainViewShellChanged (const ViewShell& rMainViewShell);

    /** Call this method when the selection has changed to update the more
        temporary tool bars (those in the TBG_FUNCTION group.)
    */
    void SelectionHasChanged (
        const ViewShell& rViewShell,
        const SdrView& rView);

    /** The set of tool bars that are handled by this manager class.
    */
    const static ::rtl::OUString msToolBar;                  // RID_DRAW_TOOLBOX, 23011
                                                             // RID_GRAPHIC_TOOLBOX, 23025
    const static ::rtl::OUString msOptionsToolBar;           // RID_DRAW_OPTIONS_TOOLBOX, 23020
                                                             // RID_GRAPHIC_OPTIONS_TOOLBOX, 23026
    const static ::rtl::OUString msCommonTaskToolBar;        // RID_DRAW_COMMONTASK_TOOLBOX, 23021
    const static ::rtl::OUString msViewerToolBar;            // RID_DRAW_VIEWER_TOOLBOX, 23023
                                                             // RID_GRAPHIC_VIEWER_TOOLBOX, 23024
    const static ::rtl::OUString msSlideSorterToolBar;       // RID_SLIDE_TOOLBOX, 23012
    const static ::rtl::OUString msSlideSorterObjectBar;     // RID_SLIDE_OBJ_TOOLBOX, 23014
    const static ::rtl::OUString msOutlineToolBar;           // RID_OUTLINE_TOOLBOX, 23017
    const static ::rtl::OUString msMasterViewToolBar;        // SID_MASTERPAGE, 27053
    const static ::rtl::OUString msDrawingObjectToolBar;     // RID_DRAW_OBJ_TOOLBOX, 23013
    const static ::rtl::OUString msGluePointsToolBar;        // RID_GLUEPOINTS_TOOLBOX, 23019
    const static ::rtl::OUString msTextObjectBar;            // RID_DRAW_TEXT_TOOLBOX, 23016
                                                             // RID_GRAPHIC_TEXT_TOOLBOX, 23028
    const static ::rtl::OUString msBezierObjectBar;          // RID_BEZIER_TOOLBOX, 23015
    const static ::rtl::OUString msGraphicObjectBar;         // RID_DRAW_GRAF_TOOLBOX, 23030
    const static ::rtl::OUString msMediaObjectBar;           // RID_DRAW_MEDIA_TOOLBOX, 23031
    const static ::rtl::OUString msTableObjectBar;           // RID_DRAW_TABLE_TOOLBOX

    /** The set of tool bar groups.
    */
    enum ToolBarGroup {
        TBG__FIRST,

        TBG_PERMANENT = TBG__FIRST,
        TBG_FUNCTION,
        TBG_MASTER_MODE,

        TBG__LAST = TBG_MASTER_MODE
    };

    /** Only after calls with bValid=<TRUE/> may the tool bar manager use
        the frame::XLayoutManager to change the visible tool bars.  Call
        this method when the controller is attached to or detachted from the
        frame.  When called with <FALSE/> then ResetAllToolBars() is
        executed.
    */
    void SetValid (bool bValid);

    /** Reset the set of visible object bars in the specified group.  Tool
        bars in other groups are not affected.
        @param rParentShell
            When this shell is not the main view then the method returns
            immediately.
        @param eGroup
            Only the tool bars in this group are rest.
    */
    void ResetToolBars (ToolBarGroup eGroup);

    /** Reset all tool bars, regardless of the group they belong to.
        @param rParentShell
            When this shell is not the main view then the method returns
            immediately.
    */
    void ResetAllToolBars (void);

    /** Add the tool bar with the given name to the specified group of tool
        bars.
        @param rParentShell
            When this shell is not the main view then the method returns
            immediately.
        @param eGroup
            The new tool bar is added to this group.
        @param rsToolBarName
            The base name of the tool bar.  A proper prefix (like
            private:resource/toolbar/) is added.  The name may be one of the
            ones defined above.  Other names are allowed as well.
    */
    void AddToolBar (
        ToolBarGroup eGroup,
        const ::rtl::OUString& rsToolBarName);

    /** Add the tool bar shell to the shell stack.  This method basically
        forwards the call to the ViewShellManager.
        For some tool bar shells additional tool bars are made visible.
        @param rParentShell
            When this shell is not the main view then the method returns
            immediately.
        @param eGroup
            The group is used for the actual tool bars.
        @param nToolBarId
            Id of the tool bar shell.
    */
    void AddToolBarShell (
        ToolBarGroup eGroup,
        ShellId nToolBarId);

    /** Remove the tool bar with the given name from the specified group.
        If the tool bar is not visible then nothing happens.
        If the tool bar is a member of another group then nothing happens
        either.
    */
    void RemoveToolBar (
        ToolBarGroup eGroup,
        const ::rtl::OUString& rsToolBarName);

    void RemoveToolBarShell (
        ToolBarGroup eGroup,
        ShellId nToolBarId);

    /** This is basically a shortcut for ResetToolBars(),AddToolBar().  The
        main difference is, that all sub shells of the specified parent
        shell are deactivated as well.
        @param rParentShell
            When this shell is not the main view then the method returns
            immediately.
        @param eGroup
            The new tool bar is added to this group.
        @param rsToolBarName
            The base name of the tool bar.  A proper prefix (like
            private:resource/toolbar/) is added.  The name may be one of the
            ones defined above.  Other names are allowed as well.
    */
    void SetToolBar (
        ToolBarGroup eGroup,
        const ::rtl::OUString& rsToolBarName);

    /** This is basically a shortcut for ResetToolBars(),AddToolBar().  The
        main difference is, that all sub shells of the specified parent
        shell are deactivated as well.
        @param rParentShell
            When this shell is not the main view then the method returns
            immediately.
        @param rParentShell
            When this shell is not the main view then the method returns
            immediately.
        @param eGroup
            The group is currently not used.
        @param nToolBarId
            Id of the tool bar shell.
    */
    void SetToolBarShell (
        ToolBarGroup eGroup,
        ShellId nToolBarId);

    void PreUpdate (void);

    /** Request an update of the active tool bars.  The update is made
        asynchronously.
    */
    void RequestUpdate (void);

    /** This is a hint for the ToolBarManager to improve the performance
        when it updates its tool bars when its own lock is released.  Taking
        control of the release of the update lock of the ViewShellManager
        avoids some shell stack modifications and tool bar updates.
    */
    void LockViewShellManager (void);

    /** Use this class to prevent the visible tool bars from being updated
        (and thus causing repaints and GUI rearrangements) when several tool
        bar operations are made in a row.
    */
    class UpdateLock { public:
        UpdateLock(const ::boost::shared_ptr<ToolBarManager>& rpManager)
            : mpManager(rpManager) { mpManager->LockUpdate(); }
        ~UpdateLock(void) { mpManager->UnlockUpdate(); }
    private:
        ::boost::shared_ptr<ToolBarManager> mpManager;
    };
    friend class UpdateLock;

    /** Return whether updates of tool bars are locked.
    */
    bool IsUpdateLocked (void) const;

    void ToolBarsDestroyed(void);

private:
    class Implementation;
    ::boost::scoped_ptr<Implementation> mpImpl;

    /** The ViewShellBase is used to get the XLayoutManager and to determine
        the plug in mode.
    */
    ToolBarManager (void);

    void LockUpdate (void);
    void UnlockUpdate (void);
};

} // end of namespace sd

#endif
<|endoftext|>


<commit_before>/****************************************************************************

 This file is part of the GLC-lib library.
 Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
 Version 1.0.0, packaged on August, 2008.

 http://glc-lib.sourceforge.net

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

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

 You should have received a copy of the GNU General Public License
 along with GLC-lib; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

*****************************************************************************/

//! \file glc_enum.cpp implementation of usefull utilities

#include "glc_enum.h"

GLC_uint glc::GLC_GenID(void)
{
	static GLC_uint Id= 0;
	return Id++;
}
<commit_msg>Start ID from 1 instead of 0.<commit_after>/****************************************************************************

 This file is part of the GLC-lib library.
 Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
 Version 1.0.0, packaged on August, 2008.

 http://glc-lib.sourceforge.net

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

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

 You should have received a copy of the GNU General Public License
 along with GLC-lib; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

*****************************************************************************/

//! \file glc_enum.cpp implementation of usefull utilities

#include "glc_enum.h"

GLC_uint glc::GLC_GenID(void)
{
	static GLC_uint Id= 1;
	return Id++;
}
<|endoftext|>


<commit_before><commit_msg>fdo#46926: fix UNO struct comparison in Python 2<commit_after><|endoftext|>


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

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

#include "TestMenu.hxx"

#include "taskpane/TaskPaneControlFactory.hxx"

#include <vcl/image.hxx>
#include <vcl/svapp.hxx>

namespace sd { namespace toolpanel {

/** This factory class is used to create instances of ColorMenu.  It can be
    extended so that its constructor stores arguments that later are passed
    to new ColorMenu objects.
*/
class ColorMenuFactory
    : public ControlFactory
{
protected:
    virtual TreeNode* InternalCreateControl (TreeNode* pTreeNode)
    {
        return new ColorMenu (pTreeNode);
    }
};

ColorMenu::ColorMenu (TreeNode* pParent)
    : Window (pParent->GetWindow()),
      TreeNode(pParent),
      maSet (this),
      mnPreferredColumnCount(2)
{
    WinBits aStyle =
        WB_ITEMBORDER
        | WB_DOUBLEBORDER
        | WB_NAMEFIELD
        | WB_FLATVALUESET
        | WB_TABSTOP
        | WB_VSCROLL;

    maSet.SetStyle (maSet.GetStyle() | aStyle);
    maSet.SetExtraSpacing(2);

    Fill ();
    maSet.Show();
    pParent->RequestResize();
}

ColorMenu::~ColorMenu (void)
{
}

::std::auto_ptr<ControlFactory> ColorMenu::CreateControlFactory (void)
{
    return ::std::auto_ptr<ControlFactory>(new ColorMenuFactory());
}

/** The preferred size depends on the preferred number of columns, the
    number of items, and the size of the items.
*/
Size ColorMenu::GetPreferredSize (void)
{
    Size aItemSize = maSet.CalcItemSizePixel (Size());
    Size aPreferredWindowSize = maSet.CalcWindowSizePixel (
        aItemSize,
        mnPreferredColumnCount,
        CalculateRowCount (aItemSize, mnPreferredColumnCount));
    return aPreferredWindowSize;
}

sal_Int32 ColorMenu::GetPreferredWidth (sal_Int32 nHeight)
{
    sal_Int32 nPreferredWidth = 0;
    if (maSet.GetItemCount() > 0)
    {
        Image aImage = maSet.GetItemImage(maSet.GetItemId(0));
        Size aItemSize = maSet.CalcItemSizePixel (aImage.GetSizePixel());
        if (nHeight>0 && aItemSize.Height()>0)
        {
            int nRowCount = nHeight / aItemSize.Height();
            if (nRowCount <= 0)
                nRowCount = 1;
            int nColumnCount = (maSet.GetItemCount() + nRowCount-1)
                / nRowCount;
            nPreferredWidth = nColumnCount * aItemSize.Width();
        }
    }

    return nPreferredWidth;
}

sal_Int32 ColorMenu::GetPreferredHeight (sal_Int32 nWidth)
{
    sal_Int32 nPreferredHeight = 0;
    if (maSet.GetItemCount()>0)
    {
        Image aImage = maSet.GetItemImage(maSet.GetItemId(0));
        Size aItemSize = maSet.CalcItemSizePixel (aImage.GetSizePixel());
        if (nWidth>0 && aItemSize.Width()>0)
        {
            int nColumnCount = nWidth / aItemSize.Width();
            if (nColumnCount <= 0)
                nColumnCount = 1;
            else if (nColumnCount > 4)
                nColumnCount = 4;
            int nRowCount = (maSet.GetItemCount() + nColumnCount-1)
                / nColumnCount;
            nPreferredHeight = nRowCount * aItemSize.Height();
        }
    }
    return nPreferredHeight;
}

bool ColorMenu::IsResizable (void)
{
    return true;
}

::Window* ColorMenu::GetWindow (void)
{
    return this;
}

void ColorMenu::Resize (void)
{
    ::Window::Resize();
    Size aWindowSize = GetOutputSizePixel();
    maSet.SetPosSizePixel (Point(0,0), aWindowSize);
    if (IsVisible() && aWindowSize.Width() > 0)
    {
        //        maSet.SetPosSizePixel (
        //            Point (0,0),
        //            aWindowSize);

        // Calculate the number of rows and columns.
        if (maSet.GetItemCount() > 0)
        {
            Image aImage = maSet.GetItemImage(maSet.GetItemId(0));
            Size aItemSize = maSet.CalcItemSizePixel (
                aImage.GetSizePixel());
            int nColumnCount = aWindowSize.Width() / 30;
            if (nColumnCount < 1)
                nColumnCount = 1;
            else if (nColumnCount > 4)
                nColumnCount = 4;

            int nRowCount = CalculateRowCount (aItemSize, nColumnCount);

            maSet.SetColCount (nColumnCount);
            maSet.SetLineCount (nRowCount);
        }
    }

}

int ColorMenu::CalculateRowCount (const Size& rItemSize, int nColumnCount)
{
    int nRowCount = 0;

    if (maSet.GetItemCount()>0 && nColumnCount>0)
    {
        nRowCount = GetOutputSizePixel().Height() / 30;
        if (nRowCount < 1)
            nRowCount = 1;
    }

    return nRowCount;
}

void ColorMenu::Fill (void)
{
    const StyleSettings& rSettings (
        Application::GetSettings().GetStyleSettings());
    maSet.Clear();
    maSet.SetItemWidth (30);
    maSet.SetItemHeight (30);
    int i = 0;
    maSet.InsertItem (++i, rSettings.GetFaceColor());
    maSet.SetItemText (i, String::CreateFromAscii("FaceColor"));
    maSet.InsertItem (++i, rSettings.GetCheckedColor());
    maSet.SetItemText (i, String::CreateFromAscii("CheckedColor"));
    maSet.InsertItem (++i, rSettings.GetLightColor());
    maSet.SetItemText (i, String::CreateFromAscii("LightColor"));
    maSet.InsertItem (++i, rSettings.GetLightBorderColor());
    maSet.SetItemText (i, String::CreateFromAscii("LightBorderColor"));
    maSet.InsertItem (++i, rSettings.GetShadowColor());
    maSet.SetItemText (i, String::CreateFromAscii("ShadowColor"));
    maSet.InsertItem (++i, rSettings.GetDarkShadowColor());
    maSet.SetItemText (i, String::CreateFromAscii("DarkShadowColor"));
    maSet.InsertItem (++i, rSettings.GetButtonTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("ButtonTextColor"));
    maSet.InsertItem (++i, rSettings.GetRadioCheckTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("RadioCheckTextColor"));
    maSet.InsertItem (++i, rSettings.GetGroupTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("GroupTextColor"));
    maSet.InsertItem (++i, rSettings.GetLabelTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("LabelTextColor"));
    maSet.InsertItem (++i, rSettings.GetInfoTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("InfoTextColor"));
    maSet.InsertItem (++i, rSettings.GetWindowColor());
    maSet.SetItemText (i, String::CreateFromAscii("WindowColor"));
    maSet.InsertItem (++i, rSettings.GetWindowTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("WindowTextColor"));
    maSet.InsertItem (++i, rSettings.GetDialogColor());
    maSet.SetItemText (i, String::CreateFromAscii("DialogColor"));
    maSet.InsertItem (++i, rSettings.GetDialogTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("DialogTextColor"));
    maSet.InsertItem (++i, rSettings.GetWorkspaceColor());
    maSet.SetItemText (i, String::CreateFromAscii("WorkspaceColor"));
    maSet.InsertItem (++i, rSettings.GetFieldColor());
    maSet.SetItemText (i, String::CreateFromAscii("FieldColor"));
    maSet.InsertItem (++i, rSettings.GetFieldTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("FieldTextColor"));
    maSet.InsertItem (++i, rSettings.GetActiveColor());
    maSet.SetItemText (i, String::CreateFromAscii("ActiveColor"));
    maSet.InsertItem (++i, rSettings.GetActiveColor2());
    maSet.SetItemText (i, String::CreateFromAscii("ActiveColor2"));
    maSet.InsertItem (++i, rSettings.GetActiveTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("ActiveTextColor"));
    maSet.InsertItem (++i, rSettings.GetActiveBorderColor());
    maSet.SetItemText (i, String::CreateFromAscii("ActiveBorderColor"));
    maSet.InsertItem (++i, rSettings.GetDeactiveColor());
    maSet.SetItemText (i, String::CreateFromAscii("DeactiveColor"));
    maSet.InsertItem (++i, rSettings.GetDeactiveColor2());
    maSet.SetItemText (i, String::CreateFromAscii("DeactiveColor2"));
    maSet.InsertItem (++i, rSettings.GetDeactiveTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("DeactiveTextColor"));
    maSet.InsertItem (++i, rSettings.GetDeactiveBorderColor());
    maSet.SetItemText (i, String::CreateFromAscii("DeactiveBorderColor"));
    maSet.InsertItem (++i, rSettings.GetHighlightColor());
    maSet.SetItemText (i, String::CreateFromAscii("HighlightColor"));
    maSet.InsertItem (++i, rSettings.GetHighlightTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("HighlightTextColor"));
    maSet.InsertItem (++i, rSettings.GetDisableColor());
    maSet.SetItemText (i, String::CreateFromAscii("DisableColor"));
    maSet.InsertItem (++i, rSettings.GetHelpColor());
    maSet.SetItemText (i, String::CreateFromAscii("HelpColor"));
    maSet.InsertItem (++i, rSettings.GetHelpTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("HelpTextColor"));
    maSet.InsertItem (++i, rSettings.GetMenuColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuColor"));
    maSet.InsertItem (++i, rSettings.GetMenuBarColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuBarColor"));
    maSet.InsertItem (++i, rSettings.GetMenuBorderColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuBorderColor"));
    maSet.InsertItem (++i, rSettings.GetMenuTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuTextColor"));
    maSet.InsertItem (++i, rSettings.GetMenuHighlightColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuHighlightColor"));
    maSet.InsertItem (++i, rSettings.GetMenuHighlightTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuHighlightTextColor"));
    maSet.InsertItem (++i, rSettings.GetLinkColor());
    maSet.SetItemText (i, String::CreateFromAscii("LinkColor"));
    maSet.InsertItem (++i, rSettings.GetVisitedLinkColor());
    maSet.SetItemText (i, String::CreateFromAscii("VisitedLinkColor"));
    maSet.InsertItem (++i, rSettings.GetHighlightLinkColor());
    maSet.SetItemText (i, String::CreateFromAscii("HighlightLinkColor"));
    maSet.InsertItem (++i, rSettings.GetFontColor());
    maSet.SetItemText (i, String::CreateFromAscii("FontColor"));
}

} } // end of namespace ::sd::toolpanel
<commit_msg>INTEGRATION: CWS sdwarningsbegone (1.5.38); FILE MERGED 2006/11/27 16:31:00 cl 1.5.38.3: #i69285# warning free code changes for sd project 2006/11/27 15:15:04 cl 1.5.38.2: #i69285# warning free code changes for sd project 2006/11/22 12:42:15 cl 1.5.38.1: #i69285# warning free code changes for unxlngi6.pro<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: TestMenu.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: kz $ $Date: 2006-12-12 18:43:34 $
 *
 *  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 "TestMenu.hxx"

#include "taskpane/TaskPaneControlFactory.hxx"

#include <vcl/image.hxx>
#include <vcl/svapp.hxx>

namespace sd { namespace toolpanel {

/** This factory class is used to create instances of ColorMenu.  It can be
    extended so that its constructor stores arguments that later are passed
    to new ColorMenu objects.
*/
class ColorMenuFactory
    : public ControlFactory
{
protected:
    virtual TreeNode* InternalCreateControl (TreeNode* pTreeNode)
    {
        return new ColorMenu (pTreeNode);
    }
};

ColorMenu::ColorMenu (TreeNode* pParent)
    : Window (pParent->GetWindow()),
      TreeNode(pParent),
      maSet (this),
      mnPreferredColumnCount(2)
{
    WinBits aStyle =
        WB_ITEMBORDER
        | WB_DOUBLEBORDER
        | WB_NAMEFIELD
        | WB_FLATVALUESET
        | WB_TABSTOP
        | WB_VSCROLL;

    maSet.SetStyle (maSet.GetStyle() | aStyle);
    maSet.SetExtraSpacing(2);

    Fill ();
    maSet.Show();
    pParent->RequestResize();
}

ColorMenu::~ColorMenu (void)
{
}

::std::auto_ptr<ControlFactory> ColorMenu::CreateControlFactory (void)
{
    return ::std::auto_ptr<ControlFactory>(new ColorMenuFactory());
}

/** The preferred size depends on the preferred number of columns, the
    number of items, and the size of the items.
*/
Size ColorMenu::GetPreferredSize (void)
{
    Size aItemSize = maSet.CalcItemSizePixel (Size());
    Size aPreferredWindowSize = maSet.CalcWindowSizePixel (
        aItemSize,
        (USHORT)mnPreferredColumnCount,
        (USHORT)CalculateRowCount (aItemSize, (USHORT)mnPreferredColumnCount));
    return aPreferredWindowSize;
}

sal_Int32 ColorMenu::GetPreferredWidth (sal_Int32 nHeight)
{
    sal_Int32 nPreferredWidth = 0;
    if (maSet.GetItemCount() > 0)
    {
        Image aImage = maSet.GetItemImage(maSet.GetItemId(0));
        Size aItemSize = maSet.CalcItemSizePixel (aImage.GetSizePixel());
        if (nHeight>0 && aItemSize.Height()>0)
        {
            int nRowCount = nHeight / aItemSize.Height();
            if (nRowCount <= 0)
                nRowCount = 1;
            int nColumnCount = (maSet.GetItemCount() + nRowCount-1)
                / nRowCount;
            nPreferredWidth = nColumnCount * aItemSize.Width();
        }
    }

    return nPreferredWidth;
}

sal_Int32 ColorMenu::GetPreferredHeight (sal_Int32 nWidth)
{
    sal_Int32 nPreferredHeight = 0;
    if (maSet.GetItemCount()>0)
    {
        Image aImage = maSet.GetItemImage(maSet.GetItemId(0));
        Size aItemSize = maSet.CalcItemSizePixel (aImage.GetSizePixel());
        if (nWidth>0 && aItemSize.Width()>0)
        {
            int nColumnCount = nWidth / aItemSize.Width();
            if (nColumnCount <= 0)
                nColumnCount = 1;
            else if (nColumnCount > 4)
                nColumnCount = 4;
            int nRowCount = (maSet.GetItemCount() + nColumnCount-1)
                / nColumnCount;
            nPreferredHeight = nRowCount * aItemSize.Height();
        }
    }
    return nPreferredHeight;
}

bool ColorMenu::IsResizable (void)
{
    return true;
}

::Window* ColorMenu::GetWindow (void)
{
    return this;
}

void ColorMenu::Resize (void)
{
    ::Window::Resize();
    Size aWindowSize = GetOutputSizePixel();
    maSet.SetPosSizePixel (Point(0,0), aWindowSize);
    if (IsVisible() && aWindowSize.Width() > 0)
    {
        //        maSet.SetPosSizePixel (
        //            Point (0,0),
        //            aWindowSize);

        // Calculate the number of rows and columns.
        if (maSet.GetItemCount() > 0)
        {
            Image aImage = maSet.GetItemImage(maSet.GetItemId(0));
            Size aItemSize = maSet.CalcItemSizePixel (
                aImage.GetSizePixel());
            int nColumnCount = aWindowSize.Width() / 30;
            if (nColumnCount < 1)
                nColumnCount = 1;
            else if (nColumnCount > 4)
                nColumnCount = 4;

            USHORT nRowCount = (USHORT)CalculateRowCount (aItemSize, nColumnCount);

            maSet.SetColCount ((USHORT)nColumnCount);
            maSet.SetLineCount (nRowCount);
        }
    }

}

int ColorMenu::CalculateRowCount (const Size&, int nColumnCount)
{
    int nRowCount = 0;

    if (maSet.GetItemCount()>0 && nColumnCount>0)
    {
        nRowCount = GetOutputSizePixel().Height() / 30;
        if (nRowCount < 1)
            nRowCount = 1;
    }

    return nRowCount;
}

void ColorMenu::Fill (void)
{
    const StyleSettings& rSettings (
        Application::GetSettings().GetStyleSettings());
    maSet.Clear();
    maSet.SetItemWidth (30);
    maSet.SetItemHeight (30);
    USHORT i = 0;
    maSet.InsertItem (++i, rSettings.GetFaceColor());
    maSet.SetItemText (i, String::CreateFromAscii("FaceColor"));
    maSet.InsertItem (++i, rSettings.GetCheckedColor());
    maSet.SetItemText (i, String::CreateFromAscii("CheckedColor"));
    maSet.InsertItem (++i, rSettings.GetLightColor());
    maSet.SetItemText (i, String::CreateFromAscii("LightColor"));
    maSet.InsertItem (++i, rSettings.GetLightBorderColor());
    maSet.SetItemText (i, String::CreateFromAscii("LightBorderColor"));
    maSet.InsertItem (++i, rSettings.GetShadowColor());
    maSet.SetItemText (i, String::CreateFromAscii("ShadowColor"));
    maSet.InsertItem (++i, rSettings.GetDarkShadowColor());
    maSet.SetItemText (i, String::CreateFromAscii("DarkShadowColor"));
    maSet.InsertItem (++i, rSettings.GetButtonTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("ButtonTextColor"));
    maSet.InsertItem (++i, rSettings.GetRadioCheckTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("RadioCheckTextColor"));
    maSet.InsertItem (++i, rSettings.GetGroupTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("GroupTextColor"));
    maSet.InsertItem (++i, rSettings.GetLabelTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("LabelTextColor"));
    maSet.InsertItem (++i, rSettings.GetInfoTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("InfoTextColor"));
    maSet.InsertItem (++i, rSettings.GetWindowColor());
    maSet.SetItemText (i, String::CreateFromAscii("WindowColor"));
    maSet.InsertItem (++i, rSettings.GetWindowTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("WindowTextColor"));
    maSet.InsertItem (++i, rSettings.GetDialogColor());
    maSet.SetItemText (i, String::CreateFromAscii("DialogColor"));
    maSet.InsertItem (++i, rSettings.GetDialogTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("DialogTextColor"));
    maSet.InsertItem (++i, rSettings.GetWorkspaceColor());
    maSet.SetItemText (i, String::CreateFromAscii("WorkspaceColor"));
    maSet.InsertItem (++i, rSettings.GetFieldColor());
    maSet.SetItemText (i, String::CreateFromAscii("FieldColor"));
    maSet.InsertItem (++i, rSettings.GetFieldTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("FieldTextColor"));
    maSet.InsertItem (++i, rSettings.GetActiveColor());
    maSet.SetItemText (i, String::CreateFromAscii("ActiveColor"));
    maSet.InsertItem (++i, rSettings.GetActiveColor2());
    maSet.SetItemText (i, String::CreateFromAscii("ActiveColor2"));
    maSet.InsertItem (++i, rSettings.GetActiveTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("ActiveTextColor"));
    maSet.InsertItem (++i, rSettings.GetActiveBorderColor());
    maSet.SetItemText (i, String::CreateFromAscii("ActiveBorderColor"));
    maSet.InsertItem (++i, rSettings.GetDeactiveColor());
    maSet.SetItemText (i, String::CreateFromAscii("DeactiveColor"));
    maSet.InsertItem (++i, rSettings.GetDeactiveColor2());
    maSet.SetItemText (i, String::CreateFromAscii("DeactiveColor2"));
    maSet.InsertItem (++i, rSettings.GetDeactiveTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("DeactiveTextColor"));
    maSet.InsertItem (++i, rSettings.GetDeactiveBorderColor());
    maSet.SetItemText (i, String::CreateFromAscii("DeactiveBorderColor"));
    maSet.InsertItem (++i, rSettings.GetHighlightColor());
    maSet.SetItemText (i, String::CreateFromAscii("HighlightColor"));
    maSet.InsertItem (++i, rSettings.GetHighlightTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("HighlightTextColor"));
    maSet.InsertItem (++i, rSettings.GetDisableColor());
    maSet.SetItemText (i, String::CreateFromAscii("DisableColor"));
    maSet.InsertItem (++i, rSettings.GetHelpColor());
    maSet.SetItemText (i, String::CreateFromAscii("HelpColor"));
    maSet.InsertItem (++i, rSettings.GetHelpTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("HelpTextColor"));
    maSet.InsertItem (++i, rSettings.GetMenuColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuColor"));
    maSet.InsertItem (++i, rSettings.GetMenuBarColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuBarColor"));
    maSet.InsertItem (++i, rSettings.GetMenuBorderColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuBorderColor"));
    maSet.InsertItem (++i, rSettings.GetMenuTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuTextColor"));
    maSet.InsertItem (++i, rSettings.GetMenuHighlightColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuHighlightColor"));
    maSet.InsertItem (++i, rSettings.GetMenuHighlightTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuHighlightTextColor"));
    maSet.InsertItem (++i, rSettings.GetLinkColor());
    maSet.SetItemText (i, String::CreateFromAscii("LinkColor"));
    maSet.InsertItem (++i, rSettings.GetVisitedLinkColor());
    maSet.SetItemText (i, String::CreateFromAscii("VisitedLinkColor"));
    maSet.InsertItem (++i, rSettings.GetHighlightLinkColor());
    maSet.SetItemText (i, String::CreateFromAscii("HighlightLinkColor"));
    maSet.InsertItem (++i, rSettings.GetFontColor());
    maSet.SetItemText (i, String::CreateFromAscii("FontColor"));
}

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


<commit_before>#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
	char s;
	cin>>s;
	if((s>'a' && s<'z') || (s>'A' && s<'Z')) cout<<"Alphabet";
	else cout<<"Not an alphabet";
	return 0;
}
<commit_msg>rm unnecessary header<commit_after>#include <iostream>
using namespace std;

int main() {
	char s;
	cin>>s;
	if((s>'a' && s<'z') || (s>'A' && s<'Z')) cout<<"Alphabet";
	else cout<<"Not an alphabet";
	return 0;
}
<|endoftext|>