00001 // $Id: urldlg.cpp 1282 2006-06-09 09:46:49Z alex $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 // 00099 00100 #include "camtypes.h" 00101 #include "urldlg.h" 00102 00103 //#include "urlres.h" //URL dialog resources 00104 //#include "resimmap.h" //URL import string resources 00105 00106 //#include "msg.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00107 00108 #include "xshelpid.h" //For the help ID 00109 00110 00111 DECLARE_SOURCE("$Revision: 1282 $"); 00112 00113 CC_IMPLEMENT_DYNCREATE(URLImportDlg, DialogOp) 00114 00115 #define new CAM_DEBUG_NEW 00116 00117 // Set up the dialog box details stored as statics in the class 00118 CDlgResID URLImportDlg::IDD = _R(IDD_URLIMPORT); 00119 const CDlgMode URLImportDlg::Mode = MODAL; 00120 00121 BOOL URLImportDlg::DontHandleNextMessage = FALSE; 00122 BOOL URLImportDlg::DialogWasCancelled = FALSE; 00123 00124 WebAddress URLImportDlg::ms_url = WebAddress(); 00125 00126 00127 00128 /****************************************************************************************** 00129 00130 > BOOL URLImportDlg::OpenAndGetURL(WebAddress* purlToReturn) 00131 00132 00133 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00134 Created: 6/6/97 00135 Inputs: - 00136 00137 Outputs: purlToReturn Pointer to a Web Address object 00138 00139 Returns: TRUE - Import was pressed 00140 FALSE - Cancel was pressed 00141 Purpose: Starts up the Import from Internet dialog box 00142 Errors: - 00143 SeeAlso: - 00144 00145 ******************************************************************************************/ 00146 00147 BOOL URLImportDlg::OpenAndGetURL(WebAddress* purlToReturn) 00148 { 00149 //Say that the dialog wasn't cancelled 00150 DialogWasCancelled=FALSE; 00151 00152 //Find the dialog's op descriptor 00153 OpDescriptor *OpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(URLImportDlg)); 00154 00155 //And start up the dialog 00156 if (OpDesc != NULL) 00157 OpDesc->Invoke(); 00158 00159 //And return the member variable 00160 *purlToReturn=URLImportDlg::ms_url; 00161 00162 return !DialogWasCancelled; 00163 } 00164 00165 00166 /****************************************************************************************** 00167 00168 > URLImportDlg::URLImportDlg(): DialogOp(URLImportDlg::IDD, URLImportDlg::Mode) 00169 00170 00171 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00172 Created: 10/4/97 00173 Inputs: - 00174 Outputs: - 00175 Returns: - 00176 Purpose: Default constructor 00177 Errors: - 00178 SeeAlso: - 00179 00180 ******************************************************************************************/ 00181 00182 URLImportDlg::URLImportDlg(): DialogOp(URLImportDlg::IDD, URLImportDlg::Mode) 00183 { 00184 00185 } 00186 00187 /****************************************************************************************** 00188 00189 > MsgResult URLImportDlg::Message(CDlgMessage DlgMsg, CGadgetID Gadget) 00190 00191 00192 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00193 Created: 10/4/97 00194 Inputs: - 00195 Outputs: - 00196 Returns: - 00197 Purpose: Handles all messages. 00198 00199 This function simply maps the message to one of our message handling 00200 functions below. 00201 00202 Errors: - 00203 SeeAlso: - 00204 00205 ******************************************************************************************/ 00206 00207 MsgResult URLImportDlg::Message(Msg* Message) 00208 { 00209 //If the message came from within our dialog 00210 if (IS_OUR_DIALOG_MSG(Message)) 00211 { 00212 //Then cast it into a dialog message and handle it 00213 DialogMsg* Msg = (DialogMsg*)Message; 00214 00215 //If this flag gets set, we should close the dialog 00216 BOOL EndDialog = FALSE; 00217 00218 //Now pass the message to a message handling function 00219 switch (Msg->DlgMsg) 00220 { 00221 case DIM_CREATE: 00222 OnCreate(); 00223 break; 00224 00225 case DIM_COMMIT: 00226 OnCommit(); 00227 EndDialog=TRUE; 00228 break; 00229 00230 case DIM_CANCEL: 00231 DialogWasCancelled=TRUE; 00232 EndDialog = TRUE; 00233 break; 00234 00235 case DIM_LFT_BN_CLICKED: 00236 // A control on the dialog box has been clicked... 00237 if(Msg->GadgetID==_R(IDC_URLIMPORT_IMPORT)) 00238 { 00239 OnCommit(); 00240 EndDialog=TRUE; 00241 } 00242 break; 00243 00244 00245 case DIM_TEXT_CHANGED: 00246 // The user has typed in an edit field 00247 switch (Msg->GadgetID) 00248 { 00249 case _R(IDC_URLIMPORT_URL): 00250 if (URLImportDlg::DontHandleNextMessage) 00251 URLImportDlg::DontHandleNextMessage=FALSE; 00252 else 00253 OnURLChanged(); 00254 break; 00255 00256 } 00257 break; 00258 00259 } 00260 00261 //And end the dialog if necessary 00262 if (EndDialog) 00263 { 00264 Close(); 00265 End(); 00266 } 00267 } 00268 00269 //Now pass the message down to the base class 00270 return DialogOp::Message(Message); 00271 } 00272 00273 /******************************************************************************************** 00274 00275 URLImportDlg message handling functions 00276 00277 The following group of functions are called from URLImportDlg::Message 00278 when a message is received. 00279 00280 They call other functions which do whatever needs to be done. 00281 00282 ********************************************************************************************/ 00283 00284 00285 /******************************************************************************************** 00286 00287 void URLImportDlg::OnCreate() 00288 00289 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00290 Created: 10/4/97 00291 Inputs: - 00292 Outputs: - 00293 Returns: - 00294 00295 Purpose: Handles a message that the dialog has just been created. 00296 00297 Errors: - 00298 SeeAlso: URLImportDlg::Message() 00299 00300 ********************************************************************************************/ 00301 00302 void URLImportDlg::OnCreate() 00303 { 00304 //Put the keyboard focus in the edit field 00305 SetKeyboardFocus(_R(IDC_URLIMPORT_URL)); 00306 } 00307 00308 /******************************************************************************************** 00309 00310 void URLImportDlg::OnCommit() 00311 00312 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00313 Created: 10/4/97 00314 Inputs: - 00315 Outputs: - 00316 Returns: - 00317 00318 Purpose: Handles a message that the "Import" button has been clicked 00319 00320 Errors: - 00321 SeeAlso: URLImportDlg::Message() 00322 00323 ********************************************************************************************/ 00324 00325 void URLImportDlg::OnCommit() 00326 { 00327 //Get the string from the edit field 00328 String_256 strUser=GetStringGadgetValue(_R(IDC_URLIMPORT_URL)); 00329 00330 //Now we want to correct this string. To do this we 00331 //need to set up some correction flags 00332 WebCorrectFlags wcfToUse; 00333 wcfToUse.SetForURLImport(); 00334 00335 //Now make a Web Address object out of the string 00336 //This will correct the string appropriately 00337 WebAddress urlToFetch(strUser, wcfToUse); 00338 00339 //And set our member variable 00340 ms_url=urlToFetch; 00341 00342 00343 } 00344 00345 /******************************************************************************************** 00346 00347 void URLImportDlg::OnURLChanged() 00348 00349 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00350 Created: 10/4/97 00351 Inputs: - 00352 Outputs: - 00353 Returns: - 00354 00355 Purpose: Handles a message that the user has typed in the "URL" field 00356 00357 Errors: - 00358 SeeAlso: URLImportDlg::Message() 00359 00360 ********************************************************************************************/ 00361 00362 void URLImportDlg::OnURLChanged() 00363 { 00364 //Does nothing at present 00365 //We may need to handle this if we want the Import... button to be greyed 00366 //until the user types in the field 00367 } 00368 00369 00370 /****************************************************************************************** 00371 00372 > static OpState URLImportDlg::GetState(String_256*, OpDescriptor*) 00373 00374 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00375 Created: 10/4/97 00376 Inputs: - 00377 Outputs: - 00378 Returns: - 00379 Purpose: URLImportDlg GetState method 00380 Errors: - 00381 SeeAlso: - 00382 00383 ******************************************************************************************/ 00384 00385 OpState URLImportDlg::GetState(String_256*, OpDescriptor*) 00386 { 00387 OpState OpSt; 00388 return(OpSt); 00389 } 00390 00391 00392 00393 00394 /****************************************************************************************** 00395 00396 > BOOL URLImportDlg::Init() 00397 00398 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00399 Created: 10/4/97 00400 Inputs: - 00401 Outputs: - 00402 Returns: - 00403 Purpose: URLImportDlg Init method 00404 Errors: - 00405 SeeAlso: - 00406 00407 ******************************************************************************************/ 00408 00409 BOOL URLImportDlg::Init() 00410 { 00411 BOOL InitOK; 00412 00413 InitOK = RegisterOpDescriptor( 00414 0, /* Tool ID */ 00415 _R(IDS_URLIMPORT), 00416 CC_RUNTIME_CLASS(URLImportDlg), 00417 OPTOKEN_URLIMPORTDLG, 00418 GetState, 00419 _R(IDH_Command_Import_from_Web), /* help ID */ 00420 0, /* bubble help */ 00421 0, /* resource ID */ 00422 0 /* control ID */ 00423 ); 00424 00425 return (InitOK); 00426 } 00427 00428 00429 /****************************************************************************************** 00430 00431 > void URLImportDlg::Do(OpDescriptor*) 00432 00433 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00434 Created: 11/4/97 00435 Inputs: - 00436 Outputs: - 00437 Returns: - 00438 Purpose: Creates then opens the dialog in response to a request from the user. 00439 Errors: - 00440 SeeAlso: - 00441 00442 ******************************************************************************************/ 00443 00444 void URLImportDlg::Do(OpDescriptor*) 00445 { 00446 BOOL ok; 00447 00448 // Force the dialog box to be created, as it is modal it will be opened via a message 00449 ok = Create(); 00450 00451 if ( !ok ) 00452 { 00453 // Could not create the dialog box so call inform error 00454 InformError(); 00455 End(); 00456 } 00457 } 00458 00459 /****************************************************************************************** 00460 00461 > void URLImportDlg::DoWithParam(OpDescriptor*) 00462 00463 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00464 Created: 11/4/97 00465 Inputs: - 00466 Outputs: - 00467 Returns: - 00468 Purpose: Creates then opens the dialog in response to a request from the user and 00469 allows values to be passed in and returned to the caller via the 00470 URLImportDlgParam class. 00471 Errors: - 00472 SeeAlso: - 00473 00474 ******************************************************************************************/ 00475 00476 void URLImportDlg::DoWithParam(OpDescriptor*, OpParam* Param) 00477 { 00478 BOOL ok; 00479 00480 // Force the dialog box to be created, as it is modal it will be opened via a message 00481 ok = Create(); 00482 00483 if ( !ok ) 00484 { 00485 // Could not create the dialog box so call inform error 00486 InformError(); 00487 End(); // End the operation 00488 } 00489 }