void setup_node( dom::element node )
    {
      dom::element on = node.find_first("option[check='on'],options[check='on']");
      dom::element off = node.find_first("option[check='off'],options[check='off']");
      dom::element mixed = node.find_first("options[check='mixed']");

      const wchar_t* _prev = node.get_attribute(CHECK_ATTR);
      std::wstring  prev = _prev?_prev:L"";
      
      if( mixed.is_valid() || (on.is_valid() && off.is_valid()))
      {
        node.set_attribute(CHECK_ATTR,L"mixed");
        if(prev != L"mixed") node.update();
      }
      else if( on.is_valid() )
      {
        node.set_attribute(CHECK_ATTR,L"on");
        if(prev != L"on") node.update();
      }
      else
      {
        node.set_attribute(CHECK_ATTR,L"off");
        if(prev != L"off") node.update();
      }
    }
Exemplo n.º 2
0
    // select 
    bool select_tab( dom::element& tabs_el, dom::element& tab_el )
    {
      if(tab_el.get_state(STATE_CURRENT))
        // already selected, nothing to do...
        return true; // but we've handled it.
     
      //find currently selected element (tab and panel) and remove "selected" from them
      dom::element prev_panel_el = tabs_el.find_first(":root>[name]:expanded");
      dom::element prev_tab_el = tabs_el.find_first(":root>.strip>[panel]:current");

      // find new tab and panel       
      const wchar_t* pname = tab_el.get_attribute("panel");
      dom::element panel_el = tabs_el.find_first(":root>[name=\"%S\"]", pname);
      
      if( !panel_el.is_valid() || !tab_el.is_valid() )
      {
        assert(false); // panel="somename" without matching name="somename"
        return true;
      }

      if( prev_panel_el.is_valid() )
      {
        prev_panel_el.set_attribute("selected", 0); // remove selected attribute - just in case somone is using attribute selectors    
        prev_panel_el.set_state(STATE_COLLAPSED,0); // set collapsed in case of someone use it for styling
      }
      if( prev_tab_el.is_valid() )
      {
        prev_tab_el.set_attribute("selected", 0); // remove selected attribute
        prev_tab_el.set_state(0,STATE_CURRENT); // reset also state flag, :current
      }
      
      panel_el.set_attribute("selected", L""); // set selected attribute (empty)
      panel_el.set_state(STATE_EXPANDED,0); // expand it
      
      tab_el.set_attribute("selected", L""); // set selected attribute (empty)
      tab_el.set_state(STATE_CURRENT,0); // set also state flag, :current
                  
      // notify all parties involved
	  if (prev_tab_el.is_valid())
	  {
		  prev_tab_el.post_event(ELEMENT_COLLAPSED,0, prev_tab_el); // source here is old collapsed tab itself
	  }
      tab_el.post_event(ELEMENT_EXPANDED,0, tab_el);  // source here is new expanded tab itself
      // NOTE #1: these event will bubble from panel elements up to the root so panel itself, tabs ctl, its parent, etc.
      // will receive these notifications. Handle them if you need to change UI dependent from current tab. 
      // NOTE #2: while handling this event in:
      //        virtual BOOL on_event (HELEMENT he, HELEMENT target, BEHAVIOR_EVENTS type, UINT reason ),
      // HELEMENT target is the panel element being collapsed/expanded
      
      return true;
    }
