<commit_before>// //////////////////////////////////////////////////////////////////////
// Import section
// //////////////////////////////////////////////////////////////////////
// STL
#include <cassert>
#include <iostream>
#include <string>
// STDAIR
#include <stdair/bom/BomRoot.hpp>
#include <stdair/bom/Inventory.hpp>
#include <stdair/factory/FacBomContent.hpp>
// AIRSCHED
#include <airsched/command/ScheduleParserHelper.hpp>
#include <airsched/command/ScheduleParser.hpp>
#include <airsched/command/InventoryGenerator.hpp>
#include <airsched/service/Logger.hpp>

namespace AIRSCHED {

  // //////////////////////////////////////////////////////////////////////
  stdair::BomRoot& ScheduleParser::
  generateInventories (const std::string& iFilename,
                       const stdair::AirlineFeatureSet& iAirlineFeatureSet,
                       const Date_T& iStartAnalysisDate) {
    stdair::BomRoot& oBomRoot =
      stdair::FacBomContent::instance().create<stdair::BomRoot> ();

    // Set the AirlineFeatureSet for the BomRoot.
    oBomRoot.setAirlineFeatureSet (&iAirlineFeatureSet);

    // Initialise the Flight-Period file parser.
    FlightPeriodFileParser lFlightPeriodParser (oBomRoot, iStartAnalysisDate,
                                                iFilename);

    // Parse the CSV-formatted schedule input file, and generate the
    // corresponding Inventories for the airlines.
    lFlightPeriodParser.generateInventories ();

    // Complete the BomRoot BOM building
    // Create the routings for all the inventories.
    InventoryGenerator::createDirectAccesses (oBomRoot);

    return oBomRoot;
  }

}
<commit_msg>Small adaptation to stdair.<commit_after>// //////////////////////////////////////////////////////////////////////
// Import section
// //////////////////////////////////////////////////////////////////////
// STL
#include <cassert>
#include <iostream>
#include <string>
// STDAIR
#include <stdair/bom/BomRoot.hpp>
#include <stdair/bom/Inventory.hpp>
#include <stdair/bom/Network.hpp>
#include <stdair/factory/FacBomContent.hpp>
// AIRSCHED
#include <airsched/command/ScheduleParserHelper.hpp>
#include <airsched/command/ScheduleParser.hpp>
#include <airsched/command/InventoryGenerator.hpp>
#include <airsched/service/Logger.hpp>

namespace AIRSCHED {

  // //////////////////////////////////////////////////////////////////////
  stdair::BomRoot& ScheduleParser::
  generateInventories (const std::string& iFilename,
                       const stdair::AirlineFeatureSet& iAirlineFeatureSet,
                       const Date_T& iStartAnalysisDate) {
    stdair::BomRoot& oBomRoot =
      stdair::FacBomContent::instance().create<stdair::BomRoot> ();

    // Set the AirlineFeatureSet for the BomRoot.
    oBomRoot.setAirlineFeatureSet (&iAirlineFeatureSet);

    // Initialise the Flight-Period file parser.
    FlightPeriodFileParser lFlightPeriodParser (oBomRoot, iStartAnalysisDate,
                                                iFilename);

    // Parse the CSV-formatted schedule input file, and generate the
    // corresponding Inventories for the airlines.
    lFlightPeriodParser.generateInventories ();

    // Complete the BomRoot BOM building
    // Create the routings for all the inventories.
    InventoryGenerator::createDirectAccesses (oBomRoot);

    return oBomRoot;
  }

}
<|endoftext|>


<commit_before>//
//  BackCurl.cpp
//  Created by Taymindis Woon on 23/5/17.
//  Copyright © 2017 Taymindis Woon. All rights reserved.
//

#include "BackCurl.h"

namespace bcl {

    /** If you activate mainLoopCallBack, please make sure bcl::LoopBackFire on the loop thread, for e.g. UI thread **/
    void init() {
        curl_global_init(CURL_GLOBAL_ALL);
    }

    void LoopBackFire() {
        while (!internal::_mainLoopTasks.empty()) {
            bcl::UniqueResponse response = std::move(internal::_mainLoopTasks.front());
            internal::_mainLoopTasks.pop_front();

            // lock during the task?
            internal::_tasks_mutex.lock();
            response->callBack(&(*response));
            internal::_tasks_mutex.unlock();
        }
    }

    bool isReady(FutureResponse const& f) {
        return f.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
    }

    /*
     You should call curl_global_cleanup once for each call you make to curl_global_init, after you are done using libcurl.

     This function is not thread safe. You must not call it when any other thread in the program (i.e. a thread sharing the same memory) is running.
     This doesn't just mean no other thread that is using libcurl. Because curl_global_cleanup calls functions of other libraries
     that are similarly thread unsafe, it could conflict with any other thread that uses these other libraries.
     */
    void cleanUp() {
        curl_global_cleanup();
    }

    // For image purpose
    size_t
    writeByteCallback(void *contents, size_t size, size_t nmemb, void *userp) {
        size_t realsize = size * nmemb;
        MemoryByte *memBlock = (MemoryByte *)userp;
        memBlock->append((unsigned char*)contents, realsize);

        return realsize;
    }

    // For Content
    size_t
    writeContentCallback(void *contents, size_t size, size_t nmemb, void *contentWrapper) {
        size_t realsize = size * nmemb;
        std::string *memBlock = (std::string *)contentWrapper;
        memBlock->append((char*)contents, realsize);

        return realsize;
    }

    namespace internal {
        std::deque<bcl::UniqueResponse> _mainLoopTasks;
        std::mutex _tasks_mutex;
        bool _hasMainLoopCallBack = false;

        //void BackCurlLoopCallBackChecker(bcl::Response &s) {
        //    _hasMainLoopCallBack = true;
        //}

        void wrapResponse(bcl::Request &r, bcl::Response &resp) {
            curl_easy_getinfo(r.curl, CURLINFO_RESPONSE_CODE, &resp.code);

            curl_easy_getinfo(r.curl, CURLINFO_TOTAL_TIME, &resp.totalTime);

            char *url = NULL;
            curl_easy_getinfo(r.curl, CURLINFO_EFFECTIVE_URL, &url);
            if (url)
                resp.effectiveUrl = std::string(url);

            char *ct = NULL;
            curl_easy_getinfo(r.curl, CURLINFO_CONTENT_TYPE, &ct);
            if (ct)
                resp.contentType = std::string(ct);

            resp.__body = r.dataPtr;

            resp.curl = r.curl;
        }

        //    template <typename DataType>
        //    auto __execute__(std::function<void(bcl::Request &req)> optsFilter, std::function<void(bcl::Response)> respFilter, CALL_TYPE,
        //                     DataType &chunk) -> Response<decltype(chunk)>
        void __execute__(bcl::Request &request, bcl::UniqueResponse response, bcl::internal::CALL_TYPE callType) {

            CURLcode curlCode;
            curl_slist *headersList = NULL;
            // curl_global_init(CURL_GLOBAL_ALL);

            /* init the curl session */
            request.curl = curl_easy_init();

            try {
                /***ROOT CAUSE MESSAGE***/
                if ((curlCode = curl_easy_setopt(request.curl, CURLOPT_ERRORBUFFER, request.errorBuffer)) != CURLE_OK) {
                    fprintf(stderr, "Failed to set error buffer [%d]\n", curlCode);
                    throw request.errorBuffer;
                }

                request.callBack(&request);

                bcl::Headers &headers = request.headers;

                if (headers.size() > 0) {
                    for (size_t i = 0; i < headers.size(); ++i)
                        headersList = curl_slist_append(headersList, (headers.at(i).first + ": " + headers.at(i).second).c_str());

                    if (curl_easy_setopt(request.curl, CURLOPT_HTTPHEADER, headersList) != CURLE_OK) {
                        fprintf(stderr, "Failed to set headers params [%s]\n", request.errorBuffer);
                        throw request.errorBuffer;
                    }
                }

                /* get it! and check for errors*/
                if (curl_easy_perform(request.curl) != CURLE_OK) {
                    throw request.errorBuffer;
                }
            } catch (char const* err) {
                response->error = std::string(err);

            } catch (std::exception& e) {

            }

            bcl::internal::wrapResponse(request, *response);

            if (headersList) {
                curl_slist_free_all(headersList);
            }

            // delete []request.cbPtr;
            switch (callType) {
                case internal::MAIN_LOOP_CALLBACK:
                {
                    std::lock_guard<std::mutex> lock(_tasks_mutex);
                    _mainLoopTasks.push_back(std::move(response));
                }
                    break;
                case internal::ASYNC_CALL:
                    response->callBack(&(*response));
                    break;
                default:
                    response->callBack(&(*response));
                    break;
            }
        }

        void __execute__(bcl::Request &request, bcl::Response &response) {

            CURLcode curlCode;
            curl_slist *headersList = NULL;
            // curl_global_init(CURL_GLOBAL_ALL);

            /* init the curl session */
            request.curl = curl_easy_init();

            try {
                /***ROOT CAUSE MESSAGE***/
                if ((curlCode = curl_easy_setopt(request.curl, CURLOPT_ERRORBUFFER, request.errorBuffer)) != CURLE_OK) {
                    fprintf(stderr, "Failed to set error buffer [%d]\n", curlCode);
                    throw request.errorBuffer;
                }

                request.callBack(&request);

                bcl::Headers &headers = request.headers;

                if (headers.size() > 0) {
                    for (size_t i = 0; i < headers.size(); ++i)
                        headersList = curl_slist_append(headersList, (headers.at(i).first + ": " + headers.at(i).second).c_str());

                    if (curl_easy_setopt(request.curl, CURLOPT_HTTPHEADER, headersList) != CURLE_OK) {
                        fprintf(stderr, "Failed to set headers params [%s]\n", request.errorBuffer);
                        throw request.errorBuffer;
                    }
                }

                /* get it! and check for errors*/
                if (curl_easy_perform(request.curl) != CURLE_OK) {
                    throw request.errorBuffer;
                }
            } catch (char const* err) {
                response.error = std::string(err);

            } catch (std::exception& e) {

            }

            bcl::internal::wrapResponse(request, response);

            if (headersList) {
                curl_slist_free_all(headersList);
            }
        }
    }

