00001 // $Id: namedlg.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 */ 00101 00102 #include "camtypes.h" 00103 //#include "dialogop.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00104 #include "namedlg.h" 00105 00106 //#include "tmpltres.h" 00107 #include "xshelpid.h" 00108 00109 00110 DECLARE_SOURCE("$Revision: 1282 $"); 00111 00112 CC_IMPLEMENT_MEMDUMP(NameDialogParam, OpParam); 00113 CC_IMPLEMENT_DYNCREATE(NameDialog, DialogOp) 00114 00115 // Give this file in memory dumps 00116 #define new CAM_DEBUG_NEW 00117 00118 00119 #define ENSURE_NOT_NULL(Pointer) ERROR2IF(Pointer == NULL, 0, "NULL Args") 00120 #ifndef VOID_ENSURE_NOT_NULL 00121 #define VOID_ENSURE_NOT_NULL(p) if (p == NULL) { ERROR2RAW("NULL Args") } 00122 #endif 00123 #define ENSURE_KIND(pNode, Kind) ERROR3IF(!pNode->IS_KIND_OF(Kind), "pNode is not kind of " #Kind); 00124 00125 00126 00127 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 00128 // N A M E D I A L O G P A R A M 00129 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 00130 00131 00132 00133 00134 00135 00136 00137 /******************************************************************************************** 00138 00139 > BOOL NameDialogParam::SetNameGiven(const StringBase& StringEntered) 00140 00141 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from MarkN) 00142 Created: 13/07/97 00143 00144 Purpose: Data access 00145 Returns: TRUE if the whole string were copied, FALSE if not 00146 00147 ********************************************************************************************/ 00148 BOOL NameDialogParam::SetNameGiven(const StringBase& StringEntered) 00149 { 00150 BOOL AllCopied = TRUE; // return this 00151 00152 UINT32 LengthToCopy = 0; 00153 if (StringEntered.Length() <= m_StringEntered.MaxLength()) 00154 { 00155 LengthToCopy = StringEntered.Length(); 00156 } 00157 else 00158 { 00159 AllCopied = FALSE; 00160 LengthToCopy = m_StringEntered.MaxLength(); 00161 } 00162 00163 StringEntered.Left(&m_StringEntered, LengthToCopy); 00164 00165 return AllCopied; 00166 } 00167 00168 00169 00170 00171 00172 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 00173 // N A M E D I A L O G 00174 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 00175 00176 00177 00178 00179 00180 const CDlgMode NameDialog::Mode = MODAL; // The dialog is modal 00181 const INT32 NameDialog::IDD = _R(IDD_NAME); 00182 00183 00184 /******************************************************************************************** 00185 00186 > static BOOL NameDialog::Init() 00187 00188 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from MarkN) 00189 Created: 13/07/97 00190 00191 Purpose: Declares a NameDialog 00192 00193 ********************************************************************************************/ 00194 BOOL NameDialog::Init() 00195 { 00196 return (RegisterOpDescriptor( 00197 0, 00198 _R(IDS_STYLENAMEDLG), 00199 CC_RUNTIME_CLASS(NameDialog), 00200 OPTOKEN_NAMEDLG, 00201 NameDialog::GetState, 00202 0, //_R(IDH_Command_Wizard_Properties), // help ID 00203 0 // bubble ID 00204 ) 00205 ); 00206 } 00207 00208 00209 /******************************************************************************************** 00210 00211 > static BOOL NameDialog::Invoke(NameDialogParam& NameParam) 00212 00213 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from MarkN) 00214 Created: 13/07/97 00215 00216 Purpose: Pops up a name dialog without you having to type in all that OpDescriptor 00217 hoo haa 00218 00219 Inputs: NameParam: A NameDialogParam containing any name you want to appear in the 00220 dialog when it starts up. 00221 Outputs: NameParam: The NameDialogParam containing any name typed into the dialog. 00222 00223 Returns: TRUE if the entry was okayed, FALSE if cancelled. 00224 00225 ********************************************************************************************/ 00226 BOOL NameDialog::Invoke(NameDialogParam& NameParam) 00227 { 00228 OpDescriptor* const pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_NAMEDLG); 00229 if (pOpDesc != NULL) 00230 { 00231 pOpDesc->Invoke(&NameParam); 00232 } 00233 else 00234 { 00235 ERROR3("Couldn't find OPTOKEN_NAMEDLG op descriptor"); 00236 } 00237 00238 return !NameParam.DialogCancelled(); 00239 } 00240 00241 00242 /******************************************************************************************** 00243 00244 > static OpState NameDialog::GetState(String_256*, OpDescriptor*) 00245 00246 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from MarkN) 00247 Created: 13/07/97 00248 00249 Purpose: See DialogOp 00250 00251 ********************************************************************************************/ 00252 OpState NameDialog::GetState(String_256*, OpDescriptor*) 00253 { 00254 OpState OpSt; 00255 00256 return(OpSt); 00257 } 00258 00259 00260 00261 /******************************************************************************************** 00262 00263 > NameDialog::NameDialog(): DialogOp(NameDialog::IDD, NameDialog::Mode) 00264 00265 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from MarkN) 00266 Created: 13/07/97 00267 00268 Purpose: NameDialog constructor. Creates a non-undoable operation 00269 00270 ********************************************************************************************/ 00271 NameDialog::NameDialog(): DialogOp(NameDialog::IDD, NameDialog::Mode) 00272 { 00273 m_pNameParam = NULL; 00274 } 00275 00276 00277 /******************************************************************************************** 00278 00279 > virtual void NameDialog::DoWithParam(OpDescriptor* ,OpParam* pOpParam) 00280 00281 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from MarkN) 00282 Created: 13/07/97 00283 00284 Purpose: Opens a dialog with the name given in pOpParam 00285 00286 Inputs: pOpParam : a NameDialogParam, containing any suggested name 00287 Outputs: pOpParam : the NameDialogParam contains 00288 00289 ********************************************************************************************/ 00290 void NameDialog::DoWithParam(OpDescriptor*, OpParam* pOpParam) 00291 { 00292 VOID_ENSURE_NOT_NULL(pOpParam); 00293 ENSURE_KIND(pOpParam, NameDialogParam); 00294 00295 SetNameParam(*(NameDialogParam*)pOpParam); 00296 00297 BOOL ok = Create(); 00298 00299 if (!ok) // Could not create 00300 { 00301 End(); // End the operation 00302 } 00303 } 00304 00305 00306 /******************************************************************************************** 00307 00308 > MsgResult NameDialog::Message(Msg* Message) 00309 00310 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from MarkN) 00311 Created: 13/07/97 00312 00313 Purpose: See DialogOp 00314 00315 ********************************************************************************************/ 00316 MsgResult NameDialog::Message(Msg* Message) 00317 { 00318 if (IS_OUR_DIALOG_MSG(Message)) 00319 { 00320 DialogMsg* pMsg = (DialogMsg*)Message; 00321 BOOL EndDialog = FALSE; 00322 switch (pMsg->DlgMsg) 00323 { 00324 case DIM_CREATE: 00325 OnCreate(); 00326 break; 00327 00328 case DIM_COMMIT: 00329 OnCommit(); 00330 EndDialog = TRUE; 00331 break; 00332 00333 case DIM_CANCEL: 00334 OnCancel(); 00335 EndDialog = TRUE; 00336 break; 00337 } 00338 00339 if (EndDialog) 00340 { 00341 Close(); // Close the dialog 00342 End(); // Destroy dialog - BEWARE! delete's this 00343 } 00344 00345 } 00346 00347 // Pass everything on to the base class . . . 00348 return DialogOp::Message(Message); 00349 } 00350 00351 00352 00353 00354 00355 /******************************************************************************************** 00356 00357 > void NameDialog::OnCreate() 00358 00359 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from MarkN) 00360 Created: 13/07/97 00361 00362 Purpose: Responds to a DIM_CREATE message by initializing the dialog control. 00363 It sets the name control with the string passed in the NameDialogParam via 00364 the DoWithParam() member 00365 00366 ********************************************************************************************/ 00367 void NameDialog::OnCreate() 00368 { 00369 String_256 Name = GetName(); 00370 00371 BOOL Ok = SetStringGadgetValue(_R(IDC_NAME_NAME),&Name); 00372 00373 if (Ok) 00374 { 00375 SetKeyboardFocus(_R(IDC_NAME_NAME)); 00376 HighlightText(_R(IDC_NAME_NAME)); 00377 } 00378 } 00379 00380 00381 /******************************************************************************************** 00382 00383 > virtual void NameDialog::OnCommit() 00384 00385 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from MarkN) 00386 Created: 13/07/97 00387 00388 Purpose: Takes the string from the dialog and puts it in the NameDialogParam given in 00389 DoWithParam() 00390 00391 ********************************************************************************************/ 00392 void NameDialog::OnCommit() 00393 { 00394 BOOL Valid = TRUE; 00395 00396 String_256 NewName; 00397 00398 // Get the string from the layer name dialog 00399 NewName = GetStringGadgetValue(_R(IDC_NAME_NAME), &Valid); 00400 00401 if (Valid) 00402 { 00403 Valid = SetName(NewName); 00404 } 00405 } 00406 00407 00408 00409 /******************************************************************************************** 00410 00411 > virtual void NameDialog::OnCancel() 00412 00413 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from MarkN) 00414 Created: 13/07/97 00415 00416 Purpose: Responds to a DIM_CANCEL message, by setting ??????????????????? 00417 in the NameDialogParam. 00418 00419 ********************************************************************************************/ 00420 void NameDialog::OnCancel() 00421 { 00422 SetCancelled(); 00423 } 00424 00425 00426 /******************************************************************************************** 00427 00428 > void NameDialog::SetNameParam(NameDialogParam& NameParam) 00429 00430 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from MarkN) 00431 Created: 13/07/97 00432 00433 Purpose: Data access 00434 00435 ********************************************************************************************/ 00436 void NameDialog::SetNameParam(NameDialogParam& NameParam) 00437 { 00438 m_pNameParam = &NameParam; 00439 } 00440 00441 00442 BOOL NameDialog::SetName(const StringBase& StringEntered) 00443 { 00444 ENSURE_NOT_NULL(m_pNameParam); 00445 00446 return m_pNameParam->SetNameGiven(StringEntered); 00447 } 00448 00449 00450 const StringBase& NameDialog::GetName() const 00451 { 00452 ERROR2IF(m_pNameParam == NULL, NullString, "NULL Member"); 00453 00454 return m_pNameParam->GetNameEntered(); 00455 } 00456 00457 00458 BOOL NameDialog::SetCancelled() 00459 { 00460 ENSURE_NOT_NULL(m_pNameParam); 00461 00462 m_pNameParam->SetDialogCancelled(); 00463 00464 return TRUE; 00465 } 00466