diff options
author | Ian McIntosh <ian_mcintosh@linuxadvocate.org> | 2005-10-01 14:09:05 +0000 |
---|---|---|
committer | Ian McIntosh <ian_mcintosh@linuxadvocate.org> | 2005-10-01 14:09:05 +0000 |
commit | 10eb4a1a8c2f6251f758391be0db9018f8535511 (patch) | |
tree | 0ef0db81e3dd205ea055826cac516c40be897c7e /src | |
parent | 3d2b7f64935698d7942d7e8a3f0fe12f28a3366a (diff) |
Remove _ from public function _downloadmanager_new().
Set check on View/Fullscreen and View/Sidebar when state changes for
reasons other than the user clicking the menu item.
Add some debug printing support.
Add a new history item when user selects a search result.
Moved some basic window state set/test functions here.
Diffstat (limited to 'src')
-rw-r--r-- | src/downloadmanager.c | 12 | ||||
-rw-r--r-- | src/mainwindow.c | 106 | ||||
-rw-r--r-- | src/mainwindow.h | 2 | ||||
-rw-r--r-- | src/map_history.c | 18 | ||||
-rw-r--r-- | src/searchwindow.c | 1 | ||||
-rw-r--r-- | src/util.c | 24 | ||||
-rw-r--r-- | src/util.h | 3 |
7 files changed, 124 insertions, 42 deletions
diff --git a/src/downloadmanager.c b/src/downloadmanager.c index a2ddda5..d6e10f6 100644 --- a/src/downloadmanager.c +++ b/src/downloadmanager.c @@ -38,7 +38,7 @@ typedef struct { gchar* pszRemoteFilePath; gchar* pszLocalFilePath; // will be NULL until file moves into 'active' list - gint nBytesDownloaded; // a count + gint nBytesDownloaded; // a count downloadmanager_t* pDownloadManager; // a handy pointer to the parent GnomeVFSAsyncHandle* pGnomeVFSHandle; @@ -52,9 +52,9 @@ static gboolean _downloadmanager_begin_download(download_t* pDownload); static void _downloadmanager_move_pending_to_active(downloadmanager_t* pDownloadManager); // -// functions +// Public API // -downloadmanager_t* _downloadmanager_new(gint nMaxConcurrentActive) +downloadmanager_t* downloadmanager_new(gint nMaxConcurrentActive) { downloadmanager_t* pNew = g_new0(downloadmanager_t, 1); pNew->pActiveArray = g_ptr_array_new(); @@ -78,9 +78,13 @@ void downloadmanager_add_uri(downloadmanager_t* pDownloadManager, const gchar* p _downloadmanager_move_pending_to_active(pDownloadManager); } -// Check to see if we can add any pending files to active list +// +// Private functions +// + static void _downloadmanager_move_pending_to_active(downloadmanager_t* pDownloadManager) { + // Check to see if we can add any pending files to active list if((pDownloadManager->pActiveArray->len < pDownloadManager->nMaxConcurrentActive) && (pDownloadManager->pPendingArray->len > 0)) { // time to promote one from pending download_t* pNext = g_ptr_array_index(pDownloadManager->pPendingArray, 0); diff --git a/src/mainwindow.c b/src/mainwindow.c index e7782a4..8a75000 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -125,9 +125,14 @@ typedef enum { // Prototypes static void mainwindow_setup_selected_tool(void); static void mainwindow_map_center_on_windowpoint(gint nX, gint nY); -static void mainwindow_add_history(); static void mainwindow_on_web_url_clicked(GtkWidget *_unused, gchar* pszURLPattern); +static gboolean mainwindow_on_window_state_change(GtkWidget *widget, GdkEventKey *event, gpointer user_data); + +void mainwindow_update_zoom_buttons(); + +void mainwindow_on_sidebarmenuitem_activate(GtkMenuItem *menuitem, gpointer user_data); + static gboolean mainwindow_on_mouse_button_click(GtkWidget* w, GdkEventButton *event); static gboolean mainwindow_on_mouse_motion(GtkWidget* w, GdkEventMotion *event); static gboolean mainwindow_on_mouse_scroll(GtkWidget* w, GdkEventScroll *event); @@ -139,6 +144,9 @@ static gboolean mainwindow_on_enter_notify(GtkWidget* w, GdkEventCrossing *event static gboolean mainwindow_on_leave_notify(GtkWidget* w, GdkEventCrossing *event); static void mainwindow_on_locationset_visible_checkbox_clicked(GtkCellRendererToggle *cell, gchar *path_str, gpointer data); static gboolean mainwindow_on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer user_data); +static gboolean mainwindow_on_key_release(GtkWidget *widget, GdkEventKey *event, gpointer user_data); + +void mainwindow_on_fullscreenmenuitem_activate(GtkMenuItem *menuitem, gpointer user_data); static void mainwindow_configure_locationset_list(); void mainwindow_refresh_locationset_list(); @@ -236,6 +244,9 @@ struct { GtkMenuItem* pBackMenuItem; GtkMenuItem* pWebMapsMenuItem; + + GtkCheckMenuItem* pViewSidebarMenuItem; + GtkCheckMenuItem* pViewFullscreenMenuItem; } g_MainWindow = {0}; // XXX: Use GDK_HAND1 for the map @@ -354,6 +365,10 @@ void mainwindow_init(GladeXML* pGladeXML) GLADE_LINK_WIDGET(pGladeXML, g_MainWindow.pSidebarNotebook, GTK_NOTEBOOK, "sidebarnotebook"); GLADE_LINK_WIDGET(pGladeXML, g_MainWindow.pContentBox, GTK_VBOX, "mainwindowcontentsbox"); + // View menu + GLADE_LINK_WIDGET(pGladeXML, g_MainWindow.pViewSidebarMenuItem, GTK_CHECK_MENU_ITEM, "viewsidebarmenuitem"); + GLADE_LINK_WIDGET(pGladeXML, g_MainWindow.pViewFullscreenMenuItem, GTK_CHECK_MENU_ITEM, "viewfullscreenmenuitem"); + // Zoom controls GLADE_LINK_WIDGET(pGladeXML, g_MainWindow.pZoomInButton, GTK_BUTTON, "zoominbutton"); GLADE_LINK_WIDGET(pGladeXML, g_MainWindow.pZoomInMenuItem, GTK_MENU_ITEM, "zoominmenuitem"); @@ -399,22 +414,38 @@ void mainwindow_init(GladeXML* pGladeXML) g_MainWindow.pTooltips = gtk_tooltips_new(); g_MainWindow.pTooltip = tooltip_new(); - // Drawing area - g_MainWindow.pDrawingArea = GTK_DRAWING_AREA(gtk_drawing_area_new()); - gtk_widget_show(GTK_WIDGET(g_MainWindow.pDrawingArea)); - // create map and load style - map_new(&g_MainWindow.pMap, GTK_WIDGET(g_MainWindow.pDrawingArea)); - map_style_load(g_MainWindow.pMap, MAP_STYLE_FILENAME); + // Signal handlers for main window + gtk_widget_add_events(GTK_WIDGET(g_MainWindow.pWindow), GDK_KEY_PRESS_MASK); + g_signal_connect(G_OBJECT(g_MainWindow.pWindow), "window_state_event", G_CALLBACK(mainwindow_on_window_state_change), NULL); + g_signal_connect(G_OBJECT(g_MainWindow.pWindow), "key_press_event", G_CALLBACK(mainwindow_on_key_press), NULL); + g_signal_connect(G_OBJECT(g_MainWindow.pWindow), "key_release_event", G_CALLBACK(mainwindow_on_key_release), NULL); - g_assert(g_MainWindow.pContentBox); - g_assert(g_MainWindow.pDrawingArea); + // Drawing area + g_MainWindow.pDrawingArea = GTK_DRAWING_AREA(gtk_drawing_area_new()); // Pack drawing area into application window gtk_box_pack_end(GTK_BOX(g_MainWindow.pContentBox), GTK_WIDGET(g_MainWindow.pDrawingArea), TRUE, // expand TRUE, // fill 0); + gtk_widget_show(GTK_WIDGET(g_MainWindow.pDrawingArea)); + + // Signal handlers for drawing area + gtk_widget_add_events(GTK_WIDGET(g_MainWindow.pDrawingArea), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK); + g_signal_connect(G_OBJECT(g_MainWindow.pDrawingArea), "expose_event", G_CALLBACK(mainwindow_on_expose_event), NULL); + g_signal_connect(G_OBJECT(g_MainWindow.pDrawingArea), "configure_event", G_CALLBACK(mainwindow_on_configure_event), NULL); + g_signal_connect(G_OBJECT(g_MainWindow.pDrawingArea), "button_press_event", G_CALLBACK(mainwindow_on_mouse_button_click), NULL); + g_signal_connect(G_OBJECT(g_MainWindow.pDrawingArea), "button_release_event", G_CALLBACK(mainwindow_on_mouse_button_click), NULL); + g_signal_connect(G_OBJECT(g_MainWindow.pDrawingArea), "motion_notify_event", G_CALLBACK(mainwindow_on_mouse_motion), NULL); + g_signal_connect(G_OBJECT(g_MainWindow.pDrawingArea), "scroll_event", G_CALLBACK(mainwindow_on_mouse_scroll), NULL); + g_signal_connect(G_OBJECT(g_MainWindow.pDrawingArea), "enter_notify_event", G_CALLBACK(mainwindow_on_enter_notify), NULL); + g_signal_connect(G_OBJECT(g_MainWindow.pDrawingArea), "leave_notify_event", G_CALLBACK(mainwindow_on_leave_notify), NULL); + + // create map and load style + map_new(&g_MainWindow.pMap, GTK_WIDGET(g_MainWindow.pDrawingArea)); + map_style_load(g_MainWindow.pMap, MAP_STYLE_FILENAME); + cursor_init(); @@ -434,17 +465,9 @@ void mainwindow_init(GladeXML* pGladeXML) // When main window closes, quit. g_signal_connect(G_OBJECT(g_MainWindow.pWindow), "delete_event", G_CALLBACK(gtk_main_quit), NULL); - // Signal handlers for drawing area - gtk_widget_add_events(GTK_WIDGET(g_MainWindow.pDrawingArea), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK); - g_signal_connect(G_OBJECT(g_MainWindow.pDrawingArea), "expose_event", G_CALLBACK(mainwindow_on_expose_event), NULL); - g_signal_connect(G_OBJECT(g_MainWindow.pDrawingArea), "configure_event", G_CALLBACK(mainwindow_on_configure_event), NULL); - g_signal_connect(G_OBJECT(g_MainWindow.pDrawingArea), "button_press_event", G_CALLBACK(mainwindow_on_mouse_button_click), NULL); - g_signal_connect(G_OBJECT(g_MainWindow.pDrawingArea), "button_release_event", G_CALLBACK(mainwindow_on_mouse_button_click), NULL); - g_signal_connect(G_OBJECT(g_MainWindow.pDrawingArea), "motion_notify_event", G_CALLBACK(mainwindow_on_mouse_motion), NULL); - g_signal_connect(G_OBJECT(g_MainWindow.pDrawingArea), "scroll_event", G_CALLBACK(mainwindow_on_mouse_scroll), NULL); - g_signal_connect(G_OBJECT(g_MainWindow.pDrawingArea), "enter_notify_event", G_CALLBACK(mainwindow_on_enter_notify), NULL); - g_signal_connect(G_OBJECT(g_MainWindow.pDrawingArea), "leave_notify_event", G_CALLBACK(mainwindow_on_leave_notify), NULL); - g_signal_connect(G_OBJECT(g_MainWindow.pDrawingArea), "key_press_event", G_CALLBACK(mainwindow_on_key_press), NULL); + // XXX: move map to starting location... for now it's (0,0) + mainwindow_add_history(); + mainwindow_update_zoom_buttons(); // make sure buttons are grayed out } gboolean mainwindow_locationset_list_is_separator_callback(GtkTreeModel *_unused, GtkTreeIter *pIter, gpointer __unused) @@ -669,12 +692,12 @@ void mainwindow_statusbar_update_position(void) */ void mainwindow_set_sidebox_visible(gboolean bVisible) { - if(bVisible) { - gtk_widget_show(GTK_WIDGET(g_MainWindow.pSidebox)); - } - else { - gtk_widget_hide(GTK_WIDGET(g_MainWindow.pSidebox)); - } + // Set the menu's check without calling the signal handler + g_signal_handlers_block_by_func(g_MainWindow.pViewSidebarMenuItem, mainwindow_on_sidebarmenuitem_activate, NULL); + gtk_check_menu_item_set_active(g_MainWindow.pViewSidebarMenuItem, bVisible); + g_signal_handlers_unblock_by_func(g_MainWindow.pViewSidebarMenuItem, mainwindow_on_sidebarmenuitem_activate, NULL); + + util_gtk_widget_set_visible(GTK_WIDGET(g_MainWindow.pSidebox), bVisible); } gboolean mainwindow_get_sidebox_visible(void) @@ -689,16 +712,7 @@ GtkWidget* mainwindow_get_window(void) void mainwindow_toggle_fullscreen(void) { - GdkWindow* pTopLevelGDKWindow = gdk_window_get_toplevel(GTK_WIDGET(g_MainWindow.pWindow)->window); - g_return_if_fail(pTopLevelGDKWindow != NULL); - - GdkWindowState windowstate = gdk_window_get_state(pTopLevelGDKWindow); - if(windowstate & GDK_WINDOW_STATE_FULLSCREEN) { - gdk_window_unfullscreen(pTopLevelGDKWindow); - } - else { - gdk_window_fullscreen(pTopLevelGDKWindow); - } + util_gtk_window_set_fullscreen(g_MainWindow.pWindow, !util_gtk_window_is_fullscreen(g_MainWindow.pWindow)); } // User clicked Quit window @@ -730,7 +744,7 @@ void mainwindow_set_zoomlevel(gint nZoomLevel) map_set_zoomlevel(g_MainWindow.pMap, nZoomLevel); // set zoomlevel scale but prevent it from calling handler (mainwindow_on_zoomscale_value_changed) - g_signal_handlers_block_by_func(g_MainWindow.pZoomScale, mainwindow_on_zoomscale_value_changed, NULL); + g_signal_handlers_block_by_func(g_MainWindow.pZoomScale, mainwindow_on_zoomscale_value_changed, NULL); gtk_range_set_value(GTK_RANGE(g_MainWindow.pZoomScale), nZoomLevel); g_signal_handlers_unblock_by_func(g_MainWindow.pZoomScale, mainwindow_on_zoomscale_value_changed, NULL); @@ -850,6 +864,8 @@ void mainwindow_on_zoomin_activate(GtkMenuItem *menuitem, gpointer user_data) { // tell the map map_set_zoomlevel(g_MainWindow.pMap, map_get_zoomlevel(g_MainWindow.pMap) + 1); + + // update the gui mainwindow_set_zoomlevel(map_get_zoomlevel(g_MainWindow.pMap)); mainwindow_draw_map(DRAWFLAG_GEOMETRY); mainwindow_set_draw_pretty_timeout(DRAW_PRETTY_ZOOM_TIMEOUT_MS); @@ -1280,6 +1296,20 @@ static gboolean mainwindow_on_mouse_scroll(GtkWidget* w, GdkEventScroll *event) static gboolean mainwindow_on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer user_data) { g_print("key_press\n"); + return FALSE; +} +static gboolean mainwindow_on_key_release(GtkWidget *widget, GdkEventKey *event, gpointer user_data) +{ + g_print("key_release\n"); + return FALSE; +} + +static gboolean mainwindow_on_window_state_change(GtkWidget *_unused, GdkEventKey *pEvent, gpointer __unused) +{ + // Set the menu's check without calling the signal handler + g_signal_handlers_block_by_func(g_MainWindow.pViewFullscreenMenuItem, mainwindow_on_fullscreenmenuitem_activate, NULL); + gtk_check_menu_item_set_active(g_MainWindow.pViewFullscreenMenuItem, util_gtk_window_is_fullscreen(g_MainWindow.pWindow)); + g_signal_handlers_unblock_by_func(g_MainWindow.pViewFullscreenMenuItem, mainwindow_on_fullscreenmenuitem_activate, NULL); } static void mainwindow_begin_import_geography_data(void) @@ -1662,7 +1692,7 @@ void mainwindow_on_forwardbutton_clicked(GtkWidget* _unused, gpointer* __unused) mainwindow_update_forward_back_buttons(); } -static void mainwindow_add_history() +void mainwindow_add_history() { // add the current spot to the history mappoint_t point; diff --git a/src/mainwindow.h b/src/mainwindow.h index 2f3b840..88623fa 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -74,6 +74,8 @@ void mainwindow_map_center_on_mappoint(mappoint_t* pPoint); void mainwindow_map_get_centerpoint(mappoint_t* pPoint); void mainwindow_map_slide_to_mappoint(mappoint_t* pPoint); +void mainwindow_add_history(); + typedef enum { DIRECTION_NONE, DIRECTION_N, DIRECTION_NE, DIRECTION_E, DIRECTION_SE, DIRECTION_S, DIRECTION_SW, DIRECTION_W, DIRECTION_NW } EDirection; diff --git a/src/map_history.c b/src/map_history.c index d889b9f..e770714 100644 --- a/src/map_history.c +++ b/src/map_history.c @@ -26,6 +26,8 @@ #include "map.h" #include "map_history.h" +static void map_history_debug_print(maphistory_t* pHistory); + typedef struct { mappoint_t MapPoint; gint nZoomLevel; @@ -72,6 +74,7 @@ void map_history_add(maphistory_t* pHistory, mappoint_t* pPoint, gint nZoomLevel pHistory->nTotalItems++; g_assert(pHistory->nCurrentIndex < pHistory->nTotalItems); + map_history_debug_print(pHistory); } gboolean map_history_can_go_forward(maphistory_t* pHistory) @@ -88,6 +91,7 @@ gboolean map_history_go_forward(maphistory_t* pHistory) { if(map_history_can_go_forward(pHistory)) { pHistory->nCurrentIndex++; + map_history_debug_print(pHistory); return TRUE; } } @@ -96,6 +100,7 @@ gboolean map_history_go_back(maphistory_t* pHistory) { if(map_history_can_go_back(pHistory)) { pHistory->nCurrentIndex--; + map_history_debug_print(pHistory); return TRUE; } } @@ -113,3 +118,16 @@ void map_history_get_current(maphistory_t* pHistory, mappoint_t* pReturnPoint, g memcpy(pReturnPoint, &(pCurrent->MapPoint), sizeof(mappoint_t)); *pnReturnZoomLevel = pCurrent->nZoomLevel; } + +static void map_history_debug_print(maphistory_t* pHistory) +{ + return; + + gint i; + g_print("Map History:\n"); + for(i=0 ; i<pHistory->nTotalItems ; i++) { + mapview_t* pCurrent = &g_array_index(pHistory->MapViewArray, mapview_t, i); + + g_print("%s(%f,%f @ %d)\n", (i==pHistory->nCurrentIndex) ? "*" : "", pCurrent->MapPoint.fLongitude, pCurrent->MapPoint.fLatitude, pCurrent->nZoomLevel); + } +} diff --git a/src/searchwindow.c b/src/searchwindow.c index 40c9288..d3f6993 100644 --- a/src/searchwindow.c +++ b/src/searchwindow.c @@ -305,6 +305,7 @@ static void searchwindow_go_to_selected_result(void) //mainwindow_map_slide_to_mappoint(&pt); mainwindow_set_zoomlevel(nZoomLevel); mainwindow_map_center_on_mappoint(&pt); + mainwindow_add_history(); void* pBusy = mainwindow_set_busy(); mainwindow_draw_map(DRAWFLAG_ALL); @@ -404,6 +404,28 @@ gchar* util_str_replace_many(const gchar* pszSource, util_str_replace_t* aReplac return pszReturn; } +gboolean util_gtk_window_is_fullscreen(GtkWindow* pWindow) +{ + GdkWindow* pTopLevelGDKWindow = gdk_window_get_toplevel(GTK_WIDGET(pWindow)->window); + g_return_if_fail(pTopLevelGDKWindow != NULL); + + GdkWindowState windowstate = gdk_window_get_state(pTopLevelGDKWindow); + + return((windowstate & GDK_WINDOW_STATE_FULLSCREEN) > 0); +} + +gboolean util_gtk_window_set_fullscreen(GtkWindow* pWindow, gboolean bFullscreen) +{ + GdkWindow* pTopLevelGDKWindow = gdk_window_get_toplevel(GTK_WIDGET(pWindow)->window); + g_return_if_fail(pTopLevelGDKWindow != NULL); + if(bFullscreen) { + gdk_window_fullscreen(pTopLevelGDKWindow); + } + else { + gdk_window_unfullscreen(pTopLevelGDKWindow); + } +} + // // // @@ -448,3 +470,5 @@ void util_gtk_entry_add_hint_text(GtkEntry* pEntry, const gchar* pszHint) // Init it _util_gtk_entry_on_focus_out_event(pEntry, NULL, pszHint); } + + @@ -58,6 +58,9 @@ gboolean util_treeview_match_all_words_callback(GtkTreeModel *pTreeModel, gint n gboolean util_gtk_tree_view_select_next(GtkTreeView* pTreeView); gboolean util_gtk_tree_view_select_previous(GtkTreeView* pTreeView); +gboolean util_gtk_window_is_fullscreen(GtkWindow* pWindow); +gboolean util_gtk_window_set_fullscreen(GtkWindow* pWindow, gboolean bFullscreen); + // if glib < 2.6 #if(!GLIB_CHECK_VERSION(2,6,0)) gint g_strv_length(const gchar** a); |