Filter Library Camera Interface Physics

FilterDlg.cpp

00001 /*
00002  * FilterDlg.cpp - base class for filter dialogs.
00003  *
00004  * This file is part of the Camera Filter Library.
00005  * Computer Aided Measurement Environment for Realtime Atomic imaging (Camera)
00006  *
00007  * Copyright (C) 2004, Leiden Probe Microscopy.
00008  * Copyright (C) 2004, Universiteit Leiden.
00009  *
00010  * Authors: M. Seynen (original), Martin J. Moene
00011  *
00012  * $Id: FilterDlg.cpp 150 2005-04-25 09:02:30Z moene $
00013  */
00014 
00015 #include "stdafx.h"                     // for common (pre-compiled) headers
00016 //#include <cfl/stdafx.h>                 // for common (pre-compiled) headers
00017 #include <cfl/resource.h>               // for messages and other resources
00018 
00019 #include <Camera/InterfaceDll.h>        // Camera--Filter Library interface
00020 #include <Camera/CameraGeneralDefines.h>// for g_d2PI
00021 
00022 #include <cfl/ScanBaseBuffer.h>         // for class CScanBaseBuffer
00023 #include <cfl/ScanFilter.h>             // this filter's header
00024 #include <cfl/FilterDlg.h>              // this filter's dialog
00025 
00026 #ifdef _DEBUG
00027 #define new DEBUG_NEW
00028 #undef THIS_FILE
00029 static char THIS_FILE[] = __FILE__;
00030 #endif
00031 
00032 /*
00033  * prototypes:
00034  */
00035 static bool SetMouseMsgHook   ( HWND hwndDlg );
00036 static void RemoveMouseMsgHook( );
00037 
00038 /*
00039  * massage map:
00040  */
00041 BEGIN_MESSAGE_MAP(CFilterDlg, CDialog)
00042    //{{AFX_MSG_MAP(CFilterDlg)
00043    ON_EN_KILLFOCUS(IDC_BUFFEROUTNAME, OnKillfocusBufferoutname)
00044    ON_BN_CLICKED(IDHELP, OnHelp)
00045    ON_WM_TIMER()
00046    ON_WM_DESTROY()
00047    //}}AFX_MSG_MAP
00048    ON_MESSAGE( TTM_RELAYEVENT, OnRelayEvent )
00049 END_MESSAGE_MAP()
00050 
00051 /*
00052  * (default) constructor:
00053  */
00054 CFilterDlg::CFilterDlg( CWnd* pParent /* =NULL */ ) :
00055    CDialog( CFilterDlg::IDD, pParent ),
00056    m_bInEditModeless( false ),
00057    m_bInitialized( false )
00058 {
00059 //   Q_LOG( _T("CFilterDlg::CFilterDlg()") );
00060 
00061    //{{AFX_DATA_INIT(CFilterDlg)
00062    // NOTE: the ClassWizard will add member initialization here
00063    //}}AFX_DATA_INIT
00064 
00065    /*
00066     * for embedded help:
00067     */
00068    m_timerHelpId = 0;
00069    m_curHelpId   = IDC_EMBEDDEDHELP;
00070 }
00071 
00072 /*
00073  * destructor: remove mouse message hook.
00074  */
00075 CFilterDlg::~CFilterDlg()
00076 {
00077 //   Q_LOG( _T("CFilterDlg::~CFilterDlg()") );
00078 
00079    /*
00080     * for embedded help:
00081     */
00082    RemoveMouseMsgHook();
00083 }
00084 
00085 /*
00086  * Dialog Data Exchange (DDX) / Dialog Data Validation (DDV) support.
00087  */
00088 void CFilterDlg::DoDataExchange(CDataExchange* pDX)
00089 {
00090 //    Q_LOG( _T("CFilterDlg::DoDataExchange()") );
00091 
00092   CDialog::DoDataExchange(pDX);
00093    //{{AFX_DATA_MAP(CFilterDlg)
00094       // NOTE: the ClassWizard will add DDX and DDV calls here
00095    //}}AFX_DATA_MAP
00096 }
00097 
00098 /*
00099  * OK button message handler.
00100  */
00101 void CFilterDlg::OnOK()
00102 {
00103 //   Q_LOG( _T("CFilterDlg::OnOK()") );
00104 
00105    /*
00106     * save the current filter settings.
00107     */
00108    m_pFilter->WriteFilterSettings();
00109 
00110    if ( InEditModeless() )
00111    {
00112       /*
00113        * Let the application handle the cleanup:
00114        */
00115       AfxGetMainWnd()->SendMessage( WMU_DELETEFILTER, 0, 0 );
00116       return ;
00117    }
00118 
00119    Q_ASSERT( m_pDoc    && "ensure m_pDoc"    );
00120    Q_ASSERT( m_pFilter && "ensure m_pFilter" );
00121 
00122    /*
00123     * let the caller (some CScanView) handle the cleanup.
00124     */
00125    m_pDoc->UpdateAllViews( NULL, SCANVIEWUPDATE_FILTEROPERATIONDONE, m_pFilter );
00126 }
00127 
00128 /*
00129  * Cancel button message handler.
00130  */
00131 void CFilterDlg::OnCancel()
00132 {
00133 //   Q_LOG( _T("CFilterDlg::OnCancel()") );
00134 
00135    if ( InEditModeless() )
00136    {
00137       /*
00138        * Let the application handle the cleanup:
00139        */
00140       AfxGetMainWnd()->SendMessage( WMU_DELETEFILTER, 0, 0 );
00141       return ;
00142    }
00143 
00144    Q_ASSERT( m_pDoc    && "ensure m_pDoc"    );
00145    Q_ASSERT( m_pFilter && "ensure m_pFilter" );
00146 
00147    /*
00148     * Let the caller (some CScanView) handle the cleanup; cancel only the current view.
00149     */
00150    m_pDoc->UpdateAllViews( NULL, SCANVIEWUPDATE_FILTEROPERATIONCANCEL, m_pFilter );
00151 }
00152 
00153 /*
00154  * Help button handler.
00155  */
00156 void CFilterDlg::OnHelp()
00157 {
00158 //   Q_LOG( _T("CFilterDlg::OnHelp()") );
00159 
00160    SetEmbeddedHelp( _T("This help is not yet available" ) );
00161 }
00162 
00163 /*
00164  * update view and in Edit mode also update the stored filter settings.
00165  */
00166 void CFilterDlg::UpdateView()
00167 {
00168 //   Q_LOG( _T("CFilterDlg::UpdateView()") );
00169 
00170    if ( InEditModeless() )
00171    {
00172       /*
00173        * update stored parameter settings for use with online/script filtering:
00174        */
00175       m_pFilter->WriteFilterSettings();
00176 
00177       return ;
00178    }
00179 
00180    Q_ASSERT( m_pDoc && "ensure m_pDoc" );
00181 
00182    m_pDoc->UpdateAllViews( NULL, SCANVIEWUPDATE_REDRAWBUFFER, m_pFilter->m_lpsbOut );
00183 }
00184 
00185 /*
00186  * initialize dialog.
00187  */
00188 BOOL CFilterDlg::OnInitDialog()
00189 {
00190 //   Q_LOG( _T("CFilterDlg::OnInitDialog()") );
00191 
00192    CDialog::OnInitDialog();
00193 
00194    /*
00195     * guard for EditModeless(): has no buffers:
00196     */
00197    if ( !InEditModeless() )
00198    {
00199       SetDlgItemText( IDC_BUFFERINNAME, m_pFilter->m_lpsbIn->m_csBufferName );
00200    }
00201    //SetDlgItemText( IDC_BUFFEROUTNAME, m_pFilter->m_lpsbOut->m_csBufferName );
00202 
00203    /*
00204     * hook mouse for embedded help:
00205     */
00206    SetMouseMsgHook(*this);
00207 
00208    return TRUE;
00209 }
00210 
00211 /*
00212  * obtain a scan buffer.
00213  */
00214 CScanBaseBuffer *CFilterDlg::BrowseForScanBuffer()
00215 {
00216 //   Q_LOG( _T("CFilterDlg::BrowseForScanBuffer()") );
00217 
00218    if ( InEditModeless() )
00219    {
00220       return NULL;
00221    }
00222 
00223    CMDIFrameWnd *pMain = (CMDIFrameWnd *)AfxGetMainWnd();
00224 
00225    CScanBaseBuffer *lpBuffer = NULL;
00226    pMain->SendMessage( WMU_SCANVIEWBROWSEFORBUFFER, 0, (LPARAM) &lpBuffer );
00227 
00228    return lpBuffer;
00229 }
00230 
00231 /*
00232  * update view for new output buffername.
00233  */
00234 void CFilterDlg::OnKillfocusBufferoutname()
00235 {
00236 //   Q_LOG( _T("CFilterDlg::OnKillfocusBufferoutname()") );
00237 
00238    /*
00239     * guard for EditModeless(): has no buffers:
00240     */
00241    if ( InEditModeless() )
00242    {
00243       return ;
00244    }
00245 
00246    GetDlgItemText( IDC_BUFFEROUTNAME, m_pFilter->m_lpsbOut->m_csBufferName );
00247 
00248    if ( m_pFilter->m_lpsbOut->m_pwData )
00249    {
00250       UpdateView();
00251    }
00252 }
00253 
00254 /*
00255  * disable the input and output buffername controls for the EditModeless dialog.
00256  */
00257 void CFilterDlg::DisableBufferControls()
00258 {
00259 //   Q_LOG( _T("CFilterDlg::DisableBufferControls()") );
00260 
00261    int IdcList[] =
00262    {
00263       IDC_BUFFERINNAME,
00264       IDC_BUFFEROUTNAME,
00265    };
00266 
00267    for ( int i = 0; i < dim(IdcList); ++i )
00268    {
00269       CWnd* wnd = GetDlgItem( IdcList[i]  );
00270 
00271       if ( wnd )
00272       {
00273          wnd->EnableWindow( FALSE );
00274       }
00275    }
00276 }
00277 
00278 /* ------------------------------------------------------------------
00279  *
00280  * KeyHelp from http://www.keyworks.net/
00281  */
00282 
00283 /*
00284  * set the text in the embedded help control (id).
00285  */
00286 void CFilterDlg::SetEmbeddedHelp( UINT id )
00287 {
00288    CString s;
00289    if ( s.LoadString( id ) )
00290    {
00291       SetEmbeddedHelp( s );
00292    }
00293 }
00294 
00295 /*
00296  * set the text in the embedded help control (C-string).
00297  */
00298 void CFilterDlg::SetEmbeddedHelp( LPCTSTR lpString )
00299 {
00300    SetDlgItemText( IDC_EMBEDDEDHELP, lpString );
00301 }
00302 
00303 #pragma warning( push, 3 )              // disable unreferenced parameter warning
00304 
00305 /*
00306  * get the (help) id of the dialog's control under the mouse cursor.
00307  */
00308 LRESULT CFilterDlg::OnRelayEvent(WPARAM wParam, LPARAM lParam)
00309 {
00310    /*
00311     * Every time we get a mouse message, we kill the timer
00312     */
00313 
00314    if ( m_timerHelpId )
00315    {
00316       KillTimer( m_timerHelpId );
00317       m_timerHelpId = 0;
00318    }
00319 
00320    int id = ::GetDlgCtrlID( ( (MSG*) lParam )->hwnd );
00321 
00322    if ( m_curHelpId != id )
00323    {
00324       if ( m_timerHelpId )
00325       {
00326          KillTimer( m_timerHelpId );
00327       }
00328 
00329       m_timerHelpId = id;
00330 
00331       SetTimer( m_timerHelpId, HOVER_DELAY, NULL );
00332    }
00333 
00334    return 0;
00335 }
00336 
00337 #pragma warning( pop )
00338 #pragma warning( push, 3 )              // disable unreferenced parameter warning
00339 
00340 /*
00341  * show embedded help if the timer fires.
00342  */
00343 void CFilterDlg::OnTimer( UINT nIDEvent )
00344 {
00345    /*
00346     * When the timer goes off, it means the mouse has been over a control
00347     * for HOVER_DELAY milliseconds. The id of the timer is the mapped id
00348     * of the html file to display.
00349     */
00350 
00351    KillTimer( m_timerHelpId );
00352 
00353 //    m_hhctrl.NavigateChm(m_timerHelpId);
00354 
00355    /*
00356     * FIXME: IDHELP shows: IDS_COLOR8|9|"select a color" from Camera String Table.
00357     *
00358     * ?use
00359     *    int LoadString(
00360     *        HINSTANCE hInstance,  // handle to module containing string resource: <-- DLL
00361     *        UINT uID,             // resource identifier
00362     *        LPTSTR lpBuffer,      // pointer to buffer for resource
00363     *        int nBufferMax        // size of buffer
00364     *     );
00365     */
00366 
00367    CString s;
00368    if ( s.LoadString( m_timerHelpId ) )
00369    {
00370       SetEmbeddedHelp( s );
00371    }
00372    else
00373    {
00374       SetEmbeddedHelp( "[empty]" );
00375    }
00376 
00377     m_curHelpId   = m_timerHelpId;      // store current help id
00378     m_timerHelpId = 0;                  // 
00379 }
00380 
00381 #pragma warning( pop )                  // disable unreferenced parameter warning
00382 
00383 /*
00384  * kill the timer for embedded help.
00385  */
00386 void CFilterDlg::OnDestroy()
00387 {
00388    if ( m_timerHelpId )
00389    {
00390       KillTimer( m_timerHelpId );
00391    }
00392 
00393     CDialog::OnDestroy();
00394 }
00395 
00396 /*------------------------------------------------------------------------
00397  * mouse event handling for embedded help
00398  *------------------------------------------------------------------------
00399  */
00400 
00401 static LRESULT CALLBACK RelayMouseMsgHook( int nCode, WPARAM wParam, LPARAM lParam );
00402 
00403 static HHOOK s_hkMouseMsg;
00404 static HWND  s_hwndMouseMsgDlg;
00405 
00406 /*
00407  * attach our mouse hook.
00408  */
00409 static bool SetMouseMsgHook( HWND hwndDlg )
00410 {
00411    /*
00412     * we only one hook at a time
00413     */
00414 
00415    Q_ASSERT( !s_hkMouseMsg && "only hook mouse one time" );
00416 
00417    s_hkMouseMsg = SetWindowsHookEx( WH_GETMESSAGE, RelayMouseMsgHook,(HINSTANCE) NULL, GetCurrentThreadId() );
00418 
00419    if ( s_hkMouseMsg )
00420    {
00421       s_hwndMouseMsgDlg = hwndDlg;
00422       return true;
00423    }
00424 
00425    return false;
00426 }
00427 
00428 /*
00429  * detach our mouse hook.
00430  */
00431 static void RemoveMouseMsgHook()
00432 {
00433    if ( s_hkMouseMsg )
00434    {
00435       UnhookWindowsHookEx( s_hkMouseMsg );
00436       s_hkMouseMsg = NULL;
00437    }
00438 }
00439 
00440 /*
00441  * also send the mouse messages to our dialog, if appropriate.
00442  */
00443 static LRESULT CALLBACK RelayMouseMsgHook( int nCode, WPARAM wParam, LPARAM lParam )
00444 {
00445    MSG* pmsg = (MSG*) lParam;
00446 
00447    if ( nCode < 0 || !( IsChild( s_hwndMouseMsgDlg, pmsg->hwnd ) ) )
00448    {
00449       return CallNextHookEx( s_hkMouseMsg, nCode, wParam, lParam );
00450    }
00451 
00452    switch ( pmsg->message )
00453    {
00454       case WM_MOUSEMOVE:
00455       case WM_LBUTTONDOWN:
00456       case WM_LBUTTONUP:
00457       case WM_RBUTTONDOWN:
00458       case WM_RBUTTONUP:
00459          SendMessage( s_hwndMouseMsgDlg, TTM_RELAYEVENT, 0, (LPARAM) pmsg );
00460          break;
00461 
00462       default:
00463          break;
00464    }
00465 
00466    return CallNextHookEx( s_hkMouseMsg, nCode, wParam, lParam );
00467 }
00468 
00469 /*
00470  * end of file
00471  */
00472 

Camera Filter Library documentation © 2004-2007 by Leiden Probe Microscopy