25#include <tqapplication.h>
27#include <tqdatetime.h>
34#include <tdeapplication.h>
35#include <kdecorationfactory.h>
41#include "kcommondecoration.h"
42#include "kcommondecoration.moc"
44KCommonDecoration::KCommonDecoration(KDecorationBridge* bridge, KDecorationFactory* factory)
55KCommonDecoration::~KCommonDecoration()
57 for (
int n=0; n<NumButtons; n++) {
58 if (m_button[n])
delete m_button[n];
60 delete m_previewWidget;
86 case LM_TitleEdgeBottom:
87 case LM_TitleEdgeLeft:
88 case LM_TitleEdgeRight:
89 case LM_TitleBorderLeft:
90 case LM_TitleBorderRight:
99 case LM_ButtonSpacing:
102 case LM_ButtonMarginTop:
103 case LM_RightButtonsMarginTop:
106 case LM_ExplicitButtonSpacer:
119 widget()->setBackgroundMode(NoBackground);
121 widget()->installEventFilter(
this );
125 connect(
this, TQ_SIGNAL(
keepAboveChanged(
bool) ), TQ_SLOT(keepAboveChange(
bool) ) );
126 connect(
this, TQ_SIGNAL(
keepBelowChanged(
bool) ), TQ_SLOT(keepBelowChange(
bool) ) );
164 TQRect r =
widget()->rect();
165 int r_x, r_y, r_x2, r_y2;
166 r.coords(&r_x, &r_y, &r_x2, &r_y2);
169 if (m_previewWidget) {
175 const int titleEdgeBottom =
layoutMetric(LM_TitleEdgeBottom);
177 int left = r_x+borderLeft;
178 int top = r_y+titleEdgeTop+titleHeight+titleEdgeBottom;
179 int width = r_x2-borderRight-left+1;
180 int height = r_y2-borderBottom-top+1;
181 m_previewWidget->setGeometry(left, top,
width,
height);
182 moveWidget(left,top, m_previewWidget);
187 for (
int n=0; n<NumButtons; n++) {
189 TQSize newSize = TQSize(
layoutMetric(LM_ButtonWidth,
true, m_button[n]),
191 if (newSize != m_button[n]->size() )
198 if (m_buttonsLeft.count() > 0) {
199 const int buttonSpacing =
layoutMetric(LM_ButtonSpacing);
201 for (ButtonContainer::const_iterator it = m_buttonsLeft.begin(); it != m_buttonsLeft.end(); ++it) {
202 bool elementLayouted =
false;
204 if (!(*it)->isHidden() ) {
205 moveWidget(x,y, *it);
206 x +=
layoutMetric(LM_ButtonWidth,
true, ::tqt_cast<KCommonDecorationButton*>(*it) );
207 elementLayouted =
true;
211 elementLayouted =
true;
213 if (elementLayouted && it != m_buttonsLeft.end() )
218 if (m_buttonsRight.count() > 0) {
220 const int titleEdgeRightLeft = r_x2-
layoutMetric(LM_TitleEdgeRight)+1;
222 const int buttonSpacing =
layoutMetric(LM_ButtonSpacing);
223 int x = titleEdgeRightLeft - buttonContainerWidth(m_buttonsRight);
224 for (ButtonContainer::const_iterator it = m_buttonsRight.begin(); it != m_buttonsRight.end(); ++it) {
225 bool elementLayouted =
false;
227 if (!(*it)->isHidden() ) {
228 moveWidget(x,y, *it);
229 x +=
layoutMetric(LM_ButtonWidth,
true, ::tqt_cast<KCommonDecorationButton*>(*it) );;
230 elementLayouted =
true;
234 elementLayouted =
true;
236 if (elementLayouted && it != m_buttonsRight.end() )
244 for (
int n=0; n<NumButtons; n++)
245 if (m_button[n]) m_button[n]->update();
250 for (
int n=0; n<NumButtons; n++)
254void KCommonDecoration::resetLayout()
256 for (
int n=0; n<NumButtons; n++) {
262 m_buttonsLeft.clear();
263 m_buttonsRight.clear();
265 delete m_previewWidget;
270 m_previewWidget =
new TQLabel(i18n(
"%1 is the name of window decoration style",
"<center><b>%1 preview</b></center>").arg(
visibleName() ),
widget());
271 m_previewWidget->show();
274 addButtons(m_buttonsLeft,
277 addButtons(m_buttonsRight,
283 const int minTitleBarWidth = 35;
284 btnHideMinWidth = buttonContainerWidth(m_buttonsLeft,
true) + buttonContainerWidth(m_buttonsRight,
true) +
288 btnHideLastWidth = 0;
291int KCommonDecoration::buttonsLeftWidth()
const
293 return buttonContainerWidth(m_buttonsLeft);
296int KCommonDecoration::buttonsRightWidth()
const
298 return buttonContainerWidth(m_buttonsRight);
301int KCommonDecoration::buttonContainerWidth(
const ButtonContainer &btnContainer,
bool countHidden)
const
303 int explicitSpacer =
layoutMetric(LM_ExplicitButtonSpacer);
305 int shownElementsCount = 0;
308 for (ButtonContainer::const_iterator it = btnContainer.begin(); it != btnContainer.end(); ++it) {
310 if (countHidden || !(*it)->isHidden() ) {
312 ++shownElementsCount;
316 ++shownElementsCount;
319 w +=
layoutMetric(LM_ButtonSpacing)*(shownElementsCount-1);
324bool KCommonDecoration::isModalSystemNotification()
326 unsigned char *data = 0;
329 unsigned long n, left;
330 Atom kde_wm_system_modal_notification;
331 kde_wm_system_modal_notification = XInternAtom(tqt_xdisplay(),
"_TDE_WM_MODAL_SYS_NOTIFICATION", False);
332 result = XGetWindowProperty(tqt_xdisplay(),
windowId(), kde_wm_system_modal_notification, 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left, &data);
333 if (result == Success && data != None && format == 32 )
340void KCommonDecoration::addButtons(ButtonContainer &btnContainer,
const TQString& s,
bool isLeft)
342 if (s.length() > 0) {
343 for (
unsigned n=0; n < s.length(); n++) {
347 if (!isModalSystemNotification()) {
348 if (!m_button[MenuButton]){
353 connect(btn, TQ_SIGNAL(pressed()), TQ_SLOT(menuButtonPressed()));
354 connect(btn, TQ_SIGNAL(released()),
this, TQ_SLOT(menuButtonReleased()));
356 m_button[MenuButton] = btn;
361 if (!isModalSystemNotification()) {
362 if (!m_button[OnAllDesktopsButton]){
366 btn->
setTipText(oad?i18n(
"Not on all desktops"):i18n(
"On all desktops") );
367 btn->setToggleButton(
true);
371 m_button[OnAllDesktopsButton] = btn;
382 m_button[HelpButton] = btn;
390 connect(btn, TQ_SIGNAL(clicked()), TQ_SLOT(
minimize()));
392 m_button[MinButton] = btn;
401 btn->
setTipText(max?i18n(
"Restore"):i18n(
"Maximize") );
402 btn->setToggleButton(
true);
404 connect(btn, TQ_SIGNAL(clicked()), TQ_SLOT(slotMaximize()));
406 m_button[MaxButton] = btn;
414 connect(btn, TQ_SIGNAL(clicked()), TQ_SLOT(
closeWindow()));
416 m_button[CloseButton] = btn;
420 if (!m_button[AboveButton]){
424 btn->
setTipText(above?i18n(
"Do not keep above others"):i18n(
"Keep above others") );
425 btn->setToggleButton(
true);
427 connect(btn, TQ_SIGNAL(clicked()), TQ_SLOT(slotKeepAbove()));
429 m_button[AboveButton] = btn;
433 if (!m_button[BelowButton]){
437 btn->
setTipText(below?i18n(
"Do not keep below others"):i18n(
"Keep below others") );
438 btn->setToggleButton(
true);
440 connect(btn, TQ_SIGNAL(clicked()), TQ_SLOT(slotKeepBelow()));
442 m_button[BelowButton] = btn;
450 btn->
setTipText(shaded?i18n(
"Unshade"):i18n(
"Shade") );
451 btn->setToggleButton(
true);
452 btn->setOn( shaded );
453 connect(btn, TQ_SIGNAL(clicked()), TQ_SLOT(slotShade()));
455 m_button[ShadeButton] = btn;
459 btnContainer.append(0);
464 btn->setLeft(isLeft);
467 btnContainer.append(btn);
474void KCommonDecoration::calcHiddenButtons()
476 if (
width() == btnHideLastWidth)
479 btnHideLastWidth =
width();
483 m_button[AboveButton], m_button[OnAllDesktopsButton], m_button[MaxButton],
484 m_button[MinButton], m_button[MenuButton], m_button[CloseButton] };
485 const int buttonsCount =
sizeof( btnArray ) /
sizeof( btnArray[ 0 ] );
487 int current_width =
width();
491 while (current_width < btnHideMinWidth && count < buttonsCount)
493 if (btnArray[count] ) {
494 current_width += btnArray[count]->width();
495 if (btnArray[count]->isVisible() )
496 btnArray[count]->hide();
501 for(
int i = count; i < buttonsCount; i++)
505 if (! btnArray[i]->isHidden() )
513void KCommonDecoration::show()
530 return TQSize(minWidth,
538 if( m_button[MaxButton] ) {
551 if ( m_button[OnAllDesktopsButton] ) {
554 i18n(
"Not on all desktops")
555 : i18n(
"On all desktops"));
562 if ( m_button[ShadeButton] ) {
564 m_button[ShadeButton]->setOn( shaded );
574 if (m_button[MenuButton])
576 m_button[MenuButton]->update();
592void KCommonDecoration::keepAboveChange(
bool above)
594 if (m_button[AboveButton])
596 m_button[AboveButton]->setOn(above);
597 m_button[AboveButton]->
setTipText( above?i18n(
"Do not keep above others"):i18n(
"Keep above others") );
601 if (m_button[BelowButton] && m_button[BelowButton]->isOn())
603 m_button[BelowButton]->setOn(
false);
604 m_button[BelowButton]->
setTipText( i18n(
"Keep below others") );
609void KCommonDecoration::keepBelowChange(
bool below)
611 if (m_button[BelowButton])
613 m_button[BelowButton]->setOn(below);
614 m_button[BelowButton]->
setTipText( below?i18n(
"Do not keep below others"):i18n(
"Keep below others") );
618 if (m_button[AboveButton] && m_button[AboveButton]->isOn())
620 m_button[AboveButton]->setOn(
false);
621 m_button[AboveButton]->
setTipText( i18n(
"Keep above others") );
626void KCommonDecoration::slotMaximize()
628 if (m_button[MaxButton])
630 maximize(m_button[MaxButton]->lastMousePress() );
634void KCommonDecoration::slotShade()
639void KCommonDecoration::slotKeepAbove()
644void KCommonDecoration::slotKeepBelow()
649void KCommonDecoration::menuButtonPressed()
651 static TQTime* t = NULL;
655 bool dbl = (lastClient==
this && t->elapsed() <= TQApplication::doubleClickInterval());
659 TQRect menuRect = m_button[MenuButton]->rect();
660 TQPoint menutop = m_button[MenuButton]->mapToGlobal(menuRect.topLeft());
661 TQPoint menubottom = m_button[MenuButton]->mapToGlobal(menuRect.bottomRight())+TQPoint(0,2);
662 KDecorationFactory* f =
factory();
664 if( !f->exists(
this ))
666 m_button[MenuButton]->setDown(
false);
672void KCommonDecoration::menuButtonReleased()
678void KCommonDecoration::resizeEvent(TQResizeEvent *)
691void KCommonDecoration::moveWidget(
int x,
int y, TQWidget *widget)
const
693 TQPoint p =
widget->pos();
697 if (x!=oldX || y!=oldY)
701void KCommonDecoration::resizeWidget(
int w,
int h, TQWidget *widget)
const
703 TQSize s =
widget->size();
704 int oldW = s.width();
705 int oldH = s.height();
707 if (w!=oldW || h!=oldH)
711void KCommonDecoration::mouseDoubleClickEvent(TQMouseEvent *e)
713 if( e->button() != TQt::LeftButton )
723void KCommonDecoration::wheelEvent(TQWheelEvent *e)
732 const int corner = 18+3*
layoutMetric(LM_BorderBottom,
false)/2;
735 TQRect r =
widget()->rect();
736 int r_x, r_y, r_x2, r_y2;
737 r.coords(&r_x, &r_y, &r_x2, &r_y2);
745 const int titleEdgeBottom =
layoutMetric(LM_TitleEdgeBottom);
746 const int titleEdgeLeft =
layoutMetric(LM_TitleEdgeLeft);
747 const int titleEdgeRight =
layoutMetric(LM_TitleEdgeRight);
749 const int borderBottomTop = r_y2-borderBottom+1;
750 const int borderLeftRight = r_x+borderLeft-1;
752 const int titleEdgeLeftRight = r_x+titleEdgeLeft-1;
753 const int titleEdgeRightLeft = r_x2-titleEdgeRight+1;
754 const int titleEdgeBottomBottom = r_y+titleEdgeTop+titleHeight+titleEdgeBottom-1;
755 const int titleEdgeTopBottom = r_y+titleEdgeTop-1;
757 if (p_y <= titleEdgeTopBottom) {
758 if (p_x <= r_x+corner)
759 pos = PositionTopLeft;
760 else if (p_x >= r_x2-corner)
761 pos = PositionTopRight;
764 }
else if (p_y <= titleEdgeBottomBottom) {
765 if (p_x <= titleEdgeLeftRight)
766 pos = PositionTopLeft;
767 else if (p_x >= titleEdgeRightLeft)
768 pos = PositionTopRight;
770 pos = PositionCenter;
771 }
else if (p_y < borderBottomTop) {
772 if (p_y < r_y2-corner) {
773 if (p_x <= borderLeftRight)
778 if (p_x <= borderLeftRight)
779 pos = PositionBottomLeft;
781 pos = PositionBottomRight;
783 }
else if(p_y >= borderBottomTop) {
784 if (p_x <= r_x+corner)
785 pos = PositionBottomLeft;
786 else if (p_x >= r_x2-corner)
787 pos = PositionBottomRight;
789 pos = PositionBottom;
801 int w =
widget()->width();
802 int h =
widget()->height();
804 bool tl=
true,tr=
true,bl=
true,br=
true;
806 TQDesktopWidget *
desktop=TDEApplication::desktop();
808 for(
int screen=0; screen <
desktop->numScreens(); ++screen)
810 TQRect fullscreen(
desktop->screenGeometry(screen));
813 if(window.topLeft() == fullscreen.topLeft() ) tl =
false;
814 if(window.topRight() == fullscreen.topRight() ) tr =
false;
815 if(window.bottomLeft() == fullscreen.bottomLeft() ) bl =
false;
816 if(window.bottomRight()== fullscreen.bottomRight() ) br =
false;
819 TQRegion mask(0, 0, w, h);
845bool KCommonDecoration::eventFilter( TQObject* o, TQEvent* e )
851 case TQEvent::Resize:
852 resizeEvent(
static_cast<TQResizeEvent*
>(e) );
857 case TQEvent::MouseButtonDblClick:
858 mouseDoubleClickEvent(
static_cast<TQMouseEvent*
>( e ));
860 case TQEvent::MouseButtonPress:
864 wheelEvent(
static_cast<TQWheelEvent*
>( e ));
871const int SUPPORTED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask
872 | NET::ToolbarMask | NET::MenuMask | NET::DialogMask | NET::TopMenuMask
873 | NET::UtilityMask | NET::SplashMask;
877 NET::WindowType type =
windowType( SUPPORTED_WINDOW_TYPES_MASK );
878 return ((type==NET::Toolbar)||(type==NET::Utility)||(type==NET::Menu));
883 int r_x, r_y, r_x2, r_y2;
884 widget()->rect().coords(&r_x, &r_y, &r_x2, &r_y2);
885 const int titleEdgeLeft =
layoutMetric(LM_TitleEdgeLeft);
887 const int titleEdgeRight =
layoutMetric(LM_TitleEdgeRight);
888 const int titleEdgeBottom =
layoutMetric(LM_TitleEdgeBottom);
889 const int titleBorderLeft =
layoutMetric(LM_TitleBorderLeft);
890 const int titleBorderRight =
layoutMetric(LM_TitleBorderRight);
892 const int titleEdgeBottomBottom = r_y+titleEdgeTop+ttlHeight+titleEdgeBottom-1;
893 return TQRect(r_x+titleEdgeLeft+buttonsLeftWidth()+titleBorderLeft, r_y+titleEdgeTop,
894 r_x2-titleEdgeRight-buttonsRightWidth()-titleBorderRight-(r_x+titleEdgeLeft+buttonsLeftWidth()+titleBorderLeft),
895 titleEdgeBottomBottom-(r_y+titleEdgeTop) );
899KCommonDecorationButton::KCommonDecorationButton(ButtonType type,
KCommonDecoration *parent,
const char *name)
900 : TQButton(parent->widget(), name),
901 m_decoration(parent),
903 m_realizeButtons(TQt::LeftButton),
904 m_lastMouse(TQt::NoButton),
907 setCursor(ArrowCursor);
910KCommonDecorationButton::~KCommonDecorationButton()
929void KCommonDecorationButton::setLeft(
bool left)
936 m_realizeButtons = btns;
941 if (!m_size.isValid() || s != size() ) {
944 setFixedSize(m_size);
949TQSize KCommonDecorationButton::sizeHint()
const
955 TQToolTip::remove(
this );
956 TQToolTip::add(
this, tip );
959void KCommonDecorationButton::setToggleButton(
bool toggle)
961 TQButton::setToggleButton(toggle);
965void KCommonDecorationButton::setOn(
bool on)
973void KCommonDecorationButton::mousePressEvent(TQMouseEvent* e)
975 m_lastMouse = e->button();
977 TQMouseEvent me(e->type(), e->pos(), e->globalPos(),
978 (e->button()&m_realizeButtons)?TQt::LeftButton:TQt::NoButton, e->state());
980 TQButton::mousePressEvent(&me);
983void KCommonDecorationButton::mouseReleaseEvent(TQMouseEvent* e)
985 m_lastMouse = e->button();
987 TQMouseEvent me(e->type(), e->pos(), e->globalPos(),
988 (e->button()&m_realizeButtons)?TQt::LeftButton:TQt::NoButton, e->state());
990 TQButton::mouseReleaseEvent(&me);
This class eases development of decorations by implementing parts of KDecoration which are error pron...
virtual void borders(int &left, int &right, int &top, int &bottom) const
This function should return the distance from each window side to the inner window.
virtual TQRegion cornerShape(WindowCorner corner)
virtual void maximizeChange()
This function is called whenever the maximalization state of the window changes.
virtual TQString defaultButtonsRight() const =0
The default title button order on the left.
virtual bool decorationBehaviour(DecorationBehaviour behaviour) const
This controls whether some specific behaviour should be enabled or not.
virtual KCommonDecorationButton * createButton(ButtonType type)=0
Create a new title bar button.
virtual TQString visibleName() const =0
The name of the decoration used in the decoration preview.
void updateButtons() const
Makes sure all buttons are repainted.
virtual TQSize minimumSize() const
This function should return the minimum required size for the decoration.
virtual void activeChange()
This function is called whenever the window either becomes or stops being active.
virtual void paintEvent(TQPaintEvent *e)=0
Draw the window decoration.
@ DB_ButtonHide
Hide buttons when there is not enough space in the titlebar.
@ DB_WindowMask
Set a mask on the window.
@ DB_MenuClose
Close window on double clicking the menu.
virtual void init()
Handles widget and layout creation, call the base implementation when subclassing this member.
virtual TQString defaultButtonsLeft() const =0
The default title button order on the left.
virtual void shadeChange()
This function is called whenever the window is shaded or unshaded.
TQRect titleRect() const
Convenience method.
bool isToolWindow() const
Convenience method.
LayoutMetric
Used to calculate the decoration layout.
virtual void iconChange()
This function is called whenever the window icon changes.
virtual void updateCaption()
This is used to update the painting of the title bar after the caption has been changed.
virtual void updateWindowShape()
This updates the window mask using the information provided by cornerShape().
virtual void captionChange()
This function is called whenever the caption changes.
virtual void reset(unsigned long changed)
Handles SettingButtons, call the base implementation when subclassing this member.
virtual void resize(const TQSize &s)
This method is called by twin when the style should resize the decoration window.
virtual int layoutMetric(LayoutMetric lm, bool respectWindowState=true, const KCommonDecorationButton *button=0) const
This controls the layout of the decoration in various ways.
void updateLayout() const
TODO: remove?
virtual void desktopChange()
This function is called whenever the desktop for the window changes.
void resetButtons() const
Manually call reset() on each button.
virtual Position mousePosition(const TQPoint &point) const
This function should return mouse cursor position in the decoration.
@ SettingButtons
The button layout was changed.
Position
These values represent positions inside an area.
@ MaximizeFull
Equal to MaximizeVertical | MaximizeHorizontal.
This is the base class for a decoration object.
void processMousePressEvent(TQMouseEvent *e)
This function is the default handler for mouse events.
static const KDecorationOptions * options()
Returns the KDecorationOptions object, which is used to access configuration settings for the decorat...
bool isMinimizable() const
Returns true if the decorated window can be minimized by the user.
void closeWindow()
This function can be called by the decoration to request closing of the decorated window.
void setShade(bool set)
Shades or unshades the decorated window.
MaximizeMode maximizeMode() const
Returns the current maximization mode of the decorated window.
bool keepAbove() const
Returns true if the decorated window should be kept above other windows.
bool isPreview() const
If this function returns true, the decorated window is used as a preview e.g.
bool isShadeable() const
Returns true if the decorated window can be shaded.
bool isSetShade() const
Returns true if the decorated window was set to be shaded.
void showWindowMenu(const TQRect &pos)
This function invokes the window operations menu.
bool keepBelow() const
Returns true if the decorated window should be kept below other windows.
TQRect geometry() const
Returns the geometry of the decoration.
WId windowId() const
Returns the handle of the window that is being decorated.
void showContextHelp()
Start showing context help in the window (i.e.
bool isMaximizable() const
Returns true if the decorated window can be maximized.
int height() const
Convenience function that returns the height of the decoration.
TQWidget * widget()
Returns the main widget for the decoration.
void setKeepAbove(bool set)
Sets or reset keeping this window above others.
void createMainWidget(TQt::WFlags flags=0)
Convenience functions that creates and sets a main widget as necessary.
KDecorationFactory * factory() const
Returns the factory that created this decoration.
void setKeepBelow(bool set)
Sets or reset keeping this window below others.
void minimize()
Minimize the decorated window.
void titlebarDblClickOperation()
This function performs the operation configured as titlebar double click operation.
bool providesContextHelp() const
Return true if the decorated window can show context help (i.e.
int desktop() const
Returns the number of the virtual desktop the decorated window is currently on (including NET::OnAllD...
bool isCloseable() const
Returns true if the decoration window can be closed by the user.
void keepBelowChanged(bool)
This signal is emitted whenever the window's keep-below state changes.
void keepAboveChanged(bool)
This signal is emitted whenever the window's keep-above state changes.
bool isOnAllDesktops() const
Convenience function that returns true if the window is on all virtual desktops.
void setMask(const TQRegion ®, int mode=0)
If the decoration is non-rectangular, this function needs to be called to set the shape of the decora...
void titlebarMouseWheelOperation(int delta)
This function performs the operation configured as titlebar wheel mouse operation.
void toggleOnAllDesktops()
This function toggles the on-all-desktops state of the decorated window.
NET::WindowType windowType(unsigned long supported_types) const
This function returns the window type of the decorated window.
int width() const
Convenience function that returns the width of the decoration.