Exemplo n.º 3
0
    // set current item
    virtual void set_current_item( const dom::element& ctl, dom::element& item )
    {
      // get previously selected item:
      dom::element prev_current = ctl.find_first(":current");
      dom::element prev = ctl.find_first(":expanded");
	  
      if(prev_current != item && prev_current.is_valid())
        prev_current.set_state(0, STATE_CURRENT);

      if( prev.is_valid() )
      {
        if( prev == item ) return; // already here, nothing to do.
        prev.set_state(0,STATE_CURRENT | STATE_EXPANDED); // drop state flags
      }
      item.set_state(STATE_CURRENT | STATE_EXPANDED); // set state flags
    }
	  void set_anchor (dom::element& table,const int idx)
    {
      dom::element row = table.find_first("tr:anchor");
      if( row.is_valid() ) row.set_state( 0,STATE_ANCHOR,false);
      row = table.child(idx);
      if( row.is_valid() )
		    row.set_state( STATE_ANCHOR | STATE_CHECKED,0,false);
	  }
    bool do_move(  dom::element& el, bool from_src_to_dst, bool selected_only )
    {
      dom::element select_src = el.find_first("[role='source']");
      dom::element select_dst = el.find_first("[role='destination']");

      if(!select_src.is_valid() || !select_dst.is_valid())
      {
        assert(false);
        return false;
      }

      if( !from_src_to_dst ) // swap src and destination
      {
        dom::element tmp = select_src;  
        select_src = select_dst;
        select_dst = tmp;
      }

      selected_cb options;
      select_src.find_all(&options, selected_only?"option:checked":"option"); // select all currently selected <option>s

      // move elements from one container to another
      if(from_src_to_dst)
        for( int n = options.elements.size() - 1; n >= 0 ; --n )
        {
          dom::element& opt = options.elements[n];
          unsigned int idx = opt.index();
          wchar_t buf[32]; swprintf(buf,L"%d",idx);
          opt.set_attribute("-srcindex",buf);
          select_dst.insert( opt, 0 );
        }
      else
        for( unsigned int n = 0; n < options.elements.size() ; ++n )
        {
          int i = _wtoi(options.elements[n].get_attribute("-srcindex"));
          select_dst.insert( options.elements[n], i );
        }

      select_src.update();
      select_dst.update();
      return true;
    }
 bool do_clear_all(  dom::element& el )
 {
   dom::element select = el.find_first("[role='source']");
   if(!select.is_valid())
   {
     assert(false);
     return false;
   }
   clear_all_options(select);
   return true;
 }
    bool try_to_load( dom::element& root, const wchar_t* url, const wchar_t* target )
    {
      if(target[0] == '_' ) 
        return false; // do ShellExecute here to open default browser if needed.
      dom::element target_el = root.find_first("#%S",target);                              
      if(!target_el.is_valid())
        return false;

      target_el.load_html(url);
      return true;
    }
Exemplo n.º 8
0
   // set current item
    virtual void set_current_item( const dom::element& ctl, dom::element& item )
    {
      // get previously expanded item:
      dom::element prev = ctl.find_first(":expanded");
      dom::element prev_current = ctl.find_first(":current");
	  
      if(prev_current != item && prev_current.is_valid())
        prev_current.set_state(0, STATE_CURRENT);

	    if( prev == item )
	    {
		    prev.set_state(STATE_CURRENT | STATE_COLLAPSED); 
	    }
	    else 
	    {
		    if( prev.is_valid() )
			    prev.set_state(STATE_COLLAPSED); // collapse old one
		    item.set_state(STATE_CURRENT | STATE_EXPANDED); // set new expanded.
	    }
      item.scroll_to_view();
    }
/** Set values of all "controls" contained inside the DOM element by items 
 *  contained in the all colection. 
 *  Function will set values of elements having name attribute defined
 *  and recognized by get_ctl_type() function.
 * \param[in] el \b dom::element&, The element.
 * \param[out] all \b named_values&, Collection.
 * \return \b bool, \c true if there are any value was harvested.
 **/
  inline bool set_values(dom::element& el, named_values& all )
  {
    int counter = 0;
    for( named_values_iterator it = all.begin(); it != all.end(); it++ )
    {
      std::wstring name = (*it).first;
      //::MessageBoxW(NULL, name, L"" )
      dom::element t = el.find_first("[name='%S']",name.c_str()); 
      if( !t.get_style_attribute("behavior") )
        continue;
      set_value(t, (*it).second);
      ++counter;
    }
    return counter != 0;
  }
  virtual void on_column_click( dom::element& table, dom::element& header_cell )
  {
    super::on_column_click( table, header_cell );

    dom::element current = table.find_first("th:checked");
    if( current == header_cell )
      return; // already here, nothing to do.

    if( current.is_valid() )
      current.set_state(0, STATE_CHECKED);
    header_cell.set_state(STATE_CHECKED);

	dom::element ctr = get_current_row( table );
    sort_rows( table, header_cell.index() );
	if( ctr.is_valid() )
		ctr.scroll_to_view();

  }
	  int get_anchor (const dom::element& table)
    {
      dom::element row = table.find_first("tr:anchor");
      if( row.is_valid() ) return (int)row.index();
      return 0;
	  }