Clone of Akilla's ac2d @ https://github.com/deregtd/AC2D

CWindow.cpp 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. #include "stdafx.h"
  2. #include "CWindow.h"
  3. CWindow::CWindow()
  4. {
  5. Top = 0;
  6. Left = 0;
  7. Width = 10000;
  8. Height = 10000;
  9. AnchorLeft = true;
  10. AnchorTop = true;
  11. AnchorRight = false;
  12. AnchorBottom = false;
  13. Visible = false;
  14. Updating = false;
  15. Parent = NULL;
  16. AddMoveEventHandler( *(MoveEventAbstractor< CWindow > *)this );
  17. AddResizeEventHandler( *(ResizeEventAbstractor< CWindow > *)this );
  18. AddMouseEventHandler( *(MouseEventsAbstractor< CWindow > *)this );
  19. AddKeyboardEventHandler( *(KeyboardEventsAbstractor< CWindow > *)this );
  20. AddRenderEventHandler( *(RenderEventAbstractor< CWindow > *)this );
  21. AddFocusEventHandler( *(FocusEventsAbstractor< CWindow > *)this );
  22. AddClipboardEventHandler( *(ClipboardEventsAbstractor< CWindow > *)this );
  23. return;
  24. }
  25. CWindow::~CWindow()
  26. {
  27. if (GetParent())
  28. GetParent()->RemoveChild(*this);
  29. return;
  30. }
  31. bool CWindow::AddMoveEventHandler( IMoveEvent &MoveEvents )
  32. {
  33. for( std::list< IMoveEvent * >::iterator I = MoveEventHandlers.begin(); I != MoveEventHandlers.end(); I++ )
  34. {
  35. if( *I == &MoveEvents )
  36. {
  37. return false;
  38. }
  39. }
  40. MoveEventHandlers.push_back( &MoveEvents );
  41. return true;
  42. }
  43. bool CWindow::AddResizeEventHandler( IResizeEvent &ResizeEvent )
  44. {
  45. for( std::list< IResizeEvent * >::iterator I = ResizeEventHandlers.begin(); I != ResizeEventHandlers.end(); I++ )
  46. {
  47. if( *I == &ResizeEvent )
  48. {
  49. return false;
  50. }
  51. }
  52. ResizeEventHandlers.push_back( &ResizeEvent );
  53. return true;
  54. }
  55. bool CWindow::AddMouseEventHandler( IMouseEvents &MouseEvents )
  56. {
  57. for( std::list< IMouseEvents * >::iterator I = MouseEventHandlers.begin(); I != MouseEventHandlers.end(); I++ )
  58. {
  59. if( *I == &MouseEvents )
  60. {
  61. return false;
  62. }
  63. }
  64. MouseEventHandlers.push_back( &MouseEvents );
  65. return true;
  66. }
  67. bool CWindow::AddKeyboardEventHandler( IKeyboardEvents &KeyboardEvents )
  68. {
  69. for( std::list< IKeyboardEvents * >::iterator I = KeyboardEventHandlers.begin(); I != KeyboardEventHandlers.end(); I++ )
  70. {
  71. if( *I == &KeyboardEvents )
  72. {
  73. return false;
  74. }
  75. }
  76. KeyboardEventHandlers.push_back( &KeyboardEvents );
  77. return true;
  78. }
  79. bool CWindow::AddRenderEventHandler( IRenderEvent &RenderEvent )
  80. {
  81. for( std::list< IRenderEvent * >::iterator I = RenderEventHandlers.begin(); I != RenderEventHandlers.end(); I++ )
  82. {
  83. if( *I == &RenderEvent )
  84. {
  85. return false;
  86. }
  87. }
  88. RenderEventHandlers.push_back( &RenderEvent );
  89. return true;
  90. }
  91. bool CWindow::AddFocusEventHandler( IFocusEvents &FocusEvents )
  92. {
  93. for( std::list< IFocusEvents * >::iterator I = FocusEventHandlers.begin(); I != FocusEventHandlers.end(); I++ )
  94. {
  95. if( *I == &FocusEvents )
  96. {
  97. return false;
  98. }
  99. }
  100. FocusEventHandlers.push_back( &FocusEvents );
  101. return true;
  102. }
  103. bool CWindow::AddClipboardEventHandler( IClipboardEvents &ClipboardEvents )
  104. {
  105. for( std::list< IClipboardEvents * >::iterator I = ClipboardEventHandlers.begin(); I != ClipboardEventHandlers.end(); I++ )
  106. {
  107. if( *I == &ClipboardEvents )
  108. {
  109. return false;
  110. }
  111. }
  112. ClipboardEventHandlers.push_back( &ClipboardEvents );
  113. return true;
  114. }
  115. bool CWindow::AddWindowEventHandler( IWindowEvents &WindowEvents )
  116. {
  117. for( std::list< IWindowEvents * >::iterator I = WindowEventHandlers.begin(); I != WindowEventHandlers.end(); I++ )
  118. {
  119. if( *I == &WindowEvents )
  120. {
  121. return false;
  122. }
  123. }
  124. WindowEventHandlers.push_back( &WindowEvents );
  125. return true;
  126. }
  127. bool CWindow::SetWidth( float NewWidth )
  128. {
  129. float LeftMargin = 0;
  130. float RightMargin = 0;
  131. bool AnchoredLeft = false;
  132. bool AnchoredRight = false;
  133. std::list< IWindow * >::iterator I;
  134. if( NewWidth < 0 )
  135. {
  136. return false;
  137. }
  138. if( FireResize( NewWidth, Height ) == true )
  139. {
  140. for( I = Children.begin(); I != Children.end(); I++ )
  141. {
  142. AnchoredLeft = (*I)->GetAnchorLeft();
  143. AnchoredRight = (*I)->GetAnchorRight();
  144. if( AnchoredLeft == true && AnchoredRight == false )
  145. {
  146. }
  147. else if( AnchoredLeft == false && AnchoredRight == true )
  148. {
  149. RightMargin = Width - (*I)->GetLeft() - (*I)->GetWidth();
  150. (*I)->SetLeft( NewWidth - RightMargin - (*I)->GetWidth() );
  151. }
  152. else if( AnchoredLeft == true && AnchoredRight == true )
  153. {
  154. LeftMargin = (*I)->GetLeft();
  155. RightMargin = Width - (*I)->GetLeft() - (*I)->GetWidth();
  156. if( NewWidth - LeftMargin - RightMargin > 0 )
  157. {
  158. (*I)->SetWidth( NewWidth - LeftMargin - RightMargin );
  159. }
  160. }
  161. else if( AnchoredLeft == false && AnchoredRight == false )
  162. {
  163. (*I)->SetLeft( (*I)->GetLeft() + ( NewWidth - Width ) / 2 );
  164. }
  165. }
  166. Width = NewWidth;
  167. FireResized();
  168. } else {
  169. return false;
  170. }
  171. return true;
  172. }
  173. bool CWindow::SetHeight( float NewHeight )
  174. {
  175. float TopMargin = 0;
  176. float BottomMargin = 0;
  177. bool AnchoredTop = false;
  178. bool AnchoredBottom = false;
  179. std::list< IWindow * >::iterator I;
  180. if( NewHeight < 0 )
  181. {
  182. return false;
  183. }
  184. if( FireResize( Width, NewHeight ) == true )
  185. {
  186. for( I = Children.begin(); I != Children.end(); I++ )
  187. {
  188. AnchoredTop = (*I)->GetAnchorTop();
  189. AnchoredBottom = (*I)->GetAnchorBottom();
  190. if( AnchoredTop == true && AnchoredBottom == false )
  191. {
  192. }
  193. else if( AnchoredTop == false && AnchoredBottom == true )
  194. {
  195. BottomMargin = Height - (*I)->GetTop() - (*I)->GetHeight();
  196. (*I)->SetTop( NewHeight - BottomMargin - (*I)->GetHeight() );
  197. }
  198. else if( AnchoredTop == true && AnchoredBottom == true )
  199. {
  200. TopMargin = (*I)->GetTop();
  201. BottomMargin = Height - (*I)->GetTop() - (*I)->GetHeight();
  202. if( NewHeight - TopMargin - BottomMargin > 0 )
  203. {
  204. (*I)->SetHeight( NewHeight - TopMargin - BottomMargin );
  205. }
  206. }
  207. else if( AnchoredTop == false && AnchoredBottom == false )
  208. {
  209. (*I)->SetTop( (*I)->GetTop() + ( NewHeight - Height ) / 2 );
  210. }
  211. }
  212. Height = NewHeight;
  213. FireResized();
  214. } else {
  215. return false;
  216. }
  217. return true;
  218. }
  219. bool CWindow::SetSize( float NewWidth, float NewHeight )
  220. {
  221. float LeftMargin = 0;
  222. float TopMargin = 0;
  223. float RightMargin = 0;
  224. float BottomMargin = 0;
  225. bool AnchoredLeft = false;
  226. bool AnchoredTop = false;
  227. bool AnchoredRight = false;
  228. bool AnchoredBottom = false;
  229. std::list< IWindow * >::iterator I;
  230. if( NewWidth < 0 || NewHeight < 0 )
  231. {
  232. return false;
  233. }
  234. if( FireResize( NewWidth, NewHeight ) == true )
  235. {
  236. for( I = Children.begin(); I != Children.end(); I++ )
  237. {
  238. AnchoredLeft = (*I)->GetAnchorLeft();
  239. AnchoredTop = (*I)->GetAnchorTop();
  240. AnchoredRight = (*I)->GetAnchorRight();
  241. AnchoredBottom = (*I)->GetAnchorBottom();
  242. //LEFT AND TOP ARE ANCHORED
  243. if( AnchoredLeft == true && AnchoredRight == false && AnchoredTop == true && AnchoredBottom == false )
  244. {
  245. }
  246. //LEFT, TOP, RIGHT AND BOTTOM ARE ANCHORED
  247. else if( AnchoredLeft == true && AnchoredRight == true && AnchoredTop == true && AnchoredBottom == true )
  248. {
  249. LeftMargin = (*I)->GetLeft();
  250. TopMargin = (*I)->GetTop();
  251. RightMargin = Width - (*I)->GetLeft() - (*I)->GetWidth();
  252. BottomMargin = Height - (*I)->GetTop() - (*I)->GetHeight();
  253. if( NewHeight - TopMargin - BottomMargin > 0 && NewWidth - LeftMargin - RightMargin > 0 )
  254. {
  255. (*I)->SetSize( NewWidth - LeftMargin - RightMargin, NewHeight - TopMargin - BottomMargin );
  256. }
  257. }
  258. //TOP AND RIGHT ARE ANCHORED
  259. else if( AnchoredLeft == false && AnchoredRight == true && AnchoredTop == true && AnchoredBottom == false )
  260. {
  261. RightMargin = Width - (*I)->GetLeft() - (*I)->GetWidth();
  262. (*I)->SetLeft( NewWidth - RightMargin - (*I)->GetWidth() );
  263. }
  264. //RIGHT AND BOTTOM ARE ANCHORED
  265. else if( AnchoredLeft == false && AnchoredRight == true && AnchoredTop == false && AnchoredBottom == true )
  266. {
  267. RightMargin = Width - (*I)->GetLeft() - (*I)->GetWidth();
  268. BottomMargin = Height - (*I)->GetTop() - (*I)->GetHeight();
  269. (*I)->SetPosition( NewWidth - RightMargin - (*I)->GetWidth(), NewHeight - BottomMargin - (*I)->GetHeight() );
  270. }
  271. //LEFT AND BOTTOM ARE ANCHORED
  272. else if( AnchoredLeft == true && AnchoredRight == false && AnchoredTop == false && AnchoredBottom == true )
  273. {
  274. BottomMargin = Height - (*I)->GetTop() - (*I)->GetHeight();
  275. (*I)->SetTop( NewHeight - BottomMargin - (*I)->GetHeight() );
  276. }
  277. //LEFT, TOP AND BOTTOM ARE ANCHORED
  278. else if( AnchoredLeft == true && AnchoredRight == false && AnchoredTop == true && AnchoredBottom == true )
  279. {
  280. TopMargin = (*I)->GetTop();
  281. BottomMargin = Height - (*I)->GetTop() - (*I)->GetHeight();
  282. if( NewHeight - TopMargin - BottomMargin > 0 )
  283. {
  284. (*I)->SetHeight( NewHeight - TopMargin - BottomMargin );
  285. }
  286. }
  287. //TOP, RIGHT AND BOTTOM ARE ANCHORED
  288. else if( AnchoredLeft == false && AnchoredRight == true && AnchoredTop == true && AnchoredBottom == true )
  289. {
  290. TopMargin = (*I)->GetTop();
  291. RightMargin = Width - (*I)->GetLeft() - (*I)->GetWidth();
  292. BottomMargin = Height - (*I)->GetTop() - (*I)->GetHeight();
  293. (*I)->SetLeft( NewWidth - RightMargin - (*I)->GetWidth() );
  294. if( NewHeight - TopMargin - BottomMargin > 0 )
  295. {
  296. (*I)->SetHeight( NewHeight - TopMargin - BottomMargin );
  297. }
  298. }
  299. //LEFT, TOP AND RIGHT ARE ANCHORED
  300. else if( AnchoredLeft == true && AnchoredRight == true && AnchoredTop == true && AnchoredBottom == false )
  301. {
  302. LeftMargin = (*I)->GetLeft();
  303. RightMargin = Width - (*I)->GetLeft() - (*I)->GetWidth();
  304. if( NewWidth - LeftMargin - RightMargin > 0 )
  305. {
  306. (*I)->SetWidth( NewWidth - LeftMargin - RightMargin );
  307. }
  308. }
  309. //LEFT, RIGHT AND BOTTOM ARE ANCHORED
  310. else if( AnchoredLeft == true && AnchoredRight == true && AnchoredTop == false && AnchoredBottom == true )
  311. {
  312. LeftMargin = (*I)->GetLeft();
  313. RightMargin = Width - (*I)->GetLeft() - (*I)->GetWidth();
  314. BottomMargin = Height - (*I)->GetTop() - (*I)->GetHeight();
  315. (*I)->SetTop( NewHeight - BottomMargin - (*I)->GetHeight() );
  316. if( NewWidth - LeftMargin - RightMargin > 0 )
  317. {
  318. (*I)->SetWidth( NewWidth - LeftMargin - RightMargin );
  319. }
  320. }
  321. //LEFT AND RIGHT ARE ANCHORED
  322. else if( AnchoredLeft == true && AnchoredRight == true && AnchoredTop == false && AnchoredBottom == false )
  323. {
  324. LeftMargin = (*I)->GetLeft();
  325. RightMargin = Width - (*I)->GetLeft() - (*I)->GetWidth();
  326. (*I)->SetTop( (*I)->GetTop() + ( NewHeight - Height ) / 2 );
  327. if( NewWidth - LeftMargin - RightMargin > 0 )
  328. {
  329. (*I)->SetWidth( NewWidth - LeftMargin - RightMargin );
  330. }
  331. }
  332. //TOP AND BOTTOM ARE ANCHORED
  333. else if( AnchoredLeft == false && AnchoredRight == false && AnchoredTop == true && AnchoredBottom == true )
  334. {
  335. TopMargin = (*I)->GetTop();
  336. BottomMargin = Height - (*I)->GetTop() - (*I)->GetHeight();
  337. (*I)->SetLeft( (*I)->GetLeft() + ( NewWidth - Width ) / 2 );
  338. if( NewHeight - TopMargin - BottomMargin > 0 )
  339. {
  340. (*I)->SetHeight( NewHeight - TopMargin - BottomMargin );
  341. }
  342. }
  343. //LEFT IS ANCHORED
  344. else if( AnchoredLeft == true && AnchoredRight == false && AnchoredTop == false && AnchoredBottom == false )
  345. {
  346. (*I)->SetTop( (*I)->GetTop() + ( NewHeight - Height ) / 2 );
  347. }
  348. //TOP IS ANCHORED
  349. else if( AnchoredLeft == false && AnchoredRight == false && AnchoredTop == true && AnchoredBottom == false )
  350. {
  351. (*I)->SetLeft( (*I)->GetLeft() + ( NewWidth - Width ) / 2 );
  352. }
  353. //RIGHT IS ANCHORED
  354. else if( AnchoredLeft == false && AnchoredRight == true && AnchoredTop == false && AnchoredBottom == false )
  355. {
  356. RightMargin = Width - (*I)->GetLeft() - (*I)->GetWidth();
  357. (*I)->SetPosition( NewWidth - RightMargin - (*I)->GetWidth(), (*I)->GetTop() + ( NewHeight - Height ) / 2 );
  358. }
  359. //BOTTOM IS ANCHORED
  360. else if( AnchoredLeft == false && AnchoredRight == false && AnchoredTop == false && AnchoredBottom == true )
  361. {
  362. BottomMargin = Height - (*I)->GetTop() - (*I)->GetHeight();
  363. (*I)->SetPosition( (*I)->GetLeft() + ( NewWidth - Width ) / 2, NewHeight - BottomMargin - (*I)->GetHeight() );
  364. }
  365. //NOTHING IS ANCHORED
  366. else if( AnchoredLeft == false && AnchoredRight == false && AnchoredTop == false && AnchoredBottom == false )
  367. {
  368. (*I)->SetPosition( (*I)->GetLeft() + ( NewWidth - Width ) / 2, (*I)->GetTop() + ( NewHeight - Height ) / 2 );
  369. }
  370. }
  371. Width = NewWidth;
  372. Height = NewHeight;
  373. FireResized();
  374. } else {
  375. return false;
  376. }
  377. return true;
  378. }
  379. bool CWindow::SetTop( float NewTop )
  380. {
  381. if( FireMove( Left, NewTop ) == true )
  382. {
  383. Top = NewTop;
  384. } else {
  385. return false;
  386. }
  387. return true;
  388. }
  389. bool CWindow::SetLeft( float NewLeft )
  390. {
  391. if( FireMove( NewLeft, Top ) == true )
  392. {
  393. Left = NewLeft;
  394. } else {
  395. return false;
  396. }
  397. return true;
  398. }
  399. bool CWindow::SetPosition( float NewLeft, float NewTop )
  400. {
  401. if( FireMove( NewLeft, NewTop ) == true )
  402. {
  403. Left = NewLeft;
  404. Top = NewTop;
  405. } else {
  406. return false;
  407. }
  408. return true;
  409. }
  410. float CWindow::GetLeft() const
  411. {
  412. return Left;
  413. }
  414. float CWindow::GetTop() const
  415. {
  416. return Top;
  417. }
  418. float CWindow::GetWidth() const
  419. {
  420. return Width;
  421. }
  422. float CWindow::GetHeight() const
  423. {
  424. return Height;
  425. }
  426. float CWindow::GetAbsoluteLeft() const
  427. {
  428. return Left + Parent->GetAbsoluteLeft();
  429. }
  430. float CWindow::GetAbsoluteTop() const
  431. {
  432. return Top + Parent->GetAbsoluteTop();
  433. }
  434. bool CWindow::SetAnchorTop( bool NewAnchorTop )
  435. {
  436. AnchorTop = NewAnchorTop;
  437. return true;
  438. }
  439. bool CWindow::SetAnchorLeft( bool NewAnchorLeft )
  440. {
  441. AnchorLeft = NewAnchorLeft;
  442. return true;
  443. }
  444. bool CWindow::SetAnchorBottom( bool NewAnchorBottom )
  445. {
  446. AnchorBottom = NewAnchorBottom;
  447. return true;
  448. }
  449. bool CWindow::SetAnchorRight( bool NewAnchorRight )
  450. {
  451. AnchorRight = NewAnchorRight;
  452. return true;
  453. }
  454. bool CWindow::GetAnchorTop() const
  455. {
  456. return AnchorTop;
  457. }
  458. bool CWindow::GetAnchorLeft() const
  459. {
  460. return AnchorLeft;
  461. }
  462. bool CWindow::GetAnchorBottom() const
  463. {
  464. return AnchorBottom;
  465. }
  466. bool CWindow::GetAnchorRight() const
  467. {
  468. return AnchorRight;
  469. }
  470. bool CWindow::SetVisible( bool NewVisible )
  471. {
  472. Visible = NewVisible;
  473. return true;
  474. }
  475. bool CWindow::GetVisible() const
  476. {
  477. return Visible;
  478. }
  479. bool CWindow::JumpToFront()
  480. {
  481. if( Parent == NULL )
  482. {
  483. return true;
  484. }
  485. try
  486. {
  487. IWindow *OldParent = Parent;
  488. Parent->RemoveChild( *this );
  489. OldParent->AddChild( *this, true );
  490. //Parent->GetChildren().remove( (IWindow *)this );
  491. //Parent->GetChildren().push_back( this );
  492. } catch( ... ) {
  493. return false;
  494. }
  495. return true;
  496. }
  497. bool CWindow::JumpToBack()
  498. {
  499. if( Parent == NULL )
  500. {
  501. return true;
  502. }
  503. try
  504. {
  505. IWindow *OldParent = Parent;
  506. Parent->RemoveChild( *this );
  507. OldParent->AddChild( *this );
  508. } catch( ... ) {
  509. return false;
  510. }
  511. return true;
  512. }
  513. bool CWindow::AddChild( IWindow &Child, bool AddToBack )
  514. {
  515. //THIS SHOULD BE CLEANED UP WHEN A CUSTOM LIST TAKES THE PLACE OF STD::LIST
  516. //ALSO, THIS UPDATING FLAG IS ASS, BUT I CAN'T THINK OF A BETTER FIX AT THE MOMENT
  517. if( &Child == this )
  518. {
  519. return false;
  520. }
  521. if( Updating == true )
  522. {
  523. return true;
  524. }
  525. Updating = true;
  526. if( Child.GetParent() != NULL )
  527. {
  528. Child.GetParent()->RemoveChild( Child );
  529. }
  530. try
  531. {
  532. if( AddToBack == false )
  533. {
  534. Children.push_front( &Child );
  535. }
  536. else
  537. {
  538. Children.push_back( &Child );
  539. }
  540. } catch( ... ) {
  541. Updating = false;
  542. return false;
  543. }
  544. Child.SetParent( this );
  545. Updating = false;
  546. return true;
  547. }
  548. bool CWindow::RemoveChild( IWindow &Child )
  549. {
  550. //THIS SHOULD BE CLEANED UP WHEN A CUSTOM LIST TAKES THE PLACE OF STD::LIST
  551. //ALSO, THIS UPDATING FLAG IS ASS, BUT I CAN'T THINK OF A BETTER FIX AT THE MOMENT
  552. if( Updating == true )
  553. {
  554. return true;
  555. }
  556. Updating = true;
  557. try
  558. {
  559. Children.remove( &Child );
  560. } catch( ... ) {
  561. Updating = false;
  562. return false;
  563. }
  564. Child.SetParent( NULL );
  565. Updating = false;
  566. return true;
  567. }
  568. bool CWindow::SetParent( IWindow *NewParent )
  569. {
  570. //THIS UPDATING FLAG IS ASS, BUT I CAN'T THINK OF A BETTER FIX AT THE MOMENT
  571. if( NewParent == this )
  572. {
  573. return false;
  574. }
  575. if( Updating == true )
  576. {
  577. return true;
  578. }
  579. Updating = true;
  580. if( Parent != NULL )
  581. {
  582. Parent->RemoveChild( *this );
  583. }
  584. Parent = NewParent;
  585. if( Parent != NULL )
  586. {
  587. Parent->AddChild( *this );
  588. }
  589. Updating = false;
  590. return true;
  591. }
  592. IWindow *CWindow::GetParent() const
  593. {
  594. return Parent;
  595. }
  596. const std::list< IWindow * > &CWindow::GetChildren() const
  597. {
  598. return Children;
  599. }
  600. bool CWindow::OnRender( IWindow & Window, double TimeSlice )
  601. {
  602. return false;
  603. }
  604. bool CWindow::OnResize( IWindow & Window, float NewWidth, float NewHeight )
  605. {
  606. return true;
  607. }
  608. bool CWindow::OnResized( IWindow & Window )
  609. {
  610. return false;
  611. }
  612. bool CWindow::OnMove( IWindow & Window, float NewLeft, float NewTop )
  613. {
  614. return true;
  615. }
  616. bool CWindow::OnClick( IWindow & Window, float X, float Y, unsigned long Button )
  617. {
  618. return false;
  619. }
  620. bool CWindow::OnDoubleClick( IWindow & Window, float X, float Y, unsigned long Button )
  621. {
  622. return false;
  623. }
  624. bool CWindow::OnMouseWheel( IWindow & Window, float X, float Y, unsigned long Button )
  625. {
  626. return false;
  627. }
  628. bool CWindow::OnMouseDown( IWindow & Window, float X, float Y, unsigned long Button )
  629. {
  630. return false;
  631. }
  632. bool CWindow::OnMouseUp( IWindow & Window, float X, float Y, unsigned long Button )
  633. {
  634. return false;
  635. }
  636. bool CWindow::OnMouseMove( IWindow & Window, float X, float Y, unsigned long Button )
  637. {
  638. return false;
  639. }
  640. bool CWindow::OnMouseEnter( IWindow & Window, float X, float Y, unsigned long Button )
  641. {
  642. return false;
  643. }
  644. bool CWindow::OnMouseExit( IWindow & Window, float X, float Y, unsigned long Button )
  645. {
  646. return false;
  647. }
  648. bool CWindow::OnKeyPress( IWindow & Window, unsigned long KeyCode )
  649. {
  650. return false;
  651. }
  652. bool CWindow::OnKeyDown( IWindow & Window, unsigned long KeyCode )
  653. {
  654. return false;
  655. }
  656. bool CWindow::OnKeyUp( IWindow & Window, unsigned long KeyCode )
  657. {
  658. return false;
  659. }
  660. bool CWindow::OnGotFocus( IWindow & Window, IWindow *FromWindow )
  661. {
  662. return false;
  663. }
  664. bool CWindow::OnLostFocus( IWindow & Window, IWindow *ToWindow )
  665. {
  666. return false;
  667. }
  668. bool CWindow::OnCut( IWindow & Window, IClipboard &Clipboard )
  669. {
  670. return false;
  671. }
  672. bool CWindow::OnCopy( IWindow & Window, IClipboard &Clipboard )
  673. {
  674. return false;
  675. }
  676. bool CWindow::OnPaste( IWindow & Window, const IClipboard &Clipboard )
  677. {
  678. return false;
  679. }
  680. bool CWindow::FireRender( double TimeSlice )
  681. {
  682. bool Temp = false;
  683. bool RetVal = false;
  684. for( std::list< IRenderEvent * >::iterator I = RenderEventHandlers.begin(); I != RenderEventHandlers.end(); I++ )
  685. {
  686. Temp = (*I)->OnRender( *this, TimeSlice );
  687. if( Temp == true )
  688. {
  689. RetVal = true;
  690. }
  691. }
  692. return RetVal;
  693. }
  694. bool CWindow::FireResize( float NewWidth, float NewHeight )
  695. {
  696. bool Temp = false;
  697. bool RetVal = false;
  698. for( std::list< IResizeEvent * >::iterator I = ResizeEventHandlers.begin(); I != ResizeEventHandlers.end(); I++ )
  699. {
  700. IResizeEvent * const foo = *I;
  701. Temp = (*I)->OnResize( *this, NewWidth, NewHeight );
  702. if( Temp == true )
  703. {
  704. RetVal = true;
  705. }
  706. }
  707. return RetVal;
  708. }
  709. bool CWindow::FireResized()
  710. {
  711. bool Temp = false;
  712. bool RetVal = false;
  713. for( std::list< IResizeEvent * >::iterator I = ResizeEventHandlers.begin(); I != ResizeEventHandlers.end(); I++ )
  714. {
  715. Temp = (*I)->OnResized( *this );
  716. if( Temp == true )
  717. {
  718. RetVal = true;
  719. }
  720. }
  721. return RetVal;
  722. }
  723. bool CWindow::FireMove( float NewLeft, float NewTop )
  724. {
  725. bool Temp = false;
  726. bool RetVal = false;
  727. for( std::list< IMoveEvent * >::iterator I = MoveEventHandlers.begin(); I != MoveEventHandlers.end(); I++ )
  728. {
  729. Temp = (*I)->OnMove( *this, NewLeft, NewTop );
  730. if( Temp == true )
  731. {
  732. RetVal = true;
  733. }
  734. }
  735. return RetVal;
  736. }
  737. bool CWindow::FireClick( float X, float Y, unsigned long Button )
  738. {
  739. bool Temp = false;
  740. bool RetVal = false;
  741. for( std::list< IMouseEvents * >::iterator I = MouseEventHandlers.begin(); I != MouseEventHandlers.end(); I++ )
  742. {
  743. Temp = (*I)->OnClick( *this, X, Y, Button );
  744. if( Temp == true )
  745. {
  746. RetVal = true;
  747. }
  748. }
  749. return RetVal;
  750. }
  751. bool CWindow::FireDoubleClick( float X, float Y, unsigned long Button )
  752. {
  753. bool Temp = false;
  754. bool RetVal = false;
  755. for( std::list< IMouseEvents * >::iterator I = MouseEventHandlers.begin(); I != MouseEventHandlers.end(); I++ )
  756. {
  757. Temp = (*I)->OnDoubleClick( *this, X, Y, Button );
  758. if( Temp == true )
  759. {
  760. RetVal = true;
  761. }
  762. }
  763. return RetVal;
  764. }
  765. bool CWindow::FireMouseWheel( float X, float Y, unsigned long Button )
  766. {
  767. bool Temp = false;
  768. bool RetVal = false;
  769. for( std::list< IMouseEvents * >::iterator I = MouseEventHandlers.begin(); I != MouseEventHandlers.end(); I++ )
  770. {
  771. Temp = (*I)->OnMouseWheel( *this, X, Y, Button );
  772. if( Temp == true )
  773. {
  774. RetVal = true;
  775. }
  776. }
  777. return RetVal;
  778. }
  779. bool CWindow::FireMouseDown( float X, float Y, unsigned long Button )
  780. {
  781. bool Temp = false;
  782. bool RetVal = false;
  783. for( std::list< IMouseEvents * >::iterator I = MouseEventHandlers.begin(); I != MouseEventHandlers.end(); I++ )
  784. {
  785. Temp = (*I)->OnMouseDown( *this, X, Y, Button );
  786. if( Temp == true )
  787. {
  788. RetVal = true;
  789. }
  790. }
  791. return RetVal;
  792. }
  793. bool CWindow::FireMouseUp( float X, float Y, unsigned long Button )
  794. {
  795. bool Temp = false;
  796. bool RetVal = false;
  797. for( std::list< IMouseEvents * >::iterator I = MouseEventHandlers.begin(); I != MouseEventHandlers.end(); I++ )
  798. {
  799. Temp = (*I)->OnMouseUp( *this, X, Y, Button );
  800. if( Temp == true )
  801. {
  802. RetVal = true;
  803. }
  804. }
  805. return RetVal;
  806. }
  807. bool CWindow::FireMouseMove( float X, float Y, unsigned long Button )
  808. {
  809. bool Temp = false;
  810. bool RetVal = false;
  811. for( std::list< IMouseEvents * >::iterator I = MouseEventHandlers.begin(); I != MouseEventHandlers.end(); I++ )
  812. {
  813. Temp = (*I)->OnMouseMove( *this, X, Y, Button );
  814. if( Temp == true )
  815. {
  816. RetVal = true;
  817. }
  818. }
  819. return RetVal;
  820. }
  821. bool CWindow::FireMouseEnter( float X, float Y, unsigned long Button )
  822. {
  823. bool Temp = false;
  824. bool RetVal = false;
  825. for( std::list< IMouseEvents * >::iterator I = MouseEventHandlers.begin(); I != MouseEventHandlers.end(); I++ )
  826. {
  827. Temp = (*I)->OnMouseEnter( *this, X, Y, Button );
  828. if( Temp == true )
  829. {
  830. RetVal = true;
  831. }
  832. }
  833. return RetVal;
  834. }
  835. bool CWindow::FireMouseExit( float X, float Y, unsigned long Button )
  836. {
  837. bool Temp = false;
  838. bool RetVal = false;
  839. for( std::list< IMouseEvents * >::iterator I = MouseEventHandlers.begin(); I != MouseEventHandlers.end(); I++ )
  840. {
  841. Temp = (*I)->OnMouseExit( *this, X, Y, Button );
  842. if( Temp == true )
  843. {
  844. RetVal = true;
  845. }
  846. }
  847. return RetVal;
  848. }
  849. bool CWindow::FireKeyPress( unsigned long KeyCode )
  850. {
  851. bool Temp = false;
  852. bool RetVal = false;
  853. for( std::list< IKeyboardEvents * >::iterator I = KeyboardEventHandlers.begin(); I != KeyboardEventHandlers.end(); I++ )
  854. {
  855. Temp = (*I)->OnKeyPress( *this, KeyCode );
  856. if( Temp == true )
  857. {
  858. RetVal = true;
  859. }
  860. }
  861. return RetVal;
  862. }
  863. bool CWindow::FireKeyDown( unsigned long KeyCode )
  864. {
  865. bool Temp = false;
  866. bool RetVal = false;
  867. for( std::list< IKeyboardEvents * >::iterator I = KeyboardEventHandlers.begin(); I != KeyboardEventHandlers.end(); I++ )
  868. {
  869. Temp = (*I)->OnKeyDown( *this, KeyCode );
  870. if( Temp == true )
  871. {
  872. RetVal = true;
  873. }
  874. }
  875. return RetVal;
  876. }
  877. bool CWindow::FireKeyUp( unsigned long KeyCode )
  878. {
  879. bool Temp = false;
  880. bool RetVal = false;
  881. for( std::list< IKeyboardEvents * >::iterator I = KeyboardEventHandlers.begin(); I != KeyboardEventHandlers.end(); I++ )
  882. {
  883. Temp = (*I)->OnKeyUp( *this, KeyCode );
  884. if( Temp == true )
  885. {
  886. RetVal = true;
  887. }
  888. }
  889. return RetVal;
  890. }
  891. bool CWindow::FireGotFocus( IWindow *FromWindow )
  892. {
  893. bool Temp = false;
  894. bool RetVal = false;
  895. for( std::list< IFocusEvents * >::iterator I = FocusEventHandlers.begin(); I != FocusEventHandlers.end(); I++ )
  896. {
  897. Temp = (*I)->OnGotFocus( *this, FromWindow );
  898. if( Temp == true )
  899. {
  900. RetVal = true;
  901. }
  902. }
  903. return RetVal;
  904. }
  905. bool CWindow::FireLostFocus( IWindow *ToWindow )
  906. {
  907. bool Temp = false;
  908. bool RetVal = false;
  909. for( std::list< IFocusEvents * >::iterator I = FocusEventHandlers.begin(); I != FocusEventHandlers.end(); I++ )
  910. {
  911. Temp = (*I)->OnLostFocus( *this, ToWindow );
  912. if( Temp == true )
  913. {
  914. RetVal = true;
  915. }
  916. }
  917. return RetVal;
  918. }
  919. bool CWindow::FireCut( IClipboard &Clipboard )
  920. {
  921. bool Temp = false;
  922. bool RetVal = false;
  923. for( std::list< IClipboardEvents * >::iterator I = ClipboardEventHandlers.begin(); I != ClipboardEventHandlers.end(); I++ )
  924. {
  925. Temp = (*I)->OnCut( *this, Clipboard );
  926. if( Temp == true )
  927. {
  928. RetVal = true;
  929. }
  930. }
  931. return RetVal;
  932. }
  933. bool CWindow::FireCopy( IClipboard &Clipboard )
  934. {
  935. bool Temp = false;
  936. bool RetVal = false;
  937. for( std::list< IClipboardEvents * >::iterator I = ClipboardEventHandlers.begin(); I != ClipboardEventHandlers.end(); I++ )
  938. {
  939. Temp = (*I)->OnCopy( *this, Clipboard );
  940. if( Temp == true )
  941. {
  942. RetVal = true;
  943. }
  944. }
  945. return RetVal;
  946. }
  947. bool CWindow::FirePaste( const IClipboard &Clipboard )
  948. {
  949. bool Temp = false;
  950. bool RetVal = false;
  951. for( std::list< IClipboardEvents * >::iterator I = ClipboardEventHandlers.begin(); I != ClipboardEventHandlers.end(); I++ )
  952. {
  953. Temp = (*I)->OnPaste( *this, Clipboard );
  954. if( Temp == true )
  955. {
  956. RetVal = true;
  957. }
  958. }
  959. return RetVal;
  960. }