home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / os2cl016.zip / pmwin.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-04  |  10.5 KB  |  343 lines

  1. /* 
  2.  
  3.  
  4.     pmwin.h (emx+gcc) 
  5.  
  6.     1994,95 Giovanni Iachello
  7.     This is freeware software. You can use or modify it as you wish,
  8.     provided that the part of code that I wrote remains freeware.
  9.     Freeware means that the source code must be available on request 
  10.     to anyone.
  11.     You must also include this notice in all files derived from this
  12.     file.
  13.  
  14.  
  15. */
  16. #ifndef _PMWIN_H_
  17. #define _PMWIN_H_
  18.  
  19. #define INCL_WIN
  20. #define INCL_DOSPROCESS
  21. #define INCL_DOSSEMAPHORES
  22. #define OS2EMX_PLAIN_CHAR
  23. #include <os2.h>
  24.  
  25. #include <stdlib.h>
  26. #include <stddef.h>
  27.  
  28. #include "pmsys.h"
  29. #include "pmgpi.h"
  30.  
  31. #undef assert
  32. #ifdef NODEBUG
  33. #define assert(ignore) ((void)0)
  34. #else
  35. #define assert(x) ((void)((x) || (DoAssert((PCSZ)#x,(PCSZ)__FILE__,__LINE__),1)))
  36. #endif
  37.  
  38.  
  39. void DoAssert(PCSZ msg,PCSZ file,unsigned line);
  40.  
  41. void ErrBox(PCSZ msg,...);
  42.  
  43. struct PMEvent;
  44. class PMRect;
  45. class PMPoint;
  46. class PMPresSpace;
  47. class PMWin;
  48. class PMMainWin;
  49. class PMHelpWin;
  50. class PMApp;
  51. class PMThread;
  52. class PMAnchorBlock;   // class that creates basic window message handling functions
  53. class PMWindowThread;
  54. class PMDialog;
  55. class PMControl;
  56. class PMListBox;
  57. class PMEntryField;
  58. class PMMenu;
  59.  
  60. struct WINCREATEARGS {
  61.     HWND hwndParent;
  62.     HWND hwndOwner;
  63.     ULONG flStyle;
  64.     ULONG flCreateFlags;
  65.     PCSZ pszClientClass;
  66.     PCSZ pszTitle;
  67.     ULONG styleClient;
  68.     HMODULE hmod; 
  69.     ULONG idResources;
  70.     PHWND phwndClient;
  71. // additional WinCreateWindow parameters
  72.     LONG x,y,cx,cy;
  73.     HWND hwndInsertBehind;
  74.     ULONG id;
  75.     PVOID pCtlData,pPresParams;
  76. // register class part
  77.     HAB hab;
  78.     PCSZ pszClassName;
  79.     PFNWP pfnWndProc;
  80.     ULONG flClassStyle;
  81.     ULONG cbWindowData;
  82. };
  83.  
  84. ////////////////////////////////////////////////////////////////////////////
  85.  
  86. MRESULT PMWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  87.  
  88. MRESULT PMDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  89.  
  90. ////////////////////////////////////////////////////////////////////////////
  91.  
  92.  
  93. struct PMEvent 
  94. {
  95.     ULONG msg;
  96.     MPARAM mp1;
  97.     MPARAM mp2;
  98.     MRESULT ret;
  99.     PCHRMSG charmsg;
  100.     PMSEMSG mousemsg;
  101.     PMEvent(ULONG m,MPARAM n,MPARAM l,PCHRMSG c=NULL,PMSEMSG ms=NULL) { 
  102.         msg=m; mp1=n; mp2=l; charmsg=c; mousemsg=ms; ret=0;
  103.     }
  104.  
  105. };
  106.  
  107. /////////////////////////////////////////////////////////////////////////////
  108.  
  109. class PMWin 
  110. {
  111. protected:
  112.     PFNWP oldproc;
  113.     WINCREATEARGS *createArgs;
  114.     HWND hwnd,hwndFrame;
  115.     PMAnchorBlock ab;
  116.     virtual BOOL dispachEvent(PMEvent & event);
  117.     friend MRESULT PMWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  118.     friend MRESULT PMDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  119.  
  120. public:
  121.     PMWin(PCSZ classname,HAB iab); // se non viene specificato nessun a.b., prendi App di default
  122.     PMWin(HAB iab); // costruttore semplice per le finestre meno complicate
  123.     virtual ~PMWin();
  124.  
  125.     HWND getHwnd() { return hwnd; }
  126.     HWND operator () () { return hwnd; }
  127.     operator HWND () { return hwnd; }
  128.     HWND getHwndFrame() { return hwndFrame; }
  129.  
  130.     virtual BOOL createWin();    
  131.     virtual BOOL destroyWin();    
  132.     virtual MRESULT msgProc(PMEvent& event);
  133.  
  134.     ULONG msgBox(PCSZ title,PCSZ msg,...);
  135.  
  136.     BOOL isChild(HWND hwndParent) { return WinIsChild(hwnd,hwndParent); }
  137.     BOOL isEnabled() { return WinIsWindowEnabled(hwnd); }
  138.     BOOL isVisible() { return WinIsWindowVisible(hwnd); }
  139.  
  140.     virtual MRESULT sendMsg (ULONG msg, MPARAM mp1=0L, MPARAM mp2=0L) 
  141.         {    return WinSendMsg (hwnd, msg, mp1, mp2); }
  142.     BOOL postMsg (ULONG msg, MPARAM mp1=0L, MPARAM mp2=0L) 
  143.         {     return WinPostMsg (hwnd, msg, mp1, mp2); }
  144.     virtual MRESULT close(); // manda WM_CLOSE
  145.     BOOL invalidate(BOOL includeChildren) { return WinInvalidateRect(hwnd,NULL,includeChildren); }
  146.  
  147.     HWND queryCapture(HWND hwndDesktop=HWND_DESKTOP) 
  148.         {    return WinQueryCapture (hwndDesktop); }
  149.     HWND queryFocus(HWND hwndDesktop=HWND_DESKTOP) 
  150.         {     return WinQueryFocus (hwndDesktop); }
  151.     BOOL setCapture(HWND hwndDesktop=HWND_DESKTOP) 
  152.         {    return WinSetCapture (hwndDesktop,hwnd); }
  153.     BOOL resetCapture(HWND hwndDesktop=HWND_DESKTOP) 
  154.         {    return WinSetCapture (hwndDesktop,NULLHANDLE); }
  155.     BOOL queryPos(PSWP pswp) 
  156.         {     return WinQueryWindowPos (hwnd, pswp); }
  157.     BOOL queryFramePos(PSWP pswp) 
  158.         {     return WinQueryWindowPos (hwndFrame, pswp); }
  159.     LONG queryWindowText(LONG cchBufferMax, PCH pchBuffer)
  160.         {     return WinQueryWindowText (hwnd,cchBufferMax,pchBuffer); }
  161.     LONG queryWindowTextLenght() 
  162.         {     return WinQueryWindowTextLength (hwnd); }
  163.     BOOL setOwner(HWND hwndNewOwner)
  164.         {     return WinSetOwner (hwnd,hwndNewOwner); }
  165.     BOOL setParent(HWND hwndNewParent, BOOL fRedraw=FALSE)
  166.         {     return WinSetParent (hwnd,hwndNewParent,fRedraw); }
  167.     BOOL setPos(HWND hwndInsertBehind, LONG x, LONG y, LONG cx, LONG cy, ULONG fl=0L)
  168.           {     return WinSetWindowPos(hwnd,hwndInsertBehind,x,y,cx,cy,fl); }
  169.     BOOL setFramePos(HWND hwndInsertBehind, LONG x, LONG y, LONG cx, LONG cy, ULONG fl=0L)
  170.           {     return WinSetWindowPos(hwndFrame,hwndInsertBehind,x,y,cx,cy,fl); }
  171.     BOOL setWindowText(PCSZ pszText) 
  172.         {     return WinSetWindowText (hwnd,pszText); }
  173.     BOOL setFrameWindowText(PCSZ pszText) 
  174.         {     return WinSetWindowText (hwndFrame,pszText); }
  175.     BOOL ptInClient(PMPoint& pt);
  176.     BOOL restoreWindowPos (PCSZ pszAppName, PCSZ pszKeyName, HWND h=NULLHANDLE)
  177.         {    
  178.             if (h==NULLHANDLE) h=hwndFrame;
  179.             return WinRestoreWindowPos (pszAppName, pszKeyName, h); 
  180.         }
  181.     BOOL storeWindowPos (PCSZ pszAppName, PCSZ pszKeyName, HWND h=NULLHANDLE)
  182.         {    
  183.             if (h==NULLHANDLE) h=hwndFrame;
  184.             return WinStoreWindowPos (pszAppName, pszKeyName, h); 
  185.         }
  186.         
  187.     BOOL associateHelpInstance (HWND hwndHelpInstance)
  188.         {    return WinAssociateHelpInstance (hwndHelpInstance, hwndFrame); }
  189.     HWND queryHelpInstance ()
  190.         {    return WinQueryHelpInstance (hwnd); }
  191.  
  192.  
  193.     virtual BOOL queryEnd() { return TRUE; } // always exit from window
  194.  
  195. // Standard message handling functions //////////////////////////////////////
  196. // the return BOOL of the following functions should be FALSE if
  197. // you want to call the default message handling procedure (ie the
  198. // message was not processed, TRUE if you don't want to.
  199.     virtual BOOL command(USHORT id,USHORT cmddev);
  200.     virtual BOOL create(PMEvent &event);
  201.     virtual BOOL destroy();
  202.     virtual void saveApplication();         // exception: PM requires that the default procedure always be called
  203.     virtual BOOL paint();                 // generic paint WM_PAINT
  204.     virtual BOOL kbd(PMEvent &event);     // any keyboard message
  205.     virtual BOOL mouse(PMEvent &event);     // any mouse message
  206.     virtual BOOL enable();
  207.     virtual BOOL show();    
  208.     virtual BOOL move();
  209.     virtual BOOL size(SHORT cx,SHORT cy);
  210.     virtual BOOL activate();
  211.     virtual BOOL setfocus();
  212.     virtual BOOL help(PMEvent &event);     // WM_HELP message
  213.     virtual BOOL helpmsg(PMEvent &event);// any WM_ help-related message
  214.     virtual BOOL timer();
  215.     virtual BOOL closed();               // received WM_CLOSE
  216.     virtual BOOL other(PMEvent &event);     // all other messages
  217.     virtual BOOL initmenu(SHORT id,PMMenu *menu); // menu initialization
  218. };
  219.  
  220.  
  221. /////////////////////////////////////////////////////////////////////////////
  222. // PMMainWin add automatic support for menus, and active file handling.
  223.  
  224. // PMMainWin File Flags
  225. //
  226. #define PMMWFF_NOTHING 0                 // main window does not use files
  227. #define PMMWFF_NONE 1                     // no active file
  228. #define PMMWFF_UNTITLED 2                 // untitled document
  229. #define PMMWFF_FILE 3                     // open file
  230.  
  231. class PMMainWin : public PMWin 
  232. {
  233. protected:
  234.     char filename[CCHMAXPATH];
  235.     BOOL modified;
  236.     int fileFlags;
  237.     char *caption;
  238.     char *fnFilter,*fsCaption,*flCaption;
  239.     char *fileUntitled,*fileNone;
  240.     BOOL fileKillConfirm();
  241. // imposta il titolo della finestra da caption e filename
  242. // set the title of the window using caption and filename
  243.     void setTitleCaption(); 
  244.     PMHelpWin* helpWin;        // finestra a cui chiedere help (help instance window)
  245. public:
  246.     PMMainWin(PCSZ classname,HAB ab,PMHelpWin *ihelpWin=NULL);
  247.     ~PMMainWin() { };
  248.     BOOL paint();
  249.     BOOL command(USHORT id,USHORT cmddev);
  250.     BOOL createWin();    
  251.     BOOL destroyWin();    
  252.     virtual BOOL paint(PMPresSpace& ) { return FALSE; }
  253. //    BOOL helpmsg(PMEvent &event); // ridefinisci la gestione dell'aiuto
  254.  
  255.     BOOL isFileModified() { return modified; }
  256.     BOOL setModified(BOOL state) { BOOL temp=modified; modified=state; setTitleCaption(); return temp; }
  257.  
  258.     BOOL queryEnd() { return fileKillConfirm(); } // query file kill confirm
  259.     BOOL closed(); // riceived WM_CLOSE, see if I can close the window
  260.  
  261. // standard menu selections
  262.     virtual BOOL fileOpen(PCSZ /*filename*/) { return TRUE; }; // return TRUE if everything is Ok
  263.     virtual BOOL fileSave(PCSZ /*filename*/) { return TRUE; };
  264.     virtual BOOL filePrint() { return TRUE; };
  265.     virtual BOOL fileNew() { return TRUE; };
  266.  
  267.     virtual BOOL editCut() { return TRUE; };
  268.     virtual BOOL editCopy() { return TRUE; };
  269.     virtual BOOL editPaste() { return TRUE; };
  270.     virtual BOOL editDelete() { return TRUE; };
  271.     virtual BOOL editUndo() { return TRUE; };
  272.     virtual BOOL editRedo() { return TRUE; };
  273.     virtual BOOL editClear() { return TRUE; };
  274. };
  275.  
  276. /////////////////////////////////////////////////////////////////////////////
  277.  
  278. class PMSubclassWin : public PMWin {
  279. public:
  280.     PMSubclassWin(HWND hwndParent, PCSZ pszClass, PCSZ pszName,
  281.         ULONG flStyle, LONG x, LONG y, LONG cx, LONG cy, HWND hwndOwner,
  282.         HWND hwndInsertBehind, ULONG id, PVOID pCtlData=NULL, PVOID pPresParams=NULL);
  283.     ~PMSubclassWin();
  284.  
  285.     BOOL createWin();    
  286. };
  287.  
  288. /////////////////////////////////////////////////////////////////////////////
  289. // Menus
  290. //
  291.  
  292. class PMMenu 
  293. {
  294. protected:
  295.     HWND menu;
  296.     PMWin* win;
  297. public:
  298.     PMMenu(PMWin* iwin);  // menu' della finestra
  299.     PMMenu(HWND menu); // menu qualsiasi
  300. PMMenu(); // costruttore vuoto, per le classi derivate..
  301.     BOOL checkItem(SHORT id,SHORT fcheck) {
  302.         return WinCheckMenuItem(menu,id,fcheck);
  303.     }
  304.     BOOL enableItem(SHORT id,SHORT fEnable) {
  305.         return WinEnableMenuItem(menu,id,fEnable);
  306.     }
  307.     BOOL isItemChecked(SHORT id) {
  308.         return WinIsMenuItemChecked(menu,id);
  309.     }
  310.     BOOL isItemEnabled(SHORT id) {
  311.         return WinIsMenuItemEnabled(menu,id);
  312.     }
  313.     BOOL isItemValid(SHORT id) {
  314.         return WinIsMenuItemValid(menu,id);
  315.     }                 
  316.     BOOL setItemText(SHORT id,PSZ psz) {
  317.         return WinSetMenuItemText(menu,id,psz);
  318.     }
  319. };
  320.  
  321.  
  322. // window system menu //////////////////////////////////////////////////////
  323. class PMSystemMenu : PMMenu 
  324. {
  325. public:
  326.     PMSystemMenu(PMWin* iwin);  
  327. };
  328.  
  329.  
  330. // popup menu //////////////////////////////////////////////////////////////
  331.  
  332. class PMPopupMenu : PMMenu 
  333. {
  334. public:
  335.     PMPopupMenu(PMWin* iwin,ULONG idres); 
  336.     BOOL popup(PMPoint& pt,ULONG sel,ULONG flags=PU_POSITIONONITEM|PU_MOUSEBUTTON1|PU_MOUSEBUTTON2|PU_KEYBOARD);
  337. };
  338.  
  339. /////////////////////////////////////////////////////////////////////////////
  340.  
  341. #endif
  342.  
  343.