SOL9 Sample: GradientToolBar

SOL9 2.0 Samples

1 Screenshot


2 Source code

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


// SOL9
// 2012/07/02


#include <sol\ApplicationView.h>

#include <sol\FileDialog.h>
#include <sol\TransparentButton.h>
#include <sol\GradientToolBar.h>
#include <sol\ImageBox.h>
#include "resource.h"

namespace SOL {

class AppView :public ApplicationView {
private:
  GradientToolBar  toolBar;
  TransparentButton openButton;
  TransparentButton exitButton;

  ImageBox    imageBox;

  FileDialog      filedlg;

public:
  /**
   * Constructor
   */
  AppView(Application& applet, const TCHAR* name, Args& args)
  :ApplicationView(applet, name,
    args.set(XmNstyle, (ulong)WS_CLIPCHILDREN|WS_CLIPSIBLINGS ))
  {
    Args ar;
    //ar.set(XmNgradientColor, GradientToolBar::LIGHT_YELLOW);
    //ar.set(XmNgradientColor, GradientToolBar::LIGHT_PINK);
    ar.set(XmNgradientColor, GradientToolBar::LIGHT_BLUE);
    //ar.set(XmNgradientColor, GradientToolBar::LIGHT_GRAY);
    ar.set(XmNgradientContrast, 6);
    toolBar.create(this, NULL, ar);

    ar.reset();
    ar.set(XmNx,      4);
    ar.set(XmNy,      4);
    ar.set(XmNwidth,  80);
    ar.set(XmNheight, 28);
    ar.set(XmNtextColor, RGB(0, 0, 0xff));
    ar.set(XmNtextAlignment, DT_CENTER);
    ar.set(XmNstyle,  (ulong)WS_BORDER);
    ar.set(XmNcursor, (ulong)LoadCursor(NULL, IDC_HAND));
    openButton.create(&toolBar, _T("Open"), ar);

    ar.reset();
    ar.set(XmNx,      4+90);
    ar.set(XmNy,      4);
    ar.set(XmNwidth,  80);
    ar.set(XmNheight, 28);
    ar.set(XmNtextColor, RGB(0, 0, 0xff));
    ar.set(XmNtextAlignment, DT_CENTER);

    ar.set(XmNstyle,  (ulong)WS_BORDER);
    exitButton.create(&toolBar, _T("Exit"), ar);

    openButton.addCallback(XmNarmCallback, this,
      (Callback)&AppView::open, NULL);
      
    exitButton.addCallback(XmNarmCallback, this,
      (Callback)&AppView::exit, NULL);

    ar.reset();
    ar.set(XmNx, 10);
    ar.set(XmNy, 50);
    ar.set(XmNwidth, 720);
    ar.set(XmNheight,420);

    ar.set(XmNscaling, ImageBox::StretchWindow);

    imageBox.create(this, NULL, ar);

    addCallback(XmNmenuCallback, ID_OPEN, this,
      (Callback)&AppView::open, NULL);
    addCallback(XmNmenuCallback, ID_EXIT, this,
      (Callback)&AppView::exit, NULL);


    TCHAR dir[_MAX_PATH];

    ::GetWindowsDirectory(dir, CountOf(dir));
    TCHAR* p = (TCHAR*)strchr(dir, (TCHAR)'\\');
    if (p) {
      p++;
      *p = '\0';
    }
  
    ar.reset();
    ar.set(XmNdirectory, dir);
    ar.set(XmNfilter, _T("Image (*.jpg)\0 *.jpg\0"));
    filedlg.create(this, _T("FileSelection"), ar);
  }

public:
  ~AppView()
  {
  }

private:
  void open(Action& action)
  {
    TCHAR dir[MAX_PATH];
    memset(dir, (TCHAR)0, CountOf(dir));
    if (restoreFileFolder(dir, CountOf(dir))) {
      Args ar;
      ar.set(XmNdirectory, dir);
      filedlg.setValues(ar);
    }

    if(filedlg.open() == IDOK) {
      TCHAR* filename = filedlg.getFileName();
      TCHAR title[256];
      ClientDC cdc(this);

      //Load an original image.
      //loadedImage.load(cdc, filename);
      imageBox.loadImage(filename);

      //2008/09/16
      saveFileFolder(filename);
      
      invalidateAll();

      update();

      _stprintf_s(title, CountOf(title), _T("%s - GradientToolBar"), filename);
      
      setText(title);

    }
  }

private:
  long size(Event& event)
  {
    int w, h;
    event.getSize(w, h);
    toolBar.reshape(0, 0, w, 38);
    return 0L;
  }

};

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

    Args args;
    args.set(XmNclassStyle, NO_REDRAW);
    AppView appView(applet, name, args);
    appView.realize();

    applet.run();

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


Last modified: 1 Feb 2017

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