GEInsertModifier.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "../../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "GEApp.h"
  23. #include "GEInsertModifier.h"
  24. rvGEInsertModifier::rvGEInsertModifier ( const char* name, idWindow* window, idWindow* parent, idWindow* before ) :
  25. rvGEModifier ( name, window )
  26. {
  27. mParent = parent;
  28. mBefore = before;
  29. assert ( mParent );
  30. mUndoParent = window->GetParent ( );
  31. mUndoBefore = NULL;
  32. mUndoRect = mWrapper->GetClientRect ( );
  33. mRect = mWrapper->GetClientRect ( );
  34. // Find the child window the window being inserted is before
  35. if ( mUndoParent )
  36. {
  37. int index;
  38. rvGEWindowWrapper* pwrapper;
  39. pwrapper = rvGEWindowWrapper::GetWrapper ( mUndoParent );
  40. index = mUndoParent->GetChildIndex ( mWindow );
  41. if ( index + 1 < pwrapper->GetChildCount ( ) )
  42. {
  43. mUndoBefore = pwrapper->GetChild ( index + 1 );
  44. }
  45. }
  46. // Since rectangles are relative to the parent rectangle we need to figure
  47. // out the new x and y coordinate as if this window were a child
  48. rvGEWindowWrapper* parentWrapper;
  49. parentWrapper = rvGEWindowWrapper::GetWrapper ( mParent );
  50. mRect.x = mWrapper->GetScreenRect( )[0] - parentWrapper->GetScreenRect()[0];
  51. mRect.y = mWrapper->GetScreenRect( )[1] - parentWrapper->GetScreenRect()[1];
  52. }
  53. /*
  54. ================
  55. rvGEInsertModifier::Apply
  56. Apply the insert modifier by removing the child from its original parent and
  57. inserting it as a child of the new parent
  58. ================
  59. */
  60. bool rvGEInsertModifier::Apply ( void )
  61. {
  62. if ( mUndoParent )
  63. {
  64. mUndoParent->RemoveChild ( mWindow );
  65. }
  66. mParent->InsertChild ( mWindow, mBefore );
  67. mWrapper->SetRect ( mRect );
  68. return true;
  69. }
  70. /*
  71. ================
  72. rvGEInsertModifier::Undo
  73. Undo the insert modifier by removing the window from the parent it was
  74. added to and re-inserting it back into its original parent
  75. ================
  76. */
  77. bool rvGEInsertModifier::Undo ( void )
  78. {
  79. mParent->RemoveChild ( mWindow );
  80. if ( mUndoParent )
  81. {
  82. mUndoParent->InsertChild ( mWindow, mUndoBefore );
  83. mWrapper->SetRect ( mUndoRect );
  84. }
  85. return true;
  86. }