    // ** Request Bundle **/
    lmbdaptr& bcl::Request::attach_lmbdaptr() {
        return callBack;
    }

    // ** Response Bundle ** /
    bcl::Response::Response(bcl::Args &_args) {
        args = _args;
        curl = NULL;
        __body = NULL;
        cbPtr = NULL;
        streamClose = NULL;

    }

    bcl::Response::~Response () {
        //    if (__streamRef != NULL && --(*__streamRef) == 0) {
        close();
        //    }
    }

    void bcl::Response::close() {
        // delete static_cast<std::remove_pointer<decltype(body)*>::type>(body); //best solution so far
        if (__body && streamClose)
            streamClose(this);

        if(args)
            delete []args;
        // if (cbPtr)
        //     delete []cbPtr;

        //        printf("address of CURL is %p\n", curl);
        if (curl)
            curl_easy_cleanup(curl); // TODO please implement clean up curl later by using valgrind got error or not
        //        __body = NULL;
    }

    lmbdaptr& bcl::Response::attach_lmbdaptr() {
        return callBack;
    }

    void bcl::Response::setStreamClose(lmbdaptr lmbdaClz)  {
        streamClose = lmbdaClz;
    }

    bcl::Arg::Arg(): type(0) {
        __strRef = new int(1);
    }

    bcl::Arg::Arg(Arg* a) : type(a->type) {
        mapVal(*a);
        __strRef = new int(1);
    }

    bcl::Arg::Arg(const Arg& a) : type(a.type), __strRef(a.__strRef)
    {
        mapVal(a);
        (*__strRef) ++;
    }

    Arg& bcl::Arg::operator = (const Arg& a)
    {
        // Assignment operator
        if (this != &a) // Avoid self assignment
        {
            if (--(*__strRef) == 0) {
                if (type == 5)
                    delete []getStr;
                delete __strRef;
            }
            mapVal(a);
            __strRef = a.__strRef;
            (*__strRef)++;
        }

        return *this;
    }

    bcl::Arg::~Arg() {
        if (--(*__strRef) == 0) {
            if (type == 5)
                delete []getStr;
            delete __strRef;
        }
    }

    void bcl::Arg::mapVal(const Arg &a) {
        switch (a.type) {
            case 1:
                getInt = a.getInt;
                break;
            case 2:
                getFloat = a.getFloat;
                break;
            case 3:
                getLong = a.getLong;
                break;
            case 4:
                getChar = a.getChar;
                break;
            case 5:
                getStr = a.getStr;
                break;
        }
        type = a.type;
    }

    // Request Args
    void setArgs(bcl::Arg *args, int arg) {
        Arg a;
        a.getInt = arg;
        a.type = 1;
        *args = a;
    }

    void setArgs(bcl::Arg *args, float arg) {
        Arg a;
        a.getFloat = arg;
        a.type = 2;
        *args = a;
    }

    void setArgs(bcl::Arg *args, long arg) {
        Arg a;
        a.getLong = arg;
        a.type = 3;
        *args = a;
    }

    void setArgs(bcl::Arg *args, char arg) {
        Arg a;
        a.getChar = arg;
        a.type = 4;
        *args = a;
    }

    void setArgs(bcl::Arg *args, const char* arg) {
        Arg a;
        a.getStr = new char[strlen(arg) + 1];
        strcpy(a.getStr, arg);
        a.type = 5;
        *args = a;
    }

}

<commit_msg>remove redundant<commit_after>//
//  BackCurl.cpp
//  Created by Taymindis Woon on 23/5/17.
//  Copyright © 2017 Taymindis Woon. All rights reserved.
//

#include "BackCurl.h"

namespace bcl {

    /** If you activate mainLoopCallBack, please make sure bcl::LoopBackFire on the loop thread, for e.g. UI thread **/
    void init() {
        curl_global_init(CURL_GLOBAL_ALL);
    }

    void LoopBackFire() {
        while (!internal::_mainLoopTasks.empty()) {
            bcl::UniqueResponse response = std::move(internal::_mainLoopTasks.front());
            internal::_mainLoopTasks.pop_front();

            // lock during the task?
            internal::_tasks_mutex.lock();
            response->callBack(&(*response));
            internal::_tasks_mutex.unlock();
        }
    }

    bool isReady(FutureResponse const& f) {
        return f.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
    }

    /*
     You should call curl_global_cleanup once for each call you make to curl_global_init, after you are done using libcurl.

     This function is not thread safe. You must not call it when any other thread in the program (i.e. a thread sharing the same memory) is running.
     This doesn't just mean no other thread that is using libcurl. Because curl_global_cleanup calls functions of other libraries
     that are similarly thread unsafe, it could conflict with any other thread that uses these other libraries.
     */
    void cleanUp() {
        curl_global_cleanup();
    }

    // For image purpose
    size_t
    writeByteCallback(void *contents, size_t size, size_t nmemb, void *userp) {
        size_t realsize = size * nmemb;
        MemoryByte *memBlock = (MemoryByte *)userp;
        memBlock->append((unsigned char*)contents, realsize);

        return realsize;
    }

    // For Content
    size_t
    writeContentCallback(void *contents, size_t size, size_t nmemb, void *contentWrapper) {
        size_t realsize = size * nmemb;
        std::string *memBlock = (std::string *)contentWrapper;
        memBlock->append((char*)contents, realsize);

        return realsize;
    }

    namespace internal {
        std::deque<bcl::UniqueResponse> _mainLoopTasks;
        std::mutex _tasks_mutex;
        bool _hasMainLoopCallBack = false;

        //void BackCurlLoopCallBackChecker(bcl::Response &s) {
        //    _hasMainLoopCallBack = true;
        //}

        void wrapResponse(bcl::Request &r, bcl::Response &resp) {
            curl_easy_getinfo(r.curl, CURLINFO_RESPONSE_CODE, &resp.code);

            curl_easy_getinfo(r.curl, CURLINFO_TOTAL_TIME, &resp.totalTime);

            char *url = NULL;
            curl_easy_getinfo(r.curl, CURLINFO_EFFECTIVE_URL, &url);
            if (url)
                resp.effectiveUrl = std::string(url);

            char *ct = NULL;
            curl_easy_getinfo(r.curl, CURLINFO_CONTENT_TYPE, &ct);
            if (ct)
                resp.contentType = std::string(ct);

            resp.__body = r.dataPtr;

            resp.curl = r.curl;
        }

        //    template <typename DataType>
        //    auto __execute__(std::function<void(bcl::Request &req)> optsFilter, std::function<void(bcl::Response)> respFilter, CALL_TYPE,
        //                     DataType &chunk) -> Response<decltype(chunk)>
        void __execute__(bcl::Request &request, bcl::UniqueResponse response, bcl::internal::CALL_TYPE callType) {

            CURLcode curlCode;
            curl_slist *headersList = NULL;
            // curl_global_init(CURL_GLOBAL_ALL);

            /* init the curl session */
            request.curl = curl_easy_init();

            try {
                /***ROOT CAUSE MESSAGE***/
                if ((curlCode = curl_easy_setopt(request.curl, CURLOPT_ERRORBUFFER, request.errorBuffer)) != CURLE_OK) {
                    fprintf(stderr, "Failed to set error buffer [%d]\n", curlCode);
                    throw request.errorBuffer;
                }

                request.callBack(&request);

                bcl::Headers &headers = request.headers;

                if (headers.size() > 0) {
                    for (size_t i = 0; i < headers.size(); ++i)
                        headersList = curl_slist_append(headersList, (headers.at(i).first + ": " + headers.at(i).second).c_str());

                    if (curl_easy_setopt(request.curl, CURLOPT_HTTPHEADER, headersList) != CURLE_OK) {
                        fprintf(stderr, "Failed to set headers params [%s]\n", request.errorBuffer);
                        throw request.errorBuffer;
                    }
                }

                /* get it! and check for errors*/
                if (curl_easy_perform(request.curl) != CURLE_OK) {
                    throw request.errorBuffer;
                }
            } catch (char const* err) {
                response->error = std::string(err);

            } catch (std::exception& e) {

            }

            bcl::internal::wrapResponse(request, *response);

            if (headersList) {
                curl_slist_free_all(headersList);
            }

            // delete []request.cbPtr;
            if(callType == internal::MAIN_LOOP_CALLBACK) {
                std::lock_guard<std::mutex> lock(_tasks_mutex);
                _mainLoopTasks.push_back(std::move(response));
            } else {
                response->callBack(&(*response));
            }
        }

        void __execute__(bcl::Request &request, bcl::Response &response) {

            CURLcode curlCode;
            curl_slist *headersList = NULL;
            // curl_global_init(CURL_GLOBAL_ALL);

            /* init the curl session */
            request.curl = curl_easy_init();

            try {
                /***ROOT CAUSE MESSAGE***/
                if ((curlCode = curl_easy_setopt(request.curl, CURLOPT_ERRORBUFFER, request.errorBuffer)) != CURLE_OK) {
                    fprintf(stderr, "Failed to set error buffer [%d]\n", curlCode);
                    throw request.errorBuffer;
                }

                request.callBack(&request);

                bcl::Headers &headers = request.headers;

                if (headers.size() > 0) {
                    for (size_t i = 0; i < headers.size(); ++i)
                        headersList = curl_slist_append(headersList, (headers.at(i).first + ": " + headers.at(i).second).c_str());

                    if (curl_easy_setopt(request.curl, CURLOPT_HTTPHEADER, headersList) != CURLE_OK) {
                        fprintf(stderr, "Failed to set headers params [%s]\n", request.errorBuffer);
                        throw request.errorBuffer;
                    }
                }

                /* get it! and check for errors*/
                if (curl_easy_perform(request.curl) != CURLE_OK) {
                    throw request.errorBuffer;
                }
            } catch (char const* err) {
                response.error = std::string(err);

            } catch (std::exception& e) {

            }

            bcl::internal::wrapResponse(request, response);

            if (headersList) {
                curl_slist_free_all(headersList);
            }
        }
    }

