#include <WScom.h>
#include <WSCfunctionList.h>
#include <WSCbase.h>

#include <WSCfileSelect.h>
#include <WSCtextField.h>
#include <WSCmessageDialog.h>

//----------------------------------------------------------
//Function for the event procedure
//----------------------------------------------------------
WSCstring backup;
void m12ep(WSCbase* object){
  //do something...
  WSCfileSelect* fs = WSGIappFileSelect();
  fs->setProperty(WSNmaskFileName,"");
  fs->setProperty(WSNdefaultPosition,True);
  long ret = fs->popup();
  if (ret == WS_DIALOG_OK){
    WSCstring* str = WSGFreadTextFile(fs->getFileName());
    if (str != NULL){
extern WSCtextField* newtext_001;
      newtext_001->setProperty(WSNlabelString,str->getString());
      newtext_001->setProperty(WSNuserString,fs->getFileName());
      backup = str->getString();
extern WSCbaseDialog* newwin000;
      WSCstring title;
      title << "NotePad: " << (char*)fs->getFileName();
      newwin000->setProperty(WSNtitleString,title);
      delete str;
    }else{
      WSCmessageDialog* msg = WSGIappMessageDialog();
      WSCstring message;
      message << "Can not open file:\n"
              << fs->getFileName() << ".";
      msg->setProperty(WSNdefaultPosition,True);
      msg->setProperty(WSNwidth,400);
      msg->setProperty(WSNheight,130);
      msg->setProperty(WSNlabelString,message); 
      msg->popup();
    }
  }
}
static WSCfunctionRegister  op("m12ep",(void*)m12ep);
