summaryrefslogtreecommitdiffstats
path: root/src/kernel/qstyle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/qstyle.cpp')
-rw-r--r--src/kernel/qstyle.cpp391
1 files changed, 381 insertions, 10 deletions
diff --git a/src/kernel/qstyle.cpp b/src/kernel/qstyle.cpp
index 3a3a2775c..d100d5f1e 100644
--- a/src/kernel/qstyle.cpp
+++ b/src/kernel/qstyle.cpp
@@ -44,6 +44,10 @@
#include "ntqpainter.h"
#include "ntqbitmap.h"
#include "ntqpixmapcache.h"
+#include "ntqframe.h"
+#include "ntqlayout.h"
+#include "ntqobjectlist.h"
+#include "ntqwidgetlist.h"
#include <limits.h>
@@ -394,6 +398,10 @@ public:
*/
TQStyle::TQStyle()
{
+ m_eventHandlerInstallationHook = NULL;
+ m_eventHandlerRemovalHook = NULL;
+ m_widgetActionRequestHook = NULL;
+ conditionalAcceleratorsEnabled = false;
d = new TQStylePrivate;
}
@@ -414,8 +422,6 @@ TQStyle::~TQStyle()
style. Current supported values are TQt::WindowsStyle and TQt::MotifStyle.
*/
-
-
/*!
Initializes the appearance of a widget.
@@ -439,8 +445,9 @@ TQStyle::~TQStyle()
\sa unPolish()
*/
-void TQStyle::polish( TQWidget*)
-{
+void TQStyle::polish( TQWidget *widget ) {
+ TQStyleControlElementData ceData = populateControlElementDataFromWidget(widget, TQStyleOption());
+ polish(ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, TQStyleOption()), widget);
}
/*!
@@ -453,10 +460,62 @@ void TQStyle::polish( TQWidget*)
\sa polish()
*/
-void TQStyle::unPolish( TQWidget*)
-{
+void TQStyle::unPolish( TQWidget *widget ) {
+ TQStyleControlElementData ceData = populateControlElementDataFromWidget(widget, TQStyleOption());
+ unPolish(ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, TQStyleOption()), widget);
+}
+
+/*!
+ Initializes the appearance of a widget.
+
+ This function is called for every widget at some point after it
+ has been fully created but just \e before it is shown the very
+ first time.
+
+ Reasonable actions in this function might be to install a widget
+ event handler for the style. An example of highly unreasonable
+ use would be setting the geometry! With TQt 3.0's style engine
+ you will rarely need to write your own polish(); instead reimplement
+ drawItem(), drawPrimitive(), etc.
+
+ The \a objectTypes object may provide enough information to
+ allow class-specific customizations. But be careful not to
+ hard-code things too much because new TQStyle subclasses are
+ expected to work reasonably with all current and \e future
+ widgets.
+
+ You may specify either a TQWidget pointer or a custom pointer.
+ If a custom pointer is specified, you must be careful to intercept any event
+ handler installation/removal calls via setEventHandlerInstallationHook and
+ setEventHandlerRemovalHook.
+
+ \sa unPolish()
+*/
+void TQStyle::polish( TQStyleControlElementData ceData, ControlElementFlags, void *ptr ) {
+ if (ceData.widgetObjectTypes.contains("TQWidget")) {
+ // Enable dynamic hide/show of accelerator shortcuts
+ TQWidget* widget = reinterpret_cast<TQWidget*>(ptr);
+ widget->installEventFilter(this);
+ }
}
+/*!
+ Undoes the initialization of a widget's appearance.
+
+ This function is the counterpart to polish. It is called for every
+ polished widget when the style is dynamically changed. The former
+ style has to unpolish its settings before the new style can polish
+ them again.
+
+ \sa polish()
+*/
+void TQStyle::unPolish( TQStyleControlElementData ceData, ControlElementFlags, void *ptr ) {
+ if (ceData.widgetObjectTypes.contains("TQWidget")) {
+ // Disable dynamic hide/show of accelerator shortcuts
+ TQWidget* widget = reinterpret_cast<TQWidget*>(ptr);
+ widget->installEventFilter(this);
+ }
+}
/*!
\overload
@@ -464,8 +523,10 @@ void TQStyle::unPolish( TQWidget*)
\sa unPolish()
*/
-void TQStyle::polish( TQApplication*)
-{
+void TQStyle::polish( TQApplication *app ) {
+ TQStyleControlElementData ceData;
+ ceData.widgetObjectTypes = getObjectTypeListForObject(app);
+ applicationPolish(ceData, getControlElementFlagsForObject(app, ceData.widgetObjectTypes, TQStyleOption()), app);
}
/*!
@@ -475,8 +536,41 @@ void TQStyle::polish( TQApplication*)
\sa polish()
*/
-void TQStyle::unPolish( TQApplication*)
-{
+void TQStyle::unPolish( TQApplication *app ) {
+ TQStyleControlElementData ceData;
+ ceData.widgetObjectTypes = getObjectTypeListForObject(app);
+ applicationUnPolish(ceData, getControlElementFlagsForObject(app, ceData.widgetObjectTypes, TQStyleOption()), app);
+}
+
+/*!
+ \overload
+ Late initialization of the TQApplication object or other global application object.
+
+ You may specify either a TQApplication pointer or a custom pointer.
+ If a custom pointer is specified, you must be careful to intercept any event
+ handler installation/removal calls via setEventHandlerInstallationHook and
+ setEventHandlerRemovalHook.
+
+ \sa unPolish()
+*/
+void TQStyle::applicationPolish( TQStyleControlElementData, ControlElementFlags, void * ) {
+ //
+}
+
+/*!
+ \overload
+
+ Undoes the application polish.
+
+ You may specify either a TQApplication pointer or a custom pointer.
+ If a custom pointer is specified, you must be careful to intercept any event
+ handler installation/removal calls via setEventHandlerInstallationHook and
+ setEventHandlerRemovalHook.
+
+ \sa polish()
+*/
+void TQStyle::applicationUnPolish( TQStyleControlElementData, ControlElementFlags, void * ) {
+ //
}
/*!
@@ -1958,6 +2052,283 @@ TQRect TQStyle::visualRect( const TQRect &logical, const TQRect &boundingRect )
}
/*!
+ \fn void TQStyle::installObjectEventHandler( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQStyle* handler );
+
+ Intercepts events generated by \a source and sends them to \a handler via
+ the bool TQStyle::objectEventHandler( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQEvent *e ) virtual method.
+
+ \sa void TQStyle::removeObjectEventHandler( TQObject* source, TQStyle* handler )
+ \sa bool TQStyle::objectEventHandler( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQEvent *e )
+*/
+void TQStyle::installObjectEventHandler( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQStyle* handler ) {
+ bool cbret = false;
+ if (m_eventHandlerInstallationHook) {
+ cbret = (*m_eventHandlerInstallationHook)(ceData, elementFlags, source, handler);
+ }
+ if (!cbret) {
+ if (ceData.widgetObjectTypes.contains("TQObject")) {
+ TQObject* o = reinterpret_cast<TQObject*>(source);
+ o->installEventFilter(this);
+ m_objectEventSourceToHandlerMap[source] = handler;
+ m_objectEventSourceDataToHandlerMap[source] = ceData;
+ m_objectEventSourceFlagsToHandlerMap[source] = elementFlags;
+ }
+ }
+}
+
+/*!
+ \fn void TQStyle::removeObjectEventHandler( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQStyle* handler );
+
+ Stops intercepting events generated by \a source.
+
+ \sa void TQStyle::installObjectEventHandler( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQStyle* handler )
+*/
+void TQStyle::removeObjectEventHandler( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQStyle* handler ) {
+ bool cbret = false;
+ if (m_eventHandlerRemovalHook) {
+ cbret = (*m_eventHandlerRemovalHook)(ceData, elementFlags, source, handler);
+ }
+ if (!cbret) {
+ if (ceData.widgetObjectTypes.contains("TQObject")) {
+ TQObject* o = reinterpret_cast<TQObject*>(source);
+ m_objectEventSourceToHandlerMap.remove(source);
+ m_objectEventSourceDataToHandlerMap.remove(source);
+ m_objectEventSourceFlagsToHandlerMap.remove(source);
+ o->removeEventFilter(this);
+ }
+ }
+}
+
+/*!
+ \fn void TQStyle::setEventHandlerInstallationHook( EventHandlerInstallationHook hook );
+
+ Sets a callback function \a hook which will be called whenever a new intercept request
+ is made via the TQStyle::installObjectEventHandler method. The callback function must
+ use this definition: bool callbackFunction( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQStyle* handler ).
+
+ \sa void TQStyle::installObjectEventHandler( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQStyle* handler )
+*/
+void TQStyle::setEventHandlerInstallationHook( EventHandlerInstallationHook hook ) {
+ m_eventHandlerInstallationHook = hook;
+}
+
+/*!
+ \fn void TQStyle::setEventHandlerRemovalHook( EventHandlerRemovalHook hook );
+
+ Sets a callback function \a hook which will be called whenever a new intercept deactivation request
+ is made via the TQStyle::removeObjectEventHandler method. The callback function must
+ use this definition: bool callbackFunction( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQStyle* handler ).
+
+ \sa void TQStyle::removeObjectEventHandler( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQStyle* handler )
+*/
+void TQStyle::setEventHandlerRemovalHook( EventHandlerRemovalHook hook ) {
+ m_eventHandlerRemovalHook = hook;
+}
+
+/*!
+ \fn bool TQStyle::objectEventHandler( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQEvent *e );
+
+ Override this virtual function to intercept events requested by a previous call to
+ TQStyle::installObjectEventHandler.
+
+ \sa void TQStyle::installObjectEventHandler( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQStyle* handler )
+ \sa void TQStyle::removeObjectEventHandler( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQStyle* handler )
+*/
+bool TQStyle::objectEventHandler( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQEvent *e ) {
+ Q_UNUSED(ceData);
+ Q_UNUSED(elementFlags);
+ Q_UNUSED(source);
+ Q_UNUSED(e);
+ return false;
+}
+
+/*!
+ \fn bool TQStyle::eventFilter(TQObject *o, TQEvent *e);
+ \internal
+*/
+bool TQStyle::eventFilter(TQObject *o, TQEvent *e) {
+ acceleratorKeypressEventMonitor(o, e);
+
+ if (m_objectEventSourceToHandlerMap.contains(o)) {
+ TQStyle* handler = m_objectEventSourceToHandlerMap[o];
+ TQStyleControlElementData ceData = m_objectEventSourceDataToHandlerMap[o];
+ ControlElementFlags elementFlags = m_objectEventSourceFlagsToHandlerMap[o];
+ bool ret = handler->objectEventHandler(ceData, elementFlags, o, e);
+ if (ret) {
+ return ret;
+ }
+ else {
+ return TQObject::eventFilter(o, e);
+ }
+ }
+ else {
+ return TQObject::eventFilter(o, e);
+ }
+}
+
+/*!
+ \fn void TQStyle::setWidgetActionRequestHook( WidgetActionRequestHook hook );
+
+ Sets a callback function \a hook which will be called whenever a new widget action request
+ is made via the TQStyle::installObjectEventHandler method. The callback function must
+ use this definition: bool callbackFunction( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQStyle* handler ).
+
+ \sa void TQStyle::installObjectEventHandler( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, TQStyle* handler )
+*/
+void TQStyle::setWidgetActionRequestHook( WidgetActionRequestHook hook ) {
+ m_widgetActionRequestHook = hook;
+}
+
+/*!
+ \fn bool widgetActionRequestHandler( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, WidgetActionRequest request );
+
+ Handles widget action requests. Return FALSE to continue processing in base classes, TRUE to eat the request and halt processing.
+*/
+bool TQStyle::widgetActionRequest( TQStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, WidgetActionRequest request, TQStyleWidgetActionRequestData requestData ) {
+ bool cbret = false;
+ if (m_widgetActionRequestHook) {
+ cbret = (*m_widgetActionRequestHook)(ceData, elementFlags, source, request, requestData);
+ }
+ if (!cbret) {
+ if (ceData.widgetObjectTypes.contains("TQWidget")) {
+ TQWidget* widget = reinterpret_cast<TQWidget*>(source);
+ if (request == WAR_Repaint) {
+ widget->repaint(FALSE);
+ }
+ else if (request == WAR_RepaintRect) {
+ widget->repaint(requestData.rect, FALSE);
+ }
+ else if (request == WAR_EnableMouseTracking) {
+ widget->setMouseTracking(TRUE);
+ }
+ else if (request == WAR_DisableMouseTracking) {
+ widget->setMouseTracking(FALSE);
+ }
+ else if (request == WAR_FrameSetStyle) {
+ TQFrame* frame = dynamic_cast<TQFrame*>(widget);
+ if (frame) {
+ frame->setFrameStyle(requestData.metric1);
+ }
+ }
+ else if (request == WAR_FrameSetLineWidth) {
+ TQFrame* frame = dynamic_cast<TQFrame*>(widget);
+ if (frame) {
+ frame->setLineWidth(requestData.metric1);
+ }
+ }
+ else if (request == WAR_SetLayoutMargin) {
+ TQLayout* layout = widget->layout();
+ if (layout) {
+ layout->setMargin(requestData.metric1);
+ }
+ }
+ else if (request == WAR_SetPalette) {
+ widget->setPalette(requestData.palette);
+ }
+ else if (request == WAR_SetBackgroundMode) {
+ widget->setBackgroundMode((TQt::BackgroundMode)requestData.metric1);
+ }
+ else if (request == WAR_SetFont) {
+ widget->setFont(requestData.font);
+ }
+ else if (request == WAR_RepaintAllAccelerators) {
+ TQWidgetList *list = TQApplication::topLevelWidgets();
+ TQWidgetListIt it( *list );
+ TQWidget * widget;
+ while ((widget=it.current()) != 0) {
+ ++it;
+
+ TQObjectList *l = widget->queryList("TQWidget");
+ TQObjectListIt it2( *l );
+ TQWidget *w;
+ while ( (w = (TQWidget*)it2.current()) != 0 ) {
+ ++it2;
+ if (w->isTopLevel() || !w->isVisible() || w->style().styleHint(SH_UnderlineAccelerator, TQStyleControlElementData(), CEF_None, w)) {
+ l->removeRef(w);
+ }
+ }
+
+ // Repaint all relevant widgets
+ it2.toFirst();
+ while ( (w = (TQWidget*)it2.current()) != 0 ) {
+ ++it2;
+ w->repaint(FALSE);
+ }
+ delete l;
+ }
+ delete list;
+ }
+ return true;
+ }
+ }
+ return true;
+}
+
+void TQStyle::acceleratorKeypressEventMonitor( TQObject *o, TQEvent *e ) {
+ // RAJA FIXME
+ // Also, SH_HideUnderlineAcceleratorWhenAltUp should probably be set to 1 in the TQWindowsStyle::styleHint overridden method
+ // Additionally, the common styleHint code in TDE (that controls popupmenu settings and such via configuration files) needs to be modified to add a config option for this new style hint
+
+ if (styleHint(SH_HideUnderlineAcceleratorWhenAltUp, TQStyleControlElementData(), CEF_None, TQStyleOption::Default, NULL, NULL) != 0) {
+ TQWidget *widget = dynamic_cast<TQWidget*>(o);
+ if (widget) {
+ switch(e->type()) {
+ case TQEvent::KeyPress:
+ if (((TQKeyEvent*)e)->key() == Key_Alt) {
+ conditionalAcceleratorsEnabled = true;
+ widgetActionRequest(TQStyleControlElementData(), CEF_None, o, WAR_RepaintAllAccelerators);
+ }
+ break;
+ case TQEvent::KeyRelease:
+ if (((TQKeyEvent*)e)->key() == Key_Alt) {
+ conditionalAcceleratorsEnabled = false;
+ widgetActionRequest(TQStyleControlElementData(), CEF_None, o, WAR_RepaintAllAccelerators);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ else {
+ conditionalAcceleratorsEnabled = false;
+ }
+}
+
+bool TQStyle::acceleratorsShown() const {
+ if (styleHint(SH_HideUnderlineAcceleratorWhenAltUp, TQStyleControlElementData(), CEF_None, TQStyleOption::Default, NULL, NULL) != 0) {
+ return conditionalAcceleratorsEnabled;
+ }
+ else {
+ return true;
+ }
+}
+
+TQStyleWidgetActionRequestData::TQStyleWidgetActionRequestData() {
+ //
+}
+TQStyleWidgetActionRequestData::TQStyleWidgetActionRequestData(int param1, int param2) {
+ metric1 = param1;
+ metric2 = param2;
+}
+
+TQStyleWidgetActionRequestData::TQStyleWidgetActionRequestData(TQPalette param) {
+ palette = param;
+}
+
+TQStyleWidgetActionRequestData::TQStyleWidgetActionRequestData(TQFont param) {
+ font = param;
+}
+
+TQStyleWidgetActionRequestData::TQStyleWidgetActionRequestData(TQRect param) {
+ rect = param;
+}
+
+TQStyleWidgetActionRequestData::~TQStyleWidgetActionRequestData() {
+ //
+}
+
+/*!
\fn int TQStyle::defaultFrameWidth() const
\obsolete
*/