    // ** Request Bundle **/
    lmbdaptr& bcl::Request::attach_lmbdaptr() {
        return callBack;
    }

    // ** Response Bundle ** /
    bcl::Response::Response(bcl::Args &_args) {
        args = _args;
        curl = NULL;
        __body = NULL;
        cbPtr = NULL;
        streamClose = NULL;

    }

    bcl::Response::~Response () {
        //    if (__streamRef != NULL && --(*__streamRef) == 0) {
        close();
        //    }
    }

    void bcl::Response::close() {
        // delete static_cast<std::remove_pointer<decltype(body)*>::type>(body); //best solution so far
        if (__body && streamClose)
            streamClose(this);

        if(args)
            delete []args;
        // if (cbPtr)
        //     delete []cbPtr;

        //        printf("address of CURL is %p\n", curl);
        if (curl)
            curl_easy_cleanup(curl); // TODO please implement clean up curl later by using valgrind got error or not
        //        __body = NULL;
    }

    lmbdaptr& bcl::Response::attach_lmbdaptr() {
        return callBack;
    }

    void bcl::Response::setStreamClose(lmbdaptr lmbdaClz)  {
        streamClose = lmbdaClz;
    }

    bcl::Arg::Arg(): type(0) {
        __strRef = new int(1);
    }

    bcl::Arg::Arg(Arg* a) : type(a->type) {
        mapVal(*a);
        __strRef = new int(1);
    }

    bcl::Arg::Arg(const Arg& a) : type(a.type), __strRef(a.__strRef)
    {
        mapVal(a);
        (*__strRef) ++;
    }

    Arg& bcl::Arg::operator = (const Arg& a)
    {
        // Assignment operator
        if (this != &a) // Avoid self assignment
        {
            if (--(*__strRef) == 0) {
                if (type == 5)
                    delete []getStr;
                delete __strRef;
            }
            mapVal(a);
            __strRef = a.__strRef;
            (*__strRef)++;
        }

        return *this;
    }

    bcl::Arg::~Arg() {
        if (--(*__strRef) == 0) {
            if (type == 5)
                delete []getStr;
            delete __strRef;
        }
    }

    void bcl::Arg::mapVal(const Arg &a) {
        switch (a.type) {
            case 1:
                getInt = a.getInt;
                break;
            case 2:
                getFloat = a.getFloat;
                break;
            case 3:
                getLong = a.getLong;
                break;
            case 4:
                getChar = a.getChar;
                break;
            case 5:
                getStr = a.getStr;
                break;
        }
        type = a.type;
    }

    // Request Args
    void setArgs(bcl::Arg *args, int arg) {
        Arg a;
        a.getInt = arg;
        a.type = 1;
        *args = a;
    }

    void setArgs(bcl::Arg *args, float arg) {
        Arg a;
        a.getFloat = arg;
        a.type = 2;
        *args = a;
    }

    void setArgs(bcl::Arg *args, long arg) {
        Arg a;
        a.getLong = arg;
        a.type = 3;
        *args = a;
    }

    void setArgs(bcl::Arg *args, char arg) {
        Arg a;
        a.getChar = arg;
        a.type = 4;
        *args = a;
    }

    void setArgs(bcl::Arg *args, const char* arg) {
        Arg a;
        a.getStr = new char[strlen(arg) + 1];
        strcpy(a.getStr, arg);
        a.type = 5;
        *args = a;
    }

}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: basidesh.hxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: kz $ $Date: 2007-10-09 15:25:06 $
 *
 *  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 _BASIDESH_HXX
#define _BASIDESH_HXX

#ifndef _SBXITEM_HXX
#include "sbxitem.hxx"
#endif

#include "scriptdocument.hxx"
#include "doceventnotifier.hxx"

#ifndef _VIEWFAC_HXX //autogen
#include <sfx2/viewfac.hxx>
#endif
#ifndef _SFX_SHELL_HXX //autogen
#include <sfx2/shell.hxx>
#endif
#ifndef _SCRBAR_HXX //autogen
#include <vcl/scrbar.hxx>
#endif
#ifndef _TABLE_HXX //autogen
#include <tools/table.hxx>
#endif
#ifndef _SFXVIEWSH_HXX //autogen
#include <sfx2/viewsh.hxx>
#endif
#include <svx/ifaceids.hxx>

#ifndef _COM_SUN_STAR_IO_XINPUTSTREAMPROVIDER_HXX_
#include <com/sun/star/io/XInputStreamProvider.hpp>
#endif

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

const ULONG BASICIDE_UI_FEATURE_SHOW_BROWSER = 0x00000001;

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

class ModulWindow;
class ModulWindowLayout;
class DialogWindow;
class SdrView;
class ObjectCatalog;
class BasicIDETabBar;
class TabBar;
class IDEBaseWindow;
class SbxObject;
class SbModule;
class StarBASIC;
class LocalizationMgr;
struct BasicIDEShell_Impl;

#if _SOLAR__PRIVATE
DECLARE_TABLE( IDEWindowTable, IDEBaseWindow* )
#else
typedef Table IDEWindowTable;
#endif

class BasicIDEShell :public SfxViewShell
                    ,public ::basctl::DocumentEventListener
{
friend class JavaDebuggingListenerImpl;
friend class LocalizationMgr;
friend class BasicIDE;

    ObjectCatalog*      pObjectCatalog;

    IDEWindowTable      aIDEWindowTable;
    USHORT              nCurKey;
    IDEBaseWindow*      pCurWin;
    ScriptDocument      m_aCurDocument;
    String              m_aCurLibName;
    LocalizationMgr*    m_pCurLocalizationMgr;

    ScrollBar           aHScrollBar;
    ScrollBar           aVScrollBar;
    ScrollBarBox        aScrollBarBox;
    BasicIDETabBar*     pTabBar;
    BOOL                bTabBarSplitted;
    BOOL                bCreatingWindow;
    ModulWindowLayout*  pModulLayout;
    BOOL                m_bAppBasicModified;
    ::basctl::DocumentEventNotifier
                        m_aNotifier;

#if _SOLAR__PRIVATE
    void                Init();
    void                InitTabBar();
    void                InitScrollBars();
    void                CheckWindows();
    void                RemoveWindows( const ScriptDocument& rDocument, const String& rLibName, BOOL bDestroy );
    void                UpdateWindows();
    void                ShowObjectDialog( BOOL bShow, BOOL bCreateOrDestroy );
    void                InvalidateBasicIDESlots();
    void                StoreAllWindowData( BOOL bPersistent = TRUE );
    void                SetMDITitle();
    void                EnableScrollbars( BOOL bEnable );
    void                SetCurLib( const ScriptDocument& rDocument, String aLibName, bool bUpdateWindows = true , bool bCheck = true );
    void                SetCurLibForLocalization( const ScriptDocument& rDocument, String aLibName );

    void                ImplStartListening( StarBASIC* pBasic );

    DECL_LINK( TabBarHdl, TabBar* );
    DECL_LINK( AccelSelectHdl, Accelerator* );
    DECL_LINK( ObjectDialogCancelHdl, ObjectCatalog * );
    DECL_LINK( TabBarSplitHdl, TabBar * );
#endif

protected:
    virtual void        AdjustPosSizePixel( const Point &rPos, const Size &rSize );
    virtual void        OuterResizePixel( const Point &rPos, const Size &rSize );
    virtual Size        GetOptimalSizePixel() const;
    USHORT              InsertWindowInTable( IDEBaseWindow* pNewWin );
    virtual USHORT      PrepareClose( BOOL bUI, BOOL bForBrowsing );

    void                SetCurWindow( IDEBaseWindow* pNewWin, BOOL bUpdateTabBar = FALSE, BOOL bRememberAsCurrent = TRUE );
    void                ManageToolbars();
    void                RemoveWindow( IDEBaseWindow* pWindow, BOOL bDestroy, BOOL bAllowChangeCurWindow = TRUE );
    void                ArrangeTabBar();

    ModulWindow*        CreateBasWin( const ScriptDocument& rDocument, const String& rLibName, const String& rModName );
    DialogWindow*       CreateDlgWin( const ScriptDocument& rDocument, const String& rLibName, const String& rDlgName );

    ModulWindow*        FindBasWin( const ScriptDocument& rDocument, const String& rLibName, const String& rModName, BOOL bCreateIfNotExist, BOOL bFindSuspended = FALSE );
    DialogWindow*       FindDlgWin( const ScriptDocument& rDocument, const String& rLibName, const String& rDlgName, BOOL bCreateIfNotExist, BOOL bFindSuspended = FALSE );
    ModulWindow*        ShowActiveModuleWindow( StarBASIC* pBasic );

    virtual void        SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
                                const SfxHint& rHint, const TypeId& rHintType );

    virtual void        Activate(BOOL bMDI);
    virtual void        Deactivate(BOOL bMDI);

    virtual void        Move();
    virtual void        ShowCursor( FASTBOOL bOn = TRUE );

    void                CreateModulWindowLayout();
    void                DestroyModulWindowLayout();
    void                UpdateModulWindowLayout( bool bBasicStopped );

    sal_Bool            HasBasic() const;

    // DocumentEventListener
    virtual void onDocumentCreated( const ScriptDocument& _rDocument );
    virtual void onDocumentOpened( const ScriptDocument& _rDocument );
    virtual void onDocumentSave( const ScriptDocument& _rDocument );
    virtual void onDocumentSaveDone( const ScriptDocument& _rDocument );
    virtual void onDocumentSaveAs( const ScriptDocument& _rDocument );
    virtual void onDocumentSaveAsDone( const ScriptDocument& _rDocument );
    virtual void onDocumentClosed( const ScriptDocument& _rDocument );
    virtual void onDocumentTitleChanged( const ScriptDocument& _rDocument );
    virtual void onDocumentModeChanged( const ScriptDocument& _rDocument );

