source: trunk/desktop/class_c/wpobject.c

Last change on this file was 291, checked in by cinc, 18 years ago

Migrated to new IDL compiler. Metaclasses are still missing.

File size: 30.2 KB
Line 
1/* ***** BEGIN LICENSE BLOCK *****
2* Version: CDDL 1.0/LGPL 2.1
3*
4* The contents of this file are subject to the COMMON DEVELOPMENT AND
5* DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use
6* this file except in compliance with the License. You may obtain a copy of
7* the License at http://www.sun.com/cddl/
8*
9* Software distributed under the License is distributed on an "AS IS" basis,
10* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11* for the specific language governing rights and limitations under the
12* License.
13*
14* The Original Code is "NOM" Netlabs Object Model
15*
16* The Initial Developer of the Original Code is
17* netlabs.org: Chris Wohlgemuth <cinc-ml@netlabs.org>.
18* Portions created by the Initial Developer are Copyright (C) 2005-2007
19* the Initial Developer. All Rights Reserved.
20*
21* Contributor(s):
22*
23* Alternatively, the contents of this file may be used under the terms of
24* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
25* case the provisions of the LGPL are applicable instead of those above. If
26* you wish to allow use of your version of this file only under the terms of
27* the LGPL, and not to allow others to use your version of this file under
28* the terms of the CDDL, indicate your decision by deleting the provisions
29* above and replace them with the notice and other provisions required by the
30* LGPL. If you do not delete the provisions above, a recipient may use your
31* version of this file under the terms of any one of the CDDL or the LGPL.
32*
33* ***** END LICENSE BLOCK ***** */
34/*
35 * And remember, phase 3 is near...
36 */
37#ifndef NOM_WPObject_IMPLEMENTATION_FILE
38#define NOM_WPObject_IMPLEMENTATION_FILE
39#endif
40
41#define INCL_DOS
42#define INCL_DOSERRORS
43#define INCL_DOSSEMAPHORES
44#include <os2.h>
45
46#include <nom.h>
47#include <nomtk.h>
48
49#include <string.h>
50#include <gtk/gtk.h>
51#include <nomguitk.h>
52
53#include "nomwindow.h"
54#include "desktoptypes.h"
55
56#include "wpnotebook.h"
57#include "wpfolderwindow.h"
58#include "m_wpfolder.h"
59#include "wpfolder.h"
60#include "wpobject.ih"
61
62
63/*************** Local vars ************************************/
64
65static nomId WPObjectNomId;
66
67/***************************************************************/
68
69/**
70 \brief Function which implements the wpAllocMem() method of WPObject.
71 */
72NOM_Scope gpointer NOMLINK impl_WPObject_wpAllocMem(WPObject* nomSelf, const gulong cbBytes,
73 gulong* prc, CORBA_Environment *ev)
74{
75
76/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
77 gpointer ptrMem=NULLHANDLE;
78 PUSEITEM pui;
79
80 /* Add mem for the inuse list structures */
81 ptrMem=NOMCalloc(1, cbBytes+sizeof(USEITEM)+sizeof(MEMORYITEM));
82
83 if(!ptrMem) {
84 if(prc)
85 *prc=(gulong)NOMERROR_NOT_ENOUGH_MEMORY;
86 return NULLHANDLE;
87 }
88
89 /* Fill the structures */
90 pui=(PUSEITEM)ptrMem;
91 pui->type=(ULONG)USAGE_MEMORY;
92 pui->wpObject=nomSelf;
93 pui++;
94 ((MEMORYITEM*)pui)->cbBuffer=cbBytes;
95
96 /* Add memory to in use list */
97 WPObject_wpAddToObjUseList(nomSelf, (PUSEITEM)ptrMem, ev);
98
99 return (gpointer)((PBYTE)ptrMem+sizeof(USEITEM)+sizeof(MEMORYITEM));
100}
101
102/**
103 \brief Function which implements the wpFreeMem() method of WPObject.
104 */
105NOM_Scope CORBA_boolean NOMLINK impl_WPObject_wpFreeMem(WPObject* nomSelf, const gpointer pByte, CORBA_Environment *ev)
106{
107 gpointer ptrMem=NULLHANDLE;
108
109 if(!pByte)
110 return FALSE;
111
112 ptrMem=(gpointer)((PBYTE)pByte-sizeof(USEITEM)-sizeof(MEMORYITEM));
113
114 /* remove from inuse list */
115 WPObject_wpDeleteFromObjUseList(nomSelf, (PUSEITEM)ptrMem, ev );
116
117 NOMFree(ptrMem);
118 return TRUE; /* free can't fail */;
119}
120
121/**
122 \brief Override of nomInit() from NOMObject.
123 */
124NOM_Scope void NOMLINK impl_WPObject_nomInit(WPObject* nomSelf, CORBA_Environment *ev)
125{
126 WPObjectData* nomThis=WPObjectGetData(nomSelf);
127
128 /* orbit-idl-c-stubs.c, VoyagerWriteProtoForParentCall line 84 */
129 WPObject_nomInit_parent((NOMObject*) nomSelf, ev);
130
131 //nomPrintf(" Entering %s with nomSelf: 0x%x. nomSelf is: %s.\n",
132 // __FUNCTION__, nomSelf , nomSelf->mtab->nomClassName);
133
134 /* Initialize important data before letting subclasses do their stuff */
135 //_gObjectMutex=g_mutex_new();
136 if(NO_ERROR!=DosCreateMutexSem(NULL, &_gObjectMutex, 0, FALSE))
137 {
138 g_error("Can't create a mutex for WPObject!");
139 }
140
141 _wpInitData(nomSelf, ev);
142}
143
144NOM_Scope void NOMLINK impl_WPObject_nomUnInit(WPObject* nomSelf, CORBA_Environment *ev)
145{
146 WPObjectData* nomThis=WPObjectGetData(nomSelf);
147
148 _wpUnInitData(nomSelf, ev);
149
150 //g_mutex_free(_gObjectMutex);
151 DosCloseMutexSem(_gObjectMutex);
152 WPObject_nomUnInit_parent((NOMObject*)nomSelf, ev);
153}
154
155/**
156 \brief Function which implements the wpInitData() method of WPObject.
157 */
158NOM_Scope void NOMLINK impl_WPObject_wpInitData(WPObject* nomSelf, CORBA_Environment *ev)
159{
160 WPObjectData* nomThis=WPObjectGetData(nomSelf);
161
162 /* Get our unique class ID. We need it for example when inserting menu items to
163 specify the namespace. We query it here because getting a GQuark from a string
164 is rather time consuming. The result is saved in a var for later use. */
165 WPObjectNomId=nomIdFromString("WPObject"); //g_quark_from_string("WPObject");
166
167 /* Make sure a title exists (even if it's an empty string */
168 _pnomStringTitle=NOMStringNew();
169}
170
171/**
172 \brief Function which implements the wpUnInitData() method of WPObject.
173 */
174NOM_Scope void NOMLINK impl_WPObject_wpUnInitData(WPObject* nomSelf, CORBA_Environment *ev)
175{
176/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
177
178}
179
180static
181gboolean defaultWPWindowDeleteHandler(GtkWidget* gtkWidget, GdkEvent* gdkEvent, gpointer pData)
182{
183 WPObject* wpObject;
184 WPWindow* wpWindow;
185
186 PUSEITEM pUseItem=(PUSEITEM) pData;
187
188 wpWindow=(WPWindow*)g_object_get_data(G_OBJECT(gtkWidget), NOMOBJECT_KEY_STRING);
189
190 g_return_val_if_fail(NULLHANDLE!=wpWindow, FALSE);
191
192 /* This is also in the use item */
193 wpObject=WPNoteBook_wpQueryObject(wpWindow, NULLHANDLE);
194
195 g_return_val_if_fail(NULLHANDLE!=wpObject, FALSE);
196
197 WPObject_wpSaveDeferred(wpObject, NULLHANDLE);
198
199 WPObject_wpDeleteFromObjUseList(wpObject, pUseItem, NULLHANDLE);
200
201 return FALSE; /* Let other handlers run */
202}
203
204/**
205 \brief Function which implements the wpOpen() method of WPObject.
206 */
207NOM_Scope gpointer NOMLINK impl_WPObject_wpOpen(WPObject* nomSelf, const PWPFolderWindow nomFolder,
208 const gulong ulView, const nomId nameSpaceId,
209 const gpointer pParam, CORBA_Environment *ev)
210{
211 /* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
212 nomId nSpaceId=nameSpaceId;
213 gulong ulV=ulView;
214
215 /* Special parameter representing a double click or "I just don't know" ;-) */
216 if(OPEN_DEFAULT==ulView)
217 ulV=WPObject_wpQueryDefaultView(nomSelf, &nSpaceId, NULLHANDLE);
218
219 /* We only handle items with in own name space */
220 if(WPObjectNomId==nSpaceId)
221 {
222 switch(ulV)
223 {
224 case OPEN_SETTINGS:
225 {
226 PUSEITEM pui;
227 gulong ulError;
228 WPNoteBook* wpNoteBook;
229
230 if(CCVIEW_ON==WPObject_wpQueryConcurrentView(nomSelf, NULLHANDLE)){
231 /* Concurrent view is ignored for the settings. */
232 if((wpNoteBook=WPObject_wpSwitchTo(nomSelf, ulV, nSpaceId, NULLHANDLE))!=NULLHANDLE)
233 return wpNoteBook;
234 }
235 wpNoteBook=WPNoteBookNew();
236 WPNoteBook_wpSetObject(wpNoteBook, nomSelf, NULLHANDLE);
237
238 _wpAddSettingsPages(nomSelf, wpNoteBook, ev);
239
240 /* Add a view item to inuse list */
241 pui=(PUSEITEM)WPObject_wpAllocMem(nomSelf, sizeof(USEITEM)+sizeof(VIEWITEM), &ulError, ev);
242 /* Fill the structures */
243
244 pui->type=(gulong)USAGE_OPENVIEW;
245 pui->wpObject=nomSelf;
246 pui++;
247 ((VIEWITEM*)pui)->ulView=OPEN_SETTINGS;
248 ((VIEWITEM*)pui)->nomWindow=(NOMWindow*)wpNoteBook;
249 ((VIEWITEM*)pui)->nameSpaceId=WPObjectNomId;
250 pui--;
251 //g_message(" in %s wpNoteBook: %lx pui %lx", __FUNCTION__, wpNoteBook, pui);
252 /* Make sure the view item is removed when the window is closed */
253 g_signal_connect(G_OBJECT(NOMWindow_queryWindowHandle((NOMWindow*)wpNoteBook, NULLHANDLE)),
254 "delete-event",
255 G_CALLBACK(defaultWPWindowDeleteHandler), (gpointer) pui);
256 WPObject_wpAddToObjUseList(nomSelf, pui, ev);
257 WPNoteBook_show(wpNoteBook, ev);
258 return (gpointer) wpNoteBook;
259 }
260 default:
261 /* We are the very last in the chain of classes being called */
262 g_return_val_if_reached(NULLHANDLE);
263 break;
264 }
265 }
266 return NULLHANDLE;
267}
268
269/**
270 \brief Function which implements the wpViewObject() method of WPObject.
271 */
272NOM_Scope gpointer NOMLINK impl_WPObject_wpViewObject(WPObject* nomSelf, const PWPFolderWindow nomFolder,
273 const gulong ulView, const nomId nameSpaceId,
274 const gpointer pParam, CORBA_Environment *ev)
275{
276/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
277 gpointer nomRetval=NULLHANDLE;
278 nomId nSpaceId=nameSpaceId;
279 gulong ulV=ulView;
280
281 /* Special parameter representing a double click or "I just don't know" ;-) */
282 if(OPEN_DEFAULT==ulView)
283 ulV=WPObject_wpQueryDefaultView(nomSelf, &nSpaceId, NULLHANDLE);
284
285 if(CCVIEW_ON==WPObject_wpQueryConcurrentView(nomSelf, NULLHANDLE))
286 return WPObject_wpOpen(nomSelf, nomFolder, ulV, nSpaceId, pParam, NULLHANDLE);
287
288 if((nomRetval=WPObject_wpSwitchTo(nomSelf, ulV, nSpaceId, NULLHANDLE))!=NULLHANDLE)
289 return nomRetval;
290
291 return WPObject_wpOpen(nomSelf, nomFolder, ulV, nSpaceId, pParam, NULLHANDLE);
292}
293
294/**
295 \brief Function which implements the wpSwitchTo() method of WPObject.
296 */
297NOM_Scope gpointer NOMLINK impl_WPObject_wpSwitchTo(WPObject* nomSelf, const gulong ulView, const nomId nameSpaceId,
298 CORBA_Environment *ev)
299{
300 /* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
301 PVIEWITEM pViewItem;
302
303 pViewItem=WPObject_wpFindViewItem(nomSelf, ulView, nameSpaceId, NULLHANDLE, NULLHANDLE);
304
305 if(pViewItem){
306 /* Bring the window to the foreground */
307 NOMWindow_present(pViewItem->nomWindow, ev);
308 return (gpointer)pViewItem->nomWindow;
309 }/* if() */
310
311 return NULLHANDLE;
312}
313
314/**
315 \brief Function which implements the wpRegisterView() method of WPObject.
316 */
317NOM_Scope CORBA_boolean NOMLINK impl_WPObject_wpRegisterView(WPObject* nomSelf, const PNOMWindow pWindow,
318 const PNOMString nomStrViewTitle, CORBA_Environment *ev)
319{
320/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
321
322 g_message("Method %s not implemented.", __FUNCTION__);
323 return FALSE;
324}
325
326/**
327 \brief Function which implements the wpAddToObjUseList() method of WPObject.
328 */
329NOM_Scope CORBA_boolean NOMLINK impl_WPObject_wpAddToObjUseList(WPObject* nomSelf, const PUSEITEM pUseItem,
330 CORBA_Environment *ev)
331{
332 WPObjectData* nomThis=WPObjectGetData(nomSelf);
333
334 if(!pUseItem)
335 return FALSE;
336
337 //g_message(" in %s : %x", __FUNCTION__, pUseItem);
338
339 WPObject_wpRequestObjectMutexSem(nomSelf, 0,ev);
340
341 _glstObjectInUse=g_slist_append( _glstObjectInUse, (gpointer)pUseItem);
342
343 WPObject_wpReleaseObjectMutexSem(nomSelf,ev);
344
345 return TRUE;
346}
347
348/**
349 \brief Function which implements the wpDeleteFromObjUseList() method of WPObject.
350 */
351NOM_Scope CORBA_boolean NOMLINK impl_WPObject_wpDeleteFromObjUseList(WPObject* nomSelf, const PUSEITEM pUseItem,
352 CORBA_Environment *ev)
353{
354 WPObjectData* nomThis=WPObjectGetData(nomSelf);
355
356 if(!pUseItem)
357 return FALSE;
358
359 WPObject_wpRequestObjectMutexSem(nomSelf, 0,ev);
360 //g_message(" in %s %lx", __FUNCTION__, pUseItem);
361 _glstObjectInUse=g_slist_remove( _glstObjectInUse, (gpointer)pUseItem);
362
363 WPObject_wpReleaseObjectMutexSem(nomSelf,ev);
364
365 return TRUE;
366}
367
368
369NOM_Scope PUSEITEM NOMLINK impl_WPObject_wpFindUseItem(WPObject* nomSelf, const gulong ulType,
370 const PUSEITEM pCurrentUseItem, CORBA_Environment *ev)
371{
372 WPObjectData* nomThis=WPObjectGetData(nomSelf);
373 PUSEITEM pUseItem=NULLHANDLE;
374 GSList* tmpList;
375
376 if(NULLHANDLE==_glstObjectInUse)
377 return NULLHANDLE;
378
379 WPObject_wpRequestObjectMutexSem(nomSelf, 0,ev);
380
381 if(NULLHANDLE==pCurrentUseItem)
382 tmpList=_glstObjectInUse;
383 else{
384 tmpList=g_slist_find(_glstObjectInUse, pCurrentUseItem);
385 tmpList=g_slist_next(tmpList);
386 }
387
388 while(tmpList)
389 {
390 pUseItem=(PUSEITEM)tmpList->data;
391
392 //g_message(" a in %s type: %d", __FUNCTION__, pUseItem->type);
393 if(pUseItem && ulType==pUseItem->type)
394 break;
395
396 tmpList=g_slist_next(tmpList);
397 pUseItem=NULLHANDLE;
398 };
399
400 WPObject_wpReleaseObjectMutexSem(nomSelf,ev);
401
402 return pUseItem;
403}
404
405
406NOM_Scope PVIEWITEM NOMLINK impl_WPObject_wpFindViewItem(WPObject* nomSelf, const gulong ulView,
407 const nomId nameSpaceId,
408 const PVIEWITEM pCurrentItem, CORBA_Environment *ev)
409{
410/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
411 PUSEITEM pUseItem;
412 PVIEWITEM pViewItem=NULLHANDLE;
413
414
415 if(!ulView)
416 return NULLHANDLE;
417
418 if(NULLHANDLE==pCurrentItem)
419 pUseItem=WPObject_wpFindUseItem(nomSelf, USAGE_OPENVIEW, NULLHANDLE, ev);
420 else{
421 pUseItem=(PUSEITEM)pCurrentItem;
422 pUseItem--; /* Note that VIEWITEM comes after the USEITEM structure */
423 pUseItem=WPObject_wpFindUseItem(nomSelf, USAGE_OPENVIEW, pUseItem, ev);
424 }
425
426 while(pUseItem)
427 {
428 ++pUseItem;
429 pViewItem=(PVIEWITEM)pUseItem;
430 pUseItem--; /* Note that VIEWITEM comes after the USEITEM structure */
431 //g_message(" a in %s %d", __FUNCTION__, flViews);
432 if((pViewItem->ulView == ulView) && (pViewItem->nameSpaceId==nameSpaceId))
433 break;
434
435 pUseItem=WPObject_wpFindUseItem(nomSelf, USAGE_OPENVIEW, pUseItem, ev);
436 pViewItem=NULLHANDLE;
437 }
438
439 return pViewItem;
440}
441
442NOM_Scope gulong NOMLINK impl_WPObject_wpQueryDefaultView(WPObject* nomSelf, const pnomId pNameSpaceId,
443 CORBA_Environment *ev)
444{
445/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
446
447 *pNameSpaceId=WPObjectNomId;
448
449 return OPEN_SETTINGS;
450}
451
452NOM_Scope CORBA_boolean NOMLINK impl_WPObject_wpSetDefaultView(WPObject* nomSelf, const gulong ulView,
453 const nomId nameSpaceId, CORBA_Environment *ev)
454{
455/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
456 CORBA_boolean nomRetval=FALSE;
457
458 g_message("%d %s not implemented", __LINE__, __FUNCTION__);
459 return nomRetval;
460}
461
462NOM_Scope void NOMLINK impl_WPObject_wpSetConcurrentView(WPObject* nomSelf, const gulong ulCCView,
463 CORBA_Environment *ev)
464{
465/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
466
467 g_message("%d %s not implemented", __LINE__, __FUNCTION__);
468
469}
470
471NOM_Scope gulong NOMLINK impl_WPObject_wpQueryConcurrentView(WPObject* nomSelf, CORBA_Environment *ev)
472{
473 /* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
474
475 return CCVIEW_ON;
476}
477
478NOM_Scope void NOMLINK impl_WPObject_wpLockObject(WPObject* nomSelf, CORBA_Environment *ev)
479{
480 WPObjectData* nomThis=WPObjectGetData(nomSelf);
481
482 g_atomic_int_inc(&_iLockCounter);
483}
484
485NOM_Scope CORBA_boolean NOMLINK impl_WPObject_wpUnlockObject(WPObject* nomSelf, CORBA_Environment *ev)
486{
487 WPObjectData* nomThis=WPObjectGetData(nomSelf);
488
489 /* We return TRUE if the counter is 0 */
490 if(g_atomic_int_dec_and_test(&_iLockCounter))
491 {
492 /* Counter is 0 so the object should go dormant */
493 return TRUE;
494 }
495 return FALSE;
496}
497
498NOM_Scope CORBA_boolean NOMLINK impl_WPObject_wpObjectIsLocked(WPObject* nomSelf, CORBA_Environment *ev)
499{
500 WPObjectData* nomThis=WPObjectGetData(nomSelf);
501
502 return g_atomic_int_get(&_iLockCounter) && TRUE;
503}
504
505NOM_Scope gpointer NOMLINK impl_WPObject_wpQueryIcon(WPObject* nomSelf, CORBA_Environment *ev)
506{
507/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
508
509 //g_message("%d %s !!! Achtung explicit metaclass nicht in mtab ---> %x %x", __LINE__, __FUNCTION__,
510 // _nomGetClass((NOMObject*)nomSelf, NULLHANDLE), _WPObject);
511 return M_WPObject_wpclsQueryIcon(_nomGetClass((NOMObject*)nomSelf, NULLHANDLE), NULLHANDLE);
512 // return M_WPObject_wpclsQueryIcon(_WPObject, NULLHANDLE);
513}
514
515NOM_Scope CORBA_unsigned_long NOMLINK impl_WPObject_wpRequestObjectMutexSem(WPObject* nomSelf,
516 const CORBA_unsigned_long ulReserved,
517 CORBA_Environment *ev)
518{
519 WPObjectData* nomThis=WPObjectGetData(nomSelf);
520
521 return DosRequestMutexSem(_gObjectMutex, -1L);
522}
523
524NOM_Scope CORBA_unsigned_long NOMLINK impl_WPObject_wpReleaseObjectMutexSem(WPObject* nomSelf, CORBA_Environment *ev)
525{
526 WPObjectData* nomThis=WPObjectGetData(nomSelf);
527 return DosReleaseMutexSem(_gObjectMutex);
528}
529
530NOM_Scope void NOMLINK impl_WPObject_wpSetTitle(WPObject* nomSelf, const PNOMString pnomStrNewTitle,
531 CORBA_Environment *ev)
532{
533 WPObjectData* nomThis=WPObjectGetData(nomSelf);
534 PNOMString tmpString=(PNOMString)NOMString_new(pnomStrNewTitle, NULLHANDLE);
535 gpointer tmpPtr;
536
537 /* Create a new title */
538 NOMString_assign(tmpString, pnomStrNewTitle, NULLHANDLE);
539
540 /* It may happen that someone changed the title from another thread. We may either
541 bail out then or just use our string as the mother of all strings. Since we are the last one
542 trying to change the title our string is presumably the correct one. At least we act
543 so :P. The memory holding the old string (which may not be the correct one anymore) is
544 still valid because we hold a pointer to it in tmpPtr. Garbage collection won't free it
545 under our feet. */
546 do{
547 /* Get old NOMString containing old title */
548 tmpPtr=g_atomic_pointer_get(&_pnomStringTitle);
549 }while(!g_atomic_pointer_compare_and_exchange((gpointer*)&_pnomStringTitle, tmpPtr, (gpointer) tmpString));
550}
551
552NOM_Scope void NOMLINK impl_WPObject_wpSetTitleFromCString(WPObject* nomSelf, const CORBA_char * chrNewTitle,
553 CORBA_Environment *ev)
554{
555 WPObjectData* nomThis=WPObjectGetData(nomSelf);
556 PNOMString orgTitle;
557 PNOMString tmpString;
558
559 orgTitle=(PNOMString)g_atomic_pointer_get(&_pnomStringTitle);
560 tmpString=(PNOMString)NOMString_new(orgTitle, NULLHANDLE);
561
562 NOMString_assignCString(tmpString, chrNewTitle, NULLHANDLE);
563 do{
564 /* Get old NOMString containing old title */
565 orgTitle=(PNOMString)g_atomic_pointer_get(&_pnomStringTitle);
566 }while(!g_atomic_pointer_compare_and_exchange((gpointer*)&_pnomStringTitle,
567 (gpointer)orgTitle, (gpointer) tmpString));
568}
569
570NOM_Scope PNOMString NOMLINK impl_WPObject_wpQueryTitle(WPObject* nomSelf, CORBA_Environment *ev)
571{
572 gpointer tmpPtr;
573 WPObjectData* nomThis=WPObjectGetData(nomSelf);
574
575 /*
576 This string will remain valid as long as we use it. Even if someone changes the title
577 while we are in this method the garbage collector won't free it. The other thread
578 changing the title is working on a copy so no problem here. */
579 tmpPtr=g_atomic_pointer_get(&_pnomStringTitle);
580
581 return NOMString_copy(tmpPtr, ev);
582}
583
584NOM_Scope CORBA_unsigned_long NOMLINK impl_WPObject_wpAddObjectGeneralPage(WPObject* nomSelf,
585 const PWPNoteBook wpNoteBook,
586 CORBA_Environment *ev)
587{
588/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
589 GtkWidget *frame;
590 GtkWidget *label;
591 GtkWidget *vbox;
592 GtkWidget *hbox;
593 GtkWidget *button;
594 GtkWidget *entry;
595
596 /* A vbox to layout the settings page */
597 vbox=gtk_vbox_new(FALSE, 0);
598
599 hbox=gtk_hbutton_box_new ();
600 gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_SPREAD);
601 gtk_box_set_spacing (GTK_BOX (hbox), 2);
602
603 /* Create buttons */
604 button = gtk_button_new_from_stock (GTK_STOCK_OK);
605 gtk_container_add (GTK_CONTAINER (hbox), button);
606 button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
607 gtk_container_add (GTK_CONTAINER (hbox), button);
608 /* Put the buttons at the very bottom */
609 gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 1);
610
611 /* The icon part */
612 frame = gtk_frame_new ("Current Icon");
613 gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
614 gtk_widget_set_size_request(frame, 200, 100);
615 gtk_box_pack_end (GTK_BOX (vbox), frame, FALSE, FALSE, 1);
616
617 /* The Title part */
618 frame = gtk_frame_new ("Title");
619 gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
620 entry=gtk_entry_new();
621 gtk_entry_set_max_length(GTK_ENTRY(entry), CCHMAXPATH);
622 gtk_container_add (GTK_CONTAINER (frame), entry);
623 gtk_box_pack_end (GTK_BOX (vbox), frame, FALSE, FALSE, 1);
624
625 /* The label for the tab */
626 label = gtk_label_new ("Icon");
627
628 gtk_widget_show_all (vbox);
629
630 NOMNoteBook_prependPage(WPNoteBook_wpQueryNoteBook(wpNoteBook, ev), vbox, label, ev);
631
632 return 1234;
633}
634
635NOM_Scope CORBA_boolean NOMLINK impl_WPObject_wpAddSettingsPages(WPObject* nomSelf, const PWPNoteBook wpNoteBook,
636 CORBA_Environment *ev)
637{
638/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
639
640 _wpAddObjectGeneralPage(nomSelf, wpNoteBook, ev);
641 return TRUE;
642}
643
644NOM_Scope CORBA_unsigned_long NOMLINK impl_WPObject_wpInsertSettingsPage(WPObject* nomSelf,
645 const PWPNoteBook wpNoteBook,
646 const gpointer ppageinfo,
647 CORBA_Environment *ev)
648{
649/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
650 CORBA_unsigned_long nomRetval;
651
652 return nomRetval;
653}
654
655
656NOM_Scope PNOMMenu NOMLINK impl_WPObject_wpDisplayMenu(WPObject* nomSelf, const PWPFolderWindow nomFolder,
657 const gpointer gReserved, const CORBA_unsigned_long ulMenuType,
658 const CORBA_unsigned_long ulReserved, CORBA_Environment *ev)
659{
660/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
661 PNOMMenu nomMenu=NOMMenuNew();
662
663 /* Let classes insert menu items now */
664 WPObject_wpModifyMenu(nomSelf, nomFolder, nomMenu, ulMenuType, ev);
665
666 /* Let classes filter menu items now */
667 WPObject_wpFilterMenu(nomSelf, nomFolder, nomMenu, ulMenuType, 0, ev);
668
669 /* And finally show it */
670 gtk_menu_popup(GTK_MENU(NOMMenu_queryMenuHandle(nomMenu,ev)), NULL, NULL, NULL, NULL, 0,
671 gtk_get_current_event_time());
672
673 return nomMenu;
674}
675
676NOM_Scope void NOMLINK impl_WPObject_wpModifyMenu(WPObject* nomSelf, const PWPFolderWindow nomFolder,
677 const PNOMMenu nomMenu, const CORBA_unsigned_long ulMenuType,
678 CORBA_Environment *ev)
679{
680 NOMMenuItem* mItem;
681 /* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
682
683 mItem=NOMMenuItemNew();
684
685 NOMMenuItem_setup(mItem, __FUNCTION__, WPObjectNomId, 0, ev);
686 WPObject_wpInsertMenuItem(nomSelf, nomMenu, mItem, 0, ev);
687
688 mItem=NOMMenuItemNew();
689 NOMMenuItem_setup(mItem, "Settings...", WPObjectNomId, WPMENUID_PROPERTIES, ev);
690 WPObject_wpInsertMenuItem(nomSelf, nomMenu, mItem, 0, ev);
691}
692
693NOM_Scope void NOMLINK impl_WPObject_wpFilterMenu(WPObject* nomSelf, const PWPFolderWindow nomFolder,
694 const PNOMMenu nomMenu, const CORBA_unsigned_long ulMenuType,
695 const CORBA_unsigned_long ulFlags, CORBA_Environment *ev)
696{
697/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
698
699}
700
701NOM_Scope CORBA_boolean NOMLINK impl_WPObject_wpMenuItemSelected(WPObject* nomSelf, const PWPFolderWindow nomFolder,
702 const PNOMMenuItem nomMenuItem,
703 CORBA_Environment *ev)
704{
705/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
706
707 /* We only handle items within own name space */
708 if(WPObjectNomId==NOMMenuItem_queryNameSpaceId(nomMenuItem, ev))
709 {
710 switch(NOMMenuItem_queryId(nomMenuItem, ev))
711 {
712 case WPMENUID_PROPERTIES:
713 {
714 WPObject_wpViewObject(nomSelf, nomFolder,
715 OPEN_SETTINGS, WPObjectNomId, NULLHANDLE, NULLHANDLE);
716 return TRUE; /* We always return TRUE to show, we handled the menu item. It doesn't
717 matter if we actually succeeded with creating the settings notebook. */
718 }
719 default:
720 break;
721 }
722 }
723 return FALSE;
724}
725
726/*
727 Callback for desktop menu items. This callback takes the object pointer and call wpMenuItemSelected()
728 of the object.
729 */
730static void menuItemActivateCallBack(GtkMenuItem* gtkMenuItem, gpointer wpObject)
731{
732 PNOMMenuItem pItem;
733
734#if 0
735 if(!nomIsObj((WPObject*)wpObject))
736 return;
737#endif
738
739 pItem=(PNOMMenuItem) g_object_get_data(G_OBJECT(gtkMenuItem), NOMOBJECT_KEY_STRING);
740
741 WPObject_wpMenuItemSelected((WPObject*) wpObject, NULLHANDLE,
742 pItem, NULLHANDLE);
743}
744
745/*
746 This method adds the correct callback function to the menuitem and inserts it into the given menu.
747
748 FIXME: position information for the menu item isn't used yet. The Item is always appended.
749
750 */
751NOM_Scope void NOMLINK impl_WPObject_wpInsertMenuItem(WPObject* nomSelf, const PNOMMenu nomMenu,
752 const PNOMMenuItem nomMenuItem,
753 const CORBA_unsigned_long ulPosition, CORBA_Environment *ev)
754{
755/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
756
757 g_signal_connect(NOMMenuItem_queryMenuItemHandle(nomMenuItem, ev), "activate",
758 (GCallback) menuItemActivateCallBack, (gpointer) nomSelf);
759
760 gtk_menu_shell_append(GTK_MENU_SHELL(NOMMenu_queryMenuHandle(nomMenu,ev)),
761 NOMMenuItem_queryMenuItemHandle(nomMenuItem, ev));
762
763}
764
765NOM_Scope CORBA_boolean NOMLINK impl_WPObject_wpSaveDeferred(WPObject* nomSelf, CORBA_Environment *ev)
766{
767/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
768
769 g_message("%s not implemented", __FUNCTION__);
770
771 return TRUE;
772}
773
774NOM_Scope CORBA_boolean NOMLINK impl_WPObject_wpSaveImmediate(WPObject* nomSelf, CORBA_Environment *ev)
775{
776/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
777
778 g_message("%s not implemented", __FUNCTION__);
779
780 return TRUE;
781}
782
783NOM_Scope void NOMLINK impl_WPObject_wpSetFolder(WPObject* nomSelf, const PWPFolder wpParentFolder,
784 CORBA_Environment *ev)
785{
786 WPObjectData* nomThis=WPObjectGetData(nomSelf);
787
788 _wpParentFldr=wpParentFolder;
789}
790
791NOM_Scope PWPFolder NOMLINK impl_WPObject_wpQueryFolder(WPObject* nomSelf, CORBA_Environment *ev)
792{
793 WPObjectData* nomThis=WPObjectGetData(nomSelf);
794
795 return _wpParentFldr;
796}
797
798
799NOM_Scope gulong NOMLINK impl_WPObject_wpDragOver(WPObject* nomSelf, const gpointer containerHandle,
800 const gpointer pDragInfo, CORBA_Environment *ev)
801{
802 /* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
803
804 return 0; /* Don't allow drop */
805}
806
807NOM_Scope gulong NOMLINK impl_WPObject_wpDrop(WPObject* nomSelf, const gpointer containerHandle,
808 const gpointer pDragInfo, CORBA_Environment *ev)
809{
810 /* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
811 g_message("Calling %s", __FUNCTION__);
812 return 0;
813}
814
815
816NOM_Scope CORBA_boolean NOMLINK impl_WPObject_wpMoveObject(WPObject* nomSelf,
817 const PWPFolder wpTargetFolder,
818 CORBA_Environment *ev)
819{
820/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
821 WPFolder * wpFolder;
822 PUSEITEM pui;
823
824 if(!nomIsObj(wpTargetFolder))
825 return FALSE;
826
827 /* Get folder holding the object */
828 wpFolder=WPObject_wpQueryFolder(nomSelf, NULLHANDLE);
829
830 g_message("Parent folder is %s",
831 NOMPath_queryCString(WPFolder_wpQueryFileName(wpFolder, TRUE, NULLHANDLE),
832 NULLHANDLE));
833
834 /* Remove it from the parent folders content list. */
835 WPFolder_wpDeleteFromContent(wpFolder, nomSelf, NULLHANDLE);
836
837 /* Remove it from the folders model thus any folder window. */
838 pui=_wpDeleteFromStore(wpFolder, nomSelf, NULLHANDLE);
839 _wpFreeMem(nomSelf, pui, NULLHANDLE);
840
841 g_message("Target folder is %s",
842 NOMPath_queryCString(WPFolder_wpQueryFileName(wpTargetFolder, TRUE, NULLHANDLE),
843 NULLHANDLE));
844
845 /* Insert into the new folder */
846 _wpAddToContent(wpTargetFolder, nomSelf, NULLHANDLE);
847 _wpAddToStore(wpTargetFolder, nomSelf, NULLHANDLE);
848
849 return FALSE;
850}
851
852NOM_Scope PWPObject NOMLINK impl_WPObject_wpCopyObject(WPObject* nomSelf,
853 const PWPFolder wpTargetFolder,
854 const CORBA_boolean fLock,
855 CORBA_Environment *ev)
856{
857/* WPObjectData* nomThis=WPObjectGetData(nomSelf); */
858
859 g_message("Calling %s, not implmented yet", __FUNCTION__);
860
861 return FALSE;
862}
863
Note: See TracBrowser for help on using the repository browser.