<commit_before>#include "MicroBit.h"

MicroBit uBit;

char INTRO[] = "SHOW.IO";
char URL[] = "https://show.io/Fq5sf7O9Y";

// lvl : Pwr@ 1m : Pwr@ 0m : Pwr @ 0m per spec
//  0  :   -90   :   -49   :     0xcf
//  1  :   -78   :   -37   :     0xdb
//  2  :   -74   :   -33   :     0xdf
//  3  :   -69   :   -28   :     0xe4
//  4  :   -66   :   -25   :     0xe7
//  5  :   -61   :   -20   :     0xec
//  6  :   -56   :   -15   :     0xf1
//  7  :   -51   :   -10   :     0xf6
const uint8_t CALLIBRATED_POWERS[] = {0xCF, 0xDB, 0xDF, 0xE4, 0xE7, 0xEC, 0xF1, 0xF6};

uint8_t power = 4;
bool screen_off = false;

/**
* Displays the current transmission power on the led display
*/
void updateDisplay()
{
    if (screen_off) {
        MicroBitImage clear_display("0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n");
        uBit.display.print(clear_display);
    } else {
        if (power == 0)
        {
            MicroBitImage tick("255,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n");
            uBit.display.print(tick);
        }
        else if (power == 1)
        {
            MicroBitImage tick("255,255,0,0,0\n255,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n");
            uBit.display.print(tick);
        }
        else if (power == 2)
        {
            MicroBitImage tick("255,255,255,0,0\n255,255,0,0,0\n255,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n");
            uBit.display.print(tick);
        }
        else if (power == 3)
        {
            MicroBitImage tick("255,255,255,255,0\n255,255,255,0,0\n255,255,0,0,0\n255,0,0,0,0\n0,0,0,0,0\n");
            uBit.display.print(tick);
        }
        else if (power == 4)
        {
            MicroBitImage tick("255,255,255,255,255\n255,255,255,255,0\n255,255,255,0,0\n255,255,0,0,0\n255,0,0,0,0\n");
            uBit.display.print(tick);
        }
        else if (power == 5)
        {
            MicroBitImage tick("255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,0\n255,255,255,0,0\n255,255,0,0,0\n");
            uBit.display.print(tick);
        }
        else if (power == 6)
        {
            MicroBitImage tick("255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,0\n255,255,255,0,0\n");
            uBit.display.print(tick);
        }
        else if (power == 7)
        {
            MicroBitImage tick("255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,0\n");
            uBit.display.print(tick);
        }
        else if (power == 8)
        {
            MicroBitImage tick("255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n");
            uBit.display.print(tick);
        }
    }
}

/**
* Handles incoming events
* @param evt: the event that triggered
*/
void onEvent(MicroBitEvent evt)
{
    // Device turn on
    if (screen_off == true && evt.value == MICROBIT_BUTTON_EVT_CLICK) {
        screen_off = false;
        updateDisplay();
        return;
    }

    // Decrease power
    if (evt.source == MICROBIT_ID_BUTTON_A && evt.value == MICROBIT_BUTTON_EVT_CLICK) {
        if (power <= 0) return;
        power--;
        if (power == 0) {
            uBit.bleManager.stopAdvertise();
        } else {
            uBit.bleManager.advertisePhysicalWebUrl(URL, CALLIBRATED_POWERS[power - 1]);
            uBit.bleManager.setTransmitPower(power-1);
        }
        updateDisplay();
        return;
    }

    // Increase power
    if (evt.source == MICROBIT_ID_BUTTON_B && evt.value == MICROBIT_BUTTON_EVT_CLICK) {
        if (power >= 8) return;
        power++;
        uBit.bleManager.advertisePhysicalWebUrl(URL, CALLIBRATED_POWERS[power - 1]);
        uBit.bleManager.setTransmitPower(power-1);
        updateDisplay();
        return;
    }

    // Turn off display
  if (evt.source == MICROBIT_ID_ACCELEROMETER) {
    if (uBit.accelerometer.getGesture() > 5) {
      screen_off = true;
      updateDisplay();
    }
    return;
  }
}

/**
* Main
*/
int main()
{
    uBit.init();
    uBit.display.scroll(INTRO);

    uBit.bleManager.advertisePhysicalWebUrl(URL, CALLIBRATED_POWERS[power - 1]);
    uBit.bleManager.setTransmitPower(power-1);
    updateDisplay();

    uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_EVT_ANY, onEvent);
    uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_EVT_ANY, onEvent);
    uBit.messageBus.listen(MICROBIT_ID_ACCELEROMETER, MICROBIT_EVT_ANY, onEvent);

    release_fiber();
}

<commit_msg>Updated the main app to use the latest fork of microbit-dal"<commit_after>#include "MicroBit.h"

MicroBit uBit;

char INTRO[] = "SHOW.IO";
char URL[] = "https://show.io/Fq5sf7O9Y";

// lvl : Pwr@ 1m : Pwr@ 0m : Pwr @ 0m per spec
//  0  :   -90   :   -49   :     0xcf
//  1  :   -78   :   -37   :     0xdb
//  2  :   -74   :   -33   :     0xdf
//  3  :   -69   :   -28   :     0xe4
//  4  :   -66   :   -25   :     0xe7
//  5  :   -61   :   -20   :     0xec
//  6  :   -56   :   -15   :     0xf1
//  7  :   -51   :   -10   :     0xf6
const uint8_t CALLIBRATED_POWERS[] = {0xCF, 0xDB, 0xDF, 0xE4, 0xE7, 0xEC, 0xF1, 0xF6};

uint8_t power = 4;
bool screen_off = false;

/**
* Displays the current transmission power on the led display
*/
void updateDisplay()
{
    if (screen_off) {
        MicroBitImage clear_display("0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n");
        uBit.display.print(clear_display);
    } else {
        if (power == 0)
        {
            MicroBitImage tick("255,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n");
            uBit.display.print(tick);
        }
        else if (power == 1)
        {
            MicroBitImage tick("255,255,0,0,0\n255,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n");
            uBit.display.print(tick);
        }
        else if (power == 2)
        {
            MicroBitImage tick("255,255,255,0,0\n255,255,0,0,0\n255,0,0,0,0\n0,0,0,0,0\n0,0,0,0,0\n");
            uBit.display.print(tick);
        }
        else if (power == 3)
        {
            MicroBitImage tick("255,255,255,255,0\n255,255,255,0,0\n255,255,0,0,0\n255,0,0,0,0\n0,0,0,0,0\n");
            uBit.display.print(tick);
        }
        else if (power == 4)
        {
            MicroBitImage tick("255,255,255,255,255\n255,255,255,255,0\n255,255,255,0,0\n255,255,0,0,0\n255,0,0,0,0\n");
            uBit.display.print(tick);
        }
        else if (power == 5)
        {
            MicroBitImage tick("255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,0\n255,255,255,0,0\n255,255,0,0,0\n");
            uBit.display.print(tick);
        }
        else if (power == 6)
        {
            MicroBitImage tick("255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,0\n255,255,255,0,0\n");
            uBit.display.print(tick);
        }
        else if (power == 7)
        {
            MicroBitImage tick("255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,0\n");
            uBit.display.print(tick);
        }
        else if (power == 8)
        {
            MicroBitImage tick("255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n255,255,255,255,255\n");
            uBit.display.print(tick);
        }
    }
}

/**
* Handles incoming events
* @param evt: the event that triggered
*/
void onEvent(MicroBitEvent evt)
{
    // Device turn on
    if (screen_off == true && evt.value == MICROBIT_BUTTON_EVT_CLICK) {
        screen_off = false;
        updateDisplay();
        return;
    }

    // Decrease power
    if (evt.source == MICROBIT_ID_BUTTON_A && evt.value == MICROBIT_BUTTON_EVT_CLICK) {
        if (power <= 0) return;
        power--;
        if (power == 0) {
            uBit.bleManager.stopAdvertising();
        } else {
            uBit.bleManager.advertisePhysicalWebUrl(URL, CALLIBRATED_POWERS[power - 1]);
            uBit.bleManager.setTransmitPower(power-1);
        }
        updateDisplay();
        return;
    }

    // Increase power
    if (evt.source == MICROBIT_ID_BUTTON_B && evt.value == MICROBIT_BUTTON_EVT_CLICK) {
        if (power >= 8) return;
        power++;
        uBit.bleManager.advertisePhysicalWebUrl(URL, CALLIBRATED_POWERS[power - 1]);
        uBit.bleManager.setTransmitPower(power-1);
        updateDisplay();
        return;
    }

    // Turn off display
  if (evt.source == MICROBIT_ID_ACCELEROMETER) {
    if (uBit.accelerometer.getGesture() > 5) {
      screen_off = true;
      updateDisplay();
    }
    return;
  }
}

