Back to index

lightning-sunbird  0.9+nobinonly
nsScrollbar.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  *  Zack Rusin <zack@kde.org>.
00020  * Portions created by the Initial Developer are Copyright (C) 2004
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Lars Knoll <knoll@kde.org>
00025  *   Zack Rusin <zack@kde.org>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either the GNU General Public License Version 2 or later (the "GPL"), or
00029  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 #include "nsScrollbar.h"
00041 #include "nsGUIEvent.h"
00042 
00043 #define mScroll  ((QScrollBar*)mWidget)
00044 
00045 nsQScrollBar::nsQScrollBar(int aMinValue, int aMaxValue, int aLineStep,
00046                            int aPageStep, int aValue, Orientation aOrientation,
00047                            QWidget *aParent, const char *aName)
00048     : QScrollBar(aMinValue, aMaxValue, aLineStep, aPageStep, aValue,
00049                  aOrientation, aParent, aName)
00050 {
00051     qDebug("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
00052     connect(this,SIGNAL(valueChanged(int)),
00053             SLOT(slotValueChanged(int)));
00054 }
00055 
00056 void nsQScrollBar::slotValueChanged(int aValue)
00057 {
00058     ScrollBarMoved(NS_SCROLLBAR_POS,aValue);
00059 }
00060 
00061 void nsQScrollBar::ScrollBarMoved(int aMessage,int aValue)
00062 {
00063     nsScrollbarEvent nsEvent(PR_TRUE, aMessage, nsnull);
00064 
00065     nsEvent.eventStructType = NS_SCROLLBAR_EVENT;
00066     nsEvent.position        = aValue;
00067 
00068     //mReceiver->scrollEvent(nsEvent,aValue);
00069     //FIXME:
00070 }
00071 
00072 //=============================================================================
00073 // nsScrollBar class
00074 //=============================================================================
00075 NS_IMPL_ADDREF_INHERITED(nsNativeScrollbar,nsCommonWidget)
00076 NS_IMPL_RELEASE_INHERITED(nsNativeScrollbar,nsCommonWidget)
00077 NS_IMPL_QUERY_INTERFACE2(nsNativeScrollbar,nsINativeScrollbar,nsIWidget)
00078 
00079 nsNativeScrollbar::nsNativeScrollbar()
00080     : nsCommonWidget(),
00081       nsINativeScrollbar()
00082 {
00083 
00084     qDebug("YESSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
00085     mOrientation = true ? QScrollBar::Vertical : QScrollBar::Horizontal;
00086     mLineStep = 1;
00087     mPageStep = 10;
00088     mMaxValue = 100;
00089     mValue    = 0;
00090     mListenForResizes = PR_TRUE;
00091 }
00092 
00093 nsNativeScrollbar::~nsNativeScrollbar()
00094 {
00095 }
00096 
00097 NS_METHOD
00098 nsNativeScrollbar::SetMaxRange(PRUint32 aEndRange)
00099 {
00100     mMaxValue = aEndRange;
00101 
00102     mScroll->setRange(0,mMaxValue - mPageStep);
00103 
00104     return NS_OK;
00105 }
00106 
00107 NS_METHOD
00108 nsNativeScrollbar::GetMaxRange(PRUint32 *aMaxRange)
00109 {
00110     *aMaxRange = mMaxValue;
00111     return NS_OK;
00112 }
00113 
00114 NS_METHOD nsNativeScrollbar::SetPosition(PRUint32 aPos)
00115 {
00116     mValue = aPos;
00117 
00118     mScroll->setValue(mValue);
00119 
00120     return NS_OK;
00121 }
00122 
00123 NS_METHOD
00124 nsNativeScrollbar::GetPosition(PRUint32 *aPos)
00125 {
00126     *aPos = mValue;
00127     return NS_OK;
00128 }
00129 
00130 //-------------------------------------------------------------------------
00131 // Set the line increment for this scrollbar
00132 //-------------------------------------------------------------------------
00133 NS_METHOD
00134 nsNativeScrollbar::SetLineIncrement(PRUint32 aLineIncrement)
00135 {
00136     if (aLineIncrement > 0) {
00137         mLineStep = aLineIncrement;
00138 
00139         mScroll->setSteps(mLineStep,mPageStep);
00140     }
00141     return NS_OK;
00142 }
00143 
00144 //-------------------------------------------------------------------------
00145 // Get the line increment for this scrollbar
00146 //-------------------------------------------------------------------------
00147 NS_METHOD
00148 nsNativeScrollbar::GetLineIncrement(PRUint32 *aLineInc)
00149 {
00150     *aLineInc = mLineStep;
00151     return NS_OK;
00152 }
00153 
00154 #if 0
00155 NS_METHOD
00156 nsNativeScrollbar::SetParameters(PRUint32 aMaxRange,PRUint32 aThumbSize,
00157                            PRUint32 aPosition,PRUint32 aLineIncrement)
00158 {
00159     mPageStep = (aThumbSize > 0) ? aThumbSize : 1;
00160     mValue    = (aPosition > 0) ? aPosition : 0;
00161     mLineStep = (aLineIncrement > 0) ? aLineIncrement : 1;
00162     mMaxValue = (aMaxRange > 0) ? aMaxRange : 10;
00163 
00164     mScroll->setValue(mValue);
00165     mScroll->setSteps(mLineStep,mPageStep);
00166     mScroll->setRange(0,mMaxValue - mPageStep);
00167     return NS_OK;
00168 }
00169 #endif
00170 
00171 //-------------------------------------------------------------------------
00172 // Deal with scrollbar messages (actually implemented only in nsNativeScrollbar)
00173 //-------------------------------------------------------------------------
00174 PRBool nsNativeScrollbar::OnScroll(nsScrollbarEvent &aEvent,PRUint32 cPos)
00175 {
00176     nsEventStatus result = nsEventStatus_eIgnore;
00177 
00178     switch (aEvent.message) {
00179         // scroll one line right or down
00180     case NS_SCROLLBAR_LINE_NEXT:
00181         mScroll->addLine();
00182         mValue = mScroll->value();
00183 
00184         // if an event callback is registered, give it the chance
00185         // to change the increment
00186         if (mEventCallback) {
00187             aEvent.position = (PRUint32)mValue;
00188             result = (*mEventCallback)(&aEvent);
00189             mValue = aEvent.position;
00190         }
00191         break;
00192 
00193         // scroll one line left or up
00194     case NS_SCROLLBAR_LINE_PREV:
00195         mScroll->subtractLine();
00196         mValue = mScroll->value();
00197 
00198         // if an event callback is registered, give it the chance
00199         // to change the decrement
00200         if (mEventCallback) {
00201             aEvent.position = (PRUint32)mValue;
00202             result = (*mEventCallback)(&aEvent);
00203             mValue = aEvent.position;
00204         }
00205         break;
00206 
00207         // Scrolls one page right or down
00208     case NS_SCROLLBAR_PAGE_NEXT:
00209         mScroll->addPage();
00210         mValue = mScroll->value();
00211 
00212         // if an event callback is registered, give it the chance
00213         // to change the increment
00214         if (mEventCallback) {
00215             aEvent.position = (PRUint32)mValue;
00216             result = (*mEventCallback)(&aEvent);
00217             mValue = aEvent.position;
00218         }
00219         break;
00220 
00221         // Scrolls one page left or up.
00222     case NS_SCROLLBAR_PAGE_PREV:
00223         mScroll->subtractPage();
00224         mValue = mScroll->value();
00225 
00226         // if an event callback is registered, give it the chance
00227         // to change the increment
00228         if (mEventCallback) {
00229             aEvent.position = (PRUint32)mValue;
00230             result = (*mEventCallback)(&aEvent);
00231             mValue = aEvent.position;
00232         }
00233         break;
00234 
00235         // Scrolls to the absolute position. The current position is specified by
00236         // the cPos parameter.
00237     case NS_SCROLLBAR_POS:
00238         mValue = cPos;
00239 
00240         // if an event callback is registered, give it the chance
00241         // to change the increment
00242         if (mEventCallback) {
00243             aEvent.position = (PRUint32)mValue;
00244             result = (*mEventCallback)(&aEvent);
00245             mValue = aEvent.position;
00246         }
00247         break;
00248     }
00249 
00250     return ignoreEvent(result);
00251 }
00252 
00253 QWidget*
00254 nsNativeScrollbar::createQWidget(QWidget *parent, nsWidgetInitData */*aInitData*/)
00255 {
00256     mWidget =  new nsQScrollBar(0, mMaxValue, mLineStep, mPageStep,
00257                                 mValue, mOrientation, parent);
00258     mWidget->setMouseTracking(PR_TRUE);
00259 
00260     return mWidget;
00261 }
00262 
00263 /* void setContent (in nsIContent content, in nsISupports scrollbar, in nsIScrollbarMediator mediator); */
00264 NS_IMETHODIMP
00265 nsNativeScrollbar::SetContent(nsIContent *content, nsISupports *scrollbar, nsIScrollbarMediator *mediator)
00266 {
00267     qDebug("XXXXXXXX SetContent");
00268     return NS_ERROR_NOT_IMPLEMENTED;
00269 }
00270 
00271 /* readonly attribute long narrowSize; */
00272 NS_IMETHODIMP
00273 nsNativeScrollbar::GetNarrowSize(PRInt32 *aNarrowSize)
00274 {
00275     qDebug("XXXXXXXXXXXX GetNarrowSize");
00276     return NS_ERROR_NOT_IMPLEMENTED;
00277 }
00278 /* attribute unsigned long viewSize; */
00279 NS_IMETHODIMP
00280 nsNativeScrollbar::GetViewSize(PRUint32 *aViewSize)
00281 {
00282     qDebug("XXXXXXXXX GetViewSize");
00283     return NS_ERROR_NOT_IMPLEMENTED;
00284 }
00285 NS_IMETHODIMP
00286 nsNativeScrollbar::SetViewSize(PRUint32 aViewSize)
00287 {
00288     qDebug("XXXXXXXXXXX SetViewSize");
00289     return NS_ERROR_NOT_IMPLEMENTED;
00290 }