00001 // $Id: gadget.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 #include "camtypes.h" 00102 //#include "dialogop.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00103 #include "gadget.h" 00104 00105 00106 // Place any IMPLEMENT type statements here 00107 CC_IMPLEMENT_MEMDUMP(CCCoreUI, CC_CLASS_MEMDUMP); 00108 CC_IMPLEMENT_MEMDUMP(Gadget, CCCoreUI); 00109 CC_IMPLEMENT_MEMDUMP(NotifyingGadget, Gadget); 00110 CC_IMPLEMENT_MEMDUMP(DialogMgrGadget, NotifyingGadget); 00111 CC_IMPLEMENT_MEMDUMP(Button, DialogMgrGadget); 00112 CC_IMPLEMENT_MEMDUMP(ListControl, DialogMgrGadget); 00113 CC_IMPLEMENT_MEMDUMP(TextControl, DialogMgrGadget); 00114 CC_IMPLEMENT_MEMDUMP(StaticTextControl, DialogMgrGadget); 00115 00116 00117 // We want better memory tracking 00118 // Declare smart memory handling in Debug builds 00119 #define new CAM_DEBUG_NEW 00120 00121 00122 // Functions follow 00123 00124 00125 /******************************************************************************************* 00126 00127 > Button::Button( DialogOp* const pDialog, CGadgetID ControlID, 00128 Notifiable* pNotify = &Nobody ) 00129 00130 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00131 Created: 09/06/97 00132 00133 Purpose: Default destructor for a Button. Does nothing 00134 00135 00136 *******************************************************************************************/ 00137 Button::Button( DialogOp* const pDialog, CGadgetID ControlID, Notifiable* const pNotify): 00138 DialogMgrGadget(pDialog, ControlID), m_pNotifyOnPress(pNotify) 00139 { 00140 } 00141 00142 00143 /******************************************************************************************* 00144 00145 > Button::~Button() 00146 00147 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00148 Created: 09/06/97 00149 00150 Purpose: Default destructor for a Button. Does nothing 00151 00152 00153 *******************************************************************************************/ 00154 Button::~Button() 00155 { 00156 } 00157 00158 00159 /******************************************************************************************* 00160 00161 > void Button::OnClicked() 00162 00163 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00164 Created: 09/06/97 00165 00166 Purpose: Notifies the Notifiable that this Button has been clicked 00167 00168 00169 *******************************************************************************************/ 00170 void Button::OnClicked() 00171 { 00172 Notify(m_pNotifyOnPress); 00173 } 00174 00175 00176 /******************************************************************************************* 00177 00178 > TextControl::TextControl( DialogOp* const pDialog, CGadgetID ControlID, 00179 const StringBase& InitialText = EmptyString, 00180 Notifiable* const pTell = &Nobody ) 00181 00182 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00183 Created: 09/06/97 00184 00185 Purpose: Default constructor for a TextControl 00186 00187 *******************************************************************************************/ 00188 TextControl::TextControl( DialogOp* const pDialog, CGadgetID ControlID, 00189 const StringBase& InitialText, 00190 Notifiable* const pTell ) : 00191 DialogMgrGadget(pDialog, ControlID), 00192 m_pObserver(pTell) 00193 { 00194 // The SetWindowText sends an EN_CHANGE, which calls OnChange, which 00195 // notifies the Text_control, which updates the String, which notifies 00196 // the Text_control, which updates the window text, and around and 00197 // and around. Solve the problem in the OnChange() function, but set 00198 // "initializing" true to tell OnChange what's going on. Turn off 00199 // notification to prevent this. 00200 // 00201 // I'm assuming synchronous behavior; I don't expect SentWindowText 00202 // to return until AFTER the EnChange() handler has been executed. 00203 // If this turns out not to be the case in the future, you'll have 00204 // to modify this code: add an "initializing" field to the class, 00205 // set it true instead of calling notify_off, set it false instead 00206 // of calling notify_on, and modify OnChange to not notify anybody 00207 // if "initializing" is true. 00208 00209 00210 if (!InitialText.IsEmpty()) 00211 { 00212 NotifyOff(); 00213 pDialog->SetStringGadgetValue(m_ControlID, InitialText); 00214 NotifyOn(); 00215 } 00216 } 00217 00218 00219 const TextControl& TextControl::operator=(const TextControl& OtherControl) 00220 { 00221 ERROR3("TextControl assignment not implemented\n"); 00222 00223 return *this; 00224 } 00225 00226 TextControl::TextControl(const TextControl& OtherControl) : 00227 DialogMgrGadget(NULL, 0) 00228 { 00229 ERROR3("TextControl copy constructor not implemented\n"); 00230 } 00231 00232 00233 /******************************************************************************************* 00234 00235 > void TextControl::UpdateText(const StringBase &NewString) 00236 00237 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00238 Created: 09/06/97 00239 00240 Purpose: Default destructor for a TextControl 00241 00242 Input: NewString : the string to set in the text control 00243 00244 *******************************************************************************************/ 00245 void TextControl::UpdateText(const StringBase &NewString) 00246 { 00247 ASSERT(m_ControlID != 0 && m_pDialog != NULL); 00248 00249 m_pDialog->SetStringGadgetValue(m_ControlID, NewString); 00250 Notify(m_pObserver); 00251 } 00252 00253 00254 /******************************************************************************************* 00255 00256 > void TextControl::RetrieveText(String* pDisplayedString) const 00257 00258 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00259 Created: 09/06/97 00260 00261 Purpose: Default destructor for a TextControl 00262 00263 Outputs: pDisplayedString : the string to set in the text control 00264 00265 *******************************************************************************************/ 00266 void TextControl::RetrieveText(StringBase* const pDisplayedString) const 00267 { 00268 ASSERT(m_ControlID != 0 && m_pDialog != NULL); 00269 00270 if (pDisplayedString != NULL) 00271 { 00272 *pDisplayedString = m_pDialog->GetStringGadgetValue(m_ControlID); 00273 } 00274 } 00275 00276 00277 /******************************************************************************************* 00278 00279 > void TextControl::OnChange() 00280 00281 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00282 Created: 09/06/97 00283 00284 Purpose: Default destructor for a TextControl 00285 00286 Outputs: pDisplayedString : the string to set in the text control 00287 00288 *******************************************************************************************/ 00289 void TextControl::OnChange() 00290 { 00291 Notify(m_pObserver); 00292 } 00293 00294 00295 00296 00297 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 00298 // StaticTextControl 00299 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 00300 00301 00302 00303 00304 /******************************************************************************************* 00305 00306 > StaticTextControl::StaticTextControl( DialogOp* const pDialog, CGadgetID ControlID, 00307 const StringBase& InitialText = EmptyString, 00308 Notifiable* const pTell = &Nobody ) 00309 00310 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00311 Created: 09/06/97 00312 00313 Purpose: Default constructor for a TextControl 00314 00315 *******************************************************************************************/ 00316 StaticTextControl::StaticTextControl( DialogOp* const pDialog, CGadgetID ControlID, 00317 const StringBase& InitialText, 00318 Notifiable* const pTell ) : 00319 DialogMgrGadget(pDialog, ControlID), 00320 m_pObserver(pTell) 00321 { 00322 if (!InitialText.IsEmpty()) 00323 { 00324 pDialog->SetStringGadgetValue(m_ControlID, InitialText); 00325 } 00326 } 00327 00328 00329 /******************************************************************************************* 00330 00331 > void StaticTextControl::UpdateText(const StringBase &NewString) 00332 00333 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00334 Created: 09/06/97 00335 00336 Purpose: Sets the text in this control 00337 00338 Input: NewString : the string to set in the static control (label) 00339 00340 *******************************************************************************************/ 00341 void StaticTextControl::UpdateText(const StringBase &NewString) 00342 { 00343 ASSERT(m_ControlID != 0 && m_pDialog != NULL); 00344 00345 m_pDialog->SetStringGadgetValue(m_ControlID, NewString); 00346 Notify(m_pObserver); 00347 } 00348 00349 00350 /******************************************************************************************* 00351 00352 > void StaticTextControl::RetrieveText(String* pDisplayedString) const 00353 00354 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00355 Created: 09/06/97 00356 00357 Purpose: Gets the text currently displayed in this StaticTextControl 00358 00359 Outputs: pDisplayedString : the string to set in the text control 00360 00361 *******************************************************************************************/ 00362 void StaticTextControl::RetrieveText(StringBase* const pDisplayedString) const 00363 { 00364 ASSERT(m_ControlID != 0 && m_pDialog != NULL); 00365 00366 if (pDisplayedString != NULL) 00367 { 00368 *pDisplayedString = m_pDialog->GetStringGadgetValue(m_ControlID); 00369 } 00370 } 00371 00372 00373 /******************************************************************************************* 00374 00375 > void StaticTextControl::OnChange() 00376 00377 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00378 Created: 09/06/97 00379 00380 Purpose: Don't use this (yet!) 00381 00382 *******************************************************************************************/ 00383 inline void StaticTextControl::OnChange() 00384 { 00385 Notify(m_pObserver); 00386 } 00387 00388 00389 const StaticTextControl& StaticTextControl::operator=(const StaticTextControl& OtherControl) 00390 { 00391 ERROR3("StaticTextControl assignment not implemented\n"); 00392 00393 return *this; 00394 } 00395 00396 StaticTextControl::StaticTextControl(const StaticTextControl& OtherControl) : 00397 DialogMgrGadget(NULL, 0) 00398 { 00399 ERROR3("StaticTextControl copy constructor not implemented\n"); 00400 } 00401