/**
* Main
*/
int main()
{
    uBit.init();
    uBit.display.scroll(INTRO);

    uBit.bleManager.advertisePhysicalWebUrl(URL, CALLIBRATED_POWERS[power - 1]);
    uBit.bleManager.setTransmitPower(power-1);
    updateDisplay();

    uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_EVT_ANY, onEvent);
    uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_EVT_ANY, onEvent);
    uBit.messageBus.listen(MICROBIT_ID_ACCELEROMETER, MICROBIT_EVT_ANY, onEvent);

    release_fiber();
}

<|endoftext|>


<commit_before>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2006 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#include "dbffile.hpp"
#include "utils.hpp"
#include <boost/algorithm/string.hpp>
#include <string>

dbf_file::dbf_file()
    : num_records_(0),
      num_fields_(0),
      record_length_(0),
      record_(0) {}

dbf_file::dbf_file(const char* file_name)
    :num_records_(0),
     num_fields_(0),
     record_length_(0),
     record_(0)
{
    file_.open(file_name);
    if (file_.is_open())
    {
        read_header();
    }
}

dbf_file::~dbf_file()
{
    ::operator delete(record_);
    file_.close();
}

bool dbf_file::open(const std::string& file_name)
{
    file_.open(file_name.c_str(),std::ios::in|std::ios::binary);
    if (file_.is_open())
        read_header();
    return file_?true:false;
}

bool dbf_file::is_open()
{
    return file_.is_open();
}

void dbf_file::close()
{
    if (file_ && file_.is_open())
        file_.close();
}

int dbf_file::num_records() const
{
    return num_records_;
}

int dbf_file::num_fields() const
{
    return num_fields_;
}

void dbf_file::move_to(int index)
{
    if (index>0 && index<=num_records_)
    {
        long pos=(num_fields_<<5)+34+(index-1)*(record_length_+1);
        file_.seekg(pos,std::ios::beg);
        file_.read(record_,record_length_);
    }
}

std::string dbf_file::string_value(int col) const
{
    if (col>=0 && col<num_fields_)
    {
        return std::string(record_+fields_[col].offset_,fields_[col].length_);
    }
    return "";
}

const field_descriptor& dbf_file::descriptor(int col) const
{
    assert(col>=0 && col<num_fields_);
    return fields_[col];
}

void dbf_file::add_attribute(int col,Feature const& f) const throw()
{
    if (col>=0 && col<num_fields_)
    {
        std::string name=fields_[col].name_;
        std::string str=boost::trim_copy(std::string(record_+fields_[col].offset_,fields_[col].length_));

        switch (fields_[col].type_)
        {
        case 'C':
        case 'D'://todo handle date?
        case 'M':
        case 'L':
            f[name] = str;
            break;
        case 'N':
        case 'F':
            {
                if (str[0]=='*')
                {
                    boost::put(f,name,0);
                    break;
                }
                if (fields_[col].dec_>0)
                {
                    double d;
                    fromString(str,d);
                    boost::put(f,name,d);
                }
                else
                {
                    int i;
                    fromString(str,i);
                    boost::put(f,name,i);
                }
                break;
            }
        }
    }
}

void dbf_file::read_header()
{
    char c=file_.get();
    if (c=='\3' || c=='\131')
    {
        skip(3);
        num_records_=read_int();
        assert(num_records_>0);
        num_fields_=read_short();
        assert(num_fields_>0);
        num_fields_=(num_fields_-33)/32;
        skip(22);
        int offset=0;
        char name[11];
        memset(&name,0,11);
        fields_.reserve(num_fields_);
        for (int i=0;i<num_fields_;++i)
        {
            field_descriptor desc;
            desc.index_=i;
            file_.read(name,10);
            desc.name_=boost::trim_left_copy(std::string(name));
            skip(1);
            desc.type_=file_.get();
            skip(4);
            desc.length_=file_.get();
            desc.dec_=file_.get();
            skip(14);
            desc.offset_=offset;
            offset+=desc.length_;
            fields_.push_back(desc);
        }
        record_length_=offset;
        if (record_length_>0)
        {
            record_=static_cast<char*>(::operator new (sizeof(char)*record_length_));
        }
    }
}

int dbf_file::read_short()
{
    char b[2];
    file_.read(b,2);
    return (b[0] & 0xff) | (b[1] & 0xff) << 8;
}

int dbf_file::read_int()
{
    char b[4];
    file_.read(b,4);
    return (b[0] & 0xff) | (b[1] & 0xff) << 8 |
        (b[2] & 0xff) << 16 | (b[3] & 0xff) <<24;
}

void dbf_file::skip(int bytes)
{
    file_.seekg(bytes,std::ios::cur);
}
<commit_msg>use boost::lexical_cast for conversions ( thanks to John Leslie <jleslie@placebase.com> )<commit_after>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2006 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#include "dbffile.hpp"
#include "utils.hpp"
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <string>

dbf_file::dbf_file()
    : num_records_(0),
      num_fields_(0),
      record_length_(0),
      record_(0) {}

dbf_file::dbf_file(const char* file_name)
    :num_records_(0),
     num_fields_(0),
     record_length_(0),
     record_(0)
{
    file_.open(file_name);
    if (file_.is_open())
    {
        read_header();
    }
}

dbf_file::~dbf_file()
{
    ::operator delete(record_);
    file_.close();
}

bool dbf_file::open(const std::string& file_name)
{
    file_.open(file_name.c_str(),std::ios::in|std::ios::binary);
    if (file_.is_open())
        read_header();
    return file_?true:false;
}

bool dbf_file::is_open()
{
    return file_.is_open();
}

void dbf_file::close()
{
    if (file_ && file_.is_open())
        file_.close();
}

int dbf_file::num_records() const
{
    return num_records_;
}

int dbf_file::num_fields() const
{
    return num_fields_;
}

void dbf_file::move_to(int index)
{
    if (index>0 && index<=num_records_)
    {
        long pos=(num_fields_<<5)+34+(index-1)*(record_length_+1);
        file_.seekg(pos,std::ios::beg);
        file_.read(record_,record_length_);
    }
}

std::string dbf_file::string_value(int col) const
{
    if (col>=0 && col<num_fields_)
    {
        return std::string(record_+fields_[col].offset_,fields_[col].length_);
    }
    return "";
}

const field_descriptor& dbf_file::descriptor(int col) const
{
    assert(col>=0 && col<num_fields_);
    return fields_[col];
}

void dbf_file::add_attribute(int col,Feature const& f) const throw()
{
    if (col>=0 && col<num_fields_)
    {
        std::string name=fields_[col].name_;
        std::string str=boost::trim_copy(std::string(record_+fields_[col].offset_,fields_[col].length_));

        switch (fields_[col].type_)
        {
        case 'C':
        case 'D'://todo handle date?
        case 'M':
        case 'L':
            f[name] = str;
            break;
        case 'N':
        case 'F':
            {
                if (str[0]=='*')
                {
                    boost::put(f,name,0);
                    break;
                }
                if ( fields_[col].dec_>0 )
                {
                    try
                    {
                        double d = boost::lexical_cast<double>(str);
                        boost::put(f,name,d);
                    }
                    catch (boost::bad_lexical_cast &)
                    {
                        boost::put(f,name,0.0);
                    }
                }
                else
                {
                    try
                    {
                        int i =  boost::lexical_cast<int>(str);
                        boost::put(f,name,i);
                    }
                    catch (boost::lexical_cast &)
                    {
                        boost::put(f,name,0);
                    }
                }
                break;
            }
        }
    }
}

void dbf_file::read_header()
{
    char c=file_.get();
    if (c=='\3' || c=='\131')
    {
        skip(3);
        num_records_=read_int();
        assert(num_records_>0);
        num_fields_=read_short();
        assert(num_fields_>0);
        num_fields_=(num_fields_-33)/32;
        skip(22);
        int offset=0;
        char name[11];
        memset(&name,0,11);
        fields_.reserve(num_fields_);
        for (int i=0;i<num_fields_;++i)
        {
            field_descriptor desc;
            desc.index_=i;
            file_.read(name,10);
            desc.name_=boost::trim_left_copy(std::string(name));
            skip(1);
            desc.type_=file_.get();
            skip(4);
            desc.length_=file_.get();
            desc.dec_=file_.get();
            skip(14);
            desc.offset_=offset;
            offset+=desc.length_;
            fields_.push_back(desc);
        }
        record_length_=offset;
        if (record_length_>0)
        {
            record_=static_cast<char*>(::operator new (sizeof(char)*record_length_));
        }
    }
}

