Rapicorn - Experimental UI Toolkit - Source Code 10.08.1
window.hh
Go to the documentation of this file.
00001 // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html
00002 #ifndef __RAPICORN_WINDOW_HH__
00003 #define __RAPICORN_WINDOW_HH__
00004 
00005 #include <ui/container.hh>
00006 #include <ui/viewp0rt.hh>
00007 
00008 namespace Rapicorn {
00009 
00010 /* --- Window --- */
00011 class WindowImpl : public virtual SingleContainerImpl, public virtual Wind0wIface,
00012                    public virtual EventLoop::Source, public virtual Viewp0rt::EventReceiver {
00013   friend class  ItemImpl;
00014   EventLoop            &m_loop;
00015   EventLoop::Source    *m_source;
00016   Mutex                 m_async_mutex;
00017   std::list<Event*>     m_async_event_queue;
00018   Region                m_expose_region;
00019   Viewp0rt             *m_viewp0rt;
00020   uint                  m_tunable_requisition_counter : 24;
00021   uint                  m_entered : 1;
00022   uint                  m_auto_close : 1;
00023   EventContext          m_last_event_context;
00024   vector<ItemImpl*>     m_last_entered_children;
00025   Viewp0rt::Config      m_config;
00026   uint                  m_notify_displayed_id;
00027   void          uncross_focus           (ItemImpl        &fitem);
00028 protected:
00029   void          set_focus               (ItemImpl         *item);
00030   virtual void  set_parent              (ContainerImpl    *parent);
00031   virtual void  dispose                 ();
00032 public:
00033   explicit              WindowImpl              ();
00034   ItemImpl*             get_focus               () const;
00035   cairo_surface_t*      create_snapshot         (const Rect  &subarea);
00036   ItemImpl*             find_item               (const String &name);
00037   virtual Wind0wIface&  wind0w                                  ();     // MT-safe
00038   // grab handling
00039   virtual void          add_grab                                (ItemImpl &child, bool unconfined = false);
00040   void                  add_grab                                (ItemImpl *child, bool unconfined = false);
00041   virtual void          remove_grab                             (ItemImpl &child);
00042   void                  remove_grab                             (ItemImpl *child);
00043   virtual ItemImpl*     get_grab                                (bool                   *unconfined = NULL);
00044   // main loop
00045   virtual EventLoop*    get_loop                                ();
00046   virtual void          enable_auto_close                       ();
00047   // signals
00048   typedef Signal<WindowImpl, bool (const String&, const StringVector&), CollectorWhile0<bool> >   CommandSignal;
00049   typedef Signal<WindowImpl, void ()> NotifySignal;
00050 private:
00051   void                  notify_displayed                        (void);
00052   virtual void          remove_grab_item                        (ItemImpl               &child);
00053   void                  grab_stack_changed                      ();
00054   /*Des*/               ~WindowImpl                             ();
00055   virtual void          dispose_item                            (ItemImpl               &item);
00056   virtual bool          self_visible                            () const;
00057   /* misc */
00058   vector<ItemImpl*>     item_difference                         (const vector<ItemImpl*>    &clist, /* preserves order of clist */
00059                                                                  const vector<ItemImpl*>    &cminus);
00060   /* sizing */
00061   virtual void          size_request                            (Requisition            &requisition);
00062   using                 ItemImpl::size_request;
00063   virtual void          size_allocate                           (Allocation              area);
00064   virtual bool          tunable_requisitions                    ();
00065   void                  resize_all                              (Allocation             *new_area);
00066   virtual void          do_invalidate                           ();
00067   virtual void          beep                                    ();
00068   /* rendering */
00069   virtual void          render                                  (Display                &display);
00070   using                 ItemImpl::render;
00071   void                  collapse_expose_region                  ();
00072   virtual void          expose_window_region                    (const Region           &region);   // window item coords
00073   virtual void          copy_area                               (const Rect             &src,
00074                                                                  const Point            &dest);
00075   void                  expose_now                              ();
00076   virtual void          draw_now                                ();
00077   /* viewp0rt ops */
00078   virtual void          create_viewp0rt                         ();
00079   virtual bool          has_viewp0rt                            ();
00080   virtual void          destroy_viewp0rt                        ();
00081   virtual bool          viewable                                ();
00082   void                  idle_show                               ();
00083   /* main loop */
00084   virtual bool          prepare                                 (const EventLoop::State &state,
00085                                                                  int64                  *timeout_usecs_p);
00086   virtual bool          check                                   (const EventLoop::State &state);
00087   virtual bool          dispatch                                (const EventLoop::State &state);
00088   virtual bool          custom_command                          (const String       &command_name,
00089                                                                  const StringList   &command_args);
00090   /* Wind0wIface */
00091   virtual void          show                                    ();
00092   virtual bool          closed                                  ();
00093   virtual void          close                                   ();
00094   virtual bool          synthesize_enter                        (double xalign = 0.5,
00095                                                                  double yalign = 0.5);
00096   virtual bool          synthesize_leave                        ();
00097   virtual bool          synthesize_click                        (ItemIface &item,
00098                                                                  int        button,
00099                                                                  double     xalign = 0.5,
00100                                                                  double     yalign = 0.5);
00101   virtual bool          synthesize_delete                       ();
00102   /* event handling */
00103   virtual void          enqueue_async                           (Event                  *event);
00104   virtual void          cancel_item_events                      (ItemImpl               *item);
00105   void                  cancel_item_events                      (ItemImpl &item) { cancel_item_events (&item); }
00106   bool                  dispatch_mouse_movement                 (const Event            &event);
00107   bool                  dispatch_event_to_pierced_or_grab       (const Event            &event);
00108   bool                  dispatch_button_press                   (const EventButton      &bevent);
00109   bool                  dispatch_button_release                 (const EventButton      &bevent);
00110   bool                  dispatch_cancel_event                   (const Event            &event);
00111   bool                  dispatch_enter_event                    (const EventMouse       &mevent);
00112   bool                  dispatch_move_event                     (const EventMouse       &mevent);
00113   bool                  dispatch_leave_event                    (const EventMouse       &mevent);
00114   bool                  dispatch_button_event                   (const Event            &event);
00115   bool                  dispatch_focus_event                    (const EventFocus       &fevent);
00116   bool                  move_focus_dir                          (FocusDirType            focus_dir);
00117   bool                  dispatch_key_event                      (const Event            &event);
00118   bool                  dispatch_scroll_event                   (const EventScroll      &sevent);
00119   bool                  dispatch_win_size_event                 (const Event            &event);
00120   bool                  dispatch_win_draw_event                 (const Event            &event);
00121   bool                  dispatch_win_delete_event               (const Event            &event);
00122   virtual bool          dispatch_event                          (const Event            &event);
00123   bool                  has_pending_win_size                    ();
00124   /* --- GrabEntry --- */
00125   struct GrabEntry {
00126     ItemImpl *item;
00127     bool  unconfined;
00128     explicit            GrabEntry (ItemImpl *i, bool uc) : item (i), unconfined (uc) {}
00129   };
00130   vector<GrabEntry>     m_grab_stack;
00131   /* --- ButtonState --- */
00132   struct ButtonState {
00133     ItemImpl           *item;
00134     uint                button;
00135     explicit            ButtonState     (ItemImpl *i, uint b) : item (i), button (b) {}
00136     explicit            ButtonState     () : item (NULL), button (0) {}
00137     bool                operator< (const ButtonState &bs2) const
00138     {
00139       const ButtonState &bs1 = *this;
00140       return bs1.item < bs2.item || (bs1.item == bs2.item &&
00141                                      bs1.button < bs2.button);
00142     }
00143   };
00144   map<ButtonState,uint> m_button_state_map;
00145   /* --- EventLoop Source --- */
00146   class WindowSource : public EventLoop::Source {
00147     WindowImpl &window;
00148   public:
00149     explicit
00150     WindowSource  (WindowImpl &_window) :
00151       window (_window)
00152     {
00153       bool entered = rapicorn_thread_entered();
00154       if (!entered)
00155         rapicorn_thread_enter();
00156       RAPICORN_ASSERT (window.m_source == NULL);
00157       window.m_source = this;
00158       if (!entered)
00159         rapicorn_thread_leave();
00160     }
00161     virtual
00162     ~WindowSource ()
00163     {
00164       bool entered = rapicorn_thread_entered();
00165       if (!entered)
00166         rapicorn_thread_enter();
00167       RAPICORN_ASSERT (window.m_source != this);
00168       if (!entered)
00169         rapicorn_thread_leave();
00170     }
00171     virtual bool prepare    (const EventLoop::State &state,
00172                              int64        *timeout_usecs_p)  { RAPICORN_ASSERT (rapicorn_thread_entered()); return window.prepare (state, timeout_usecs_p); }
00173     virtual bool check      (const EventLoop::State &state)  { RAPICORN_ASSERT (rapicorn_thread_entered()); return window.check (state); }
00174     virtual bool dispatch   (const EventLoop::State &state)  { RAPICORN_ASSERT (rapicorn_thread_entered()); return window.dispatch (state); }
00175     virtual void
00176     destroy ()
00177     {
00178       RAPICORN_ASSERT (rapicorn_thread_entered());
00179       RAPICORN_ASSERT (window.m_source == this);
00180       window.m_source = NULL;
00181       window.destroy_viewp0rt();
00182     }
00183   };
00184 };
00185 
00186 } // Rapicorn
00187 
00188 #endif  /* __RAPICORN_WINDOW_HH__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines