home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / interact / findw.cp next >
Encoding:
Text File  |  1998-04-08  |  7.8 KB  |  322 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. // ===========================================================================
  20. // findw.cp
  21. // Find dialog box
  22. // Contains all the views/commands for the find dialog box
  23. // Created by atotic, Aug 6th, 1994
  24. // ===========================================================================
  25.  
  26. #include "findw.h"
  27. #include "uapp.h"
  28. #include "resgui.h"
  29. #include "macutil.h"
  30. //#include "VEditField.h"
  31. #include "CTSMEditField.h"
  32. #include <LStdControl.h>
  33. #include <URegistrar.h>
  34.  
  35. #include "csid.h"
  36. #include "libi18n.h"
  37.  
  38. #ifdef EDITOR
  39. #include "edt.h"    // composer find/replace dialog
  40. #include "CBrowserContext.h"
  41. #endif
  42.  
  43.  
  44.  
  45.  
  46.     // globals
  47. CFindWindow*         CFindWindow::sFindWindow            = NULL;     
  48. CHTMLView*            CFindWindow::sViewBeingSearched        = NULL;        // Who is being searched?
  49. cstring                CFindWindow::sLastSearch;                        // Last search string
  50. Boolean                CFindWindow::sCaseless                = TRUE;        // Search is caseless?
  51. Boolean                CFindWindow::sBackward                = FALSE;    // Search backward
  52. Boolean                CFindWindow::sWrap                    = FALSE;    // Wrap ?
  53.  
  54. Boolean                LMailNewsFindWindow::sFindInHeaders = FALSE;    // search message headers?
  55. #ifdef EDITOR
  56. cstring                CComposeFindWindow::sLastReplace;                // Last replacement string
  57. #endif
  58.  
  59. CFindWindow::CFindWindow(LStream* inStream)
  60.     : LDialogBox(inStream)
  61. {
  62.     sFindWindow = this;
  63. }
  64.  
  65. CFindWindow::~CFindWindow()
  66. {
  67.     StoreDefaultWindowState(this);
  68.     sFindWindow = NULL;
  69. }
  70.  
  71. void CFindWindow::FinishCreateSelf()
  72. {
  73.     LDialogBox::FinishCreateSelf();
  74.  
  75.     RestoreDefaultWindowState(this);
  76.  
  77.     fSearchFor             = (CTSMEditField*)sFindWindow->FindPaneByID('what');
  78.     fCaseSensitive         = (LStdCheckBox*)sFindWindow->FindPaneByID('case');
  79.     fSearchBackwards     = (LStdCheckBox*)sFindWindow->FindPaneByID('back');
  80.     fWrapSearch         = (LStdCheckBox*)sFindWindow->FindPaneByID('wrap');
  81. }
  82.  
  83.     // Interface to the application
  84. void CFindWindow::RegisterViewTypes()
  85. {
  86.     RegisterClass_(CFindWindow);
  87.     #ifdef MOZ_MAIL_NEWS
  88.     RegisterClass_(LMailNewsFindWindow);
  89.     RegisterClass_(CComposeFindWindow);
  90.     #endif
  91. }
  92.  
  93. void CFindWindow::SetDialogValues()
  94. {
  95.     CStr255 searchString(sLastSearch);
  96.     fSearchFor->SetDescriptor(searchString);
  97.     fSearchFor->SelectAll();
  98.     sFindWindow->SetLatentSub(fSearchFor);
  99.     
  100.     fCaseSensitive->SetValue(!sCaseless);
  101.     fSearchBackwards->SetValue(sBackward);
  102.     
  103.     if (fWrapSearch != NULL)
  104.         fWrapSearch->SetValue(sWrap);
  105. }
  106.  
  107. void CFindWindow::SetTextTraitsID(ResIDT inTextTraitsID)
  108. {
  109.     fSearchFor->SetTextTraitsID(inTextTraitsID);
  110. }
  111.  
  112. void CFindWindow::DoFind(CHTMLView* theHTMLView)
  113. {
  114.     sViewBeingSearched = theHTMLView;
  115.     
  116.     if (!sFindWindow)
  117.     {
  118.         theHTMLView->CreateFindWindow();
  119.         ThrowIfNil_(sFindWindow);
  120.     }
  121.     
  122.     if    (theHTMLView->GetWinCSID() != INTL_CharSetNameToID(INTL_ResourceCharSet()))
  123.     {
  124.         sFindWindow->SetTextTraitsID( CPrefs::GetTextFieldTextResIDs(theHTMLView->GetWinCSID()));
  125.     }
  126.     
  127.     sFindWindow->SetDialogValues();
  128.     sFindWindow->Show();
  129.     sFindWindow->Select();
  130. }
  131.  
  132. Boolean CFindWindow::CanFindAgain()
  133. {
  134.     return (sLastSearch.length() > 0);
  135. }
  136.  
  137. void CFindWindow::GetDialogValues()
  138. {
  139.     CStr255 lookFor;
  140.     fSearchFor->GetDescriptor(lookFor);
  141.     sLastSearch = (char*)lookFor;
  142.     sCaseless = (fCaseSensitive->GetValue() == 0);
  143.     sBackward = fSearchBackwards->GetValue();
  144.     
  145.     sWrap = (fWrapSearch != NULL && fWrapSearch->GetValue());
  146. }
  147.  
  148. void CFindWindow::ListenToMessage(MessageT inMessage, void* ioParam)
  149. {
  150.     switch( inMessage )
  151.     {
  152.         case msg_OK:
  153.         {
  154.             this->GetDialogValues();
  155.             sViewBeingSearched->DoFind();
  156.             ListenToMessage( cmd_Close, NULL );
  157.             break;
  158.         }
  159.         
  160.         
  161.         case msg_Cancel:
  162.         {
  163.             LDialogBox::ListenToMessage( cmd_Close, ioParam );
  164.             break;
  165.         }
  166.         
  167.         default:
  168.         {
  169.             LDialogBox::ListenToMessage(inMessage, ioParam);
  170.             break;
  171.         }
  172.     }
  173. }
  174.  
  175.  
  176. /* SavePlace, RestorePlace and DoSetBounds all override the window and subpane
  177.    positioning behaviour used in FinishCreateSelf and the destructor, so that
  178.    only the window position is saved and restored.  This is important to
  179.    the internationalization folks, who want the PPob to control pane positions,
  180.    rather than the preferences file. */
  181. void CFindWindow::SavePlace (LStream */*outPlace*/)
  182. {
  183.     // don't!
  184. }
  185.  
  186. void CFindWindow::RestorePlace (LStream */*inPlace*/)
  187. {
  188.     // don't
  189. }
  190.  
  191. void CFindWindow::DoSetBounds (const Rect &inBounds) // bounds in global coords
  192. {
  193.     // refuse to accept a change in window size: we're a fixed dialog, after all.
  194.     Rect    newBounds = UWindows::GetWindowContentRect(GetMacPort());
  195.  
  196.     newBounds.right += inBounds.left - newBounds.left;
  197.     newBounds.left = inBounds.left;
  198.     newBounds.bottom += inBounds.top - newBounds.top;
  199.     newBounds.top = inBounds.top;
  200.  
  201.     super::DoSetBounds (newBounds);
  202. }
  203.  
  204.  
  205. void CFindWindow::FindCommandStatus(CommandT    /*inCommand*/,
  206.                                     Boolean    &     outEnabled, 
  207.                                     Boolean &     /*outUsesMark*/, 
  208.                                     Char16  &     /*outMark*/,
  209.                                     Str255         /*outName*/ )
  210. {
  211.     // we're a modal dialog
  212.     outEnabled = false;
  213. }
  214.             
  215. #ifdef MOZ_MAIL_NEWS
  216.  
  217. LMailNewsFindWindow::LMailNewsFindWindow( LStream* inStream )
  218. :    CFindWindow( inStream )
  219. {
  220. }
  221.  
  222. void LMailNewsFindWindow::FinishCreateSelf()
  223. {
  224.     CFindWindow::FinishCreateSelf();
  225.     fFindInHeaders = (LStdRadioButton*)this->FindPaneByID( 'Rhea' );
  226. }
  227.  
  228. void LMailNewsFindWindow::GetDialogValues()
  229. {
  230.     CFindWindow::GetDialogValues();
  231.     sFindInHeaders = ( fFindInHeaders->GetValue() != 0 );
  232. }
  233.  
  234. # ifdef EDITOR
  235. # pragma mark -
  236.  
  237. CComposeFindWindow::CComposeFindWindow( LStream *inStream ) : CFindWindow( inStream )
  238. {
  239. }
  240.  
  241.  
  242. void CComposeFindWindow::FinishCreateSelf()
  243. {
  244.     CFindWindow::FinishCreateSelf();
  245.     
  246.     UReanimator::LinkListenerToControls( this, this, mPaneID );
  247.     
  248.     fReplaceWith = (CTSMEditField *)sFindWindow->FindPaneByID( 'newT' );
  249.     XP_ASSERT( fReplaceWith != NULL );
  250. }
  251.  
  252.  
  253. void CComposeFindWindow::SetDialogValues()
  254. {
  255.     CFindWindow::SetDialogValues();
  256.     
  257.     CStr255 replaceString( sLastReplace );
  258.     fReplaceWith->SetDescriptor( replaceString );
  259.     fReplaceWith->SelectAll();
  260.     sFindWindow->SetLatentSub( fReplaceWith );
  261. }
  262.  
  263.  
  264. void CComposeFindWindow::GetDialogValues()
  265. {
  266.     CFindWindow::GetDialogValues();
  267.     
  268.     CStr255 replaceString;
  269.     fReplaceWith->GetDescriptor( replaceString );
  270.     sLastReplace = (char*)replaceString;
  271. }
  272.  
  273.  
  274. void CComposeFindWindow::ListenToMessage(MessageT inMessage, void* ioParam)
  275. {
  276.     switch( inMessage )
  277.     {
  278.         case msg_OK:    /* find */
  279.         {
  280.             this->GetDialogValues();
  281.             sViewBeingSearched->DoFind();
  282. //            ListenToMessage( cmd_Close, NULL );
  283.             break;
  284.         }
  285.         
  286.         case 'Repl':
  287.         case 'RepA':
  288.         case 'RepN':
  289.         {
  290.             Str255 str;
  291.             fReplaceWith->GetDescriptor( str );
  292.             p2cstr( str );
  293.             
  294.             EDT_ReplaceText( (sViewBeingSearched->GetContext())->operator MWContext*(), (char *)str, 
  295.                             inMessage == 'RepA', sLastSearch, sCaseless, sBackward, sWrap );
  296.             
  297.             /* do we need to find the next one? */
  298.             if ( inMessage == 'RepN' )
  299.             {
  300.                 sViewBeingSearched->DoFind();
  301.             }
  302.             break;
  303.         }
  304.         
  305.         case msg_Cancel:
  306.         {
  307.             LDialogBox::ListenToMessage( cmd_Close, ioParam );
  308.             break;
  309.         }
  310.         
  311.         default:
  312.         {
  313.             LDialogBox::ListenToMessage(inMessage, ioParam);
  314.             break;
  315.         }
  316.     }
  317. }
  318.  
  319.  
  320. # endif // EDITOR
  321. #endif // MOZ_MAIL_NEWS
  322.