int dbf_file::read_short()
{
    char b[2];
    file_.read(b,2);
    return (b[0] & 0xff) | (b[1] & 0xff) << 8;
}

int dbf_file::read_int()
{
    char b[4];
    file_.read(b,4);
    return (b[0] & 0xff) | (b[1] & 0xff) << 8 |
        (b[2] & 0xff) << 16 | (b[3] & 0xff) <<24;
}

void dbf_file::skip(int bytes)
{
    file_.seekg(bytes,std::ios::cur);
}
<|endoftext|>


<commit_before> /*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: accfrmobjmap.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 02:49: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
 *
 ************************************************************************/

#pragma hdrstop

#ifndef _DOC_HXX
#include <doc.hxx>
#endif
#ifndef _FRMFMT_HXX
#include <frmfmt.hxx>
#endif
#ifndef _PAGEFRM_HXX
#include <pagefrm.hxx>
#endif
#ifndef _TXTFRM_HXX
#include <txtfrm.hxx>
#endif
#ifndef _NODE_HXX
#include <node.hxx>
#endif
// OD 2004-05-24 #i28701#
#ifndef _SORTEDOBJS_HXX
#include <sortedobjs.hxx>
#endif

#ifndef _ACCFFRMOBJMAP_HXX
#include <accfrmobjmap.hxx>
#endif

::std::pair< SwFrmOrObjMap::iterator, bool > SwFrmOrObjMap::insert(
        sal_uInt32 nPos, const SwFrmOrObj& rLower )
{
    SwFrmOrObjMapKey aKey( SwFrmOrObjMapKey::TEXT, nPos );
    value_type aEntry( aKey, rLower );
    return _SwFrmOrObjMap::insert( aEntry );
}

::std::pair< SwFrmOrObjMap::iterator, bool > SwFrmOrObjMap::insert(
        const SdrObject *pObj, const SwFrmOrObj& rLower, const SwDoc *pDoc )
{
    if( !bLayerIdsValid )
    {
        nHellId = pDoc->GetHellId();
        nControlsId = pDoc->GetControlsId();
        bLayerIdsValid = sal_True;
    }

    SdrLayerID nLayer = pObj->GetLayer();
    SwFrmOrObjMapKey::LayerId eLayerId = (nHellId == nLayer)
                    ? SwFrmOrObjMapKey::HELL
                    : ((nControlsId == nLayer) ? SwFrmOrObjMapKey::CONTROLS
                                               : SwFrmOrObjMapKey::HEAVEN);
    SwFrmOrObjMapKey aKey( eLayerId, pObj->GetOrdNum() );
    value_type aEntry( aKey, rLower );
    return _SwFrmOrObjMap::insert( aEntry );
}

SwFrmOrObjMap::SwFrmOrObjMap(
        const SwRect& rVisArea, const SwFrm *pFrm ) :
    bLayerIdsValid( sal_False )
{
    SwFrmOrObj aFrm( pFrm );
    sal_Bool bVisibleOnly = aFrm.IsVisibleChildrenOnly();

    sal_uInt32 nPos = 0;
    SwFrmOrObj aLower( pFrm->GetLower() );
    while( aLower.GetSwFrm() )
    {
        if( !bVisibleOnly || aLower.GetBox().IsOver( rVisArea ) )
            insert( nPos++, aLower );

        aLower = aLower.GetSwFrm()->GetNext();
    }

    if( pFrm->IsPageFrm() )
    {
        ASSERT( bVisibleOnly, "page frame within tab frame???" );
        const SwPageFrm *pPgFrm =
            static_cast< const SwPageFrm * >( pFrm );
        const SwSortedObjs *pObjs = pPgFrm->GetSortedObjs();
        if( pObjs )
        {
            const SwDoc *pDoc = pPgFrm->GetFmt()->GetDoc();
            for( sal_uInt16 i=0; i<pObjs->Count(); i++ )
            {
                aLower = (*pObjs)[i]->GetDrawObj();
                if( aLower.GetBox().IsOver( rVisArea ) )
                    insert( aLower.GetSdrObject(), aLower, pDoc );
            }
        }
    }
    else if( pFrm->IsTxtFrm() )
    {
        const SwDoc *pDoc = static_cast< const SwTxtFrm * >( pFrm )->GetNode()
                                                                   ->GetDoc();
        const SwSortedObjs *pObjs = pFrm->GetDrawObjs();
        if( pObjs )
        {
            for( sal_uInt16 i=0; i<pObjs->Count(); i++ )
            {
                aLower = (*pObjs)[i]->GetDrawObj();
                if( aLower.IsBoundAsChar() &&
                    (!bVisibleOnly || aLower.GetBox().IsOver( rVisArea )) )
                    insert( aLower.GetSdrObject(), aLower, pDoc );
            }
        }
    }
}
<commit_msg>INTEGRATION: CWS pchfix02 (1.6.476); FILE MERGED 2006/09/01 17:51:12 kaib 1.6.476.1: #i68856# Added header markers and pch files<commit_after> /*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: accfrmobjmap.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-16 20:35:48 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

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

#ifndef _DOC_HXX
#include <doc.hxx>
#endif
#ifndef _FRMFMT_HXX
#include <frmfmt.hxx>
#endif
#ifndef _PAGEFRM_HXX
#include <pagefrm.hxx>
#endif
#ifndef _TXTFRM_HXX
#include <txtfrm.hxx>
#endif
#ifndef _NODE_HXX
#include <node.hxx>
#endif
// OD 2004-05-24 #i28701#
#ifndef _SORTEDOBJS_HXX
#include <sortedobjs.hxx>
#endif

#ifndef _ACCFFRMOBJMAP_HXX
#include <accfrmobjmap.hxx>
#endif

::std::pair< SwFrmOrObjMap::iterator, bool > SwFrmOrObjMap::insert(
        sal_uInt32 nPos, const SwFrmOrObj& rLower )
{
    SwFrmOrObjMapKey aKey( SwFrmOrObjMapKey::TEXT, nPos );
    value_type aEntry( aKey, rLower );
    return _SwFrmOrObjMap::insert( aEntry );
}

::std::pair< SwFrmOrObjMap::iterator, bool > SwFrmOrObjMap::insert(
        const SdrObject *pObj, const SwFrmOrObj& rLower, const SwDoc *pDoc )
{
    if( !bLayerIdsValid )
    {
        nHellId = pDoc->GetHellId();
        nControlsId = pDoc->GetControlsId();
        bLayerIdsValid = sal_True;
    }

    SdrLayerID nLayer = pObj->GetLayer();
    SwFrmOrObjMapKey::LayerId eLayerId = (nHellId == nLayer)
                    ? SwFrmOrObjMapKey::HELL
                    : ((nControlsId == nLayer) ? SwFrmOrObjMapKey::CONTROLS
                                               : SwFrmOrObjMapKey::HEAVEN);
    SwFrmOrObjMapKey aKey( eLayerId, pObj->GetOrdNum() );
    value_type aEntry( aKey, rLower );
    return _SwFrmOrObjMap::insert( aEntry );
}

SwFrmOrObjMap::SwFrmOrObjMap(
        const SwRect& rVisArea, const SwFrm *pFrm ) :
    bLayerIdsValid( sal_False )
{
    SwFrmOrObj aFrm( pFrm );
    sal_Bool bVisibleOnly = aFrm.IsVisibleChildrenOnly();

    sal_uInt32 nPos = 0;
    SwFrmOrObj aLower( pFrm->GetLower() );
    while( aLower.GetSwFrm() )
    {
        if( !bVisibleOnly || aLower.GetBox().IsOver( rVisArea ) )
            insert( nPos++, aLower );

        aLower = aLower.GetSwFrm()->GetNext();
    }

    if( pFrm->IsPageFrm() )
    {
        ASSERT( bVisibleOnly, "page frame within tab frame???" );
        const SwPageFrm *pPgFrm =
            static_cast< const SwPageFrm * >( pFrm );
        const SwSortedObjs *pObjs = pPgFrm->GetSortedObjs();
        if( pObjs )
        {
            const SwDoc *pDoc = pPgFrm->GetFmt()->GetDoc();
            for( sal_uInt16 i=0; i<pObjs->Count(); i++ )
            {
                aLower = (*pObjs)[i]->GetDrawObj();
                if( aLower.GetBox().IsOver( rVisArea ) )
                    insert( aLower.GetSdrObject(), aLower, pDoc );
            }
        }
    }
    else if( pFrm->IsTxtFrm() )
    {
        const SwDoc *pDoc = static_cast< const SwTxtFrm * >( pFrm )->GetNode()
                                                                   ->GetDoc();
        const SwSortedObjs *pObjs = pFrm->GetDrawObjs();
        if( pObjs )
        {
            for( sal_uInt16 i=0; i<pObjs->Count(); i++ )
            {
                aLower = (*pObjs)[i]->GetDrawObj();
                if( aLower.IsBoundAsChar() &&
                    (!bVisibleOnly || aLower.GetBox().IsOver( rVisArea )) )
                    insert( aLower.GetSdrObject(), aLower, pDoc );
            }
        }
    }
}
<|endoftext|>


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

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

