home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / prefs / nsdlg / public / cdialog.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.6 KB  |  94 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef __CDIALOG_H_
  20. #define __CDIALOG_H_
  21.  
  22. #include "cstring.h"
  23.  
  24. // Simple class to encapsulate dialog behavior (modal and modeless)
  25. class CDialog {
  26.     public:
  27.         CDialog(HINSTANCE hInstance, UINT nTemplateID);
  28.  
  29.         // Create a modeless dialog
  30.         BOOL    Create(HWND hwndOwner);
  31.  
  32.         // Create a modal dialog
  33.         int        DoModal(HWND hwndOwner);
  34.  
  35.         // Destroy the window
  36.         BOOL    DestroyWindow();
  37.  
  38.     protected:
  39.         // Event processing
  40.         virtual BOOL    InitDialog();
  41.         virtual BOOL    OnCommand(int id, HWND hwndCtl, UINT notifyCode);
  42.  
  43.         // Called from member function OnCommand(). OnOK() calls DoTransfer
  44.         // to transfer data from the dialog box. Both member functions call
  45.         // EndDialog() to destroy the dialog box. OnOK() only destroys the
  46.         // dialog box if validation is successful
  47.         virtual void    OnOK();
  48.         virtual void    OnCancel();
  49.  
  50.         // Dialog data transfer. Override this routine and transfer data to/from
  51.         // the dialog box. Called from member functions InitDialog() and OnOK()
  52.         //
  53.         // When transfering data from the dialog box, return FALSE if validation
  54.         // is unsuccessful
  55.         virtual BOOL    DoTransfer(BOOL bSaveAndValidate) = 0;
  56.         
  57.         // Override this to handle other events yourself. This routine does two
  58.         // things:
  59.         //   - calls the original window procedure (which is DefDlgProc)
  60.         //   - handles WM_COMMAND, splits out the parameters, and calls
  61.         //     member function OnCommand
  62.         virtual    LRESULT    WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
  63.  
  64.         // Helper functions to assist with data transfer. For radio button
  65.         // transfers, the ID must be the first in a group of auto radio buttons.
  66.         // When transferring a LPSTR from an edit field, space for the string is
  67.         // malloc'd and the caller must free; any existing LPSTR is free'd first
  68.         void    RadioButtonTransfer(int nIDButton, int &value, BOOL bSaveAndValidate);
  69.         void    CheckBoxTransfer(int nIDButton, BOOL &value, BOOL bSaveAndValidate);
  70.         void    EditFieldTransfer(int nIDEdit, CString &str, BOOL bSaveAndValidate);
  71.         void    EditFieldTransfer(int nIDEdit, int &value, BOOL bSaveAndValidate);
  72.         void    EditFieldTransfer(int nIDEdit, UINT &value, BOOL bSaveAndValidate);
  73.         void    ListBoxTransfer(int nIDList, int &index, BOOL bSaveAndValidate);
  74.         void    ListBoxTransfer(int nIDList, CString &str, BOOL bSaveAndValidate);
  75.         void    ComboBoxTransfer(int nIDCombo, int &index, BOOL bSaveAndValidate);
  76.         void    ComboBoxTransfer(int nIDCombo, CString &str, BOOL bSaveAndValidate);
  77.  
  78.         // Helper routine to enable/disable a control by ID
  79.         void    EnableDlgItem(UINT nIDCtl, BOOL bEnable);
  80.     
  81.     protected:
  82.         HINSTANCE    m_hInstance;
  83.         UINT        m_nTemplateID;
  84.         HWND        m_hwndDlg;
  85.  
  86.     private:
  87.         WNDPROC    m_wpOriginalProc;    
  88.         friend LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
  89.         friend BOOL CALLBACK DialogFunc(HWND, UINT, WPARAM, LPARAM);
  90. };
  91.  
  92. #endif /* __CDIALOG_H_ */
  93.  
  94.