18#include "KWFrameView.h"
19#include "KWFrameViewManager.h"
21#include "KWFrameSet.h"
22#include "KWTextFrameSet.h"
23#include "KWTableFrameSet.h"
24#include "KWPartFrameSet.h"
25#include "KWVariable.h"
26#include "KWPictureFrameSet.h"
27#include "KWViewMode.h"
28#include "KWDocument.h"
31#include "KoZoomHandler.h"
34#include <tdeactionclasses.h>
36#include <tqapplication.h>
37#include <tqpopupmenu.h>
39static const double HORIZONTAL_SNAP = 6;
40static const double VERTICAL_SNAP = 6;
45 Q_ASSERT(
frame->frameSet());
54 else if(
dynamic_cast<KWPictureFrameSet *
>(
frame->frameSet()) != 0)
58 kdWarning() <<
"Unknown frameset supplied!" << endl;
62KWFrameView::~KWFrameView() {
67 return hit(point,
true,
true);
71 return hit(point, fuzzy,
false);
74bool KWFrameView::hit(
const KoPoint &point,
bool fuzzy ,
bool borderOnly)
const {
79 if(
frame()->width() < HORIZONTAL_SNAP * 3)
80 hs =
frame()->width() / 3;
82 if(
frame()->height() < VERTICAL_SNAP * 3)
83 vs =
frame()->height() / 3;
85 if(point.x() <
frame()->x() - hs)
87 if(point.x() >
frame()->right() + hs)
89 if(point.y() <
frame()->y() - vs)
91 if(point.y() >
frame()->bottom() + vs)
95 if(point.x() >
frame()->x() + hs && point.x() <
frame()->right() - hs &&
96 point.y() >
frame()->y() + vs && point.y() <
frame()->bottom() - vs )
104 MouseMeaning mm = m_policy->mouseMeaningOnBorder(point, keyState);
105 if(mm != MEANING_NONE && (
frame()->frameSet()->isProtectSize() ||
106 frame()->frameSet()->isMainFrameset() ||
frame()->frameSet()->isAHeader() ||
107 frame()->frameSet()->isAFooter() ))
108 mm = MEANING_FORBIDDEN;
111 if(hit(point,
false,
false))
112 return m_policy->mouseMeaning(point, keyState);
117 m_policy->setSelected(selectPolicy);
118 if( m_selected ==
selected )
return;
119 m_manager->slotFrameSelectionChanged();
124 view->unplugActionList(
"tableactions" );
125 view->unplugActionList(
"frameset_type_action" );
126 TQPopupMenu *popup = m_policy->createPopup(point, view);
128 popup->popup(popupPoint);
142 readOnly = fs->isProtectSize() || fs->isMainFrameset() ||
143 fs->isAHeader() || fs->isAFooter() || fs->
isFloating();
145 void paint(TQPainter *p,
int x,
int y) {
146 p->setPen( TQPen( TQt::black, 1, TQPen::SolidLine ) );
147 p->setBrush( TQApplication::palette().color( TQPalette::Active, TQColorGroup::Highlight ) );
148 p->drawRect( x, y, GRIP_SIZE, GRIP_SIZE );
150 TQBrush brush = TQApplication::palette().color( TQPalette::Active,TQColorGroup::Base );
151 p->fillRect( x+1, y+1, GRIP_SIZE-2, GRIP_SIZE-2, brush );
157 if ( crect.intersects( frameRect ) )
159 ResizeHandle handle(
this);
161 const int width = frameRect.width();
162 const int height = frameRect.height();
163 for(
int y=0; y < 3; y++) {
164 int offsetY = -1 + y + frameRect.y();
165 if(y > 0) offsetY += (height - 6) / (y == 1 ? 2:1);
166 for(
int x=0; x < 3; x++) {
167 if(x == 1 && y == 1)
continue;
168 int offsetX = -1 + x + frameRect.x();
169 if(x > 0) offsetX += (width - 6) / (x == 1 ? 2:1);
170 handle.paint(painter, offsetX, offsetY);
178 m_separator =
new TDEActionSeparator();
182 if(m_view->frame()->frameSet()->isMainFrameset())
184 actionList.append(m_separator);
185 TDEToggleAction *action =
dynamic_cast<TDEToggleAction*
> (view->actionCollection()->
186 action(
"inline_frame"));
191 actionList.append(action);
195 double hs = HORIZONTAL_SNAP;
196 KWFrame *frame = m_view->frame();
197 if(frame->width() < HORIZONTAL_SNAP * 3)
198 hs = frame->width() / 3;
199 double vs = VERTICAL_SNAP;
200 if(frame->height() < VERTICAL_SNAP * 3)
201 vs = frame->height() / 3;
204 if( point.x() <= frame->x() + hs ) {
205 if(point.y() <= frame->y() + vs)
206 return MEANING_TOPLEFT;
207 if(point.y() >= frame->bottom() - vs)
208 return MEANING_BOTTOMLEFT;
209 if( TQABS(frame->y() + frame->height() / 2 - point.y()) <= vs )
211 return MEANING_MOUSE_MOVE;
213 if( point.x() >= frame->right() - hs) {
214 if(point.y() <= frame->y() + vs)
215 return MEANING_TOPRIGHT;
216 if(point.y() >= frame->bottom() - vs)
217 return MEANING_BOTTOMRIGHT;
218 if( TQABS(frame->y() + frame->height() / 2 - point.y()) <= vs )
219 return MEANING_RIGHT;
220 return MEANING_MOUSE_MOVE;
223 if( frame->y() + vs >= point.y() ) {
224 if( TQABS(frame->x() + frame->width() / 2 - point.x() ) <= hs )
226 return MEANING_MOUSE_MOVE;
228 if( frame->bottom() - vs <= point.y() ) {
229 if( TQABS(frame->x() + frame->width() / 2 - point.x() ) <= hs )
230 return MEANING_BOTTOM;
231 return MEANING_MOUSE_MOVE;
242 if ( keyState & TQt::ControlButton )
243 return MEANING_MOUSE_SELECT;
246 if ( (keyState & TQt::ShiftButton) && m_view->parent()->selectedFrame() != 0 )
247 return MEANING_MOUSE_SELECT;
249 return MEANING_MOUSE_INSIDE_TEXT;
252 view->plugActionList(
"tableactions", view->tableActions() );
253 if( m_view->isBorderHit(point) )
254 return view->popupMenu(
"frame_popup_table");
255 return view->popupMenu(
"text_popup");
258 KWFrame *frame = m_view->frame();
259 double hs = HORIZONTAL_SNAP;
260 double vs = VERTICAL_SNAP;
261 bool ctrl = keyState & TQt::ControlButton;
263 if ( TQABS( frame->x() - point.x() ) < hs
264 && point.y() >= frame->y() && point.y() <= frame->bottom() ) {
266 return MEANING_SELECT_ROW;
268 return MEANING_RESIZE_COLUMN;
270 if ( TQABS( frame->y() - point.y() ) < vs
271 && point.x() >= frame->x() && point.x() <= frame->right() ) {
273 return MEANING_SELECT_COLUMN;
275 return MEANING_MOUSE_SELECT;
279 return MEANING_MOUSE_SELECT;
280 if ( TQABS( frame->right() - point.x() ) < hs
281 && point.y() >= frame->y() && point.y() <= frame->bottom() )
282 return MEANING_RESIZE_COLUMN;
283 if ( TQABS( frame->bottom() - point.y() ) < vs
284 && point.x() >= frame->x() && point.x() <= frame->right() )
285 return MEANING_MOUSE_SELECT;
290 if( selectPolicy == MEANING_SELECT_COLUMN ) {
292 for (KWTableFrameSet::TableIter cells(fs->
groupmanager()); cells; ++cells) {
293 if(cells->firstColumn() >= column && cells->lastColumn() <= column) {
294 KWFrameView *fv = m_view->parent()->view(cells->frame(0));
300 else if( selectPolicy == MEANING_SELECT_ROW ) {
302 for (KWTableFrameSet::TableIter cells(fs->
groupmanager()); cells; ++cells) {
303 if(cells->firstRow() >= row && cells->lastRow() <= row) {
304 KWFrameView *fv = m_view->parent()->view(cells->frame(0));
310 else if( selectPolicy == MEANING_SELECT_RANGE ) {
311kdDebug() <<
"not yet implemented; select table range\n";
320 if( keyState & TQt::ControlButton ) {
321 return m_view->selected() ? MEANING_MOUSE_MOVE : MEANING_MOUSE_SELECT;
323 if ( m_view->selected() )
324 return MEANING_ACTIVATE_PART;
325 return MEANING_MOUSE_SELECT;
330 TDEActionSeparator *separator=
new TDEActionSeparator();
331 TDEActionCollection *actionCollection = view->actionCollection();
332 TQPtrList<TDEAction> actionList;
333 actionList.append(separator);
334 if( !part->protectContent() ) {
335 TDEToggleAction *action =
dynamic_cast<TDEToggleAction*
>(actionCollection->action(
"embedded_store_internal"));
337 action->setChecked(part->getChild()->document()->storeInternal());
338 action->setEnabled(part->getChild()->document()->hasExternURL());
339 actionList.append(action);
342 view->plugActionList(
"frameset_type_action", actionList );
344 return view->popupMenu(
"frame_popup");
350 if( (keyState & TQt::ControlButton) == TQt::ControlButton )
351 return MEANING_MOUSE_SELECT;
353 if(fs == 0 || fs->kWordDocument() == 0)
354 return MEANING_MOUSE_INSIDE_TEXT;
355 KWVariableCollection *varCol = fs->kWordDocument()->variableCollection();
356 if (varCol->variableSetting()->displayLink() && varCol->variableSetting()->underlineLink()
357 && fs->linkVariableUnderMouse( point ) )
358 return MEANING_MOUSE_OVER_LINK;
359 KoVariable* var = fs->variableUnderMouse(point);
363 return MEANING_MOUSE_OVER_FOOTNOTE;
365 return MEANING_MOUSE_INSIDE_TEXT;
368 if( m_view->isBorderHit(point) ) {
370 TDEActionSeparator *separator=
new TDEActionSeparator();
371 TDEActionCollection *actionCollection = view->actionCollection();
372 TQPtrList<TDEAction> actionList;
373 if(fs->isHeaderOrFooter()) {
374 actionList.append(separator);
375 actionList.append(actionCollection->action(
"configure_headerfooter"));
377 else if (fs->isFootEndNote()) {
378 actionList.append(separator);
379 TDEAction *action = actionCollection->action(
"goto_footendnote");
380 action->setText( fs->isFootNote() ?
381 i18n(
"Go to Footnote" ) : i18n(
"Go to Endnote" ) );
382 actionList.append(action);
385 view->plugActionList(
"frameset_type_action", actionList );
386 return view->popupMenu(
"frame_popup");
389 if ( view->getGUI()->canvasWidget()->currentFrameSetEdit()->frameSet()->
type() == FT_FORMULA )
390 return view->popupMenu(
"Formula");
394 canvasWidget()->currentFrameSetEdit());
396 TQString word = fse->wordUnderCursor( *fse->cursor() );
399 view->unplugActionList(
"datatools" );
400 view->unplugActionList(
"variable_action" );
401 view->unplugActionList(
"spell_result_action" );
402 view->unplugActionList(
"datatools_link" );
405 TQPtrList<TDEAction> &actionList = view->dataToolActionList();
406 TQPtrList<TDEAction> &variableList = view->variableActionList();
409 variableList.clear();
411 bool singleWord=
false;
412 KWDocument * doc = m_view->frame()->frameSet()->kWordDocument();
413 actionList = fse->dataToolActionList(doc->instance(), word, singleWord);
415 KoVariable* var = fse->variable();
416 doc->variableCollection()->setVariableSelected(var);
418 variableList = doc->variableCollection()->popupActionList();
420 if( variableList.count()>0) {
421 view->plugActionList(
"variable_action", variableList );
422 return view->popupMenu(
"variable_popup");
426 KoLinkVariable* linkVar =
dynamic_cast<KoLinkVariable *
>( var );
428 view->plugActionList(
"datatools_link", actionList );
429 return view->popupMenu(
"text_popup_link");
431 view->plugActionList(
"datatools", actionList );
432 KoNoteVariable * noteVar =
dynamic_cast<KoNoteVariable *
>( var );
434 return view->popupMenu(
"comment_popup");
436 KoCustomVariable * customVar =
dynamic_cast<KoCustomVariable *
>( var );
438 return view->popupMenu(
"custom_var_popup");
442 view->changeFootNoteMenuItem( footNoteVar->noteType() == FootNote );
443 return view->popupMenu(
"footnote_popup");
446 TQPtrList<TDEAction> actionCheckSpellList = view->listOfResultOfCheckWord( word );
447 if ( !actionCheckSpellList.isEmpty() ) {
448 view->plugActionList(
"spell_result_action", actionCheckSpellList );
449 return view->popupMenu(
"text_popup_spell_with_result");
451 return view->popupMenu(
"text_popup_spell");
454 return view->popupMenu(
"text_popup");
463 return m_view->selected() ? MEANING_MOUSE_MOVE: MEANING_MOUSE_SELECT;
467 TDEActionSeparator *separator=
new TDEActionSeparator();
468 TDEActionCollection *actionCollection = view->actionCollection();
469 TQPtrList<TDEAction> actionList;
470 actionList.append(separator);
471 TDEAction *action = actionCollection->action(
"change_picture");
473 actionList.append(action);
474 action = actionCollection->action(
"save_picture");
476 actionList.append(action);
478 view->plugActionList(
"frameset_type_action", actionList );
480 return view->popupMenu(
"frame_popup");
This base class is an interface for Policies used in the KWFrameView.
void addFloatingAction(KWView *view, TQPtrList< TDEAction > &actionList)
Shared method for all policies to add the 'set floating' action to a popup menu.
virtual MouseMeaning mouseMeaningOnBorder(const KoPoint &point, int keyState)
Shared method for all policies called when the border of the frame is clicked.
FramePolicy(KWFrameView *view)
Constructor.
A policy for Image (aka Picture) Frames.
MouseMeaning mouseMeaning(const KoPoint &point, int keyState)
Return the MouseMeaning enum value for the parent view.
TQPopupMenu * createPopup(const KoPoint &point, KWView *view)
Return a fully initialized popup for the context of frame at point.
Class: KWFrameSet Base type, a frameset holds content as well as frames to show that content.
virtual FrameSetType type() const
The type of frameset.
bool isFloating() const
Return true if this frameset is floating (inline), false if it's fixed.
KWTableFrameSet * groupmanager() const
returns the groupManager this frameset belongs to.
KWFrame * frame(unsigned int _num) const
get a frame by number
Class that knows about all the (visible) frames in the document and will act as a manager between the...
an instance of a KWFrameView represents the view in the MVC model of a frame; there can be multiple K...
bool isBorderHit(const KoPoint &point) const
returns if the point is on the border
void setSelected(bool selected, MouseMeaning selectPolicy=MEANING_MOUSE_SELECT)
Set the selected state of this frameView.
KWFrameViewManager * parent() const
Return the parent KWFrameViewManager this frameView belongs to.
bool contains(const KoPoint &point, bool fuzzy=true) const
returns if the point is anywhere in te frame, if fuzzy is true; also a little outside
KWFrameView(KWFrameViewManager *parent, KWFrame *frame)
Constructor.
KWFrame * frame() const
returns the frame this frameView represents
bool selected() const
returns if this frameView is selected. A selected frame is shown differently on screen.
void paintFrameAttributes(TQPainter *painter, const TQRect &crect, KWViewMode *vm, KoZoomHandler *zh)
Paint view based items of the frameView, like selected state.
void showPopup(const KoPoint &point, KWView *view, const TQPoint &popupPoint) const
Show a context-sensitive popup menu based on the location of 'point'.
MouseMeaning mouseMeaning(const KoPoint &point, int keyState)
Return the MouseMeaning enum value for the parent view.
This class represents a single frame.
KWFrameSet * frameSet() const
Data stucture methods.
A frameset that contains an embedded object (a KWDocumentChild).
This class implements tables by acting as the manager for the frame(set)s which make up the table cel...
Object that is created to edit a Text frame set (KWTextFrameSet).
Class: KWTextFrameSet Contains text (KoTextObject) and frames to display that text.
Abstract base class for KWCanvas's view modes.
virtual TQPoint normalToView(const TQPoint &nPoint)=0
Normal coord -> view coord.
A policy for Part Frames.
TQPopupMenu * createPopup(const KoPoint &point, KWView *view)
Return a fully initialized popup for the context of frame at point.
MouseMeaning mouseMeaning(const KoPoint &point, int keyState)
Return the MouseMeaning enum value for the parent view.
A policy for Table Frames.
MouseMeaning mouseMeaning(const KoPoint &point, int keyState)
Return the MouseMeaning enum value for the parent view.
TQPopupMenu * createPopup(const KoPoint &point, KWView *view)
Return a fully initialized popup for the context of frame at point.
MouseMeaning mouseMeaningOnBorder(const KoPoint &point, int keyState)
Shared method for all policies called when the border of the frame is clicked.
void setSelected(MouseMeaning selectPolicy)
Override this method to do more than select the parent frame-view.
A policy for Text Frames.
MouseMeaning mouseMeaning(const KoPoint &point, int keyState)
Return the MouseMeaning enum value for the parent view.
TQPopupMenu * createPopup(const KoPoint &point, KWView *view)
Return a fully initialized popup for the context of frame at point.