class SwFrm;
// --> OD 2004-10-08 #i26945#
class SwTxtFrm;
// <--
class SwLayoutFrm;
class SwPageFrm;
class SwAnchoredObject;
class SwLayAction;
// --> OD 2004-10-04 #i26945#
class SwPageNumAndTypeOfAnchors;
// <--

// -----------------------------------------------------------------------------
// OD 2004-06-25 #i28701#
// Format floating screen objects, which are anchored at the given anchor frame
// and registered at the given page frame.
// -----------------------------------------------------------------------------
class SwObjectFormatter
{
    private:
        // page frame, at which the floating screen objects are registered.
        const SwPageFrm& mrPageFrm;

        // boolean, indicating that only as-character anchored objects have to
        // be formatted.
        bool mbFormatOnlyAsCharAnchored;

        // value of document compatibility option 'Consider wrapping style on
        // object positioning'
        const bool mbConsiderWrapOnObjPos;

        // layout action calling the format of the floating screen objects
        SwLayAction* mpLayAction;

        // data structure to collect page number of object's 'anchor'
        // --> OD 2004-10-04 #i26945#
        SwPageNumAndTypeOfAnchors* mpPgNumAndTypeOfAnchors;
        // <--

        /** helper method for method <_FormatObj(..)> - performs the intrinsic
            format of the layout of the given layout frame and all its lower
            layout frames.

            OD 2004-06-28 #i28701#
            IMPORTANT NOTE:
            Method corresponds to methods <SwLayAction::FormatLayoutFly(..)> and
            <SwLayAction::FormatLayout(..)>. Thus, its code for the formatting have
            to be synchronised.

            @author OD
        */
        void _FormatLayout( SwLayoutFrm& _rLayoutFrm );

        /** helper method for method <_FormatObj(..)> - performs the intrinsic
            format of the content of the given floating screen object.

            OD 2004-06-28 #i28701#

            @author OD
        */
        void _FormatObjCntnt( SwAnchoredObject& _rAnchoredObj );

    protected:
        SwObjectFormatter( const SwPageFrm& _rPageFrm,
                           SwLayAction* _pLayAction = 0L,
                           const bool _bCollectPgNumOfAnchors = false );

        static SwObjectFormatter* CreateObjFormatter( SwFrm& _rAnchorFrm,
                                                      const SwPageFrm& _rPageFrm,
                                                      SwLayAction* _pLayAction );

        virtual SwFrm& GetAnchorFrm() = 0;
        const SwPageFrm& GetPageFrm() const;
        const bool FormatOnlyAsCharAnchored() const;
        const bool ConsiderWrapOnObjPos() const;
        SwLayAction* GetLayAction();

        /** method to restrict the format of floating screen objects to
            as-character anchored ones

            @author OD
        */
        void SetFormatOnlyAsCharAnchored();

        /** performs the intrinsic format of a given floating screen object and its content.

            OD 2004-06-28 #i28701#

            @author OD
        */
        void _FormatObj( SwAnchoredObject& _rAnchoredObj );

        /** invokes the intrinsic format method for all floating screen objects,
            anchored at anchor frame on the given page frame

            OD 2004-06-28 #i28701#
            OD 2004-10-08 #i26945# - for format of floating screen objects for
            follow text frames, the 'master' text frame is passed to the method.
            Thus, the objects, whose anchor character is inside the follow text
            frame can be formatted.

            @author OD

            @param _pMasterTxtFrm
            input parameter - pointer to 'master' text frame. default value: NULL
        */
        bool _FormatObjsAtFrm( SwTxtFrm* _pMasterTxtFrm = 0L );

        /** accessor to collected anchored object

            OD 2004-07-05 #i28701#

            @author OD
        */
        SwAnchoredObject* GetCollectedObj( const sal_uInt32 _nIndex );

        /** accessor to 'anchor' page number of collected anchored object

            OD 2004-07-05 #i28701#

            @author OD
        */
        sal_uInt32 GetPgNumOfCollected( const sal_uInt32 _nIndex );

        /** accessor to 'anchor' type of collected anchored object

            OD 2004-10-04 #i26945#

            @author OD
        */
        bool IsCollectedAnchoredAtMaster( const sal_uInt32 _nIndex );

        /** accessor to total number of collected anchored objects

            OD 2004-07-05 #i28701#

            @author OD
        */
        sal_uInt32 CountOfCollected();

    public:
        virtual ~SwObjectFormatter();

        /** intrinsic method to format a certain floating screen object

            OD 2005-01-10 #i40147# - add parameter <_bCheckForMovedFwd>

            @author OD

            @param _rAnchoredObj
            input parameter - anchored object, which have to be formatted.

            @param _bCheckForMovedFwd
            input parameter - boolean indicating, that after a successful
            format of the anchored object the anchor frame has to be checked,
            if it would moved forward due to the positioning of the anchored object.
            default value: false
            value only considered, if wrapping style influence has to be
            considered for the positioning of the anchored object.
        */
        virtual bool DoFormatObj( SwAnchoredObject& _rAnchoredObj,
                                  const bool _bCheckForMovedFwd = false ) = 0;

        /** intrinsic method to format all floating screen objects

            @author OD
        */
        virtual bool DoFormatObjs() = 0;

        /** method to format all floating screen objects at the given anchor frame

            @author OD
        */
        static bool FormatObjsAtFrm( SwFrm& _rAnchorFrm,
                                     const SwPageFrm& _rPageFrm,
                                     SwLayAction* _pLayAction = 0L );

        /** method to format all as-character anchored floating screen objects
            at the given anchor frame

            @author OD
        */
        static bool FormatAsCharAnchoredObjsAtFrm( SwFrm& _rAnchorFrm,
                                                   const SwPageFrm& _rPageFrm,
                                                   SwLayAction* _pLayAction = 0L );

        /** method to format a given floating screen object

            @author OD
        */
        static bool FormatObj( SwAnchoredObject& _rAnchoredObj,
                               SwFrm* _pAnchorFrm = 0L,
                               const SwPageFrm* _pPageFrm = 0L,
                               SwLayAction* _pLayAction = 0L );
};

#endif
<commit_msg>INTEGRATION: CWS ooo19126 (1.4.372); FILE MERGED 2005/09/05 13:40:02 rt 1.4.372.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: objectformatter.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 03:52:28 $
 *
 *  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 _OBJECTFORMATTER_HXX
#define _OBJECTFORMATTER_HXX

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

class SwFrm;
// --> OD 2004-10-08 #i26945#
class SwTxtFrm;
// <--
class SwLayoutFrm;
class SwPageFrm;
class SwAnchoredObject;
class SwLayAction;
// --> OD 2004-10-04 #i26945#
class SwPageNumAndTypeOfAnchors;
// <--

// -----------------------------------------------------------------------------
// OD 2004-06-25 #i28701#
// Format floating screen objects, which are anchored at the given anchor frame
// and registered at the given page frame.
// -----------------------------------------------------------------------------
class SwObjectFormatter
{
    private:
        // page frame, at which the floating screen objects are registered.
        const SwPageFrm& mrPageFrm;

        // boolean, indicating that only as-character anchored objects have to
        // be formatted.
        bool mbFormatOnlyAsCharAnchored;

        // value of document compatibility option 'Consider wrapping style on
        // object positioning'
        const bool mbConsiderWrapOnObjPos;

        // layout action calling the format of the floating screen objects
        SwLayAction* mpLayAction;

        // data structure to collect page number of object's 'anchor'
        // --> OD 2004-10-04 #i26945#
        SwPageNumAndTypeOfAnchors* mpPgNumAndTypeOfAnchors;
        // <--

        /** helper method for method <_FormatObj(..)> - performs the intrinsic
            format of the layout of the given layout frame and all its lower
            layout frames.

            OD 2004-06-28 #i28701#
            IMPORTANT NOTE:
            Method corresponds to methods <SwLayAction::FormatLayoutFly(..)> and
            <SwLayAction::FormatLayout(..)>. Thus, its code for the formatting have
            to be synchronised.

            @author OD
        */
        void _FormatLayout( SwLayoutFrm& _rLayoutFrm );

        /** helper method for method <_FormatObj(..)> - performs the intrinsic
            format of the content of the given floating screen object.

            OD 2004-06-28 #i28701#

            @author OD
        */
        void _FormatObjCntnt( SwAnchoredObject& _rAnchoredObj );

    protected:
        SwObjectFormatter( const SwPageFrm& _rPageFrm,
                           SwLayAction* _pLayAction = 0L,
                           const bool _bCollectPgNumOfAnchors = false );

        static SwObjectFormatter* CreateObjFormatter( SwFrm& _rAnchorFrm,
                                                      const SwPageFrm& _rPageFrm,
                                                      SwLayAction* _pLayAction );

        virtual SwFrm& GetAnchorFrm() = 0;
        const SwPageFrm& GetPageFrm() const;
        const bool FormatOnlyAsCharAnchored() const;
        const bool ConsiderWrapOnObjPos() const;
        SwLayAction* GetLayAction();

        /** method to restrict the format of floating screen objects to
            as-character anchored ones

            @author OD
        */
        void SetFormatOnlyAsCharAnchored();

        /** performs the intrinsic format of a given floating screen object and its content.

            OD 2004-06-28 #i28701#

            @author OD
        */
        void _FormatObj( SwAnchoredObject& _rAnchoredObj );

        /** invokes the intrinsic format method for all floating screen objects,
            anchored at anchor frame on the given page frame

            OD 2004-06-28 #i28701#
            OD 2004-10-08 #i26945# - for format of floating screen objects for
            follow text frames, the 'master' text frame is passed to the method.
            Thus, the objects, whose anchor character is inside the follow text
            frame can be formatted.

            @author OD

            @param _pMasterTxtFrm
            input parameter - pointer to 'master' text frame. default value: NULL
        */
        bool _FormatObjsAtFrm( SwTxtFrm* _pMasterTxtFrm = 0L );

        /** accessor to collected anchored object

            OD 2004-07-05 #i28701#

            @author OD
        */
        SwAnchoredObject* GetCollectedObj( const sal_uInt32 _nIndex );

        /** accessor to 'anchor' page number of collected anchored object

            OD 2004-07-05 #i28701#

            @author OD
        */
        sal_uInt32 GetPgNumOfCollected( const sal_uInt32 _nIndex );

        /** accessor to 'anchor' type of collected anchored object

            OD 2004-10-04 #i26945#

            @author OD
        */
        bool IsCollectedAnchoredAtMaster( const sal_uInt32 _nIndex );

        /** accessor to total number of collected anchored objects

            OD 2004-07-05 #i28701#

            @author OD
        */
        sal_uInt32 CountOfCollected();

    public:
        virtual ~SwObjectFormatter();

        /** intrinsic method to format a certain floating screen object

            OD 2005-01-10 #i40147# - add parameter <_bCheckForMovedFwd>

            @author OD

            @param _rAnchoredObj
            input parameter - anchored object, which have to be formatted.

            @param _bCheckForMovedFwd
            input parameter - boolean indicating, that after a successful
            format of the anchored object the anchor frame has to be checked,
            if it would moved forward due to the positioning of the anchored object.
            default value: false
            value only considered, if wrapping style influence has to be
            considered for the positioning of the anchored object.
        */
        virtual bool DoFormatObj( SwAnchoredObject& _rAnchoredObj,
                                  const bool _bCheckForMovedFwd = false ) = 0;

        /** intrinsic method to format all floating screen objects

            @author OD
        */
        virtual bool DoFormatObjs() = 0;

        /** method to format all floating screen objects at the given anchor frame

            @author OD
        */
        static bool FormatObjsAtFrm( SwFrm& _rAnchorFrm,
                                     const SwPageFrm& _rPageFrm,
                                     SwLayAction* _pLayAction = 0L );

        /** method to format all as-character anchored floating screen objects
            at the given anchor frame

            @author OD
        */
        static bool FormatAsCharAnchoredObjsAtFrm( SwFrm& _rAnchorFrm,
                                                   const SwPageFrm& _rPageFrm,
                                                   SwLayAction* _pLayAction = 0L );

        /** method to format a given floating screen object

            @author OD
        */
        static bool FormatObj( SwAnchoredObject& _rAnchoredObj,
                               SwFrm* _pAnchorFrm = 0L,
                               const SwPageFrm* _pPageFrm = 0L,
                               SwLayAction* _pLayAction = 0L );
};

#endif
<|endoftext|>


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

#pragma hdrstop

#ifndef _SFX_BINDINGS_HXX //autogen
#include <sfx2/bindings.hxx>
#endif
#ifndef _SVX_HTMLMODE_HXX //autogen
#include <svx/htmlmode.hxx>
#endif
#ifndef sdtacitm_hxx //autogen
#include <svx/sdtacitm.hxx>
#endif
#ifndef _SVDOBJ_HXX //autogen
#include <svx/svdobj.hxx>
#endif
#ifndef _SDTAGITM_HXX //autogen
#include <svx/sdtagitm.hxx>
#endif
#ifndef SDTAKITM_HXX //autogen
#include <svx/sdtakitm.hxx>
#endif
#ifndef _SDTADITM_HXX //autogen
#include <svx/sdtaditm.hxx>
#endif
#ifndef _SDTAAITM_HXX //autogen
#include <svx/sdtaaitm.hxx>
#endif
#ifndef _SVDVIEW_HXX //autogen
#include <svx/svdview.hxx>
#endif
#ifndef _SFXVIEWFRM_HXX
#include <sfx2/viewfrm.hxx>
#endif
#ifndef _SVDCAPT_HXX
#include <svx/svdocapt.hxx>
#endif
#ifndef _OUTLOBJ_HXX
#include <svx/outlobj.hxx>
#endif

#ifndef _CMDID_H
#include <cmdid.h>
#endif
#ifndef _VIEW_HXX
#include <view.hxx>
#endif
#ifndef _EDTWIN_HXX
#include <edtwin.hxx>
#endif
#ifndef _WRTSH_HXX
#include <wrtsh.hxx>
#endif
#ifndef _VIEWOPT_HXX
#include <viewopt.hxx>
#endif
#ifndef _DRAWBASE_HXX
#include <drawbase.hxx>
#endif
#ifndef _SW_CONCUSTOMSHAPE_HXX
#include <concustomshape.hxx>
#endif
#ifndef _GALLERY_HXX_
#include <svx/gallery.hxx>
#endif
#ifndef _SFXREQUEST_HXX //autogen
#include <sfx2/request.hxx>
#endif
#ifndef _FM_FMMODEL_HXX
#include <svx/fmmodel.hxx>
#endif
#ifndef _SFXITEMPOOL_HXX
#include <svtools/itempool.hxx>
#endif
#ifndef _SVDPAGE_HXX
#include <svx/svdpage.hxx>
#endif
#ifndef _SVDOASHP_HXX
#include <svx/svdoashp.hxx>
#endif
#ifndef _SDTAGITM_HXX
#include <svx/sdtagitm.hxx>
#endif

/*************************************************************************
|*
|* C'Tor
|*
\************************************************************************/
ConstCustomShape::ConstCustomShape( SwWrtShell* pWrtShell, SwEditWin* pEditWin, SwView* pSwView, SfxRequest& rReq )
    : SwDrawBase( pWrtShell, pEditWin, pSwView )
{
    const SfxItemSet* pArgs = rReq.GetArgs();
    if ( pArgs )
    {
        const SfxStringItem& rItm = (const SfxStringItem&)pArgs->Get( rReq.GetSlot() );
        aCustomShape = rItm.GetValue();
    }
}

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

BOOL ConstCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
{
    BOOL bReturn = SwDrawBase::MouseButtonDown(rMEvt);
    if ( bReturn )
    {
        SdrView *pSdrView = pSh->GetDrawView();
        if ( pSdrView )
        {
            SdrObject* pObj = pSdrView->GetCreateObj();
            if ( pObj )
            {
                SetAttributes( pObj );
                sal_Bool bForceFillStyle = sal_True;
                sal_Bool bForceNoFillStyle = sal_False;
                if ( ((SdrObjCustomShape*)pObj)->UseNoFillStyle() )
                {
                    bForceFillStyle = sal_False;
                    bForceNoFillStyle = sal_True;
                }

                SfxItemSet aAttr( pView->GetPool() );
                if ( bForceNoFillStyle )
                    aAttr.Put( XFillStyleItem( XFILL_NONE ) );
                pObj->SetMergedItemSet(aAttr);
            }
        }
    }
    return bReturn;
}

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

BOOL ConstCustomShape::MouseButtonUp(const MouseEvent& rMEvt)
{
    return SwDrawBase::MouseButtonUp(rMEvt);
}

/*************************************************************************
|*
|* activate function
|*
\************************************************************************/

void ConstCustomShape::Activate(const USHORT nSlotId)
{
    pWin->SetDrawMode( OBJ_CUSTOMSHAPE );

    SwDrawBase::Activate(nSlotId);
}

/*************************************************************************
|*
|* applying attributes
|*
\************************************************************************/

void ConstCustomShape::SetAttributes( SdrObject* pObj )
{
    sal_Bool bAttributesAppliedFromGallery = sal_False;

    SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
    if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
    {
        std::vector< rtl::OUString > aObjList;
        if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
        {
            sal_uInt16 i;
            for ( i = 0; i < aObjList.size(); i++ )
            {
                if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
                {
                    FmFormModel aFormModel;
                    SfxItemPool& rPool = aFormModel.GetItemPool();
                    rPool.FreezeIdRanges();
                    if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
                    {
                        const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
                        if( pSourceObj )
                        {
                            const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
                            SfxItemSet aDest( pObj->GetModel()->GetItemPool(),              // ranges from SdrAttrObj
                            SDRATTR_START, SDRATTR_SHADOW_LAST,
                            SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
                            SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
                            // Graphic Attributes
                            SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
                            // 3d Properties
                            SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
                            // CustomShape properties
                            SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
                            // range from SdrTextObj
                            EE_ITEMS_START, EE_ITEMS_END,
                            // end
                            0, 0);
                            aDest.Set( rSource );
                            pObj->SetMergedItemSet( aDest );
                            sal_Int32 nAngle = pSourceObj->GetRotateAngle();
                            if ( nAngle )
                            {
                                double a = nAngle * F_PI18000;
                                pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
                            }
                            bAttributesAppliedFromGallery = sal_True;
                        }
                    }
                    break;
                }
            }
        }
    }
    if ( !bAttributesAppliedFromGallery )
    {
        const rtl::OUString sPredefinedType( RTL_CONSTASCII_USTRINGPARAM ( "PredefinedType" ) );
        com::sun::star::beans::PropertyValue aPropVal;
        aPropVal.Name = sPredefinedType;
        aPropVal.Value <<= aCustomShape;
        aGeometryItem.SetPropertyValue( aPropVal );
        pObj->SetMergedItem( aGeometryItem );
        pObj->SetMergedItem( SdrTextAutoGrowHeightItem( sal_False ) );
    }
}

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

#pragma hdrstop

#ifndef _SFX_BINDINGS_HXX //autogen
#include <sfx2/bindings.hxx>
#endif
#ifndef _SVX_HTMLMODE_HXX //autogen
#include <svx/htmlmode.hxx>
#endif
#ifndef sdtacitm_hxx //autogen
#include <svx/sdtacitm.hxx>
#endif
#ifndef _SVDOBJ_HXX //autogen
#include <svx/svdobj.hxx>
#endif
#ifndef _SDTAGITM_HXX //autogen
#include <svx/sdtagitm.hxx>
#endif
#ifndef SDTAKITM_HXX //autogen
#include <svx/sdtakitm.hxx>
#endif
#ifndef _SDTADITM_HXX //autogen
#include <svx/sdtaditm.hxx>
#endif
#ifndef _SDTAAITM_HXX //autogen
#include <svx/sdtaaitm.hxx>
#endif
#ifndef _SVDVIEW_HXX //autogen
#include <svx/svdview.hxx>
#endif
#ifndef _SFXVIEWFRM_HXX
#include <sfx2/viewfrm.hxx>
#endif
#ifndef _SVDCAPT_HXX
#include <svx/svdocapt.hxx>
#endif
#ifndef _OUTLOBJ_HXX
#include <svx/outlobj.hxx>
#endif

#ifndef _CMDID_H
#include <cmdid.h>
#endif
#ifndef _VIEW_HXX
#include <view.hxx>
#endif
#ifndef _EDTWIN_HXX
#include <edtwin.hxx>
#endif
#ifndef _WRTSH_HXX
#include <wrtsh.hxx>
#endif
#ifndef _VIEWOPT_HXX
#include <viewopt.hxx>
#endif
#ifndef _DRAWBASE_HXX
#include <drawbase.hxx>
#endif
#ifndef _SW_CONCUSTOMSHAPE_HXX
#include <concustomshape.hxx>
#endif
#ifndef _GALLERY_HXX_
#include <svx/gallery.hxx>
#endif
#ifndef _SFXREQUEST_HXX //autogen
#include <sfx2/request.hxx>
#endif
#ifndef _FM_FMMODEL_HXX
#include <svx/fmmodel.hxx>
#endif
#ifndef _SFXITEMPOOL_HXX
#include <svtools/itempool.hxx>
#endif
#ifndef _SVDPAGE_HXX
#include <svx/svdpage.hxx>
#endif
#ifndef _SVDOASHP_HXX
#include <svx/svdoashp.hxx>
#endif
#ifndef _SDTAGITM_HXX
#include <svx/sdtagitm.hxx>
#endif

/*************************************************************************
|*
|* C'Tor
|*
\************************************************************************/
ConstCustomShape::ConstCustomShape( SwWrtShell* pWrtShell, SwEditWin* pEditWin, SwView* pSwView, SfxRequest& rReq )
    : SwDrawBase( pWrtShell, pEditWin, pSwView )
{
    const SfxItemSet* pArgs = rReq.GetArgs();
    if ( pArgs )
    {
        const SfxStringItem& rItm = (const SfxStringItem&)pArgs->Get( rReq.GetSlot() );
        aCustomShape = rItm.GetValue();
    }
}

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

BOOL ConstCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
{
    BOOL bReturn = SwDrawBase::MouseButtonDown(rMEvt);
    if ( bReturn )
    {
        SdrView *pSdrView = pSh->GetDrawView();
        if ( pSdrView )
        {
            SdrObject* pObj = pSdrView->GetCreateObj();
            if ( pObj )
            {
                SetAttributes( pObj );
                sal_Bool bForceFillStyle = sal_True;
                sal_Bool bForceNoFillStyle = sal_False;
                if ( ((SdrObjCustomShape*)pObj)->UseNoFillStyle() )
                {
                    bForceFillStyle = sal_False;
                    bForceNoFillStyle = sal_True;
                }

                SfxItemSet aAttr( pView->GetPool() );
                if ( bForceNoFillStyle )
                    aAttr.Put( XFillStyleItem( XFILL_NONE ) );
                pObj->SetMergedItemSet(aAttr);
            }
        }
    }
    return bReturn;
}

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

BOOL ConstCustomShape::MouseButtonUp(const MouseEvent& rMEvt)
{
    return SwDrawBase::MouseButtonUp(rMEvt);
}

/*************************************************************************
|*
|* activate function
|*
\************************************************************************/

void ConstCustomShape::Activate(const USHORT nSlotId)
{
    pWin->SetDrawMode( OBJ_CUSTOMSHAPE );

    SwDrawBase::Activate(nSlotId);
}

/*************************************************************************
|*
|* applying attributes
|*
\************************************************************************/

void ConstCustomShape::SetAttributes( SdrObject* pObj )
{
    sal_Bool bAttributesAppliedFromGallery = sal_False;

    SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
    if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
    {
        std::vector< rtl::OUString > aObjList;
        if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
        {
            sal_uInt16 i;
            for ( i = 0; i < aObjList.size(); i++ )
            {
                if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
                {
                    FmFormModel aFormModel;
                    SfxItemPool& rPool = aFormModel.GetItemPool();
                    rPool.FreezeIdRanges();
                    if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
                    {
                        const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
                        if( pSourceObj )
                        {
                            const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
                            SfxItemSet aDest( pObj->GetModel()->GetItemPool(),              // ranges from SdrAttrObj
                            SDRATTR_START, SDRATTR_SHADOW_LAST,
                            SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
                            SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
                            // Graphic Attributes
                            SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
                            // 3d Properties
                            SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
                            // CustomShape properties
                            SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
                            // range from SdrTextObj
                            EE_ITEMS_START, EE_ITEMS_END,
                            // end
                            0, 0);
                            aDest.Set( rSource );
                            pObj->SetMergedItemSet( aDest );
                            sal_Int32 nAngle = pSourceObj->GetRotateAngle();
                            if ( nAngle )
                            {
                                double a = nAngle * F_PI18000;
                                pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
                            }
                            bAttributesAppliedFromGallery = sal_True;
                        }
                    }
                    break;
                }
            }
        }
    }
    if ( !bAttributesAppliedFromGallery )
    {
        const rtl::OUString sPredefinedType( RTL_CONSTASCII_USTRINGPARAM ( "PredefinedType" ) );
        com::sun::star::beans::PropertyValue aPropVal;
        aPropVal.Name = sPredefinedType;
        aPropVal.Value <<= aCustomShape;
        aGeometryItem.SetPropertyValue( aPropVal );
        pObj->SetMergedItem( aGeometryItem );
        pObj->SetMergedItem( SdrTextAutoGrowHeightItem( sal_False ) );
    }
}

