1 #ifndef _BUTTON_H 2 #include <Button.h> 3 #endif 4 5 #ifndef _CHECK_BOX_H 6 #include <CheckBox.h> 7 #endif 8 9 #ifndef _STRING_H 10 #include <String.h> 11 #endif 12 13 #ifndef _TEXT_CONTROL_H 14 #include <TextControl.h> 15 #endif 16 17 #ifndef _WINDOW_H 18 #include <Window.h> 19 #endif 20 21 #ifndef CONSTANTS_H 22 #include "Constants.h" 23 #endif 24 25 #ifndef REPLACE_WINDOW_H 26 #include "ReplaceWindow.h" 27 #endif 28 29 ReplaceWindow::ReplaceWindow(BRect frame, BHandler *_handler, BString *searchString, BString *replaceString, bool *caseState, bool *wrapState, bool *backState) 30 : BWindow(frame, "", B_MODAL_WINDOW, B_NOT_RESIZABLE,B_CURRENT_WORKSPACE) 31 { 32 33 fReplaceView=new BView(Bounds(),"",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); 34 fReplaceView->SetViewColor(216,216,216); 35 fReplaceView->AddChild (fSearchString= new BTextControl(BRect(5,10,290,50), "", "Find:",NULL, NULL, 36 B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); 37 fSearchString->SetDivider(65); 38 fReplaceView->AddChild(fReplaceString=new BTextControl(BRect(5,35,290,50), "", "Replace with:",NULL, 39 NULL,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); 40 fReplaceString->SetDivider(65); 41 42 fReplaceView->AddChild(fCaseSensBox=new BCheckBox(BRect(72,60,162,52),"","Case-sensitive", NULL, 43 B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); 44 fReplaceView->AddChild(fWrapBox=new BCheckBox(BRect(72,80,195,70),"","Wrap-around search", NULL, 45 B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); 46 fReplaceView->AddChild(fBackSearchBox=new BCheckBox(BRect(72,100,179,95),"","Search backwards", NULL, 47 B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); 48 fReplaceView->AddChild(fAllWindowsBox=new BCheckBox(BRect(72,120,195,95),"","Replace in all windows", 49 new BMessage(CHANGE_WINDOW) ,B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); 50 fUichange=false; 51 52 //vertical separator at 110 in StyledEdit 53 fReplaceView->AddChild(fReplaceAllButton=new BButton(BRect(10,150,98,166),"","Replace All",new BMessage(MSG_REPLACE_ALL), 54 B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); 55 fReplaceView->AddChild(fCancelButton=new BButton(BRect(141,150,211,166),"","Cancel",new BMessage(B_QUIT_REQUESTED), 56 B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); 57 fReplaceView->AddChild(fReplaceButton=new BButton(BRect(221,150,291,166),"","Replace",new BMessage(MSG_REPLACE), 58 B_FOLLOW_LEFT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE)); 59 fReplaceButton->MakeDefault(true); 60 61 AddChild(fReplaceView); 62 fHandler=_handler; 63 64 const char *searchtext= searchString->String(); 65 const char *replacetext= replaceString->String(); 66 67 fSearchString->SetText(searchtext); 68 fReplaceString->SetText(replacetext); 69 70 if(*caseState== true) 71 fCaseSensBox->SetValue(B_CONTROL_ON); 72 else 73 fCaseSensBox->SetValue(B_CONTROL_OFF); 74 75 if(*wrapState== true) 76 fWrapBox->SetValue(B_CONTROL_ON); 77 else 78 fWrapBox->SetValue(B_CONTROL_OFF); 79 80 if(*backState== true) 81 fBackSearchBox->SetValue(B_CONTROL_ON); 82 else 83 fBackSearchBox->SetValue(B_CONTROL_OFF); 84 85 Show(); 86 } 87 88 void ReplaceWindow::MessageReceived(BMessage *msg){ 89 switch(msg->what){ 90 case B_QUIT_REQUESTED: 91 QuitRequested(); 92 break; 93 case MSG_REPLACE: 94 ExtractToMsg(new BMessage(MSG_REPLACE)); 95 break; 96 case CHANGE_WINDOW: 97 ChangeUi(); 98 break; 99 case MSG_REPLACE_ALL: 100 ExtractToMsg(new BMessage(MSG_REPLACE_ALL)); 101 break; 102 default: 103 BWindow::MessageReceived(msg); 104 break; 105 } 106 } 107 108 void ReplaceWindow::ChangeUi(){ 109 110 if(!fUichange){ 111 fReplaceAllButton->MakeDefault(true); 112 fReplaceButton->SetEnabled(false); 113 fWrapBox->SetValue(B_CONTROL_ON); 114 fWrapBox->SetEnabled(false); 115 fBackSearchBox->SetEnabled(false); 116 fUichange=true; 117 } 118 else{ 119 fReplaceButton->MakeDefault(true); 120 fReplaceButton->SetEnabled(true); 121 fReplaceAllButton->SetEnabled(true); 122 fWrapBox->SetValue(B_CONTROL_OFF); 123 fWrapBox->SetEnabled(true); 124 fBackSearchBox->SetEnabled(true); 125 fUichange=false; 126 } 127 128 }/***ReplaceWindow::ChangeUi()***/ 129 130 void ReplaceWindow::DispatchMessage(BMessage *message, BHandler *fHandler){ 131 int8 key; 132 if ( message->what == B_KEY_DOWN ) { 133 status_t result; 134 result= message-> FindInt8("byte", 0, &key); 135 136 if (result== B_OK) { 137 if(key== B_ESCAPE){ 138 message-> MakeEmpty(); 139 message-> what= B_QUIT_REQUESTED; 140 } 141 } 142 } 143 BWindow::DispatchMessage(message,fHandler); 144 } 145 146 void ReplaceWindow::ExtractToMsg(BMessage *message ){ 147 148 int32 caseBoxState; 149 int32 wrapBoxState; 150 int32 backBoxState; 151 int32 allWinBoxState; 152 153 caseBoxState= fCaseSensBox-> Value(); 154 wrapBoxState= fWrapBox-> Value(); 155 backBoxState= fBackSearchBox-> Value(); 156 allWinBoxState= fAllWindowsBox-> Value(); 157 158 bool caseSens; 159 bool wrapIt; 160 bool backSearch; 161 bool allWindows; 162 163 if(caseBoxState== B_CONTROL_ON) 164 caseSens= true; 165 else 166 caseSens= false; 167 168 if(wrapBoxState== B_CONTROL_ON) 169 wrapIt= true; 170 else 171 wrapIt= false; 172 173 if(backBoxState== B_CONTROL_ON) 174 backSearch= true; 175 else 176 backSearch= false; 177 178 if(allWinBoxState== B_CONTROL_ON) 179 allWindows= true; 180 else 181 allWindows= false; 182 183 message->AddString("FindText",fSearchString->Text()); 184 message->AddString("ReplaceText",fReplaceString->Text()); 185 message->AddBool("casesens", caseSens); 186 message->AddBool("wrap", wrapIt); 187 message->AddBool("backsearch", backSearch); 188 message->AddBool("allwindows", allWindows); 189 190 fHandler->Looper()->PostMessage(message,fHandler); 191 delete(message); 192 PostMessage(B_QUIT_REQUESTED); 193 } 194 195 196 197 198 199