home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / optima / samples.z / PreviewFileDialog.wxc < prev    next >
Encoding:
Text File  |  1996-08-13  |  8.0 KB  |  297 lines

  1. Save Format v1.3
  2. @begin ClassFile "PreviewFileDialog"
  3.  Exported 0;
  4.  
  5. @begin-code BaseClassList
  6.  
  7. public WFileDialog
  8.  
  9. @end-code;
  10.  
  11.  @begin UserFunction "PreviewFileDialog()"
  12.   GencodeSrcLine 16;
  13.   FunctionName "PreviewFileDialog::PreviewFileDialog()";
  14.  @end;
  15.  
  16.  @begin UserFunction "Prototype for PreviewFileDialog()"
  17.   Private 1;
  18.   GencodeSrcLine 24;
  19.   FunctionName "PreviewFileDialog::Prototype for PreviewFileDialog()";
  20.  @end;
  21.  
  22.  @begin UserFunction "~PreviewFileDialog()"
  23.   GencodeSrcLine 31;
  24.   FunctionName "PreviewFileDialog::~PreviewFileDialog()";
  25.  @end;
  26.  
  27.  @begin UserFunction "Prototype for ~PreviewFileDialog()"
  28.   Private 1;
  29.   GencodeSrcLine 26;
  30.   FunctionName "PreviewFileDialog::Prototype for ~PreviewFileDialog()";
  31.  @end;
  32.  
  33.  @begin UserFunction "handleCreate( WObject *, WEventData * )"
  34.   Private 1;
  35.   GencodeSrcLine 44;
  36.   FunctionName "PreviewFileDialog::handleCreate( WObject *, WEventData * )";
  37.  @end;
  38.  
  39.  @begin UserFunction "Prototype for handleCreate( WObject *, WEventData * )"
  40.   Private 1;
  41.   GencodeSrcLine 28;
  42.   FunctionName "PreviewFileDialog::Prototype for handleCreate( WObject *, WEventData * )";
  43.  @end;
  44.  
  45.  @begin UserFunction "handleChange( WObject *, WEventData * )"
  46.   Private 1;
  47.   GencodeSrcLine 91;
  48.   FunctionName "PreviewFileDialog::handleChange( WObject *, WEventData * )";
  49.  @end;
  50.  
  51.  @begin UserFunction "Prototype for handleChange( WObject *, WEventData * )"
  52.   Private 1;
  53.   GencodeSrcLine 30;
  54.   FunctionName "PreviewFileDialog::Prototype for handleChange( WObject *, WEventData * )";
  55.  @end;
  56.  
  57.  @begin UserFunction "handleMessage( WCommonDialog *, WMessageHookEventData * )"
  58.   Private 1;
  59.   GencodeSrcLine 117;
  60.   FunctionName "PreviewFileDialog::handleMessage( WCommonDialog *, WMessageHookEventData * )";
  61.  @end;
  62.  
  63.  @begin UserFunction "Prototype for handleMessage( WCommonDialog *, WMessageHookEventData * )"
  64.   Private 1;
  65.   GencodeSrcLine 32;
  66.   FunctionName "PreviewFileDialog::Prototype for handleMessage( WCommonDialog *, WMessageHookEventData * )";
  67.  @end;
  68.  
  69.  @begin HPPPrefixBlock
  70. @begin-code HPPPrefix
  71.  
  72. // Declarations added here will be included at the top of the .HPP file
  73.  
  74. @end-code;
  75.   GencodeSrcLine 11;
  76.  @end;
  77.  
  78.  @begin CPPPrefixBlock
  79. @begin-code CPPPrefix
  80.  
  81. // Code added here will be included at the top of the .CPP file
  82.  
  83. //  Include definitions for resources.
  84. #include "WRes.h"
  85.  
  86. @end-code;
  87.   GencodeSrcLine 11;
  88.  @end;
  89.  
  90.  @begin ClassContentsBlock
  91. @begin-code ClassContents
  92.  
  93.     private:
  94.         WPictureBox         *_previewBox;
  95.         WRect               _previewRect;
  96.         WLabel              *_previewLabel;
  97.  
  98. @end-code;
  99.   GencodeSrcLine 18;
  100.  @end;
  101.  
  102. @begin-code GeneratedClassContents
  103.  
  104.  
  105. @end-code;
  106.  
  107. @begin-code Code "PreviewFileDialog::PreviewFileDialog()"
  108.  
  109. @@CLASSNAME@::@CLASSNAME@()
  110. {
  111.     _previewBox = NULL;
  112.     _previewLabel = NULL;
  113.  
  114.     SetEventHandler( WCreateEvent, this, 
  115.                      (WEventHandler) handleCreate );
  116.     if( GetStyle() & WFDSExplorer ) {                     
  117.         SetEventHandler( WChangeEvent, this, 
  118.                          (WEventHandler) handleChange );
  119.     } else {
  120.         SetEventHandler( WMessageHookEvent, this, 
  121.                          (WEventHandler) handleMessage );
  122.     }
  123. }
  124.  
  125. @end-code;
  126.  
  127. @begin-code Code "PreviewFileDialog::Prototype for PreviewFileDialog()"
  128.  
  129.     public:
  130.         @@CLASSNAME@();
  131.  
  132. @end-code;
  133.  
  134. @begin-code Code "PreviewFileDialog::~PreviewFileDialog()"
  135.  
  136. @@CLASSNAME@::~@CLASSNAME@()
  137. {   
  138.     /*  Free memory associated with the preview box
  139.     */
  140.     if( _previewLabel ) {
  141.         delete _previewLabel;
  142.         _previewLabel = NULL;
  143.     }
  144.     if( _previewBox ) {
  145.         delete _previewBox;
  146.         _previewBox = NULL;
  147.     }
  148. }
  149.  
  150. @end-code;
  151.  
  152. @begin-code Code "PreviewFileDialog::Prototype for ~PreviewFileDialog()"
  153.  
  154.     public:
  155.         ~@CLASSNAME@();
  156.  
  157. @end-code;
  158.  
  159. @begin-code Code "PreviewFileDialog::handleCreate( WObject *, WEventData * )"
  160.  
  161. WBool @CLASSNAME@::handleCreate( WObject *, WEventData * )
  162. {
  163.     WDialog     *dlg;
  164.     WRect       r;
  165.     WFont       font;
  166.     float       hDLUToPixels;   // horizontal dialog units -> pixels conversion factor
  167.     float       vDLUToPixels;   // vertical dialog units -> pixels conversion factor
  168.     
  169.     dlg = GetDialog();
  170.     font = dlg->GetFont();
  171.     hDLUToPixels = WApplication::GetDialogBaseWidth( font );
  172.     vDLUToPixels = WApplication::GetDialogBaseHeight( font );
  173.     
  174.     /*  Create preview box
  175.     */
  176.     _previewBox = new WPictureBox;
  177.     _previewBox->Create( dlg );
  178.     _previewBox->ChangeStyle( WSSCenterImage, TRUE );
  179.     _previewBox->ChangeExtendedStyle( WSExClientEdge, TRUE );
  180.  
  181.     /*  Size the picture box (all done in dialog units)
  182.     */
  183.     r.x = 280.0 * hDLUToPixels;
  184.     r.y = 20.0 * vDLUToPixels;
  185.     r.w = 68.0 * hDLUToPixels;
  186.     r.h = 85.0 * vDLUToPixels;
  187.     _previewBox->SetRectangle( r );
  188.     _previewRect = r;
  189.  
  190.     /*  Put a label over the preview window
  191.     */
  192.     r.x = 280.0 * hDLUToPixels;
  193.     r.y = 9.0 * vDLUToPixels;
  194.     r.w = 68.0 * hDLUToPixels;
  195.     r.h = 12.0 * vDLUToPixels;
  196.     _previewLabel = new WLabel;
  197.     _previewLabel->Create( dlg, r, "Preview:" );
  198.  
  199.     /*    Resize the dialog and center it.
  200.     */
  201.     r = dlg->GetRectangle( TRUE );
  202.     r.w = _previewRect.x + _previewRect.w + 7.0 * hDLUToPixels;
  203.     dlg->SetRectangle( r );
  204.     dlg->Center();    
  205.  
  206.     return FALSE;
  207. }
  208.  
  209. @end-code;
  210.  
  211. @begin-code Code "PreviewFileDialog::Prototype for handleCreate( WObject *, WEventData * )"
  212.  
  213.     private:
  214.         WBool handleCreate( WObject *, WEventData * );
  215.  
  216. @end-code;
  217.  
  218. @begin-code Code "PreviewFileDialog::handleChange( WObject *, WEventData * )"
  219.  
  220. WBool @CLASSNAME@::handleChange( WObject *, WEventData * )
  221. {
  222.     //  The definition of CDM_GETFILEPATH taken from windows.h
  223.     #define CDM_GETFILEPATH         1125
  224.     
  225.     WDialog      *dlg;
  226.     WLong        rc;
  227.     WBitmap      bmp;
  228.     char         buffer[ _MAX_PATH ];
  229.     WMessage     msg( CDM_GETFILEPATH, _MAX_PATH, (WDWord)buffer );
  230.  
  231.     
  232.     /*  Get the filename selected in the dialog. We do this by sending 
  233.         a message to the dialog.
  234.     */
  235.     dlg = GetDialog();
  236.     rc = dlg->SendMessage( msg );
  237.     if( _previewBox != NULL && rc > 0 ) {
  238.         
  239.         /*  Update the preview box
  240.         */
  241.         bmp.Create( buffer, FALSE );
  242.         _previewBox->SetBitmap( bmp );
  243.     }
  244.     return FALSE;
  245. }
  246.  
  247. @end-code;
  248.  
  249. @begin-code Code "PreviewFileDialog::Prototype for handleChange( WObject *, WEventData * )"
  250.  
  251.     private:
  252.         WBool handleChange( WObject *, WEventData * );
  253.  
  254. @end-code;
  255.  
  256. @begin-code Code "PreviewFileDialog::handleMessage( WCommonDialog *, WMessageHookEventData * )"
  257.  
  258. WBool @CLASSNAME@::handleMessage( WCommonDialog *, WMessageHookEventData *event )
  259. {
  260.     int controlID, notifyCode, index;
  261.         
  262.     /*  NOTE: You don't get WChangeEvents if you're not using the
  263.               explorer style of dialog, so we have to watch for  
  264.               messages from the files list box explicitly.
  265.     */
  266.     if( event->message.msg == 0x0111 /* WM_COMMAND */ ) {
  267.         notifyCode = event->message.wParam >> 16;
  268.         controlID = event->message.wParam & 0xffff;
  269.         if( controlID == 0x460 /* control ID of the list box */ &&
  270.             notifyCode == 0x1 /* LBN_SELCHANGE */ ) {
  271.             WListBox    listBox;
  272.             WString     fileName;
  273.             WBitmap     bmp;
  274.             
  275.             listBox.AttachToWindow( (WWindowHandle)(event->message.lParam), FALSE );
  276.             index = listBox.GetSelected();
  277.             if( index != -1 ) {    
  278.                 fileName = listBox.GetText( index );
  279.                 bmp.Create( fileName, FALSE );
  280.                 _previewBox->SetBitmap( bmp );
  281.             }
  282.             listBox.DetachFromWindow();
  283.         }
  284.     }
  285.     return FALSE;
  286. }
  287.  
  288. @end-code;
  289.  
  290. @begin-code Code "PreviewFileDialog::Prototype for handleMessage( WCommonDialog *, WMessageHookEventData * )"
  291.  
  292.     private:
  293.         WBool handleMessage( WCommonDialog *,  WMessageHookEventData * );
  294.  
  295. @end-code;
  296. @end;
  297.