SOL9 Sample: ScrolledImageViewer

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * ScrolledImageViewer.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL9

// 2012/07/15 
// 2012/08/07

#define COMMONCONTROLS_V6

#include <sol\ApplicationView.h>
#include <sol\PaintDC.h>
#include <sol\ScrolledImageView.h>
#include <sol\FileDialog.h>
#include <sol\DropFiles.h>

#include <sol\Folder.h>

#include "resource.h"

namespace SOL {

class ScrolledImageViewer :public ApplicationView {

private:

  FileDialog    fileDialog;

  _bstr_t imageFileName;

  ScrolledImageView imageViewer;

public:
  /**
   * Constructor
   */
  ScrolledImageViewer(Application& applet, const TCHAR* name, Args& args)
  :ApplicationView(applet, name,
    args.set(XmNstyle, WS_CLIPCHILDREN|WS_CLIPSIBLINGS)
        .set(XmNexStyle,(ulong)WS_EX_ACCEPTFILES) ) 
  {
    Args ar;
    ar.set(XmNstyle, WS_CHILD|WS_VISIBLE);
    ar.set(XmNx, 0);
    ar.set(XmNy, 0);
    ar.set(XmNwidth, 720);
    ar.set(XmNheight, 600);
    imageViewer.create(this, NULL, ar);
    imageViewer.disable();

    addCallback(XmNmenuCallback, IDM_OPEN, this,
      (Callback)&ScrolledImageViewer::open, NULL);
    addCallback(XmNmenuCallback, IDM_EXIT, this,
      (Callback)&ScrolledImageViewer::exit, NULL);

    addCallback(XmNmenuCallback, IDM_VERSION, this,
      (Callback)&ScrolledImageViewer::version, NULL);


    addEventHandler(WM_SIZE, this, 
      (Handler)&ScrolledImageViewer::size, NULL);

    addEventHandler(WM_CLOSE, this, 
      (Handler)&ScrolledImageViewer::close, NULL);

    ar.reset();
    ar.set(XmNfilter, 
      _T("Image File(*.bmp,*.jpg,*.png,*.tif,*.ico,*.gif)\0*.bmp;*.jpg;*.png;*.tif;*.ico;*.gif\0JPEG File*.jpg)\0*.jpg\0PNG File(*.png)\0*.png\0Tiff File(*.tif)\0*.tif\0Icon File(*.ico)\0*.ico;\0GIF File(*.gif)\0*.gif;\0"));

    fileDialog.create(this, _T(""), ar);

    restorePlacement();
  }

public:
  ~ScrolledImageViewer()
  {
    clear();
  }

private:
  void clear()
  {
    imageViewer.clear();
    imageViewer.disable();
  }

private:
  long close(Event& event)
  {
    savePlacement();
    return defaultProc(event);
  }

private:
  void  open(Action& action)
  {
    Args ar;
    
    TCHAR dir[MAX_PATH];
    memset(dir, (TCHAR)0, CountOf(dir));

    if (restoreFileFolder(dir, CountOf(dir))) {
      ar.set(XmNdirectory, dir);
      fileDialog.setValues(ar);
    }
  
    if(fileDialog.open()){

      imageFileName = fileDialog.getFileName();
      TCHAR* filename = fileDialog.getFileName();

      TCHAR* ftitle = fileDialog.getFileTitle();
    
      File file;
      if (file.isExistent(filename)) {
        saveFileFolder(filename);
        imageViewer.enable();
        imageViewer.drawImage(imageFileName);

        TCHAR title[MAX_PATH];
        _stprintf_s(title, CountOf(title), _T("%s - ScrolledImageViewer"), (const TCHAR*)imageFileName);    
        setText(title);

      }
    }  
  }

private:
  long size(Event& event)
  {
    int w, h;
    event.getSize(w, h);
    imageViewer.reshape(0, 0, w, h);

    return 0;
  }

private:
  void version(Action& action)
  {
    showMessageDialog(_T("Version"),
      _T("ScrolledImageViewer 1.0.0.1 \r\n Copyright(c) 2012 Antillia.com"), MB_ICONINFORMATION|MB_OK);
  }
};

}


//////////////////////////////////////////////
//
void  Main(int argc, TCHAR** argv)
{
  ModuleFileName module(argv[0]);
  const TCHAR* name = module.getFileName();
  
  try {
    Application applet(name, argc, argv);

    Args args;
    
    ScrolledImageViewer imageViewer(applet, name, args);
    imageViewer.realize();

    applet.run();

  } catch (Exception& ex) {
    caught(ex);
  } catch (...) {
    caught(UnknownException());
  }
}


Last modified: 1 Feb 2017

Copyright (c) 2017 Antillia.com ALL RIGHTS RESERVED.