public:
                        TYPEINFO();
                        SFX_DECL_INTERFACE( SVX_INTERFACE_BASIDE_VIEWSH )
                        SFX_DECL_VIEWFACTORY(BasicIDEShell);

                        BasicIDEShell( SfxViewFrame *pFrame, Window *);
                        BasicIDEShell( SfxViewFrame *pFrame, SfxViewShell *pOldSh );
                        BasicIDEShell( SfxViewFrame *pFrame, const BasicIDEShell &rOrig );
                        ~BasicIDEShell();

    IDEBaseWindow*      GetCurWindow() const    { return pCurWin; }
    const ScriptDocument&
                        GetCurDocument() const { return m_aCurDocument; }
    const String&       GetCurLibName() const { return m_aCurLibName; }
    ObjectCatalog*      GetObjectCatalog() const    { return pObjectCatalog; }
    LocalizationMgr*    GetCurLocalizationMgr() const { return m_pCurLocalizationMgr; }

    ScrollBar&          GetHScrollBar()         { return aHScrollBar; }
    ScrollBar&          GetVScrollBar()         { return aVScrollBar; }
    ScrollBarBox&       GetScrollBarBox()       { return aScrollBarBox; }
    TabBar*             GetTabBar()             { return (TabBar*)pTabBar; }
    IDEWindowTable&     GetIDEWindowTable()     { return aIDEWindowTable; }

    SdrView*            GetCurDlgView();

    SfxUndoManager*     GetUndoManager();

    virtual USHORT          Print( SfxProgress &rProgress, BOOL bIsAPI, PrintDialog *pPrintDialog = 0 );
    virtual SfxPrinter*     GetPrinter( BOOL bCreate );
    virtual USHORT          SetPrinter( SfxPrinter *pNewPrinter, USHORT nDiffFlags = SFX_PRINTER_ALL, bool bIsAPI=false );
    virtual String          GetSelectionText( BOOL bCompleteWords );
    virtual BOOL            HasSelection( BOOL bText ) const;

    void                GetState( SfxItemSet& );
    void                ExecuteGlobal( SfxRequest& rReq );
    void                ExecuteCurrent( SfxRequest& rReq );
    void                ExecuteBasic( SfxRequest& rReq );
    void                ExecuteDialog( SfxRequest& rReq );

    virtual sal_Bool    HasUIFeature( sal_uInt32 nFeature );

    long                CallBasicErrorHdl( StarBASIC* pBasic );
    long                CallBasicBreakHdl( StarBASIC* pBasic );

    ModulWindowLayout*  GetLayoutWindow() const { return pModulLayout; }

    IDEBaseWindow*      FindWindow( const ScriptDocument& rDocument, const String& rLibName = String(), const String& rName = String(), USHORT nType = BASICIDE_TYPE_UNKNOWN, BOOL bFindSuspended = FALSE );
    IDEBaseWindow*      FindApplicationWindow();
    BOOL                NextPage( BOOL bPrev = FALSE );

    BOOL                IsAppBasicModified() const { return m_bAppBasicModified; }
    void                SetAppBasicModified( BOOL bModified = TRUE ) { m_bAppBasicModified = bModified; }

    // For Dialog Drag&Drop in Dialog Organizer
    static void CopyDialogResources(
        ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStreamProvider >& io_xISP,
        const ScriptDocument& rSourceDoc, const String& rSourceLibName, const ScriptDocument& rDestDoc,
        const String& rDestLibName, const String& rDlgName );
};

#endif // _BASIDESH_HXX
<commit_msg>INTEGRATION: CWS odbmacros2 (1.7.16); FILE MERGED 2008/02/25 13:26:53 fs 1.7.16.2: #i86427# GetCurrentDocument made public 2007/12/22 13:32:23 fs 1.7.16.1: #i49133# overload GetCurrentComponent<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: basidesh.hxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: kz $ $Date: 2008-03-06 19:14:54 $
 *
 *  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 _BASIDESH_HXX
#define _BASIDESH_HXX

#ifndef _SBXITEM_HXX
#include "sbxitem.hxx"
#endif

#include "scriptdocument.hxx"
#include "doceventnotifier.hxx"

#ifndef _VIEWFAC_HXX //autogen
#include <sfx2/viewfac.hxx>
#endif
#ifndef _SFX_SHELL_HXX //autogen
#include <sfx2/shell.hxx>
#endif
#ifndef _SCRBAR_HXX //autogen
#include <vcl/scrbar.hxx>
#endif
#ifndef _TABLE_HXX //autogen
#include <tools/table.hxx>
#endif
#ifndef _SFXVIEWSH_HXX //autogen
#include <sfx2/viewsh.hxx>
#endif
#include <svx/ifaceids.hxx>

#ifndef _COM_SUN_STAR_IO_XINPUTSTREAMPROVIDER_HXX_
#include <com/sun/star/io/XInputStreamProvider.hpp>
#endif

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

const ULONG BASICIDE_UI_FEATURE_SHOW_BROWSER = 0x00000001;

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

class ModulWindow;
class ModulWindowLayout;
class DialogWindow;
class SdrView;
class ObjectCatalog;
class BasicIDETabBar;
class TabBar;
class IDEBaseWindow;
class SbxObject;
class SbModule;
class StarBASIC;
class LocalizationMgr;
struct BasicIDEShell_Impl;

#if _SOLAR__PRIVATE
DECLARE_TABLE( IDEWindowTable, IDEBaseWindow* )
#else
typedef Table IDEWindowTable;
#endif

class BasicIDEShell :public SfxViewShell
                    ,public ::basctl::DocumentEventListener
{
friend class JavaDebuggingListenerImpl;
friend class LocalizationMgr;
friend class BasicIDE;

    ObjectCatalog*      pObjectCatalog;

    IDEWindowTable      aIDEWindowTable;
    USHORT              nCurKey;
    IDEBaseWindow*      pCurWin;
    ScriptDocument      m_aCurDocument;
    String              m_aCurLibName;
    LocalizationMgr*    m_pCurLocalizationMgr;

    ScrollBar           aHScrollBar;
    ScrollBar           aVScrollBar;
    ScrollBarBox        aScrollBarBox;
    BasicIDETabBar*     pTabBar;
    BOOL                bTabBarSplitted;
    BOOL                bCreatingWindow;
    ModulWindowLayout*  pModulLayout;
    BOOL                m_bAppBasicModified;
    ::basctl::DocumentEventNotifier
                        m_aNotifier;

#if _SOLAR__PRIVATE
    void                Init();
    void                InitTabBar();
    void                InitScrollBars();
    void                CheckWindows();
    void                RemoveWindows( const ScriptDocument& rDocument, const String& rLibName, BOOL bDestroy );
    void                UpdateWindows();
    void                ShowObjectDialog( BOOL bShow, BOOL bCreateOrDestroy );
    void                InvalidateBasicIDESlots();
    void                StoreAllWindowData( BOOL bPersistent = TRUE );
    void                SetMDITitle();
    void                EnableScrollbars( BOOL bEnable );
    void                SetCurLib( const ScriptDocument& rDocument, String aLibName, bool bUpdateWindows = true , bool bCheck = true );
    void                SetCurLibForLocalization( const ScriptDocument& rDocument, String aLibName );

    void                ImplStartListening( StarBASIC* pBasic );

    DECL_LINK( TabBarHdl, TabBar* );
    DECL_LINK( AccelSelectHdl, Accelerator* );
    DECL_LINK( ObjectDialogCancelHdl, ObjectCatalog * );
    DECL_LINK( TabBarSplitHdl, TabBar * );
#endif

protected:
    virtual void        AdjustPosSizePixel( const Point &rPos, const Size &rSize );
    virtual void        OuterResizePixel( const Point &rPos, const Size &rSize );
    virtual Size        GetOptimalSizePixel() const;
    USHORT              InsertWindowInTable( IDEBaseWindow* pNewWin );
    virtual USHORT      PrepareClose( BOOL bUI, BOOL bForBrowsing );

    void                SetCurWindow( IDEBaseWindow* pNewWin, BOOL bUpdateTabBar = FALSE, BOOL bRememberAsCurrent = TRUE );
    void                ManageToolbars();
    void                RemoveWindow( IDEBaseWindow* pWindow, BOOL bDestroy, BOOL bAllowChangeCurWindow = TRUE );
    void                ArrangeTabBar();

    ModulWindow*        CreateBasWin( const ScriptDocument& rDocument, const String& rLibName, const String& rModName );
    DialogWindow*       CreateDlgWin( const ScriptDocument& rDocument, const String& rLibName, const String& rDlgName );

    ModulWindow*        FindBasWin( const ScriptDocument& rDocument, const String& rLibName, const String& rModName, BOOL bCreateIfNotExist, BOOL bFindSuspended = FALSE );
    DialogWindow*       FindDlgWin( const ScriptDocument& rDocument, const String& rLibName, const String& rDlgName, BOOL bCreateIfNotExist, BOOL bFindSuspended = FALSE );
    ModulWindow*        ShowActiveModuleWindow( StarBASIC* pBasic );

    virtual void        SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
                                const SfxHint& rHint, const TypeId& rHintType );

    virtual void        Activate(BOOL bMDI);
    virtual void        Deactivate(BOOL bMDI);

    virtual void        Move();
    virtual void        ShowCursor( FASTBOOL bOn = TRUE );

    void                CreateModulWindowLayout();
    void                DestroyModulWindowLayout();
    void                UpdateModulWindowLayout( bool bBasicStopped );

    sal_Bool            HasBasic() const;

    // DocumentEventListener
    virtual void onDocumentCreated( const ScriptDocument& _rDocument );
    virtual void onDocumentOpened( const ScriptDocument& _rDocument );
    virtual void onDocumentSave( const ScriptDocument& _rDocument );
    virtual void onDocumentSaveDone( const ScriptDocument& _rDocument );
    virtual void onDocumentSaveAs( const ScriptDocument& _rDocument );
    virtual void onDocumentSaveAsDone( const ScriptDocument& _rDocument );
    virtual void onDocumentClosed( const ScriptDocument& _rDocument );
    virtual void onDocumentTitleChanged( const ScriptDocument& _rDocument );
    virtual void onDocumentModeChanged( const ScriptDocument& _rDocument );

