diff options
Diffstat (limited to 'ldmicro/lib/linuxUI/linuxUI.cpp')
-rw-r--r-- | ldmicro/lib/linuxUI/linuxUI.cpp | 146 |
1 files changed, 116 insertions, 30 deletions
diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp index 9fec264..b57d4d0 100644 --- a/ldmicro/lib/linuxUI/linuxUI.cpp +++ b/ldmicro/lib/linuxUI/linuxUI.cpp @@ -1,5 +1,9 @@ #include "linuxUI.h" +/// Global variables to hole mouse click positions +int GLOBAL_mouse_last_clicked_x; +int GLOBAL_mouse_last_clicked_y; + /// Brushes const COLORREF BLACK_BR(0, 0, 0); const COLORREF WHITE_BR(255, 255, 255); @@ -10,6 +14,9 @@ const COLORREF DKGRAY_BR(169, 169, 169); /// Variable to current text color COLORREF HdcCurrentTextColor; +/// Variable to hold timers +std::vector<TimerRecord> timerRecords; + /// EnableMenuItem Variables const UINT MF_ENABLED = 0; const UINT MF_GRAYED = 1; @@ -96,21 +103,87 @@ int MessageBox(HWID pWindow, char* message, char* title, UINT mFlags) BOOL GetSaveFileName(OPENFILENAME *ofn) { GtkWidget *dialog; - GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; + GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE; dialog = gtk_file_chooser_dialog_new (ofn->lpstrTitle, GTK_WINDOW(ofn->parentWindow), action, "_Cancel", GTK_RESPONSE_CANCEL, - "_Open", + "_Save", GTK_RESPONSE_ACCEPT, NULL); - //g_print("filter created\n"); + char filename[15] = "Untitled"; + + if (ofn->lpstrDefExt != NULL) + sprintf(filename, "Untitled.%s", ofn->lpstrDefExt); - if (ofn->Flags & OFN_OVERWRITEPROMPT == OFN_OVERWRITEPROMPT) + gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(dialog), filename); + + if (ofn->Flags & OFN_OVERWRITEPROMPT) gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); + + GtkFileFilter *filter = gtk_file_filter_new (); + char* strFilter = new char[strlen(ofn->lpstrFilter)]; + DWORD strFilterLen = 0; + BOOL filterResetFlag = FALSE; + + for (int i = 0; !(ofn->lpstrFilter[i] == '\0' && ofn->lpstrFilter[i-1] == '\0'); ++i) + { + memcpy (strFilter + strFilterLen, &ofn->lpstrFilter[i], 1 ); + ++strFilterLen; + if (ofn->lpstrFilter[i] == '\0') + if (filterResetFlag) + { + gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter), strFilter); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(dialog), filter); + filter = gtk_file_filter_new (); + strFilterLen = 0; + filterResetFlag = FALSE; + } + else + { + gtk_file_filter_set_name (GTK_FILE_FILTER(filter), strFilter); + strFilterLen = 0; + filterResetFlag = TRUE; + } + } + + sprintf(strFilter, "*.%s", ofn->lpstrDefExt); + gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter), strFilter); + gtk_file_chooser_set_filter (GTK_FILE_CHOOSER(dialog), filter); + + delete strFilter; + BOOL exitStatus = gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT; + if (exitStatus) + { + char* str; + str = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(dialog)); + + strcpy(ofn->lpstrFile, str); + g_free(str); + } + + gtk_widget_destroy (dialog); + + return exitStatus; +} + +BOOL GetOpenFileName(OPENFILENAME *ofn) +{ + GtkWidget *dialog; + GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; + + dialog = gtk_file_chooser_dialog_new (ofn->lpstrTitle, + GTK_WINDOW(ofn->parentWindow), + action, + "_Cancel", + GTK_RESPONSE_CANCEL, + "_Open", + GTK_RESPONSE_ACCEPT, + NULL); + GtkFileFilter *filter = gtk_file_filter_new (); char* strFilter = new char[strlen(ofn->lpstrFilter)]; DWORD strFilterLen = 0; @@ -127,19 +200,15 @@ BOOL GetSaveFileName(OPENFILENAME *ofn) gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(dialog), filter); filter = gtk_file_filter_new (); strFilterLen = 0; - //g_print("filter pat: %s\n", strFilter); - //g_print("filter reset\n"); filterResetFlag = FALSE; } else { gtk_file_filter_set_name (GTK_FILE_FILTER(filter), strFilter); - //g_print("filter name: %s\n", strFilter); strFilterLen = 0; filterResetFlag = TRUE; } } - //g_print("filter rules added\n"); sprintf(strFilter, "*.%s", ofn->lpstrDefExt); gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter), strFilter); @@ -148,8 +217,6 @@ BOOL GetSaveFileName(OPENFILENAME *ofn) delete strFilter; - //g_print("default filter set\n"); - BOOL exitStatus = gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT; if (exitStatus) { @@ -158,15 +225,13 @@ BOOL GetSaveFileName(OPENFILENAME *ofn) strcpy(ofn->lpstrFile, str); g_free(str); } - //g_print("file path saved: %s\n", ofn->lpstrFile); gtk_widget_destroy (dialog); - //g_print("exit\n"); - return exitStatus; } + void EnableMenuItem(HMENU MenuName, HMENU MenuItem, UINT CheckEnabledItem) { switch (CheckEnabledItem){ @@ -231,8 +296,6 @@ void SelectObject(HCRDC hcr, HFONT hfont) // cairo_set_font_matrix (hcr, &matrix); - // g_print("wR = %f\nhR = %f\n", (double)hfont->nWidth / extents.width, (double)hfont->nHeight / extents.height); - // g_print("tW = %f tH = %f\n", extents.width, extents.width); cairo_set_font_size(hcr, 10); } @@ -263,11 +326,11 @@ HFONT CreateFont(int nHeight, int nWidth, int nOrientation, int fnWeight, void SetBkColor(HWID widget, HCRDC hcr, COLORREF bkCol) { - // gtk_widget_override_background_color(GTK_WIDGET(widget), - // GTK_STATE_FLAG_NORMAL, &bkCol); + gtk_widget_override_background_color(GTK_WIDGET(widget), + GTK_STATE_FLAG_NORMAL, &bkCol); - // gint width = gtk_widget_get_allocated_width (widget); - // gint height = gtk_widget_get_allocated_height (widget); + gint width = gtk_widget_get_allocated_width (widget); + gint height = gtk_widget_get_allocated_height (widget); // COLORREF col; // GtkStyleContext *context; @@ -277,10 +340,11 @@ void SetBkColor(HWID widget, HCRDC hcr, COLORREF bkCol) // gtk_style_context_get_color (context, // gtk_style_context_get_state (context), // &col); - - // gdk_cairo_set_source_rgba (hcr, &col); + gdk_cairo_set_source_rgba (hcr, &bkCol); + // cairo_rectangle(hcr, 0, 0, width, height); + // cairo_stroke_preserve(hcr); - // cairo_fill (hcr); + cairo_fill (hcr); } void SetTextColor(HCRDC hcr, COLORREF color) @@ -298,24 +362,22 @@ void TextOut(HWID hWid, HCRDC hcr, int nXStart, int nYStart, LPCTSTR lpString, i int width = gtk_widget_get_allocated_width (hWid); int height= gtk_widget_get_allocated_height (hWid); BOOL resize_flag = FALSE; - // g_print("w = %f h = %f") if(nYStart+(extents.height/2.0) >= height) { - // g_print("Y extend\n"); height += extents.height + 50; resize_flag = TRUE; } if (nXStart+(extents.width/2.0) >= width) { - // g_print("X extend\n"); width += extents.width; resize_flag = TRUE; } if (resize_flag) gtk_widget_set_size_request(hWid, width, height); + char* text = (char*)malloc(cchString); strncpy(text, lpString, cchString); text[cchString] = '\0'; @@ -323,8 +385,6 @@ void TextOut(HWID hWid, HCRDC hcr, int nXStart, int nYStart, LPCTSTR lpString, i cairo_move_to(hcr, nXStart, nYStart); cairo_show_text(hcr, text); - // g_print("%s", text); - cairo_fill (hcr); } @@ -341,10 +401,7 @@ COLORREF GetTextColor(HCRDC Hdc) BOOL InvalidateRect(HWID hWid, const RECT *lpRect, BOOL bErase) { if(!GDK_IS_WINDOW(hWid)) - { - // g_print("not window\n"); return FALSE; - } if (lpRect == NULL) { @@ -425,3 +482,32 @@ BOOL GetWindowRect(HWID hWid, PRECT pRect) void DestroyWindow (GtkWidget* widget, gpointer data){ gtk_widget_destroy (widget); } +UINT SetTimer(HWID hWid, UINT nIDEvent, UINT uElapse, BOOL (*lpTimerFunc)(BOOL) ) +{ + auto record_it = std::find_if(timerRecords.begin(), timerRecords.end(), [&nIDEvent](TimerRecord &Record) { return Record.ufID == nIDEvent; }); + + if (record_it != timerRecords.end()) + return 0; + + TimerRecord tr; + tr.pfun = lpTimerFunc; + tr.ufID = nIDEvent; + tr.utID = g_timeout_add(uElapse, (GSourceFunc)lpTimerFunc, FALSE); + + timerRecords.push_back(tr); + return tr.utID; +} + +BOOL KillTimer(HWID hWid, UINT uIDEvent) +{ + auto record_it = std::find_if(timerRecords.begin(), timerRecords.end(), [&uIDEvent](TimerRecord &Record) { return Record.ufID == uIDEvent; }); + + if (record_it == timerRecords.end()) + return FALSE; + + record_it->pfun(TRUE); + g_source_remove (record_it->utID); + timerRecords.erase(record_it); + + return TRUE; +} |