summaryrefslogtreecommitdiffstats
path: root/twin-styles/icewm/icewm.h
blob: a023d3416c4e5f0134fe610db0787b56cce9e2dd (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
/*
  $Id$

  Gallium-IceWM themeable KWin client

  Copyright 2001
	Karol Szwed <gallium@kde.org>
	http://gallium.n3.net/

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; see the file COPYING.  If not, write to
  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  Boston, MA 02110-1301, USA.

  -----------------------------------------------------------------------------
  This client loads most icewm 1.0.X pixmap themes, without taking into account
  specific font settings for clients, or coloured mouse cursors. Titlebar
  fonts can be changed via the kde control center. Bi-colour mouse cursors
  may be added in future if requested by users, as well as theme font support.
  Any styles using inbuilt icewm titlebar drawing without using pixmaps (e.g.
  Warp4, win95 etc.) are not fully supported, and may cause drawing errors,
  as these themes use in-built icewm drawing mechanisms.

  When a pixmap theme is not present (or a corrupt one is present) then very
  plain title decorations are painted instead, so that users don't see
  non-painted window areas where possible ;)

  At a later date, frame shaping may be added if really requested, and an
  update to support the latest icewm 1.1.X theme format may be made.
*/

#ifndef __TDEGALLIUM_ICEWM_H
#define __TDEGALLIUM_ICEWM_H

#include <tqbutton.h>
#include <tqlayout.h>
#include <kpixmap.h>
#include <kdecoration.h>
#include <kdecorationfactory.h>
#include <tqbutton.h>
class TQLabel;
class TQSpacerItem;
class TQBoxLayout;
class TQGridLayout;

namespace IceWM {

class IceWMClient;

// Pixmap group
enum { InActive=0, Active };
// Pixmap stretching mode
enum { Vertical=0, Horizontal=1 };


// Handles the resetClients() signal from the Options class,
// and manages the dynamic pixmaps, configuration and theme changing
class ThemeHandler: public KDecorationFactory
{
	public:
		ThemeHandler();
		~ThemeHandler();

		virtual KDecoration* createDecoration( KDecorationBridge* );
		virtual bool reset( unsigned long changed );
		virtual bool supports( Ability ability );

	private:
		bool initialized;
		TQString themeName;

		void readConfig();
		TQColor decodeColor( TQString& s );
		bool isFrameValid();
		void initTheme();
		void freePixmaps();
		void freePixmapGroup( TQPixmap* p[] );
		void setPixmap( TQPixmap* p[], TQString s1, TQString s2, bool
						stretch=false, bool stretchHoriz=true );
		void setPixmapButton( TQPixmap* p[], TQString s1, TQString s2);
		TQPixmap* stretchPixmap( TQPixmap* src, bool stretchHoriz=true,
								int stretchSize=-1);
		TQPixmap* duplicateValidPixmap( bool act, int size = -1 );
		void convertButtons( TQString& s );
		TQString reverseString( TQString s );
};


class IceWMButton : public TQButton
{
	public:
		IceWMButton( IceWMClient *parent=0, const char *name=0,
					 TQPixmap* (*p)[2]=0L, bool isToggle=false,
					 const TQString& tip=NULL, const int realizeBtns = Qt::LeftButton );
		void setTipText(const TQString &tip);
		void  usePixmap( TQPixmap* (*p)[2] );
		TQSize sizeHint() const;
		void  turnOn( bool isOn );
		ButtonState   last_button;

	protected:
		void mousePressEvent( TQMouseEvent* e );
		void mouseReleaseEvent( TQMouseEvent* e );

		void drawButton( TQPainter *p );
		void drawButtonLabel( TQPainter * ) {;}

	private:
		int m_realizeButtons;
		IceWMClient* client;
		TQPixmap* (*pix)[2]; // Points to active/inactive pixmap array
};


class IceWMClient : public KDecoration
{
    Q_OBJECT
  
	public:
	    IceWMClient( KDecorationBridge* bridge, KDecorationFactory* factory );
	    ~IceWMClient();

		virtual void init();
		virtual void resize(const TQSize&);
		virtual bool eventFilter( TQObject* o, TQEvent* e );

	protected:
	    void resizeEvent( TQResizeEvent* );
	    void paintEvent( TQPaintEvent* );
	    void showEvent( TQShowEvent* );
	    void mouseDoubleClickEvent( TQMouseEvent * );
	    void wheelEvent( TQWheelEvent * );
	    virtual void captionChange();
	    virtual void maximizeChange();
	    virtual void shadeChange();
	    virtual void activeChange();
	//	void shadeChange(bool);     /* KWin Client class doesn't provide this yet */
	    Position mousePosition( const TQPoint& ) const;
		void renderMenuIcons();
		void iconChange();
		virtual void desktopChange( );
		virtual void borders(int&, int&, int&, int&) const;
		virtual TQSize minimumSize() const;

	protected slots:
	    void slotMaximize();
	    void menuButtonPressed();
	    void menuButtonReleased();
	    void toggleShade();

	private:
	    // These are all the icewm button types :)
	    enum Buttons{ BtnSysMenu=0, BtnClose, BtnMaximize, BtnMinimize,
					  BtnHide, BtnRollup, BtnDepth, BtnCount };

		TQString shortenCaption( const TQString* s );
		void calcHiddenButtons();
	    int  titleTextWidth( const TQString& s );
		void addClientButtons( const TQString& s );
		TQSpacerItem* addPixmapSpacer( TQPixmap* p[],
			TQSizePolicy::SizeType = TQSizePolicy::Maximum, int hsize = -1 );

	    IceWMButton* button[ IceWMClient::BtnCount ];
	    TQPixmap*     menuButtonWithIconPix[2];
	    TQSpacerItem* titleSpacerJ;
	    TQSpacerItem* titleSpacerL;
	    TQSpacerItem* titleSpacerS;
	    TQSpacerItem* titleSpacerP;
	    TQSpacerItem* titlebar;
	    TQSpacerItem* titleSpacerM;
	    TQSpacerItem* titleSpacerB;
    	TQSpacerItem* titleSpacerR;
	    TQSpacerItem* titleSpacerQ;
	    TQBoxLayout*  hb;
	    TQGridLayout* grid;
	    bool m_closing;
};

}

#endif

// vim: ts=4