class Myform::MyFormHolder

Attributes

caller[RW]
form[RW]
holder[RW]
runmode[RW]

Public Class Methods

new(mode="dialog",caller=self,runmode=nil,form_id=nil) click to toggle source
# File lib/FormHolder.rb, line 38
        def initialize(mode="dialog",caller=self,runmode=nil,form_id=nil)
                @form_id=form_id
                @caller=caller
                @runmode=runmode
                @form=Myform::MyForm.new(self,form_id,runmode)
                case mode
                        when "embedded"
                                @holder=EmbeddedFormHolder.new(self)

               when "dialog"
                                #run in dialog window
#                               form.set_id(caller.target)
                                @holder=Gtk::Dialog.new().set_resizable(true)#.set_transient_for(@caller.get_ancestor(Gtk::Window))#.set_modal(true)
                                #press calcel or close if user closes the window
                                holder.signal_connect("delete-event"){|me,ev| if info? || wysiwyg? then @closeb.activate; else @cancel.activate; end }

                                #restoring the saved width,height/top,bottom positions
                                unless wysiwyg?
                                        if w=get_conf(form.get_id,0,"width") and h=get_conf(form.get_id,0,"height") then holder.resize(w.to_i,h.to_i) end
                                        if x=get_conf(form.get_id,0,"x") and y=get_conf(form.get_id,0,"y") then holder.move(x.to_i,y.to_i) end
                                        #save form dimensions and position when user resizes
                                        holder.signal_connect("configure-event"){|me,event|
                                                set_conf(form.get_id,0,"width",event.width.to_s)
                                                set_conf(form.get_id,0,"height",event.height.to_s)
                                                set_conf(form.get_id,0,"x",event.x.to_s)
                                                set_conf(form.get_id,0,"y",event.y.to_s)
                                       false
                                        }
                                end
                                form_accel_group= Gtk::AccelGroup.new
                                form_accel_group.connect(Gdk::Keyval::GDK_KEY_Return,Gdk::Window::CONTROL_MASK ,Gtk::ACCEL_VISIBLE){
                              if info? || wysiwyg? then @closeb.activate; else @ok.activate; end
                                }
                                form_accel_group.connect(Gdk::Keyval::GDK_KEY_Escape,nil ,Gtk::ACCEL_VISIBLE){
                                        if info? || wysiwyg? then @closeb.activate; else @cancel.activate; end
                                }
                                holder.add_accel_group(form_accel_group)
                                @form.set_ag(form_accel_group)

                                #adding the Form Buttons
                                holder.vbox.pack_start(form,true,true,0)
                                if info? || wysiwyg?
                                        @closeb=holder.add_button('',Gtk::Dialog::RESPONSE_CLOSE).set_image(Gtk::Image.new(Gtk::Stock::CLOSE,Gtk::IconSize::SMALL_TOOLBAR)).set_label('close').set_relief(Gtk::ReliefStyle::NONE)
                              else
                              @apply=holder.add_button('',Gtk::Dialog::RESPONSE_APPLY).set_image(Gtk::Image.new(Gtk::Stock::APPLY,Gtk::IconSize::SMALL_TOOLBAR)).set_label('apply').set_relief(Gtk::ReliefStyle::NONE) unless @form.gtk_attribute("apply_button")=="false"
                              @ok=holder.add_button('',Gtk::Dialog::RESPONSE_OK).set_image(Gtk::Image.new(Gtk::Stock::OK,Gtk::IconSize::SMALL_TOOLBAR)).set_label('ok').set_relief(Gtk::ReliefStyle::NONE) unless @form.gtk_attribute("ok_button")=="false"
                              @cancel=holder.add_button('',Gtk::Dialog::RESPONSE_CANCEL).set_image(Gtk::Image.new(Gtk::Stock::CANCEL,Gtk::IconSize::SMALL_TOOLBAR)).set_label('cancel').set_relief(Gtk::ReliefStyle::NONE)
                                end
                                holder.set_default_response(0)
                                #holder.realize;holder.window.set_functions(Gdk::Window::WMFunction::ALL | Gdk::Window::WMFunction::CLOSE)

                        when "touchscreen"
                                @holder=Gtk::VBox.new
                                @form.modify_bg(Gtk::STATE_NORMAL,Gdk::Color.new(65000, 0, 0))
                                @form.items.each{|item| 
                              item.modify_bg(Gtk::STATE_NORMAL,Gdk::Color.new(0,65000, 0))
                              item.renderer.modify_bg(Gtk::STATE_NORMAL,Gdk::Color.new(0,35000, 0))
                                }
                                @holder.modify_bg(Gtk::STATE_NORMAL,Gdk::Color.new(0, 0, 65000))
                                @holder.pack_start(@form,true,true)
                                set_parentM(self)
               else ewarn("not recognized form run mode: #{mode}","form")
                end
  end