public:
                        TYPEINFO();
                        SFX_DECL_INTERFACE( SVX_INTERFACE_BASIDE_VIEWSH )
                        SFX_DECL_VIEWFACTORY(BasicIDEShell);

                        BasicIDEShell( SfxViewFrame *pFrame, Window *);
                        BasicIDEShell( SfxViewFrame *pFrame, SfxViewShell *pOldSh );
                        BasicIDEShell( SfxViewFrame *pFrame, const BasicIDEShell &rOrig );
                        ~BasicIDEShell();

    IDEBaseWindow*      GetCurWindow() const    { return pCurWin; }
    const ScriptDocument&
                        GetCurDocument() const { return m_aCurDocument; }
    const String&       GetCurLibName() const { return m_aCurLibName; }
    ObjectCatalog*      GetObjectCatalog() const    { return pObjectCatalog; }
    LocalizationMgr*    GetCurLocalizationMgr() const { return m_pCurLocalizationMgr; }

    ScrollBar&          GetHScrollBar()         { return aHScrollBar; }
    ScrollBar&          GetVScrollBar()         { return aVScrollBar; }
    ScrollBarBox&       GetScrollBarBox()       { return aScrollBarBox; }
    TabBar*             GetTabBar()             { return (TabBar*)pTabBar; }
    IDEWindowTable&     GetIDEWindowTable()     { return aIDEWindowTable; }

    SdrView*            GetCurDlgView() const;

    SfxUndoManager*     GetUndoManager();

    virtual USHORT          Print( SfxProgress &rProgress, BOOL bIsAPI, PrintDialog *pPrintDialog = 0 );
    virtual SfxPrinter*     GetPrinter( BOOL bCreate );
    virtual USHORT          SetPrinter( SfxPrinter *pNewPrinter, USHORT nDiffFlags = SFX_PRINTER_ALL, bool bIsAPI=false );
    virtual String          GetSelectionText( BOOL bCompleteWords );
    virtual BOOL            HasSelection( BOOL bText ) const;

    void                GetState( SfxItemSet& );
    void                ExecuteGlobal( SfxRequest& rReq );
    void                ExecuteCurrent( SfxRequest& rReq );
    void                ExecuteBasic( SfxRequest& rReq );
    void                ExecuteDialog( SfxRequest& rReq );

    virtual sal_Bool    HasUIFeature( sal_uInt32 nFeature );

    long                CallBasicErrorHdl( StarBASIC* pBasic );
    long                CallBasicBreakHdl( StarBASIC* pBasic );

    ModulWindowLayout*  GetLayoutWindow() const { return pModulLayout; }

    IDEBaseWindow*      FindWindow( const ScriptDocument& rDocument, const String& rLibName = String(), const String& rName = String(), USHORT nType = BASICIDE_TYPE_UNKNOWN, BOOL bFindSuspended = FALSE );
    IDEBaseWindow*      FindApplicationWindow();
    BOOL                NextPage( BOOL bPrev = FALSE );

    BOOL                IsAppBasicModified() const { return m_bAppBasicModified; }
    void                SetAppBasicModified( BOOL bModified = TRUE ) { m_bAppBasicModified = bModified; }

    // For Dialog Drag&Drop in Dialog Organizer
    static void CopyDialogResources(
        ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStreamProvider >& io_xISP,
        const ScriptDocument& rSourceDoc, const String& rSourceLibName, const ScriptDocument& rDestDoc,
        const String& rDestLibName, const String& rDlgName );

    virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >
                        GetCurrentDocument() const;

};

#endif // _BASIDESH_HXX
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: dlgedobj.hxx,v $
 *
 *  $Revision: 1.17 $
 *
 *  last change: $Author: hr $ $Date: 2003-11-05 12:40:38 $
 *
 *  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 _BASCTL_DLGEDOBJ_HXX
#define _BASCTL_DLGEDOBJ_HXX

#ifndef _SVDOUNO_HXX
#include <svx/svdouno.hxx>
#endif

#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
#include <comphelper/processfactory.hxx>
#endif

#ifndef _COM_SUN_STAR_BEANS_XPROPERTYCHANGELISTENER_HPP_
#include <com/sun/star/beans/XPropertyChangeListener.hpp>
#endif

#ifndef _COM_SUN_STAR_CONTAINER_XCONTAINERLISTENER_HPP_
#include <com/sun/star/container/XContainerListener.hpp>
#endif

#include <vector>
#include <map>

typedef ::std::multimap< sal_Int16, ::rtl::OUString, ::std::less< sal_Int16 > > IndexToNameMap;

class DlgEdForm;

//============================================================================
// DlgEdObj
//============================================================================

class DlgEdObj: public SdrUnoObj
{
    friend class DlgEditor;
    friend class DlgEdFactory;
    friend class DlgEdPropListenerImpl;
    friend class DlgEdForm;

private:
    sal_Bool        bIsListening;
    DlgEdForm*      pDlgEdForm;
    ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener> m_xPropertyChangeListener;
    ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener> m_xContainerListener;

protected:
    DlgEdObj();
    DlgEdObj(const ::rtl::OUString& rModelName);
    DlgEdObj(const ::rtl::OUString& rModelName,
             const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSFac);

    virtual void     WriteData(SvStream& rOut) const;                           // not working yet
    virtual void     ReadData(const SdrObjIOHeader& rHead, SvStream& rIn);      // not working yet

    virtual void NbcMove( const Size& rSize );
    virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact);
    virtual FASTBOOL EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd);

    DECL_LINK(OnCreate, void* );

    void StartListening();
    void EndListening(sal_Bool bRemoveListener = sal_True);
    sal_Bool    isListening() const { return bIsListening; }

public:
    TYPEINFO();

    virtual ~DlgEdObj();
    virtual void SetPage(SdrPage* pNewPage);

    virtual void SetDlgEdForm( DlgEdForm* pForm ) { pDlgEdForm = pForm; }
    virtual DlgEdForm* GetDlgEdForm() const { return pDlgEdForm; }

    virtual sal_uInt32 GetObjInventor() const;
    virtual sal_uInt16 GetObjIdentifier() const;

    virtual SdrObject*  Clone() const;                                          // not working yet
    virtual SdrObject*  Clone(SdrPage* pPage, SdrModel* pModel) const;          // not working yet
    virtual void        operator= (const SdrObject& rObj);                      // not working yet
    virtual void clonedFrom(const DlgEdObj* _pSource);                          // not working yet

    virtual sal_Bool        supportsService( const sal_Char* _pServiceName ) const;
    virtual ::rtl::OUString GetDefaultName() const;
    virtual ::rtl::OUString GetUniqueName() const;

    virtual sal_Int32   GetStep() const;
    virtual void        UpdateStep();

    virtual void SetDefaults();
    virtual void SetRectFromProps();
    virtual void SetPropsFromRect();

    virtual void SAL_CALL NameChange( const  ::com::sun::star::beans::PropertyChangeEvent& evt ) throw( ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL TabIndexChange( const  ::com::sun::star::beans::PropertyChangeEvent& evt ) throw( ::com::sun::star::uno::RuntimeException);

    // PropertyChangeListener
    virtual void SAL_CALL _propertyChange( const  ::com::sun::star::beans::PropertyChangeEvent& evt ) throw(::com::sun::star::uno::RuntimeException);

    // ContainerListener
    virtual void SAL_CALL _elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL _elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL _elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);

    virtual void SetLayer(SdrLayerID nLayer);
    virtual SdrObject* CheckHit(const Point& rPnt,USHORT nTol,const SetOfByte*) const;
};

//============================================================================
// DlgEdForm
//============================================================================

class DlgEdForm: public DlgEdObj
{
    friend class DlgEditor;
    friend class DlgEdFactory;

private:
    DlgEditor* pDlgEditor;
    ::std::vector<DlgEdObj*> pChilds;

protected:
    DlgEdForm(const ::rtl::OUString& rModelName);
    DlgEdForm(const ::rtl::OUString& rModelName,
              const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSFac);
    DlgEdForm();

    virtual void NbcMove( const Size& rSize );
    virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact);
    virtual FASTBOOL EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd);

public:
    TYPEINFO();

    virtual ~DlgEdForm();

    virtual void SetDlgEditor( DlgEditor* pEditor ) { pDlgEditor = pEditor; }
    virtual DlgEditor* GetDlgEditor() const { return pDlgEditor; }

    virtual void AddChild( DlgEdObj* pDlgEdObj );
    virtual void RemoveChild( DlgEdObj* pDlgEdObj );
    virtual ::std::vector<DlgEdObj*> GetChilds() const { return pChilds; }

    virtual void UpdateStep();

    virtual void SetRectFromProps();
    virtual void SetPropsFromRect();

    virtual void UpdateTabIndices();
    virtual void UpdateTabOrder();
    virtual void UpdateGroups();
    virtual void UpdateTabOrderAndGroups();

    virtual SdrObject* CheckHit(const Point& rPnt,USHORT nTol,const SetOfByte*) const;
};

