|
Rapicorn - Experimental UI Toolkit - Source Code 10.08.1
|
00001 // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html 00002 #include <ui/serverapi.hh> // includes <ui/item.hh> after ItemIface declaration 00003 00004 #ifndef __RAPICORN_ITEM_HH_ 00005 #define __RAPICORN_ITEM_HH_ 00006 00007 #include <ui/events.hh> 00008 #include <ui/region.hh> 00009 #include <ui/commands.hh> 00010 #include <ui/properties.hh> 00011 #include <ui/heritage.hh> 00012 00013 namespace Rapicorn { 00014 00015 /* --- Item structures and forward decls --- */ 00016 typedef Rect Allocation; 00017 class ItemImpl; 00018 class SizeGroup; 00019 class Adjustment; 00020 class ContainerImpl; 00021 class WindowImpl; 00022 00023 /* --- event handler --- */ 00024 class EventHandler : public virtual BaseObject { 00025 typedef Signal<EventHandler, bool (const Event&), CollectorWhile0<bool> > EventSignal; 00026 protected: 00027 virtual bool handle_event (const Event &event); 00028 public: 00029 explicit EventHandler (); 00030 EventSignal sig_event; 00031 typedef enum { 00032 RESET_ALL 00033 } ResetMode; 00034 virtual void reset (ResetMode mode = RESET_ALL) = 0; 00035 }; 00036 00037 /* --- ItemImpl --- */ 00038 typedef Signals::Slot1<void, ItemImpl&> ItemSlot; 00039 class ItemImpl : public virtual ItemIface { 00040 friend class ClassDoctor; 00041 friend class ContainerImpl; 00042 friend class SizeGroup; 00043 uint32 m_flags; /* interface-inlined for fast read-out */ 00044 ContainerImpl *m_parent; /* interface-inlined for fast read-out */ 00045 Heritage *m_heritage; 00046 Requisition m_requisition; 00047 Allocation m_allocation; 00048 FactoryContext *m_factory_context; 00049 Requisition inner_size_request (); // ungrouped size requisition 00050 void propagate_state (bool notify_changed); 00051 ContainerImpl** _parent_loc () { return &m_parent; } 00052 void propagate_heritage (); 00053 void heritage (Heritage *heritage); 00054 protected: 00055 virtual void constructed (); 00056 /* flag handling */ 00057 bool change_flags_silently (uint32 mask, bool on); 00058 enum { 00059 ANCHORED = 1 << 0, 00060 VISIBLE = 1 << 1, 00061 PARENT_VISIBLE = 1 << 2, 00062 HIDDEN_CHILD = 1 << 3, 00063 SENSITIVE = 1 << 4, 00064 PARENT_SENSITIVE = 1 << 5, 00065 PRELIGHT = 1 << 6, 00066 IMPRESSED = 1 << 7, 00067 FOCUS_CHAIN = 1 << 8, 00068 HAS_DEFAULT = 1 << 9, 00069 INVALID_REQUISITION = 1 << 10, 00070 INVALID_ALLOCATION = 1 << 11, 00071 INVALID_CONTENT = 1 << 12, 00072 HSPREAD_CONTAINER = 1 << 13, 00073 VSPREAD_CONTAINER = 1 << 14, 00074 HSPREAD = 1 << 15, 00075 VSPREAD = 1 << 16, 00076 HEXPAND = 1 << 17, 00077 VEXPAND = 1 << 18, 00078 HSHRINK = 1 << 19, 00079 VSHRINK = 1 << 20, 00080 ALLOCATABLE = 1 << 21, 00081 POSITIVE_ALLOCATION = 1 << 22, 00082 DEBUG = 1 << 23, 00083 LAST_FLAG = 1 << 24 00084 }; 00085 void set_flag (uint32 flag, bool on = true); 00086 void unset_flag (uint32 flag) { set_flag (flag, false); } 00087 bool test_flags (uint32 mask) const { return (m_flags & mask) != 0; } 00088 bool test_all_flags (uint32 mask) const { return (m_flags & mask) == mask; } 00089 virtual bool self_visible () const; 00090 /* size requisition and allocation */ 00091 Requisition cache_requisition (Requisition *requisition = NULL); 00092 virtual void size_request (Requisition &requisition) = 0; 00093 virtual void size_allocate (Allocation area) = 0; 00094 virtual void invalidate_parent (); 00095 bool tune_requisition (Requisition requisition); 00096 bool tune_requisition (double new_width, 00097 double new_height); 00098 /* signal methods */ 00099 virtual void do_invalidate (); 00100 virtual void do_changed (); 00101 /* idlers & timers */ 00102 uint exec_fast_repeater (const BoolSlot &sl); 00103 uint exec_slow_repeater (const BoolSlot &sl); 00104 uint exec_key_repeater (const BoolSlot &sl); 00105 bool remove_exec (uint exec_id); 00106 virtual void visual_update (); 00107 /* misc */ 00108 virtual ~ItemImpl (); 00109 virtual void finalize (); 00110 virtual void set_parent (ContainerImpl *parent); 00111 virtual void hierarchy_changed (ItemImpl *old_toplevel); 00112 virtual bool move_focus (FocusDirType fdir); 00113 virtual bool custom_command (const String &command_name, 00114 const StringList &command_args); 00115 void anchored (bool b) { set_flag (ANCHORED, b); } 00116 void notify_key_error (); 00117 public: 00118 explicit ItemImpl (); 00119 bool anchored () const { return test_flags (ANCHORED); } 00120 bool visible () const { return test_flags (VISIBLE) && !test_flags (HIDDEN_CHILD); } 00121 void visible (bool b) { set_flag (VISIBLE, b); } 00122 bool allocatable () const { return visible() && test_all_flags (ALLOCATABLE | PARENT_VISIBLE); } 00123 bool drawable () const { return visible() && test_flags (POSITIVE_ALLOCATION); } 00124 virtual bool viewable () const; // drawable() && parent->viewable(); 00125 bool sensitive () const { return test_all_flags (SENSITIVE | PARENT_SENSITIVE); } 00126 virtual void sensitive (bool b); 00127 bool insensitive () const { return !sensitive(); } 00128 void insensitive (bool b) { sensitive (!b); } 00129 bool prelight () const { return test_flags (PRELIGHT); } 00130 virtual void prelight (bool b); 00131 bool branch_prelight () const; 00132 bool impressed () const { return test_flags (IMPRESSED); } 00133 virtual void impressed (bool b); 00134 bool branch_impressed () const; 00135 bool has_default () const { return test_flags (HAS_DEFAULT); } 00136 bool grab_default () const; 00137 virtual bool can_focus () const; 00138 bool has_focus () const; 00139 bool grab_focus (); 00140 bool hexpand () const { return test_flags (HEXPAND | HSPREAD | HSPREAD_CONTAINER); } 00141 void hexpand (bool b) { set_flag (HEXPAND, b); } 00142 bool vexpand () const { return test_flags (VEXPAND | VSPREAD | VSPREAD_CONTAINER); } 00143 void vexpand (bool b) { set_flag (VEXPAND, b); } 00144 bool hspread () const { return test_flags (HSPREAD | HSPREAD_CONTAINER); } 00145 void hspread (bool b) { set_flag (HSPREAD, b); } 00146 bool vspread () const { return test_flags (VSPREAD | VSPREAD_CONTAINER); } 00147 void vspread (bool b) { set_flag (VSPREAD, b); } 00148 bool hshrink () const { return test_flags (HSHRINK); } 00149 void hshrink (bool b) { set_flag (HSHRINK, b); } 00150 bool vshrink () const { return test_flags (VSHRINK); } 00151 void vshrink (bool b) { set_flag (VSHRINK, b); } 00152 bool debug () const { return test_flags (DEBUG); } 00153 void debug (bool f) { set_flag (DEBUG, f); } 00154 virtual String name () const; 00155 virtual void name (const String &str); 00156 FactoryContext* factory_context () const; 00157 void factory_context (FactoryContext *fc); 00158 ColorSchemeType color_scheme () const; 00159 void color_scheme (ColorSchemeType cst); 00160 /* override requisition */ 00161 double width () const; 00162 void width (double w); 00163 double height () const; 00164 void height (double h); 00165 /* properties */ 00166 void set_property (const String &property_name, 00167 const String &value, 00168 const nothrow_t &nt = dothrow); 00169 bool try_set_property (const String &property_name, 00170 const String &value, 00171 const nothrow_t &nt = dothrow); 00172 String get_property (const String &property_name); 00173 Property* lookup_property (const String &property_name); 00174 virtual const PropertyList& list_properties (); 00175 /* commands */ 00176 bool exec_command (const String &command_call_string); 00177 Command* lookup_command (const String &command_name); 00178 virtual const CommandList& list_commands (); 00179 /* parents */ 00180 ContainerImpl* parent () const { return m_parent; } 00181 bool has_ancestor (const ItemImpl &ancestor) const; 00182 ItemImpl* common_ancestor (const ItemImpl &other) const; 00183 ItemImpl* common_ancestor (const ItemImpl *other) const { return common_ancestor (*other); } 00184 WindowImpl* get_window () const; 00185 /* cross links */ 00186 void cross_link (ItemImpl &link, 00187 const ItemSlot &uncross); 00188 void cross_unlink (ItemImpl &link, 00189 const ItemSlot &uncross); 00190 void uncross_links (ItemImpl &link); 00191 /* invalidation / changes */ 00192 void invalidate (); 00193 void invalidate_size (); 00194 void changed (); 00195 void expose (); /* item allocation */ 00196 void expose (const Rect &rect); /* item coordinates relative */ 00197 void expose (const Region ®ion); /* item coordinates relative */ 00198 void copy_area (const Rect &rect, const Point &dest); 00199 void queue_visual_update (); 00200 void force_visual_update (); 00201 /* public signals */ 00202 SignalFinalize<ItemImpl> sig_finalize; 00203 Signal<ItemImpl, void ()> sig_changed; 00204 Signal<ItemImpl, void ()> sig_invalidate; 00205 Signal<ItemImpl, void (ItemImpl *oldt)> sig_hierarchy_changed; 00206 /* event handling */ 00207 bool process_event (const Event &event); /* item coordinates relative */ 00208 bool process_viewp0rt_event (const Event &event); /* viewp0rt coordinates relative */ 00209 /* coordinate handling */ 00210 protected: 00211 Affine affine_to_viewp0rt (); /* item => viewp0rt affine */ 00212 Affine affine_from_viewp0rt (); /* viewp0rt => item affine */ 00213 public: 00214 virtual bool point (Point p); /* item coordinates relative */ 00215 Point point_to_viewp0rt (Point item_point); /* item coordinates relative */ 00216 Point point_from_viewp0rt (Point window_point);/* viewp0rt coordinates relative */ 00217 virtual bool translate_from (const ItemImpl &src_item, 00218 const uint n_points, 00219 Point *points) const; 00220 bool translate_to (const uint n_points, 00221 Point *points, 00222 const ItemImpl &target_item) const; 00223 bool translate_from (const ItemImpl &src_item, 00224 const uint n_rects, 00225 Rect *rects) const; 00226 bool translate_to (const uint n_rects, 00227 Rect *rects, 00228 const ItemImpl &target_item) const; 00229 bool viewp0rt_point (Point p); /* viewp0rt coordinates relative */ 00230 /* public size accessors */ 00231 Requisition requisition (); // effective size requisition 00232 Requisition size_request () { return requisition(); } // FIXME: remove 00233 void set_allocation (const Allocation &area); // assign new allocation 00234 const Allocation& allocation () { return m_allocation; } // current allocation 00235 /* display */ 00236 virtual void render (Display &display) = 0; 00237 /* heritage / appearance */ 00238 StateType state () const; 00239 Heritage* heritage () const { return m_heritage; } 00240 Color foreground () { return heritage()->foreground (state()); } 00241 Color background () { return heritage()->background (state()); } 00242 Color dark_color () { return heritage()->dark_color (state()); } 00243 Color dark_shadow () { return heritage()->dark_shadow (state()); } 00244 Color dark_glint () { return heritage()->dark_glint (state()); } 00245 Color light_color () { return heritage()->light_color (state()); } 00246 Color light_shadow () { return heritage()->light_shadow (state()); } 00247 Color light_glint () { return heritage()->light_glint (state()); } 00248 Color focus_color () { return heritage()->focus_color (state()); } 00249 /* debugging/testing */ 00250 virtual String test_dump (); 00251 protected: 00252 void make_test_dump (TestStream &tstream); 00253 virtual void dump_test_data (TestStream &tstream); 00254 virtual void dump_private_data (TestStream &tstream); 00255 /* convenience */ 00256 public: 00257 void find_adjustments (AdjustmentSourceType adjsrc1, 00258 Adjustment **adj1, 00259 AdjustmentSourceType adjsrc2 = ADJUSTMENT_SOURCE_NONE, 00260 Adjustment **adj2 = NULL, 00261 AdjustmentSourceType adjsrc3 = ADJUSTMENT_SOURCE_NONE, 00262 Adjustment **adj3 = NULL, 00263 AdjustmentSourceType adjsrc4 = ADJUSTMENT_SOURCE_NONE, 00264 Adjustment **adj4 = NULL); 00265 public: /* packing */ 00266 struct PackInfo { 00267 double hposition, hspan, vposition, vspan; 00268 uint left_spacing, right_spacing, bottom_spacing, top_spacing; 00269 double halign, hscale, valign, vscale; 00270 }; 00271 const PackInfo& pack_info () const { return const_cast<ItemImpl*> (this)->pack_info (false); } 00272 double hposition () const { return pack_info ().hposition; } 00273 void hposition (double d); 00274 double hspan () const { return pack_info ().hspan; } 00275 void hspan (double d); 00276 double vposition () const { return pack_info ().vposition; } 00277 void vposition (double d); 00278 double vspan () const { return pack_info ().vspan; } 00279 void vspan (double d); 00280 uint left_spacing () const { return pack_info ().left_spacing; } 00281 void left_spacing (uint s); 00282 uint right_spacing () const { return pack_info ().right_spacing; } 00283 void right_spacing (uint s); 00284 uint bottom_spacing () const { return pack_info ().bottom_spacing; } 00285 void bottom_spacing (uint s); 00286 uint top_spacing () const { return pack_info ().top_spacing; } 00287 void top_spacing (uint s); 00288 double halign () const { return pack_info ().halign; } 00289 void halign (double f); 00290 double hscale () const { return pack_info ().hscale; } 00291 void hscale (double f); 00292 double valign () const { return pack_info ().valign; } 00293 void valign (double f); 00294 double vscale () const { return pack_info ().vscale; } 00295 void vscale (double f); 00296 Point position () const { const PackInfo &pi = pack_info(); return Point (pi.hposition, pi.vposition); } 00297 void position (Point p); // mirrors (hposition,vposition) 00298 double hanchor () const { return halign(); } // mirrors halign 00299 void hanchor (double a) { halign (a); } // mirrors halign 00300 double vanchor () const { return valign(); } // mirrors valign 00301 void vanchor (double a) { valign (a); } // mirrors valign 00302 private: 00303 void repack (const PackInfo &orig, const PackInfo &pnew); 00304 PackInfo& pack_info (bool create); 00305 public: 00306 virtual ItemIface* unique_component (const String &path); 00307 virtual ItemSeq collect_components (const String &path); 00308 template<class C> typename 00309 InterfaceMatch<C>::Result interface (const String &ident = String(), 00310 const std::nothrow_t &nt = dothrow) const; 00311 template<class C> typename 00312 InterfaceMatch<C>::Result parent_interface (const String &ident = String(), 00313 const std::nothrow_t &nt = dothrow) const; 00314 virtual OwnedMutex& owned_mutex (); 00315 protected: 00316 void allocation (const Allocation &area); 00317 virtual bool do_event (const Event &event); 00318 private: 00319 void type_cast_error (const char *dest_type) RAPICORN_NORETURN; 00320 bool match_interface (bool wself, bool wparent, bool children, InterfaceMatcher &imatcher) const; 00321 }; 00322 inline bool operator== (const ItemImpl &item1, const ItemImpl &item2) { return &item1 == &item2; } 00323 inline bool operator!= (const ItemImpl &item1, const ItemImpl &item2) { return &item1 != &item2; } 00324 00325 template<class C> typename ItemImpl::InterfaceMatch<C>::Result 00326 ItemImpl::interface (const String &ident, 00327 const std::nothrow_t &nt) const 00328 { 00329 InterfaceMatch<C> interface_match (ident); 00330 match_interface (1, 0, 1, interface_match); 00331 return interface_match.result (&nt == &dothrow); 00332 } 00333 00334 template<class C> typename ItemImpl::InterfaceMatch<C>::Result 00335 ItemImpl::parent_interface (const String &ident, 00336 const std::nothrow_t &nt) const 00337 { 00338 InterfaceMatch<C> interface_match (ident); 00339 match_interface (0, 1, 0, interface_match); 00340 return interface_match.result (&nt == &dothrow); 00341 } 00342 00343 } // Rapicorn 00344 00345 #endif /* __RAPICORN_ITEM_HH_ */
1.7.4