// #i33136#
bool ConstCustomShape::doConstructOrthogonal() const
{
    return SdrObjCustomShape::doConstructOrthogonal(aCustomShape);
}

// eof
<|endoftext|>


<commit_before>/** @file

  an example plugin showing off how to use versioning

  @section license License

  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
 */

#include <ts/ts.h>

#define PLUGIN_NAME "hook-trace"

template <typename T, unsigned N>
static inline unsigned
countof(const T (&)[N])
{
  return N;
}

static int
HookTracer(TSCont contp, TSEvent event, void *edata)
{
  union {
    TSHttpTxn txn;
    TSHttpSsn ssn;
    TSHttpAltInfo alt;
    void *ptr;
  } ev;

  ev.ptr = edata;

  switch (event) {
  case TS_EVENT_HTTP_SSN_START:
    TSDebug(PLUGIN_NAME, "Received SSN_START on session %p", ev.ssn);
    TSHttpSsnReenable(ev.ssn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_SSN_CLOSE:
    TSDebug(PLUGIN_NAME, "Received SSN_CLOSE on session %p", ev.ssn);
    TSHttpSsnReenable(ev.ssn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_SELECT_ALT:
    TSDebug(PLUGIN_NAME, "Received SELECT_ALT on altinfo %p", ev.alt);
    break;

  case TS_EVENT_HTTP_READ_REQUEST_HDR:
    TSDebug(PLUGIN_NAME, "Received READ_REQUEST_HDR on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_OS_DNS:
    TSDebug(PLUGIN_NAME, "Received OS_DNS on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_SEND_REQUEST_HDR:
    TSDebug(PLUGIN_NAME, "Received SEND_REQUEST_HDR on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_READ_CACHE_HDR:
    TSDebug(PLUGIN_NAME, "Received READ_CACHE_HDR on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_READ_RESPONSE_HDR:
    TSDebug(PLUGIN_NAME, "Received READ_RESPONSE_HDR on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_SEND_RESPONSE_HDR:
    TSDebug(PLUGIN_NAME, "Received SEND_RESPONSE_HDR on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_TXN_START:
    TSDebug(PLUGIN_NAME, "Received TXN_START on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_TXN_CLOSE:
    TSDebug(PLUGIN_NAME, "Received TXN_CLOSE on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_CACHE_LOOKUP_COMPLETE:
    TSDebug(PLUGIN_NAME, "Received CACHE_LOOKUP_COMPLETE on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_PRE_REMAP:
    TSDebug(PLUGIN_NAME, "Received PRE_REMAP on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_POST_REMAP:
    TSDebug(PLUGIN_NAME, "Received POST_REMAP on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  default:
    break;
  }

  return TS_EVENT_NONE;
}

void
TSPluginInit(int argc, const char *argv[])
{
  // clang-format off
  static const TSHttpHookID hooks[] = {
    TS_HTTP_READ_REQUEST_HDR_HOOK,
    TS_HTTP_OS_DNS_HOOK,
    TS_HTTP_SEND_REQUEST_HDR_HOOK,
    TS_HTTP_READ_CACHE_HDR_HOOK,
    TS_HTTP_READ_RESPONSE_HDR_HOOK,
    TS_HTTP_SEND_RESPONSE_HDR_HOOK,
    TS_HTTP_SELECT_ALT_HOOK,
    TS_HTTP_TXN_START_HOOK,
    TS_HTTP_TXN_CLOSE_HOOK,
    TS_HTTP_SSN_START_HOOK,
    TS_HTTP_SSN_CLOSE_HOOK,
    TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK,
    TS_HTTP_PRE_REMAP_HOOK,
    TS_HTTP_POST_REMAP_HOOK,
  };
  // clang-format on

  (void)argc; // unused
  (void)argv; // unused

  TSPluginRegistrationInfo info;

  info.plugin_name   = (char *)PLUGIN_NAME;
  info.vendor_name   = (char *)"Apache Software Foundation";
  info.support_email = (char *)"dev@trafficserver.apache.org";

  for (unsigned i = 0; i < countof(hooks); ++i) {
    TSHttpHookAdd(hooks[i], TSContCreate(HookTracer, TSMutexCreate()));
  }

  TSReleaseAssert(TSPluginRegister(&info) == TS_SUCCESS);
}
<commit_msg>TS-4672: Add lifecycle events to hook-trace example plugin.<commit_after>/** @file

  an example plugin showing off how to use versioning

  @section license License

  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
 */

#include <ts/ts.h>

#define PLUGIN_NAME "hook-trace"

template <typename T, unsigned N>
static inline unsigned
countof(const T (&)[N])
{
  return N;
}

static int
HttpHookTracer(TSCont contp, TSEvent event, void *edata)
{
  union {
    TSHttpTxn txn;
    TSHttpSsn ssn;
    TSHttpAltInfo alt;
    void *ptr;
  } ev;

  ev.ptr = edata;

  switch (event) {
  case TS_EVENT_HTTP_SSN_START:
    TSDebug(PLUGIN_NAME, "Received SSN_START on session %p", ev.ssn);
    TSHttpSsnReenable(ev.ssn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_SSN_CLOSE:
    TSDebug(PLUGIN_NAME, "Received SSN_CLOSE on session %p", ev.ssn);
    TSHttpSsnReenable(ev.ssn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_SELECT_ALT:
    TSDebug(PLUGIN_NAME, "Received SELECT_ALT on altinfo %p", ev.alt);
    break;

  case TS_EVENT_HTTP_READ_REQUEST_HDR:
    TSDebug(PLUGIN_NAME, "Received READ_REQUEST_HDR on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_OS_DNS:
    TSDebug(PLUGIN_NAME, "Received OS_DNS on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_SEND_REQUEST_HDR:
    TSDebug(PLUGIN_NAME, "Received SEND_REQUEST_HDR on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_READ_CACHE_HDR:
    TSDebug(PLUGIN_NAME, "Received READ_CACHE_HDR on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_READ_RESPONSE_HDR:
    TSDebug(PLUGIN_NAME, "Received READ_RESPONSE_HDR on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_SEND_RESPONSE_HDR:
    TSDebug(PLUGIN_NAME, "Received SEND_RESPONSE_HDR on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_TXN_START:
    TSDebug(PLUGIN_NAME, "Received TXN_START on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_TXN_CLOSE:
    TSDebug(PLUGIN_NAME, "Received TXN_CLOSE on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_CACHE_LOOKUP_COMPLETE:
    TSDebug(PLUGIN_NAME, "Received CACHE_LOOKUP_COMPLETE on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_PRE_REMAP:
    TSDebug(PLUGIN_NAME, "Received PRE_REMAP on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  case TS_EVENT_HTTP_POST_REMAP:
    TSDebug(PLUGIN_NAME, "Received POST_REMAP on transaction %p", ev.txn);
    TSHttpTxnReenable(ev.txn, TS_EVENT_HTTP_CONTINUE);
    break;

  default:
    break;
  }

  return TS_EVENT_NONE;
}

static int
LifecycleHookTracer(TSCont contp, TSEvent event, void *edata)
{
  switch (event) {
  case TS_EVENT_LIFECYCLE_PORTS_INITIALIZED:
    TSDebug(PLUGIN_NAME, "Received LIFECYCLE_PORTS_INITIALIZED data %p", edata);
    break;

  case TS_EVENT_LIFECYCLE_PORTS_READY:
    TSDebug(PLUGIN_NAME, "Received LIFECYCLE_PORTS_READY data %p", edata);
    break;

  case TS_EVENT_LIFECYCLE_CACHE_READY:
    TSDebug(PLUGIN_NAME, "Received LIFECYCLE_CACHE_READY data %p", edata);
    break;

  case TS_EVENT_LIFECYCLE_SERVER_SSL_CTX_INITIALIZED:
    TSDebug(PLUGIN_NAME, "Received LIFECYCLE_SERVER_SSL_INITIALIZED data %p", edata);
    break;

  case TS_EVENT_LIFECYCLE_CLIENT_SSL_CTX_INITIALIZED:
    TSDebug(PLUGIN_NAME, "Received LIFECYCLE_CLIENT_SSL_CTX_INITIALIZED data %p", edata);
    break;

  case TS_EVENT_LIFECYCLE_MSG:
    TSDebug(PLUGIN_NAME, "Received LIFECYCLE_MSG data %p", edata);
    break;

  default:
    TSDebug(PLUGIN_NAME, "Received unsupported lifecycle event %d data %p", event, edata);
    break;
  }

  return TS_EVENT_NONE;
}

void
TSPluginInit(int argc, const char *argv[])
{
  // clang-format off
  static const TSHttpHookID http[] = {
    TS_HTTP_READ_REQUEST_HDR_HOOK,
    TS_HTTP_OS_DNS_HOOK,
    TS_HTTP_SEND_REQUEST_HDR_HOOK,
    TS_HTTP_READ_CACHE_HDR_HOOK,
    TS_HTTP_READ_RESPONSE_HDR_HOOK,
    TS_HTTP_SEND_RESPONSE_HDR_HOOK,
    TS_HTTP_SELECT_ALT_HOOK,
    TS_HTTP_TXN_START_HOOK,
    TS_HTTP_TXN_CLOSE_HOOK,
    TS_HTTP_SSN_START_HOOK,
    TS_HTTP_SSN_CLOSE_HOOK,
    TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK,
    TS_HTTP_PRE_REMAP_HOOK,
    TS_HTTP_POST_REMAP_HOOK,
  };

  static const TSLifecycleHookID lifecycle[] = {
    TS_LIFECYCLE_PORTS_INITIALIZED_HOOK,
    TS_LIFECYCLE_PORTS_READY_HOOK,
    TS_LIFECYCLE_CACHE_READY_HOOK,
    TS_LIFECYCLE_SERVER_SSL_CTX_INITIALIZED_HOOK,
    TS_LIFECYCLE_CLIENT_SSL_CTX_INITIALIZED_HOOK,
    TS_LIFECYCLE_MSG_HOOK,
  };

  // clang-format on

  (void)argc; // unused
  (void)argv; // unused

  TSPluginRegistrationInfo info;

  info.plugin_name   = (char *)PLUGIN_NAME;
  info.vendor_name   = (char *)"Apache Software Foundation";
  info.support_email = (char *)"dev@trafficserver.apache.org";

  for (unsigned i = 0; i < countof(http); ++i) {
    TSHttpHookAdd(http[i], TSContCreate(HttpHookTracer, TSMutexCreate()));
  }

  for (unsigned i = 0; i < countof(lifecycle); ++i) {
    TSLifecycleHookAdd(lifecycle[i], TSContCreate(LifecycleHookTracer, TSMutexCreate()));
  }

  TSReleaseAssert(TSPluginRegister(&info) == TS_SUCCESS);
}
<|endoftext|>


<commit_before>namespace mant {
  namespace bbob {
    class SchwefelFunction : public BlackBoxOptimisationBenchmark {
      public:
        inline explicit SchwefelFunction(
            const unsigned int numberOfDimensions) noexcept;

        inline std::string toString() const noexcept override;

      protected:
        const arma::Col<double> parameterConditioning_;

        inline double getObjectiveValueImplementation(
            const arma::Col<double>& parameter) const noexcept override;

#if defined(MANTELLA_USE_PARALLEL)
        friend class cereal::access;

        template <typename Archive>
        void serialize(
            Archive& archive) noexcept {
          archive(cereal::make_nvp("BlackBoxOptimisationBenchmark", cereal::base_class<BlackBoxOptimisationBenchmark>(this)));
          archive(cereal::make_nvp("numberOfDimensions", numberOfDimensions_));
          archive(cereal::make_nvp("parameterReflection", parameterReflection_));
        }

        template <typename Archive>
        static void load_and_construct(
            Archive& archive,
            cereal::construct<SchwefelFunction>& construct) noexcept {
          unsigned int numberOfDimensions;
          archive(cereal::make_nvp("numberOfDimensions", numberOfDimensions));
          construct(numberOfDimensions);

          archive(cereal::make_nvp("BlackBoxOptimisationBenchmark", cereal::base_class<BlackBoxOptimisationBenchmark>(construct.ptr())));
          archive(cereal::make_nvp("parameterReflection", construct->parameterReflection_));
        }
#endif
    };

    //
    // Implementation
    //

    inline SchwefelFunction::SchwefelFunction(
        const unsigned int numberOfDimensions) noexcept
      : BlackBoxOptimisationBenchmark(numberOfDimensions),
        parameterConditioning_(getParameterConditioning(std::sqrt(10.0))) {
      // A vector with all elements randomly and uniformly set to either 2 or -2.
      setParameterScaling(arma::zeros<arma::Col<double>>(numberOfDimensions_) + (std::bernoulli_distribution(0.5)(Rng::getGenerator()) ? 2.0 : -2.0));
    }

    inline double SchwefelFunction::getObjectiveValueImplementation(
        const arma::Col<double>& parameter) const noexcept {
      arma::Col<double> s = parameter;
      s.tail(s.n_elem - 1) += 0.25 * (s.head(s.n_elem - 1) - 4.2096874633);

      const arma::Col<double>& z = 100.0 * (parameterConditioning_ % (s - 4.2096874633) + 4.2096874633);

      return 0.01 * (418.9828872724339 - arma::dot(z, arma::sin(arma::sqrt(arma::abs(z)))) / static_cast<double>(numberOfDimensions_)) + 100.0 * getBoundConstraintsValue(z / 100.0);
    }

    inline std::string SchwefelFunction::toString() const noexcept {
      return "bbob_schwefel_function";
    }
  }
}

#if defined(MANTELLA_USE_PARALLEL)
CEREAL_REGISTER_TYPE(mant::bbob::SchwefelFunction);
#endif
<commit_msg>Removed obsolete API (parameterReflection)<commit_after>namespace mant {
  namespace bbob {
    class SchwefelFunction : public BlackBoxOptimisationBenchmark {
      public:
        inline explicit SchwefelFunction(
            const unsigned int numberOfDimensions) noexcept;

        inline std::string toString() const noexcept override;

      protected:
        const arma::Col<double> parameterConditioning_;

        inline double getObjectiveValueImplementation(
            const arma::Col<double>& parameter) const noexcept override;

#if defined(MANTELLA_USE_PARALLEL)
        friend class cereal::access;

        template <typename Archive>
        void serialize(
            Archive& archive) noexcept {
          archive(cereal::make_nvp("BlackBoxOptimisationBenchmark", cereal::base_class<BlackBoxOptimisationBenchmark>(this)));
          archive(cereal::make_nvp("numberOfDimensions", numberOfDimensions_));
        }

        template <typename Archive>
        static void load_and_construct(
            Archive& archive,
            cereal::construct<SchwefelFunction>& construct) noexcept {
          unsigned int numberOfDimensions;
          archive(cereal::make_nvp("numberOfDimensions", numberOfDimensions));
          construct(numberOfDimensions);

          archive(cereal::make_nvp("BlackBoxOptimisationBenchmark", cereal::base_class<BlackBoxOptimisationBenchmark>(construct.ptr())));
        }
#endif
    };

    //
    // Implementation
    //

    inline SchwefelFunction::SchwefelFunction(
        const unsigned int numberOfDimensions) noexcept
      : BlackBoxOptimisationBenchmark(numberOfDimensions),
        parameterConditioning_(getParameterConditioning(std::sqrt(10.0))) {
      // A vector with all elements randomly and uniformly set to either 2 or -2.
      setParameterScaling(arma::zeros<arma::Col<double>>(numberOfDimensions_) + (std::bernoulli_distribution(0.5)(Rng::getGenerator()) ? 2.0 : -2.0));
    }

    inline double SchwefelFunction::getObjectiveValueImplementation(
        const arma::Col<double>& parameter) const noexcept {
      arma::Col<double> s = parameter;
      s.tail(s.n_elem - 1) += 0.25 * (s.head(s.n_elem - 1) - 4.2096874633);

      const arma::Col<double>& z = 100.0 * (parameterConditioning_ % (s - 4.2096874633) + 4.2096874633);

      return 0.01 * (418.9828872724339 - arma::dot(z, arma::sin(arma::sqrt(arma::abs(z)))) / static_cast<double>(numberOfDimensions_)) + 100.0 * getBoundConstraintsValue(z / 100.0);
    }

    inline std::string SchwefelFunction::toString() const noexcept {
      return "bbob_schwefel_function";
    }
  }
}

#if defined(MANTELLA_USE_PARALLEL)
CEREAL_REGISTER_TYPE(mant::bbob::SchwefelFunction);
#endif
<|endoftext|>