home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / windows / x / 20853 < prev    next >
Encoding:
Internet Message Format  |  1993-01-07  |  5.6 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!agate!doc.ic.ac.uk!uknet!lsl!snail
  2. From: snail@lsl.co.uk
  3. Newsgroups: comp.windows.x
  4. Subject: Re: Using XtCreatePopupShell with transient and topLevel shell class
  5. Message-ID: <1993Jan7.122607.2898@lsl.co.uk>
  6. Date: 7 Jan 93 12:26:07 GMT
  7. References: <1993Jan5.224918.23614@walter.bellcore.com>
  8. Organization: Laser-Scan Ltd., Cambridge
  9. Lines: 118
  10.  
  11. In article <1993Jan5.224918.23614@walter.bellcore.com>, cindy@kolob.NoSubdomain.NoDomain (Cindy Lee) writes:
  12. > Hi folks,
  13. > I'm trying to create an application with 2 shells that will enable
  14. > the following 2 window manager functions:
  15. > 1) bringing either window forward in front of the other one
  16. > 2) iconifying BOTH windows
  17. > I'm fiddling with XtCreatePopupShell with class types of
  18. > transientShellWidgetClass and topLevelShellWidgetClass.
  19. > The transient satisfies requirement #2 but not #1.
  20. > The topLevel satisfies requirement #1 but not #2.
  21.  
  22. We've done this here, except for any amount of shells. First thing is you
  23. should use toplevel or application shells. This satisfies requirement #1.
  24.  
  25. To satisfy requirement #2 is more complex and requires you to write some code.
  26. Our system is set up such that any shell can iconify/deiconify/withdraw itself
  27. without affecting any other shell, EXCEPT that the very first shell created 
  28. behaves differently. If it is iconised, it then tells all other shells to
  29. iconise themselves, it if is deiconised, it tells all shells to restore
  30. themselves to the state they were in before the first shell was iconised.
  31.  
  32. This code took a while to write and I'm not going to give it away, quite apart
  33. form the fact it uses some of our collection objects etc. However I'm gonna
  34. give you the basic outline of what you need to do...(to get a system like ours,
  35. then it's simple to change to the way you need)
  36.  
  37. #1    attach an event handler to every toplevel shell that gets called when
  38.         the shell is iconised/withdrawn/de-iconised.
  39.  
  40.       XtAddEventHandler(shell_w,                        /* shell        */
  41.                         PropertyChangeMask,             /* iconise      */
  42.                         False,
  43.                         _mmi_iconise_event,             /* callback func*/
  44.                         shell_data);                    /* callback data*/
  45.   
  46. #2
  47.     The callback function should be along these lines:-
  48.  
  49. static XtCallbackProc _mmi_iconise_event(Widget         w,
  50.                                          XtPointer      client_data,
  51.                                          XPropertyEvent *event)
  52. {
  53.    if (event->type != PropertyNotify)
  54.       return NULL;
  55.  
  56.    /* We check for a new Property Value and that the property that has  */
  57.    /* changed is Window Manager State 'WM_STATE'. Then we know the      */
  58.    /* iconised state has changed, and we queue the function. This       */
  59.    /* ensures that when the postponed function is called the state info */
  60.    /* about the shell is known.                                         */
  61.  
  62.    if (event->state == PropertyNewValue)
  63.    {
  64.       string = XGetAtomName(XtDisplay(w), event->atom);
  65.       if (strcmp(string, "WM_STATE") == 0)
  66.     {
  67.         /* check the shell state.. see the FAQ or one of my
  68.            posting on this. My posting is derived from the FAQ
  69.            but is I feel a bit easier to follow, last posted about
  70.                    a month ago.
  71.  
  72.             if the shell is in a state you're interested in then
  73.                    you can make the decision to iconise/deiconise/withdraw
  74.                    or restore the other shells states. If you want to
  75.                    restore the other shells states, then you must track 
  76.                    their states.
  77.  
  78.                    Also if you want it so that any shell can invoke this
  79.                    then you'll have to check for looping caused by events
  80.                    caused by your iconise/deiconise/withdraw strategy.
  81.  
  82.            Note that the shell_data structure I have passed as
  83.                    client_data tells me the shell widget id, what I believe
  84.                    it's state is and what it's previous state is etc,
  85.                    you could add flags to this to prevent the looping
  86.                    I describe. If you need globals, you've done it wrong. 
  87.                 */
  88.     }
  89.       XFree(string);
  90.    }
  91.    return NULL;
  92. }
  93.  
  94. You also need:-
  95.  
  96. #3 To iconify a window:-    XIconifyWindow()
  97. #4 To deiconify:-          XMapRaised()
  98. #5 To withdraw:-           XWithdrawWindow()
  99. #6 To iconify a withdrawn window:- XMapRaised() followed by XIconifyWindow()
  100.                                 doesn't look nice, but if you know better let 
  101.                                 me know.
  102.  
  103. #7 It often helps to remove the event handlers whilst doing the above (to
  104.    prevent loops) and then re-install the event handler afterwards.
  105.  
  106. #8 When doing a XMapRaised() also call
  107.       XtCallCallbacks(shell_w, XtNpopupCallback, NULL);
  108.    so that the callbacks get called. In X11R4 there was a bug so they didn't
  109.    get called. We still call them in X11R5 - no problem.
  110.  
  111. #9 You will also notice that dialog shells etc don't get re-mapped to the
  112.    screen when you de-iconify their parent, so you must keep track of all
  113.    dialog shells etc and after the XMapRaised of their parents do the
  114.    following:-
  115.  
  116.    XtMapWidget(XtParent(dialog_shell_w));
  117.  
  118. That should help you on your way....
  119.  
  120. Now don't say I don't give you any help :-)
  121. -- 
  122. snail@lsl.co.uk      
  123.  
  124. "Washing one's hands of the conflict between the powerful and the powerless
  125.  means to side with the powerful, not to be Neutral."
  126.                                                      Quote by Freire.
  127.                                                      Poster by OXFAM.
  128.