28#include "kspread_dlg_reference.h"
29#include "kspread_canvas.h"
30#include "kspread_doc.h"
31#include "kspread_util.h"
32#include "kspread_map.h"
33#include "kspread_view.h"
34#include "kspread_sheet.h"
36#include "kspread_locale.h"
39#include <tqcombobox.h>
41#include <tqlineedit.h>
42#include <tqpushbutton.h>
45#include <kbuttonbox.h>
46#include <tdemessagebox.h>
48#include <tdeversion.h>
50#include <kstdguiitem.h>
54reference::reference(
View* parent,
const char* name )
55 : TQDialog( parent, name,true )
58 TQVBoxLayout *lay1 =
new TQVBoxLayout(
this );
59 lay1->setMargin( KDialog::marginHint() );
60 lay1->setSpacing( KDialog::spacingHint() );
61 m_list =
new TQListBox(
this);
62 lay1->addWidget( m_list );
64 setCaption( i18n(
"Area Name") );
66 m_rangeName =
new TQLabel(
this);
67 lay1->addWidget(m_rangeName);
69 m_pRemove =
new TQPushButton(i18n(
"&Remove"),
this);
70 lay1->addWidget( m_pRemove );
72 KButtonBox *bb =
new KButtonBox(
this );
74 m_pEdit = bb->addButton( i18n(
"&Edit...") );
75 m_pOk = bb->addButton( KStdGuiItem::ok() );
76 m_pCancel = bb->addButton( KStdGuiItem::cancel() );
77 m_pOk->setDefault(
true );
79 lay1->addWidget( bb );
82 TQStringList sheetName;
83 TQPtrListIterator<Sheet> it2 ( m_pView->doc()->map()->sheetList() );
84 for( ; it2.current(); ++it2 )
86 sheetName.append( it2.current()->sheetName());
89 TQValueList<Reference>::Iterator it;
90 TQValueList<Reference> area = m_pView->doc()->listArea();
91 for ( it = area.begin(); it != area.end(); ++it )
93 text = (*it).ref_name;
94 if ( sheetName.contains((*it).sheet_name ))
95 m_list->insertItem(text);
98 if ( !m_list->count() )
100 m_pOk->setEnabled(
false );
101 m_pRemove->setEnabled(
false );
102 m_pEdit->setEnabled(
false );
105 connect( m_pOk, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( slotOk() ) );
106 connect( m_pCancel, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( slotCancel() ) );
107 connect( m_pEdit, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( slotEdit() ) );
108 connect( m_pRemove, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( slotRemove() ) );
109 connect( m_list, TQ_SIGNAL(doubleClicked(TQListBoxItem *)),
this,
110 TQ_SLOT(slotDoubleClicked(TQListBoxItem *)));
111 connect( m_list, TQ_SIGNAL(highlighted ( TQListBoxItem * ) ),
this,
112 TQ_SLOT(slotHighlighted(TQListBoxItem * )));
113 m_rangeName->setText(i18n(
"Area: %1").arg(
""));
118void reference::displayAreaValues(TQString
const & areaName)
121 TQValueList<Reference>::Iterator it;
122 TQValueList<Reference> area( m_pView->doc()->listArea() );
123 for ( it = area.begin(); it != area.end(); ++it )
125 if ((*it).ref_name == areaName)
127 if (!m_pView->doc()->map()->findSheet( (*it).sheet_name))
128 kdDebug(36001) <<
"(*it).table_name '" << (*it).sheet_name
129 <<
"' not found!*********" << endl;
131 tmpName = util_rangeName(m_pView->doc()->map()->findSheet( (*it).sheet_name),
137 tmpName = i18n(
"Area: %1").arg(tmpName);
138 m_rangeName->setText(tmpName);
141void reference::slotHighlighted(TQListBoxItem * )
143 TQString tmp = m_list->text(m_list->currentItem());
144 displayAreaValues(tmp);
147void reference::slotDoubleClicked(TQListBoxItem *)
152void reference::slotRemove()
154 if (m_list->currentItem() == -1)
157 int ret = KMessageBox::warningContinueCancel(
this, i18n(
"Do you really want to remove this area name?"),i18n(
"Remove Area"),KStdGuiItem::del());
158 if (ret == KMessageBox::Cancel)
162 if ( m_list->currentItem() != -1)
164 m_pView->doc()->emitBeginOperation(
false );
166 TQString textRemove = m_list->text(m_list->currentItem());
167 m_pView->doc()->removeArea(textRemove );
168 m_pView->doc()->setModified(
true);
181 m_list->removeItem(m_list->currentItem());
185 for ( tbl = m_pView->doc()->map()->firstSheet(); tbl != 0L; tbl = m_pView->doc()->map()->nextSheet() )
187 tbl->refreshRemoveAreaName(textRemove);
190 m_pView->slotUpdateView( m_pView->activeSheet() );
193 if ( !m_list->count() )
195 m_pOk->setEnabled(
false );
196 m_pRemove->setEnabled(
false );
197 m_pEdit->setEnabled(
false );
201void reference::slotEdit()
203 TQString name(m_list->text(m_list->currentItem()));
204 if ( name.isEmpty() )
206 EditAreaName editDlg( m_pView,
"EditArea", name );
209 m_rangeName->setText(i18n(
"Area: %1").arg(
""));
210 TQString tmp = m_list->text(m_list->currentItem());
212 displayAreaValues( tmp );
215void reference::slotOk()
217 m_pView->doc()->emitBeginOperation(
false );
220 if (m_list->currentItem() != -1)
222 int index = m_list->currentItem();
223 text = m_list->text(index);
224 TQValueList<Reference> area = m_pView->doc()->listArea();
226 if (m_pView->activeSheet()->sheetName() != area[ index ].sheet_name)
228 Sheet *sheet = m_pView->doc()->map()->findSheet(area[ index ].sheet_name);
230 m_pView->setActiveSheet(sheet);
233 Region region(m_pView,
Cell::fullName(m_pView->activeSheet(), area[index].rect.left(), area[index].rect.top()));
234 m_pView->selectionInfo()->initialize(region);
235 m_pView->selectionInfo()->initialize(area[ index ].rect);
238 m_pView->slotUpdateView( m_pView->activeSheet() );
242void reference::slotCancel()
249EditAreaName::EditAreaName(
View * parent,
251 TQString
const & areaname )
252 : KDialogBase( parent, name ,true,i18n(
"Edit Area" ) , Ok|Cancel )
257 setSizePolicy( TQSizePolicy( (TQSizePolicy::SizeType)5,
258 (TQSizePolicy::SizeType)4, 0, 0,
259 sizePolicy().hasHeightForWidth() ) );
261 TQWidget * page =
new TQWidget(
this );
264 TQGridLayout * EditAreaNameLayout
265 =
new TQGridLayout( page, 1, 1, 11, 6,
"EditAreaNameLayout");
267 TQHBoxLayout * Layout1 =
new TQHBoxLayout( 0, 0, 6,
"Layout1");
268 TQSpacerItem * spacer =
new TQSpacerItem( 0, 0, TQSizePolicy::Expanding,
269 TQSizePolicy::Minimum );
270 Layout1->addItem( spacer );
272 EditAreaNameLayout->addMultiCellLayout( Layout1, 3, 3, 0, 1 );
274 TQLabel * TextLabel4 =
new TQLabel( page,
"TextLabel4" );
275 TextLabel4->setText( i18n(
"Cells:" ) );
277 EditAreaNameLayout->addWidget( TextLabel4, 2, 0 );
279 m_area =
new TQLineEdit( page,
"m_area" );
281 EditAreaNameLayout->addWidget( m_area, 2, 1 );
283 TQLabel * TextLabel1 =
new TQLabel( page,
"TextLabel1" );
284 TextLabel1->setText( i18n(
"Sheet:" ) );
286 EditAreaNameLayout->addWidget( TextLabel1, 1, 0 );
288 m_sheets =
new TQComboBox(
false, page,
"m_sheets" );
290 EditAreaNameLayout->addWidget( m_sheets, 1, 1 );
292 TQLabel * TextLabel2 =
new TQLabel( page,
"TextLabel2" );
293 TextLabel2->setText( i18n(
"Area name:" ) );
295 EditAreaNameLayout->addWidget( TextLabel2, 0, 0 );
297 m_areaName =
new TQLabel( page,
"m_areaName" );
298 m_areaName->setText( areaname );
300 EditAreaNameLayout->addWidget( m_areaName, 0, 1 );
302 TQPtrList<Sheet> sheetList = m_pView->doc()->map()->sheetList();
303 for (
unsigned int c = 0; c < sheetList.count(); ++c)
305 Sheet * t = sheetList.at(c);
308 m_sheets->insertItem( t->sheetName() );
312 TQValueList<Reference>::Iterator it;
313 TQValueList<Reference> area(m_pView->doc()->listArea());
314 for ( it = area.begin(); it != area.end(); ++it )
316 if ((*it).ref_name == areaname)
318 if (!m_pView->doc()->map()->findSheet( (*it).sheet_name))
319 kdDebug(36001) <<
"(*it).table_name '" << (*it).sheet_name
320 <<
"' not found!*********" << endl;
322 tmpName = util_rangeName( (*it).rect );
327 m_sheets->setCurrentText( (*it).sheet_name );
328 m_area->setText( tmpName );
332EditAreaName::~EditAreaName()
336void EditAreaName::slotOk()
338 Range range( m_area->text() );
340 if ( !range.isValid() )
342 Point point( m_area->text() );
343 if ( !point.isValid() )
346 m_area->setText( m_area->text() +
":" + m_area->text() );
348 range =
Range( m_area->text() );
351 m_pView->doc()->emitBeginOperation(
false );
353 m_pView->doc()->removeArea( m_areaName->text() );
354 m_pView->doc()->addAreaName(range.range(), m_areaName->text(), m_sheets->currentText() );
358 for ( sheet = m_pView->doc()->map()->firstSheet(); sheet != 0L;
359 sheet = m_pView->doc()->map()->nextSheet() )
361 sheet->refreshChangeAreaName( m_areaName->text() );
364 m_pView->slotUpdateView( m_pView->activeSheet() );
368#include "kspread_dlg_reference.moc"
TQString fullName() const
Returns the full name of the cell, i.e.
Represents the position of a single cell in a workbook.
Represents a region within a workbook.
The one for all class for points and ranges.
The View class displays a KSpread document.