xref: /trunk/main/dbaccess/source/ui/querydesign/QueryTabWinUndoAct.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 #ifndef DBAUI_OQueryTabWinUndoAct_HXX
31 #include "QueryTabWinUndoAct.hxx"
32 #endif
33 #ifndef _OSL_DIAGNOSE_H_
34 #include <osl/diagnose.h>
35 #endif
36 #ifndef DBAUI_QUERY_TABLEWINDOW_HXX
37 #include "QTableWindow.hxx"
38 #endif
39 #ifndef DBAUI_QUERY_TABLEWINDOWDATA_HXX
40 #include "QTableWindowData.hxx"
41 #endif
42 #ifndef DBAUI_TABLECONNECTION_HXX
43 #include "TableConnection.hxx"
44 #endif
45 #ifndef DBAUI_TABLECONNECTIONDATA_HXX
46 #include "TableConnectionData.hxx"
47 #endif
48 #ifndef DBAUI_QUERYDESIGNFIELDUNDOACT_HXX
49 #include "QueryDesignFieldUndoAct.hxx"
50 #endif
51 #ifndef DBAUI_QUERYTABLEVIEW_HXX
52 #include "QueryTableView.hxx"
53 #endif
54 
55 
56 using namespace dbaui;
57 DBG_NAME(OQueryDesignFieldUndoAct)
58 OQueryDesignFieldUndoAct::OQueryDesignFieldUndoAct(OSelectionBrowseBox* pSelBrwBox, sal_uInt16 nCommentID)
59     : OCommentUndoAction(nCommentID)
60     , pOwner(pSelBrwBox)
61     , m_nColumnPostion(BROWSER_INVALIDID)
62 {
63     DBG_CTOR(OQueryDesignFieldUndoAct,NULL);
64 }
65 // -----------------------------------------------------------------------------
66 OQueryDesignFieldUndoAct::~OQueryDesignFieldUndoAct()
67 {
68     DBG_DTOR(OQueryDesignFieldUndoAct,NULL);
69     pOwner = NULL;
70 }
71 // -----------------------------------------------------------------------------
72 
73 DBG_NAME(OQueryTabWinUndoAct )
74 // ------------------------------------------------------------------------------------------------
75 OQueryTabWinUndoAct::OQueryTabWinUndoAct(OQueryTableView* pOwner, sal_uInt16 nCommentID)
76     :OQueryDesignUndoAction(pOwner, nCommentID)
77     ,m_pTabWin(NULL)
78 {
79     DBG_CTOR(OQueryTabWinUndoAct ,NULL);
80 }
81 //==============================================================================
82 OQueryTabWinUndoAct::~OQueryTabWinUndoAct()
83 {
84     DBG_DTOR(OQueryTabWinUndoAct ,NULL);
85     if (m_bOwnerOfObjects)
86     {   // wenn ich der alleinige Owner des Fenster bin, muss ich dafuer sorgen, dass es geloescht wird
87         OSL_ENSURE(m_pTabWin != NULL, "OQueryTabWinUndoAct::~OQueryTabWinUndoAct() : m_pTabWin sollte nicht NULL sein");
88         OSL_ENSURE(!m_pTabWin->IsVisible(), "OQueryTabWinUndoAct::~OQueryTabWinUndoAct() : *m_pTabWin sollte nicht sichtbar sein");
89 
90         if ( m_pTabWin )
91             m_pTabWin->clearListBox();
92         delete m_pTabWin;
93 
94         // und natuerlich auch die entsprechenden Connections
95         ::std::vector<OTableConnection*>::iterator aIter = m_vTableConnection.begin();
96         ::std::vector<OTableConnection*>::iterator aEnd = m_vTableConnection.end();
97         for(;aIter != aEnd;++aIter)
98         {
99             m_pOwner->DeselectConn(*aIter);
100             delete (*aIter);
101         }
102         m_vTableConnection.clear();
103     }
104 }
105 //------------------------------------------------------------------------------
106 void OTabFieldCellModifiedUndoAct::Undo()
107 {
108     pOwner->EnterUndoMode();
109     OSL_ENSURE(m_nColumnPostion != BROWSER_INVALIDID,"Column position was not set add the undo action!");
110     OSL_ENSURE(m_nColumnPostion < pOwner->GetColumnCount(),"Position outside the column count!");
111     if ( m_nColumnPostion != BROWSER_INVALIDID )
112     {
113         sal_uInt16 nColumnId = pOwner->GetColumnId(m_nColumnPostion);
114         String strNext = pOwner->GetCellContents(m_nCellIndex, nColumnId);
115         pOwner->SetCellContents(m_nCellIndex, nColumnId, m_strNextCellContents);
116         m_strNextCellContents = strNext;
117     }
118     pOwner->LeaveUndoMode();
119 }
120 
121 //------------------------------------------------------------------------------
122 void OTabFieldSizedUndoAct::Undo()
123 {
124     pOwner->EnterUndoMode();
125     OSL_ENSURE(m_nColumnPostion != BROWSER_INVALIDID,"Column position was not set add the undo action!");
126     if ( m_nColumnPostion != BROWSER_INVALIDID )
127     {
128         sal_uInt16 nColumnId = pOwner->GetColumnId(m_nColumnPostion);
129         long nNextWidth = pOwner->GetColumnWidth(nColumnId);
130         pOwner->SetColWidth(nColumnId, m_nNextWidth);
131         m_nNextWidth = nNextWidth;
132     }
133     pOwner->LeaveUndoMode();
134 }
135 // -----------------------------------------------------------------------------
136 void OTabFieldMovedUndoAct::Undo()
137 {
138     pOwner->EnterUndoMode();
139     OSL_ENSURE(m_nColumnPostion != BROWSER_INVALIDID,"Column position was not set add the undo action!");
140     if ( m_nColumnPostion != BROWSER_INVALIDID )
141     {
142         sal_uInt16 nId = pDescr->GetColumnId();
143         sal_uInt16 nOldPos = pOwner->GetColumnPos(nId);
144         pOwner->SetColumnPos(nId,m_nColumnPostion);
145         pOwner->ColumnMoved(nId,sal_False);
146         m_nColumnPostion = nOldPos;
147     }
148     pOwner->LeaveUndoMode();
149 }
150 // -----------------------------------------------------------------------------
151 
152 
153 
154 
155 
156