#endif // _BASCTL_DLGEDOBJ_HXX

<commit_msg>INTEGRATION: CWS aw019 (1.17.116); FILE MERGED 2004/09/30 12:45:53 aw 1.17.116.1: #i11190#<commit_after>/*************************************************************************
 *
 *  $RCSfile: dlgedobj.hxx,v $
 *
 *  $Revision: 1.18 $
 *
 *  last change: $Author: pjunck $ $Date: 2004-11-03 11:17:30 $
 *
 *  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 _BASCTL_DLGEDOBJ_HXX
#define _BASCTL_DLGEDOBJ_HXX

#ifndef _SVDOUNO_HXX
#include <svx/svdouno.hxx>
#endif

#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
#include <comphelper/processfactory.hxx>
#endif

#ifndef _COM_SUN_STAR_BEANS_XPROPERTYCHANGELISTENER_HPP_
#include <com/sun/star/beans/XPropertyChangeListener.hpp>
#endif

#ifndef _COM_SUN_STAR_CONTAINER_XCONTAINERLISTENER_HPP_
#include <com/sun/star/container/XContainerListener.hpp>
#endif

#include <vector>
#include <map>

typedef ::std::multimap< sal_Int16, ::rtl::OUString, ::std::less< sal_Int16 > > IndexToNameMap;

class DlgEdForm;

//============================================================================
// DlgEdObj
//============================================================================

class DlgEdObj: public SdrUnoObj
{
    friend class DlgEditor;
    friend class DlgEdFactory;
    friend class DlgEdPropListenerImpl;
    friend class DlgEdForm;

private:
    sal_Bool        bIsListening;
    DlgEdForm*      pDlgEdForm;
    ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener> m_xPropertyChangeListener;
    ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener> m_xContainerListener;

protected:
    DlgEdObj();
    DlgEdObj(const ::rtl::OUString& rModelName);
    DlgEdObj(const ::rtl::OUString& rModelName,
             const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSFac);

//BFS01 virtual void     WriteData(SvStream& rOut) const;                           // not working yet
//BFS01 virtual void     ReadData(const SdrObjIOHeader& rHead, SvStream& rIn);      // not working yet

    virtual void NbcMove( const Size& rSize );
    virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact);
    virtual FASTBOOL EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd);

    DECL_LINK(OnCreate, void* );

    void StartListening();
    void EndListening(sal_Bool bRemoveListener = sal_True);
    sal_Bool    isListening() const { return bIsListening; }

public:
    TYPEINFO();

    virtual ~DlgEdObj();
    virtual void SetPage(SdrPage* pNewPage);

    virtual void SetDlgEdForm( DlgEdForm* pForm ) { pDlgEdForm = pForm; }
    virtual DlgEdForm* GetDlgEdForm() const { return pDlgEdForm; }

    virtual sal_uInt32 GetObjInventor() const;
    virtual sal_uInt16 GetObjIdentifier() const;

    virtual SdrObject*  Clone() const;                                          // not working yet
    virtual SdrObject*  Clone(SdrPage* pPage, SdrModel* pModel) const;          // not working yet
    virtual void        operator= (const SdrObject& rObj);                      // not working yet
    virtual void clonedFrom(const DlgEdObj* _pSource);                          // not working yet

    virtual sal_Bool        supportsService( const sal_Char* _pServiceName ) const;
    virtual ::rtl::OUString GetDefaultName() const;
    virtual ::rtl::OUString GetUniqueName() const;

    virtual sal_Int32   GetStep() const;
    virtual void        UpdateStep();

    virtual void SetDefaults();
    virtual void SetRectFromProps();
    virtual void SetPropsFromRect();

    virtual void SAL_CALL NameChange( const  ::com::sun::star::beans::PropertyChangeEvent& evt ) throw( ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL TabIndexChange( const  ::com::sun::star::beans::PropertyChangeEvent& evt ) throw( ::com::sun::star::uno::RuntimeException);

    // PropertyChangeListener
    virtual void SAL_CALL _propertyChange( const  ::com::sun::star::beans::PropertyChangeEvent& evt ) throw(::com::sun::star::uno::RuntimeException);

    // ContainerListener
    virtual void SAL_CALL _elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL _elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL _elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);

    virtual void SetLayer(SdrLayerID nLayer);
    virtual SdrObject* CheckHit(const Point& rPnt,USHORT nTol,const SetOfByte*) const;
};

//============================================================================
// DlgEdForm
//============================================================================

class DlgEdForm: public DlgEdObj
{
    friend class DlgEditor;
    friend class DlgEdFactory;

private:
    DlgEditor* pDlgEditor;
    ::std::vector<DlgEdObj*> pChilds;

protected:
    DlgEdForm(const ::rtl::OUString& rModelName);
    DlgEdForm(const ::rtl::OUString& rModelName,
              const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSFac);
    DlgEdForm();

    virtual void NbcMove( const Size& rSize );
    virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact);
    virtual FASTBOOL EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd);

public:
    TYPEINFO();

    virtual ~DlgEdForm();

    virtual void SetDlgEditor( DlgEditor* pEditor ) { pDlgEditor = pEditor; }
    virtual DlgEditor* GetDlgEditor() const { return pDlgEditor; }

    virtual void AddChild( DlgEdObj* pDlgEdObj );
    virtual void RemoveChild( DlgEdObj* pDlgEdObj );
    virtual ::std::vector<DlgEdObj*> GetChilds() const { return pChilds; }

    virtual void UpdateStep();

    virtual void SetRectFromProps();
    virtual void SetPropsFromRect();

    virtual void UpdateTabIndices();
    virtual void UpdateTabOrder();
    virtual void UpdateGroups();
    virtual void UpdateTabOrderAndGroups();

    virtual SdrObject* CheckHit(const Point& rPnt,USHORT nTol,const SetOfByte*) const;
};

#endif // _BASCTL_DLGEDOBJ_HXX

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: image.cxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: vg $ $Date: 2003-05-22 11:01:17 $
 *
 *  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 _STREAM_HXX //autogen
#include <tools/stream.hxx>
#endif
#include <tools/tenccvt.hxx>
#pragma hdrstop
#include <svtools/sbx.hxx>
#include "sb.hxx"
#include <string.h>     // memset() etc
#include "image.hxx"
#include "filefmt.hxx"

SbiImage::SbiImage()
{
    rTypes     = new SbxArray;
    pStringOff = NULL;
    pStrings   = NULL;
    pCode      = NULL;
    nFlags     =
    nStrings   =
    nStringSize=
    nCodeSize  =
    nDimBase   = 0;
    bInit      =
    bError     = FALSE;
    bFirstInit = TRUE;
    eCharSet   = gsl_getSystemTextEncoding();
}

SbiImage::~SbiImage()
{
    Clear();
}

void SbiImage::Clear()
{
    delete[] pStringOff;
    delete[] pStrings;
    delete[] pCode;
    pStringOff = NULL;
    pStrings   = NULL;
    pCode      = NULL;
    nFlags     =
    nStrings   =
    nStringSize=
    nCodeSize  = 0;
    eCharSet   = gsl_getSystemTextEncoding();
    nDimBase   = 0;
    bError     = FALSE;
}

/**************************************************************************
*
*   Service-Routinen fuer das Laden und Speichern
*
**************************************************************************/

BOOL SbiGood( SvStream& r )
{
    return BOOL( !r.IsEof() && r.GetError() == SVSTREAM_OK );
}

// Oeffnen eines Records

ULONG SbiOpenRecord( SvStream& r, UINT16 nSignature, UINT16 nElem )
{
    ULONG nPos = r.Tell();
    r << nSignature << (INT32) 0 << nElem;
    return nPos;
}

// Schliessen eines Records

void SbiCloseRecord( SvStream& r, ULONG nOff )
{
    ULONG nPos = r.Tell();
    r.Seek( nOff + 2 );
    r << (INT32) ( nPos - nOff - 8 );
    r.Seek( nPos );
}

/**************************************************************************
*
*   Laden und Speichern
*
**************************************************************************/

// Falls die Versionsnummer nicht passt, werden die binaeren Teile
// nicht geladen, wohl aber Source, Kommentar und Name.

BOOL SbiImage::Load( SvStream& r )
{
    UINT16 nSign, nCount;
    UINT32 nLen, nOff;

    Clear();
    ULONG nStart = r.Tell();
    // Master-Record einlesen
    r >> nSign >> nLen >> nCount;
    ULONG nLast = r.Tell() + nLen;
    UINT32 nVersion = 0;            // Versionsnummer
    UINT32 nCharSet;                // System-Zeichensatz
    UINT32 lDimBase;
    UINT16 nReserved1;
    UINT32 nReserved2;
    UINT32 nReserved3;
    BOOL bBadVer = FALSE;
    if( nSign == B_MODULE )
    {
        r >> nVersion >> nCharSet >> lDimBase
          >> nFlags >> nReserved1 >> nReserved2 >> nReserved3;
        eCharSet = (CharSet) nCharSet;
        eCharSet = GetSOLoadTextEncoding( eCharSet );
        bBadVer  = BOOL( nVersion != B_CURVERSION );
        nDimBase = (USHORT) lDimBase;
    }

    ULONG nNext;
    while( ( nNext = r.Tell() ) < nLast )
    {
        short i;

        r >> nSign >> nLen >> nCount;
        nNext += nLen + 8;
        if( r.GetError() == SVSTREAM_OK )
          switch( nSign )
        {
            case B_NAME:
                r.ReadByteString( aName, eCharSet );
                //r >> aName;
                break;
            case B_COMMENT:
                r.ReadByteString( aComment, eCharSet );
                //r >> aComment;
                break;
            case B_SOURCE:
            {
                String aTmp;
                r.ReadByteString( aTmp, eCharSet );
                aOUSource = aTmp;
                //r >> aSource;
                break;
            }
            case B_PCODE:
                if( bBadVer ) break;
                pCode = new char[ nLen ];
                nCodeSize = (USHORT) nLen;
                r.Read( pCode, nCodeSize );
                break;
            case B_PUBLICS:
            case B_POOLDIR:
            case B_SYMPOOL:
            case B_LINERANGES:
                break;
            case B_STRINGPOOL:
                if( bBadVer ) break;
                MakeStrings( nCount );
                for( i = 0; i < nStrings && SbiGood( r ); i++ )
                {
                    r >> nOff;
                    pStringOff[ i ] = (USHORT) nOff;
                }
                r >> nLen;
                if( SbiGood( r ) )
                {
                    delete [] pStrings;
                    pStrings = new sal_Unicode[ nLen ];
                    nStringSize = (USHORT) nLen;

                    char* pByteStrings = new char[ nLen ];
                    r.Read( pByteStrings, nStringSize );
                    for( short i = 0; i < nStrings; i++ )
                    {
                        USHORT nOff = pStringOff[ i ];
                        String aStr( pByteStrings + nOff, eCharSet );
                        memcpy( pStrings + nOff, aStr.GetBuffer(), (aStr.Len() + 1) * sizeof( sal_Unicode ) );
                    }
                    delete[] pByteStrings;
                } break;
            case B_MODEND:
                goto done;
            default:
                break;
        }
        else
            break;
        r.Seek( nNext );
    }
done:
    r.Seek( nLast );
    //if( eCharSet != ::GetSystemCharSet() )
        //ConvertStrings();
    if( !SbiGood( r ) )
        bError = TRUE;
    return BOOL( !bError );
}

