summaryrefslogtreecommitdiffstats
path: root/kicker/kicker/core/container_extension.h
blob: 724ba0a10ee91c22c26238004f5bb9e83cb9f395 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*****************************************************************

Copyright (c) 2000 Matthias Elter <elter@kde.org>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

******************************************************************/

#ifndef __container_extension_h__
#define __container_extension_h__

#include <tqframe.h>
#include <tqptrlist.h>

#include <kpanelextension.h>
#include <dcopobject.h>
#include <netwm_def.h>

#include "global.h"
#include "appletinfo.h"
#include "unhidetrigger.h"
#include "extensionSettings.h"

class TQBoxLayout;
class TQGridLayout;
class TQPopupMenu;
class TQTimer;
class TQVBox;
class QXEmbed;
class HideButton;
class KConfig;
class KWinModule;
class PopupWidgetFilter;
class PanelExtensionOpMenu;
class TQColor;

class ExtensionContainer : public TQFrame
{
    Q_OBJECT

public:
    enum UserHidden { Unhidden, LeftTop, RightBottom };
    enum HideMode { ManualHide, AutomaticHide, BackgroundHide };

    ExtensionContainer(const AppletInfo& info,
                       const TQString& extensionId,
                       TQWidget *parent = 0);
    ExtensionContainer(KPanelExtension* extension,
                       const AppletInfo& info,
                       const TQString& extensionId,
                       TQWidget *parent = 0);
    virtual ~ExtensionContainer();

    virtual TQSize sizeHint(KPanelExtension::Position, const TQSize &maxSize) const;

    const AppletInfo& info() const { return _info; }

    TQString extensionId() const { return _id; }

    void readConfig();
    void writeConfig();

    virtual TQString panelId() const { return extensionId(); }

    virtual void about();
    virtual void help();
    virtual void preferences();
    virtual void reportBug();

    void removeSessionConfigFile();

    KPanelExtension::Orientation orientation() const;
    KPanelExtension::Position position() const;
    void setPosition(KPanelExtension::Position p) { arrange( p, alignment(), xineramaScreen() ); }

    int xineramaScreen() const;
    void setXineramaScreen(int screen);

    void setResizeableHandle( bool resizeablehandle=true );
    void setHideButtons(bool showLeft, bool showRight);
    void setSize(KPanelExtension::Size size, int custom);
    KPanelExtension::Size size() const;
    int customSize() const { return m_settings.customSize(); }
    HideMode hideMode() const;
    void unhideIfHidden(int showForHowManyMS = 0);
    bool reserveStrut() const;

    KPanelExtension::Alignment alignment() const;
    void setAlignment(KPanelExtension::Alignment a) { arrange( position(), a, xineramaScreen() ); }

    TQRect currentGeometry() const;
    TQRect initialGeometry(KPanelExtension::Position p, KPanelExtension::Alignment a,
                          int XineramaScreen, bool autoHidden = false,
                          UserHidden userHidden = Unhidden) const;

    bool eventFilter( TQObject *, TQEvent * );

    int panelOrder() const { return m_panelOrder; }
    void setPanelOrder(int order) { m_panelOrder = order; }

signals:
    void removeme(ExtensionContainer*);

protected slots:
    virtual void showPanelMenu( const TQPoint& pos );
    void moveMe();
    void updateLayout();
    void actuallyUpdateLayout();
    void enableMouseOverEffects();
    void updateHighlightColor();

protected:
    bool event(TQEvent*);
    void closeEvent( TQCloseEvent* e );
    void paintEvent(TQPaintEvent*);
    void leaveEvent(TQEvent*);

    void arrange(KPanelExtension::Position p, KPanelExtension::Alignment a, int XineramaScreen);
    bool autoHidden() const { return _autoHidden; };
    UserHidden userHidden() const { return _userHidden; };
    void resetLayout();
    bool needsBorder() const;

private slots:
    void unhideTriggered( UnhideTrigger::Trigger t, int XineramaScreen );
    void autoHideTimeout();
    void hideLeft();
    void hideRight();
    void autoHide(bool hide);
    void animatedHide(bool left);
    void updateWindowManager();
    void currentDesktopChanged(int);
    void strutChanged();
    void blockUserInput( bool block );
    void maybeStartAutoHideTimer();
    void stopAutoHideTimer();
    void maintainFocus(bool);

private:
    bool shouldUnhideForTrigger(UnhideTrigger::Trigger t) const;
    void init();
    TQSize initialSize(KPanelExtension::Position p, TQRect workArea) const;
    TQPoint initialLocation(KPanelExtension::Position p, KPanelExtension::Alignment a,
                           int XineramaScreen, const TQSize &s, TQRect workArea,
                           bool autohidden = false, UserHidden userHidden = Unhidden) const;
    void positionChange(KPanelExtension::Position p);
    void alignmentChange(KPanelExtension::Alignment a);
    void xineramaScreenChange(int /*XineramaScreen*/) {}
    int arrangeHideButtons();
    int setupBorderSpace();

    ExtensionSettings m_settings;
    ExtensionContainer::HideMode m_hideMode;
    UnhideTrigger::Trigger m_unhideTriggeredAt;

    // State variables
    bool             _autoHidden;
    UserHidden       _userHidden;
    bool             _block_user_input;
    TQPoint           _last_lmb_press;
    bool             _is_lmb_down;
    bool             _in_autohide;

    // Misc objects
    TQTimer               *_autohideTimer;
    TQTimer               *_updateLayoutTimer;
    NETExtendedStrut      _strut;
    PopupWidgetFilter    *_popupWidgetFilter;

    TQString               _id;
    PanelExtensionOpMenu *_opMnu;
    AppletInfo            _info;
    KPanelExtension::Type _type;

    // Widgets
    HideButton     *_ltHB; // Left Hide Button
    HideButton     *_rbHB; // Right Hide Button
    TQGridLayout   *_layout;
    TQWidget       *_resizeHandle; 

    KPanelExtension *m_extension;
    int m_maintainFocus;
    int m_panelOrder;
    TQColor m_highlightColor;
};

class PopupWidgetFilter : public TQObject
{
  Q_OBJECT

  public:
    PopupWidgetFilter( TQObject *parent );
    ~PopupWidgetFilter() {}
    bool eventFilter( TQObject *obj, TQEvent* e );
  signals:
    void popupWidgetHiding();
};

typedef TQValueList<ExtensionContainer*> ExtensionList;

#endif