//********************************************************************************
// Mozilla GBM plug-in: GbmBitmapViewer.hpp
//
// Copyright (C) 2006-2008 Heiko Nitzsche
//
//   This software is provided 'as-is', without any express or implied
//   warranty.  In no event will the author be held liable for any damages
//   arising from the use of this software.
//
//   Permission is granted to anyone to use this software for any purpose,
//   including commercial applications, and to alter it and redistribute it
//   freely, subject to the following restrictions:
//
//   1. The origin of this software must not be misrepresented; you must not
//      claim that you wrote the original software. If you use this software
//      in a product, an acknowledgment in the product documentation would be
//      appreciated but is not required.
//   2. Altered source versions must be plainly marked as such, and must not be
//      misrepresented as being the original software.
//   3. This notice may not be removed or altered from any source distribution.
//
//********************************************************************************

#ifndef __CLASS_GBM_BITMAP_VIEWER__
    #define __CLASS_GBM_BITMAP_VIEWER__


#include "os2defs.h"
#include "gbmdlg.h"

#include "GbmDocument.hpp"
#include "GbmRenderer.hpp"

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

class GbmBitmapViewer
{
    public:

        GbmBitmapViewer(HMODULE hMod, GbmDocument & document, const GbmDialogAccessor * pDlgAccessor);
        virtual ~GbmBitmapViewer();

        void setParentWindow(HWND hwnd, BOOL fullMode);
        void setLoadProgress(const int progress, const int progressMax);
        void setScalerType(const GbmRenderer::ScalerType scalerType);

        void draw(HPS hps, RECTL *rect, double pageScaleX, double pageScaleY);

        BOOL hasBitmap() const;

        int  getNumberOfPages() const;
        int  getPageWidth();
        int  getPageHeight();
        int  getPageColorDepth();

        const char * getLongDescription() const;

        HWND getFrameHwnd() const { return mHwndFrame; }

        MRESULT instanceWindowProcedure      (HWND  hwnd, ULONG  msg, MPARAM mp1, MPARAM mp2);
        MRESULT instanceGbmDlgWindowProcedure(HWND  hwnd, ULONG  msg, MPARAM mp1, MPARAM mp2) const;

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

    private:

        // types

        enum ZoomMode { ZoomMode_NONE, ZoomMode_FITWIN, ZoomMode_FITWIDTH, ZoomMode_STRETCH, ZoomMode_FREE };

        typedef struct LANG_LOOKUP_TABLE_DEF
        {
            const char  * language;
                  short   resid[7];
        } LANG_LOOKUP_TABLE_ENTRY;

        static struct LANG_LOOKUP_TABLE_DEF  LANG_LOOKUP_TABLE [];
        static int    LANG_LOOKUP_TABLE_LENGTH;

        // variables

        const LANG_LOOKUP_TABLE_ENTRY * mpLanguage;
              char                      mStringSaveAs[101];
              char                      mStringOverrideFile[101];

              HMODULE             mDllModule;
              GbmDocument       & mGbmDocument;
        const GbmDialogAccessor * mpDlgAccessor;

        int        mCurrentPopupMenuId;
        int        mCurrentPageIndex;
        double     mScaleX, mScaleY;
        ZoomMode   mZoomMode;
        GbmRenderer::ScalerType mScalerType;

        int  mLoadProgress, mLoadProgressMax;

        HWND mHwndFrame  , mHwndClient;
        HWND mHwndHScroll, mHwndVScroll;
        HWND mHwndMenu   , mHwndPopupMenu;
        HWND mHwndHelp;

        SHORT mHScrollMax, mHScrollPos, mHScrollInc;
        SHORT mVScrollMax, mVScrollPos, mVScrollInc;

        SHORT mCxClient, mCyClient;

        CHAR mStringUnsupportedFmt[50];
        CHAR mSaveAsFilename[CCHMAXPATH+1];
        CHAR mSaveAsOptions [L_GBM_OPTIONS+1];

        // functions

        BOOL createHelpInstance(const HAB hab);
        void destroyHelpInstance();

        void executeOperations(HWND hwnd, long rotateBy, GbmDocumentPage::MirrorMode mirrorMode);
        void gotoPageIndex    (HWND hwnd, int pageIndex);
        void updateScaleFactor(HWND hwnd, BOOL forceWindowRepaint, BOOL skipWindowRepaint);
        void updateWindowSize (HWND hwnd);
        void updateScrollBars (HWND hwnd);
        void updateMenuItems  (HWND hwnd, SHORT itemId) const;

        BOOL showFileDialog_SaveAs(HWND   hwnd,
                                   CHAR * filename, int          filenameSize,
                                   CHAR * options , int          optionsSize) const;
        BOOL processGbmFileDlg(HWND   hwndDlg , GBMFILEDLG * gbmfild,
                               CHAR * filename, int          filenameSize,
                               CHAR * options , int          optionsSize) const;
};

#endif