BOOL SbiImage::Save( SvStream& r )
{
    // Erst mal der Header:
    ULONG nStart = SbiOpenRecord( r, B_MODULE, 1 );
    ULONG nPos;

    eCharSet = GetSOStoreTextEncoding( eCharSet );

    r << (INT32) B_CURVERSION
      << (INT32) eCharSet
      << (INT32) nDimBase
      << (INT16) nFlags
      << (INT16) 0
      << (INT32) 0
      << (INT32) 0;

    // Name?
    if( aName.Len() && SbiGood( r ) )
    {
        nPos = SbiOpenRecord( r, B_NAME, 1 );
        r.WriteByteString( aName, eCharSet );
        //r << aName;
        SbiCloseRecord( r, nPos );
    }
    // Kommentar?
    if( aComment.Len() && SbiGood( r ) )
    {
        nPos = SbiOpenRecord( r, B_COMMENT, 1 );
        r.WriteByteString( aComment, eCharSet );
        //r << aComment;
        SbiCloseRecord( r, nPos );
    }
    // Source?
    if( aOUSource.getLength() && SbiGood( r ) )
    {
        nPos = SbiOpenRecord( r, B_SOURCE, 1 );
        String aTmp;
        sal_Int32 nLen = aOUSource.getLength();
        if( nLen > STRING_MAXLEN )
            aTmp = aOUSource.copy( 0, STRING_MAXLEN - 1 );
        else
            aTmp = aOUSource;
        r.WriteByteString( aTmp, eCharSet );
        //r << aSource;
        SbiCloseRecord( r, nPos );
    }
    // Binaere Daten?
    if( pCode && SbiGood( r ) )
    {
        nPos = SbiOpenRecord( r, B_PCODE, 1 );
        r.Write( pCode, nCodeSize );
        SbiCloseRecord( r, nPos );
    }
    // String-Pool?
    if( nStrings )
    {
        nPos = SbiOpenRecord( r, B_STRINGPOOL, nStrings );
        // Fuer jeden String:
        //  UINT32 Offset des Strings im Stringblock
        for( short i = 0; i < nStrings && SbiGood( r ); i++ )
            r << (UINT32) pStringOff[ i ];

        // Danach der String-Block
        char* pByteStrings = new char[ nStringSize ];
        for( i = 0; i < nStrings; i++ )
        {
            USHORT nOff = pStringOff[ i ];
            ByteString aStr( pStrings + nOff, eCharSet );
            memcpy( pByteStrings + nOff, aStr.GetBuffer(), (aStr.Len() + 1) * sizeof( char ) );
        }
        r << (UINT32) nStringSize;
        r.Write( pByteStrings, nStringSize );

        delete[] pByteStrings;
        SbiCloseRecord( r, nPos );
    }
    // Und die Gesamtlaenge setzen
    SbiCloseRecord( r, nStart );
    if( !SbiGood( r ) )
        bError = TRUE;
    return BOOL( !bError );
}

/**************************************************************************
*
*   Routinen, die auch vom Compiler gerufen werden
*
**************************************************************************/

void SbiImage::MakeStrings( short nSize )
{
    nStrings = nStringIdx = nStringOff = 0;
    nStringSize = 1024;
    pStrings = new sal_Unicode[ nStringSize ];
    pStringOff = new UINT16[ nSize ];
    if( pStrings && pStringOff )
    {
        nStrings = nSize;
        memset( pStringOff, 0, nSize * sizeof( UINT16 ) );
        memset( pStrings, 0, nStringSize * sizeof( sal_Unicode ) );
    }
    else
        bError = TRUE;
}

// Hinzufuegen eines Strings an den StringPool. Der String-Puffer
// waechst dynamisch in 1K-Schritten

void SbiImage::AddString( const String& r )
{
    if( nStringIdx >= nStrings )
        bError = TRUE;
    if( !bError )
    {
        UINT16 len = r.Len() + 1;
        long needed = (long) nStringOff + len;
        if( needed > 0xFF00L )
            bError = TRUE;  // out of mem!
        else if( (USHORT) needed > nStringSize )
        {
            UINT16 nNewLen = needed + 1024;
            nNewLen &= 0xFC00;  // trim to 1K border
            sal_Unicode* p = new sal_Unicode[ nNewLen ];
            if( p )
            {
                memcpy( p, pStrings, nStringSize * sizeof( sal_Unicode ) );
                delete[] pStrings;
                pStrings = p;
                nStringSize = nNewLen;
            }
            else
                bError = TRUE;
        }
        if( !bError )
        {
            pStringOff[ nStringIdx++ ] = nStringOff;
            //ByteString aByteStr( r, eCharSet );
            memcpy( pStrings + nStringOff, r.GetBuffer(), len * sizeof( sal_Unicode ) );
            nStringOff += len;
            // war das der letzte String? Dann die Groesse
            // des Puffers aktualisieren
            if( nStringIdx >= nStrings )
                nStringSize = nStringOff;
        }
    }
}

// Codeblock hinzufuegen
// Der Block wurde vom Compiler aus der Klasse SbBuffer herausgeholt
// und ist bereits per new angelegt. Ausserdem enthaelt er alle Integers
// im Big Endian-Format, kann also direkt gelesen/geschrieben werden.

void SbiImage::AddCode( char* p, USHORT s )
{
    pCode = p;
    nCodeSize = s;
}

void SbiImage::AddType(SbxObject* pObject) // User-Type mit aufnehmen
{
    SbxObject *pCopyObject = new SbxObject(*pObject);
    rTypes->Insert (pCopyObject,rTypes->Count());
}

/**************************************************************************
*
*   Zugriffe auf das Image
*
**************************************************************************/

// IDs zaehlen ab 1!!

String SbiImage::GetString( short nId ) const
{
    if( nId && nId <= nStrings )
    {
        USHORT nOff = pStringOff[ --nId ];
        String aStr( pStrings + nOff );
        return aStr;
    }
    return String();
}

const SbxObject* SbiImage::FindType (String aTypeName) const
{
        return (SbxObject *)rTypes->Find(aTypeName,SbxCLASS_OBJECT);
}

<commit_msg>INTEGRATION: CWS ooo20031110 (1.9.42); FILE MERGED 2003/11/11 11:06:28 waratah 1.9.42.1: #i22301# Correct for scoping rules<commit_after>/*************************************************************************
 *
 *  $RCSfile: image.cxx,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: rt $ $Date: 2003-12-01 16:26:51 $
 *
 *  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 _STREAM_HXX //autogen
#include <tools/stream.hxx>
#endif
#include <tools/tenccvt.hxx>
#pragma hdrstop
#include <svtools/sbx.hxx>
#include "sb.hxx"
#include <string.h>     // memset() etc
#include "image.hxx"
#include "filefmt.hxx"

SbiImage::SbiImage()
{
    rTypes     = new SbxArray;
    pStringOff = NULL;
    pStrings   = NULL;
    pCode      = NULL;
    nFlags     =
    nStrings   =
    nStringSize=
    nCodeSize  =
    nDimBase   = 0;
    bInit      =
    bError     = FALSE;
    bFirstInit = TRUE;
    eCharSet   = gsl_getSystemTextEncoding();
}

SbiImage::~SbiImage()
{
    Clear();
}

void SbiImage::Clear()
{
    delete[] pStringOff;
    delete[] pStrings;
    delete[] pCode;
    pStringOff = NULL;
    pStrings   = NULL;
    pCode      = NULL;
    nFlags     =
    nStrings   =
    nStringSize=
    nCodeSize  = 0;
    eCharSet   = gsl_getSystemTextEncoding();
    nDimBase   = 0;
    bError     = FALSE;
}

/**************************************************************************
*
*   Service-Routinen fuer das Laden und Speichern
*
**************************************************************************/

BOOL SbiGood( SvStream& r )
{
    return BOOL( !r.IsEof() && r.GetError() == SVSTREAM_OK );
}

// Oeffnen eines Records

ULONG SbiOpenRecord( SvStream& r, UINT16 nSignature, UINT16 nElem )
{
    ULONG nPos = r.Tell();
    r << nSignature << (INT32) 0 << nElem;
    return nPos;
}

// Schliessen eines Records

