Ignore:
Timestamp:
Nov 28, 2006, 8:14:29 PM (19 years ago)
Author:
cinc
Message:

Created NOMString class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/desktop/class_c/wpfolder.c

    r111 r122  
    6161#include "desktop.h"
    6262#include "helper.h"
     63#include "desktoptypes.h"
    6364
    6465/* Enum for the folder store */
     
    9394}
    9495
     96/*
     97  Check if the right button click was within a certain time. That means
     98  the user released the button again within a short time period. On OS/2
     99  a context menu will display after the user released the button not when
     100  the user pressed it.
     101 */
     102#define CTXT_MENU_BUTTON_DELAY 250
     103static gboolean
     104fldr_checkContextButton(GdkEventButton *event)
     105{
     106  static guint guiTime=0;
     107
     108  /* Right mouse button */
     109  if (event->button != 3)
     110    return FALSE;
     111
     112  /* Ignore double-clicks and triple-clicks */
     113  if(event->type == GDK_BUTTON_PRESS)
     114    guiTime=event->time;
     115
     116  if(event->type == GDK_BUTTON_RELEASE)
     117    {
     118      if(event->time-guiTime<CTXT_MENU_BUTTON_DELAY)
     119        return TRUE;
     120    }
     121
     122  return FALSE;
     123}
     124
    95125static gboolean
    96126fldr_handleButtonEvent (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
    97127{
    98 #if 0
    99128  if(fldr_checkContextButton(event))
    100129    {
     130      DosBeep(5000, 100);
     131      /* This is the folder object not the object on which a click occured */
    101132      WPObject *wpObject=(WPObject*)user_data;
    102      
     133      if(nomIsObj(wpObject)){
     134        nomPrintf("%s: %x->%s\n", __FUNCTION__, wpObject, wpObject->mtab->nomClassName);       
     135      }
     136#if 0     
    103137      if(!somIsObj(wpObject))
    104138        return TRUE;
     
    108142      _wpDisplayMenu(wpObject, NULLHANDLE, (HWND) widget, NULLHANDLE, 0, (ULONG) 0);
    109143      return TRUE;
     144#endif
    110145    }
     146
     147  return FALSE;
     148}
     149
     150
     151static BOOL
     152fldr_fillStore (GtkListStore *store, const gchar* gchrPath)
     153{
     154
     155  GDir *gDir;
     156  const gchar *gchrCurrentEntry;
     157  GtkTreeIter iter;
     158
     159  nomPrintf("In %s:  %s\n", __FUNCTION__, gchrPath);         
     160
     161  /* First clear the store */
     162  gtk_list_store_clear (store);
     163
     164  /* Now go through the directory and extract all the file
     165   * information */
     166  gDir = g_dir_open (gchrPath, 0, NULL);
     167  if (!gDir)
     168    return FALSE;
     169
     170  while ((gchrCurrentEntry = g_dir_read_name (gDir))!= NULL)
     171    {
     172      gchar *path, *display_name;
     173      gboolean is_dir;
     174
     175      if (gchrCurrentEntry[0] != '\0')
     176        {
     177          path = g_build_filename (gchrPath, gchrCurrentEntry, NULL);
     178          nomPrintf("  %s\n", path);         
     179
     180          display_name = g_filename_to_utf8 (gchrCurrentEntry, -1, NULL, NULL, NULL);
     181          if(g_file_test (path, G_FILE_TEST_IS_DIR))
     182            {
     183              /* It's a folder */
     184              WPFolder* wpFolder;
     185
     186              wpFolder=WPFolderNew();
     187              if(nomIsObj(wpFolder))
     188                {
     189                  gtk_list_store_append (store, &iter);
     190
     191                  gtk_list_store_set (store, &iter,
     192                                      COL_PATH, path,
     193                                      COL_DISPLAY_NAME, display_name,
     194                                      COL_IS_DIRECTORY, is_dir,
     195                                      COL_PIXBUF, _wpQueryIcon(wpFolder, NULLHANDLE), //folder_pixbuf ,
     196                                      -1);
     197
     198                }/* if(nomIsObj(wpFolder)) */
     199            }/* if(g_file_test (path, G_FILE_TEST_IS_DIR)) */
     200          else
     201            {
     202              /* It's a file */
     203              WPDataFile* wpDataFile;
     204
     205              wpDataFile=WPDataFileNew();
     206
     207              if(nomIsObj(wpDataFile))
     208                {
     209                  gtk_list_store_append (store, &iter);
     210
     211#warning !!!! some problems with icon handling here !!!!
     212                  nomPrintf("Icon ptr: %x\n", _wpQueryIcon((WPObject*)wpDataFile, NULLHANDLE));
     213                  gtk_list_store_set (store, &iter,
     214                                      COL_PATH, path,
     215                                      COL_DISPLAY_NAME, display_name,
     216                                      COL_IS_DIRECTORY, is_dir,
     217                                      COL_PIXBUF, _wpQueryIcon((WPObject*)wpDataFile, NULLHANDLE), //file_pixbuf,
     218                                      -1);
     219                }
     220            }
     221          g_free (path);
     222          g_free (display_name);
     223        }/* if (gchrCurrentEntry[0] != '\0') */
     224    }/* while */
     225
     226  g_dir_close(gDir);
     227
     228  return TRUE;
     229}
     230
     231/* pszPath contains the fully qualified path (checked with WPS) */
     232NOM_Scope CORBA_boolean NOMLINK impl_WPFolder_wpPopulate(WPFolder* nomSelf, const CORBA_unsigned_long ulReserved, const CORBA_char * pszPath, const CORBA_boolean fFoldersOnly, CORBA_Environment *ev)
     233{
     234 WPFolderData* nomThis=WPFolderGetData(nomSelf);
     235  GtkListStore* gStore;
     236  PPRIVFOLDERDATA priv;
     237
     238  nomPrintf("    Entering %s with nomSelf: 0x%x. nomSelf is: %s. Path is %s\n",
     239            __FUNCTION__, nomSelf , nomSelf->mtab->nomClassName, pszPath);
     240
     241  g_return_val_if_fail(_privFolderData!=NULLHANDLE, FALSE);      /* Huh! What happened in wpInitData()? */
     242  g_log("WPFolder", G_LOG_LEVEL_DEBUG, "%s: Populating %s\n", __FUNCTION__, pszPath);
     243
     244#warning !!!!! Window creation must be done elsewhere !!!!!
     245  _wpCreateFolderWindow(nomSelf, NULLHANDLE);
     246
     247#if 0
     248  /* Already populated? */
     249  if(fFoldersOnly &&
     250     (_wpQueryFldrFlags(somSelf) & (FOI_POPULATEDWITHFOLDERS | FOI_POPULATEDWITHALL)))
     251    return TRUE;
     252  else if(_wpQueryFldrFlags(somSelf) & FOI_POPULATEDWITHALL)
     253    return TRUE;
    111254#endif
     255
     256  priv=_privFolderData;
     257
     258  if(!priv->gstoreFldContents)
     259    {
     260      /* Create a store holding the folder contents */
     261      gStore=fldr_CreateStore();
     262      g_return_val_if_fail(gStore!=NULLHANDLE, FALSE);
     263      priv->gstoreFldContents=gStore;
     264    }
     265
     266  /* Fill our store */
     267  if(gStore)
     268    fldr_fillStore(gStore, pszPath);
     269  else
     270    return FALSE;
     271
     272  gtk_icon_view_set_model(GTK_ICON_VIEW (priv->gtkIconView), GTK_TREE_MODEL (priv->gstoreFldContents));
     273
     274  /* We now set which model columns that correspont to the text
     275   * and pixbuf of each item
     276   */
     277  gtk_icon_view_set_text_column (GTK_ICON_VIEW (priv->gtkIconView), COL_DISPLAY_NAME);
     278  gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (priv->gtkIconView), COL_PIXBUF);
     279  gtk_icon_view_set_item_width (GTK_ICON_VIEW (priv->gtkIconView),
     280                                100);
     281
     282  g_object_unref (gStore);
     283
    112284  return FALSE;
    113285}
    114286
     287
     288NOM_Scope void NOMLINK impl_WPFolder_wpInitData(WPFolder* nomSelf, CORBA_Environment *ev)
     289{
     290  gulong ulErr;
     291  WPFolderData* nomThis=WPFolderGetData(nomSelf);
     292
     293  /* orbit-idl-c-stubs.c, VoyagerWriteProtoForParentCall line 84 */
     294  WPFolder_wpInitData_parent((WPObject*)nomSelf,  ev);
     295
     296  nomPrintf("    Entering %s with nomSelf: 0x%x. nomSelf is: %s.\n",
     297            __FUNCTION__, nomSelf , nomSelf->mtab->nomClassName);
     298  _privFolderData=_wpAllocMem((WPObject*)nomSelf, sizeof(PRIVFOLDERDATA), (CORBA_unsigned_long*)&ulErr, NULLHANDLE);
     299}
     300
     301NOM_Scope gpointer NOMLINK impl_WPFolder_wpOpen(WPFolder* nomSelf, const gpointer ptrReserved,
     302                                                const CORBA_unsigned_long ulView, const gpointer ptrParams,
     303                                                CORBA_Environment *ev)
     304{
     305/* WPFolderData* nomThis=WPFolderGetData(nomSelf); */
     306
     307  switch(ulView)
     308    {
     309    case OPEN_CONTENTS:
     310    case OPEN_DEFAULT:
     311      {
     312#if 0
     313        char path[CCHMAXPATH];
     314        ULONG ulSize;
     315       
     316        /* Get full path of folder */
     317        ulSize=sizeof(path);
     318       
     319        if(!_wpQueryRealName(somSelf, path, &ulSize, TRUE))
     320          return NULLHANDLE; /* Error */
     321       
     322        nomPrintf("%s: opening %s\n", __FUNCTION__, path);
     323       
     324        /* Create folder window */
     325        hwndFolder=fldr_createFolderWindow(somSelf, path);
     326       
     327        if(!hwndFolder)
     328          return NULLHANDLE;
     329       
     330        somPrintf("somSelf: %x, hwndFolder: %x\n", somSelf, hwndFolder);
     331        /* Set object pointer */
     332        /*          dw_window_set_data(hwndFolder, "thisObject", somSelf);
     333                    msg("somSelf 2: %x, hwnd: %x", dw_window_get_data(hwndFolder, "thisObject"), hwndFolder); */
     334
     335        /* populate the folder */
     336        _wpPopulate(somSelf, 0, path, FALSE); /* Contents or details. Tree isn't supported yet */
     337
     338        break;
     339#endif
     340      }/* default */
     341    default:
     342      g_return_val_if_reached(NULLHANDLE);
     343      break;
     344    }/* switch */
     345  return NULLHANDLE;
     346}
     347
     348NOM_Scope gpointer NOMLINK impl_WPFolder_wpQueryIcon(WPFolder* nomSelf, CORBA_Environment *ev)
     349{
     350  static const gchar *gchrIconName=NULLHANDLE;
     351  static gpointer ptrIcon=NULLHANDLE;
     352  GError *error=NULL;
     353
     354/* WPFolderData* nomThis=WPFolderGetData(nomSelf); */
     355
     356  /* Load default wpObject icon */
     357  if(!gchrIconName){
     358    gchrIconName=g_build_filename(priv_getIconDir(), WPFOLDER_ICON_FILE, NULL);
     359   
     360    g_return_val_if_fail(g_file_test (gchrIconName, G_FILE_TEST_EXISTS), NULLHANDLE);
     361    nomPrintf("IconFile: %s\n", gchrIconName); 
     362    //  _hPointerCls = (HPOINTER)gdk_pixbuf_new_from_file (gchrIconName, &error);
     363    ptrIcon=gdk_pixbuf_new_from_file (gchrIconName, &error);
     364  }
     365  return ptrIcon;
     366
     367  /*  WPFolder_wpQueryIcon_parent(nomSelf,  ev); */
     368}
     369
    115370/*
    116   This function creates the folder window it doesn't queries any files or creates
     371  This method creates the folder window it doesn't queries any files or creates
    117372  models and stuff.
    118373*/
    119 GtkWidget* fldr_createFolderWindow(WPFolder *nomSelf, const gchar* gcPath)
    120 {
     374NOM_Scope gpointer NOMLINK impl_WPFolder_wpCreateFolderWindow(WPFolder* nomSelf, CORBA_Environment *ev)
     375{
     376/* WPFolderData* nomThis=WPFolderGetData(nomSelf); */
    121377  GtkWidget* window;
    122378  GtkWidget *vbox;
     
    132388  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    133389  /* Set title */
    134   gtk_window_set_title (GTK_WINDOW (window), gcPath);
     390  //  gtk_window_set_title (GTK_WINDOW (window), gcPath);
     391  gtk_window_set_title (GTK_WINDOW (window), "");
    135392  /* FIXME: Set default size of folder frame. Will later use a stored value */
    136393  gtk_window_set_default_size (GTK_WINDOW (window), 650, 400);
     
    197454}
    198455
    199 static BOOL
    200 fldr_fillStore (GtkListStore *store, const gchar* gchrPath)
    201 {
    202 
    203   GDir *gDir;
    204   const gchar *gchrCurrentEntry;
    205   GtkTreeIter iter;
    206  
    207   /* First clear the store */
    208   gtk_list_store_clear (store);
    209 
    210   /* Now go through the directory and extract all the file
    211    * information */
    212   gDir = g_dir_open (gchrPath, 0, NULL);
    213   if (!gDir)
    214     return FALSE;
    215 
    216   while ((gchrCurrentEntry = g_dir_read_name (gDir))!= NULL)
    217     {
    218       gchar *path, *display_name;
    219       gboolean is_dir;
    220 
    221       if (gchrCurrentEntry[0] != '\0')
    222         {
    223           path = g_build_filename (gchrPath, gchrCurrentEntry, NULL);
    224           nomPrintf("  %s\n", path);         
    225 
    226           display_name = g_filename_to_utf8 (gchrCurrentEntry, -1, NULL, NULL, NULL);
    227           if(g_file_test (path, G_FILE_TEST_IS_DIR))
    228             {
    229               /* It's a folder */
    230               WPFolder* wpFolder;
    231 
    232               wpFolder=WPFolderNew();
    233               if(nomIsObj(wpFolder))
    234                 {
    235                   gtk_list_store_append (store, &iter);
    236 #if 0
    237                   gtk_list_store_set (store, &iter,
    238                                       COL_PATH, path,
    239                                       COL_DISPLAY_NAME, display_name,
    240                                       COL_IS_DIRECTORY, is_dir,
    241                                       COL_PIXBUF, _wpQueryIcon(wpFolder), //folder_pixbuf ,
    242                                       -1);
    243 #endif
    244                 }/* if(nomIsObj(wpFolder)) */
    245             }/* if(g_file_test (path, G_FILE_TEST_IS_DIR)) */
    246           else
    247             {
    248               /* It's a file */
    249               WPDataFile* wpDataFile;
    250 
    251               wpDataFile=WPDataFileNew();
    252 
    253               if(nomIsObj(wpDataFile))
    254                 {
    255                   gtk_list_store_append (store, &iter);
    256 
    257 #warning !!!! some problems with icon handling here !!!!
    258                   nomPrintf("Icon ptr: %x\n", _wpQueryIcon(wpDataFile, NULLHANDLE));
    259                   gtk_list_store_set (store, &iter,
    260                                       COL_PATH, path,
    261                                       COL_DISPLAY_NAME, display_name,
    262                                       COL_IS_DIRECTORY, is_dir,
    263                                       COL_PIXBUF, _wpQueryIcon(wpDataFile, NULLHANDLE), //file_pixbuf,
    264                                       -1);
    265                 }
    266             }
    267           g_free (path);
    268           g_free (display_name);
    269         }/* if (gchrCurrentEntry[0] != '\0') */
    270     }/* while */
    271 
    272   g_dir_close(gDir);
    273 
    274   return TRUE;
    275 }
    276 
    277 /* pszPath contains the fully qualified path (checked with WPS) */
    278 NOM_Scope CORBA_boolean NOMLINK impl_WPFolder_wpPopulate(WPFolder* nomSelf, const CORBA_unsigned_long ulReserved, const CORBA_char * pszPath, const CORBA_boolean fFoldersOnly, CORBA_Environment *ev)
    279 {
    280  WPFolderData* nomThis=WPFolderGetData(nomSelf);
    281   GtkListStore* gStore;
    282   PPRIVFOLDERDATA priv;
    283 
    284   nomPrintf("    Entering %s with nomSelf: 0x%x. nomSelf is: %s. Path is %s\n",
    285             __FUNCTION__, nomSelf , nomSelf->mtab->nomClassName, pszPath);
    286 
    287   g_return_val_if_fail(_privFolderData!=NULLHANDLE, FALSE);      /* Huh! What happened in wpInitData()? */
    288   g_log("WPFolder", G_LOG_LEVEL_DEBUG, "%s: Populating %s\n", __FUNCTION__, pszPath);
    289 
    290 #warning !!!!! Window creation must be done elsewhere !!!!!
    291   fldr_createFolderWindow(nomSelf, pszPath);
    292 
    293 #if 0
    294   /* Already populated? */
    295   if(fFoldersOnly &&
    296      (_wpQueryFldrFlags(somSelf) & (FOI_POPULATEDWITHFOLDERS | FOI_POPULATEDWITHALL)))
    297     return TRUE;
    298   else if(_wpQueryFldrFlags(somSelf) & FOI_POPULATEDWITHALL)
    299     return TRUE;
    300 #endif
    301 
    302   priv=_privFolderData;
    303 
    304   if(!priv->gstoreFldContents)
    305     {
    306       /* Create a store holding the folder contents */
    307       gStore=fldr_CreateStore();
    308       g_return_val_if_fail(gStore!=NULLHANDLE, FALSE);
    309       priv->gstoreFldContents=gStore;
    310     }
    311 
    312   /* Fill our store */
    313   fldr_fillStore(gStore, pszPath);
    314 
    315 
    316   gtk_icon_view_set_model(GTK_ICON_VIEW (priv->gtkIconView), GTK_TREE_MODEL (priv->gstoreFldContents));
    317 
    318 
    319   /* We now set which model columns that correspont to the text
    320    * and pixbuf of each item
    321    */
    322   gtk_icon_view_set_text_column (GTK_ICON_VIEW (priv->gtkIconView), COL_DISPLAY_NAME);
    323   gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (priv->gtkIconView), COL_PIXBUF);
    324   gtk_icon_view_set_item_width (GTK_ICON_VIEW (priv->gtkIconView),
    325                                 100);
    326 
    327   g_object_unref (gStore);
    328 
    329   return FALSE;
    330 }
    331 
    332 
    333 NOM_Scope void NOMLINK impl_WPFolder_wpInitData(WPFolder* nomSelf, CORBA_Environment *ev)
    334 {
    335   gulong ulErr;
    336   WPFolderData* nomThis=WPFolderGetData(nomSelf);
    337 
    338   /* orbit-idl-c-stubs.c, VoyagerWriteProtoForParentCall line 84 */
    339   WPFolder_wpInitData_parent(nomSelf,  ev);
    340 
    341   nomPrintf("    Entering %s with nomSelf: 0x%x. nomSelf is: %s.\n",
    342             __FUNCTION__, nomSelf , nomSelf->mtab->nomClassName);
    343   _privFolderData=_wpAllocMem((WPObject*)nomSelf, sizeof(PRIVFOLDERDATA), (CORBA_unsigned_long*)&ulErr, NULLHANDLE);
    344 }
    345 
    346 NOM_Scope void NOMLINK impl_WPFolder_wpOpen(WPFolder* nomSelf, CORBA_Environment *ev)
    347 {
    348 /* WPFolderData* nomThis=WPFolderGetData(nomSelf); */
    349 
    350 #if 0
    351   /* orbit-idl-c-stubs.c, VoyagerWriteProtoForParentCall line 84 */
    352   WPFolder_wpOpen_parent(nomSelf,  ev);
    353 #endif
    354 }
    355 
    356 NOM_Scope void NOMLINK impl_WPFolder_wpQueryIcon(WPFolder* nomSelf, CORBA_Environment *ev)
    357 {
    358   static const gchar *gchrIconName=NULLHANDLE;
    359   static gpointer ptrIcon=NULLHANDLE;
    360   GError *error=NULL;
    361 
    362 /* WPFolderData* nomThis=WPFolderGetData(nomSelf); */
    363 
    364   /* Load default wpObject icon */
    365   if(!gchrIconName){
    366     gchrIconName=g_build_filename(priv_getIconDir(), WPFOLDER_ICON_FILE, NULL);
    367    
    368     g_return_val_if_fail(g_file_test (gchrIconName, G_FILE_TEST_EXISTS), NULLHANDLE);
    369     nomPrintf("IconFile: %s\n", gchrIconName); 
    370     //  _hPointerCls = (HPOINTER)gdk_pixbuf_new_from_file (gchrIconName, &error);
    371     ptrIcon=gdk_pixbuf_new_from_file (gchrIconName, &error);
    372   }
    373   return ptrIcon;
    374 
    375   /*  WPFolder_wpQueryIcon_parent(nomSelf,  ev); */
    376 }
    377 
    378 
    379 
    380 
    381 
     456
     457
     458
     459
Note: See TracChangeset for help on using the changeset viewer.