Public Instance Methods

add?() click to toggle source
# File lib/FormHolder.rb, line 159
def add?
      runmode == "add"
end
destroy() click to toggle source
# File lib/FormHolder.rb, line 196
def destroy
      @form.destroy unless @form.nil? or @form.destroyed?
      @holder.destroy unless @holder.nil? or @holder.destroyed?
end
embedd?() click to toggle source
# File lib/FormHolder.rb, line 108
def embedd?
        @form.embedd?
end
get_ancestor(classname) click to toggle source
# File lib/FormHolder.rb, line 172
def get_ancestor(classname)
      @caller.get_ancestor(classname)
end
info?() click to toggle source
# File lib/FormHolder.rb, line 162
def info?
      runmode == "info"
end
is_embedded() click to toggle source
# File lib/FormHolder.rb, line 104
def is_embedded
        @form.is_embedded
end
parentM() click to toggle source
# File lib/FormHolder.rb, line 165
def parentM
              @parent_moditem
end
run(pid=@form.parentselected,batch=nil) click to toggle source
# File lib/FormHolder.rb, line 112
def run(pid=@form.parentselected,batch=nil)
      @form.parentselected=pid
      @form.batch=@form.batch_support? && batch.class == Array && batch.size>1 ? batch : nil
      batch=@form.batch_support? && batch.class == Array ? batch : [@form.parentselected]

              ret=-1
              if @holder
              begin
              manqod_db.lock_id_of_base(@form.table,batch) unless add? || wysiwyg?
                      @form.update(@caller)
             ret=-1 #ha ret 0, akkor nem volt valtozas, ha -1, akkor hiba volt, ha >0, akkor az a parentid (addnal van hasznalva asszem, pozicionalasra)
             while ret<0
                              case response=@holder.run
                                      when Gtk::Dialog::RESPONSE_OK then #ok
                                              ret=@form.apply_changes(self).to_i
                                              einfo("apply_changes return: #{ret}","form")
                                              @caller.caller.list.save_cursor_id(ret) if @caller.class.name == 'MyButton'
                                      when Gtk::Dialog::RESPONSE_CANCEL, Gtk::Dialog::RESPONSE_CLOSE, Gtk::Dialog::RESPONSE_DELETE_EVENT then
                                              ret=0
                                      when Gtk::Dialog::RESPONSE_APPLY then #apply
                                              ret=@form.apply_changes(self).to_i
                                              manqod_db.unlock_id_of_base(@form.table,batch.push(ret)) unless pid == ret
                                              einfo("apply_changes return: #{ret}","form")
                                              @caller.caller.list.scroll_to_cursor(ret) if @caller.class.name == 'MyButton'
                                             manqod_db.lock_id_of_base(@form.table,ret) unless wysiwyg?
                                              update(@caller,ret,"modify") if ["add","copy"].include?(@form.runmode)
                                              ret=-1
                                      else eerror("unknown form return code: #{response}")
                              end
                              client.reload_moditem(@form_id) if wysiwyg? #if wysiwyg then reload it in server
             end
             @holder.destroy
             rescue =>err
                     warn("Form error: #{err}",backtrace_to_debug(err),"form","error",false,true,err.to_s)
             ensure
                     begin
                             manqod_db.unlock_id_of_base(@form.table,batch)
                             rescue => err
                             eerror("Form ensured unlock error: #{err}\n#{err.backtrace.join("\n")}","form")
                     end
             end
              end
              ret
end
set_parentM(parent_moditem) click to toggle source
# File lib/FormHolder.rb, line 168
def set_parentM(parent_moditem)
              @parent_moditem=parent_moditem
              self
end
show_all() click to toggle source
# File lib/FormHolder.rb, line 184
def show_all
      @holder.show_all
      self.run if @runmode=="dialog"
end
title() click to toggle source
# File lib/FormHolder.rb, line 192
def title
      "no title"
end
to_s() click to toggle source
# File lib/FormHolder.rb, line 175
def to_s
      "FormHolder of #{form}"
end
update(notifier,pid=@form.parentselected,rm=@form.runmode) click to toggle source
# File lib/FormHolder.rb, line 178
def update(notifier,pid=@form.parentselected,rm=@form.runmode)
              if pid
                     manqod_db.lock_id_of_base(@form.table,pid) unless add? || wysiwyg?
                      @form.update(notifier,pid,rm)
      end
end
vshrink(d) click to toggle source
# File lib/FormHolder.rb, line 189
def vshrink(d)
              holder.allocation.set_height(holder.allocation.height-d.to_i)
end
wysiwyg?() click to toggle source
# File lib/FormHolder.rb, line 156
def wysiwyg?
      runmode == "wysiwygf"
end