void SbiCloseRecord( SvStream& r, ULONG nOff )
{
    ULONG nPos = r.Tell();
    r.Seek( nOff + 2 );
    r << (INT32) ( nPos - nOff - 8 );
    r.Seek( nPos );
}

/**************************************************************************
*
*   Laden und Speichern
*
**************************************************************************/

// Falls die Versionsnummer nicht passt, werden die binaeren Teile
// nicht geladen, wohl aber Source, Kommentar und Name.

BOOL SbiImage::Load( SvStream& r )
{
    UINT16 nSign, nCount;
    UINT32 nLen, nOff;

    Clear();
    ULONG nStart = r.Tell();
    // Master-Record einlesen
    r >> nSign >> nLen >> nCount;
    ULONG nLast = r.Tell() + nLen;
    UINT32 nVersion = 0;            // Versionsnummer
    UINT32 nCharSet;                // System-Zeichensatz
    UINT32 lDimBase;
    UINT16 nReserved1;
    UINT32 nReserved2;
    UINT32 nReserved3;
    BOOL bBadVer = FALSE;
    if( nSign == B_MODULE )
    {
        r >> nVersion >> nCharSet >> lDimBase
          >> nFlags >> nReserved1 >> nReserved2 >> nReserved3;
        eCharSet = (CharSet) nCharSet;
        eCharSet = GetSOLoadTextEncoding( eCharSet );
        bBadVer  = BOOL( nVersion != B_CURVERSION );
        nDimBase = (USHORT) lDimBase;
    }

    ULONG nNext;
    while( ( nNext = r.Tell() ) < nLast )
    {
        short i;

        r >> nSign >> nLen >> nCount;
        nNext += nLen + 8;
        if( r.GetError() == SVSTREAM_OK )
          switch( nSign )
        {
            case B_NAME:
                r.ReadByteString( aName, eCharSet );
                //r >> aName;
                break;
            case B_COMMENT:
                r.ReadByteString( aComment, eCharSet );
                //r >> aComment;
                break;
            case B_SOURCE:
            {
                String aTmp;
                r.ReadByteString( aTmp, eCharSet );
                aOUSource = aTmp;
                //r >> aSource;
                break;
            }
            case B_PCODE:
                if( bBadVer ) break;
                pCode = new char[ nLen ];
                nCodeSize = (USHORT) nLen;
                r.Read( pCode, nCodeSize );
                break;
            case B_PUBLICS:
            case B_POOLDIR:
            case B_SYMPOOL:
            case B_LINERANGES:
                break;
            case B_STRINGPOOL:
                if( bBadVer ) break;
                MakeStrings( nCount );
                for( i = 0; i < nStrings && SbiGood( r ); i++ )
                {
                    r >> nOff;
                    pStringOff[ i ] = (USHORT) nOff;
                }
                r >> nLen;
                if( SbiGood( r ) )
                {
                    delete [] pStrings;
                    pStrings = new sal_Unicode[ nLen ];
                    nStringSize = (USHORT) nLen;

                    char* pByteStrings = new char[ nLen ];
                    r.Read( pByteStrings, nStringSize );
                    for( short i = 0; i < nStrings; i++ )
                    {
                        USHORT nOff = pStringOff[ i ];
                        String aStr( pByteStrings + nOff, eCharSet );
                        memcpy( pStrings + nOff, aStr.GetBuffer(), (aStr.Len() + 1) * sizeof( sal_Unicode ) );
                    }
                    delete[] pByteStrings;
                } break;
            case B_MODEND:
                goto done;
            default:
                break;
        }
        else
            break;
        r.Seek( nNext );
    }
done:
    r.Seek( nLast );
    //if( eCharSet != ::GetSystemCharSet() )
        //ConvertStrings();
    if( !SbiGood( r ) )
        bError = TRUE;
    return BOOL( !bError );
}

BOOL SbiImage::Save( SvStream& r )
{
    // Erst mal der Header:
    ULONG nStart = SbiOpenRecord( r, B_MODULE, 1 );
    ULONG nPos;

    eCharSet = GetSOStoreTextEncoding( eCharSet );

    r << (INT32) B_CURVERSION
      << (INT32) eCharSet
      << (INT32) nDimBase
      << (INT16) nFlags
      << (INT16) 0
      << (INT32) 0
      << (INT32) 0;

    // Name?
    if( aName.Len() && SbiGood( r ) )
    {
        nPos = SbiOpenRecord( r, B_NAME, 1 );
        r.WriteByteString( aName, eCharSet );
        //r << aName;
        SbiCloseRecord( r, nPos );
    }
    // Kommentar?
    if( aComment.Len() && SbiGood( r ) )
    {
        nPos = SbiOpenRecord( r, B_COMMENT, 1 );
        r.WriteByteString( aComment, eCharSet );
        //r << aComment;
        SbiCloseRecord( r, nPos );
    }
    // Source?
    if( aOUSource.getLength() && SbiGood( r ) )
    {
        nPos = SbiOpenRecord( r, B_SOURCE, 1 );
        String aTmp;
        sal_Int32 nLen = aOUSource.getLength();
        if( nLen > STRING_MAXLEN )
            aTmp = aOUSource.copy( 0, STRING_MAXLEN - 1 );
        else
            aTmp = aOUSource;
        r.WriteByteString( aTmp, eCharSet );
        //r << aSource;
        SbiCloseRecord( r, nPos );
    }
    // Binaere Daten?
    if( pCode && SbiGood( r ) )
    {
        nPos = SbiOpenRecord( r, B_PCODE, 1 );
        r.Write( pCode, nCodeSize );
        SbiCloseRecord( r, nPos );
    }
    // String-Pool?
    if( nStrings )
    {
        nPos = SbiOpenRecord( r, B_STRINGPOOL, nStrings );
        // Fuer jeden String:
        //  UINT32 Offset des Strings im Stringblock
        short i;

        for( i = 0; i < nStrings && SbiGood( r ); i++ )
            r << (UINT32) pStringOff[ i ];

        // Danach der String-Block
        char* pByteStrings = new char[ nStringSize ];
        for( i = 0; i < nStrings; i++ )
        {
            USHORT nOff = pStringOff[ i ];
            ByteString aStr( pStrings + nOff, eCharSet );
            memcpy( pByteStrings + nOff, aStr.GetBuffer(), (aStr.Len() + 1) * sizeof( char ) );
        }
        r << (UINT32) nStringSize;
        r.Write( pByteStrings, nStringSize );

        delete[] pByteStrings;
        SbiCloseRecord( r, nPos );
    }
    // Und die Gesamtlaenge setzen
    SbiCloseRecord( r, nStart );
    if( !SbiGood( r ) )
        bError = TRUE;
    return BOOL( !bError );
}

/**************************************************************************
*
*   Routinen, die auch vom Compiler gerufen werden
*
**************************************************************************/

void SbiImage::MakeStrings( short nSize )
{
    nStrings = nStringIdx = nStringOff = 0;
    nStringSize = 1024;
    pStrings = new sal_Unicode[ nStringSize ];
    pStringOff = new UINT16[ nSize ];
    if( pStrings && pStringOff )
    {
        nStrings = nSize;
        memset( pStringOff, 0, nSize * sizeof( UINT16 ) );
        memset( pStrings, 0, nStringSize * sizeof( sal_Unicode ) );
    }
    else
        bError = TRUE;
}

// Hinzufuegen eines Strings an den StringPool. Der String-Puffer
// waechst dynamisch in 1K-Schritten

void SbiImage::AddString( const String& r )
{
    if( nStringIdx >= nStrings )
        bError = TRUE;
    if( !bError )
    {
        UINT16 len = r.Len() + 1;
        long needed = (long) nStringOff + len;
        if( needed > 0xFF00L )
            bError = TRUE;  // out of mem!
        else if( (USHORT) needed > nStringSize )
        {
            UINT16 nNewLen = needed + 1024;
            nNewLen &= 0xFC00;  // trim to 1K border
            sal_Unicode* p = new sal_Unicode[ nNewLen ];
            if( p )
            {
                memcpy( p, pStrings, nStringSize * sizeof( sal_Unicode ) );
                delete[] pStrings;
                pStrings = p;
                nStringSize = nNewLen;
            }
            else
                bError = TRUE;
        }
        if( !bError )
        {
            pStringOff[ nStringIdx++ ] = nStringOff;
            //ByteString aByteStr( r, eCharSet );
            memcpy( pStrings + nStringOff, r.GetBuffer(), len * sizeof( sal_Unicode ) );
            nStringOff += len;
            // war das der letzte String? Dann die Groesse
            // des Puffers aktualisieren
            if( nStringIdx >= nStrings )
                nStringSize = nStringOff;
        }
    }
}

// Codeblock hinzufuegen
// Der Block wurde vom Compiler aus der Klasse SbBuffer herausgeholt
// und ist bereits per new angelegt. Ausserdem enthaelt er alle Integers
// im Big Endian-Format, kann also direkt gelesen/geschrieben werden.

void SbiImage::AddCode( char* p, USHORT s )
{
    pCode = p;
    nCodeSize = s;
}

void SbiImage::AddType(SbxObject* pObject) // User-Type mit aufnehmen
{
    SbxObject *pCopyObject = new SbxObject(*pObject);
    rTypes->Insert (pCopyObject,rTypes->Count());
}

/**************************************************************************
*
*   Zugriffe auf das Image
*
**************************************************************************/

// IDs zaehlen ab 1!!

String SbiImage::GetString( short nId ) const
{
    if( nId && nId <= nStrings )
    {
        USHORT nOff = pStringOff[ --nId ];
        String aStr( pStrings + nOff );
        return aStr;
    }
    return String();
}

const SbxObject* SbiImage::FindType (String aTypeName) const
{
        return (SbxObject *)rTypes->Find(aTypeName,SbxCLASS_OBJECT);
}

<|endoftext|>


<commit_before><commit_msg>Some correction as per new llvm<commit_after><|endoftext|>