Re: Unified libraries to allow porting code to other oses

new topic     » goto parent     » topic index » view thread      » older message » newer message
irv said...

Using your example, and assuming the statusbar doesn't also have its own text which is settable:

{"text",{P,S},0,-routine_id("setStatusBarPanelText")} -- the prototype 
 
function setStatusBarPanelText(atom stbar, object txt) 
object panel = get(stbar,"child") 
set(panel,"text",txt) 
.... 

Note that the routine_id for the function above has been negated. This makes it easy to differentiate positive numbers which are pointers to calls in the .dll, from negative numbers, which are calls to Euphoria routines, so you use c_func or call_func as appropriate.

Of course, there might be a situation where the statusbar has text, and its panel also has text, I suppose. In that case, just use a different name for one, such as statusbar caption. Or even something like:

   {"panel.text",{P,S},-routine_id("setSbPanelTxt")} 

Using that, your program could call:

set(panelbar,"panel.text","FooBar")

"panel->text" would work, or whatever you like, these are just strings.
set(panelbar,"panel->text->color","blue") if you want to look like some other programming language :)

 {"cell_data",{P,I,I,S}} -- prototype for setting grid row, col, data 
 
Program code: 
  set(grid,"cell_data",2,4,"Something or other")  
 

Hi Irv,

Here is the complete code to set the property text for all widgets supporting it:

constant HEADER = 1, FOOTER = 2 
 
-- set a property of a widget 
public procedure setProperty(object Id, sequence Property, object Value, object Section=0) 
  integer id, parent, param1, param2 
  if sequence(Id) then 
    parent = Id[1] 
    id     = Id[2] 
  else 
    id     = Id 
  end if 
  if sequence(Section) then 
    param1 = Section[1] 
    param2 = Section[2] 
  else 
    param1 = Section 
  end if 
  atom class = getClass(id) 
  if equal(Property, "text") then 
    if atom(Section) then 
      if Section = 0 then 
        switch class do 
          case wxRichTextCtrl, wxTextCtrl then set_text( id, Value ) 
          case wxButton, wxDefButton, wxToggleButton then set_button_label( id, Value ) 
          case wxFrame, wxRadioBox, wxStaticText then set_label( id, Value ) 
          case wxTextAttrEx then set_textattrex_bullet_text( id, Value ) 
          case wxStatusBar then set_status_text( id, Value, 0 ) 
        end switch 
      else 
        switch class do 
          case wxAuiNotebook then aui_notebook_set_page_text( id, Section, Value ) 
          case wxListCtrl then set_column_label( id, Section, Value ) 
          case wxChoicebook, wxListbook, wxNotebook, wxToolbook, wxTreebook then set_page_text( id, Section, Value ) 
          case wxStatusBar then set_status_text( id, Value, Section ) 
          case wxBitmapComboBox, wxChoice, wxComboBox, wxListBox, wxListCtrl then set_string( id, Section, Value ) 
          case wxTreeCtrl, wxTreeEvent then set_tree_item_text( id, Section, Value ) 
          case wxToolBar, wxToolBarItem then set_tool_label( id, Section, Value ) 
          case wxMenu, wxMenuBar, wxMenuItem then set_menu_label( id, Section, Value ) 
        end switch 
      end if 
    elsif (length(Section) = 2) and find(class, {wxGrid, wxGridCellAttr, wxGridCellAutoWrapStringEditor, wxGridCellEditor}) then 
      if Section[1] = 0 then 
        set_col_label( id, Section[2]-1, Value ) 
      elsif Section[2] = 0 then 
        set_row_label( id, Section[1]-1, Value ) 
      else 
        set_cell_value(id, Value, Section[1]-1, Section[2]-1) 
      end if 
    elsif (length(Section) = 3) and (class = wxRichTextPrinting) then 
      if Section[1] = HEADER then 
        set_richprint_footer_text( id, Value, Section[2], Section[3] ) 
      elsif Section[1] = FOOTER then 
        set_richprint_header_text( id, Value, Section[2], Section[3] ) 
      end if 
    end if 
  end if 
end procedure 

You can notice that original functions have various names, that parameters are not always in the same order and that parameters length differ. How could I build a list of prototypes your way in this conditions?

As all this code is only for one property, my feeling is that there is no benefit setting all the properties with one unique huge function. If you take a look at the function list I uploaded in ODS form, you will have an order of magnitude of the size it could reach. One function per property as previously coded would not be less maintainable than such a unique huge function.

Regards

Jean-Marc

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu