SOL9 Sample: Explorer

SOL9 2.0 Samples

1 Screenshot


2 Source code

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



// SOL++2000 
// 2000.02.18

#define COMMONCONTROLS_V6

#include <sol\ApplicationView.h>
#include <sol\ComboBox.h>
#include <sol\Label.h>
#include <sol/FileInfo.h>
#include "DirTreeView.h"
#include "resource.h"

namespace SOL {

class Explorer :public ApplicationView {
private:
  Label     label;
  ComboBox   drives;
  DirTreeView  treev;

public:
  Explorer(Application& applet, const TCHAR* name, Args& args)
    :ApplicationView(applet, name, 
      args.set(XmNbackground, (COLOR_BTNFACE+1))  )
  {
    Args ar;
    label.create(this, _T("Drive: "), ar);

    ar.reset();
    ar.set(XmNstyle, (ulong)CBS_DROPDOWNLIST);
    drives.create(this, _T(""), ar);

    drives.addCallback(XmNselChangeCallback, this,
      (Callback)&Explorer::driveSelected, NULL);
    buildDriveList();

    ar.reset();
    ar.set(XmNexStyle, (ulong)WS_EX_CLIENTEDGE);
    ar.set(XmNstyle, (ulong)TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT);
    treev.create(this, _T(""), ar);

    addCallback(XmNmenuCallback, IDM_REFRESH, this,
      (Callback)&Explorer::refresh, NULL);

    addCallback(XmNmenuCallback, IDM_EXIT, this,
      (Callback)&Explorer::exit, NULL);

    treev.addCallback(XmNitemExpandingCallback, this,
      (Callback)&Explorer::expanding, NULL);

    TCHAR dir[_MAX_PATH];
    ::GetCurrentDirectory(CountOf(dir), dir); //2012/06/26
    TCHAR* p = (TCHAR*)strchr(dir, (TCHAR)':');
    if(p++) {
      *p = NULL;
    }
    int pos = drives.findStringExact(-1, dir);
    drives.selectString(pos, dir);
    FileInfo fileInfo;
    
    int iconId = fileInfo.getSmallIconIndex(dir);

    HTREEITEM root = treev.addItem(NULL, TVI_ROOT, dir, iconId, iconId);
  
    treev.findDirectories(root, dir, 0, 2);
    treev.sortChildren(root, TRUE);
    treev.expand(root, TVE_EXPAND);
  }

private:
  void refresh(Action& action)
  {
    showMessageDialog(_T("Explorer"), _T("Not implemented yet"), MB_OK);
  }

private:
  void buildDriveList()
  {
    TCHAR path[10];
    DWORD d = ::GetLogicalDrives();
    for(int i = 0; i<26; i++) {
      if(d & 1) {
        _stprintf_s(path, CountOf(path), _T("%c:"), (TCHAR)'A'+i);
        drives.addString(path);
      }
      d = d >> 1;
    }
  }

private:
  void driveSelected(Action& action)
  {
    TCHAR dir[10];
    int idx = drives.getCurSel();
    if(idx != CB_ERR) {
      drives.getLBText(idx, dir);
      treev.deleteAllItems();
      FileInfo fileInfo;
      int iconId = fileInfo.getSmallIconIndex(dir);

      HTREEITEM root = treev.addItem(NULL, TVI_ROOT, dir, iconId, iconId);
      treev.findDirectories(root, dir, 0, 2);
      treev.sortChildren(root, TRUE);
      treev.expand(root, TVE_EXPAND);
    }
  }

private:
  long size(Event& event)
  {
    LPARAM s = event.getLParam();
    int h = drives.getItemHeight(-1)+4;
    RECT r;
    label.getWindowRect(&r);
    int w = r.right - r.left;
    label.reshape(2, 2, w-2,  h);
    drives.reshape(w+2, 2, 100, 100); 
    treev.reshape(0, h+6, LOWORD(s), HIWORD(s)-h-6);
    return 0L;
  }

private:
  void expanding(Action& action)
  {               
    Event& event = action.getEvent();  
    NM_TREEVIEW* nmtreev = (NM_TREEVIEW*)event.getLParam();
    HTREEITEM htreeItem = nmtreev->itemNew.hItem;
   
    StringBufferT<TCHAR> dir;
    // Get fullpathname of the selected node
    treev.getHierachy(htreeItem, dir, _T("\\"));
    // Delete all children
    treev.deleteChildren(htreeItem);
    // Builde a tree for the subdirectory
    treev.findDirectories(htreeItem, dir, 0, 2);
    treev.sortChildren(htreeItem, TRUE);
  }
};

}

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

    Args args;
    Explorer explorer(applet, name, args);
    explorer.realize();

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


Last modified: 1 Feb 2017

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