home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR24 / CFGED1B.ZIP / PMVIEWS.ZIP / pmviews / dialog.cc < prev    next >
C/C++ Source or Header  |  1992-08-29  |  8KB  |  311 lines

  1. // this might look like 'C', but it's really  -*-c++-*-
  2. /* dialog.cc
  3.  *
  4.  * Methoden der Dialog-Klasse von PMviews 
  5.  *
  6.  * Die Dialog-Klasse ermoeglichen die Generierung
  7.  * von PM-Dialogen fuer eine
  8.  * eine PM Applikation
  9.  *
  10.  * Language        : C++
  11.  * Operating System: OS/2 V2.0 and higher
  12.  * Compiler        : GNU GCC V2.1 and higher
  13.  *
  14.  *
  15.  * $Id: dialog.cc,v 1.3 1992/08/29 18:16:06 gruen Exp $
  16.  * $Log: dialog.cc,v $
  17. // Revision 1.3  1992/08/29  18:16:06  gruen
  18. // Version as used by cfged 1.0 beta. Applied some additional callbacks and
  19. // fixed bugs.
  20. //
  21. // Revision 1.2  1992/08/09  22:18:36  gruen
  22. // corrected some bugs, changed the contsructors for the dialog windows, appended
  23. // some methods.
  24. //
  25. // Revision 1.1  1992/07/19  02:01:11  gruen
  26. // Initial revision
  27. //
  28.  *
  29.  * Copyright (c) 1992 Lutz Grueneberg
  30.  *
  31.  * This library is free software; you can redistribute it and/or modify
  32.  * it under the terms of the GNU Library General Public License as
  33.  * published by the Free Software Foundation; either version 2 of the
  34.  * License, or (at your option) any later version.  This library is
  35.  * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  36.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  37.  * A PARTICULAR PURPOSE.  See the GNU Library General Public License for
  38.  * more details. You should have received a copy of the GNU Library
  39.  * General Public License along with this library; if not, write to the
  40.  * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  41.  */
  42.  
  43. #define INCL_WIN
  44. #include <os2.h>
  45.  
  46. MRESULT EXPENTRY MyDlgWndProc(HWND hwnd, USHORT msg,
  47.                      MPARAM  mp1, MPARAM  mp2);
  48.  
  49. #include "session.h"
  50. #include "window.h"
  51. #include "dialog.h"
  52.  
  53. Dialog *Dialog::pDialogList = NULL;
  54.  
  55. /* Dialog::Dialog()
  56.  *
  57.  * Konstruktor der Klasse Dialog.
  58.  * Hier werden die notwendigen Daten gesichert.
  59.  * Der (notwendige) Eintrag der (PM-)Klasse beim System 
  60.  * sowie die Erzeugung des Fensters erfolgen beim 
  61.  * Create-Aufruf.
  62.  */
  63.  
  64. Dialog::Dialog(HWND hwndOwnerNew,               /* Konstruktor der Klasse */
  65.            USHORT  idResNew,
  66.                HWND hwndParentNew=HWND_DESKTOP) /* Ressource ID of Dialog */
  67. {
  68.   hwndParent = hwndParentNew;
  69.   hwndOwner  = hwndOwnerNew;
  70.   hwndDlg    = 0L;
  71.   idRes      = idResNew;
  72. }
  73.  
  74.  
  75. /* Dialog::create()
  76.  *
  77.  * create-Methode der Klasse Dialog.
  78.  * Das Dialog-Fenster wird mittels WinDlgBox erzeugt.
  79.  */
  80.  
  81. VOID Dialog::create()
  82. {
  83.   /* register this dialog in the List of displayed dialogs */
  84.   pDialogNext = pDialogList;
  85.   pDialogList = this;
  86.   /* create the dialog box via PM */
  87.   WinDlgBox (hwndParent,     
  88.          hwndOwner,
  89.          StaticDlgWndProc,
  90.          (HMODULE) NULL,
  91.          idRes,
  92.          this);
  93. }  
  94.  
  95. /* Dialog::load()
  96.  * 
  97.  * Loading a Dialog, preparing a modeless Dialog box
  98.  */
  99. HWND Dialog::load()
  100. {
  101.   /* register this dialog in the List of displayed dialogs */
  102.   pDialogNext = pDialogList;
  103.   pDialogList = this;
  104.   /* create the dialog box via PM */
  105.   return WinLoadDlg(hwndParent,     
  106.                 hwndOwner,
  107.                 StaticDlgWndProc,
  108.                 (HMODULE) NULL,
  109.             idRes,
  110.             this);
  111. }  
  112.  
  113. /* Dialog::destroy()
  114.  *
  115.  * destroy-Methode der Klasse Dialog.
  116.  * Diese Methode zertstört den Dialog.
  117.  */
  118.  
  119. VOID Dialog::destroy()
  120. {
  121.   Dialog  *pTargetDialog;
  122.   /* Dismiss the dialog */
  123.   WinDismissDlg(hwndDlg, 0);
  124.   /* remove the Dialog from the list of active Dialog boxes */
  125.   if( pDialogList == this) {
  126.     pDialogList = pDialogList->pDialogNext;
  127.     return;
  128.   }
  129.   for(pTargetDialog = pDialogList; 
  130.       pTargetDialog != NULL && pTargetDialog->pDialogNext != NULL;
  131.       pTargetDialog = pTargetDialog->pDialogNext) {
  132.     if( pTargetDialog->pDialogNext == this) {
  133.       pTargetDialog = pTargetDialog->pDialogNext->pDialogNext;
  134.       break;
  135.     }
  136.   }
  137. }
  138.  
  139. /* Dialog::StaticDlgWndProc
  140.  *
  141.  * Diese Funktion ist der staische Window-Handler fuer die Dialog Class
  142.  * Sie verarbeitet alle eingehenden Messages und ruft die
  143.  * Methode DlgWndProc Instanz der Klasse auf.
  144.  */
  145.  
  146. MRESULT Dialog::StaticDlgWndProc(HWND hwnd, USHORT msg,
  147.                  MPARAM  mp1, MPARAM  mp2)
  148. {
  149.   Dialog  *pTargetDialog;
  150.  
  151.   /* if WM_INITDLG is passed, register the instance      */
  152.   if( msg == WM_INITDLG) {
  153.     pTargetDialog = (Dialog*)PVOIDFROMMP( mp2);
  154.     pTargetDialog->hwndDlg = hwnd;
  155.   }
  156.   /* locate the instance in the list of existing dialogs */
  157.   for(pTargetDialog = pDialogList; pTargetDialog != NULL;
  158.       pTargetDialog = pTargetDialog->pDialogNext) {
  159.     if( pTargetDialog->hwndDlg == hwnd)
  160.       return pTargetDialog->DlgWndProc( hwnd, msg, mp1, mp2);
  161.   }
  162.   /* this should never be reached */
  163.   return WinDefDlgProc (hwnd, msg, mp1, mp2);
  164. }
  165.  
  166. /* Dialog::DlgWndProc
  167.  *
  168.  * Diese Funktion ist der Window-Handler fuer die Dialog Class
  169.  * Sie verarbeitet alle eingehenden Messages und ruft die
  170.  * entsprechenden virtuellen Methoden der Klasse auf.
  171.  */
  172.  
  173. MRESULT Dialog::DlgWndProc(HWND hwnd, USHORT msg,
  174.                MPARAM  mp1, MPARAM  mp2)
  175. {
  176.   BOOL    fDoDefault = TRUE;
  177.   MRESULT result;
  178.  
  179.   switch( msg) {
  180.   case WM_INITDLG: 
  181.     result=msgInitDlg(hwnd,msg,mp1,mp2,&fDoDefault); 
  182.     break;
  183.  
  184.   case WM_COMMAND: 
  185.     result = msgCommand(hwnd,msg,mp1,mp2,&fDoDefault); 
  186.     /* if default processing is used, do it explicit */
  187.     /* this is required to remove the dialog from the active dialog list */
  188.     if( fDoDefault) {
  189.       destroy();
  190.       result = 0;
  191.       fDoDefault = FALSE;
  192.     }
  193.     break;
  194.  
  195.   case WM_CONTROL: 
  196.     result=msgControl(hwnd,msg,mp1,mp2,&fDoDefault); 
  197.     break;
  198.  
  199.   case WM_ACTIVATE:
  200.     result = msgActivate(hwnd,msg,mp1,mp2,&fDoDefault); 
  201.     break;
  202.  
  203.   case WM_CLOSE:
  204.     result = msgClose(hwnd,msg,mp1,mp2,&fDoDefault); 
  205.     break;
  206.  
  207.   case WM_DESTROY: 
  208.     result = msgDestroy(hwnd,msg,mp1,mp2,&fDoDefault); 
  209.     break;
  210.  
  211.   default:
  212.     fDoDefault = TRUE;
  213.   }
  214.   return fDoDefault ? WinDefDlgProc (hwnd, msg, mp1, mp2) : result;
  215. }
  216.  
  217. MRESULT Dialog::msgInitDlg( HWND hwnd, USHORT msg,
  218.                MPARAM  mp1, MPARAM  mp2, BOOL *fDoDefault)
  219. {
  220.   *fDoDefault = TRUE;
  221.   return 0;
  222. }
  223.  
  224. MRESULT Dialog::msgCommand( HWND hwnd, USHORT msg,
  225.                MPARAM  mp1, MPARAM  mp2, BOOL *fDoDefault)
  226. {
  227.   *fDoDefault = TRUE;
  228.   return 0;
  229. }
  230.  
  231. MRESULT Dialog::msgControl( HWND hwnd, USHORT msg,
  232.                MPARAM  mp1, MPARAM  mp2, BOOL *fDoDefault)
  233. {
  234.   *fDoDefault = TRUE;
  235.   return 0;
  236. }
  237.  
  238. MRESULT Dialog::msgActivate(HWND hwnd, USHORT msg,
  239.                 MPARAM  mp1, MPARAM  mp2, BOOL *fDoDefault)
  240. {
  241.   *fDoDefault = TRUE;
  242.   return 0;
  243. }
  244.  
  245. MRESULT Dialog::msgClose(HWND hwnd, USHORT msg,
  246.                 MPARAM  mp1, MPARAM  mp2, BOOL *fDoDefault)
  247. {
  248.   *fDoDefault = TRUE;
  249.   return 0;
  250. }
  251.  
  252. MRESULT Dialog::msgDestroy(HWND hwnd, USHORT msg,
  253.                MPARAM  mp1, MPARAM  mp2, BOOL *fDoDefault)
  254. {
  255.   *fDoDefault = TRUE;
  256.   return 0;
  257. }
  258.  
  259. BOOL    Dialog::querySize( SIZEL *pSize)
  260. {
  261.   RECTL rcl;
  262.   BOOL  fReturn;
  263.   
  264.   fReturn = WinQueryWindowRect( hwndDlg, &rcl);
  265.   pSize->cx = rcl.xRight;
  266.   pSize->cy = rcl.yTop;    
  267.   return fReturn;
  268. }
  269.  
  270. BOOL    Dialog::queryPos( POINTL *pPos)
  271. {
  272.   SWP   swp;
  273.   BOOL  fReturn;
  274.   
  275.   fReturn = WinQueryWindowPos( hwndDlg, &swp);
  276.   pPos->x = swp.x;
  277.   pPos->y = swp.y;    
  278.   return fReturn;
  279. }
  280.  
  281. HWND Dialog::queryHwndOwner( VOID)
  282. {
  283.   return hwndOwner;
  284. }
  285.  
  286. BOOL    Dialog::setPos( POINTL *pPos)
  287. {
  288.   return WinSetWindowPos( hwndDlg, HWND_TOP, 
  289.              pPos->x, pPos->y, 0, 0, 
  290.              SWP_MOVE|SWP_SHOW);
  291. }
  292.  
  293. BOOL    Dialog::show( BOOL fShow)
  294. {
  295.   return WinShowWindow( hwndDlg, fShow); 
  296. }
  297.  
  298. BOOL    Dialog::enable( BOOL fEnable)
  299. {
  300.   return WinEnableWindow( hwndDlg, fEnable);
  301. }
  302.  
  303.  
  304. BOOL Dialog::setTitle( CHAR *szNewTitle)
  305. {
  306.   if( !hwndDlg) return FALSE;
  307.     return WinSetWindowText( hwndDlg, (PSZ)szNewTitle);
  308. }
  309.  
  310. /* E O F */
  311.