home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Samples / NextHand / Source / NextHand.cpp < prev    next >
C/C++ Source or Header  |  1996-08-12  |  12KB  |  401 lines

  1. // Nexthand.cpp
  2. // Next like Toolbar
  3.  
  4. // $Header: W:/Projects/OCL/Samples/NextHand/Source/rcs/NextHand.cpp 1.50 1996/08/11 23:48:43 B.STEIN Release $
  5.  
  6. #define __OCL_RESOLVE_TEMPLATES__
  7.  
  8. #include "..\Source\NextHand.hpp"
  9.  
  10. #ifdef __EMX__
  11.   template class OList<OIcon>;
  12.   template class OList<NextBarEvent>;
  13. #endif
  14.  
  15.  
  16. pNextHand nxh;
  17.  
  18. void main(int argc, char *argv[])
  19. {
  20.  nxh = new NextHand;
  21.  
  22.  OApp::current().saveArgs(argc, argv);
  23.  
  24.  nxh->toolbar = new NextBar;
  25.  
  26.  if (nxh->toolbar->init())
  27.    {
  28.     OApp::current().run();
  29.     delete nxh;
  30.     _exit(0);
  31.    }
  32.  
  33.  delete nxh;
  34.  
  35.  _exit(1);
  36. }
  37.  
  38.  
  39.  
  40. PSZ NextHand::isOfType() const
  41. {
  42.  return("NextHand");
  43. }
  44.  
  45. BOOL NextHand::ShutdownPosted()
  46. {
  47.  WinSendMsg(toolbar->frame, WM_CLOSE, NULL, NULL);
  48.  return(FALSE);
  49. }
  50.  
  51.  
  52.  
  53. NextBar::NextBar()
  54.   : OHelp(MAIN_HELP_TABLE, NO_HLP_AVAIL),
  55.     OFrame(NHX_MAIN, FCF_TASKLIST, CS_SIZEREDRAW | CS_SAVEBITS),
  56.     floatTimer(this, NHX_FLOAT_TIMER, FLOAT_TIMER)
  57.   {}
  58.  
  59.  
  60. NextBar::~NextBar()
  61. {
  62.  if (ini) delete ini;
  63.  if (nxButtons) delete nxButtons;
  64.  events.reset();
  65. }
  66.  
  67.  
  68. PSZ NextBar::isOfType() const
  69. {
  70.  return("NextBar");
  71. }
  72.  
  73.  
  74. BOOL NextBar::init()
  75. {
  76.  OString  str(OApp::currentOApp->callName);
  77.  pOString pstr = OApp::currentOApp->args.getFirst();
  78.  ULONG    size = sizeof(NextInfo);
  79.  
  80.  if (pstr) {
  81.    Profile << pstr->getText();
  82.    str << pstr->getText();
  83.    if (strstr(str, "."))
  84.      str.rightCut('.');
  85.    str + (PSZ) ".ini"; }
  86.  else {
  87.    str.rightCut('\\'); 
  88.    Profile << str;
  89.    Profile + (PSZ) "\\NextHand.dat";
  90.    str + (PSZ) "\\NextHand.ini"; }
  91.  
  92.  ini = new OProfile(str);
  93.  if ((!ini) || (!ini->getData("NextHand", "NextInfo 1.5", &setup, &size))) {
  94.    strcpy(setup.bubbleFont, "8.Helv");
  95.    setup.style = OButtonBar::left2right;
  96.    setup.floating = FALSE;
  97.    setup.position.x = 0;
  98.    setup.position.y = (ULONG) WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  99.    setup.large = WinQuerySysValue(HWND_DESKTOP, SV_CXICON) > 32 ? TRUE : FALSE;
  100.    buttonSize = setup.large ? 50 : 40;
  101.    setup.position.y -= buttonSize;
  102.    setup.position.cx = 0;
  103.    setup.position.cy = 0; }
  104.  else {
  105.    setup.position.cx = 0;
  106.    setup.position.cy = 0; }
  107.  buttonSize = setup.large ? 50 : 40;
  108.  
  109.  winText << (PSZ)"NextHand Toolbar";
  110.  
  111.  createFrame(winText);
  112.  
  113.  menu = WinLoadMenu(frame, NULLHANDLE, NHX_MENU);
  114.  WinSetParent(menu, HWND_OBJECT, FALSE);
  115.  if (setup.style == OButtonBar::left2right)
  116.    WinCheckMenuItem(menu, NHX_WAAGERECHT, TRUE);
  117.  else
  118.    WinCheckMenuItem(menu, NHX_SENKRECHT, TRUE);
  119.  if (setup.large)
  120.    WinCheckMenuItem(menu, NHX_LARGEICONS, TRUE);
  121.  else
  122.    WinCheckMenuItem(menu, NHX_NORMICONS, TRUE);
  123.  WinCheckMenuItem(menu, NHX_FLOAT, setup.floating);
  124.  
  125.  nxButtons = new OButtonBar(NHX_TOOLBAR, this);
  126.  if (!nxButtons)
  127.     return(FALSE);
  128.  nxButtons->setOrientation(setup.style);
  129.  if (setup.large) {
  130.     nxButtons->setButtonDimensions(50, 50);
  131.     nxButtons->setPicSize(40); }
  132.  
  133.  if (!loadProfile())
  134.     return(FALSE);
  135.  
  136.  nxButtons->createButtonBar();
  137.  nxButtons->bubbleHelpWin.setFont(setup.bubbleFont);
  138.  
  139.  str << OApp::currentOApp->callName;
  140.  str.rightCut('\\'); 
  141.  str + (PSZ) "\\NextHand.hlp";
  142.  initializeHelp(str, "NextHand Help", frame);
  143.  
  144.  WinSetWindowPos(frame, HWND_TOP, setup.position.x, setup.position.y,
  145.                 (setup.style == OButtonBar::left2right) ?  
  146.                  nxButtons->buttons.numberOfElements() * buttonSize : buttonSize,
  147.                 (setup.style == OButtonBar::left2right) ?
  148.                  buttonSize : nxButtons->buttons.numberOfElements() * buttonSize,
  149.                  SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ACTIVATE);
  150.  return(TRUE);
  151. }
  152.  
  153.  
  154. BOOL NextBar::loadProfile()
  155. {
  156.  ifstream         Dat(Profile.getText());
  157.  pNextBarEvent    event = NULL;
  158.  pOGraphicsButton button = NULL;
  159.  CHAR             Buffer[CCHMAXPATH];
  160.  CHAR             *Match;
  161.  ULONG            i = 1;
  162.  pOIcon           ico;
  163.  
  164.  events.reset();
  165.  nxButtons->buttons.reset();
  166.  iconList.reset();
  167.  
  168. // Add the NEXT-Button
  169.  
  170.  ico    = new OIcon(NHX_MAIN, NULLHANDLE);
  171.  button = new OGraphicsButton(NHX_MAIN, nxButtons, ico, "Ordner schließen"); 
  172.  iconList.add(ico);
  173.  nxButtons->buttons.add(button);
  174.  
  175.  if (!Dat) return(TRUE);
  176.  
  177.  Dat.getline(Buffer, sizeof(Buffer)-1);
  178.  if(!strstr(Buffer, "NEXTHAND BEGIN")) 
  179.    {
  180.     error(NO_NEXTHAND_FILE);
  181.     return(FALSE); 
  182.    }
  183.  
  184.  while(!Dat.fail())
  185.    {
  186.     if(strstr(Buffer, "NEXTHAND END"))
  187.       break;
  188.     while((Dat.getline(Buffer, sizeof(Buffer)-1)) &&
  189.             (!strstr(Buffer, "MENUITEM")) &&
  190.             (!strstr(Buffer, "NEXTHAND END"))) 
  191.       {
  192.        Buffer[strlen(Buffer)]='\0';
  193.        Match=strchr(Buffer, ':');
  194.        if(Match=='\0')
  195.          Match=strchr(Buffer, '\0');
  196.        else if ((Match=strchr(Match, ' '))==NULL)
  197.          Match=strchr(Buffer, '\0');
  198.        else
  199.          for( ; (*Match==' ') && (*Match!='\0'); Match++);
  200.        if(strstr(Buffer, "PgmTitle"))
  201.          event->title << (PSZ) Match;
  202.        else if(strstr(Buffer, "PgmIcon"))
  203.          event->icon << (PSZ) Match;
  204.        else if(strstr(Buffer, "PgmName"))
  205.          event->name << (PSZ) Match;
  206.        else if(strstr(Buffer, "PgmDirectory"))
  207.          event->dir << (PSZ) Match;
  208.        else if(strstr(Buffer, "PgmInputs"))
  209.          event->inputs << (PSZ) Match;
  210.        else if(strstr(Buffer, "DOSSETTINGS BEGIN")) {
  211.          Dat.getline(Buffer, sizeof(Buffer)-1);
  212.          while(!strstr(Buffer, "DOSSETTINGS END")) {
  213.            event->settings + (PSZ) Buffer;
  214.            event->settings + (PSZ) "\n";
  215.            Dat.getline(Buffer, sizeof(Buffer)-1); }}
  216.        else if(strstr(Buffer, "SessionType"))
  217.          event->session = atol(Match);
  218.        else if(strstr(Buffer, "PgmControl"))
  219.          event->control = atol(Match);
  220.        else if(strstr(Buffer, "FgBg"))
  221.          event->Bkgr = atol(Match); 
  222.       }
  223.  
  224.    if (event)
  225.      events.add(event);
  226.    if(strstr(Buffer, "NEXTHAND END"))
  227.      break;
  228.    else if(strstr(Buffer, "MENUITEM"))
  229.      event = new NextBarEvent;
  230.   }
  231.  
  232.  Dat.close();
  233.  
  234.  event = events.getFirst();
  235.  while(event){
  236.     try {
  237.       ico = new OIcon((!event->icon) ? event->name : event->icon); }
  238.     catch(OPMException& ex) {
  239.       ico = new OIcon; }
  240.  
  241.     button = new OGraphicsButton(NHX_FIRST_BUTTON + i,
  242.                                  nxButtons, ico, event->title); 
  243.     nxButtons->buttons.add(button);
  244.     iconList.add(ico);
  245.     i++;
  246.     event = events.getNext(); }
  247.  
  248.  return(TRUE);
  249. }
  250.  
  251.  
  252. BOOL NextBar::saveProfile()
  253. {
  254.  ofstream       Dat(Profile);
  255.  pNextBarEvent  event = events.getFirst();
  256.  
  257.  Dat << "NEXTHAND BEGIN" << endl;
  258.  while(event)
  259.    {
  260.     Dat << "MENUITEM" << endl;
  261.     if (event->title)
  262.        Dat << "PgmTitle: " << event->title.getText() << endl;
  263.     if (event->name)
  264.        Dat << "PgmName: " << event->name.getText() << endl;
  265.     if (event->icon)
  266.        Dat << "PgmIcon: " << event->icon.getText() << endl;
  267.     if (event->dir)
  268.        Dat <<  "PgmDirectory: " << event->dir.getText() << endl;
  269.     if (event->inputs)
  270.        Dat << "PgmInputs: " << event->inputs.getText() << endl;
  271.     if (((event->session == SSF_TYPE_VDM) || 
  272.          (event->session == SSF_TYPE_WINDOWEDVDM) ||
  273.          (event->session == PROG_WINDOW_PROT) ||
  274.          (event->session == PROG_31_ENH)) &&
  275.          (strlen(event->settings)!=0))
  276.        Dat << "DOSSETTINGS BEGIN" << endl
  277.            << event->settings.getText()
  278.            << "\nDOSSETTINGS END" << endl;
  279.     if (event->session != SSF_TYPE_DEFAULT)
  280.        Dat << "SessionType: " <<  (ULONG) event->session << endl;
  281.     if (event->control != SSF_CONTROL_VISIBLE)
  282.        Dat << "PgmControl: " << (ULONG) event->control << endl;
  283.     if (event->Bkgr & SSF_FGBG_BACK)
  284.        Dat << "FgBg: " << (ULONG) event->Bkgr << endl;
  285.     event = events.getNext();
  286.    }
  287.  Dat << "NEXTHAND END" << endl;
  288.  Dat.close();
  289.  return(TRUE);
  290. }
  291.  
  292.  
  293. void NextBar::setNewStyle(ULONG flag)
  294. {
  295.  WinQueryWindowPos(frame, &setup.position);
  296.  hideFrame();
  297.  WinCheckMenuItem(menu, NHX_WAAGERECHT, (flag == OButtonBar::left2right) ? TRUE : FALSE);
  298.  WinCheckMenuItem(menu, NHX_SENKRECHT, (flag == OButtonBar::left2right) ? FALSE : TRUE);
  299.  WinCheckMenuItem(menu, NHX_LARGEICONS, setup.large ? TRUE : FALSE);
  300.  WinCheckMenuItem(menu, NHX_NORMICONS, setup.large ? FALSE : TRUE);
  301.  if (setup.large) {
  302.     nxButtons->setButtonDimensions(50, 50);
  303.     nxButtons->setPicSize(40); }
  304.  else {
  305.     nxButtons->setButtonDimensions(40, 40);
  306.     nxButtons->setPicSize(32); }
  307.  buttonSize = setup.large ? 50 : 40;
  308.  
  309.  nxButtons->destroyButtons();
  310.  setup.style = flag;
  311.  nxButtons->setOrientation(setup.style);
  312.  WinSetWindowPos(frame, HWND_TOP, 0, 0,
  313.                 (setup.style == OButtonBar::left2right) ?
  314.                  nxButtons->buttons.numberOfElements() * buttonSize : buttonSize,
  315.                 (setup.style == OButtonBar::left2right) ?
  316.                  buttonSize : nxButtons->buttons.numberOfElements() * buttonSize,
  317.                  SWP_SIZE | SWP_ACTIVATE);
  318.  nxButtons->setupButtons();
  319.  showFrame();
  320. }
  321.  
  322.  
  323. void NextBar::trackButtons()
  324. {
  325.  TRACKINFO         TrackInfo;
  326.  
  327.  WinQueryWindowPos(frame, &sizepos);
  328.  memset (&TrackInfo, 0, sizeof(TrackInfo));  // init the trackinfo struct
  329.  
  330.  TrackInfo.cxBorder = 1;
  331.  TrackInfo.cyBorder = 1;
  332.  TrackInfo.cxGrid = 1;
  333.  TrackInfo.cyGrid = 1;
  334.  TrackInfo.cxKeyboard = 8;
  335.  TrackInfo.cyKeyboard = 8;
  336.  TrackInfo.rclTrack.xLeft   = sizepos.x;
  337.  TrackInfo.rclTrack.xRight  = sizepos.x + sizepos.cx;
  338.  TrackInfo.rclTrack.yBottom = sizepos.y;
  339.  TrackInfo.rclTrack.yTop = sizepos.y + sizepos.cy;
  340.  WinQueryWindowPos(HWND_DESKTOP, &sizepos);
  341.  TrackInfo.rclBoundary.xLeft   = sizepos.x;
  342.  TrackInfo.rclBoundary.xRight  = sizepos.x + sizepos.cx;
  343.  TrackInfo.rclBoundary.yBottom = sizepos.y;
  344.  TrackInfo.rclBoundary.yTop = sizepos.y + sizepos.cy;
  345.  TrackInfo.ptlMinTrackSize.x = 0;
  346.  TrackInfo.ptlMinTrackSize.y = 0;
  347.  TrackInfo.ptlMaxTrackSize.x = sizepos.cx;
  348.  TrackInfo.ptlMaxTrackSize.y = sizepos.cy;
  349.  TrackInfo.fs = TF_MOVE | TF_STANDARD | TF_ALLINBOUNDARY;
  350.  
  351.  if (WinTrackRect(HWND_DESKTOP, 0, &TrackInfo))   // now we move ourselves
  352.     WinSetWindowPos(frame, 0, (SHORT) TrackInfo.rclTrack.xLeft,
  353.                               (SHORT) TrackInfo.rclTrack.yBottom, 0, 0, SWP_MOVE);
  354.  WinSetWindowPos(frame, 0, 0, 0, 0, 0, SWP_SHOW | SWP_ACTIVATE);
  355.  WinQueryWindowPos(frame, &setup.position);
  356. }
  357.  
  358.  
  359. void NextBar::resetToolBar()
  360. {
  361.  hideFrame();
  362.  saveProfile();
  363.  nxButtons->destroyButtons();
  364.  loadProfile();
  365.  nxButtons->setupButtons();
  366.  WinSetWindowPos(frame, HWND_TOP, setup.position.x, setup.position.y,
  367.                 (setup.style == OButtonBar::left2right) ?
  368.                  nxButtons->buttons.numberOfElements() * buttonSize : buttonSize,
  369.                 (setup.style == OButtonBar::left2right) ?
  370.                  buttonSize : nxButtons->buttons.numberOfElements() * buttonSize,
  371.                  SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ACTIVATE);
  372. }
  373.  
  374.  
  375. void NextBar::closeFolders(BOOL close)
  376. {
  377.  CHAR  Class[33];
  378.  HENUM henum;
  379.  HWND  hwndd, hwndNext;
  380.  
  381.  hwndd = WinQueryWindow(HWND_DESKTOP, QW_BOTTOM);
  382.  henum = WinBeginEnumWindows(HWND_DESKTOP);
  383.  
  384.  while ((hwndNext = WinGetNextWindow(henum)) != NULLHANDLE) 
  385.   {
  386.    WinQueryClassName(hwndNext, 32, Class);
  387.    if ((hwndNext != hwndd) && 
  388.        (!strcmp(Class, "wpFolder window")))
  389.     {
  390.      WinSetFocus(HWND_DESKTOP, hwndNext);
  391.      if (close)
  392.        WinPostMsg(hwndNext, WM_CLOSE, NULL, NULL);
  393.      else
  394.        WinSetWindowPos(hwndNext, HWND_BOTTOM, 0, 0, 0, 0, SWP_HIDE);
  395.     }
  396.   }
  397.  WinEndEnumWindows(henum);
  398. }
  399.  
  400. // end
  401.