Embedding evince with evview

Linux specific forum
DarkDragon
Addict
Addict
Posts: 2345
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Embedding evince with evview

Post by DarkDragon »

Hello,

I'm trying to embed evince in my program using evview 2.30 (on ubuntu 10.04 amd64), but it doesn't work. It just shows an empty window and nothing I try changes this except if I only set the status to loading (which shows the loading-text) without inserting a document.

Code: Select all

Enumeration
  #EV_SIZING_BEST_FIT
  #EV_SIZING_FIT_WIDTH
  #EV_SIZING_FREE
EndEnumeration

Import "/usr/lib/libevview.so"
  ev_init.i()
  ev_view_new.i()
  ev_view_set_loading.i(*View)
  ev_view_reload.i(*View)
  ev_view_set_model.i(*View, *Model)
  
  ev_document_factory_get_document.i(Filename.p-ascii, *Error)
  ev_document_model_set_continuous.i(*View, Mode.i)
  ev_document_model_new_with_document.i(*Document)
  
  ev_document_model_set_page.i(*Model, Page.i)
  ev_document_model_get_page.i(*Model)
  
  ev_document_model_set_scale.i(*Model, Scale.d)
  ev_document_model_get_scale.d(*Model)
  
  ev_document_model_set_min_scale.i(*Model, Scale.d)
  ev_document_model_get_min_scale.d(*Model)
  
  ev_document_model_set_max_scale.i(*Model, Scale.d)
  ev_document_model_get_max_scale.d(*Model)
  
  ev_document_model_set_sizing_mode.i(*Model, Mode.i)
EndImport

Define *window.GtkWidget
Define *evview.GtkWidget
Define *document
Define *model

gtk_init_(0, 0)
ev_init()

*window = gtk_window_new_(#GTK_WINDOW_TOPLEVEL)

*evview = ev_view_new()
*document = ev_document_factory_get_document("file:///home/bradan/Downloads/uebung7.pdf", #Null)
; the file exists

*model = ev_document_model_new_with_document(*document)

gtk_container_add_(*window, *evview)

gtk_widget_set_size_request_(*window, 800, 600)

ev_document_model_set_sizing_mode(*model, #EV_SIZING_FIT_WIDTH)

; without the following line it shows "wird geladen..." ("loading ...")
ev_view_set_model(*evview, *model)

ev_view_set_loading(*evview)

gtk_widget_show_(*evview)
gtk_widget_show_(*window)

gtk_main_()
Thanks for any help. *document, *model etc. are all non-zero.
bye,
Daniel
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Re: Embedding evince with evview

Post by walker »

Hi,

I'm not sure (working on win atm) but try a gtk_widget_show_all_() ... guessing the model has to be "shown" too ...
DarkDragon
Addict
Addict
Posts: 2345
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Embedding evince with evview

Post by DarkDragon »

Hello,

Thanks for your answer, but it didn't help. Anyway, the evince documentation is really empty and it has changed very much as I can read in the www. In former times they only used

Code: Select all

ev_view_set_document(*evview, *document)
instead of

Code: Select all

ev_view_set_model(*evview, *model)
But that command does not exist anymore. I've found a workaround, but its tricky and shouldn't be used.

Code: Select all

Procedure FindWindowByText(Text.s, Parent.s = "-root")
  Protected Result = 0
  Protected Line.s
  Protected Handle.s
  
  Program = RunProgram("xwininfo", Parent + " -children", "", #PB_Program_Open | #PB_Program_Read)
  If Program
    
    While ProgramRunning(Program)
      If AvailableProgramOutput(Program)
        Line = Trim(ReadProgramString(Program))
        If Line
          If FindString(Line, Text, 1)
            Handle = ReplaceString(StringField(Line, 1, " "), "0x", "$")
            Result = Val(Handle)
          EndIf
        EndIf
      EndIf
    Wend
    
    CloseProgram(Program)
  EndIf
  ProcedureReturn Result
EndProcedure

ImportC "/usr/lib/libX11.so"
  XOpenDisplay.i(*Display)
  XCloseDisplay.i(*Display)
  XReparentWindow.i(*Display, Window.i, Parent.i, x.i, y.i)
  XSync.i(*Display, Flag.i)
  XFlush.i(*Display)
EndImport

ImportC "/usr/lib/libgtk-x11-2.0.so"
  gtk_widget_get_window.i(*Window)
EndImport

Define *Display
Define ParentWnd, ChildWnd

*Display = XOpenDisplay(0)
Debug *Display

OpenWindow(0, 0, 0, 800, 600, "Bradan's Blubber", #PB_Window_BorderLess)

*Window.GtkWindow = WindowID(0)

Debug gdk_x11_drawable_get_xid_(gtk_widget_get_window(*Window))

ParentWnd = FindWindowByText("Bradan's Blubber")
ChildWnd = FindWindowByText("test.pdf")

Debug ChildWnd
Debug ParentWnd

XReparentWindow(*Display, ChildWnd, ParentWnd, 10, 10)

XSync(*Display, 0)
XFlush(*Display)

XCloseDisplay(*Display)

Repeat
Until WaitWindowEvent(3) = #PB_Event_CloseWindow
You need to start evince with "test.pdf" first. Evince also has some parameters which I use for identifying the new window. And there is another problem: all the child gtk widgets are owner-drawn, and have no XWindow as container. So you need to create your own toplevel borderless window, embed it with x11 into your gtk window, and embed the evince thing into that window to have a native purebasic window control. Otherwise you might need to port the whole x11 headers which is just horrible.

I'll wait for further suggestions how to solve it with the evview library. ;-)
bye,
Daniel
Post Reply