home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vclassrc.zip / vclassed.c < prev    next >
Text File  |  1998-12-27  |  10KB  |  267 lines

  1. /*  <VClassed 1.6, a PM OS/2 WorkPlace Shell class manager>
  2.     Copyright (C) 1996, 1997, 1998  Daniele Vistalli
  3.  
  4.     This program is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation; either version 2 of the License, or
  7.     (at your option) any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.  
  19.     You can contact me :
  20.     Daniele Vistalli :
  21.             dvistalli@tin.it
  22.         virusface@usa.net
  23.  
  24. */
  25.  
  26. #define INCL_WIN
  27.  
  28. #include <os2.h>
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #include <string.h>
  32.  
  33. #include "vclassed.h"
  34.  
  35. #define WM_LoadCList WM_USER+1
  36.  
  37. MRESULT EXPENTRY VCEdProc (HWND wnd,ULONG msg,MPARAM mp1,MPARAM mp2)
  38. {
  39.    static HWND LBwnd, Popup;
  40.    static PSZ *Classes, *Modules;
  41.    static SHORT Selcount;
  42.    static SHORT Selection;
  43.    static BOOL Sorted;
  44.    POBJCLASS p,q;
  45.    ULONG Size;
  46.    POINTL mspos;
  47.    char tmp[80];
  48.  
  49.    switch (msg) {
  50.      case WM_INITDLG :
  51.            LBwnd = WinWindowFromID(wnd,DID_List);
  52.            // Load & Set popup menu
  53.            Popup = WinLoadMenu(HWND_DESKTOP,NULLHANDLE,MNU_PopupList);
  54.            WinEnableMenuItem(Popup,BTN_Dereg,FALSE);
  55.            WinEnableMenuItem(Popup,BTN_Create,FALSE);
  56.  
  57.            Sorted = TRUE;
  58.            WinCheckMenuItem(Popup,BTN_Sorted,Sorted);
  59.  
  60.            WinPostMsg(wnd,WM_LoadCList,0,0);
  61.            return(0);
  62.      case WM_BUTTON2DOWN :
  63.            mspos.x = MOUSEMSG(&msg)->x;
  64.            mspos.y = MOUSEMSG(&msg)->y;
  65.            if (WinWindowFromPoint(wnd, &mspos, FALSE) == LBwnd)
  66.            {
  67.               // Executes popup menu
  68.               WinPopupMenu(wnd,wnd,Popup, mspos.x, mspos.y, 1,PU_KEYBOARD | PU_MOUSEBUTTON1 | PU_HCONSTRAIN | PU_VCONSTRAIN);
  69.               return((MRESULT) 1);
  70.            }
  71.            return(WinDefDlgProc(wnd,msg,mp1,mp2));
  72.      case WM_CONTROL :
  73.          if (SHORT1FROMMP(mp1) == DID_List)
  74.             {
  75.              switch (SHORT2FROMMP(mp1)) {
  76.               case LN_SELECT : { Selcount = 0;
  77.                                  Selection = LIT_FIRST;
  78.                                  while ((Selection = SHORT1FROMMR(WinSendMsg(LBwnd,LM_QUERYSELECTION,MPFROMSHORT(Selection),0))) != LIT_NONE) Selcount++;
  79.                                  if (Selcount == 1)
  80.                                   {
  81.                                    tmp[0] = 0;
  82.                                    strcat(tmp,*(Classes+ SHORT1FROMMR(WinSendMsg(LBwnd,LM_QUERYSELECTION,(MPARAM) LIT_FIRST,0))) );
  83.                                    strcat(tmp," -> ");
  84.                                    strcat(tmp,*(Modules+ SHORT1FROMMR(WinSendMsg(LBwnd,LM_QUERYSELECTION,(MPARAM) LIT_FIRST,0))) );
  85.                                    WinSetDlgItemText(wnd,ST_Info,tmp);
  86.                                   }
  87.                                    else
  88.                                      {
  89.                                         sprintf(tmp,"%d class(es) selected",Selcount);
  90.                                         WinSetDlgItemText(wnd,ST_Info,tmp);
  91.                                      }
  92.  
  93.                                   WinEnableMenuItem(Popup,BTN_Dereg,(Selcount != 0));
  94.  
  95.                                   WinEnableMenuItem(Popup,BTN_Create,(Selcount==1));
  96.                                 }
  97.  
  98.               default : return(WinDefDlgProc(wnd,msg,mp1,mp2));
  99.               }
  100.             }
  101.          return(WinDefDlgProc(wnd,msg,mp1,mp2));
  102.      case WM_COMMAND :
  103.        switch (SHORT1FROMMP(mp1)) {
  104.         case BTN_Sorted :
  105.             Sorted = !Sorted;
  106.             WinCheckMenuItem(Popup,BTN_Sorted,Sorted);
  107.             WinPostMsg(wnd,WM_LoadCList,0,0);
  108.             return(0);
  109.         case BTN_About :
  110.                 WinDlgBox(HWND_DESKTOP,wnd,&WinDefDlgProc,NULLHANDLE,DLG_About,NULL);
  111.                 return(0);
  112.         case DID_OK :
  113.         case DID_CANCEL :
  114.                 WinPostMsg(wnd,WM_CLOSE,0,0);
  115.                 return(0);
  116.         case BTN_Dereg :
  117.               if (Selcount != 0)
  118.                { char AText[255];
  119.                  SHORT n;
  120.                  BOOL reload = FALSE;
  121.                  Selection = LIT_FIRST;
  122.  
  123.                  for(n=0;n<Selcount;n++)
  124.                  {
  125.                   Selection = SHORT1FROMMR(WinSendMsg(LBwnd,LM_QUERYSELECTION,MPFROMSHORT(Selection),0));
  126.                   sprintf(AText,"Are you sure you want do deregister class : %s ?",*(Classes+Selection));
  127.                   if (WinMessageBox(HWND_DESKTOP,wnd,AText,"Confirm",0,MB_YESNO | MB_MOVEABLE | MB_ICONQUESTION) == MBID_YES)
  128.                     {
  129.                       if (WinDeregisterObjectClass(*(Classes+Selection))) WinMessageBox(HWND_DESKTOP,wnd,"Class deregistered succesfully","Success",0,MB_OK | MB_MOVEABLE | MB_INFORMATION);
  130.                       else WinMessageBox(HWND_DESKTOP,wnd,"Error deregistering class","Error",0,MB_OK | MB_MOVEABLE | MB_ICONHAND);
  131.                       reload = TRUE;
  132.                     }
  133.                   }
  134.                   if (reload) WinPostMsg(wnd,WM_LoadCList,0,0);
  135.                }
  136.              else WinMessageBox(HWND_DESKTOP,wnd,"At least one class must be selected","Error",0,MB_OK | MB_MOVEABLE | MB_ICONHAND);
  137.              return(0);
  138.         case BTN_Register :
  139.               if (WinDlgBox(HWND_DESKTOP,wnd,&RegisterDlgProc,NULLHANDLE,DLG_Register,NULL) == DID_OK) WinPostMsg(wnd,WM_LoadCList,0,0);
  140.               return(0);
  141.         case BTN_Create :
  142.              { CRecord Cl;
  143.  
  144.                if (Selcount == 1)
  145.                 {
  146.                   Cl.cbSize = sizeof(CRecord);
  147.                   Selection = SHORT1FROMMR(WinSendMsg(LBwnd,LM_QUERYSELECTION,MPFROMSHORT(LIT_FIRST),0));
  148.                   Cl.data = strdup(*(Classes + Selection));
  149.                   WinDlgBox(HWND_DESKTOP,wnd,&CreateDlgProc,NULLHANDLE,DLG_CreateObj,&Cl);
  150.                 }
  151.                 else WinMessageBox(HWND_DESKTOP,wnd,"One class must be selected to create an object","Error",0,MB_OK | MB_MOVEABLE | MB_ICONHAND);
  152.               return(0);
  153.              }
  154.         case BTN_Refresh :
  155.            WinPostMsg(wnd,WM_LoadCList,0,0);
  156.            return(0);
  157.         default :
  158.           return(WinDefDlgProc(wnd,msg,mp1,mp2));
  159.          }
  160.      case (WM_LoadCList) :
  161.          {
  162.            WinSetDlgItemText(wnd,ST_Info,"Loading class list ...");
  163.            if (WinQueryLboxCount(LBwnd) != 0) WinSendMsg(LBwnd,LM_DELETEALL,0,0);
  164.  
  165.            p = NULL;
  166.            if (WinEnumObjectClasses(p,&Size))
  167.             {
  168.               static PSZ *C1, *M1;
  169.  
  170.               p = (POBJCLASS) malloc(Size);
  171.  
  172.               if (Classes != NULL) free(Classes);
  173.               if (Modules != NULL) free(Modules);
  174.  
  175.               Classes = malloc(Size);
  176.               Modules = malloc(Size);
  177.               C1 = malloc(Size);
  178.               M1 = malloc(Size);
  179.  
  180.               WinEnumObjectClasses(p,&Size);
  181.               q = p;
  182.               Selcount = 0;
  183.  
  184.               while (p != NULL)
  185.                {
  186.                  if (Sorted) WinInsertLboxItem(LBwnd,LIT_SORTASCENDING,p->pszClassName);
  187.                  else WinInsertLboxItem(LBwnd,LIT_END,p->pszClassName);
  188.                  *(C1 + Selcount) = (PSZ) p->pszClassName;
  189.                  *(M1 + Selcount) = (PSZ) p->pszModName;
  190.                  p = p->pNext;
  191.                  Selcount++;
  192.                }
  193.               free(q);
  194.  
  195.               for (Size = 0;Size < Selcount;Size++)
  196.                { SHORT pos;
  197.  
  198.                   if (Sorted == TRUE) pos = SHORT1FROMMR(WinSendMsg(LBwnd,LM_SEARCHSTRING,MPFROM2SHORT(LSS_CASESENSITIVE,LIT_FIRST),MPFROMP(*(C1+Size))));
  199.                   else pos = Size;
  200.                      *(Classes + pos) = *(C1+Size);
  201.                      *(Modules + pos) = *(M1+Size);
  202.                }
  203.               free(C1);
  204.               free(M1);
  205.             }
  206.             WinSetDlgItemText(wnd,ST_Info,"Class list loaded");
  207.             sprintf(tmp,"%d",Selcount);
  208.             WinSetDlgItemText(wnd,ST_Count,tmp);
  209.             Selcount = 0;
  210.            return(0);
  211.          }
  212.      case WM_CLOSE :
  213.                      if (WinMessageBox(HWND_DESKTOP,wnd,"Are you sure you want to quit VClassed ?","Confirm",0,MB_YESNO | MB_ICONQUESTION | MB_MOVEABLE) == MBID_YES)
  214.                        { return(WinDefDlgProc(wnd,msg,mp1,mp2)); }
  215.                      else
  216.                        { return((MPARAM) 0); }
  217.  
  218.      case WM_DESTROY :
  219.         WinDestroyWindow(Popup);
  220.         return(0);
  221.      default:
  222.        return(WinDefDlgProc(wnd,msg,mp1,mp2));
  223.      }
  224. }
  225.  
  226. void main()
  227. {
  228.   HAB mhab;
  229.   HMQ mhmq;
  230.   HWND dlgwnd;
  231.   HSWITCH thetask;
  232.   HPOINTER icon;
  233.   RECTL mrect;
  234.   SWCNTRL tswitch;
  235.   PID pid;
  236.  
  237.  /* Startup */
  238.   mhab = WinInitialize(0);
  239.   mhmq = WinCreateMsgQueue(mhab,0);
  240.  
  241.  /* Main block */
  242.   icon = WinLoadPointer(HWND_DESKTOP,NULLHANDLE,1); // Load pointer for Main dialog
  243.   dlgwnd = WinLoadDlg(HWND_DESKTOP,HWND_DESKTOP,&VCEdProc,NULLHANDLE,1,NULL); // Load main dialog
  244.   WinSendMsg(dlgwnd,WM_SETICON,(MPARAM) icon,0); // Set new dialog icon
  245.   WinQueryWindowRect(dlgwnd,&mrect);
  246.  
  247.   WinQueryWindowProcess(dlgwnd,&pid,NULL);
  248.   tswitch.hwnd = dlgwnd;
  249.   tswitch.hwndIcon = icon;
  250.   tswitch.idProcess = pid;
  251.   tswitch.idSession = 0;
  252.   tswitch.uchVisibility = SWL_VISIBLE;
  253.   tswitch.fbJump = SWL_JUMPABLE;
  254.   strcpy(tswitch.szSwtitle,"VClassed 1.5 - Class Manager");
  255.   WinSetWindowPos(dlgwnd,0,(WinQuerySysValue(HWND_DESKTOP,SV_CXSCREEN) - (mrect.xRight-mrect.xLeft)) / 2,
  256.                            (WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN) - (mrect.yTop-mrect.yBottom)) / 2, 0,0, SWP_MOVE | SWP_SHOW);
  257.  
  258.   thetask = WinAddSwitchEntry(&tswitch);
  259.  
  260.   WinProcessDlg(dlgwnd);
  261.  
  262.  /* Close'n'Clean */
  263.   WinRemoveSwitchEntry(thetask);
  264.   WinDestroyWindow(dlgwnd);
  265.   WinDestroyMsgQueue(mhmq);
  266.   WinTerminate(mhab);
  267. }