Ignore:
Timestamp:
Jul 10, 2009, 11:37:08 PM (16 years ago)
Author:
lpino
Message:
  • Fix a lot of bugs
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/org.eclipse.swt/Eclipse SWT/pm/org/eclipse/swt/widgets/TabFolder.java

    r106 r165  
    4444public class TabFolder extends Composite {
    4545        TabItem [] items;
     46        int[] itemsID;
     47        int iLongestMajText = 0;
    4648//      ImageList imageList;
    4749        static final int TabFolderProc;
     
    165167//public Point computeSize (int wHint, int hHint, boolean changed) {
    166168//      checkWidget ();
     169//      RECTL rcl = new RECTL ();
     170//      RECTL insetRect = new RECTL ();
     171//      WinQueryWindowPos(hwndDialog, &swpDialog);
     172//      OS.WinQueryWindowPos(handle, rcl);
     173//      insetRect.yBottom=insetRect.xLeft=0;
     174//      insetRect.xRight=rcl.cx;
     175//      insetRect.yTop=rcl.cy;
     176//      Return size of notebook page in pixel for given notebook window size (with tab text size set)
     177
     178//      OS.WinSendMsg(hwndNotebook, BKM_CALCPAGERECT, insetRect, true);
     179//      Calculate notebook size so that notebook dialog page fits into the notebook page
     180
     181//      swpNB.cx-=(rectlNB.xRight-rectlNB.xLeft)-ptlNB.x;
     182//      swpNB.cy-=(rectlNB.yTop-rectlNB.yBottom)-ptlNB.y;
     183//
     184
    167185//      RECT insetRect = new RECT (), itemRect = new RECT ();
     186//      OS.WinSendMsg (handle, OS.BKM_CALCPAGERECT, rcl, false);
    168187//      OS.SendMessage (handle, OS.TCM_ADJUSTRECT, 0, insetRect);
    169188//      int width = insetRect.left - insetRect.right, height = 0;
     
    208227        if (count == items.length) {
    209228                TabItem [] newItems = new TabItem [items.length + 4];
     229                int[] newIDs = new int[itemsID.length + 4];
    210230                System.arraycopy (items, 0, newItems, 0, items.length);
     231                System.arraycopy (itemsID, 0, newIDs, 0, itemsID.length);
    211232                items = newItems;
     233                itemsID = newIDs;
    212234        }
    213235//        PSZ tabText = new PSZ("Hello");
    214          int pageID = OS.WinSendMsg (handle, OS.BKM_INSERTPAGE, 0, OS.MPFROM2SHORT((short)(OS.BKA_AUTOPAGESIZE | OS.BKA_MAJOR | OS.BKA_STATUSTEXTON),(short)OS.BKA_FIRST));
     236         int pageID = OS.WinSendMsg (handle, OS.BKM_INSERTPAGE, 0, OS.MPFROM2SHORT((short)(OS.BKA_AUTOPAGESIZE | OS.BKA_MAJOR | OS.BKA_STATUSTEXTON),(short)OS.BKA_LAST));
     237         //@@INFO(lpino): All tabs are gray to keep a consistent look with the rests of the platforms
     238         OS.WinSendMsg (handle, OS.BKM_SETTABCOLOR, pageID , 0x00C0C0C0);
    215239//         OS.WinSendMsg (handle, OS.BKM_SETTABTEXT, pageID, tabText);
    216 //      if (pageID == 0) {
    217 //              error (SWT.ERROR_ITEM_NOT_ADDED);
    218 //      }
     240        if (pageID == OS.NULLHANDLE) {
     241                error (SWT.ERROR_ITEM_NOT_ADDED);
     242        }
    219243        System.arraycopy (items, index, items, index + 1, count - index);
     244        System.arraycopy (itemsID, index, itemsID, index + 1, count - index);
     245        itemsID[index] = pageID;
    220246        items [index] = item;
    221247       
     
    236262        super.createHandle ();
    237263        state &= ~CANVAS;
    238        
    239 //      /*
    240 //      * Feature in Windows.  Despite the fact that the
    241 //      * tool tip text contains \r\n, the tooltip will
    242 //      * not honour the new line unless TTM_SETMAXTIPWIDTH
    243 //      * is set.  The fix is to set TTM_SETMAXTIPWIDTH to
    244 //      * a large value.
    245 //      */
    246 //      int hwndToolTip = OS.SendMessage (handle, OS.TCM_GETTOOLTIPS, 0, 0);
    247 //      OS.SendMessage (hwndToolTip, OS.TTM_SETMAXTIPWIDTH, 0, 0x7FFF);
    248 //     
    249 //      /*
    250 //      * Feature in Windows.  When the tool tip control is
    251 //      * created, the parent of the tool tip is the shell.
    252 //      * If SetParent () is used to reparent the tab folder
    253 //      * into a new shell, the tool tip is not reparented
    254 //      * and pops up underneath the new shell.  The fix is
    255 //      * to make sure the tool tip is a topmost window.
    256 //      */
    257 //      /*
    258 //      * Bug in Windows 98 and NT.  Setting the tool tip to be the
    259 //      * top most window using HWND_TOPMOST can result in a parent
    260 //      * dialog shell being moved behind its parent if the dialog
    261 //      * has a sibling that is currently on top.  The fix is to lock
    262 //      * the z-order of the active window.
    263 //      */
    264 //      Display display = getDisplay ();
    265 //      int flags = OS.SWP_NOACTIVATE | OS.SWP_NOMOVE | OS.SWP_NOSIZE;
    266 //      display.lockActiveWindow = true;
    267 //      OS.SetWindowPos (hwndToolTip, OS.HWND_TOPMOST, 0, 0, 0, 0, flags);
    268 //      display.lockActiveWindow = false;
    269264}
    270265
     
    272267        super.createWidget ();
    273268        items = new TabItem [4];
     269        itemsID = new int[4];
    274270}
    275271
     
    282278        }
    283279        if (index == count) return;
    284         int selectionIndex = OS.WinSendMsg (handle, OS.BKM_QUERYPAGEID, 0, OS.MPFROM2SHORT((short)OS.BKA_TOP,(short)OS.BKA_MAJOR));
     280        int selectionIndex = itemsID[index];
    285281        if (OS.WinSendMsg (handle, OS.BKM_DELETEPAGE, selectionIndex, (short)OS.BKA_TAB) == 0) {
    286282                error (SWT.ERROR_ITEM_NOT_REMOVED);
    287283        }
    288284        System.arraycopy (items, index + 1, items, index, --count - index);
     285        System.arraycopy (itemsID, index + 1, itemsID, index, --count - index);
    289286        items [count] = null;
     287        itemsID[count] = 0;
    290288        if (count == 0) {
    291289//              if (imageList != null) {
     
    296294//              imageList = null;
    297295                items = new TabItem [4];
     296                itemsID = new int[4];
    298297        }
    299298        if (count > 0 && index == selectionIndex) {
     
    507506        }
    508507        items = null;
     508        itemsID = null;
    509509//      if (imageList != null) {
    510510//              OS.SendMessage (handle, OS.TCM_SETIMAGELIST, 0, 0);
     
    593593                }
    594594        }
    595         OS.WinSendMsg (handle, OS.BKM_TURNTOPAGE, getPageID(index), 0);
     595        OS.WinSendMsg (handle, OS.BKM_TURNTOPAGE, itemsID[index], 0);
    596596        int newIndex = getSelectionIndex();
    597597        if (newIndex != -1) {
     
    610610}
    611611int getTabIndex(int pageID){
    612     int total = OS.WinSendMsg (handle, OS.BKM_QUERYPAGECOUNT, 0, OS.BKA_MAJOR);
    613     int diff = OS.WinSendMsg (handle, OS.BKM_QUERYPAGECOUNT, pageID, OS.BKA_END);
    614     return total-diff;
     612    for(int i=0;i<itemsID.length;i++){
     613        if(itemsID[i] == pageID)
     614            return i;
     615    }
     616    return -1;
    615617}
    616618
     
    657659
    658660int widgetStyle () {
    659         /*
    660         * Bug in Windows.  Under certain circumstances,
    661         * when TCM_SETITEM is used to change the text
    662         * in a tab item, the tab folder draws on top
    663         * of the client area.  The fix is ensure that
    664         * this cannot happen by setting WS_CLIPCHILDREN.
    665         */
    666661        int bits = super.widgetStyle () | OS.WS_VISIBLE | OS.WS_CLIPCHILDREN | OS.BKS_TABBEDDIALOG | OS.BKS_MAJORTABTOP | OS.WS_CLIPSIBLINGS;   
    667662        return bits;
     
    675670        return TabFolderProc;
    676671}
     672
     673boolean setTabDimensions( PSZ tabText ){
     674        int iSize = 0;
     675        int hps = this.hps;
     676        if (hps == 0) hps = OS.WinGetPS (handle);
     677        FONTMETRICS fm = new FONTMETRICS();
     678        if(OS.GpiQueryFontMetrics (hps, FONTMETRICS.sizeof, fm))
     679            fm.lMaxBaselineExt<<=1;
     680        else
     681            fm.lMaxBaselineExt = 30;
     682
     683        iSize = getStringSize( hps, tabText );
     684
     685        if( iSize > iLongestMajText )
     686            iLongestMajText = iSize;
     687
     688        if (this.hps == 0) OS.WinReleasePS (hps);
     689
     690        OS.WinSendMsg(handle, OS.BKM_SETDIMENSIONS,
     691                  OS.MPFROM2SHORT((short)(iLongestMajText+5), (short)((float)fm.lMaxBaselineExt * 0.8)),
     692                  (short)OS.BKA_MAJORTAB);
     693
     694       OS.WinSendMsg(handle, OS.BKM_SETDIMENSIONS,
     695                 OS.MPFROM2SHORT((short)0, (short)0),
     696                 (short)OS.BKA_MINORTAB);
     697  return true;
     698}
     699
     700int getStringSize( int hps, PSZ szString )
     701{
     702    int[] pnts = new int [OS.TXTBOX_COUNT * 2];
     703    OS.GpiQueryTextBox( hps, szString.getBytes().length, szString.getBytes(), OS.TXTBOX_COUNT, pnts);
     704    return pnts[8];
     705}
     706
    677707
    678708//LRESULT WM_GETDLGCODE (int wParam, int lParam) {
     
    704734//      int hittest = OS.DefWindowProc (handle, OS.WM_NCHITTEST, wParam, lParam);
    705735//      return new LRESULT (hittest);
    706 //}
    707 //
    708 //LRESULT WM_NOTIFY (int wParam, int lParam) {
    709 //      /*
    710 //      * Feature in Windows.  When the tab folder window
    711 //      * proc processes WM_NOTIFY, it forwards this
    712 //      * message to its parent.  This is done so that
    713 //      * children of this control that send this message
    714 //      * type to their parent will notify not only
    715 //      * this control but also the parent of this control,
    716 //      * which is typically the application window and
    717 //      * the window that is looking for the message.
    718 //      * If the control did not forward the message,
    719 //      * applications would have to subclass the control
    720 //      * window to see the message. Because the control
    721 //      * window is subclassed by SWT, the message
    722 //      * is delivered twice, once by SWT and once when
    723 //      * the message is forwarded by the window proc.
    724 //      * The fix is to avoid calling the window proc
    725 //      * for this control.
    726 //      */
    727 //      LRESULT result = super.WM_NOTIFY (wParam, lParam);
    728 //      if (result != null) return result;
    729 //      return LRESULT.ZERO;
    730736//}
    731737//
     
    818824                                postEvent (SWT.Selection, event);
    819825                        }
     826            case OS.BKN_NEWPAGESIZE:
     827         //     if (isDisposed ()) return result;
     828        //      int index = OS.SendMessage (handle, OS.TCM_GETCURSEL, 0, 0);
     829        //      if (index != -1) {
     830        //              TabItem item = items [index];
     831        //              Control control = item.control;
     832        //              if (control != null && !control.isDisposed ()) {
     833        //                      control.setBounds (getClientArea ());
     834        //              }
     835        //      }
     836
    820837        }
    821838        return super.wmControlChild (mp1, mp2);
    822839}
    823 //LRESULT wmNotifyChild (int wParam, int lParam) {
    824 //      NMHDR hdr = new NMHDR ();
    825 //      OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
    826 //      int code = hdr.code;
    827 //      switch (code) {
    828 //              case OS.TCN_SELCHANGE:
    829 //              case OS.TCN_SELCHANGING:
    830 //                      TabItem item = null;
    831 //                      int index = OS.SendMessage (handle, OS.TCM_GETCURSEL, 0, 0);
    832 //                      if (index != -1) item = items [index];
    833 //                      if (item != null) {
    834 //                              Control control = item.control;
    835 //                              if (control != null && !control.isDisposed ()) {
    836 //                                      if (code == OS.TCN_SELCHANGE) {
    837 //                                              control.setBounds (getClientArea ());
    838 //                                      }
    839 //                                      control.setVisible (code == OS.TCN_SELCHANGE);
    840 //                              }
    841 //                      }
    842 //                      if (code == OS.TCN_SELCHANGE) {
    843 //                              Event event = new Event ();
    844 //                              event.item = item;
    845 //                              postEvent (SWT.Selection, event);
    846 //                      }
    847 //      }
    848 //      return super.wmNotifyChild (wParam, lParam);
    849 //}
    850 }
     840}
Note: See TracChangeset for help on using the changeset viewer.